MLIR 22.0.0git
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
 Utility class for implementing types.
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
TypeID getTypeID ()
 Return a unique identifier for the concrete type.
MLIRContextgetContext () const
 Return the MLIRContext in which this type was uniqued.
DialectgetDialect () const
 Get the dialect this type is registered to.
bool isIndex () const
bool isBF16 () const
bool isF16 () const
bool isTF32 () const
bool isF32 () const
bool isF64 () const
bool isF80 () const
bool isF128 () const
bool isFloat () const
 Return true if this is an float type (with the specified width).
bool isFloat (unsigned width) const
 Return true if this is a float type with the specified width.
bool isInteger () const
 Return true if this is an integer type (with the specified width).
bool isInteger (unsigned width) const
bool isSignlessInteger () const
 Return true if this is a signless integer type (with the specified width).
bool isSignlessInteger (unsigned width) const
bool isSignedInteger () const
 Return true if this is a signed integer type (with the specified width).
bool isSignedInteger (unsigned width) const
bool isUnsignedInteger () const
 Return true if this is an unsigned integer type (with the specified width).
bool isUnsignedInteger (unsigned width) const
unsigned getIntOrFloatBitWidth () const
 Return the bit width of an integer or a float type, assert failure on other types.
bool isSignlessIntOrIndex () const
 Return true if this is a signless integer or index type.
bool isSignlessIntOrIndexOrFloat () const
 Return true if this is a signless integer, index, or float type.
bool isSignlessIntOrFloat () const
 Return true of this is a signless integer or a float type.
bool isIntOrIndex () const
 Return true if this is an integer (of any signedness) or an index type.
bool isIntOrFloat () const
 Return true if this is an integer (of any signedness) or a float type.
bool isIntOrIndexOrFloat () const
 Return true if this is an integer (of any signedness), index, or float type.
void print (raw_ostream &os) const
 Print the current type.
void print (raw_ostream &os, AsmState &state) const
void dump () const
friend::llvm::hash_code hash_value (Type arg)
const voidgetAsOpaquePointer () const
 Methods for supporting PointerLikeTypeTraits.
template<typename InterfaceT>
bool hasPromiseOrImplementsInterface ()
 Returns true if InterfaceT has been promised by the dialect or implemented.
template<template< typename T > class Trait>
bool hasTrait ()
 Returns true if the type was registered with a particular trait.
const AbstractTygetAbstractType () const
 Return the abstract type descriptor for this type.
ImplTypegetImpl () const
 Return the Type implementation.
void walkImmediateSubElements (function_ref< void(Attribute)> walkAttrsFn, function_ref< void(Type)> walkTypesFn) const
 Walk all of the immediately nested sub-attributes and sub-types.
auto replaceImmediateSubElements (ArrayRef< Attribute > replAttrs, ArrayRef< Type > replTypes) const
 Replace the immediately nested sub-attributes and sub-types with those provided.
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.
template<typename... ReplacementFns>
auto replace (ReplacementFns &&...replacementFns)
 Recursively replace all of the nested sub-attributes and sub-types using the provided map functions.

Static Public Member Functions

static Type getFromOpaquePointer (const void *pointer)

Protected Attributes

ImplTypeimpl {nullptr}

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:

  • Optional:
    • static LogicalResult verifyInvariants( function_ref<InFlightDiagnostic()> emitError, Args... args)
      • This method is invoked when calling the 'TypeBase::get/getChecked' methods to ensure that the arguments passed in are valid to construct a type instance with.
      • This method is expected to return failure if a type cannot be constructed with 'args', success otherwise.
      • 'args' must correspond with the arguments passed into the 'TypeBase::get' call.

Type storage objects inherit from TypeStorage and contain the following:

  • The dialect that defined the type.
  • Any parameters of the type.
  • An optional mutable component. For non-parametric types, a convenience DefaultTypeStorage is provided. Parametric storage types must derive TypeStorage and respect the following:
  • Define a type alias, KeyTy, to a type that uniquely identifies the instance of the type.
    • The key type must be constructible from the values passed into the detail::TypeUniquer::get call.
    • If the KeyTy does not have an llvm::DenseMapInfo specialization, the storage class must define a hashing method: 'static unsigned hashKey(const KeyTy &)'
  • Provide a method, 'bool operator==(const KeyTy &) const', to compare the storage instance against an instance of the key type.
  • Provide a static construction method: 'DerivedStorage *construct(TypeStorageAllocator &, const KeyTy &key)' that builds a unique instance of the derived storage. The arguments to this function are an allocator to store any uniqued data within the context and the key type for this storage.
  • If they have a mutable component, this component must not be a part of the key.

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
Initial value:
detail::StorageUserBase<ConcreteType, BaseType, StorageType,
detail::TypeUniquer, Traits...>
Utility class for implementing users of storage classes uniqued by a StorageUniquer.
A utility class to get, or create, unique instances of types within an MLIRContext.

Utility class for implementing types.

Definition at line 79 of file Types.h.

Constructor & Destructor Documentation

◆ Type() [1/3]

mlir::Type::Type ( )
constexprdefault

◆ 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

References Type().

Member Function Documentation

◆ dump()

void Type::dump ( ) const

Definition at line 3998 of file AsmPrinter.cpp.

References print().

◆ getAbstractType()

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

◆ getAsOpaquePointer()

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

Methods for supporting PointerLikeTypeTraits.

Definition at line 164 of file Types.h.

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.

References mlir::Dialect::getContext(), and getDialect().

Referenced by combineOneSpec(), mlir::quant::fakeQuantAttrsToType(), mlir::quant::fakeQuantAttrsToType(), mlir::gpu::MMAMatrixType::get(), mlir::quant::AnyQuantizedType::get(), mlir::quant::CalibratedQuantizedType::get(), mlir::quant::UniformQuantizedPerAxisType::get(), mlir::quant::UniformQuantizedSubChannelType::get(), mlir::quant::UniformQuantizedType::get(), mlir::spirv::ArrayType::get(), mlir::spirv::ArrayType::get(), mlir::spirv::CooperativeMatrixType::get(), mlir::spirv::MatrixType::get(), mlir::spirv::PointerType::get(), mlir::spirv::RuntimeArrayType::get(), mlir::spirv::RuntimeArrayType::get(), mlir::spirv::SampledImageType::get(), mlir::spirv::TensorArmType::get(), getBoolAttribute(), mlir::gpu::MMAMatrixType::getChecked(), mlir::quant::AnyQuantizedType::getChecked(), mlir::quant::CalibratedQuantizedType::getChecked(), mlir::quant::UniformQuantizedPerAxisType::getChecked(), mlir::quant::UniformQuantizedSubChannelType::getChecked(), mlir::quant::UniformQuantizedType::getChecked(), mlir::spirv::MatrixType::getChecked(), mlir::spirv::SampledImageType::getChecked(), mlir::Value::getContext(), mlir::detail::getDefaultABIAlignment(), mlir::detail::getDefaultPreferredAlignment(), mlir::detail::getDefaultTypeSizeInBits(), getGetValueTypeOpValueType(), getI1SameShape(), getI1SameShape(), getI1SameShape(), getI1SameShape(), mlir::acc::OpenACCSupport::getRecipeName(), getRegisterIndexToTileOffsetMap(), getRegisterType(), mlir::emitc::getSignedTypeFor(), mlir::memref::getTensorTypeFromMemRefType(), mlir::spirv::getUnaryOpResultType(), mlir::emitc::getUnsignedTypeFor(), getValAndBoolStructType(), inferIntrinsicResultType(), mlir::LLVM::isCompatibleType(), isSupportedElementType(), mlir::spirv::MemorySpaceToStorageClassConverter::MemorySpaceToStorageClassConverter(), mlir::arith::NarrowTypeEmulationConverter::NarrowTypeEmulationConverter(), mlir::tosa::populateTosaTypeConversion(), mlir::UnrankedMemRefDescriptor::sizeBasePtr(), and mlir::arith::WideIntEmulationConverter::WideIntEmulationConverter().

◆ getDialect()

◆ getFromOpaquePointer()

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

◆ getImpl()

◆ getIntOrFloatBitWidth()

unsigned Type::getIntOrFloatBitWidth ( ) const

Return the bit width of an integer or a float type, assert failure on other types.

Definition at line 122 of file Types.cpp.

References isIntOrFloat().

Referenced by alignedConversionPrecondition(), areSameBitwidthScalarType(), buildAttributeAPInt(), castF32To(), castToF32(), convertRoundEvenOp(), convertScalarToComplexDtype(), mlir::createConvertArithToSPIRVPass(), createCtlzFunc(), createElementIPowIFunc(), createInitialValueForReduceOp(), createLinalgBodyCalculationForElementwiseOp(), declareReduction(), deduceCanonicalResource(), emulatedVectorLoad(), getBitWidth(), getBitWidth(), mlir::spirv::getBitWidth(), mlir::tosa::getBitWidth(), mlir::xegpu::uArch::Subgroup2DBlockLoadInstruction::getBlockWidthHeightCount(), mlir::xegpu::uArch::Subgroup2DBlockPrefetchInstruction::getBlockWidthHeightCount(), mlir::xegpu::uArch::Subgroup2DBlockStoreInstruction::getBlockWidthHeightCount(), mlir::detail::getDefaultTypeSizeInBits(), mlir::detail::getDenseElementBitWidth(), mlir::xegpu::impl::XeGPUPropagateLayoutBase< DerivedT >::getDependentDialects(), mlir::Builder::getIntegerAttr(), getNumBits(), getRegisterIndexToTileOffsetMap(), getScalarOrElementWidth(), mlir::emitc::getSignedTypeFor(), mlir::spirv::SPIRVType::getSizeInBytes(), mlir::arm_sme::getSMETileSliceMinNumElts(), mlir::xegpu::uArch::SubgroupMatrixMultiplyAcc::getSupportedK(), getTileShape(), mlir::emitc::getUnsignedTypeFor(), mlir::GPUPrintfOpToHIPLowering::matchAndRewrite(), mlir::detail::Parser::parseDenseArrayAttr(), parseSwitchOpCases(), parseSwitchOpCases(), mlir::memref::populateMemRefNarrowTypeEmulationConversions(), mlir::tosa::populateTosaTypeConversion(), mlir::AsmPrinter::Impl::printDenseArrayAttr(), resultsInSupportedAsyncCopy(), shiftValue(), truncToI32(), verifyMmaSyncOp(), verifyRescaleValueAndZpTypes(), and wmmaPushInputOperand().

◆ getTypeID()

◆ hash_value()

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

References Type().

◆ hasPromiseOrImplementsInterface()

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

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

Definition at line 174 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 182 of file Types.h.

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

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

◆ isBF16()

◆ isF128()

bool Type::isF128 ( ) const

Definition at line 43 of file Types.cpp.

Referenced by mlir::arm_sme::isValidSMETileElementType().

◆ isF16()

◆ isF32()

◆ isF64()

◆ isF80()

bool Type::isF80 ( ) const

Definition at line 42 of file Types.cpp.

◆ isFloat() [1/2]

bool Type::isFloat ( ) const

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

Definition at line 45 of file Types.cpp.

Referenced by getRegisterType(), and ConvertNativeFuncPattern< Op >::isSPIRVCompatibleFloatOrVec().

◆ isFloat() [2/2]

bool Type::isFloat ( unsigned width) const

Return true if this is a float type with the specified width.

Definition at line 48 of file Types.cpp.

◆ isIndex()

◆ isInteger() [1/2]

◆ isInteger() [2/2]

bool Type::isInteger ( unsigned width) const

Definition at line 58 of file Types.cpp.

◆ isIntOrFloat()

◆ isIntOrIndex()

bool Type::isIntOrIndex ( ) const

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

Definition at line 112 of file Types.cpp.

References isIndex().

Referenced by ceilDivPositive(), ceilDivPositive(), mlir::sparse_tensor::genIsNonzero(), isSupportedCombiningKind(), mlir::detail::Parser::parseDenseArrayAttr(), and mlir::AsmPrinter::Impl::printDenseArrayAttr().

◆ isIntOrIndexOrFloat()

bool Type::isIntOrIndexOrFloat ( ) const

◆ isSignedInteger() [1/2]

bool Type::isSignedInteger ( ) const

◆ isSignedInteger() [2/2]

bool Type::isSignedInteger ( unsigned width) const

Definition at line 82 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 64 of file Types.cpp.

Referenced by areIndexCastCompatible(), isSignlessIntOrFloat(), isSignlessIntOrIndex(), isSignlessIntOrIndexOrFloat(), and mlir::AsmPrinter::Impl::printAttributeImpl().

◆ isSignlessInteger() [2/2]

bool Type::isSignlessInteger ( unsigned width) const

Definition at line 70 of file Types.cpp.

◆ isSignlessIntOrFloat()

bool Type::isSignlessIntOrFloat ( ) const

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

Definition at line 108 of file Types.cpp.

References isSignlessInteger().

◆ isSignlessIntOrIndex()

bool Type::isSignlessIntOrIndex ( ) const

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

Definition at line 100 of file Types.cpp.

References isSignlessInteger().

◆ isSignlessIntOrIndexOrFloat()

bool Type::isSignlessIntOrIndexOrFloat ( ) const

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

Definition at line 104 of file Types.cpp.

References isSignlessInteger().

Referenced by appendMangledType().

◆ isTF32()

◆ isUnsignedInteger() [1/2]

◆ isUnsignedInteger() [2/2]

bool Type::isUnsignedInteger ( unsigned width) const

Definition at line 94 of file Types.cpp.

◆ operator bool()

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

Definition at line 95 of file Types.h.

◆ 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.

References Type().

◆ operator=()

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

References Type().

◆ operator==()

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

Definition at line 93 of file Types.h.

References impl, and Type().

◆ print() [1/2]

void Type::print ( raw_ostream & os) const

Print the current type.

Definition at line 3985 of file AsmPrinter.cpp.

References getContext(), and print().

Referenced by mlir::acc::getRecipeName(), mlir::operator<<(), and mlir::LLVM::detail::printType().

◆ print() [2/2]

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

◆ 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 226 of file Types.h.

References mlir::detail::AttrTypeReplacerBase< Concrete >::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 205 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 215 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 194 of file Types.h.

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

Member Data Documentation

◆ impl

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

Definition at line 234 of file Types.h.

Referenced by mlir::hash_value(), and operator==().


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