diff options
29 files changed, 44 insertions, 84 deletions
diff --git a/mlir/g3doc/QuickstartRewrites.md b/mlir/g3doc/QuickstartRewrites.md index a7548c00392..2ccbfa174ab 100644 --- a/mlir/g3doc/QuickstartRewrites.md +++ b/mlir/g3doc/QuickstartRewrites.md @@ -222,7 +222,7 @@ struct TestPass : public FunctionPass { TestPass() : FunctionPass(&TestPass::passID) {} PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace diff --git a/mlir/include/mlir/Pass/Pass.h b/mlir/include/mlir/Pass/Pass.h index c489dafb20b..6edcc3bb8a8 100644 --- a/mlir/include/mlir/Pass/Pass.h +++ b/mlir/include/mlir/Pass/Pass.h @@ -24,6 +24,10 @@ namespace mlir { class Function; class Module; +/// A special type used by transformation passes to provide an address that can +/// act as a unique identifier during pass registration. +struct alignas(8) PassID {}; + // Values that can be used by to signal success/failure. This can be implicitly // converted to/from boolean values, with false representing success and true // failure. @@ -35,18 +39,18 @@ struct LLVM_NODISCARD PassResult { class Pass { public: - explicit Pass(const void *passID) : passID(passID) {} + explicit Pass(const PassID *passID) : passID(passID) {} virtual ~Pass() = default; virtual PassResult runOnModule(Module *m) = 0; /// Returns the unique identifier that corresponds to this pass. - const void *getPassID() const { return passID; } + const PassID *getPassID() const { return passID; } static PassResult success() { return PassResult::Success; } static PassResult failure() { return PassResult::Failure; } /// Returns the pass info for the specified pass class or null if unknown. - static const PassInfo *lookupPassInfo(const void *passID); + static const PassInfo *lookupPassInfo(const PassID *passID); /// Returns the pass info for this pass. const PassInfo *lookupPassInfo() const { return lookupPassInfo(passID); } @@ -57,12 +61,12 @@ private: virtual void anchor(); /// Unique identifier for pass. - const void *const passID; + const PassID *const passID; }; class ModulePass : public Pass { public: - explicit ModulePass(const void *passID) : Pass(passID) {} + explicit ModulePass(const PassID *passID) : Pass(passID) {} virtual PassResult runOnModule(Module *m) override = 0; @@ -79,7 +83,7 @@ private: /// module. class FunctionPass : public Pass { public: - explicit FunctionPass(const void *passID) : Pass(passID) {} + explicit FunctionPass(const PassID *passID) : Pass(passID) {} /// Implement this function to be run on every function in the module. virtual PassResult runOnFunction(Function *fn) = 0; diff --git a/mlir/include/mlir/Pass/PassRegistry.h b/mlir/include/mlir/Pass/PassRegistry.h index 8f324bf0f69..c8d85f1dd69 100644 --- a/mlir/include/mlir/Pass/PassRegistry.h +++ b/mlir/include/mlir/Pass/PassRegistry.h @@ -31,6 +31,7 @@ namespace mlir { class Pass; +class PassID; using PassAllocatorFunction = std::function<Pass *()>; @@ -40,7 +41,7 @@ class PassInfo { public: /// PassInfo constructor should not be invoked directly, instead use /// PassRegistration or registerPass. - PassInfo(StringRef arg, StringRef description, const void *passID, + PassInfo(StringRef arg, StringRef description, const PassID *passID, PassAllocatorFunction allocator) : arg(arg), description(description), allocator(allocator), passID(passID) {} @@ -70,12 +71,12 @@ private: PassAllocatorFunction allocator; // Unique identifier for pass. - const void *passID; + const PassID *passID; }; /// Register a specific dialect creation function with the system, typically /// used through the PassRegistration template. -void registerPass(StringRef arg, StringRef description, const void *passID, +void registerPass(StringRef arg, StringRef description, const PassID *passID, const PassAllocatorFunction &function); /// PassRegistration provides a global initializer that registers a Pass diff --git a/mlir/include/mlir/Transforms/DialectConversion.h b/mlir/include/mlir/Transforms/DialectConversion.h index b547e21c28a..b1e87e7223e 100644 --- a/mlir/include/mlir/Transforms/DialectConversion.h +++ b/mlir/include/mlir/Transforms/DialectConversion.h @@ -151,7 +151,7 @@ class DialectConversion : public ModulePass { public: /// Construct a pass given its unique identifier. - DialectConversion(const void *passID) : ModulePass(passID) {} + DialectConversion(const PassID *passID) : ModulePass(passID) {} /// Run the pass on the module. PassResult runOnModule(Module *m) override; diff --git a/mlir/include/mlir/Transforms/MLPatternLoweringPass.h b/mlir/include/mlir/Transforms/MLPatternLoweringPass.h index 1abd85a1d2b..15e4f215c61 100644 --- a/mlir/include/mlir/Transforms/MLPatternLoweringPass.h +++ b/mlir/include/mlir/Transforms/MLPatternLoweringPass.h @@ -101,7 +101,7 @@ using OwningMLLoweringPatternList = template <typename... Patterns> class MLPatternLoweringPass : public FunctionPass { public: - explicit MLPatternLoweringPass(void *ID) : FunctionPass(ID) {} + explicit MLPatternLoweringPass(const PassID *ID) : FunctionPass(ID) {} virtual std::unique_ptr<MLFuncGlobalLoweringState> makeFuncWiseState(Function *f) const { diff --git a/mlir/lib/Analysis/MemRefBoundCheck.cpp b/mlir/lib/Analysis/MemRefBoundCheck.cpp index 9f6efff3187..b86651793f9 100644 --- a/mlir/lib/Analysis/MemRefBoundCheck.cpp +++ b/mlir/lib/Analysis/MemRefBoundCheck.cpp @@ -42,13 +42,11 @@ struct MemRefBoundCheck : public FunctionPass { PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char MemRefBoundCheck::passID = 0; - FunctionPass *mlir::createMemRefBoundCheckPass() { return new MemRefBoundCheck(); } diff --git a/mlir/lib/Analysis/MemRefDependenceCheck.cpp b/mlir/lib/Analysis/MemRefDependenceCheck.cpp index 43bc0c98916..0b5c9b997a5 100644 --- a/mlir/lib/Analysis/MemRefDependenceCheck.cpp +++ b/mlir/lib/Analysis/MemRefDependenceCheck.cpp @@ -44,13 +44,11 @@ struct MemRefDependenceCheck : public FunctionPass { PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char MemRefDependenceCheck::passID = 0; - FunctionPass *mlir::createMemRefDependenceCheckPass() { return new MemRefDependenceCheck(); } diff --git a/mlir/lib/Analysis/OpStats.cpp b/mlir/lib/Analysis/OpStats.cpp index 6ae7ec59c50..c1fcacac15a 100644 --- a/mlir/lib/Analysis/OpStats.cpp +++ b/mlir/lib/Analysis/OpStats.cpp @@ -36,7 +36,7 @@ struct PrintOpStatsPass : public ModulePass { // Print summary of op stats. void printSummary(); - static char passID; + constexpr static PassID passID = {}; private: llvm::StringMap<int64_t> opCount; @@ -44,8 +44,6 @@ private: }; } // namespace -char PrintOpStatsPass::passID = 0; - PassResult PrintOpStatsPass::runOnModule(Module *m) { opCount.clear(); diff --git a/mlir/lib/EDSC/LowerEDSCTestPass.cpp b/mlir/lib/EDSC/LowerEDSCTestPass.cpp index 41b2031bdbc..67d4fb38080 100644 --- a/mlir/lib/EDSC/LowerEDSCTestPass.cpp +++ b/mlir/lib/EDSC/LowerEDSCTestPass.cpp @@ -35,12 +35,10 @@ struct LowerEDSCTestPass : public FunctionPass { LowerEDSCTestPass() : FunctionPass(&LowerEDSCTestPass::passID) {} PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char LowerEDSCTestPass::passID = 0; - #include "mlir/EDSC/reference-impl.inc" PassResult LowerEDSCTestPass::runOnFunction(Function *f) { diff --git a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp index e1abeffe604..ba3619e38b6 100644 --- a/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp +++ b/mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp @@ -1030,7 +1030,7 @@ class LLVMLowering : public DialectConversion { public: LLVMLowering() : DialectConversion(&passID) {} - const static char passID = '\0'; + constexpr static PassID passID = {}; protected: // Create a set of converters that live in the pass object by passing them a @@ -1078,8 +1078,6 @@ private: llvm::Module *module; }; -const char LLVMLowering::passID; - ModulePass *mlir::createConvertToLLVMIRPass() { return new LLVMLowering; } static PassRegistration<LLVMLowering> diff --git a/mlir/lib/Pass/PassRegistry.cpp b/mlir/lib/Pass/PassRegistry.cpp index c26da1f4099..e90fb2217a2 100644 --- a/mlir/lib/Pass/PassRegistry.cpp +++ b/mlir/lib/Pass/PassRegistry.cpp @@ -23,10 +23,11 @@ using namespace mlir; /// Static mapping of all of the registered passes. -static llvm::ManagedStatic<llvm::DenseMap<const void *, PassInfo>> passRegistry; +static llvm::ManagedStatic<llvm::DenseMap<const PassID *, PassInfo>> + passRegistry; void mlir::registerPass(StringRef arg, StringRef description, - const void *passID, + const PassID *passID, const PassAllocatorFunction &function) { bool inserted = passRegistry ->insert(std::make_pair( @@ -37,7 +38,7 @@ void mlir::registerPass(StringRef arg, StringRef description, } /// Returns the pass info for the specified pass class or null if unknown. -const PassInfo *mlir::Pass::lookupPassInfo(const void *passID) { +const PassInfo *mlir::Pass::lookupPassInfo(const PassID *passID) { auto it = passRegistry->find(passID); if (it == passRegistry->end()) return nullptr; diff --git a/mlir/lib/Transforms/CSE.cpp b/mlir/lib/Transforms/CSE.cpp index cd205fe773b..e83be30655a 100644 --- a/mlir/lib/Transforms/CSE.cpp +++ b/mlir/lib/Transforms/CSE.cpp @@ -83,7 +83,7 @@ namespace { struct CSE : public FunctionPass { CSE() : FunctionPass(&CSE::passID) {} - static char passID; + constexpr static PassID passID = {}; /// Shared implementation of operation elimination and scoped map definitions. using AllocatorTy = llvm::RecyclingAllocator< @@ -125,8 +125,6 @@ private: }; } // end anonymous namespace -char CSE::passID = 0; - /// Attempt to eliminate a redundant operation. bool CSE::simplifyOperation(Instruction *op) { // TODO(riverriddle) We currently only eliminate non side-effecting diff --git a/mlir/lib/Transforms/Canonicalizer.cpp b/mlir/lib/Transforms/Canonicalizer.cpp index 0388744d4d2..ac77e201acf 100644 --- a/mlir/lib/Transforms/Canonicalizer.cpp +++ b/mlir/lib/Transforms/Canonicalizer.cpp @@ -37,12 +37,10 @@ struct Canonicalizer : public FunctionPass { Canonicalizer() : FunctionPass(&Canonicalizer::passID) {} PassResult runOnFunction(Function *fn) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char Canonicalizer::passID = 0; - PassResult Canonicalizer::runOnFunction(Function *fn) { auto *context = fn->getContext(); OwningRewritePatternList patterns; diff --git a/mlir/lib/Transforms/ConstantFold.cpp b/mlir/lib/Transforms/ConstantFold.cpp index 7634d9ec16a..4817baaa23e 100644 --- a/mlir/lib/Transforms/ConstantFold.cpp +++ b/mlir/lib/Transforms/ConstantFold.cpp @@ -37,12 +37,10 @@ struct ConstantFold : public FunctionPass { void foldInstruction(Instruction *op); PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char ConstantFold::passID = 0; - /// Attempt to fold the specified operation, updating the IR to match. If /// constants are found, we keep track of them in the existingConstants list. /// diff --git a/mlir/lib/Transforms/DmaGeneration.cpp b/mlir/lib/Transforms/DmaGeneration.cpp index 5df938634e7..5083bc4d586 100644 --- a/mlir/lib/Transforms/DmaGeneration.cpp +++ b/mlir/lib/Transforms/DmaGeneration.cpp @@ -116,13 +116,11 @@ struct DmaGeneration : public FunctionPass { // Constant zero index to avoid too many duplicates. Value *zeroIndex = nullptr; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char DmaGeneration::passID = 0; - /// Generates DMAs for memref's living in 'slowMemorySpace' into newly created /// buffers in 'fastMemorySpace', and replaces memory operations to the former /// by the latter. Only load op's handled for now. diff --git a/mlir/lib/Transforms/LoopFusion.cpp b/mlir/lib/Transforms/LoopFusion.cpp index 524b34bb86f..303efc69ceb 100644 --- a/mlir/lib/Transforms/LoopFusion.cpp +++ b/mlir/lib/Transforms/LoopFusion.cpp @@ -88,7 +88,7 @@ struct LoopFusion : public FunctionPass { LoopFusion() : FunctionPass(&LoopFusion::passID) {} PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; // Any local buffers smaller than this size will be created in // `fastMemorySpace` if provided. @@ -102,8 +102,6 @@ struct LoopFusion : public FunctionPass { } // end anonymous namespace -char LoopFusion::passID = 0; - FunctionPass *mlir::createLoopFusionPass() { return new LoopFusion; } namespace { diff --git a/mlir/lib/Transforms/LoopTiling.cpp b/mlir/lib/Transforms/LoopTiling.cpp index 76e8e9254c9..2253d1d354a 100644 --- a/mlir/lib/Transforms/LoopTiling.cpp +++ b/mlir/lib/Transforms/LoopTiling.cpp @@ -52,13 +52,11 @@ struct LoopTiling : public FunctionPass { PassResult runOnFunction(Function *f) override; constexpr static unsigned kDefaultTileSize = 4; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char LoopTiling::passID = 0; - // Tile size to use for all loops (overridden by -tile-sizes if provided). static llvm::cl::opt<unsigned> clTileSize("tile-size", llvm::cl::init(LoopTiling::kDefaultTileSize), diff --git a/mlir/lib/Transforms/LoopUnroll.cpp b/mlir/lib/Transforms/LoopUnroll.cpp index b452b4f76e2..3b4a0517f0d 100644 --- a/mlir/lib/Transforms/LoopUnroll.cpp +++ b/mlir/lib/Transforms/LoopUnroll.cpp @@ -86,12 +86,10 @@ struct LoopUnroll : public FunctionPass { static const unsigned kDefaultUnrollFactor = 4; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char LoopUnroll::passID = 0; - PassResult LoopUnroll::runOnFunction(Function *f) { // Gathers all innermost loops through a post order pruned walk. struct InnermostLoopGatherer { diff --git a/mlir/lib/Transforms/LoopUnrollAndJam.cpp b/mlir/lib/Transforms/LoopUnrollAndJam.cpp index 76668c7f0b5..87e2770aa41 100644 --- a/mlir/lib/Transforms/LoopUnrollAndJam.cpp +++ b/mlir/lib/Transforms/LoopUnrollAndJam.cpp @@ -82,12 +82,10 @@ struct LoopUnrollAndJam : public FunctionPass { PassResult runOnFunction(Function *f) override; bool runOnAffineForOp(OpPointer<AffineForOp> forOp); - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char LoopUnrollAndJam::passID = 0; - FunctionPass *mlir::createLoopUnrollAndJamPass(int unrollJamFactor) { return new LoopUnrollAndJam( unrollJamFactor == -1 ? None : Optional<unsigned>(unrollJamFactor)); diff --git a/mlir/lib/Transforms/LowerAffine.cpp b/mlir/lib/Transforms/LowerAffine.cpp index 8b62601ab41..83620516994 100644 --- a/mlir/lib/Transforms/LowerAffine.cpp +++ b/mlir/lib/Transforms/LowerAffine.cpp @@ -251,12 +251,10 @@ public: bool lowerAffineIf(AffineIfOp *ifOp); bool lowerAffineApply(AffineApplyOp *op); - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char LowerAffinePass::passID = 0; - // Given a range of values, emit the code that reduces them with "min" or "max" // depending on the provided comparison predicate. The predicate defines which // comparison to perform, "lt" for "min", "gt" for "max" and is used for the diff --git a/mlir/lib/Transforms/LowerVectorTransfers.cpp b/mlir/lib/Transforms/LowerVectorTransfers.cpp index bd43a637665..ac8f7e064f5 100644 --- a/mlir/lib/Transforms/LowerVectorTransfers.cpp +++ b/mlir/lib/Transforms/LowerVectorTransfers.cpp @@ -434,13 +434,11 @@ struct LowerVectorTransfersPass // Thread-safe RAII context with local scope. BumpPtrAllocator freed on exit. edsc::ScopedEDSCContext raiiContext; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char LowerVectorTransfersPass::passID = 0; - FunctionPass *mlir::createLowerVectorTransfersPass() { return new LowerVectorTransfersPass(); } diff --git a/mlir/lib/Transforms/MaterializeVectors.cpp b/mlir/lib/Transforms/MaterializeVectors.cpp index 3cd33c20fae..6177ca1233b 100644 --- a/mlir/lib/Transforms/MaterializeVectors.cpp +++ b/mlir/lib/Transforms/MaterializeVectors.cpp @@ -201,13 +201,11 @@ struct MaterializeVectorsPass : public FunctionPass { PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char MaterializeVectorsPass::passID = 0; - /// Given a shape with sizes greater than 0 along all dimensions, /// returns the distance, in number of elements, between a slice in a dimension /// and the next slice in the same dimension. diff --git a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp index 68bce854222..0ba06fecae0 100644 --- a/mlir/lib/Transforms/MemRefDataFlowOpt.cpp +++ b/mlir/lib/Transforms/MemRefDataFlowOpt.cpp @@ -84,13 +84,11 @@ struct MemRefDataFlowOpt : public FunctionPass { DominanceInfo *domInfo = nullptr; PostDominanceInfo *postDomInfo = nullptr; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char MemRefDataFlowOpt::passID = 0; - /// Creates a pass to perform optimizations relying on memref dataflow such as /// store to load forwarding, elimination of dead stores, and dead allocs. FunctionPass *mlir::createMemRefDataFlowOptPass() { diff --git a/mlir/lib/Transforms/PipelineDataTransfer.cpp b/mlir/lib/Transforms/PipelineDataTransfer.cpp index b6bfde58494..f41f56efd8f 100644 --- a/mlir/lib/Transforms/PipelineDataTransfer.cpp +++ b/mlir/lib/Transforms/PipelineDataTransfer.cpp @@ -45,13 +45,11 @@ struct PipelineDataTransfer : public FunctionPass { std::vector<OpPointer<AffineForOp>> forOps; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char PipelineDataTransfer::passID = 0; - /// Creates a pass to pipeline explicit movement of data across levels of the /// memory hierarchy. FunctionPass *mlir::createPipelineDataTransferPass() { diff --git a/mlir/lib/Transforms/SimplifyAffineStructures.cpp b/mlir/lib/Transforms/SimplifyAffineStructures.cpp index 20961180b83..4ddfd9f06fb 100644 --- a/mlir/lib/Transforms/SimplifyAffineStructures.cpp +++ b/mlir/lib/Transforms/SimplifyAffineStructures.cpp @@ -42,13 +42,11 @@ struct SimplifyAffineStructures : public FunctionPass { PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char SimplifyAffineStructures::passID = 0; - FunctionPass *mlir::createSimplifyAffineStructuresPass() { return new SimplifyAffineStructures(); } diff --git a/mlir/lib/Transforms/StripDebugInfo.cpp b/mlir/lib/Transforms/StripDebugInfo.cpp index 2eb4a37445c..fc2b0eb0a95 100644 --- a/mlir/lib/Transforms/StripDebugInfo.cpp +++ b/mlir/lib/Transforms/StripDebugInfo.cpp @@ -28,12 +28,10 @@ struct StripDebugInfo : public FunctionPass { PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char StripDebugInfo::passID = 0; - PassResult StripDebugInfo::runOnFunction(Function *f) { UnknownLoc unknownLoc = UnknownLoc::get(f->getContext()); diff --git a/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp b/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp index 3fa08bba096..2363c5638ee 100644 --- a/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp +++ b/mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp @@ -96,13 +96,11 @@ struct VectorizerTestPass : public FunctionPass { void testComposeMaps(Function *f); void testNormalizeMaps(Function *f); - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char VectorizerTestPass::passID = 0; - void VectorizerTestPass::testVectorShapeRatio(Function *f) { using matcher::Op; SmallVector<int64_t, 8> shape(clTestVectorShapeRatio.begin(), diff --git a/mlir/lib/Transforms/Vectorize.cpp b/mlir/lib/Transforms/Vectorize.cpp index 40a2c9794ae..e009696fa1f 100644 --- a/mlir/lib/Transforms/Vectorize.cpp +++ b/mlir/lib/Transforms/Vectorize.cpp @@ -656,13 +656,11 @@ struct Vectorize : public FunctionPass { PassResult runOnFunction(Function *f) override; - static char passID; + constexpr static PassID passID = {}; }; } // end anonymous namespace -char Vectorize::passID = 0; - /////// TODO(ntv): Hoist to a VectorizationStrategy.cpp when appropriate. ////// namespace { diff --git a/mlir/lib/Transforms/ViewFunctionGraph.cpp b/mlir/lib/Transforms/ViewFunctionGraph.cpp index 4865859b9ec..14e21770e25 100644 --- a/mlir/lib/Transforms/ViewFunctionGraph.cpp +++ b/mlir/lib/Transforms/ViewFunctionGraph.cpp @@ -83,7 +83,7 @@ struct PrintCFGPass : public FunctionPass { return success(); } - static char passID; + constexpr static PassID passID = {}; private: llvm::raw_ostream &os; @@ -92,8 +92,6 @@ private: }; } // namespace -char PrintCFGPass::passID = 0; - FunctionPass *mlir::createPrintCFGGraphPass(llvm::raw_ostream &os, bool shortNames, const llvm::Twine &title) { |

