diff --git a/mlir/docs/WritingAPass.md b/mlir/docs/WritingAPass.md --- a/mlir/docs/WritingAPass.md +++ b/mlir/docs/WritingAPass.md @@ -753,8 +753,8 @@ unsigned &count; DominanceCounterInstrumentation(unsigned &count) : count(count) {} - void runAfterAnalysis(llvm::StringRef, AnalysisID *id, Operation *) override { - if (id == AnalysisID::getID()) + void runAfterAnalysis(llvm::StringRef, TypeID id, Operation *) override { + if (id == TypeID::get()) ++count; } }; diff --git a/mlir/include/mlir/IR/AttributeSupport.h b/mlir/include/mlir/IR/AttributeSupport.h --- a/mlir/include/mlir/IR/AttributeSupport.h +++ b/mlir/include/mlir/IR/AttributeSupport.h @@ -92,13 +92,13 @@ template static T get(MLIRContext *ctx, unsigned kind, Args &&... args) { return ctx->getAttributeUniquer().get( - getInitFn(ctx, T::getClassID()), kind, std::forward(args)...); + getInitFn(ctx, T::getTypeID()), kind, std::forward(args)...); } private: /// Returns a functor used to initialize new attribute storage instances. - static std::function - getInitFn(MLIRContext *ctx, const ClassID *const attrID); + static std::function getInitFn(MLIRContext *ctx, + TypeID attrID); }; } // namespace detail diff --git a/mlir/include/mlir/IR/Dialect.h b/mlir/include/mlir/IR/Dialect.h --- a/mlir/include/mlir/IR/Dialect.h +++ b/mlir/include/mlir/IR/Dialect.h @@ -160,7 +160,7 @@ /// Lookup an interface for the given ID if one is registered, otherwise /// nullptr. - const DialectInterface *getRegisteredInterface(ClassID *interfaceID) { + const DialectInterface *getRegisteredInterface(TypeID interfaceID) { auto it = registeredInterfaces.find(interfaceID); return it != registeredInterfaces.end() ? it->getSecond().get() : nullptr; } @@ -190,12 +190,12 @@ /// This method is used by derived classes to add their types to the set. template void addTypes() { - (void)std::initializer_list{0, (addSymbol(Args::getClassID()), 0)...}; + (void)std::initializer_list{0, (addSymbol(Args::getTypeID()), 0)...}; } /// This method is used by derived classes to add their attributes to the set. template void addAttributes() { - (void)std::initializer_list{0, (addSymbol(Args::getClassID()), 0)...}; + (void)std::initializer_list{0, (addSymbol(Args::getTypeID()), 0)...}; } /// Enable support for unregistered operations. @@ -215,7 +215,7 @@ private: // Register a symbol(e.g. type) with its given unique class identifier. - void addSymbol(const ClassID *const classID); + void addSymbol(TypeID typeID); Dialect(const Dialect &) = delete; void operator=(Dialect &) = delete; @@ -241,14 +241,14 @@ bool unknownTypesAllowed = false; /// A collection of registered dialect interfaces. - DenseMap> registeredInterfaces; + DenseMap> registeredInterfaces; /// Registers a specific dialect creation function with the global registry. /// Used through the registerDialect template. - /// Registrations are deduplicated by dialect ClassID and only the first + /// Registrations are deduplicated by dialect TypeID and only the first /// registration will be used. static void - registerDialectAllocator(const ClassID *classId, + registerDialectAllocator(TypeID typeID, const DialectAllocatorFunction &function); template friend void registerDialect(); @@ -260,7 +260,7 @@ /// Utility to register a dialect. Client can register their dialect with the /// global registry by calling registerDialect(); template void registerDialect() { - Dialect::registerDialectAllocator(ClassID::getID(), + Dialect::registerDialectAllocator(TypeID::get(), [](MLIRContext *ctx) { // Just allocate the dialect, the context // takes ownership of it. diff --git a/mlir/include/mlir/IR/DialectHooks.h b/mlir/include/mlir/IR/DialectHooks.h --- a/mlir/include/mlir/IR/DialectHooks.h +++ b/mlir/include/mlir/IR/DialectHooks.h @@ -38,15 +38,15 @@ private: /// Registers a function that will set hooks in the registered dialects. - /// Registrations are deduplicated by dialect ClassID and only the first + /// Registrations are deduplicated by dialect TypeID and only the first /// registration will be used. - static void registerDialectHooksSetter(const ClassID *classId, + static void registerDialectHooksSetter(TypeID typeID, const DialectHooksSetter &function); template friend void registerDialectHooks(StringRef dialectName); }; -void registerDialectHooksSetter(const ClassID *classId, +void registerDialectHooksSetter(TypeID typeID, const DialectHooksSetter &function); /// Utility to register dialect hooks. Client can register their dialect hooks @@ -55,7 +55,7 @@ template void registerDialectHooks(StringRef dialectName) { DialectHooks::registerDialectHooksSetter( - ClassID::getID(), [dialectName](MLIRContext *ctx) { + TypeID::get(), [dialectName](MLIRContext *ctx) { Dialect *dialect = ctx->getRegisteredDialect(dialectName); if (!dialect) { llvm::errs() << "error: cannot register hooks for unknown dialect '" diff --git a/mlir/include/mlir/IR/DialectInterface.h b/mlir/include/mlir/IR/DialectInterface.h --- a/mlir/include/mlir/IR/DialectInterface.h +++ b/mlir/include/mlir/IR/DialectInterface.h @@ -9,7 +9,7 @@ #ifndef MLIR_IR_DIALECTINTERFACE_H #define MLIR_IR_DIALECTINTERFACE_H -#include "mlir/Support/STLExtras.h" +#include "mlir/Support/TypeID.h" #include "llvm/ADT/DenseSet.h" namespace mlir { @@ -29,7 +29,7 @@ using Base = DialectInterfaceBase; /// Get a unique id for the derived interface type. - static ClassID *getInterfaceID() { return ClassID::getID(); } + static TypeID getInterfaceID() { return TypeID::get(); } protected: DialectInterfaceBase(Dialect *dialect) : BaseT(dialect, getInterfaceID()) {} @@ -50,10 +50,10 @@ Dialect *getDialect() const { return dialect; } /// Return the derived interface id. - ClassID *getID() const { return interfaceID; } + TypeID getID() const { return interfaceID; } protected: - DialectInterface(Dialect *dialect, ClassID *id) + DialectInterface(Dialect *dialect, TypeID id) : dialect(dialect), interfaceID(id) {} private: @@ -61,7 +61,7 @@ Dialect *dialect; /// The unique identifier for the derived interface type. - ClassID *interfaceID; + TypeID interfaceID; }; //===----------------------------------------------------------------------===// @@ -93,7 +93,7 @@ using InterfaceVectorT = std::vector; public: - DialectInterfaceCollectionBase(MLIRContext *ctx, ClassID *interfaceKind); + DialectInterfaceCollectionBase(MLIRContext *ctx, TypeID interfaceKind); virtual ~DialectInterfaceCollectionBase(); protected: diff --git a/mlir/include/mlir/IR/Location.h b/mlir/include/mlir/IR/Location.h --- a/mlir/include/mlir/IR/Location.h +++ b/mlir/include/mlir/IR/Location.h @@ -237,7 +237,7 @@ template static Location get(T underlyingLocation, MLIRContext *context) { return get(reinterpret_cast(underlyingLocation), - ClassID::getID(), UnknownLoc::get(context)); + TypeID::get(), UnknownLoc::get(context)); } /// Returns an instance of opaque location which contains a given pointer to @@ -245,7 +245,7 @@ template static Location get(T underlyingLocation, Location fallbackLocation) { return get(reinterpret_cast(underlyingLocation), - ClassID::getID(), fallbackLocation); + TypeID::get(), fallbackLocation); } /// Returns a pointer to some data structure that opaque location stores. @@ -270,14 +270,14 @@ /// to an object of particular type. template static bool isa(Location location) { auto opaque_loc = location.dyn_cast(); - return opaque_loc && opaque_loc.getClassId() == ClassID::getID(); + return opaque_loc && opaque_loc.getUnderlyingTypeID() == TypeID::get(); } /// Returns a pointer to the corresponding object. uintptr_t getUnderlyingLocation() const; - /// Returns a ClassID* that represents the underlying objects c++ type. - ClassID *getClassId() const; + /// Returns a TypeID that represents the underlying objects c++ type. + TypeID getUnderlyingTypeID() const; /// Returns a fallback location. Location getFallbackLocation() const; @@ -288,7 +288,7 @@ } private: - static Location get(uintptr_t underlyingLocation, ClassID *classID, + static Location get(uintptr_t underlyingLocation, TypeID typeID, Location fallbackLocation); }; diff --git a/mlir/include/mlir/IR/OpDefinition.h b/mlir/include/mlir/IR/OpDefinition.h --- a/mlir/include/mlir/IR/OpDefinition.h +++ b/mlir/include/mlir/IR/OpDefinition.h @@ -1169,7 +1169,7 @@ /// Return true if this "op class" can match against the specified operation. static bool classof(Operation *op) { if (auto *abstractOp = op->getAbstractOperation()) - return ClassID::getID() == abstractOp->classID; + return TypeID::get() == abstractOp->typeID; return op->getName().getStringRef() == ConcreteType::getOperationName(); } @@ -1262,15 +1262,15 @@ } }; - /// Returns true if this operation contains the trait for the given classID. - static bool hasTrait(ClassID *traitID) { - return llvm::is_contained(llvm::makeArrayRef({ClassID::getID()...}), + /// Returns true if this operation contains the trait for the given typeID. + static bool hasTrait(TypeID traitID) { + return llvm::is_contained(llvm::makeArrayRef({TypeID::get()...}), traitID); } /// Returns an opaque pointer to a concept instance of the interface with the /// given ID if one was registered to this operation. - static void *getRawInterface(ClassID *id) { + static void *getRawInterface(TypeID id) { return InterfaceLookup::template lookup...>(id); } @@ -1284,7 +1284,7 @@ template static typename std::enable_if::value, void *>::type - lookup(ClassID *interfaceID) { + lookup(TypeID interfaceID) { return (T::getInterfaceID() == interfaceID) ? &T::instance() : nullptr; } @@ -1292,12 +1292,12 @@ template static typename std::enable_if::value, void *>::type - lookup(ClassID *) { + lookup(TypeID) { return nullptr; } template - static void *lookup(ClassID *interfaceID) { + static void *lookup(TypeID interfaceID) { auto *concept = lookup(interfaceID); return concept ? concept : lookup(interfaceID); } @@ -1343,14 +1343,14 @@ static bool classof(Operation *op) { return getInterfaceFor(op); } /// Define an accessor for the ID of this interface. - static ClassID *getInterfaceID() { return ClassID::getID(); } + static TypeID getInterfaceID() { return TypeID::get(); } /// This is a special trait that registers a given interface with an /// operation. template struct Trait : public OpTrait::TraitBase { /// Define an accessor for the ID of this interface. - static ClassID *getInterfaceID() { return ClassID::getID(); } + static TypeID getInterfaceID() { return TypeID::get(); } /// Provide an accessor to a static instance of the interface model for the /// concrete operation type. diff --git a/mlir/include/mlir/IR/OperationSupport.h b/mlir/include/mlir/IR/OperationSupport.h --- a/mlir/include/mlir/IR/OperationSupport.h +++ b/mlir/include/mlir/IR/OperationSupport.h @@ -94,7 +94,7 @@ Dialect &dialect; /// The unique identifier of the derived Op class. - ClassID *classID; + TypeID typeID; /// Use the specified object to parse this ops custom assembly format. ParseResult (&parseAssembly)(OpAsmParser &parser, OperationState &result); @@ -149,7 +149,7 @@ /// Returns if the operation has a particular trait. template