9 #ifndef MLIR_IR_TYPES_H
10 #define MLIR_IR_TYPES_H
13 #include "llvm/ADT/ArrayRef.h"
14 #include "llvm/ADT/DenseMapInfo.h"
15 #include "llvm/Support/PointerLikeTypeTraits.h"
77 template <
typename ConcreteType,
typename BaseType,
typename StorageType,
78 template <
typename T>
class... Traits>
86 constexpr
Type() =
default;
95 explicit operator bool()
const {
return impl; }
99 template <
typename... Tys>
101 template <
typename... Tys>
103 template <
typename U>
105 template <
typename U>
107 template <
typename U>
169 void print(raw_ostream &os)
const;
177 return static_cast<const void *
>(
impl);
180 return Type(
reinterpret_cast<ImplType *
>(
const_cast<void *
>(pointer)));
185 template <
typename InterfaceT>
189 mlir::isa<InterfaceT>(*
this);
193 template <
template <
typename T>
class Trait>
227 auto walk(WalkFns &&...walkFns) {
229 (walker.
addWalk(std::forward<WalkFns>(walkFns)), ...);
230 return walker.
walk<Order>(*this);
237 template <
typename... ReplacementFns>
238 auto replace(ReplacementFns &&...replacementFns) {
240 (replacer.
addReplacement(std::forward<ReplacementFns>(replacementFns)),
242 return replacer.
replace(*
this);
258 namespace TypeTrait {
260 template <
typename ConcreteType,
template <
typename>
class TraitType>
270 template <
typename ConcreteType,
typename Traits>
272 TypeTrait::TraitBase> {
287 llvm::getTypeName<ConcreteType>());
304 namespace TypeTrait {
305 template <
typename ConcreteType>
318 template <
typename... Tys>
320 return llvm::isa<Tys...>(*this);
323 template <
typename... Tys>
325 return llvm::isa_and_present<Tys...>(*this);
328 template <
typename U>
330 return llvm::dyn_cast<U>(*
this);
333 template <
typename U>
335 return llvm::dyn_cast_or_null<U>(*
this);
338 template <
typename U>
340 return llvm::cast<U>(*
this);
361 template <
typename T>
362 struct DenseMapInfo<T, std::enable_if_t<std::is_base_of<mlir::Type, T>::value &&
363 !mlir::detail::IsInterface<T>::value>>
367 return T::getFromOpaquePointer(pointer);
371 return T::getFromOpaquePointer(pointer);
377 struct PointerLikeTypeTraits<
mlir::Type> {
385 static constexpr
int NumLowBitsAvailable = 3;
391 template <
typename To,
typename From>
394 std::enable_if_t<std::is_same_v<mlir::Type, std::remove_const_t<From>> ||
395 std::is_base_of_v<mlir::Type, From>>>
408 if constexpr (std::is_base_of_v<To, From>) {
411 return To::classof(ty);
This class contains all of the static information common to all instances of a registered Type.
Type replaceImmediateSubElements(Type type, ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Replace the immediate sub-elements of the given type.
void walkImmediateSubElements(Type type, function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Walk the immediate sub-elements of the given type.
T::Concept * getInterface() const
Returns an instance of the concept object for the given interface if it was registered to this type,...
bool hasTrait() const
Returns true if the type has a particular trait.
This class provides management for the lifetime of the state used when printing the IR.
Attribute replace(Attribute attr)
Replace the given attribute/type, and recursively replace any sub elements.
void addReplacement(ReplaceFn< Attribute > fn)
Register a replacement function for mapping a given attribute or type.
void addWalk(WalkFn< Attribute > &&fn)
Register a walk function for a given attribute or type.
WalkResult walk(T element)
Walk the given attribute/type, and recursively walk any sub elements.
Attributes are known-constant values of operations.
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
MLIRContext is the top-level object for a collection of MLIR operations.
This class provides an efficient unique identifier for a specific C++ type.
This class represents the base of a type interface.
static InterfaceBase::Concept * getInterfaceFor(Type type)
Returns the impl interface instance for the given type.
friend InterfaceBase
Allow access to 'getInterfaceFor'.
Base storage class appearing in a Type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
void print(raw_ostream &os) const
Print the current type.
const void * getAsOpaquePointer() const
Methods for supporting PointerLikeTypeTraits.
bool isInteger(unsigned width) const
Return true if this is an integer type with the specified width.
Dialect & getDialect() const
Get the dialect this type is registered to.
auto replaceImmediateSubElements(ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
Replace the immediately nested sub-attributes and sub-types with those provided.
Type(const Type &other)=default
bool isSignlessIntOrIndex() const
Return true if this is a signless integer or index type.
U dyn_cast_or_null() const
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
bool isa_and_nonnull() const
bool isSignedInteger() const
Return true if this is a signed integer type (with the specified width).
bool isFloat8E4M3FN() const
bool isSignlessInteger() const
Return true if this is a signless integer type (with the specified width).
friend ::llvm::hash_code hash_value(Type arg)
static Type getFromOpaquePointer(const void *pointer)
bool hasTrait()
Returns true if the type was registered with a particular trait.
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
void walkImmediateSubElements(function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
Walk all of the immediately nested sub-attributes and sub-types.
bool hasPromiseOrImplementsInterface()
Returns true if InterfaceT has been promised by the dialect or implemented.
bool isFloat8E4M3FNUZ() const
bool isUnsignedInteger() const
Return true if this is an unsigned integer type (with the specified width).
const AbstractTy & getAbstractType() const
Return the abstract type descriptor for this type.
bool isIntOrIndex() const
Return true if this is an integer (of any signedness) or an index type.
bool isFloat8E4M3B11FNUZ() const
Type & operator=(const Type &other)=default
ImplType * getImpl() const
Return the Type implementation.
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
Type(const ImplType *impl)
bool isFloat8E5M2() const
bool operator==(Type other) const
TypeID getTypeID()
Return a unique identifier for the concrete type.
bool operator!=(Type other) const
auto replace(ReplacementFns &&...replacementFns)
Recursively replace all of the nested sub-attributes and sub-types using the provided map functions.
auto walk(WalkFns &&...walkFns)
Walk this type and all attibutes/types nested within using the provided walk functions.
bool isSignlessIntOrFloat() const
Return true of this is a signless integer or a float type.
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
bool isFloat8E5M2FNUZ() const
bool isSignlessIntOrIndexOrFloat() const
Return true if this is a signless integer, index, or float type.
This class represents an abstract interface.
Interface< ConcreteType, Type, Traits, Type, TypeTrait::TraitBase > InterfaceBase
typename Traits::Concept Concept
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
Helper class for implementing traits for storage classes.
Include the generated interface declarations.
bool hasPromisedInterface(Dialect &dialect, TypeID interfaceRequestorID, TypeID interfaceID)
Checks if a promise has been made for the interface/requestor pair.
void handleUseOfUndefinedPromisedInterface(Dialect &dialect, TypeID interfaceRequestorID, TypeID interfaceID, StringRef interfaceName)
Checks if the given interface, which is attempting to be used, is a promised interface of this dialec...
Include the generated interface declarations.
WalkOrder
Traversal order for region, block and operation walk utilities.
inline ::llvm::hash_code hash_value(AffineExpr arg)
Make AffineExpr hashable.
raw_ostream & operator<<(raw_ostream &os, const AliasResult &result)
static bool isPossible(mlir::Type ty)
Arguments are taken as mlir::Type here and not as From, because when casting from an intermediate typ...
static To doCast(mlir::Type ty)
static T getTombstoneKey()
static mlir::Type getEmptyKey()
static unsigned getHashValue(mlir::Type val)
static mlir::Type getTombstoneKey()
static bool isEqual(mlir::Type LHS, mlir::Type RHS)
static void * getAsVoidPointer(mlir::Type I)
static mlir::Type getFromVoidPointer(void *P)
This trait is used to determine if a storage user, like Type, is mutable or not.
A utility class to get, or create, unique instances of types within an MLIRContext.