MLIR
21.0.0git
|
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable component. More...
#include "mlir/IR/Types.h"
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 | |
Type & | operator= (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 > | |
U | dyn_cast () const |
template<typename U > | |
U | dyn_cast_or_null () const |
template<typename U > | |
U | cast () const |
TypeID | getTypeID () |
Return a unique identifier for the concrete type. More... | |
MLIRContext * | getContext () const |
Return the MLIRContext in which this type was uniqued. More... | |
Dialect & | getDialect () const |
Get the dialect this type is registered to. More... | |
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). More... | |
bool | isFloat (unsigned width) const |
Return true if this is a float type with the specified width. More... | |
bool | isInteger () const |
Return true if this is an integer type (with the specified width). More... | |
bool | isInteger (unsigned width) const |
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 AbstractTy & | getAbstractType () const |
Return the abstract type descriptor for this type. More... | |
ImplType * | getImpl () 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 | |
ImplType * | impl {nullptr} |
Friends | |
::llvm::hash_code | hash_value (Type arg) |
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:
using mlir::Type::AbstractTy = AbstractType |
using mlir::Type::ImplType = TypeStorage |
using mlir::Type::TypeBase = detail::StorageUserBase<ConcreteType, BaseType, StorageType, detail::TypeUniquer, Traits...> |
|
constexprdefault |
Referenced by getFromOpaquePointer().
|
default |
void Type::dump | ( | ) | const |
Definition at line 3975 of file AsmPrinter.cpp.
|
inline |
Return the abstract type descriptor for this type.
Definition at line 203 of file Types.h.
Referenced by mlir::TypeInterface< ConcreteType, Traits >::getInterfaceFor(), hasTrait(), replaceImmediateSubElements(), mlir::irdl::BaseTypeConstraint::verify(), and walkImmediateSubElements().
|
inline |
Methods for supporting PointerLikeTypeTraits.
Definition at line 180 of file Types.h.
References impl.
Referenced by llvm::PointerLikeTypeTraits< mlir::Type >::getAsVoidPointer().
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::CooperativeMatrixType::get(), mlir::spirv::ArrayType::get(), mlir::quant::CalibratedQuantizedType::get(), mlir::spirv::SampledImageType::get(), mlir::spirv::PointerType::get(), mlir::quant::UniformQuantizedPerAxisType::get(), mlir::quant::UniformQuantizedSubChannelType::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::UniformQuantizedSubChannelType::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::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::UnrankedMemRefDescriptor::sizeBasePtr(), and mlir::arith::WideIntEmulationConverter::WideIntEmulationConverter().
|
inline |
Get the dialect this type is registered to.
Definition at line 123 of file Types.h.
Referenced by mlir::pdl::PDLType::classof(), mlir::quant::QuantizedType::classof(), mlir::spirv::SPIRVType::classof(), combineOneSpec(), mlir::TypeInterface< ConcreteType, Traits >::getInterfaceFor(), hasPromiseOrImplementsInterface(), mlir::TensorType::isValidElementType(), memsetCanRewire(), and parseAndVerifyType().
|
inlinestatic |
Definition at line 183 of file Types.h.
References Type().
Referenced by mlir::DiagnosticArgument::getAsType(), and llvm::PointerLikeTypeTraits< mlir::Type >::getFromVoidPointer().
|
inline |
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.
Referenced by alignedConversionPrecondition(), areSameBitwidthScalarType(), buildAttributeAPInt(), castF32To(), castToF32(), convertRoundEvenOp(), convertScalarToComplexDtype(), createCtlzFunc(), createElementIPowIFunc(), createInitialValueForReduceOp(), createLinalgBodyCalculationForElementwiseOp(), declareReduction(), deduceCanonicalResource(), emulatedVectorLoad(), mlir::sparse_tensor::genIndexLoad(), getBitWidth(), mlir::spirv::getBitWidth(), mlir::spirv::ScalarType::getCapabilities(), mlir::detail::getDefaultTypeSizeInBits(), mlir::detail::getDenseElementBitWidth(), mlir::spirv::ScalarType::getExtensions(), mlir::Builder::getIntegerAttr(), mlir::nvgpu::getLaneIdAndValueIdToOperandCoord(), mlir::nvgpu::getLdMatrixParams(), getNumBits(), getRegisterIndexToTileOffsetMap(), getScalarOrElementWidth(), mlir::emitc::getSignedTypeFor(), mlir::spirv::ScalarType::getSizeInBytes(), mlir::arm_sme::getSMETileSliceMinNumElts(), getTileShape(), mlir::emitc::getUnsignedTypeFor(), mlir::nvgpu::inferTileWidthInBits(), mlir::GPUPrintfOpToHIPLowering::matchAndRewrite(), mlir::detail::Parser::parseDenseArrayAttr(), parseSwitchOpCases(), resultsInSupportedAsyncCopy(), shiftValue(), truncToI32(), verifyMmaSyncOp(), verifyRescaleValueAndZpTypes(), and wmmaPushInputOperand().
|
inline |
Return a unique identifier for the concrete type.
This is used to support dynamic type casting.
Definition at line 117 of file Types.h.
Referenced by mlir::TypeInterface< ConcreteType, Traits >::getInterfaceFor(), mlir::DataLayout::getTypeABIAlignment(), mlir::DataLayout::getTypePreferredAlignment(), mlir::DataLayout::getTypeSize(), mlir::DataLayout::getTypeSizeInBits(), hasPromiseOrImplementsInterface(), mlir::DynamicType::isa(), mlir::irdl::BaseTypeConstraint::verify(), and mlir::OpTrait::impl::verifyElementwise().
|
inline |
Returns true if InterfaceT
has been promised by the dialect or implemented.
Definition at line 190 of file Types.h.
References getDialect(), getTypeID(), and mlir::dialect_extension_detail::hasPromisedInterface().
|
inline |
Returns true if the type was registered with a particular trait.
Definition at line 198 of file Types.h.
References getAbstractType(), and mlir::AbstractType::hasTrait().
Referenced by mlir::DynamicType::classof().
bool Type::isBF16 | ( | ) | const |
Definition at line 37 of file Types.cpp.
Referenced by getCuSparseDataTypeFrom(), isAllowedSizeN(), isAllowedWGMMADataType(), mlir::arm_sme::isValidSMETileElementType(), parseAndVerifyType(), mlir::sparse_tensor::primaryTypeEncoding(), verifyMmaSyncOp(), wmmaPushInputOperand(), and wmmaPushOutputOperand().
bool Type::isF128 | ( | ) | const |
Definition at line 43 of file Types.cpp.
Referenced by mlir::arm_sme::isValidSMETileElementType().
bool Type::isF16 | ( | ) | const |
Definition at line 38 of file Types.cpp.
Referenced by floatCst(), getCuSparseDataTypeFrom(), getCuSparseLtDataTypeFrom(), mlir::nvgpu::getMmaSyncRegisterType(), isAllowedSizeN(), isAllowedWGMMADataType(), mlir::gpu::MMAMatrixType::isValidElementType(), mlir::arm_sme::isValidSMETileElementType(), mlir::math::ErfPolynomialApproximation::matchAndRewrite(), mlir::sparse_tensor::primaryTypeEncoding(), verifyMmaSyncOp(), and wmmaPushOutputOperand().
bool Type::isF32 | ( | ) | const |
Definition at line 40 of file Types.cpp.
Referenced by castF32To(), castToF32(), convertRoundOp(), floatCst(), getCuSparseDataTypeFrom(), mlir::nvgpu::getMmaSyncRegisterType(), getRegisterType(), isAllowedSizeN(), isAllowedWGMMADataType(), mlir::gpu::MMAMatrixType::isValidElementType(), mlir::arm_sme::isValidSMETileElementType(), mlir::math::ErfcPolynomialApproximation::matchAndRewrite(), mlir::math::ErfPolynomialApproximation::matchAndRewrite(), mlir::sparse_tensor::primaryTypeEncoding(), and verifyMmaSyncOp().
bool Type::isF64 | ( | ) | const |
Definition at line 41 of file Types.cpp.
Referenced by getCuSparseDataTypeFrom(), mlir::nvgpu::getMmaSyncRegisterType(), getRegisterType(), mlir::arm_sme::isValidSMETileElementType(), mlir::sparse_tensor::primaryTypeEncoding(), and verifyMmaSyncOp().
bool Type::isFloat | ( | ) | const |
bool Type::isFloat | ( | unsigned | width | ) | const |
bool Type::isIndex | ( | ) | const |
Definition at line 54 of file Types.cpp.
Referenced by areIndexCastCompatible(), assertValidValueDim(), buildAttributeAPInt(), mlir::ValueBoundsConstraintSet::computeBound(), convertScalarToIntDtype(), delinearizeInductionVariable(), mlir::affine::fullyComposeAndComputeConstantDelta(), mlir::detail::getDenseElementBitWidth(), mlir::Builder::getIntegerAttr(), getProductOfIntsOrIndexes(), mlir::ConstantIntRanges::getStorageBitwidth(), mlir::getValueOrCreateCastToIndexLike(), getZero(), inferIndexCast(), isMatchingWidth(), mlir::emitc::isSupportedEmitCType(), mlir::affine::isValidDim(), isValidIntOrFloat(), mlir::affine::isValidSymbol(), mlir::spirv::ElementwiseOpPattern< Op, SPIRVOp >::matchAndRewrite(), mlir::affine::materializeComputedBound(), mlir::sparse_tensor::overheadTypeEncoding(), printLaunchDimType(), mlir::arith::reifyValueBound(), mlir::sparse_tensor::SparseTensorSpecifier::setSpecifierField(), mlir::ValueBoundsConstraintSet::Variable::Variable(), verifyInitializationAttribute(), and mlir::detail::verifyShapedDimOpInterface().
bool Type::isInteger | ( | ) | const |
Return true if this is an integer type (with the specified width).
Definition at line 56 of file Types.cpp.
Referenced by castBoolToIntN(), castIntNToBool(), createInitialValueForReduceOp(), createLinalgBodyCalculationForElementwiseOp(), createLinalgBodyCalculationForReduceOp(), mlir::DenseElementsAttr::get(), getConstantUint32(), getCuSparseDataTypeFrom(), getCuSparseIndexTypeFrom(), getCuSparseLtDataTypeFrom(), mlir::OpToFuncCallLowering< SourceOp >::getFunctionName(), getMatchSyncIntrinsicId(), mlir::nvgpu::getMmaSyncRegisterType(), getRegisterType(), getScalarOrVectorI32Constant(), mlir::emitc::getSignedTypeFor(), mlir::emitc::getUnsignedTypeFor(), isAllowedSizeN(), isAllowedWGMMADataType(), isBoolScalarOrVector(), isMatchingWidth(), mlir::DenseElementsAttr::isValidBool(), mlir::gpu::MMAMatrixType::isValidElementType(), mlir::arm_sme::isValidSMETileElementType(), mlir::detail::Parser::parseDenseArrayAttr(), mlir::sparse_tensor::primaryTypeEncoding(), verifyMmaSyncOp(), mlir::OpTrait::tosa::MulOperandsAndResultElementType< ConcreteType >::verifyTrait(), verifyZeroPoint(), and wmmaPushOutputOperand().
bool Type::isIntOrFloat | ( | ) | const |
Return true if this is an integer (of any signedness) or a float type.
Definition at line 116 of file Types.cpp.
Referenced by alignedConversionPrecondition(), areSameBitwidthScalarType(), createLinalgBodyCalculationForElementwiseOp(), getBitWidth(), mlir::spirv::getBitWidth(), mlir::detail::getDefaultTypeSizeInBits(), getScalarOrElementWidth(), isAllocationSupported(), mlir::spirv::SPIRVType::isScalarOrVector(), mlir::GPUPrintfOpToVPrintfLowering::matchAndRewrite(), and ConvertAccessChain::matchAndRewrite().
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.
Referenced by ceilDivPositive(), mlir::sparse_tensor::genIsNonzero(), isSupportedCombiningKind(), and mlir::detail::Parser::parseDenseArrayAttr().
bool Type::isIntOrIndexOrFloat | ( | ) | const |
Return true if this is an integer (of any signedness), index, or float type.
Definition at line 120 of file Types.cpp.
Referenced by mlir::DenseElementsAttr::get(), getSharding(), getZero(), mlir::vector::isBroadcastableTo(), isSupportedCombiningKind(), isSupportedSourceType(), isUniformDefinition(), mlir::BaseMemRefType::isValidElementType(), mlir::detail::Parser::parseDenseArrayAttr(), and verifyRegionAttribute().
bool Type::isSignedInteger | ( | ) | const |
Return true if this is a signed integer type (with the specified width).
Definition at line 76 of file Types.cpp.
Referenced by buildAttributeAPInt(), mlir::Builder::getIntegerAttr(), isSignedIntegerOrVector(), mlir::gpu::MMAMatrixType::isValidElementType(), and wmmaPushInputOperand().
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(), and mlir::arith::ConstantIntOp::build().
bool Type::isSignlessIntOrFloat | ( | ) | const |
Return true of this is a signless integer or a float type.
Definition at line 108 of file Types.cpp.
Referenced by mlir::linalg::RegionMatcher::matchAsScalarBinaryOp().
bool Type::isSignlessIntOrIndex | ( | ) | const |
bool Type::isSignlessIntOrIndexOrFloat | ( | ) | const |
Return true if this is a signless integer, index, or float type.
Definition at line 104 of file Types.cpp.
Referenced by appendMangledType().
bool Type::isTF32 | ( | ) | const |
Definition at line 39 of file Types.cpp.
Referenced by isAllowedSizeN(), and isAllowedWGMMADataType().
bool Type::isUnsignedInteger | ( | ) | const |
Return true if this is an unsigned integer type (with the specified width).
Definition at line 88 of file Types.cpp.
Referenced by createLinalgBodyCalculationForElementwiseOp(), isUnsignedIntegerOrVector(), mlir::gpu::MMAMatrixType::isValidElementType(), mlir::detail::Parser::parseDecOrHexAttr(), mlir::tosa::populateTosaTypeConversion(), and wmmaPushInputOperand().
|
inlineexplicit |
|
inline |
|
inline |
void Type::print | ( | raw_ostream & | os | ) | const |
Print the current type.
Definition at line 3962 of file AsmPrinter.cpp.
Referenced by createCtlzFunc(), and mlir::operator<<().
void Type::print | ( | raw_ostream & | os, |
AsmState & | state | ||
) | const |
Definition at line 3971 of file AsmPrinter.cpp.
|
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 242 of file Types.h.
References mlir::detail::AttrTypeReplacerBase< Concrete >::addReplacement(), and mlir::AttrTypeReplacer::replace().
|
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 221 of file Types.h.
References getAbstractType(), and mlir::AbstractType::replaceImmediateSubElements().
|
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 231 of file Types.h.
References mlir::AttrTypeWalker::addWalk(), and mlir::AttrTypeWalker::walk().
|
inline |
Walk all of the immediately nested sub-attributes and sub-types.
This method does not recurse into sub elements.
Definition at line 210 of file Types.h.
References getAbstractType(), and mlir::AbstractType::walkImmediateSubElements().
|
protected |
Definition at line 250 of file Types.h.
Referenced by getAsOpaquePointer(), getImpl(), operator bool(), and operator==().