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"

Go to the source code of this file.

Functions

mlir::DenseElementsAttr convertStringAttrToDenseElementsAttr (cir::ConstArrayAttr attr, mlir::Type type)
template<typename StorageTy>
StorageTy getZeroInitFromType (mlir::Type ty)
template<>
mlir::APInt getZeroInitFromType (mlir::Type ty)
template<>
mlir::APFloat getZeroInitFromType (mlir::Type ty)
template<typename AttrTy, typename StorageTy>
void convertToDenseElementsAttrImpl (cir::ConstArrayAttr attr, llvm::SmallVectorImpl< StorageTy > &values)
template<typename AttrTy, typename StorageTy>
mlir::DenseElementsAttr convertToDenseElementsAttr (cir::ConstArrayAttr attr, const llvm::SmallVectorImpl< int64_t > &dims, mlir::Type type)
std::optional< mlir::Attribute > lowerConstArrayAttr (cir::ConstArrayAttr constArr, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp={})
std::optional< mlir::Attribute > lowerConstRecordAttr (cir::ConstRecordAttr constRecord, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, 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)
 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::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::Attribute getBitIntStorageAttr (mlir::ConversionPatternRewriter &rewriter, cir::IntAttr attr, const mlir::DataLayout &dataLayout)

Function Documentation

◆ adjustGlobalTypeForInit() [1/2]

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

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.

Definition at line 909 of file LoweringHelpers.cpp.

References adjustGlobalTypeForInit().

◆ adjustGlobalTypeForInit() [2/2]

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

◆ convertStringAttrToDenseElementsAttr()

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

Definition at line 155 of file LoweringHelpers.cpp.

References getIntOrBoolBitWidth().

Referenced by lowerConstArrayAttr().

◆ convertToDenseElementsAttr()

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

◆ convertToDenseElementsAttrImpl()

template<typename AttrTy, typename StorageTy>
void convertToDenseElementsAttrImpl ( cir::ConstArrayAttr attr,
llvm::SmallVectorImpl< StorageTy > & values )

◆ 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 124 of file LoweringHelpers.cpp.

References convertTypeForMemory().

◆ 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 998 of file LoweringHelpers.cpp.

References getConstAPInt().

◆ createAShR()

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

Definition at line 991 of file LoweringHelpers.cpp.

References getConst().

◆ createLShR()

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

Definition at line 1004 of file LoweringHelpers.cpp.

References getConst().

◆ createShL()

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

Definition at line 984 of file LoweringHelpers.cpp.

References getConst().

◆ getBitIntStorageAttr()

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

Definition at line 46 of file LoweringHelpers.cpp.

References bytes().

Referenced by cir::direct::GlobalInitAttrRewriter::visitCirAttr().

◆ getConst()

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

Definition at line 979 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 974 of file LoweringHelpers.cpp.

Referenced by createAnd().

◆ getZeroInitFromType() [1/3]

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

◆ getZeroInitFromType() [2/3]

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

Definition at line 181 of file LoweringHelpers.cpp.

◆ getZeroInitFromType() [3/3]

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

Definition at line 181 of file LoweringHelpers.cpp.

◆ lowerConstArrayAttr()

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

◆ lowerConstRecordAttr()

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

◆ 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 396 of file LoweringHelpers.cpp.

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

Referenced by spellOutSplitTrailingZeros().