diff --git a/mlir/examples/Linalg/Linalg3/include/linalg3/Transforms.h b/mlir/examples/Linalg/Linalg3/include/linalg3/Transforms.h index 4346b47cf493..123d6afba088 100644 --- a/mlir/examples/Linalg/Linalg3/include/linalg3/Transforms.h +++ b/mlir/examples/Linalg/Linalg3/include/linalg3/Transforms.h @@ -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 createLowerLinalgLoadStorePass(); } // namespace linalg diff --git a/mlir/examples/Linalg/Linalg3/lib/Transforms.cpp b/mlir/examples/Linalg/Linalg3/lib/Transforms.cpp index 7fc4bb5c897e..79fa4ca34f20 100644 --- a/mlir/examples/Linalg/Linalg3/lib/Transforms.cpp +++ b/mlir/examples/Linalg/Linalg3/lib/Transforms.cpp @@ -300,6 +300,6 @@ Rewriter::matchAndRewrite(linalg::StoreOp store, } } // namespace -FunctionPassBase *linalg::createLowerLinalgLoadStorePass() { - return new LowerLinalgLoadStorePass(); +std::unique_ptr linalg::createLowerLinalgLoadStorePass() { + return llvm::make_unique(); } diff --git a/mlir/examples/toy/Ch4/include/toy/Passes.h b/mlir/examples/toy/Ch4/include/toy/Passes.h index dd73b95f9c20..93cf0d5ba155 100644 --- a/mlir/examples/toy/Ch4/include/toy/Passes.h +++ b/mlir/examples/toy/Ch4/include/toy/Passes.h @@ -22,12 +22,14 @@ #ifndef MLIR_TUTORIAL_TOY_PASSES_H #define MLIR_TUTORIAL_TOY_PASSES_H +#include + namespace mlir { class Pass; } // namespace mlir namespace toy { -mlir::Pass *createShapeInferencePass(); +std::unique_ptr createShapeInferencePass(); } // namespace toy #endif // MLIR_TUTORIAL_TOY_PASSES_H diff --git a/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp b/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp index 5c258f1ef5b8..4a6bf8790e02 100644 --- a/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp +++ b/mlir/examples/toy/Ch4/mlir/ShapeInferencePass.cpp @@ -375,5 +375,7 @@ public: } // end anonymous namespace namespace toy { -mlir::Pass *createShapeInferencePass() { return new ShapeInferencePass(); } +std::unique_ptr createShapeInferencePass() { + return llvm::make_unique(); +} } // namespace toy diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp index a273c9301ce6..9e7a8a39e0a6 100644 --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -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" diff --git a/mlir/examples/toy/Ch5/include/toy/Lowering.h b/mlir/examples/toy/Ch5/include/toy/Lowering.h index 362a34283464..4788ea3fbebe 100644 --- a/mlir/examples/toy/Ch5/include/toy/Lowering.h +++ b/mlir/examples/toy/Ch5/include/toy/Lowering.h @@ -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 createEarlyLoweringPass(); /// Create a pass for the late lowering toward LLVM dialect. -mlir::Pass *createLateLoweringPass(); +std::unique_ptr createLateLoweringPass(); } // namespace toy diff --git a/mlir/examples/toy/Ch5/include/toy/Passes.h b/mlir/examples/toy/Ch5/include/toy/Passes.h index dd73b95f9c20..93cf0d5ba155 100644 --- a/mlir/examples/toy/Ch5/include/toy/Passes.h +++ b/mlir/examples/toy/Ch5/include/toy/Passes.h @@ -22,12 +22,14 @@ #ifndef MLIR_TUTORIAL_TOY_PASSES_H #define MLIR_TUTORIAL_TOY_PASSES_H +#include + namespace mlir { class Pass; } // namespace mlir namespace toy { -mlir::Pass *createShapeInferencePass(); +std::unique_ptr createShapeInferencePass(); } // namespace toy #endif // MLIR_TUTORIAL_TOY_PASSES_H diff --git a/mlir/examples/toy/Ch5/mlir/EarlyLowering.cpp b/mlir/examples/toy/Ch5/mlir/EarlyLowering.cpp index 015a3fd64c28..96230fdfbea9 100644 --- a/mlir/examples/toy/Ch5/mlir/EarlyLowering.cpp +++ b/mlir/examples/toy/Ch5/mlir/EarlyLowering.cpp @@ -142,5 +142,7 @@ struct EarlyLoweringPass : public FunctionPass { } // end anonymous namespace namespace toy { -Pass *createEarlyLoweringPass() { return new EarlyLoweringPass(); } +std::unique_ptr createEarlyLoweringPass() { + return llvm::make_unique(); +} } // namespace toy diff --git a/mlir/examples/toy/Ch5/mlir/LateLowering.cpp b/mlir/examples/toy/Ch5/mlir/LateLowering.cpp index 3b6bfc9df5db..6135e275a758 100644 --- a/mlir/examples/toy/Ch5/mlir/LateLowering.cpp +++ b/mlir/examples/toy/Ch5/mlir/LateLowering.cpp @@ -458,5 +458,7 @@ struct LateLoweringPass : public ModulePass { } // end anonymous namespace namespace toy { -Pass *createLateLoweringPass() { return new LateLoweringPass(); } +std::unique_ptr createLateLoweringPass() { + return llvm::make_unique(); +} } // namespace toy diff --git a/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp b/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp index cef2939788c7..6437c0b3f730 100644 --- a/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp +++ b/mlir/examples/toy/Ch5/mlir/ShapeInferencePass.cpp @@ -375,5 +375,7 @@ public: } // end anonymous namespace namespace toy { -mlir::Pass *createShapeInferencePass() { return new ShapeInferencePass(); } +std::unique_ptr createShapeInferencePass() { + return llvm::make_unique(); +} } // namespace toy diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp index 1d80c3c018d3..a21eda74d826 100644 --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -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" diff --git a/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h b/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h index b19fb53e3e27..bd1a3fea0ff5 100644 --- a/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h +++ b/mlir/include/mlir/Conversion/GPUToCUDA/GPUToCUDAPass.h @@ -39,7 +39,7 @@ using CubinGenerator = std::function; /// 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 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 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 createGenerateCubinAccessorPass(); } // namespace mlir #endif // MLIR_CONVERSION_GPUTOCUDA_GPUTOCUDAPASS_H_ diff --git a/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h b/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h index b53549fb2756..f1c8601795c1 100644 --- a/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h +++ b/mlir/include/mlir/Conversion/GPUToNVVM/GPUToNVVMPass.h @@ -17,11 +17,13 @@ #ifndef MLIR_CONVERSION_GPUTONVVM_GPUTONVVMPASS_H_ #define MLIR_CONVERSION_GPUTONVVM_GPUTONVVMPASS_H_ +#include + namespace mlir { struct FunctionPassBase; /// Creates a pass that lowers GPU dialect operations to NVVM counterparts. -FunctionPassBase *createLowerGpuOpsToNVVMOpsPass(); +std::unique_ptr createLowerGpuOpsToNVVMOpsPass(); } // namespace mlir diff --git a/mlir/include/mlir/Conversion/LoopsToGPU/LoopsToGPUPass.h b/mlir/include/mlir/Conversion/LoopsToGPU/LoopsToGPUPass.h index 52f0dd4babb1..3d32c36c43c0 100644 --- a/mlir/include/mlir/Conversion/LoopsToGPU/LoopsToGPUPass.h +++ b/mlir/include/mlir/Conversion/LoopsToGPU/LoopsToGPUPass.h @@ -17,6 +17,8 @@ #ifndef MLIR_CONVERSION_LOOPSTOGPU_LOOPSTOGPUPASS_H_ #define MLIR_CONVERSION_LOOPSTOGPU_LOOPSTOGPUPASS_H_ +#include + 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 +createSimpleLoopsToGPUPass(unsigned numBlockDims, unsigned numThreadDims); } // namespace mlir #endif // MLIR_CONVERSION_LOOPSTOGPU_LOOPSTOGPUPASS_H_ diff --git a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h index 941e382905f4..a08b2fb45d6b 100644 --- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h +++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h @@ -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 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 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 -ModulePassBase * +std::unique_ptr createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller) { return createConvertToLLVMIRPass(patternListFiller, [](MLIRContext *context) { return llvm::make_unique(context); diff --git a/mlir/include/mlir/Dialect/GPU/Passes.h b/mlir/include/mlir/Dialect/GPU/Passes.h index f9b569d50af6..d562b5835c7a 100644 --- a/mlir/include/mlir/Dialect/GPU/Passes.h +++ b/mlir/include/mlir/Dialect/GPU/Passes.h @@ -22,11 +22,13 @@ #ifndef MLIR_DIALECT_GPU_PASSES_H_ #define MLIR_DIALECT_GPU_PASSES_H_ +#include + namespace mlir { class ModulePassBase; -ModulePassBase *createGpuKernelOutliningPass(); +std::unique_ptr createGpuKernelOutliningPass(); } // namespace mlir diff --git a/mlir/include/mlir/Dialect/QuantOps/Passes.h b/mlir/include/mlir/Dialect/QuantOps/Passes.h index 6b647a87f4a4..1d43f7087db1 100644 --- a/mlir/include/mlir/Dialect/QuantOps/Passes.h +++ b/mlir/include/mlir/Dialect/QuantOps/Passes.h @@ -25,6 +25,8 @@ #ifndef MLIR_DIALECT_QUANTOPS_PASSES_H #define MLIR_DIALECT_QUANTOPS_PASSES_H +#include + 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 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 createConvertConstPass(); } // namespace quant } // namespace mlir diff --git a/mlir/include/mlir/Dialect/SPIRV/Passes.h b/mlir/include/mlir/Dialect/SPIRV/Passes.h index e896da7ae8af..85f4f79ed59e 100644 --- a/mlir/include/mlir/Dialect/SPIRV/Passes.h +++ b/mlir/include/mlir/Dialect/SPIRV/Passes.h @@ -27,7 +27,7 @@ namespace mlir { namespace spirv { -ModulePassBase *createConvertStandardToSPIRVPass(); +std::unique_ptr createConvertStandardToSPIRVPass(); } // namespace spirv } // namespace mlir diff --git a/mlir/include/mlir/Linalg/Passes.h b/mlir/include/mlir/Linalg/Passes.h index 029414920595..57dd09cfc63b 100644 --- a/mlir/include/mlir/Linalg/Passes.h +++ b/mlir/include/mlir/Linalg/Passes.h @@ -30,14 +30,16 @@ class FunctionPassBase; class ModulePassBase; namespace linalg { -FunctionPassBase *createLinalgFusionPass(ArrayRef tileSizes = {}); +std::unique_ptr +createLinalgFusionPass(ArrayRef tileSizes = {}); -FunctionPassBase *createLinalgTilingPass(ArrayRef tileSizes = {}, - bool promoteViews = false); +std::unique_ptr +createLinalgTilingPass(ArrayRef tileSizes = {}, + bool promoteViews = false); -FunctionPassBase *createLowerLinalgToLoopsPass(); +std::unique_ptr createLowerLinalgToLoopsPass(); -ModulePassBase *createLowerLinalgToLLVMPass(); +std::unique_ptr createLowerLinalgToLLVMPass(); } // namespace linalg } // namespace mlir diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index b1531a357e5b..f5c8d8bd1a63 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -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 clone() const = 0; /// Return the current function being transformed. FuncOp getFunction() { return getPassState().irAndPassFailed.getPointer(); } @@ -259,8 +259,8 @@ struct FunctionPass : public detail::PassModel { } /// A clone method to create a copy of this pass. - FunctionPassBase *clone() const override { - return new T(*static_cast(this)); + std::unique_ptr clone() const override { + return llvm::make_unique(*static_cast(this)); } }; diff --git a/mlir/include/mlir/Pass/PassManager.h b/mlir/include/mlir/Pass/PassManager.h index 68dfeb099bc9..b01445eae4cb 100644 --- a/mlir/include/mlir/Pass/PassManager.h +++ b/mlir/include/mlir/Pass/PassManager.h @@ -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); /// 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 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 pass); //===--------------------------------------------------------------------===// // Instrumentations diff --git a/mlir/include/mlir/Pass/PassRegistry.h b/mlir/include/mlir/Pass/PassRegistry.h index ea0fbbe39dbd..bd108f3e77f8 100644 --- a/mlir/include/mlir/Pass/PassRegistry.h +++ b/mlir/include/mlir/Pass/PassRegistry.h @@ -29,6 +29,7 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include +#include 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; -using PassAllocatorFunction = std::function; +using PassAllocatorFunction = std::function()>; /// 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 struct PassRegistration { } PassRegistration(StringRef arg, StringRef description) { - PassAllocatorFunction constructor = [] { return new ConcretePass(); }; + PassAllocatorFunction constructor = [] { + return llvm::make_unique(); + }; registerPass(arg, description, PassID::getID(), constructor); } }; diff --git a/mlir/include/mlir/Quantizer/Transforms/Passes.h b/mlir/include/mlir/Quantizer/Transforms/Passes.h index 0d7b4cb55b3d..f894ea801e07 100644 --- a/mlir/include/mlir/Quantizer/Transforms/Passes.h +++ b/mlir/include/mlir/Quantizer/Transforms/Passes.h @@ -33,17 +33,17 @@ class TargetConfiguration; /// Creates a pass that infers quantized types based on metadata discovered /// in the computation. -ModulePassBase * +std::unique_ptr 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 createRemoveInstrumentationPass(); /// Adds default (dummy) statistics to ops that can benefit from runtime stats. /// Meant for testing. -FunctionPassBase *createAddDefaultStatsPass(); +std::unique_ptr createAddDefaultStatsPass(); } // namespace quantizer } // namespace mlir diff --git a/mlir/include/mlir/Transforms/Passes.h b/mlir/include/mlir/Transforms/Passes.h index ee36517cea79..693c7b0ae00b 100644 --- a/mlir/include/mlir/Transforms/Passes.h +++ b/mlir/include/mlir/Transforms/Passes.h @@ -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 createTestConstantFoldPass(); /// Creates an instance of the Canonicalizer pass. -FunctionPassBase *createCanonicalizerPass(); +std::unique_ptr createCanonicalizerPass(); /// Creates a pass to perform common sub expression elimination. -FunctionPassBase *createCSEPass(); +std::unique_ptr createCSEPass(); /// Creates a pass to vectorize loops, operations and data types using a /// target-independent, n-D super-vector abstraction. -FunctionPassBase * +std::unique_ptr createVectorizePass(llvm::ArrayRef virtualVectorSize); /// Creates a pass to allow independent testing of vectorizer functionality with /// FileCheck. -FunctionPassBase *createVectorizerTestPass(); +std::unique_ptr createVectorizerTestPass(); /// Creates a pass to lower super-vectors to target-dependent HW vectors. -FunctionPassBase * +std::unique_ptr createMaterializeVectorsPass(llvm::ArrayRef vectorSize); /// Creates a loop unrolling pass with the provided parameters. @@ -64,71 +64,73 @@ createMaterializeVectorsPass(llvm::ArrayRef 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 createLoopUnrollPass( int unrollFactor = -1, int unrollFull = -1, const std::function &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 +createLoopUnrollAndJamPass(int unrollJamFactor = -1); /// Creates an simplification pass for affine structures. -FunctionPassBase *createSimplifyAffineStructuresPass(); +std::unique_ptr 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 +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 createLoopInvariantCodeMotionPass(); /// Creates a pass to pipeline explicit movement of data across levels of the /// memory hierarchy. -FunctionPassBase *createPipelineDataTransferPass(); +std::unique_ptr 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 createLowerAffinePass(); /// Creates a pass to perform tiling on loop nests. -FunctionPassBase *createLoopTilingPass(uint64_t cacheSizeBytes); +std::unique_ptr 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 createSimpleParametricTilingPass(ArrayRef outerLoopSizes); /// Creates a pass that transforms perfectly nested loops with independent /// bounds into a single loop. -FunctionPassBase *createLoopCoalescingPass(); +std::unique_ptr 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 createAffineDataCopyGenerationPass( unsigned slowMemorySpace, unsigned fastMemorySpace, unsigned tagMemorySpace = 0, int minDmaTransferSize = 1024, uint64_t fastMemCapacityBytes = std::numeric_limits::max()); /// Creates a pass to lower VectorTransferReadOp and VectorTransferWriteOp. -FunctionPassBase *createLowerVectorTransfersPass(); +std::unique_ptr 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 createMemRefDataFlowOptPass(); /// Creates a pass to strip debug information from a function. -FunctionPassBase *createStripDebugInfoPass(); +std::unique_ptr createStripDebugInfoPass(); /// Creates a pass which tests loop fusion utilities. -FunctionPassBase *createTestLoopFusionPass(); +std::unique_ptr createTestLoopFusionPass(); } // end namespace mlir diff --git a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp index 766377528a1f..0223dee9ede7 100644 --- a/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp +++ b/mlir/lib/Conversion/GPUToCUDA/ConvertKernelFuncToCubin.cpp @@ -163,9 +163,9 @@ GpuKernelToCubinPass::translateGpuKernelToCubinAnnotation(FuncOp &function) { return success(); } -ModulePassBase * +std::unique_ptr mlir::createConvertGPUKernelToCubinPass(CubinGenerator cubinGenerator) { - return new GpuKernelToCubinPass(cubinGenerator); + return llvm::make_unique(cubinGenerator); } static PassRegistration diff --git a/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp b/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp index bf7577856db9..bf0816c8b713 100644 --- a/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp +++ b/mlir/lib/Conversion/GPUToCUDA/ConvertLaunchFuncToCudaCalls.cpp @@ -382,8 +382,9 @@ void GpuLaunchFuncToCudaCallsPass::translateGpuLaunchCalls( launchOp.erase(); } -mlir::ModulePassBase *mlir::createConvertGpuLaunchFuncToCudaCallsPass() { - return new GpuLaunchFuncToCudaCallsPass(); +std::unique_ptr +mlir::createConvertGpuLaunchFuncToCudaCallsPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Conversion/GPUToCUDA/GenerateCubinAccessors.cpp b/mlir/lib/Conversion/GPUToCUDA/GenerateCubinAccessors.cpp index 813a3bee0adb..fa481632e29c 100644 --- a/mlir/lib/Conversion/GPUToCUDA/GenerateCubinAccessors.cpp +++ b/mlir/lib/Conversion/GPUToCUDA/GenerateCubinAccessors.cpp @@ -141,8 +141,8 @@ private: } // anonymous namespace -ModulePassBase *createGenerateCubinAccessorPass() { - return new GpuGenerateCubinAccessorsPass(); +std::unique_ptr createGenerateCubinAccessorPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp index e4a6f964f500..91671489f2d1 100644 --- a/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp +++ b/mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp @@ -128,8 +128,8 @@ public: } // anonymous namespace -FunctionPassBase *createLowerGpuOpsToNVVMOpsPass() { - return new LowerGpuOpsToNVVMOpsPass(); +std::unique_ptr createLowerGpuOpsToNVVMOpsPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Conversion/LoopsToGPU/LoopsToGPUPass.cpp b/mlir/lib/Conversion/LoopsToGPU/LoopsToGPUPass.cpp index 7c785b5c9953..36869b87f1ab 100644 --- a/mlir/lib/Conversion/LoopsToGPU/LoopsToGPUPass.cpp +++ b/mlir/lib/Conversion/LoopsToGPU/LoopsToGPUPass.cpp @@ -66,13 +66,14 @@ struct ForLoopMapper : public FunctionPass { }; } // namespace -FunctionPassBase *mlir::createSimpleLoopsToGPUPass(unsigned numBlockDims, - unsigned numThreadDims) { - return new ForLoopMapper(numBlockDims, numThreadDims); +std::unique_ptr +mlir::createSimpleLoopsToGPUPass(unsigned numBlockDims, + unsigned numThreadDims) { + return llvm::make_unique(numBlockDims, numThreadDims); } static PassRegistration registration(PASS_NAME, "Convert top-level loops to GPU kernels", [] { - return new ForLoopMapper(clNumBlockDims.getValue(), - clNumThreadDims.getValue()); + return llvm::make_unique(clNumBlockDims.getValue(), + clNumThreadDims.getValue()); }); diff --git a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp index c62a5d8719d3..731c07e22c36 100644 --- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp @@ -1132,14 +1132,15 @@ struct LLVMLoweringPass : public ModulePass { }; } // end namespace -ModulePassBase *mlir::createConvertToLLVMIRPass() { - return new LLVMLoweringPass; +std::unique_ptr mlir::createConvertToLLVMIRPass() { + return llvm::make_unique(); } -ModulePassBase * +std::unique_ptr mlir::createConvertToLLVMIRPass(LLVMPatternListFiller patternListFiller, LLVMTypeConverterMaker typeConverterMaker) { - return new LLVMLoweringPass(patternListFiller, typeConverterMaker); + return llvm::make_unique(patternListFiller, + typeConverterMaker); } static PassRegistration diff --git a/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp b/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp index ad2c4b57fb41..3d4ef639cfa5 100644 --- a/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp +++ b/mlir/lib/Conversion/StandardToSPIRV/ConvertStandardToSPIRVPass.cpp @@ -48,8 +48,9 @@ void ConvertStandardToSPIRVPass::runOnModule() { } } -ModulePassBase *mlir::spirv::createConvertStandardToSPIRVPass() { - return new ConvertStandardToSPIRVPass(); +std::unique_ptr +mlir::spirv::createConvertStandardToSPIRVPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp index 01decce28ac7..b7be427be1b3 100644 --- a/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp +++ b/mlir/lib/Dialect/GPU/Transforms/KernelOutlining.cpp @@ -109,8 +109,8 @@ public: } // namespace -ModulePassBase *mlir::createGpuKernelOutliningPass() { - return new GpuKernelOutliningPass(); +std::unique_ptr mlir::createGpuKernelOutliningPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Dialect/QuantOps/Transforms/ConvertConst.cpp b/mlir/lib/Dialect/QuantOps/Transforms/ConvertConst.cpp index 120d0cf0e569..9c48c672300d 100644 --- a/mlir/lib/Dialect/QuantOps/Transforms/ConvertConst.cpp +++ b/mlir/lib/Dialect/QuantOps/Transforms/ConvertConst.cpp @@ -112,8 +112,8 @@ void ConvertConstPass::runOnFunction() { applyPatternsGreedily(func, patterns); } -FunctionPassBase *mlir::quant::createConvertConstPass() { - return new ConvertConstPass(); +std::unique_ptr mlir::quant::createConvertConstPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp b/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp index dfdce8964baa..924e6390d88b 100644 --- a/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp +++ b/mlir/lib/Dialect/QuantOps/Transforms/ConvertSimQuant.cpp @@ -103,8 +103,9 @@ void ConvertSimulatedQuantPass::runOnFunction() { signalPassFailure(); } -FunctionPassBase *mlir::quant::createConvertSimulatedQuantPass() { - return new ConvertSimulatedQuantPass(); +std::unique_ptr +mlir::quant::createConvertSimulatedQuantPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Linalg/Transforms/Fusion.cpp b/mlir/lib/Linalg/Transforms/Fusion.cpp index 4864f394c88d..992c4664b10a 100644 --- a/mlir/lib/Linalg/Transforms/Fusion.cpp +++ b/mlir/lib/Linalg/Transforms/Fusion.cpp @@ -350,14 +350,14 @@ LinalgFusionPass::LinalgFusionPass(ArrayRef sizes) this->tileSizes.assign(sizes.begin(), sizes.end()); } -FunctionPassBase * +std::unique_ptr mlir::linalg::createLinalgFusionPass(ArrayRef tileSizes) { - return new LinalgFusionPass(tileSizes); + return llvm::make_unique(tileSizes); } static PassRegistration pass("linalg-fusion", "Fuse operations in the linalg dialect", [] { - auto *pass = new LinalgFusionPass(); + auto pass = llvm::make_unique(); pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end()); return pass; }); diff --git a/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp b/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp index 84452a2ec2c2..49af61e33eb5 100644 --- a/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp +++ b/mlir/lib/Linalg/Transforms/LowerToLLVMDialect.cpp @@ -741,8 +741,8 @@ void LowerLinalgToLLVMPass::runOnModule() { } } -ModulePassBase *mlir::linalg::createLowerLinalgToLLVMPass() { - return new LowerLinalgToLLVMPass(); +std::unique_ptr mlir::linalg::createLowerLinalgToLLVMPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Linalg/Transforms/LowerToLoops.cpp b/mlir/lib/Linalg/Transforms/LowerToLoops.cpp index afeb5c43f91f..24e56b110638 100644 --- a/mlir/lib/Linalg/Transforms/LowerToLoops.cpp +++ b/mlir/lib/Linalg/Transforms/LowerToLoops.cpp @@ -390,8 +390,8 @@ void LowerLinalgToLoopsPass::runOnFunction() { } } -FunctionPassBase *mlir::linalg::createLowerLinalgToLoopsPass() { - return new LowerLinalgToLoopsPass(); +std::unique_ptr mlir::linalg::createLowerLinalgToLoopsPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Linalg/Transforms/Tiling.cpp b/mlir/lib/Linalg/Transforms/Tiling.cpp index 8090a587d426..48c0da8f88f3 100644 --- a/mlir/lib/Linalg/Transforms/Tiling.cpp +++ b/mlir/lib/Linalg/Transforms/Tiling.cpp @@ -527,15 +527,15 @@ LinalgTilingPass::LinalgTilingPass(ArrayRef sizes, bool promoteViews) { this->promoteViews = promoteViews; } -FunctionPassBase * +std::unique_ptr mlir::linalg::createLinalgTilingPass(ArrayRef tileSizes, bool promoteViews) { - return new LinalgTilingPass(tileSizes, promoteViews); + return llvm::make_unique(tileSizes, promoteViews); } static PassRegistration pass("linalg-tile", "Tile operations in the linalg dialect", [] { - auto *pass = new LinalgTilingPass(); + auto pass = llvm::make_unique(); pass->tileSizes.assign(clTileSizes.begin(), clTileSizes.end()); pass->promoteViews = clPromoteFullTileViews; return pass; diff --git a/mlir/lib/Pass/Pass.cpp b/mlir/lib/Pass/Pass.cpp index 3ed7b248042b..35d96634cf16 100644 --- a/mlir/lib/Pass/Pass.cpp +++ b/mlir/lib/Pass/Pass.cpp @@ -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) { switch (pass->getKind()) { case Pass::Kind::FunctionPass: - addPass(cast(pass)); + addPass(cast(std::move(pass))); break; case Pass::Kind::ModulePass: - addPass(cast(pass)); + addPass(cast(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 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()); } /// 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 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(); fpe = &adaptor->getFunctionExecutor(); + addPass(std::unique_ptr{adaptor.release()}); } else { - auto *adaptor = new ModuleToFunctionPassAdaptorParallel(); - addPass(adaptor); + auto adaptor = llvm::make_unique(); fpe = &adaptor->getFunctionExecutor(); + addPass(std::unique_ptr{adaptor.release()}); } /// Add the executor to the stack. @@ -309,11 +309,11 @@ void PassManager::addPass(FunctionPassBase *pass) { } else { fpe = cast(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()); } /// Add the provided instrumentation to the pass manager. This takes ownership diff --git a/mlir/lib/Pass/PassDetail.h b/mlir/lib/Pass/PassDetail.h index 0b41c44ef146..bb482a2bc65b 100644 --- a/mlir/lib/Pass/PassDetail.h +++ b/mlir/lib/Pass/PassDetail.h @@ -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 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 pass) { + passes.push_back(std::move(pass)); + } static bool classof(const PassExecutor *pe) { return pe->getKind() == Kind::ModuleExecutor; diff --git a/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp b/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp index 3f26bf075af8..4868d3be2914 100644 --- a/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp +++ b/mlir/lib/Quantizer/Transforms/AddDefaultStatsTestPass.cpp @@ -118,8 +118,8 @@ void AddDefaultStatsPass::runWithConfig(SolverContext &solverContext, }); } -FunctionPassBase *mlir::quantizer::createAddDefaultStatsPass() { - return new AddDefaultStatsPass(); +std::unique_ptr mlir::quantizer::createAddDefaultStatsPass() { + return llvm::make_unique(); } static PassRegistration pass( diff --git a/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp b/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp index 765a36e791a8..e1365e769b3c 100644 --- a/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp +++ b/mlir/lib/Quantizer/Transforms/InferQuantizedTypesPass.cpp @@ -286,9 +286,9 @@ void InferQuantizedTypesPass::transformResultType(CAGResultAnchor *anchor, } } -ModulePassBase *mlir::quantizer::createInferQuantizedTypesPass( +std::unique_ptr mlir::quantizer::createInferQuantizedTypesPass( SolverContext &solverContext, const TargetConfiguration &config) { - return new InferQuantizedTypesPass(solverContext, config); + return llvm::make_unique(solverContext, config); } static PassRegistration diff --git a/mlir/lib/Quantizer/Transforms/RemoveInstrumentationPass.cpp b/mlir/lib/Quantizer/Transforms/RemoveInstrumentationPass.cpp index d5fb28463d63..104a3b604044 100644 --- a/mlir/lib/Quantizer/Transforms/RemoveInstrumentationPass.cpp +++ b/mlir/lib/Quantizer/Transforms/RemoveInstrumentationPass.cpp @@ -66,8 +66,9 @@ void RemoveInstrumentationPass::runOnFunction() { applyPatternsGreedily(func, patterns); } -FunctionPassBase *mlir::quantizer::createRemoveInstrumentationPass() { - return new RemoveInstrumentationPass(); +std::unique_ptr +mlir::quantizer::createRemoveInstrumentationPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Transforms/AffineDataCopyGeneration.cpp b/mlir/lib/Transforms/AffineDataCopyGeneration.cpp index 522ed4a4c09c..e422bd244257 100644 --- a/mlir/lib/Transforms/AffineDataCopyGeneration.cpp +++ b/mlir/lib/Transforms/AffineDataCopyGeneration.cpp @@ -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 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( + slowMemorySpace, fastMemorySpace, tagMemorySpace, minDmaTransferSize, + fastMemCapacityBytes); } // Info comprising stride and number of elements transferred every stride. diff --git a/mlir/lib/Transforms/CSE.cpp b/mlir/lib/Transforms/CSE.cpp index eeb63e7f9eb2..59658526c25f 100644 --- a/mlir/lib/Transforms/CSE.cpp +++ b/mlir/lib/Transforms/CSE.cpp @@ -258,7 +258,9 @@ void CSE::runOnFunction() { markAnalysesPreserved(); } -FunctionPassBase *mlir::createCSEPass() { return new CSE(); } +std::unique_ptr mlir::createCSEPass() { + return llvm::make_unique(); +} static PassRegistration pass("cse", "Eliminate common sub-expressions in functions"); diff --git a/mlir/lib/Transforms/Canonicalizer.cpp b/mlir/lib/Transforms/Canonicalizer.cpp index 80d8ea92b033..6f4a40f86f35 100644 --- a/mlir/lib/Transforms/Canonicalizer.cpp +++ b/mlir/lib/Transforms/Canonicalizer.cpp @@ -53,8 +53,8 @@ void Canonicalizer::runOnFunction() { } /// Create a Canonicalizer pass. -FunctionPassBase *mlir::createCanonicalizerPass() { - return new Canonicalizer(); +std::unique_ptr mlir::createCanonicalizerPass() { + return llvm::make_unique(); } static PassRegistration pass("canonicalize", diff --git a/mlir/lib/Transforms/LoopCoalescing.cpp b/mlir/lib/Transforms/LoopCoalescing.cpp index f47433c52c08..eb52e8d58022 100644 --- a/mlir/lib/Transforms/LoopCoalescing.cpp +++ b/mlir/lib/Transforms/LoopCoalescing.cpp @@ -96,8 +96,8 @@ public: } // namespace -FunctionPassBase *mlir::createLoopCoalescingPass() { - return new LoopCoalescingPass; +std::unique_ptr mlir::createLoopCoalescingPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Transforms/LoopFusion.cpp b/mlir/lib/Transforms/LoopFusion.cpp index ea1a03f09a39..2736ebc0f55d 100644 --- a/mlir/lib/Transforms/LoopFusion.cpp +++ b/mlir/lib/Transforms/LoopFusion.cpp @@ -111,10 +111,11 @@ struct LoopFusion : public FunctionPass { } // end anonymous namespace -FunctionPassBase *mlir::createLoopFusionPass(unsigned fastMemorySpace, - uint64_t localBufSizeThreshold, - bool maximalFusion) { - return new LoopFusion(fastMemorySpace, localBufSizeThreshold, maximalFusion); +std::unique_ptr +mlir::createLoopFusionPass(unsigned fastMemorySpace, + uint64_t localBufSizeThreshold, bool maximalFusion) { + return llvm::make_unique(fastMemorySpace, localBufSizeThreshold, + maximalFusion); } namespace { diff --git a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp index d8b5b2d8b2ca..09fe9afe8082 100644 --- a/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp +++ b/mlir/lib/Transforms/LoopInvariantCodeMotion.cpp @@ -76,8 +76,8 @@ static bool isMemRefDereferencingOp(Operation &op) { return false; } -FunctionPassBase *mlir::createLoopInvariantCodeMotionPass() { - return new LoopInvariantCodeMotion(); +std::unique_ptr mlir::createLoopInvariantCodeMotionPass() { + return llvm::make_unique(); } // Returns true if the individual op is loop invariant. diff --git a/mlir/lib/Transforms/LoopTiling.cpp b/mlir/lib/Transforms/LoopTiling.cpp index 0a331cae100e..d6ff9a94234e 100644 --- a/mlir/lib/Transforms/LoopTiling.cpp +++ b/mlir/lib/Transforms/LoopTiling.cpp @@ -81,8 +81,9 @@ struct LoopTiling : public FunctionPass { /// 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 +mlir::createLoopTilingPass(uint64_t cacheSizeBytes) { + return llvm::make_unique(cacheSizeBytes); } // Move the loop body of AffineForOp 'src' from 'src' into the specified diff --git a/mlir/lib/Transforms/LoopUnroll.cpp b/mlir/lib/Transforms/LoopUnroll.cpp index 1c7f3393adad..c3db90e4b3a2 100644 --- a/mlir/lib/Transforms/LoopUnroll.cpp +++ b/mlir/lib/Transforms/LoopUnroll.cpp @@ -180,10 +180,10 @@ LogicalResult LoopUnroll::runOnAffineForOp(AffineForOp forOp) { return loopUnrollByFactor(forOp, kDefaultUnrollFactor); } -FunctionPassBase *mlir::createLoopUnrollPass( +std::unique_ptr mlir::createLoopUnrollPass( int unrollFactor, int unrollFull, const std::function &getUnrollFactor) { - return new LoopUnroll( + return llvm::make_unique( unrollFactor == -1 ? None : Optional(unrollFactor), unrollFull == -1 ? None : Optional(unrollFull), getUnrollFactor); } diff --git a/mlir/lib/Transforms/LoopUnrollAndJam.cpp b/mlir/lib/Transforms/LoopUnrollAndJam.cpp index 7650db1ce275..362aa8683ccc 100644 --- a/mlir/lib/Transforms/LoopUnrollAndJam.cpp +++ b/mlir/lib/Transforms/LoopUnrollAndJam.cpp @@ -82,8 +82,9 @@ struct LoopUnrollAndJam : public FunctionPass { }; } // end anonymous namespace -FunctionPassBase *mlir::createLoopUnrollAndJamPass(int unrollJamFactor) { - return new LoopUnrollAndJam( +std::unique_ptr +mlir::createLoopUnrollAndJamPass(int unrollJamFactor) { + return llvm::make_unique( unrollJamFactor == -1 ? None : Optional(unrollJamFactor)); } diff --git a/mlir/lib/Transforms/LowerAffine.cpp b/mlir/lib/Transforms/LowerAffine.cpp index 062134dea9c6..f24bc6d88dac 100644 --- a/mlir/lib/Transforms/LowerAffine.cpp +++ b/mlir/lib/Transforms/LowerAffine.cpp @@ -529,8 +529,8 @@ class LowerAffinePass : public FunctionPass { /// Lowers If and For operations within a function into their lower level CFG /// equivalent blocks. -FunctionPassBase *mlir::createLowerAffinePass() { - return new LowerAffinePass(); +std::unique_ptr mlir::createLowerAffinePass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Transforms/LowerVectorTransfers.cpp b/mlir/lib/Transforms/LowerVectorTransfers.cpp index e2d5920f1dd7..e941850b5b1e 100644 --- a/mlir/lib/Transforms/LowerVectorTransfers.cpp +++ b/mlir/lib/Transforms/LowerVectorTransfers.cpp @@ -373,8 +373,8 @@ struct LowerVectorTransfersPass } // end anonymous namespace -FunctionPassBase *mlir::createLowerVectorTransfersPass() { - return new LowerVectorTransfersPass(); +std::unique_ptr mlir::createLowerVectorTransfersPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Transforms/MaterializeVectors.cpp b/mlir/lib/Transforms/MaterializeVectors.cpp index 17acc92f49a2..24b1f77c9391 100644 --- a/mlir/lib/Transforms/MaterializeVectors.cpp +++ b/mlir/lib/Transforms/MaterializeVectors.cpp @@ -766,9 +766,9 @@ void MaterializeVectorsPass::runOnFunction() { signalPassFailure(); } -FunctionPassBase * +std::unique_ptr mlir::createMaterializeVectorsPass(llvm::ArrayRef vectorSize) { - return new MaterializeVectorsPass(vectorSize); + return llvm::make_unique(vectorSize); } static PassRegistration diff --git a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp index 4f8b1c61cbf0..b16dff93ee31 100644 --- a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp +++ b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp @@ -88,8 +88,8 @@ struct MemRefDataFlowOpt : public FunctionPass { /// 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 mlir::createMemRefDataFlowOptPass() { + return llvm::make_unique(); } // This is a straightforward implementation not optimized for speed. Optimize diff --git a/mlir/lib/Transforms/PipelineDataTransfer.cpp b/mlir/lib/Transforms/PipelineDataTransfer.cpp index af456c314081..d4d91c9b0e23 100644 --- a/mlir/lib/Transforms/PipelineDataTransfer.cpp +++ b/mlir/lib/Transforms/PipelineDataTransfer.cpp @@ -49,8 +49,8 @@ struct PipelineDataTransfer : public FunctionPass { /// Creates a pass to pipeline explicit movement of data across levels of the /// memory hierarchy. -FunctionPassBase *mlir::createPipelineDataTransferPass() { - return new PipelineDataTransfer(); +std::unique_ptr mlir::createPipelineDataTransferPass() { + return llvm::make_unique(); } // Returns the position of the tag memref operand given a DMA operation. diff --git a/mlir/lib/Transforms/SimplifyAffineStructures.cpp b/mlir/lib/Transforms/SimplifyAffineStructures.cpp index 3b6c231d0544..3cc9309a5d51 100644 --- a/mlir/lib/Transforms/SimplifyAffineStructures.cpp +++ b/mlir/lib/Transforms/SimplifyAffineStructures.cpp @@ -88,8 +88,8 @@ struct SimplifyAffineStructures } // end anonymous namespace -FunctionPassBase *mlir::createSimplifyAffineStructuresPass() { - return new SimplifyAffineStructures(); +std::unique_ptr mlir::createSimplifyAffineStructuresPass() { + return llvm::make_unique(); } void SimplifyAffineStructures::runOnFunction() { diff --git a/mlir/lib/Transforms/StripDebugInfo.cpp b/mlir/lib/Transforms/StripDebugInfo.cpp index c82354ed49ef..21d8ef15219f 100644 --- a/mlir/lib/Transforms/StripDebugInfo.cpp +++ b/mlir/lib/Transforms/StripDebugInfo.cpp @@ -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 mlir::createStripDebugInfoPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/lib/Transforms/Vectorize.cpp b/mlir/lib/Transforms/Vectorize.cpp index ce2540653323..932f00bfcbea 100644 --- a/mlir/lib/Transforms/Vectorize.cpp +++ b/mlir/lib/Transforms/Vectorize.cpp @@ -1276,9 +1276,9 @@ void Vectorize::runOnFunction() { LLVM_DEBUG(dbgs() << "\n"); } -FunctionPassBase * +std::unique_ptr mlir::createVectorizePass(llvm::ArrayRef virtualVectorSize) { - return new Vectorize(virtualVectorSize); + return llvm::make_unique(virtualVectorSize); } static PassRegistration diff --git a/mlir/test/lib/TestDialect/TestPatterns.cpp b/mlir/test/lib/TestDialect/TestPatterns.cpp index 584ff996fca1..9b7fe8e94bf3 100644 --- a/mlir/test/lib/TestDialect/TestPatterns.cpp +++ b/mlir/test/lib/TestDialect/TestPatterns.cpp @@ -247,6 +247,9 @@ static llvm::cl::opt clEnumValN(TestLegalizePatternDriver::ConversionMode::Partial, "partial", "Perform a partial conversion"))); -static mlir::PassRegistration legalizer_pass( - "test-legalize-patterns", "Run test dialect legalization patterns", - [] { return new TestLegalizePatternDriver(legalizerConversionMode); }); +static mlir::PassRegistration + legalizer_pass("test-legalize-patterns", + "Run test dialect legalization patterns", [] { + return llvm::make_unique( + legalizerConversionMode); + }); diff --git a/mlir/test/lib/Transforms/TestConstantFold.cpp b/mlir/test/lib/Transforms/TestConstantFold.cpp index 7d17f60c7196..02c66ef86acd 100644 --- a/mlir/test/lib/Transforms/TestConstantFold.cpp +++ b/mlir/test/lib/Transforms/TestConstantFold.cpp @@ -74,8 +74,8 @@ void TestConstantFold::runOnFunction() { } /// Creates a constant folding pass. -FunctionPassBase *mlir::createTestConstantFoldPass() { - return new TestConstantFold(); +std::unique_ptr mlir::createTestConstantFoldPass() { + return llvm::make_unique(); } static PassRegistration diff --git a/mlir/test/lib/Transforms/TestLoopFusion.cpp b/mlir/test/lib/Transforms/TestLoopFusion.cpp index 39990968a349..bcb050769a16 100644 --- a/mlir/test/lib/Transforms/TestLoopFusion.cpp +++ b/mlir/test/lib/Transforms/TestLoopFusion.cpp @@ -58,8 +58,8 @@ struct TestLoopFusion : public FunctionPass { } // end anonymous namespace -FunctionPassBase *mlir::createTestLoopFusionPass() { - return new TestLoopFusion; +std::unique_ptr mlir::createTestLoopFusionPass() { + return llvm::make_unique(); } // Gathers all AffineForOps in 'block' at 'currLoopDepth' in 'depthToLoops'. diff --git a/mlir/test/lib/Transforms/TestLoopMapping.cpp b/mlir/test/lib/Transforms/TestLoopMapping.cpp index bf354670f928..a9da70a6d5e5 100644 --- a/mlir/test/lib/Transforms/TestLoopMapping.cpp +++ b/mlir/test/lib/Transforms/TestLoopMapping.cpp @@ -62,4 +62,4 @@ public: static PassRegistration reg("test-mapping-to-processing-elements", "test mapping a single loop on a virtual processor grid", - [] { return new TestLoopMappingPass(); }); + [] { return llvm::make_unique(); }); diff --git a/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp b/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp index d30eacc044dc..e01ff66d8251 100644 --- a/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp +++ b/mlir/test/lib/Transforms/TestLoopParametricTiling.cpp @@ -55,9 +55,9 @@ public: }; } // end namespace -FunctionPassBase * +std::unique_ptr mlir::createSimpleParametricTilingPass(ArrayRef outerLoopSizes) { - return new SimpleParametricLoopTilingPass(outerLoopSizes); + return llvm::make_unique(outerLoopSizes); } static PassRegistration @@ -65,7 +65,8 @@ static PassRegistration "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( + ArrayRef{}); pass->sizes.assign(clOuterLoopSizes.begin(), clOuterLoopSizes.end()); return pass; }); diff --git a/mlir/test/lib/Transforms/TestVectorizationUtils.cpp b/mlir/test/lib/Transforms/TestVectorizationUtils.cpp index b51de4123060..3bfe6b6fce3f 100644 --- a/mlir/test/lib/Transforms/TestVectorizationUtils.cpp +++ b/mlir/test/lib/Transforms/TestVectorizationUtils.cpp @@ -290,8 +290,8 @@ void VectorizerTestPass::runOnFunction() { } } -FunctionPassBase *mlir::createVectorizerTestPass() { - return new VectorizerTestPass(); +std::unique_ptr mlir::createVectorizerTestPass() { + return llvm::make_unique(); } static PassRegistration