clang 23.0.0git
LoweringHelpers.cpp File Reference
#include "clang/CIR/LoweringHelpers.h"
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
#include "mlir/IR/SymbolTable.h"

Go to the source code of this file.

Functions

static unsigned getIntOrBoolBitWidth (mlir::Type ty)
mlir::DenseElementsAttr convertStringAttrToDenseElementsAttr (cir::ConstArrayAttr attr, mlir::Type type)
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, const llvm::SmallVectorImpl< int64_t > &currentDims, int64_t dimIndex, int64_t currentIndex)
template<typename AttrTy, typename StorageTy>
mlir::DenseElementsAttr convertToDenseElementsAttr (cir::ConstArrayAttr attr, const llvm::SmallVectorImpl< int64_t > &dims, mlir::Type elementType, mlir::Type convertedElementType)
static bool globalViewMatchesPointerLeaf (cir::GlobalViewAttr gv, mlir::ModuleOp moduleOp, const mlir::TypeConverter *converter)
 Return true when gv can be lowered to a FlatSymbolRefAttr leaf without addrspacecast or bitcast (mirrors CIRAttrToValue::visitCirAttr).
static std::optional< mlir::Attribute > lowerPointerElementAttr (mlir::Attribute elt, mlir::MLIRContext *ctx, mlir::ModuleOp moduleOp, const mlir::TypeConverter *converter)
 Lower a single pointer-element of a cir.const_array to an LLVM-dialect constant leaf suitable for a bulk llvm.mlir.constant.
static bool containsPoison (mlir::Attribute attr)
std::optional< mlir::Attribute > lowerConstArrayAttr (cir::ConstArrayAttr constArr, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp)
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)

Function Documentation

◆ containsPoison()

bool containsPoison ( mlir::Attribute attr)
static

Definition at line 209 of file LoweringHelpers.cpp.

References containsPoison().

Referenced by containsPoison(), and lowerConstArrayAttr().

◆ convertStringAttrToDenseElementsAttr()

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

Definition at line 27 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 elementType,
mlir::Type convertedElementType )

Definition at line 131 of file LoweringHelpers.cpp.

References convertToDenseElementsAttrImpl(), and getZeroInitFromType().

Referenced by lowerConstArrayAttr().

◆ convertToDenseElementsAttrImpl()

template<typename AttrTy, typename StorageTy>
void convertToDenseElementsAttrImpl ( cir::ConstArrayAttr attr,
llvm::SmallVectorImpl< StorageTy > & values,
const llvm::SmallVectorImpl< int64_t > & currentDims,
int64_t dimIndex,
int64_t currentIndex )
Parameters
attrthe ConstArrayAttr to convert
valuesthe output parameter, the values array to fill
currentDimsthe shpae of tensor we're going to convert to
dimIndexthe current dimension we're processing
currentIndexthe current index in the values array

Definition at line 79 of file LoweringHelpers.cpp.

References convertToDenseElementsAttrImpl().

Referenced by convertToDenseElementsAttr(), and convertToDenseElementsAttrImpl().

◆ createAnd()

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

Definition at line 307 of file LoweringHelpers.cpp.

References getConstAPInt().

◆ createAShR()

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

Definition at line 300 of file LoweringHelpers.cpp.

References getConst().

◆ createLShR()

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

Definition at line 313 of file LoweringHelpers.cpp.

References getConst().

◆ createShL()

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

Definition at line 293 of file LoweringHelpers.cpp.

References getConst().

◆ getConst()

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

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

Referenced by createAnd().

◆ getIntOrBoolBitWidth()

unsigned getIntOrBoolBitWidth ( mlir::Type ty)
static

Definition at line 18 of file LoweringHelpers.cpp.

Referenced by convertStringAttrToDenseElementsAttr().

◆ getZeroInitFromType() [1/2]

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

Definition at line 53 of file LoweringHelpers.cpp.

◆ getZeroInitFromType() [2/2]

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

Definition at line 60 of file LoweringHelpers.cpp.

◆ globalViewMatchesPointerLeaf()

bool globalViewMatchesPointerLeaf ( cir::GlobalViewAttr gv,
mlir::ModuleOp moduleOp,
const mlir::TypeConverter * converter )
static

Return true when gv can be lowered to a FlatSymbolRefAttr leaf without addrspacecast or bitcast (mirrors CIRAttrToValue::visitCirAttr).

Definition at line 148 of file LoweringHelpers.cpp.

Referenced by lowerPointerElementAttr().

◆ lowerConstArrayAttr()

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

◆ lowerPointerElementAttr()

std::optional< mlir::Attribute > lowerPointerElementAttr ( mlir::Attribute elt,
mlir::MLIRContext * ctx,
mlir::ModuleOp moduleOp,
const mlir::TypeConverter * converter )
static

Lower a single pointer-element of a cir.const_array to an LLVM-dialect constant leaf suitable for a bulk llvm.mlir.constant.

Only handles address-of-global without indices and null pointers; indexed global views must use the per-element llvm.insertvalue fallback.

Definition at line 193 of file LoweringHelpers.cpp.

References globalViewMatchesPointerLeaf().

Referenced by lowerConstArrayAttr().