diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h index 6a4fdf7bc581..928c6f75124c 100644 --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -194,7 +194,7 @@ protected: }; // Register a type with its given unqiue type identifer. - void addType(const TypeID *const typeID); + void addType(const ClassID *const typeID); // Enable support for unregistered operations. void allowUnknownOperations(bool allow = true) { allowUnknownOps = allow; } diff --git a/mlir/include/mlir/IR/TypeSupport.h b/mlir/include/mlir/IR/TypeSupport.h index fc25ea21338e..d8504de599e4 100644 --- a/mlir/include/mlir/IR/TypeSupport.h +++ b/mlir/include/mlir/IR/TypeSupport.h @@ -28,18 +28,10 @@ #include namespace mlir { +struct ClassID; class Dialect; class MLIRContext; -/// TypeID is used to provide a unique address identifier for derived Type -/// classes. -struct TypeID { - template static TypeID *getID() { - static TypeID id; - return &id; - } -}; - //===----------------------------------------------------------------------===// // TypeStorage //===----------------------------------------------------------------------===// @@ -123,7 +115,7 @@ private: /// Get the dialect that registered the type with the provided typeid. static const Dialect &lookupDialectForType(MLIRContext *ctx, - const TypeID *const typeID); + const ClassID *const typeID); }; } // namespace detail diff --git a/mlir/include/mlir/IR/Types.h b/mlir/include/mlir/IR/Types.h index e18b13101c14..d2c6e9084b6c 100644 --- a/mlir/include/mlir/IR/Types.h +++ b/mlir/include/mlir/IR/Types.h @@ -22,6 +22,7 @@ #include "mlir/IR/TypeSupport.h" #include "mlir/Support/LLVM.h" #include "mlir/Support/LogicalResult.h" +#include "mlir/Support/STLExtras.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMapInfo.h" @@ -135,7 +136,7 @@ public: using ImplType = StorageType; /// Return a unique identifier for the concrete type. - static TypeID *getTypeID() { return TypeID::getID(); } + static ClassID *getTypeID() { return ClassID::getID(); } protected: /// Get or create a new ConcreteType instance within the context. This diff --git a/mlir/include/mlir/Pass/AnalysisManager.h b/mlir/include/mlir/Pass/AnalysisManager.h index 561ff7bfb56f..f62443ea994e 100644 --- a/mlir/include/mlir/Pass/AnalysisManager.h +++ b/mlir/include/mlir/Pass/AnalysisManager.h @@ -28,12 +28,7 @@ namespace mlir { /// A special type used by analyses to provide an address that identifies a /// particular analysis set or a concrete analysis type. -struct AnalysisID { - template static AnalysisID *getID() { - static AnalysisID id; - return &id; - } -}; +using AnalysisID = ClassID; //===----------------------------------------------------------------------===// // Analysis Preservation and Concept Modeling diff --git a/mlir/include/mlir/Pass/PassInstrumentation.h b/mlir/include/mlir/Pass/PassInstrumentation.h index e1ff54bd4d49..0f427066296b 100644 --- a/mlir/include/mlir/Pass/PassInstrumentation.h +++ b/mlir/include/mlir/Pass/PassInstrumentation.h @@ -19,11 +19,12 @@ #define MLIR_PASS_PASSINSTRUMENTATION_H_ #include "mlir/Support/LLVM.h" +#include "mlir/Support/STLExtras.h" #include "llvm/ADT/Any.h" #include "llvm/ADT/StringRef.h" namespace mlir { -struct AnalysisID; +using AnalysisID = ClassID; class Pass; namespace detail { diff --git a/mlir/include/mlir/Pass/PassRegistry.h b/mlir/include/mlir/Pass/PassRegistry.h index 800484a6ba56..faa647297fae 100644 --- a/mlir/include/mlir/Pass/PassRegistry.h +++ b/mlir/include/mlir/Pass/PassRegistry.h @@ -24,6 +24,7 @@ #define MLIR_PASS_PASSREGISTRY_H_ #include "mlir/Support/LLVM.h" +#include "mlir/Support/STLExtras.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" @@ -40,12 +41,7 @@ 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. -struct alignas(8) PassID { - template static PassID *getID() { - static PassID id; - return &id; - } -}; +using PassID = ClassID; /// Structure to group information about a passes and pass pipelines (argument /// to invoke via mlir-opt, description, pass pipeline builder). diff --git a/mlir/include/mlir/Support/STLExtras.h b/mlir/include/mlir/Support/STLExtras.h index 33434fea41f7..7201c19ff9a9 100644 --- a/mlir/include/mlir/Support/STLExtras.h +++ b/mlir/include/mlir/Support/STLExtras.h @@ -63,6 +63,14 @@ inline void interleaveComma(const Container &c, raw_ostream &os) { interleave(c.begin(), c.end(), [&](T a) { os << a; }, [&]() { os << ", "; }); } +/// A special type used to provide an address for a given class that can act as +/// a unique identifier during pass registration. +struct alignas(8) ClassID { + template static ClassID *getID() { + static ClassID id; + return &id; + } +}; } // end namespace mlir // Allow tuples to be usable as DenseMap keys. diff --git a/mlir/lib/IR/MLIRContext.cpp b/mlir/lib/IR/MLIRContext.cpp index 249a1e185de8..8c0e98cd6c42 100644 --- a/mlir/lib/IR/MLIRContext.cpp +++ b/mlir/lib/IR/MLIRContext.cpp @@ -324,7 +324,7 @@ public: llvm::StringMap registeredOperations; /// This is a mapping from type identifier to Dialect for registered types. - DenseMap registeredTypes; + DenseMap registeredTypes; /// These are identifiers uniqued into this MLIRContext. llvm::StringMap identifiers; @@ -553,7 +553,7 @@ void Dialect::addOperation(AbstractOperation opInfo) { } /// Register a dialect-specific type with the current context. -void Dialect::addType(const TypeID *const typeID) { +void Dialect::addType(const ClassID *const typeID) { auto &impl = context->getImpl(); // Lock access to the context registry. @@ -822,7 +822,7 @@ StorageUniquer &MLIRContext::getTypeUniquer() { return getImpl().typeUniquer; } /// Get the dialect that registered the type with the provided typeid. const Dialect &TypeUniquer::lookupDialectForType(MLIRContext *ctx, - const TypeID *const typeID) { + const ClassID *const typeID) { auto &impl = ctx->getImpl(); auto it = impl.registeredTypes.find(typeID); assert(it != impl.registeredTypes.end() && "typeID is not registered.");