Express ownership transfer in PassManager API through std::unique_ptr (NFC)

Since raw pointers are always passed around for IR construct without
implying any ownership transfer, it can be error prone to have implicit
ownership transferred the same way.
For example this code can seem harmless:

  Pass *pass = ....
  pm.addPass(pass);
  pm.addPass(pass);
  pm.run(module);

PiperOrigin-RevId: 263053082
This commit is contained in:
Mehdi Amini 2019-08-12 19:12:42 -07:00 committed by A. Unique TensorFlower
parent 532c652d6c
commit 926fb685de
66 changed files with 217 additions and 169 deletions

View File

@ -73,7 +73,7 @@ void lowerToLoops(mlir::FuncOp f);
/// Creates a pass that rewrites linalg.load and linalg.store to affine.load and
/// affine.store operations.
mlir::FunctionPassBase *createLowerLinalgLoadStorePass();
std::unique_ptr<mlir::FunctionPassBase> createLowerLinalgLoadStorePass();
} // namespace linalg

View File

@ -300,6 +300,6 @@ Rewriter<linalg::StoreOp>::matchAndRewrite(linalg::StoreOp store,
}
} // namespace
FunctionPassBase *linalg::createLowerLinalgLoadStorePass() {
return new LowerLinalgLoadStorePass();
std::unique_ptr<FunctionPassBase> linalg::createLowerLinalgLoadStorePass() {
return llvm::make_unique<LowerLinalgLoadStorePass>();
}

View File

@ -22,12 +22,14 @@
#ifndef MLIR_TUTORIAL_TOY_PASSES_H
#define MLIR_TUTORIAL_TOY_PASSES_H
#include <memory>
namespace mlir {
class Pass;
} // namespace mlir
namespace toy {
mlir::Pass *createShapeInferencePass();
std::unique_ptr<mlir::Pass> createShapeInferencePass();
} // namespace toy
#endif // MLIR_TUTORIAL_TOY_PASSES_H

View File

@ -375,5 +375,7 @@ public:
} // end anonymous namespace
namespace toy {
mlir::Pass *createShapeInferencePass() { return new ShapeInferencePass(); }
std::unique_ptr<mlir::Pass> createShapeInferencePass() {
return llvm::make_unique<ShapeInferencePass>();
}
} // namespace toy

View File

@ -28,6 +28,7 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Module.h"
#include "mlir/Parser.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Transforms/Passes.h"

View File

@ -35,10 +35,10 @@ class DialectConversion;
namespace toy {
/// Create a pass for lowering operations in the `Linalg` dialects, for a subset
/// of the Toy IR (matmul).
mlir::Pass *createEarlyLoweringPass();
std::unique_ptr<mlir::Pass> createEarlyLoweringPass();
/// Create a pass for the late lowering toward LLVM dialect.
mlir::Pass *createLateLoweringPass();
std::unique_ptr<mlir::Pass> createLateLoweringPass();
} // namespace toy

View File

@ -22,12 +22,14 @@
#ifndef MLIR_TUTORIAL_TOY_PASSES_H
#define MLIR_TUTORIAL_TOY_PASSES_H
#include <memory>
namespace mlir {
class Pass;
} // namespace mlir
namespace toy {
mlir::Pass *createShapeInferencePass();
std::unique_ptr<mlir::Pass> createShapeInferencePass();
} // namespace toy
#endif // MLIR_TUTORIAL_TOY_PASSES_H

View File

@ -142,5 +142,7 @@ struct EarlyLoweringPass : public FunctionPass<EarlyLoweringPass> {
} // end anonymous namespace
namespace toy {
Pass *createEarlyLoweringPass() { return new EarlyLoweringPass(); }
std::unique_ptr<mlir::Pass> createEarlyLoweringPass() {
return llvm::make_unique<EarlyLoweringPass>();
}
} // namespace toy

View File

@ -458,5 +458,7 @@ struct LateLoweringPass : public ModulePass<LateLoweringPass> {
} // end anonymous namespace
namespace toy {
Pass *createLateLoweringPass() { return new LateLoweringPass(); }
std::unique_ptr<mlir::Pass> createLateLoweringPass() {
return llvm::make_unique<LateLoweringPass>();
}
} // namespace toy

View File

@ -375,5 +375,7 @@ public:
} // end anonymous namespace
namespace toy {
mlir::Pass *createShapeInferencePass() { return new ShapeInferencePass(); }
std::unique_ptr<mlir::Pass> createShapeInferencePass() {
return llvm::make_unique<ShapeInferencePass>();
}
} // namespace toy

View File

@ -32,6 +32,7 @@
#include "mlir/IR/MLIRContext.h"
#include "mlir/IR/Module.h"
#include "mlir/Parser.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
#include "mlir/Target/LLVMIR.h"
#include "mlir/Transforms/Passes.h"

View File

@ -39,7 +39,7 @@ using CubinGenerator = std::function<OwnedCubin(const std::string &, FuncOp &)>;
/// attached as a string attribute named 'nvvm.cubin' to the kernel function.
/// After the transformation, the body of the kernel function is removed (i.e.,
/// it is turned into a declaration).
ModulePassBase *
std::unique_ptr<ModulePassBase>
createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator);
/// Creates a pass to convert a gpu.launch_func operation into a sequence of
@ -48,11 +48,11 @@ createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator);
/// This pass does not generate code to call CUDA directly but instead uses a
/// small wrapper library that exports a stable and conveniently typed ABI
/// ontop of CUDA.
ModulePassBase *createConvertGpuLaunchFuncToCudaCallsPass();
std::unique_ptr<ModulePassBase> createConvertGpuLaunchFuncToCudaCallsPass();
/// Creates a pass to augment a module with getter functions for all contained
/// cubins as encoded via the 'nvvm.cubin' attribute.
ModulePassBase *createGenerateCubinAccessorPass();
std::unique_ptr<ModulePassBase> createGenerateCubinAccessorPass();
} // namespace mlir
#endif // MLIR_CONVERSION_GPUTOCUDA_GPUTOCUDAPASS_H_

View File

@ -17,11 +17,13 @@
#ifndef MLIR_CONVERSION_GPUTONVVM_GPUTONVVMPASS_H_
#define MLIR_CONVERSION_GPUTONVVM_GPUTONVVMPASS_H_
#include <memory>
namespace mlir {
struct FunctionPassBase;
/// Creates a pass that lowers GPU dialect operations to NVVM counterparts.
FunctionPassBase *createLowerGpuOpsToNVVMOpsPass();
std::unique_ptr<FunctionPassBase> createLowerGpuOpsToNVVMOpsPass();
} // namespace mlir

View File

@ -17,6 +17,8 @@
#ifndef MLIR_CONVERSION_LOOPSTOGPU_LOOPSTOGPUPASS_H_
#define MLIR_CONVERSION_LOOPSTOGPU_LOOPSTOGPUPASS_H_
#include <memory>
namespace mlir {
class FunctionPassBase;
@ -28,8 +30,8 @@ class FunctionPassBase;
/// parallelization is performed, it is under the responsibility of the caller
/// to strip-mine the loops and to perform the dependence analysis before
/// calling the conversion.
FunctionPassBase *createSimpleLoopsToGPUPass(unsigned numBlockDims,
unsigned numThreadDims);
std::unique_ptr<FunctionPassBase>
createSimpleLoopsToGPUPass(unsigned numBlockDims, unsigned numThreadDims);
} // namespace mlir
#endif // MLIR_CONVERSION_LOOPSTOGPU_LOOPSTOGPUPASS_H_

View File

@ -57,12 +57,12 @@ void populateStdToLLVMConversionPatterns(LLVMTypeConverter &converter,
OwningRewritePatternList &patterns);
/// Creates a pass to convert the Standard dialect into the LLVMIR dialect.
ModulePassBase *createConvertToLLVMIRPass();
std::unique_ptr<ModulePassBase> createConvertToLLVMIRPass();
/// Creates a pass to convert operations to the LLVMIR dialect. The conversion
/// is defined by a list of patterns and a type converter that will be obtained
/// during the pass using the provided callbacks.
ModulePassBase *
std::unique_ptr<ModulePassBase>
createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller,
LLVMTypeConverterMaker typeConverterMaker);
@ -71,7 +71,7 @@ createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller,
/// callback and an optional type conversion class, an instance is created
/// during the pass.
template <typename TypeConverter = LLVMTypeConverter>
ModulePassBase *
std::unique_ptr<ModulePassBase>
createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller) {
return createConvertToLLVMIRPass(patternListFiller, [](MLIRContext *context) {
return llvm::make_unique<TypeConverter>(context);

View File

@ -22,11 +22,13 @@
#ifndef MLIR_DIALECT_GPU_PASSES_H_
#define MLIR_DIALECT_GPU_PASSES_H_
#include <memory>
namespace mlir {
class ModulePassBase;
ModulePassBase *createGpuKernelOutliningPass();
std::unique_ptr<ModulePassBase> createGpuKernelOutliningPass();
} // namespace mlir

View File

@ -25,6 +25,8 @@
#ifndef MLIR_DIALECT_QUANTOPS_PASSES_H
#define MLIR_DIALECT_QUANTOPS_PASSES_H
#include <memory>
namespace mlir {
class FunctionPassBase;
@ -32,14 +34,14 @@ namespace quant {
/// Creates a pass that converts quantization simulation operations (i.e.
/// FakeQuant and those like it) to casts into/out of supported QuantizedTypes.
FunctionPassBase *createConvertSimulatedQuantPass();
std::unique_ptr<FunctionPassBase> createConvertSimulatedQuantPass();
/// Creates a pass that converts constants followed by a qbarrier to a
/// constant whose value is quantized. This is typically one of the last
/// passes done when lowering to express actual quantized arithmetic in a
/// low level representation. Because it modifies the constant, it is
/// destructive and cannot be undone.
FunctionPassBase *createConvertConstPass();
std::unique_ptr<FunctionPassBase> createConvertConstPass();
} // namespace quant
} // namespace mlir

View File

@ -27,7 +27,7 @@
namespace mlir {
namespace spirv {
ModulePassBase *createConvertStandardToSPIRVPass();
std::unique_ptr<ModulePassBase> createConvertStandardToSPIRVPass();
} // namespace spirv
} // namespace mlir

View File

@ -30,14 +30,16 @@ class FunctionPassBase;
class ModulePassBase;
namespace linalg {
FunctionPassBase *createLinalgFusionPass(ArrayRef<int64_t> tileSizes = {});
std::unique_ptr<FunctionPassBase>
createLinalgFusionPass(ArrayRef<int64_t> tileSizes = {});
FunctionPassBase *createLinalgTilingPass(ArrayRef<int64_t> tileSizes = {},
bool promoteViews = false);
std::unique_ptr<FunctionPassBase>
createLinalgTilingPass(ArrayRef<int64_t> tileSizes = {},
bool promoteViews = false);
FunctionPassBase *createLowerLinalgToLoopsPass();
std::unique_ptr<FunctionPassBase> createLowerLinalgToLoopsPass();
ModulePassBase *createLowerLinalgToLLVMPass();
std::unique_ptr<ModulePassBase> createLowerLinalgToLLVMPass();
} // namespace linalg
} // namespace mlir

View File

@ -104,7 +104,7 @@ protected:
virtual void runOnFunction() = 0;
/// A clone method to create a copy of this pass.
virtual FunctionPassBase *clone() const = 0;
virtual std::unique_ptr<FunctionPassBase> clone() const = 0;
/// Return the current function being transformed.
FuncOp getFunction() { return getPassState().irAndPassFailed.getPointer(); }
@ -259,8 +259,8 @@ struct FunctionPass : public detail::PassModel<FuncOp, T, FunctionPassBase> {
}
/// A clone method to create a copy of this pass.
FunctionPassBase *clone() const override {
return new T(*static_cast<const T *>(this));
std::unique_ptr<FunctionPassBase> clone() const override {
return llvm::make_unique<T>(*static_cast<const T *>(this));
}
};

View File

@ -71,16 +71,16 @@ public:
/// Add an opaque pass pointer to the current manager. This takes ownership
/// over the provided pass pointer.
void addPass(Pass *pass);
void addPass(std::unique_ptr<Pass> pass);
/// Add a module pass to the current manager. This takes ownership over the
/// provided pass pointer.
void addPass(ModulePassBase *pass);
void addPass(std::unique_ptr<ModulePassBase> pass);
/// Add a function pass to the current manager. This takes ownership over the
/// provided pass pointer. This will automatically create a function pass
/// executor if necessary.
void addPass(FunctionPassBase *pass);
void addPass(std::unique_ptr<FunctionPassBase> pass);
//===--------------------------------------------------------------------===//
// Instrumentations

View File

@ -29,6 +29,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include <functional>
#include <memory>
namespace mlir {
class Pass;
@ -37,7 +38,7 @@ class PassManager;
/// A registry function that adds passes to the given pass manager.
using PassRegistryFunction = std::function<void(PassManager &)>;
using PassAllocatorFunction = std::function<Pass *()>;
using PassAllocatorFunction = std::function<std::unique_ptr<Pass>()>;
/// A special type used by transformation passes to provide an address that can
/// act as a unique identifier during pass registration.
@ -120,7 +121,9 @@ template <typename ConcretePass> struct PassRegistration {
}
PassRegistration(StringRef arg, StringRef description) {
PassAllocatorFunction constructor = [] { return new ConcretePass(); };
PassAllocatorFunction constructor = [] {
return llvm::make_unique<ConcretePass>();
};
registerPass(arg, description, PassID::getID<ConcretePass>(), constructor);
}
};

View File

@ -33,17 +33,17 @@ class TargetConfiguration;
/// Creates a pass that infers quantized types based on metadata discovered
/// in the computation.
ModulePassBase *
std::unique_ptr<ModulePassBase>
createInferQuantizedTypesPass(SolverContext &solverContext,
const TargetConfiguration &config);
/// Creates a pass which removes any instrumentation and hint ops which have
/// no effect on final runtime.
FunctionPassBase *createRemoveInstrumentationPass();
std::unique_ptr<FunctionPassBase> createRemoveInstrumentationPass();
/// Adds default (dummy) statistics to ops that can benefit from runtime stats.
/// Meant for testing.
FunctionPassBase *createAddDefaultStatsPass();
std::unique_ptr<FunctionPassBase> createAddDefaultStatsPass();
} // namespace quantizer
} // namespace mlir

View File

@ -37,25 +37,25 @@ class ModulePassBase;
/// top-down constant folding functionality; it is intended to be used for
/// testing purpose. Use Canonicalizer pass, which exploits more simplification
/// opportunties exposed by constant folding, for the general cases.
FunctionPassBase *createTestConstantFoldPass();
std::unique_ptr<FunctionPassBase> createTestConstantFoldPass();
/// Creates an instance of the Canonicalizer pass.
FunctionPassBase *createCanonicalizerPass();
std::unique_ptr<FunctionPassBase> createCanonicalizerPass();
/// Creates a pass to perform common sub expression elimination.
FunctionPassBase *createCSEPass();
std::unique_ptr<FunctionPassBase> createCSEPass();
/// Creates a pass to vectorize loops, operations and data types using a
/// target-independent, n-D super-vector abstraction.
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
createVectorizePass(llvm::ArrayRef<int64_t> virtualVectorSize);
/// Creates a pass to allow independent testing of vectorizer functionality with
/// FileCheck.
FunctionPassBase *createVectorizerTestPass();
std::unique_ptr<FunctionPassBase> createVectorizerTestPass();
/// Creates a pass to lower super-vectors to target-dependent HW vectors.
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
createMaterializeVectorsPass(llvm::ArrayRef<int64_t> vectorSize);
/// Creates a loop unrolling pass with the provided parameters.
@ -64,71 +64,73 @@ createMaterializeVectorsPass(llvm::ArrayRef<int64_t> vectorSize);
/// factors supplied through other means. If -1 is passed as the unrollFactor
/// and no callback is provided, anything passed from the command-line (if at
/// all) or the default unroll factor is used (LoopUnroll:kDefaultUnrollFactor).
FunctionPassBase *createLoopUnrollPass(
std::unique_ptr<FunctionPassBase> createLoopUnrollPass(
int unrollFactor = -1, int unrollFull = -1,
const std::function<unsigned(AffineForOp)> &getUnrollFactor = nullptr);
/// Creates a loop unroll jam pass to unroll jam by the specified factor. A
/// factor of -1 lets the pass use the default factor or the one on the command
/// line if provided.
FunctionPassBase *createLoopUnrollAndJamPass(int unrollJamFactor = -1);
std::unique_ptr<FunctionPassBase>
createLoopUnrollAndJamPass(int unrollJamFactor = -1);
/// Creates an simplification pass for affine structures.
FunctionPassBase *createSimplifyAffineStructuresPass();
std::unique_ptr<FunctionPassBase> createSimplifyAffineStructuresPass();
/// Creates a loop fusion pass which fuses loops. Buffers of size less than or
/// equal to `localBufSizeThreshold` are promoted to memory space
/// `fastMemorySpace'.
FunctionPassBase *createLoopFusionPass(unsigned fastMemorySpace = 0,
uint64_t localBufSizeThreshold = 0,
bool maximalFusion = false);
std::unique_ptr<FunctionPassBase>
createLoopFusionPass(unsigned fastMemorySpace = 0,
uint64_t localBufSizeThreshold = 0,
bool maximalFusion = false);
/// Creates a loop invariant code motion pass that hoists loop invariant
/// instructions out of the loop.
FunctionPassBase *createLoopInvariantCodeMotionPass();
std::unique_ptr<FunctionPassBase> createLoopInvariantCodeMotionPass();
/// Creates a pass to pipeline explicit movement of data across levels of the
/// memory hierarchy.
FunctionPassBase *createPipelineDataTransferPass();
std::unique_ptr<FunctionPassBase> createPipelineDataTransferPass();
/// Lowers affine control flow operations (ForStmt, IfStmt and AffineApplyOp)
/// to equivalent lower-level constructs (flow of basic blocks and arithmetic
/// primitives).
FunctionPassBase *createLowerAffinePass();
std::unique_ptr<FunctionPassBase> createLowerAffinePass();
/// Creates a pass to perform tiling on loop nests.
FunctionPassBase *createLoopTilingPass(uint64_t cacheSizeBytes);
std::unique_ptr<FunctionPassBase> createLoopTilingPass(uint64_t cacheSizeBytes);
/// Creates a pass that performs parametric tiling so that the outermost loops
/// have the given fixed number of iterations. Assumes outermost loop nests
/// are permutable.
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
createSimpleParametricTilingPass(ArrayRef<int64_t> outerLoopSizes);
/// Creates a pass that transforms perfectly nested loops with independent
/// bounds into a single loop.
FunctionPassBase *createLoopCoalescingPass();
std::unique_ptr<FunctionPassBase> createLoopCoalescingPass();
/// Performs packing (or explicit copying) of accessed memref regions into
/// buffers in the specified faster memory space through either pointwise copies
/// or DMA operations.
FunctionPassBase *createAffineDataCopyGenerationPass(
std::unique_ptr<FunctionPassBase> createAffineDataCopyGenerationPass(
unsigned slowMemorySpace, unsigned fastMemorySpace,
unsigned tagMemorySpace = 0, int minDmaTransferSize = 1024,
uint64_t fastMemCapacityBytes = std::numeric_limits<uint64_t>::max());
/// Creates a pass to lower VectorTransferReadOp and VectorTransferWriteOp.
FunctionPassBase *createLowerVectorTransfersPass();
std::unique_ptr<FunctionPassBase> createLowerVectorTransfersPass();
/// Creates a pass to perform optimizations relying on memref dataflow such as
/// store to load forwarding, elimination of dead stores, and dead allocs.
FunctionPassBase *createMemRefDataFlowOptPass();
std::unique_ptr<FunctionPassBase> createMemRefDataFlowOptPass();
/// Creates a pass to strip debug information from a function.
FunctionPassBase *createStripDebugInfoPass();
std::unique_ptr<FunctionPassBase> createStripDebugInfoPass();
/// Creates a pass which tests loop fusion utilities.
FunctionPassBase *createTestLoopFusionPass();
std::unique_ptr<FunctionPassBase> createTestLoopFusionPass();
} // end namespace mlir

View File

@ -163,9 +163,9 @@ GpuKernelToCubinPass::translateGpuKernelToCubinAnnotation(FuncOp &function) {
return success();
}
ModulePassBase *
std::unique_ptr<ModulePassBase>
mlir::createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator) {
return new GpuKernelToCubinPass(cubinGenerator);
return llvm::make_unique<GpuKernelToCubinPass>(cubinGenerator);
}
static PassRegistration<GpuKernelToCubinPass>

View File

@ -382,8 +382,9 @@ void GpuLaunchFuncToCudaCallsPass::translateGpuLaunchCalls(
launchOp.erase();
}
mlir::ModulePassBase *mlir::createConvertGpuLaunchFuncToCudaCallsPass() {
return new GpuLaunchFuncToCudaCallsPass();
std::unique_ptr<mlir::ModulePassBase>
mlir::createConvertGpuLaunchFuncToCudaCallsPass() {
return llvm::make_unique<GpuLaunchFuncToCudaCallsPass>();
}
static PassRegistration<GpuLaunchFuncToCudaCallsPass>

View File

@ -141,8 +141,8 @@ private:
} // anonymous namespace
ModulePassBase *createGenerateCubinAccessorPass() {
return new GpuGenerateCubinAccessorsPass();
std::unique_ptr<ModulePassBase> createGenerateCubinAccessorPass() {
return llvm::make_unique<GpuGenerateCubinAccessorsPass>();
}
static PassRegistration<GpuGenerateCubinAccessorsPass>

View File

@ -128,8 +128,8 @@ public:
} // anonymous namespace
FunctionPassBase *createLowerGpuOpsToNVVMOpsPass() {
return new LowerGpuOpsToNVVMOpsPass();
std::unique_ptr<FunctionPassBase> createLowerGpuOpsToNVVMOpsPass() {
return llvm::make_unique<LowerGpuOpsToNVVMOpsPass>();
}
static PassRegistration<LowerGpuOpsToNVVMOpsPass>

View File

@ -66,13 +66,14 @@ struct ForLoopMapper : public FunctionPass<ForLoopMapper> {
};
} // namespace
FunctionPassBase *mlir::createSimpleLoopsToGPUPass(unsigned numBlockDims,
unsigned numThreadDims) {
return new ForLoopMapper(numBlockDims, numThreadDims);
std::unique_ptr<FunctionPassBase>
mlir::createSimpleLoopsToGPUPass(unsigned numBlockDims,
unsigned numThreadDims) {
return llvm::make_unique<ForLoopMapper>(numBlockDims, numThreadDims);
}
static PassRegistration<ForLoopMapper>
registration(PASS_NAME, "Convert top-level loops to GPU kernels", [] {
return new ForLoopMapper(clNumBlockDims.getValue(),
clNumThreadDims.getValue());
return llvm::make_unique<ForLoopMapper>(clNumBlockDims.getValue(),
clNumThreadDims.getValue());
});

View File

@ -1132,14 +1132,15 @@ struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
};
} // end namespace
ModulePassBase *mlir::createConvertToLLVMIRPass() {
return new LLVMLoweringPass;
std::unique_ptr<ModulePassBase> mlir::createConvertToLLVMIRPass() {
return llvm::make_unique<LLVMLoweringPass>();
}
ModulePassBase *
std::unique_ptr<ModulePassBase>
mlir::createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller,
LLVMTypeConverterMaker typeConverterMaker) {
return new LLVMLoweringPass(patternListFiller, typeConverterMaker);
return llvm::make_unique<LLVMLoweringPass>(patternListFiller,
typeConverterMaker);
}
static PassRegistration<LLVMLoweringPass>

View File

@ -48,8 +48,9 @@ void ConvertStandardToSPIRVPass::runOnModule() {
}
}
ModulePassBase *mlir::spirv::createConvertStandardToSPIRVPass() {
return new ConvertStandardToSPIRVPass();
std::unique_ptr<ModulePassBase>
mlir::spirv::createConvertStandardToSPIRVPass() {
return llvm::make_unique<ConvertStandardToSPIRVPass>();
}
static PassRegistration<ConvertStandardToSPIRVPass>

View File

@ -109,8 +109,8 @@ public:
} // namespace
ModulePassBase *mlir::createGpuKernelOutliningPass() {
return new GpuKernelOutliningPass();
std::unique_ptr<ModulePassBase> mlir::createGpuKernelOutliningPass() {
return llvm::make_unique<GpuKernelOutliningPass>();
}
static PassRegistration<GpuKernelOutliningPass>

View File

@ -112,8 +112,8 @@ void ConvertConstPass::runOnFunction() {
applyPatternsGreedily(func, patterns);
}
FunctionPassBase *mlir::quant::createConvertConstPass() {
return new ConvertConstPass();
std::unique_ptr<FunctionPassBase> mlir::quant::createConvertConstPass() {
return llvm::make_unique<ConvertConstPass>();
}
static PassRegistration<ConvertConstPass>

View File

@ -103,8 +103,9 @@ void ConvertSimulatedQuantPass::runOnFunction() {
signalPassFailure();
}
FunctionPassBase *mlir::quant::createConvertSimulatedQuantPass() {
return new ConvertSimulatedQuantPass();
std::unique_ptr<FunctionPassBase>
mlir::quant::createConvertSimulatedQuantPass() {
return llvm::make_unique<ConvertSimulatedQuantPass>();
}
static PassRegistration<ConvertSimulatedQuantPass>

View File

@ -350,14 +350,14 @@ LinalgFusionPass::LinalgFusionPass(ArrayRef<int64_t> sizes)
this->tileSizes.assign(sizes.begin(), sizes.end());
}
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
mlir::linalg::createLinalgFusionPass(ArrayRef<int64_t> tileSizes) {
return new LinalgFusionPass(tileSizes);
return llvm::make_unique<LinalgFusionPass>(tileSizes);
}
static PassRegistration<LinalgFusionPass>
pass("linalg-fusion", "Fuse operations in the linalg dialect", [] {
auto *pass = new LinalgFusionPass();
auto pass = llvm::make_unique<LinalgFusionPass>();
pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end());
return pass;
});

View File

@ -741,8 +741,8 @@ void LowerLinalgToLLVMPass::runOnModule() {
}
}
ModulePassBase *mlir::linalg::createLowerLinalgToLLVMPass() {
return new LowerLinalgToLLVMPass();
std::unique_ptr<ModulePassBase> mlir::linalg::createLowerLinalgToLLVMPass() {
return llvm::make_unique<LowerLinalgToLLVMPass>();
}
static PassRegistration<LowerLinalgToLLVMPass>

View File

@ -390,8 +390,8 @@ void LowerLinalgToLoopsPass::runOnFunction() {
}
}
FunctionPassBase *mlir::linalg::createLowerLinalgToLoopsPass() {
return new LowerLinalgToLoopsPass();
std::unique_ptr<FunctionPassBase> mlir::linalg::createLowerLinalgToLoopsPass() {
return llvm::make_unique<LowerLinalgToLoopsPass>();
}
static PassRegistration<LowerLinalgToLoopsPass>

View File

@ -527,15 +527,15 @@ LinalgTilingPass::LinalgTilingPass(ArrayRef<int64_t> sizes, bool promoteViews) {
this->promoteViews = promoteViews;
}
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
mlir::linalg::createLinalgTilingPass(ArrayRef<int64_t> tileSizes,
bool promoteViews) {
return new LinalgTilingPass(tileSizes, promoteViews);
return llvm::make_unique<LinalgTilingPass>(tileSizes, promoteViews);
}
static PassRegistration<LinalgTilingPass>
pass("linalg-tile", "Tile operations in the linalg dialect", [] {
auto *pass = new LinalgTilingPass();
auto pass = llvm::make_unique<LinalgTilingPass>();
pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end());
pass->promoteViews = clPromoteFullTileViews;
return pass;

View File

@ -264,44 +264,44 @@ void PassManager::disableMultithreading(bool disable) {
/// Add an opaque pass pointer to the current manager. This takes ownership
/// over the provided pass pointer.
void PassManager::addPass(Pass *pass) {
void PassManager::addPass(std::unique_ptr<Pass> pass) {
switch (pass->getKind()) {
case Pass::Kind::FunctionPass:
addPass(cast<FunctionPassBase>(pass));
addPass(cast<FunctionPassBase>(std::move(pass)));
break;
case Pass::Kind::ModulePass:
addPass(cast<ModulePassBase>(pass));
addPass(cast<ModulePassBase>(std::move(pass)));
break;
}
}
/// Add a module pass to the current manager. This takes ownership over the
/// provided pass pointer.
void PassManager::addPass(ModulePassBase *pass) {
void PassManager::addPass(std::unique_ptr<ModulePassBase> pass) {
nestedExecutorStack.clear();
mpe->addPass(pass);
mpe->addPass(std::move(pass));
// Add a verifier run if requested.
if (verifyPasses)
mpe->addPass(new ModuleVerifierPass());
mpe->addPass(llvm::make_unique<ModuleVerifierPass>());
}
/// Add a function pass to the current manager. This takes ownership over the
/// provided pass pointer. This will automatically create a function pass
/// executor if necessary.
void PassManager::addPass(FunctionPassBase *pass) {
void PassManager::addPass(std::unique_ptr<FunctionPassBase> pass) {
detail::FunctionPassExecutor *fpe;
if (nestedExecutorStack.empty()) {
/// Create an executor adaptor for this pass.
if (disableThreads || !llvm::llvm_is_multithreaded()) {
// If multi-threading is disabled, then create a synchronous adaptor.
auto *adaptor = new ModuleToFunctionPassAdaptor();
addPass(adaptor);
auto adaptor = llvm::make_unique<ModuleToFunctionPassAdaptor>();
fpe = &adaptor->getFunctionExecutor();
addPass(std::unique_ptr<ModulePassBase>{adaptor.release()});
} else {
auto *adaptor = new ModuleToFunctionPassAdaptorParallel();
addPass(adaptor);
auto adaptor = llvm::make_unique<ModuleToFunctionPassAdaptorParallel>();
fpe = &adaptor->getFunctionExecutor();
addPass(std::unique_ptr<ModulePassBase>{adaptor.release()});
}
/// Add the executor to the stack.
@ -309,11 +309,11 @@ void PassManager::addPass(FunctionPassBase *pass) {
} else {
fpe = cast<detail::FunctionPassExecutor>(nestedExecutorStack.back());
}
fpe->addPass(pass);
fpe->addPass(std::move(pass));
// Add a verifier run if requested.
if (verifyPasses)
fpe->addPass(new FunctionVerifierPass());
fpe->addPass(llvm::make_unique<FunctionVerifierPass>());
}
/// Add the provided instrumentation to the pass manager. This takes ownership

View File

@ -66,7 +66,9 @@ public:
/// Add a pass to the current executor. This takes ownership over the provided
/// pass pointer.
void addPass(FunctionPassBase *pass) { passes.emplace_back(pass); }
void addPass(std::unique_ptr<FunctionPassBase> pass) {
passes.push_back(std::move(pass));
}
/// Returns the number of passes held by this executor.
size_t size() const { return passes.size(); }
@ -94,7 +96,9 @@ public:
/// Add a pass to the current executor. This takes ownership over the provided
/// pass pointer.
void addPass(ModulePassBase *pass) { passes.emplace_back(pass); }
void addPass(std::unique_ptr<ModulePassBase> pass) {
passes.push_back(std::move(pass));
}
static bool classof(const PassExecutor *pe) {
return pe->getKind() == Kind::ModuleExecutor;

View File

@ -118,8 +118,8 @@ void AddDefaultStatsPass::runWithConfig(SolverContext &solverContext,
});
}
FunctionPassBase *mlir::quantizer::createAddDefaultStatsPass() {
return new AddDefaultStatsPass();
std::unique_ptr<FunctionPassBase> mlir::quantizer::createAddDefaultStatsPass() {
return llvm::make_unique<AddDefaultStatsPass>();
}
static PassRegistration<AddDefaultStatsPass> pass(

View File

@ -286,9 +286,9 @@ void InferQuantizedTypesPass::transformResultType(CAGResultAnchor *anchor,
}
}
ModulePassBase *mlir::quantizer::createInferQuantizedTypesPass(
std::unique_ptr<ModulePassBase> mlir::quantizer::createInferQuantizedTypesPass(
SolverContext &solverContext, const TargetConfiguration &config) {
return new InferQuantizedTypesPass(solverContext, config);
return llvm::make_unique<InferQuantizedTypesPass>(solverContext, config);
}
static PassRegistration<InferQuantizedTypesPass>

View File

@ -66,8 +66,9 @@ void RemoveInstrumentationPass::runOnFunction() {
applyPatternsGreedily(func, patterns);
}
FunctionPassBase *mlir::quantizer::createRemoveInstrumentationPass() {
return new RemoveInstrumentationPass();
std::unique_ptr<FunctionPassBase>
mlir::quantizer::createRemoveInstrumentationPass() {
return llvm::make_unique<RemoveInstrumentationPass>();
}
static PassRegistration<RemoveInstrumentationPass>

View File

@ -162,12 +162,12 @@ struct AffineDataCopyGeneration
/// buffers in 'fastMemorySpace', and replaces memory operations to the former
/// by the latter. Only load op's handled for now.
/// TODO(bondhugula): extend this to store op's.
FunctionPassBase *mlir::createAffineDataCopyGenerationPass(
std::unique_ptr<FunctionPassBase> mlir::createAffineDataCopyGenerationPass(
unsigned slowMemorySpace, unsigned fastMemorySpace, unsigned tagMemorySpace,
int minDmaTransferSize, uint64_t fastMemCapacityBytes) {
return new AffineDataCopyGeneration(slowMemorySpace, fastMemorySpace,
tagMemorySpace, minDmaTransferSize,
fastMemCapacityBytes);
return llvm::make_unique<AffineDataCopyGeneration>(
slowMemorySpace, fastMemorySpace, tagMemorySpace, minDmaTransferSize,
fastMemCapacityBytes);
}
// Info comprising stride and number of elements transferred every stride.

View File

@ -258,7 +258,9 @@ void CSE::runOnFunction() {
markAnalysesPreserved<DominanceInfo, PostDominanceInfo>();
}
FunctionPassBase *mlir::createCSEPass() { return new CSE(); }
std::unique_ptr<FunctionPassBase> mlir::createCSEPass() {
return llvm::make_unique<CSE>();
}
static PassRegistration<CSE>
pass("cse", "Eliminate common sub-expressions in functions");

View File

@ -53,8 +53,8 @@ void Canonicalizer::runOnFunction() {
}
/// Create a Canonicalizer pass.
FunctionPassBase *mlir::createCanonicalizerPass() {
return new Canonicalizer();
std::unique_ptr<FunctionPassBase> mlir::createCanonicalizerPass() {
return llvm::make_unique<Canonicalizer>();
}
static PassRegistration<Canonicalizer> pass("canonicalize",

View File

@ -96,8 +96,8 @@ public:
} // namespace
FunctionPassBase *mlir::createLoopCoalescingPass() {
return new LoopCoalescingPass;
std::unique_ptr<FunctionPassBase> mlir::createLoopCoalescingPass() {
return llvm::make_unique<LoopCoalescingPass>();
}
static PassRegistration<LoopCoalescingPass>

View File

@ -111,10 +111,11 @@ struct LoopFusion : public FunctionPass<LoopFusion> {
} // end anonymous namespace
FunctionPassBase *mlir::createLoopFusionPass(unsigned fastMemorySpace,
uint64_t localBufSizeThreshold,
bool maximalFusion) {
return new LoopFusion(fastMemorySpace, localBufSizeThreshold, maximalFusion);
std::unique_ptr<FunctionPassBase>
mlir::createLoopFusionPass(unsigned fastMemorySpace,
uint64_t localBufSizeThreshold, bool maximalFusion) {
return llvm::make_unique<LoopFusion>(fastMemorySpace, localBufSizeThreshold,
maximalFusion);
}
namespace {

View File

@ -76,8 +76,8 @@ static bool isMemRefDereferencingOp(Operation &op) {
return false;
}
FunctionPassBase *mlir::createLoopInvariantCodeMotionPass() {
return new LoopInvariantCodeMotion();
std::unique_ptr<FunctionPassBase> mlir::createLoopInvariantCodeMotionPass() {
return llvm::make_unique<LoopInvariantCodeMotion>();
}
// Returns true if the individual op is loop invariant.

View File

@ -81,8 +81,9 @@ struct LoopTiling : public FunctionPass<LoopTiling> {
/// Creates a pass to perform loop tiling on all suitable loop nests of a
/// Function.
FunctionPassBase *mlir::createLoopTilingPass(uint64_t cacheSizeBytes) {
return new LoopTiling(cacheSizeBytes);
std::unique_ptr<FunctionPassBase>
mlir::createLoopTilingPass(uint64_t cacheSizeBytes) {
return llvm::make_unique<LoopTiling>(cacheSizeBytes);
}
// Move the loop body of AffineForOp 'src' from 'src' into the specified

View File

@ -180,10 +180,10 @@ LogicalResult LoopUnroll::runOnAffineForOp(AffineForOp forOp) {
return loopUnrollByFactor(forOp, kDefaultUnrollFactor);
}
FunctionPassBase *mlir::createLoopUnrollPass(
std::unique_ptr<FunctionPassBase> mlir::createLoopUnrollPass(
int unrollFactor, int unrollFull,
const std::function<unsigned(AffineForOp)> &getUnrollFactor) {
return new LoopUnroll(
return llvm::make_unique<LoopUnroll>(
unrollFactor == -1 ? None : Optional<unsigned>(unrollFactor),
unrollFull == -1 ? None : Optional<bool>(unrollFull), getUnrollFactor);
}

View File

@ -82,8 +82,9 @@ struct LoopUnrollAndJam : public FunctionPass<LoopUnrollAndJam> {
};
} // end anonymous namespace
FunctionPassBase *mlir::createLoopUnrollAndJamPass(int unrollJamFactor) {
return new LoopUnrollAndJam(
std::unique_ptr<FunctionPassBase>
mlir::createLoopUnrollAndJamPass(int unrollJamFactor) {
return llvm::make_unique<LoopUnrollAndJam>(
unrollJamFactor == -1 ? None : Optional<unsigned>(unrollJamFactor));
}

View File

@ -529,8 +529,8 @@ class LowerAffinePass : public FunctionPass<LowerAffinePass> {
/// Lowers If and For operations within a function into their lower level CFG
/// equivalent blocks.
FunctionPassBase *mlir::createLowerAffinePass() {
return new LowerAffinePass();
std::unique_ptr<FunctionPassBase> mlir::createLowerAffinePass() {
return llvm::make_unique<LowerAffinePass>();
}
static PassRegistration<LowerAffinePass>

View File

@ -373,8 +373,8 @@ struct LowerVectorTransfersPass
} // end anonymous namespace
FunctionPassBase *mlir::createLowerVectorTransfersPass() {
return new LowerVectorTransfersPass();
std::unique_ptr<FunctionPassBase> mlir::createLowerVectorTransfersPass() {
return llvm::make_unique<LowerVectorTransfersPass>();
}
static PassRegistration<LowerVectorTransfersPass>

View File

@ -766,9 +766,9 @@ void MaterializeVectorsPass::runOnFunction() {
signalPassFailure();
}
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
mlir::createMaterializeVectorsPass(llvm::ArrayRef<int64_t> vectorSize) {
return new MaterializeVectorsPass(vectorSize);
return llvm::make_unique<MaterializeVectorsPass>(vectorSize);
}
static PassRegistration<MaterializeVectorsPass>

View File

@ -88,8 +88,8 @@ struct MemRefDataFlowOpt : public FunctionPass<MemRefDataFlowOpt> {
/// Creates a pass to perform optimizations relying on memref dataflow such as
/// store to load forwarding, elimination of dead stores, and dead allocs.
FunctionPassBase *mlir::createMemRefDataFlowOptPass() {
return new MemRefDataFlowOpt();
std::unique_ptr<FunctionPassBase> mlir::createMemRefDataFlowOptPass() {
return llvm::make_unique<MemRefDataFlowOpt>();
}
// This is a straightforward implementation not optimized for speed. Optimize

View File

@ -49,8 +49,8 @@ struct PipelineDataTransfer : public FunctionPass<PipelineDataTransfer> {
/// Creates a pass to pipeline explicit movement of data across levels of the
/// memory hierarchy.
FunctionPassBase *mlir::createPipelineDataTransferPass() {
return new PipelineDataTransfer();
std::unique_ptr<FunctionPassBase> mlir::createPipelineDataTransferPass() {
return llvm::make_unique<PipelineDataTransfer>();
}
// Returns the position of the tag memref operand given a DMA operation.

View File

@ -88,8 +88,8 @@ struct SimplifyAffineStructures
} // end anonymous namespace
FunctionPassBase *mlir::createSimplifyAffineStructuresPass() {
return new SimplifyAffineStructures();
std::unique_ptr<FunctionPassBase> mlir::createSimplifyAffineStructuresPass() {
return llvm::make_unique<SimplifyAffineStructures>();
}
void SimplifyAffineStructures::runOnFunction() {

View File

@ -38,8 +38,8 @@ void StripDebugInfo::runOnFunction() {
}
/// Creates a pass to strip debug information from a function.
FunctionPassBase *mlir::createStripDebugInfoPass() {
return new StripDebugInfo();
std::unique_ptr<FunctionPassBase> mlir::createStripDebugInfoPass() {
return llvm::make_unique<StripDebugInfo>();
}
static PassRegistration<StripDebugInfo>

View File

@ -1276,9 +1276,9 @@ void Vectorize::runOnFunction() {
LLVM_DEBUG(dbgs() << "\n");
}
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
mlir::createVectorizePass(llvm::ArrayRef<int64_t> virtualVectorSize) {
return new Vectorize(virtualVectorSize);
return llvm::make_unique<Vectorize>(virtualVectorSize);
}
static PassRegistration<Vectorize>

View File

@ -247,6 +247,9 @@ static llvm::cl::opt<TestLegalizePatternDriver::ConversionMode>
clEnumValN(TestLegalizePatternDriver::ConversionMode::Partial,
"partial", "Perform a partial conversion")));
static mlir::PassRegistration<TestLegalizePatternDriver> legalizer_pass(
"test-legalize-patterns", "Run test dialect legalization patterns",
[] { return new TestLegalizePatternDriver(legalizerConversionMode); });
static mlir::PassRegistration<TestLegalizePatternDriver>
legalizer_pass("test-legalize-patterns",
"Run test dialect legalization patterns", [] {
return llvm::make_unique<TestLegalizePatternDriver>(
legalizerConversionMode);
});

View File

@ -74,8 +74,8 @@ void TestConstantFold::runOnFunction() {
}
/// Creates a constant folding pass.
FunctionPassBase *mlir::createTestConstantFoldPass() {
return new TestConstantFold();
std::unique_ptr<FunctionPassBase> mlir::createTestConstantFoldPass() {
return llvm::make_unique<TestConstantFold>();
}
static PassRegistration<TestConstantFold>

View File

@ -58,8 +58,8 @@ struct TestLoopFusion : public FunctionPass<TestLoopFusion> {
} // end anonymous namespace
FunctionPassBase *mlir::createTestLoopFusionPass() {
return new TestLoopFusion;
std::unique_ptr<FunctionPassBase> mlir::createTestLoopFusionPass() {
return llvm::make_unique<TestLoopFusion>();
}
// Gathers all AffineForOps in 'block' at 'currLoopDepth' in 'depthToLoops'.

View File

@ -62,4 +62,4 @@ public:
static PassRegistration<TestLoopMappingPass>
reg("test-mapping-to-processing-elements",
"test mapping a single loop on a virtual processor grid",
[] { return new TestLoopMappingPass(); });
[] { return llvm::make_unique<TestLoopMappingPass>(); });

View File

@ -55,9 +55,9 @@ public:
};
} // end namespace
FunctionPassBase *
std::unique_ptr<FunctionPassBase>
mlir::createSimpleParametricTilingPass(ArrayRef<int64_t> outerLoopSizes) {
return new SimpleParametricLoopTilingPass(outerLoopSizes);
return llvm::make_unique<SimpleParametricLoopTilingPass>(outerLoopSizes);
}
static PassRegistration<SimpleParametricLoopTilingPass>
@ -65,7 +65,8 @@ static PassRegistration<SimpleParametricLoopTilingPass>
"test application of parametric tiling to the outer loops so that the "
"ranges of outer loops become static",
[] {
auto *pass = new SimpleParametricLoopTilingPass({});
auto pass = llvm::make_unique<SimpleParametricLoopTilingPass>(
ArrayRef<int64_t>{});
pass->sizes.assign(clOuterLoopSizes.begin(), clOuterLoopSizes.end());
return pass;
});

View File

@ -290,8 +290,8 @@ void VectorizerTestPass::runOnFunction() {
}
}
FunctionPassBase *mlir::createVectorizerTestPass() {
return new VectorizerTestPass();
std::unique_ptr<FunctionPassBase> mlir::createVectorizerTestPass() {
return llvm::make_unique<VectorizerTestPass>();
}
static PassRegistration<VectorizerTestPass>