clang 24.0.0git
LoweringHelpers.h File Reference
#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/Interfaces/DataLayoutInterfaces.h"
#include "mlir/Transforms/DialectConversion.h"
#include "clang/CIR/Dialect/IR/CIRDialect.h"
#include "llvm/ADT/StringMap.h"

Go to the source code of this file.

Typedefs

using CIRPreConversionTypeMap = llvm::StringMap<mlir::Type>

Functions

mlir::DenseElementsAttr convertStringAttrToDenseElementsAttr (cir::ConstArrayAttr attr, mlir::Type type)
template<typename StorageTy>
StorageTy getZeroInitFromType (mlir::Type ty)
 Return a zero with the lowered element type's width or float semantics.
template<>
mlir::APInt getZeroInitFromType (mlir::Type ty)
template<>
mlir::APFloat getZeroInitFromType (mlir::Type ty)
template<typename AttrTy, typename StorageTy>
std::optional< mlir::DenseElementsAttr > convertToDenseElementsAttr (cir::ConstArrayAttr attr, const llvm::SmallVectorImpl< int64_t > &dims, mlir::Type convertedElementType)
std::optional< mlir::Attribute > lowerConstArrayAttr (cir::ConstArrayAttr constArr, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, const CIRPreConversionTypeMap &preConversionTypes, mlir::ModuleOp moduleOp)
std::optional< mlir::Attribute > lowerConstRecordAttr (cir::ConstRecordAttr constRecord, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, const CIRPreConversionTypeMap &preConversionTypes, mlir::ModuleOp moduleOp)
mlir::Attribute spellOutSplitTrailingZeros (mlir::Attribute attr)
 Return attr with the trailing zeros of any array that adjustGlobalTypeForInit would split off written out as explicit zero elements, so that it lowers to its own type.
mlir::Type adjustGlobalTypeForInit (mlir::Type llvmType, mlir::Attribute init, const mlir::TypeConverter &converter, const mlir::DataLayout &dataLayout, mlir::Type *failedType=nullptr)
 Adjust llvmType (the converted type of init) to the concrete LLVM type a global constant initialized with init actually lowers to.
mlir::Type adjustGlobalTypeForInit (mlir::Type llvmType, mlir::Attribute init, const mlir::TypeConverter &converter, const mlir::DataLayout &dataLayout, llvm::SmallVectorImpl< unsigned > &paddingAddedIndexes, mlir::Type *failedType=nullptr)
mlir::Value getConstAPInt (mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ, const llvm::APInt &val)
mlir::Value getConst (mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ, unsigned val)
mlir::Value createShL (mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
mlir::Value createAShR (mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
mlir::Value createAnd (mlir::OpBuilder &bld, mlir::Value lhs, const llvm::APInt &rhs)
mlir::Value createLShR (mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
mlir::Type convertTypeForMemory (const mlir::TypeConverter &converter, mlir::DataLayout const &dataLayout, mlir::Type type, bool isForHLSL=false)
mlir::Type convertTypeForLoadStore (const mlir::TypeConverter &converter, mlir::DataLayout const &dataLayout, mlir::Type type)
 The type of a load/store's value, as opposed to convertTypeForMemory's type of the memory it lives in.
mlir::TypedAttr lowerScalarConstAttr (mlir::Attribute attr, mlir::Type llvmType)
 Lower a scalar CIR constant (#cir.int, #cir.fp or #cir.bool) to a builtin attribute of type llvmType.
mlir::Attribute getBitIntStorageAttr (mlir::ConversionPatternRewriter &rewriter, cir::IntAttr attr, const mlir::DataLayout &dataLayout)

Typedef Documentation

◆ CIRPreConversionTypeMap

using CIRPreConversionTypeMap = llvm::StringMap<mlir::Type>

Definition at line 27 of file LoweringHelpers.h.

Function Documentation

◆ adjustGlobalTypeForInit() [1/2]

mlir::Type adjustGlobalTypeForInit ( mlir::Type llvmType,
mlir::Attribute init,
const mlir::TypeConverter & converter,
const mlir::DataLayout & dataLayout,
llvm::SmallVectorImpl< unsigned > & paddingAddedIndexes,
mlir::Type * failedType = nullptr )

◆ adjustGlobalTypeForInit() [2/2]

mlir::Type adjustGlobalTypeForInit ( mlir::Type llvmType,
mlir::Attribute init,
const mlir::TypeConverter & converter,
const mlir::DataLayout & dataLayout,
mlir::Type * failedType = nullptr )

Adjust llvmType (the converted type of init) to the concrete LLVM type a global constant initialized with init actually lowers to.

This differs from a plain type conversion for flexible-array-member and union initializers, and the adjustment recurses through nested aggregates. Returns llvmType unchanged when no adjustment is needed. This is the single source of truth for the shape of a lowered record constant; the value-producing paths (the insertvalue visitor and lowerConstRecordAttr) conform to it. Returns null if the input type or an initializer type cannot be lowered. If provided, failedType receives the CIR initializer type whose conversion failed, including in nested aggregates.

Definition at line 954 of file LoweringHelpers.cpp.

References adjustGlobalTypeForInit().

◆ convertStringAttrToDenseElementsAttr()

mlir::DenseElementsAttr convertStringAttrToDenseElementsAttr ( cir::ConstArrayAttr attr,
mlir::Type type )

Definition at line 168 of file LoweringHelpers.cpp.

References getIntOrBoolBitWidth().

Referenced by lowerConstArrayAttr().

◆ convertToDenseElementsAttr()

template<typename AttrTy, typename StorageTy>
std::optional< mlir::DenseElementsAttr > convertToDenseElementsAttr ( cir::ConstArrayAttr attr,
const llvm::SmallVectorImpl< int64_t > & dims,
mlir::Type convertedElementType )

Definition at line 273 of file LoweringHelpers.cpp.

References convertToDenseElementsAttrImpl(), and getZeroInitFromType().

Referenced by lowerConstArrayAttr().

◆ convertTypeForLoadStore()

mlir::Type convertTypeForLoadStore ( const mlir::TypeConverter & converter,
mlir::DataLayout const & dataLayout,
mlir::Type type )

The type of a load/store's value, as opposed to convertTypeForMemory's type of the memory it lives in.

The two are effectively identical except with split-storage bit-int.

Definition at line 138 of file LoweringHelpers.cpp.

References convertTypeForMemory(), cir::isBitIntType(), and uint64_t.

◆ convertTypeForMemory()

mlir::Type convertTypeForMemory ( const mlir::TypeConverter & converter,
mlir::DataLayout const & dataLayout,
mlir::Type type,
bool isForHLSL = false )

◆ createAnd()

mlir::Value createAnd ( mlir::OpBuilder & bld,
mlir::Value lhs,
const llvm::APInt & rhs )

Definition at line 1047 of file LoweringHelpers.cpp.

References getConstAPInt().

◆ createAShR()

mlir::Value createAShR ( mlir::OpBuilder & bld,
mlir::Value lhs,
unsigned rhs )

Definition at line 1040 of file LoweringHelpers.cpp.

References getConst().

◆ createLShR()

mlir::Value createLShR ( mlir::OpBuilder & bld,
mlir::Value lhs,
unsigned rhs )

Definition at line 1053 of file LoweringHelpers.cpp.

References getConst().

◆ createShL()

mlir::Value createShL ( mlir::OpBuilder & bld,
mlir::Value lhs,
unsigned rhs )

Definition at line 1033 of file LoweringHelpers.cpp.

References getConst().

◆ getBitIntStorageAttr()

mlir::Attribute getBitIntStorageAttr ( mlir::ConversionPatternRewriter & rewriter,
cir::IntAttr attr,
const mlir::DataLayout & dataLayout )

Definition at line 60 of file LoweringHelpers.cpp.

References bytes().

◆ getConst()

mlir::Value getConst ( mlir::OpBuilder & bld,
mlir::Location loc,
mlir::Type typ,
unsigned val )

Definition at line 1028 of file LoweringHelpers.cpp.

Referenced by createAShR(), createLShR(), and createShL().

◆ getConstAPInt()

mlir::Value getConstAPInt ( mlir::OpBuilder & bld,
mlir::Location loc,
mlir::Type typ,
const llvm::APInt & val )

Definition at line 1023 of file LoweringHelpers.cpp.

Referenced by createAnd().

◆ getZeroInitFromType() [1/3]

template<typename StorageTy>
StorageTy getZeroInitFromType ( mlir::Type ty)

Return a zero with the lowered element type's width or float semantics.

Referenced by convertToDenseElementsAttr().

◆ getZeroInitFromType() [2/3]

template<>
mlir::APInt getZeroInitFromType ( mlir::Type ty)

Definition at line 194 of file LoweringHelpers.cpp.

◆ getZeroInitFromType() [3/3]

template<>
mlir::APFloat getZeroInitFromType ( mlir::Type ty)

Definition at line 194 of file LoweringHelpers.cpp.

◆ lowerConstArrayAttr()

std::optional< mlir::Attribute > lowerConstArrayAttr ( cir::ConstArrayAttr constArr,
mlir::SymbolTableCollection & symbolTables,
const mlir::TypeConverter * converter,
const CIRPreConversionTypeMap & preConversionTypes,
mlir::ModuleOp moduleOp )

◆ lowerConstRecordAttr()

std::optional< mlir::Attribute > lowerConstRecordAttr ( cir::ConstRecordAttr constRecord,
mlir::SymbolTableCollection & symbolTables,
const mlir::TypeConverter * converter,
const CIRPreConversionTypeMap & preConversionTypes,
mlir::ModuleOp moduleOp )

◆ lowerScalarConstAttr()

mlir::TypedAttr lowerScalarConstAttr ( mlir::Attribute attr,
mlir::Type llvmType )

Lower a scalar CIR constant (#cir.int, #cir.fp or #cir.bool) to a builtin attribute of type llvmType.

Callers pass the value type (i1 for a bool) or the memory type (i8 for a bool); a split-storage _BitInt has no scalar memory form and goes through getBitIntStorageAttr instead. Returns null for any other attribute.

Definition at line 49 of file LoweringHelpers.cpp.

Referenced by lowerConstRecordMemberAttr().

◆ spellOutSplitTrailingZeros()

mlir::Attribute spellOutSplitTrailingZeros ( mlir::Attribute attr)

Return attr with the trailing zeros of any array that adjustGlobalTypeForInit would split off written out as explicit zero elements, so that it lowers to its own type.

For constants that, unlike global initializers, cannot change type.

Definition at line 419 of file LoweringHelpers.cpp.

References containsSplitTrailingZeros(), shouldSplitTrailingZeros(), and spellOutSplitTrailingZeros().

Referenced by spellOutSplitTrailingZeros().