Define a PassID class to use when defining a pass. This allows for the type used...
authorRiver Riddle <riverriddle@google.com>
Fri, 22 Feb 2019 02:01:09 +0000 (18:01 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 23:37:12 +0000 (16:37 -0700)
PiperOrigin-RevId: 235107957

29 files changed:
mlir/g3doc/QuickstartRewrites.md
mlir/include/mlir/Pass/Pass.h
mlir/include/mlir/Pass/PassRegistry.h
mlir/include/mlir/Transforms/DialectConversion.h
mlir/include/mlir/Transforms/MLPatternLoweringPass.h
mlir/lib/Analysis/MemRefBoundCheck.cpp
mlir/lib/Analysis/MemRefDependenceCheck.cpp
mlir/lib/Analysis/OpStats.cpp
mlir/lib/EDSC/LowerEDSCTestPass.cpp
mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp
mlir/lib/Pass/PassRegistry.cpp
mlir/lib/Transforms/CSE.cpp
mlir/lib/Transforms/Canonicalizer.cpp
mlir/lib/Transforms/ConstantFold.cpp
mlir/lib/Transforms/DmaGeneration.cpp
mlir/lib/Transforms/LoopFusion.cpp
mlir/lib/Transforms/LoopTiling.cpp
mlir/lib/Transforms/LoopUnroll.cpp
mlir/lib/Transforms/LoopUnrollAndJam.cpp
mlir/lib/Transforms/LowerAffine.cpp
mlir/lib/Transforms/LowerVectorTransfers.cpp
mlir/lib/Transforms/MaterializeVectors.cpp
mlir/lib/Transforms/MemRefDataFlowOpt.cpp
mlir/lib/Transforms/PipelineDataTransfer.cpp
mlir/lib/Transforms/SimplifyAffineStructures.cpp
mlir/lib/Transforms/StripDebugInfo.cpp
mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp
mlir/lib/Transforms/Vectorize.cpp
mlir/lib/Transforms/ViewFunctionGraph.cpp

index a7548c00392773eef3c9f959486abf9215ee64c9..2ccbfa174ab07f4a669cdbb14f8bdbc771ca6e3d 100644 (file)
@@ -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
 
index c489dafb20bf69ff38323ab0307d53056b220e49..6edcc3bb8a84662822ca583ed315fed698a459a7 100644 (file)
@@ -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;
index 8f324bf0f69fe038816d096a88e42ecb547ea8fd..c8d85f1dd69c912090e2b8803145c1c9bd805f6d 100644 (file)
@@ -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
index b547e21c28a672634888a072a28e596c61940ceb..b1e87e7223e840187459468fc9f9e36db08c67d9 100644 (file)
@@ -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;
index 1abd85a1d2be679a4891808702f289ed23dafacf..15e4f215c614fa8a241917b68c792cdeb05a1e27 100644 (file)
@@ -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 {
index 9f6efff318710673e3966cfe11a89a9e7d5941a4..b86651793f99f4f935ec28bfcfcc94304a870c7b 100644 (file)
@@ -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();
 }
index 43bc0c989161f4186ca28c92d9da6424a32af80d..0b5c9b997a59a10033dd1567aa3b7137a2ce4329 100644 (file)
@@ -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();
 }
index 6ae7ec59c50f5d26c78c12deb67cdfc5e4d8d186..c1fcacac15a9ba8a82af11bd072cad53dd5726d2 100644 (file)
@@ -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();
 
index 41b2031bdbcc4c2ff42aa580dcb94a8c7ecbc757..67d4fb38080785ed2bb0117b9790511a4de4ab6b 100644 (file)
@@ -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) {
index e1abeffe604d7636c2dc6141e8f20e79f19a4a42..ba3619e38b6f251f507accd835688102f83fb7c0 100644 (file)
@@ -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>
index c26da1f4099a188e1dc53425e4c7e0ecc0a85933..e90fb2217a22b82bd9efec8587f6c05354db9ba8 100644 (file)
 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;
index cd205fe773bcea31b3efe3721f3ce4672e0ab46e..e83be30655a268ec99ecfbda8d1669ae54cc7174 100644 (file)
@@ -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
index 0388744d4d2671b578d1c7d20964bb1ea577ad7e..ac77e201acfd337bcbca9875fa793971d1c4d5c4 100644 (file)
@@ -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;
index 7634d9ec16a4e7da0f93e6a8bf0d16fc5dd4ce7c..4817baaa23e82c1436b53a95667101ee3d7e76d6 100644 (file)
@@ -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.
 ///
index 5df938634e7d28ef868ea17f3bde54be3b9ee98b..5083bc4d5865cacc36f928465d7fbb40fa71522f 100644 (file)
@@ -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.
index 524b34bb86f05f57040ca20b04a137a54da990fb..303efc69ceb4da794fa1ba442be3611041c9f12d 100644 (file)
@@ -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 {
index 76e8e9254c9b2ca81383d68c6f6401df8ae477db..2253d1d354aaf80700ab265ce7e22904d9e69bc7 100644 (file)
@@ -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),
index b452b4f76e284f263e9deaa0f02b9c91c9874930..3b4a0517f0d02b78baad8b4cddb54607661f7cd9 100644 (file)
@@ -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 {
index 76668c7f0b5c5ef16a89f91a1301014bc7d5014b..87e2770aa41f56d9ddabc46f77f900c8831a9d0e 100644 (file)
@@ -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));
index 8b62601ab416de55a019414b185c8fb6e78d9b66..836205169947e92361d86873f78c7231d9b38294 100644 (file)
@@ -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
index bd43a637665b4d2ba668fc7fe0bcbaf7e9c8391d..ac8f7e064f576bb0817d0e866c0d7f47d6ce3395 100644 (file)
@@ -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();
 }
index 3cd33c20fae2905d201eeef3dc2d0add9c621f4e..6177ca1233bb4d27fa6494b85b1d2635454a47d6 100644 (file)
@@ -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.
index 68bce8542229e13ea0d1245e2128290b38c28336..0ba06fecae058a99166e2c02c4598c961fb0f6b3 100644 (file)
@@ -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() {
index b6bfde584941ae88e071ef93298319cf2fb4deb5..f41f56efd8fe15e02f7fc1c7f19d63834b88a6fa 100644 (file)
@@ -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() {
index 20961180b83913b3b214981376b7120d5e7f0acd..4ddfd9f06fb1e6c52d3739f925d9124e287caac3 100644 (file)
@@ -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();
 }
index 2eb4a37445cf2cf765f9e26ba13ec0c858a8a88e..fc2b0eb0a95c2e60afc8da4888dbdae76f401e87 100644 (file)
@@ -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());
 
index 3fa08bba096cb09c1aacae3feb159f738b43562d..2363c5638ee89ace5910ab7725778147f4cdd842 100644 (file)
@@ -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(),
index 40a2c9794ae257369995963ab1258a46082357b9..e009696fa1f9444fcab350e6d077758eb2e0b0b1 100644 (file)
@@ -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 {
 
index 4865859b9ec5168bcfbc6b1833e028b3ceb4e40e..14e21770e2527415e52cedfdf14466b6eb74697e 100644 (file)
@@ -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) {