forked from OSchip/llvm-project
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:
parent
323e1bf7f8
commit
fa6eb9bfaf
|
@ -194,7 +194,7 @@ protected:
|
||||||
};
|
};
|
||||||
|
|
||||||
// Register a type with its given unqiue type identifer.
|
// 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.
|
// Enable support for unregistered operations.
|
||||||
void allowUnknownOperations(bool allow = true) { allowUnknownOps = allow; }
|
void allowUnknownOperations(bool allow = true) { allowUnknownOps = allow; }
|
||||||
|
|
|
@ -28,18 +28,10 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
namespace mlir {
|
namespace mlir {
|
||||||
|
struct ClassID;
|
||||||
class Dialect;
|
class Dialect;
|
||||||
class MLIRContext;
|
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
|
// TypeStorage
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -123,7 +115,7 @@ private:
|
||||||
|
|
||||||
/// Get the dialect that registered the type with the provided typeid.
|
/// Get the dialect that registered the type with the provided typeid.
|
||||||
static const Dialect &lookupDialectForType(MLIRContext *ctx,
|
static const Dialect &lookupDialectForType(MLIRContext *ctx,
|
||||||
const TypeID *const typeID);
|
const ClassID *const typeID);
|
||||||
};
|
};
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "mlir/IR/TypeSupport.h"
|
#include "mlir/IR/TypeSupport.h"
|
||||||
#include "mlir/Support/LLVM.h"
|
#include "mlir/Support/LLVM.h"
|
||||||
#include "mlir/Support/LogicalResult.h"
|
#include "mlir/Support/LogicalResult.h"
|
||||||
|
#include "mlir/Support/STLExtras.h"
|
||||||
#include "llvm/ADT/ArrayRef.h"
|
#include "llvm/ADT/ArrayRef.h"
|
||||||
#include "llvm/ADT/DenseMapInfo.h"
|
#include "llvm/ADT/DenseMapInfo.h"
|
||||||
|
|
||||||
|
@ -135,7 +136,7 @@ public:
|
||||||
using ImplType = StorageType;
|
using ImplType = StorageType;
|
||||||
|
|
||||||
/// Return a unique identifier for the concrete type.
|
/// Return a unique identifier for the concrete type.
|
||||||
static TypeID *getTypeID() { return TypeID::getID<ConcreteType>(); }
|
static ClassID *getTypeID() { return ClassID::getID<ConcreteType>(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/// Get or create a new ConcreteType instance within the context. This
|
/// Get or create a new ConcreteType instance within the context. This
|
||||||
|
|
|
@ -28,12 +28,7 @@
|
||||||
namespace mlir {
|
namespace mlir {
|
||||||
/// A special type used by analyses to provide an address that identifies a
|
/// A special type used by analyses to provide an address that identifies a
|
||||||
/// particular analysis set or a concrete analysis type.
|
/// particular analysis set or a concrete analysis type.
|
||||||
struct AnalysisID {
|
using AnalysisID = ClassID;
|
||||||
template <typename AnalysisT> static AnalysisID *getID() {
|
|
||||||
static AnalysisID id;
|
|
||||||
return &id;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Analysis Preservation and Concept Modeling
|
// Analysis Preservation and Concept Modeling
|
||||||
|
|
|
@ -19,11 +19,12 @@
|
||||||
#define MLIR_PASS_PASSINSTRUMENTATION_H_
|
#define MLIR_PASS_PASSINSTRUMENTATION_H_
|
||||||
|
|
||||||
#include "mlir/Support/LLVM.h"
|
#include "mlir/Support/LLVM.h"
|
||||||
|
#include "mlir/Support/STLExtras.h"
|
||||||
#include "llvm/ADT/Any.h"
|
#include "llvm/ADT/Any.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
|
|
||||||
namespace mlir {
|
namespace mlir {
|
||||||
struct AnalysisID;
|
using AnalysisID = ClassID;
|
||||||
class Pass;
|
class Pass;
|
||||||
|
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define MLIR_PASS_PASSREGISTRY_H_
|
#define MLIR_PASS_PASSREGISTRY_H_
|
||||||
|
|
||||||
#include "mlir/Support/LLVM.h"
|
#include "mlir/Support/LLVM.h"
|
||||||
|
#include "mlir/Support/STLExtras.h"
|
||||||
#include "llvm/ADT/StringRef.h"
|
#include "llvm/ADT/StringRef.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/Compiler.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
|
/// A special type used by transformation passes to provide an address that can
|
||||||
/// act as a unique identifier during pass registration.
|
/// act as a unique identifier during pass registration.
|
||||||
struct alignas(8) PassID {
|
using PassID = ClassID;
|
||||||
template <typename PassT> static PassID *getID() {
|
|
||||||
static PassID id;
|
|
||||||
return &id;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Structure to group information about a passes and pass pipelines (argument
|
/// Structure to group information about a passes and pass pipelines (argument
|
||||||
/// to invoke via mlir-opt, description, pass pipeline builder).
|
/// to invoke via mlir-opt, description, pass pipeline builder).
|
||||||
|
|
|
@ -63,6 +63,14 @@ inline void interleaveComma(const Container<T> &c, raw_ostream &os) {
|
||||||
interleave(c.begin(), c.end(), [&](T a) { os << a; }, [&]() { 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
|
} // end namespace mlir
|
||||||
|
|
||||||
// Allow tuples to be usable as DenseMap keys.
|
// Allow tuples to be usable as DenseMap keys.
|
||||||
|
|
|
@ -324,7 +324,7 @@ public:
|
||||||
llvm::StringMap<AbstractOperation> registeredOperations;
|
llvm::StringMap<AbstractOperation> registeredOperations;
|
||||||
|
|
||||||
/// This is a mapping from type identifier to Dialect for registered types.
|
/// 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.
|
/// These are identifiers uniqued into this MLIRContext.
|
||||||
llvm::StringMap<char, llvm::BumpPtrAllocator &> identifiers;
|
llvm::StringMap<char, llvm::BumpPtrAllocator &> identifiers;
|
||||||
|
@ -553,7 +553,7 @@ void Dialect::addOperation(AbstractOperation opInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Register a dialect-specific type with the current context.
|
/// 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();
|
auto &impl = context->getImpl();
|
||||||
|
|
||||||
// Lock access to the context registry.
|
// 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.
|
/// Get the dialect that registered the type with the provided typeid.
|
||||||
const Dialect &TypeUniquer::lookupDialectForType(MLIRContext *ctx,
|
const Dialect &TypeUniquer::lookupDialectForType(MLIRContext *ctx,
|
||||||
const TypeID *const typeID) {
|
const ClassID *const typeID) {
|
||||||
auto &impl = ctx->getImpl();
|
auto &impl = ctx->getImpl();
|
||||||
auto it = impl.registeredTypes.find(typeID);
|
auto it = impl.registeredTypes.find(typeID);
|
||||||
assert(it != impl.registeredTypes.end() && "typeID is not registered.");
|
assert(it != impl.registeredTypes.end() && "typeID is not registered.");
|
||||||
|
|
Loading…
Reference in New Issue