9#ifndef MLIR_TOOLS_PDLL_AST_TYPES_H_
10#define MLIR_TOOLS_PDLL_AST_TYPES_H_
14#include "llvm/ADT/SmallVectorExtras.h"
36 template <
typename ImplT,
typename BaseT = Type>
53 explicit operator bool()
const {
return impl; }
76 return static_cast<const T *
>(
impl);
107template <
typename ConcreteT,
typename KeyT =
void>
117 return new (alloc.
allocate<ConcreteT>()) ConcreteT(
key);
130template <
typename ConcreteT>
154 std::pair<StringRef, const ods::Operation *>> {
159 const std::pair<StringRef, const ods::Operation *> &
key) {
185 std::pair<ArrayRef<Type>, ArrayRef<StringRef>>> {
192 key.second, [&](StringRef name) { return alloc.copyInto(name); });
252 std::optional<StringRef> name = std::nullopt,
257 std::optional<StringRef>
getName()
const;
288 using RangeType::RangeType;
304 using RangeType::RangeType;
408 return llvm::hash_value(val.
getImpl());
418template <
typename To,
typename From>
422 std::is_same_v<mlir::pdll::ast::Type, std::remove_const_t<From>> ||
423 std::is_base_of_v<mlir::pdll::ast::Type, From>>>
429 if constexpr (std::is_base_of_v<To, From>) {
432 return To::classof(ty);
#define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME)
This class acts as the base storage that all storage classes must derived from.
This is a utility allocator used to allocate memory for instances of derived types.
ArrayRef< T > copyInto(ArrayRef< T > elements)
Copy the specified array of elements into memory managed by our bump pointer allocator.
T * allocate()
Allocate an instance of the provided type.
This class provides an efficient unique identifier for a specific C++ type.
static TypeID get()
Construct a type info object for the given type T.
This class represents a PDLL type that corresponds to an mlir::Attribute.
static AttributeType get(Context &context)
Return an instance of the Attribute type.
This class represents a PDLL type that corresponds to a constraint.
static ConstraintType get(Context &context)
Return an instance of the Constraint type.
This class represents the main context of the PDLL AST.
This class represents a PDLL type that corresponds to an mlir::Operation.
const ods::Operation * getODSOperation() const
Return the ODS operation that this type refers to, or nullptr if the ODS operation is unknown.
static OperationType get(Context &context, std::optional< StringRef > name=std::nullopt, const ods::Operation *odsOp=nullptr)
Return an instance of the Operation type with an optional operation name.
std::optional< StringRef > getName() const
Return the name of this operation type, or std::nullopt if it doesn't have on.
This class represents a PDLL type that corresponds to a range of elements with a given element type.
Type getElementType() const
Return the element type of this range.
static RangeType get(Context &context, Type elementType)
Return an instance of the Range type with the given element type.
This class represents a PDLL type that corresponds to a rewrite reference.
static RewriteType get(Context &context)
Return an instance of the Rewrite type.
This class represents a PDLL tuple type, i.e.
size_t size() const
Return the number of elements within this tuple.
ArrayRef< StringRef > getElementNames() const
Return the element names of this tuple.
bool empty() const
Return if the tuple has no elements.
ArrayRef< Type > getElementTypes() const
Return the element types of this tuple.
static TupleType get(Context &context, ArrayRef< Type > elementTypes, ArrayRef< StringRef > elementNames)
Return an instance of the Tuple type.
This class represents a PDLL type that corresponds to an mlir::TypeRange.
static TypeRangeType get(Context &context)
Return an instance of the TypeRange type.
static bool classof(Type type)
Provide type casting support.
This class represents a PDLL type that corresponds to an mlir::Type.
static TypeType get(Context &context)
Return an instance of the Type type.
This class provides several utilities when defining derived type classes.
TypeBase< ImplT, BaseT > Base
static bool classof(Type type)
Provide type casting support.
TypeID getTypeID() const
Return the TypeID instance of this type.
bool operator!=(const Type &other) const
Storage * getImpl() const
Return the internal storage instance of this type.
void print(raw_ostream &os) const
Print this type to the given stream.
Type(Storage *impl=nullptr)
const T * getImplAs() const
Return the internal storage instance of this type reinterpreted as the given derived storage type.
Type refineWith(Type other) const
Try to refine this type with the one provided.
bool operator==(const Type &other) const
This class represents a PDLL type that corresponds to an mlir::ValueRange.
static bool classof(Type type)
Provide type casting support.
static ValueRangeType get(Context &context)
Return an instance of the ValueRange type.
This class represents a PDLL type that corresponds to an mlir::Value.
static ValueType get(Context &context)
Return an instance of the Value type.
This class provides an ODS representation of a specific operation.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
llvm::hash_code hash_value(Type type)
raw_ostream & operator<<(raw_ostream &os, Type type)
Include the generated interface declarations.
llvm::DenseMapInfo< T, Enable > DenseMapInfo
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
static bool isPossible(mlir::pdll::ast::Type ty)
static To doCast(mlir::pdll::ast::Type ty)
static bool isEqual(mlir::pdll::ast::Type lhs, mlir::pdll::ast::Type rhs)
static unsigned getHashValue(mlir::pdll::ast::Type val)
static mlir::pdll::ast::Type getTombstoneKey()
static mlir::pdll::ast::Type getEmptyKey()
TypeID typeID
The type identifier for the derived type class.
static OperationTypeStorage * construct(StorageUniquer::StorageAllocator &alloc, const std::pair< StringRef, const ods::Operation * > &key)
static TupleTypeStorage * construct(StorageUniquer::StorageAllocator &alloc, std::pair< ArrayRef< Type >, ArrayRef< StringRef > > key)
A utility CRTP base class that defines many of the necessary utilities for defining a PDLL AST Type.
TypeStorageBase(KeyTy key)
bool operator==(const KeyTy &key) const
Utility methods required by the storage allocator.
const KeyTy & getValue() const
Return the key value of this storage class.
static ConcreteT * construct(StorageUniquer::StorageAllocator &alloc, const KeyTy &key)
Construct an instance with the given storage allocator.
TypeStorageBase< ConcreteT, KeyT > Base