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>
168 void print(raw_ostream &os)
const;
176 return static_cast<const void *
>(
impl);
179 return Type(
reinterpret_cast<ImplType *
>(
const_cast<void *
>(pointer)));
183 template <
template <
typename T>
class Trait>
217 auto walk(WalkFns &&...walkFns) {
219 (walker.
addWalk(std::forward<WalkFns>(walkFns)), ...);
220 return walker.
walk<Order>(*this);
227 template <
typename... ReplacementFns>
228 auto replace(ReplacementFns &&...replacementFns) {
230 (replacer.
addReplacement(std::forward<ReplacementFns>(replacementFns)),
232 return replacer.
replace(*
this);
248 namespace TypeTrait {
250 template <
typename ConcreteType,
template <
typename>
class TraitType>
260 template <
typename ConcreteType,
typename Traits>
262 TypeTrait::TraitBase> {
286 namespace TypeTrait {
287 template <
typename ConcreteType>
300 template <
typename... Tys>
302 return llvm::isa<Tys...>(*this);
305 template <
typename... Tys>
307 return llvm::isa_and_present<Tys...>(*this);
310 template <
typename U>
312 return llvm::dyn_cast<U>(*
this);
315 template <
typename U>
317 return llvm::dyn_cast_or_null<U>(*
this);
320 template <
typename U>
322 return llvm::cast<U>(*
this);
343 template <
typename T>
344 struct DenseMapInfo<T, std::enable_if_t<std::is_base_of<mlir::Type, T>::value &&
345 !mlir::detail::IsInterface<T>::value>>
349 return T::getFromOpaquePointer(pointer);
353 return T::getFromOpaquePointer(pointer);
359 struct PointerLikeTypeTraits<
mlir::Type> {
367 static constexpr
int NumLowBitsAvailable = 3;
373 template <
typename To,
typename From>
376 std::enable_if_t<std::is_same_v<mlir::Type, std::remove_const_t<From>> ||
377 std::is_base_of_v<mlir::Type, From>>>
390 if constexpr (std::is_base_of_v<To, From>) {
394 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.
detail::Interface< ConcreteType, Type, Traits, Type, TypeTrait::TraitBase > InterfaceBase
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 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.
This header declares functions that assist transformations in the MemRef dialect.
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.