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>
100 [[deprecated(
"Use mlir::isa<U>() instead")]]
102 template <
typename... Tys>
103 [[deprecated(
"Use mlir::isa_and_nonnull<U>() instead")]]
105 template <
typename U>
106 [[deprecated(
"Use mlir::dyn_cast<U>() instead")]]
108 template <
typename U>
109 [[deprecated(
"Use mlir::dyn_cast_or_null<U>() instead")]]
111 template <
typename U>
112 [[deprecated(
"Use mlir::cast<U>() instead")]]
181 void print(raw_ostream &os)
const;
189 return static_cast<const void *
>(
impl);
192 return Type(
reinterpret_cast<ImplType *
>(
const_cast<void *
>(pointer)));
197 template <
typename InterfaceT>
201 mlir::isa<InterfaceT>(*
this);
205 template <
template <
typename T>
class Trait>
239 auto walk(WalkFns &&...walkFns) {
241 (walker.
addWalk(std::forward<WalkFns>(walkFns)), ...);
242 return walker.
walk<Order>(*this);
249 template <
typename... ReplacementFns>
250 auto replace(ReplacementFns &&...replacementFns) {
252 (replacer.
addReplacement(std::forward<ReplacementFns>(replacementFns)),
254 return replacer.
replace(*
this);
270 namespace TypeTrait {
272 template <
typename ConcreteType,
template <
typename>
class TraitType>
282 template <
typename ConcreteType,
typename Traits>
284 TypeTrait::TraitBase> {
299 llvm::getTypeName<ConcreteType>());
316 namespace TypeTrait {
317 template <
typename ConcreteType>
330 template <
typename... Tys>
332 return llvm::isa<Tys...>(*this);
335 template <
typename... Tys>
337 return llvm::isa_and_present<Tys...>(*this);
340 template <
typename U>
342 return llvm::dyn_cast<U>(*
this);
345 template <
typename U>
347 return llvm::dyn_cast_or_null<U>(*
this);
350 template <
typename U>
352 return llvm::cast<U>(*
this);
373 template <
typename T>
374 struct DenseMapInfo<T, std::enable_if_t<std::is_base_of<mlir::Type, T>::value &&
375 !mlir::detail::IsInterface<T>::value>>
379 return T::getFromOpaquePointer(pointer);
383 return T::getFromOpaquePointer(pointer);
389 struct PointerLikeTypeTraits<
mlir::Type> {
397 static constexpr
int NumLowBitsAvailable = 3;
403 template <
typename To,
typename From>
406 std::enable_if_t<std::is_same_v<mlir::Type, std::remove_const_t<From>> ||
407 std::is_base_of_v<mlir::Type, From>>>
420 if constexpr (std::is_base_of_v<To, From>) {
423 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.
This is an attribute/type replacer that is naively cached.
Attribute replace(Attribute attr)
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.
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 isFloat8E3M4() const
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 isFloat6E3M2FN() const
bool isInteger() const
Return true if this is an integer type (with the specified width).
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 isFloat8E8M0FNU() const
bool isFloat4E2M1FN() 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 isFloat6E2M3FN() const
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 isFloat8E4M3() const
bool isFloat8E5M2FNUZ() const
bool isSignlessIntOrIndexOrFloat() const
Return true if this is a signless integer, index, or float type.
void addReplacement(ReplaceFn< Attribute > fn)
Register a replacement function for mapping a given attribute or 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.
The OpAsmOpInterface, see OpAsmInterface.td for more details.
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.