MLIR  19.0.0git
Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | Friends | List of all members
mlir::Type Class Reference

Instances of the Type class are uniqued, have an immutable identifier and an optional mutable component. More...

#include "mlir/IR/Types.h"

+ Inheritance diagram for mlir::Type:

Public Types

template<typename ConcreteType , typename BaseType , typename StorageType , template< typename T > class... Traits>
using TypeBase = detail::StorageUserBase< ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits... >
 Utility class for implementing types. More...
 
using ImplType = TypeStorage
 
using AbstractTy = AbstractType
 

Public Member Functions

constexpr Type ()=default
 
 Type (const ImplType *impl)
 
 Type (const Type &other)=default
 
Typeoperator= (const Type &other)=default
 
bool operator== (Type other) const
 
bool operator!= (Type other) const
 
 operator bool () const
 
bool operator! () const
 
template<typename... Tys>
bool isa () const
 
template<typename... Tys>
bool isa_and_nonnull () const
 
template<typename U >
dyn_cast () const
 
template<typename U >
dyn_cast_or_null () const
 
template<typename U >
cast () const
 
TypeID getTypeID ()
 Return a unique identifier for the concrete type. More...
 
MLIRContextgetContext () const
 Return the MLIRContext in which this type was uniqued. More...
 
DialectgetDialect () const
 Get the dialect this type is registered to. More...
 
bool isIndex () const
 
bool isFloat8E5M2 () const
 
bool isFloat8E4M3FN () const
 
bool isFloat8E5M2FNUZ () const
 
bool isFloat8E4M3FNUZ () const
 
bool isFloat8E4M3B11FNUZ () const
 
bool isBF16 () const
 
bool isF16 () const
 
bool isTF32 () const
 
bool isF32 () const
 
bool isF64 () const
 
bool isF80 () const
 
bool isF128 () const
 
bool isInteger () const
 Return true if this is an integer type (with the specified width). More...
 
bool isInteger (unsigned width) const
 Return true if this is an integer type with the specified width. More...
 
bool isSignlessInteger () const
 Return true if this is a signless integer type (with the specified width). More...
 
bool isSignlessInteger (unsigned width) const
 
bool isSignedInteger () const
 Return true if this is a signed integer type (with the specified width). More...
 
bool isSignedInteger (unsigned width) const
 
bool isUnsignedInteger () const
 Return true if this is an unsigned integer type (with the specified width). More...
 
bool isUnsignedInteger (unsigned width) const
 
unsigned getIntOrFloatBitWidth () const
 Return the bit width of an integer or a float type, assert failure on other types. More...
 
bool isSignlessIntOrIndex () const
 Return true if this is a signless integer or index type. More...
 
bool isSignlessIntOrIndexOrFloat () const
 Return true if this is a signless integer, index, or float type. More...
 
bool isSignlessIntOrFloat () const
 Return true of this is a signless integer or a float type. More...
 
bool isIntOrIndex () const
 Return true if this is an integer (of any signedness) or an index type. More...
 
bool isIntOrFloat () const
 Return true if this is an integer (of any signedness) or a float type. More...
 
bool isIntOrIndexOrFloat () const
 Return true if this is an integer (of any signedness), index, or float type. More...
 
void print (raw_ostream &os) const
 Print the current type. More...
 
void print (raw_ostream &os, AsmState &state) const
 
void dump () const
 
const void * getAsOpaquePointer () const
 Methods for supporting PointerLikeTypeTraits. More...
 
template<typename InterfaceT >
bool hasPromiseOrImplementsInterface ()
 Returns true if InterfaceT has been promised by the dialect or implemented. More...
 
template<template< typename T > class Trait>
bool hasTrait ()
 Returns true if the type was registered with a particular trait. More...
 
const AbstractTygetAbstractType () const
 Return the abstract type descriptor for this type. More...
 
ImplTypegetImpl () const
 Return the Type implementation. More...
 
void walkImmediateSubElements (function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
 Walk all of the immediately nested sub-attributes and sub-types. More...
 
auto replaceImmediateSubElements (ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
 Replace the immediately nested sub-attributes and sub-types with those provided. More...
 
template<WalkOrder Order = WalkOrder::PostOrder, typename... WalkFns>
auto walk (WalkFns &&...walkFns)
 Walk this type and all attibutes/types nested within using the provided walk functions. More...
 
template<typename... ReplacementFns>
auto replace (ReplacementFns &&...replacementFns)
 Recursively replace all of the nested sub-attributes and sub-types using the provided map functions. More...
 

Static Public Member Functions

static Type getFromOpaquePointer (const void *pointer)
 

Protected Attributes

ImplTypeimpl {nullptr}
 

Friends

::llvm::hash_code hash_value (Type arg)
 

Detailed Description

Instances of the Type class are uniqued, have an immutable identifier and an optional mutable component.

They wrap a pointer to the storage object owned by MLIRContext. Therefore, instances of Type are passed around by value.

Some types are "primitives" meaning they do not have any parameters, for example the Index type. Parametric types have additional information that differentiates the types of the same class, for example the Integer type has bitwidth, making i8 and i16 belong to the same kind by be different instances of the IntegerType. Type parameters are part of the unique immutable key. The mutable component of the type can be modified after the type is created, but cannot affect the identity of the type.

Types are constructed and uniqued via the 'detail::TypeUniquer' class.

Derived type classes are expected to implement several required implementation hooks:

Type storage objects inherit from TypeStorage and contain the following:

Definition at line 74 of file Types.h.

Member Typedef Documentation

◆ AbstractTy

Definition at line 84 of file Types.h.

◆ ImplType

Definition at line 82 of file Types.h.

◆ TypeBase

template<typename ConcreteType , typename BaseType , typename StorageType , template< typename T > class... Traits>
using mlir::Type::TypeBase = detail::StorageUserBase<ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits...>

Utility class for implementing types.

Definition at line 79 of file Types.h.

Constructor & Destructor Documentation

◆ Type() [1/3]

constexpr mlir::Type::Type ( )
constexprdefault

Referenced by getFromOpaquePointer().

◆ Type() [2/3]

mlir::Type::Type ( const ImplType impl)
inline

Definition at line 87 of file Types.h.

◆ Type() [3/3]

mlir::Type::Type ( const Type other)
default

Member Function Documentation

◆ cast()

template<typename U >
U mlir::Type::cast

◆ dump()

void Type::dump ( ) const

Definition at line 3796 of file AsmPrinter.cpp.

◆ dyn_cast()

template<typename U >
U mlir::Type::dyn_cast

◆ dyn_cast_or_null()

template<typename U >
U mlir::Type::dyn_cast_or_null

Definition at line 335 of file Types.h.

◆ getAbstractType()

const AbstractTy& mlir::Type::getAbstractType ( ) const
inline

◆ getAsOpaquePointer()

const void* mlir::Type::getAsOpaquePointer ( ) const
inline

Methods for supporting PointerLikeTypeTraits.

Definition at line 177 of file Types.h.

References impl.

Referenced by llvm::PointerLikeTypeTraits< mlir::Type >::getAsVoidPointer().

◆ getContext()

MLIRContext * Type::getContext ( ) const

Return the MLIRContext in which this type was uniqued.

Definition at line 35 of file Types.cpp.

Referenced by combineOneSpec(), mlir::TypeConverter::convertType(), mlir::quant::fakeQuantAttrsToType(), mlir::gpu::MMAMatrixType::get(), mlir::spirv::MatrixType::get(), mlir::spirv::RuntimeArrayType::get(), mlir::spirv::JointMatrixINTELType::get(), mlir::spirv::CooperativeMatrixType::get(), mlir::spirv::ArrayType::get(), mlir::quant::CalibratedQuantizedType::get(), mlir::spirv::SampledImageType::get(), mlir::DataLayoutEntryAttr::get(), mlir::spirv::PointerType::get(), mlir::quant::UniformQuantizedPerAxisType::get(), mlir::quant::UniformQuantizedType::get(), mlir::quant::AnyQuantizedType::get(), getBoolAttribute(), mlir::gpu::MMAMatrixType::getChecked(), mlir::spirv::MatrixType::getChecked(), mlir::quant::CalibratedQuantizedType::getChecked(), mlir::spirv::SampledImageType::getChecked(), mlir::quant::UniformQuantizedPerAxisType::getChecked(), mlir::quant::UniformQuantizedType::getChecked(), mlir::quant::AnyQuantizedType::getChecked(), mlir::Value::getContext(), mlir::detail::getDefaultABIAlignment(), mlir::detail::getDefaultPreferredAlignment(), mlir::detail::getDefaultTypeSizeInBits(), getGetValueTypeOpValueType(), getI1SameShape(), mlir::bufferization::getMemRefTypeWithFullyDynamicLayout(), getRegisterIndexToTileOffsetMap(), mlir::memref::getTensorTypeFromMemRefType(), mlir::spirv::getUnaryOpResultType(), getValAndBoolStructType(), inferIntrinsicResultType(), mlir::LLVM::isCompatibleType(), isSupportedElementType(), mlir::spirv::MemorySpaceToStorageClassConverter::MemorySpaceToStorageClassConverter(), mlir::arith::NarrowTypeEmulationConverter::NarrowTypeEmulationConverter(), mlir::math::populateLegalizeToF32TypeConverter(), mlir::UnrankedMemRefDescriptor::sizeBasePtr(), and mlir::arith::WideIntEmulationConverter::WideIntEmulationConverter().

◆ getDialect()

Dialect Type::getDialect ( ) const
inline

◆ getFromOpaquePointer()

static Type mlir::Type::getFromOpaquePointer ( const void *  pointer)
inlinestatic

◆ getImpl()

ImplType* mlir::Type::getImpl ( ) const
inline

◆ getIntOrFloatBitWidth()

unsigned Type::getIntOrFloatBitWidth ( ) const

◆ getTypeID()

TypeID mlir::Type::getTypeID ( )
inline

◆ hasPromiseOrImplementsInterface()

template<typename InterfaceT >
bool mlir::Type::hasPromiseOrImplementsInterface ( )
inline

Returns true if InterfaceT has been promised by the dialect or implemented.

Definition at line 187 of file Types.h.

References getDialect(), getTypeID(), and mlir::dialect_extension_detail::hasPromisedInterface().

◆ hasTrait()

template<template< typename T > class Trait>
bool mlir::Type::hasTrait ( )
inline

Returns true if the type was registered with a particular trait.

Definition at line 195 of file Types.h.

References getAbstractType(), and mlir::AbstractType::hasTrait().

Referenced by mlir::DynamicType::classof().

◆ isa()

template<typename... Tys>
bool mlir::Type::isa

Definition at line 320 of file Types.h.

Referenced by createMemcpy(), isMemref(), and isValueCompatibleWithFullReplicationSharding().

◆ isa_and_nonnull()

template<typename... Tys>
bool mlir::Type::isa_and_nonnull

Definition at line 325 of file Types.h.

Referenced by destructureIndices().

◆ isBF16()

bool Type::isBF16 ( ) const

◆ isF128()

bool Type::isF128 ( ) const

Definition at line 54 of file Types.cpp.

Referenced by fltSemanticsForType(), and mlir::arm_sme::isValidSMETileElementType().

◆ isF16()

bool Type::isF16 ( ) const

◆ isF32()

bool Type::isF32 ( ) const

◆ isF64()

bool Type::isF64 ( ) const

◆ isF80()

bool Type::isF80 ( ) const

Definition at line 53 of file Types.cpp.

Referenced by fltSemanticsForType().

◆ isFloat8E4M3B11FNUZ()

bool Type::isFloat8E4M3B11FNUZ ( ) const

Definition at line 45 of file Types.cpp.

◆ isFloat8E4M3FN()

bool Type::isFloat8E4M3FN ( ) const

Definition at line 38 of file Types.cpp.

Referenced by isAllowedSizeN(), and isAllowedWGMMADataType().

◆ isFloat8E4M3FNUZ()

bool Type::isFloat8E4M3FNUZ ( ) const

Definition at line 42 of file Types.cpp.

Referenced by mfmaOpToIntrinsic().

◆ isFloat8E5M2()

bool Type::isFloat8E5M2 ( ) const

Definition at line 37 of file Types.cpp.

Referenced by isAllowedSizeN(), and isAllowedWGMMADataType().

◆ isFloat8E5M2FNUZ()

bool Type::isFloat8E5M2FNUZ ( ) const

Definition at line 39 of file Types.cpp.

Referenced by mfmaOpToIntrinsic().

◆ isIndex()

bool Type::isIndex ( ) const

◆ isInteger() [1/2]

bool Type::isInteger ( ) const

◆ isInteger() [2/2]

bool Type::isInteger ( unsigned  width) const

Return true if this is an integer type with the specified width.

Definition at line 61 of file Types.cpp.

◆ isIntOrFloat()

bool Type::isIntOrFloat ( ) const

◆ isIntOrIndex()

bool Type::isIntOrIndex ( ) const

Return true if this is an integer (of any signedness) or an index type.

Definition at line 115 of file Types.cpp.

Referenced by mlir::sparse_tensor::genIsNonzero(), isSupportedCombiningKind(), and mlir::detail::Parser::parseDenseArrayAttr().

◆ isIntOrIndexOrFloat()

bool Type::isIntOrIndexOrFloat ( ) const

◆ isSignedInteger() [1/2]

bool Type::isSignedInteger ( ) const

Return true if this is a signed integer type (with the specified width).

Definition at line 79 of file Types.cpp.

Referenced by buildAttributeAPInt(), castToSourceType(), mlir::Builder::getIntegerAttr(), isSignedIntegerOrVector(), and mlir::gpu::MMAMatrixType::isValidElementType().

◆ isSignedInteger() [2/2]

bool Type::isSignedInteger ( unsigned  width) const

Definition at line 85 of file Types.cpp.

◆ isSignlessInteger() [1/2]

bool Type::isSignlessInteger ( ) const

Return true if this is a signless integer type (with the specified width).

Definition at line 67 of file Types.cpp.

Referenced by areIndexCastCompatible(), and mlir::arith::ConstantIntOp::build().

◆ isSignlessInteger() [2/2]

bool Type::isSignlessInteger ( unsigned  width) const

Definition at line 73 of file Types.cpp.

◆ isSignlessIntOrFloat()

bool Type::isSignlessIntOrFloat ( ) const

Return true of this is a signless integer or a float type.

Definition at line 111 of file Types.cpp.

◆ isSignlessIntOrIndex()

bool Type::isSignlessIntOrIndex ( ) const

Return true if this is a signless integer or index type.

Definition at line 103 of file Types.cpp.

◆ isSignlessIntOrIndexOrFloat()

bool Type::isSignlessIntOrIndexOrFloat ( ) const

Return true if this is a signless integer, index, or float type.

Definition at line 107 of file Types.cpp.

Referenced by appendMangledType().

◆ isTF32()

bool Type::isTF32 ( ) const

Definition at line 50 of file Types.cpp.

Referenced by isAllowedSizeN(), and isAllowedWGMMADataType().

◆ isUnsignedInteger() [1/2]

bool Type::isUnsignedInteger ( ) const

Return true if this is an unsigned integer type (with the specified width).

Definition at line 91 of file Types.cpp.

Referenced by isUnsignedIntegerOrVector(), mlir::gpu::MMAMatrixType::isValidElementType(), and mlir::detail::Parser::parseDecOrHexAttr().

◆ isUnsignedInteger() [2/2]

bool Type::isUnsignedInteger ( unsigned  width) const

Definition at line 97 of file Types.cpp.

◆ operator bool()

mlir::Type::operator bool ( ) const
inlineexplicit

Definition at line 95 of file Types.h.

References impl.

◆ operator!()

bool mlir::Type::operator! ( ) const
inline

Definition at line 97 of file Types.h.

◆ operator!=()

bool mlir::Type::operator!= ( Type  other) const
inline

Definition at line 94 of file Types.h.

◆ operator=()

Type& mlir::Type::operator= ( const Type other)
default

◆ operator==()

bool mlir::Type::operator== ( Type  other) const
inline

Definition at line 93 of file Types.h.

References impl.

◆ print() [1/2]

void Type::print ( raw_ostream &  os) const

Print the current type.

Definition at line 3783 of file AsmPrinter.cpp.

Referenced by createCtlzFunc(), and mlir::operator<<().

◆ print() [2/2]

void Type::print ( raw_ostream &  os,
AsmState state 
) const

Definition at line 3792 of file AsmPrinter.cpp.

◆ replace()

template<typename... ReplacementFns>
auto mlir::Type::replace ( ReplacementFns &&...  replacementFns)
inline

Recursively replace all of the nested sub-attributes and sub-types using the provided map functions.

Returns nullptr in the case of failure. See AttrTypeReplacer for information on the support replacement function types.

Definition at line 239 of file Types.h.

References mlir::AttrTypeReplacer::addReplacement(), and mlir::AttrTypeReplacer::replace().

◆ replaceImmediateSubElements()

auto mlir::Type::replaceImmediateSubElements ( ArrayRef< Attribute replAttrs,
ArrayRef< Type replTypes 
) const
inline

Replace the immediately nested sub-attributes and sub-types with those provided.

The order of the provided elements is derived from the order of the elements returned by the callbacks of walkImmediateSubElements. The element at index 0 would replace the very first attribute given by walkImmediateSubElements. On success, the new instance with the values replaced is returned. If replacement fails, nullptr is returned.

Definition at line 218 of file Types.h.

References getAbstractType(), and mlir::AbstractType::replaceImmediateSubElements().

◆ walk()

template<WalkOrder Order = WalkOrder::PostOrder, typename... WalkFns>
auto mlir::Type::walk ( WalkFns &&...  walkFns)
inline

Walk this type and all attibutes/types nested within using the provided walk functions.

See AttrTypeWalker for information on the supported walk function types.

Definition at line 228 of file Types.h.

References mlir::AttrTypeWalker::addWalk(), and mlir::AttrTypeWalker::walk().

◆ walkImmediateSubElements()

void mlir::Type::walkImmediateSubElements ( function_ref< void(Attribute)>  walkAttrsFn,
function_ref< void(Type)>  walkTypesFn 
) const
inline

Walk all of the immediately nested sub-attributes and sub-types.

This method does not recurse into sub elements.

Definition at line 207 of file Types.h.

References getAbstractType(), and mlir::AbstractType::walkImmediateSubElements().

Friends And Related Function Documentation

◆ hash_value

::llvm::hash_code hash_value ( Type  arg)
friend

Definition at line 315 of file Types.h.

Member Data Documentation

◆ impl

ImplType* mlir::Type::impl {nullptr}
protected

Definition at line 247 of file Types.h.

Referenced by getAsOpaquePointer(), getImpl(), operator bool(), and operator==().


The documentation for this class was generated from the following files: