Add a new ClassID utility class that allows for generating unique identifiers for class types. This replaces the duplicated functionality of AnalysisID/PassID/etc.

--

PiperOrigin-RevId: 247237835
This commit is contained in:
River Riddle 2019-05-08 10:23:10 -07:00 committed by Mehdi Amini
parent 323e1bf7f8
commit fa6eb9bfaf
8 changed files with 21 additions and 28 deletions

View File

@ -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; }

View File

@ -28,18 +28,10 @@
#include <memory>
namespace mlir {
struct ClassID;
class Dialect;
class MLIRContext;
/// TypeID is used to provide a unique address identifier for derived Type
/// classes.
struct TypeID {
template <typename T> 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

View File

@ -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<ConcreteType>(); }
static ClassID *getTypeID() { return ClassID::getID<ConcreteType>(); }
protected:
/// Get or create a new ConcreteType instance within the context. This

View File

@ -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 <typename AnalysisT> static AnalysisID *getID() {
static AnalysisID id;
return &id;
}
};
using AnalysisID = ClassID;
//===----------------------------------------------------------------------===//
// Analysis Preservation and Concept Modeling

View File

@ -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 {

View File

@ -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<Pass *()>;
/// 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 <typename PassT> 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).

View File

@ -63,6 +63,14 @@ inline void interleaveComma(const Container<T> &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 <typename T> static ClassID *getID() {
static ClassID id;
return &id;
}
};
} // end namespace mlir
// Allow tuples to be usable as DenseMap keys.

View File

@ -324,7 +324,7 @@ public:
llvm::StringMap<AbstractOperation> registeredOperations;
/// This is a mapping from type identifier to Dialect for registered types.
DenseMap<const TypeID *, Dialect *> registeredTypes;
DenseMap<const ClassID *, Dialect *> registeredTypes;
/// These are identifiers uniqued into this MLIRContext.
llvm::StringMap<char, llvm::BumpPtrAllocator &> 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.");