14#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
15#include "mlir/Dialect/LLVMIR/LLVMTypes.h"
16#include "mlir/IR/BuiltinTypes.h"
17#include "mlir/IR/SymbolTable.h"
18#include "mlir/Interfaces/DataLayoutInterfaces.h"
27bool isSplitStorageBitInt(cir::IntType ty,
const mlir::DataLayout &dataLayout) {
30 unsigned storageBits = ty.getStorageTypeWidth(dataLayout);
31 auto storageTy = mlir::IntegerType::get(ty.getContext(), storageBits);
32 uint64_t storeSize = storageBits / 8;
34 llvm::alignTo(storeSize, dataLayout.getTypeABIAlignment(storageTy));
35 return allocSize != storeSize;
39bool isBigEndian(
const mlir::DataLayout &dataLayout) {
41 mlir::dyn_cast_or_null<mlir::StringAttr>(dataLayout.getEndianness());
42 return endiannessStr && endiannessStr ==
"big";
48 const mlir::DataLayout &dataLayout) {
49 auto intTy = mlir::cast<cir::IntType>(attr.getType());
50 unsigned storageBits = intTy.getStorageTypeWidth(dataLayout);
51 llvm::APInt val = attr.getValue();
52 val = intTy.isSigned() ? val.sext(storageBits) : val.zext(storageBits);
54 if (!isSplitStorageBitInt(intTy, dataLayout))
55 return rewriter.getIntegerAttr(
56 mlir::IntegerType::get(intTy.getContext(), storageBits), val);
58 if (isBigEndian(dataLayout))
63 unsigned numBytes = storageBits / 8;
65 bytes.reserve(numBytes);
66 for (
unsigned i = 0; i != numBytes; ++i)
67 bytes.emplace_back(8, val.extractBitsAsZExtValue(8, i * 8));
69 auto i8Ty = mlir::IntegerType::get(intTy.getContext(), 8);
70 return mlir::DenseElementsAttr::get(
71 mlir::RankedTensorType::get({numBytes}, i8Ty),
bytes);
75 mlir::DataLayout
const &dataLayout,
79 if (mlir::isa<cir::BoolType>(type)) {
80 return mlir::IntegerType::get(type.getContext(),
81 dataLayout.getTypeSizeInBits(type));
84 if (
auto matrixTy = mlir::dyn_cast<cir::MatrixType>(type)) {
85 if (mlir::isa<cir::BoolType>(matrixTy.getElementType())) {
88 "convertTypeForMemory: Matrix with bool as element type");
91 uint64_t size = matrixTy.getNumRows() * matrixTy.getNumColumns();
92 mlir::Type elementType = converter.convertType(matrixTy.getElementType());
93 return mlir::LLVM::LLVMArrayType::get(elementType, size);
96 if (
auto vecTy = mlir::dyn_cast<cir::VectorType>(type)) {
97 if (mlir::isa<cir::BoolType>(vecTy.getElementType())) {
99 return mlir::IntegerType::get(type.getContext(),
100 vecTy.getBoolStorageWidth());
109 if (
auto intTy = mlir::dyn_cast<cir::IntType>(type);
110 intTy && intTy.isBitInt()) {
111 if (isSplitStorageBitInt(intTy, dataLayout))
112 return mlir::LLVM::LLVMArrayType::get(
113 mlir::IntegerType::get(type.getContext(), 8),
114 intTy.getStorageTypeWidth(dataLayout) / 8);
115 return mlir::IntegerType::get(type.getContext(),
116 intTy.getStorageTypeWidth(dataLayout));
119 return converter.convertType(type);
123 mlir::DataLayout
const &dataLayout,
128 if (
auto intTy = mlir::dyn_cast<cir::IntType>(type);
129 intTy && intTy.isBitInt())
130 return mlir::IntegerType::get(type.getContext(),
131 intTy.getStorageTypeWidth(dataLayout));
135 if (
auto matrixTy = mlir::dyn_cast<cir::MatrixType>(type)) {
136 uint64_t size = matrixTy.getNumRows() * matrixTy.getNumColumns();
137 mlir::Type elemTy = converter.convertType(matrixTy.getElementType());
138 return mlir::VectorType::get(size, elemTy);
145 if (
auto intTy = mlir::dyn_cast<cir::IntType>(ty))
146 return intTy.getWidth();
147 assert(mlir::isa<cir::BoolType>(ty) &&
148 "expected CIR integer or bool element type");
152mlir::DenseElementsAttr
155 const auto stringAttr = mlir::cast<mlir::StringAttr>(attr.getElts());
156 const auto arrayTy = mlir::cast<cir::ArrayType>(attr.getType());
157 const unsigned totalSize = arrayTy.getSize();
158 const unsigned trailingZeros = attr.getTrailingZerosNum();
159 assert(stringAttr.size() + trailingZeros == totalSize &&
160 "string const_array size must match explicit elements plus "
165 values.reserve(totalSize);
170 for (
const char element : stringAttr)
171 values.emplace_back(bitWidth,
static_cast<unsigned char>(element));
173 values.insert(values.end(), trailingZeros, mlir::APInt::getZero(bitWidth));
175 return mlir::DenseElementsAttr::get(
176 mlir::RankedTensorType::get({totalSize}, type),
llvm::ArrayRef(values));
180 if (mlir::isa<cir::BoolType>(ty))
181 return mlir::APInt::getZero(1);
182 const auto intTy = mlir::cast<cir::IntType>(ty);
183 return mlir::APInt::getZero(intTy.getWidth());
187 auto fpTy = mlir::cast<cir::FPTypeInterface>(ty);
188 return mlir::APFloat::getZero(fpTy.getFloatSemantics());
196template <
typename AttrTy,
typename StorageTy>
200 int64_t currentIndex) {
201 if (
auto stringAttr = mlir::dyn_cast<mlir::StringAttr>(attr.getElts())) {
202 if (
auto arrayType = mlir::dyn_cast<cir::ArrayType>(attr.getType())) {
203 for (
auto element : stringAttr) {
204 auto intAttr = cir::IntAttr::get(arrayType.getElementType(), element);
205 values[currentIndex++] = mlir::dyn_cast<AttrTy>(intAttr).getValue();
208 currentIndex += attr.getTrailingZerosNum();
214 std::size_t elementsSizeInCurrentDim = 1;
215 for (std::size_t i = dimIndex; i < currentDims.size(); i++)
216 elementsSizeInCurrentDim *= currentDims[i];
218 auto arrayAttr = mlir::cast<mlir::ArrayAttr>(attr.getElts());
219 for (
auto eltAttr : arrayAttr) {
220 if constexpr (std::is_same_v<StorageTy, mlir::APInt>) {
221 if (
auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(eltAttr)) {
222 values[currentIndex++] =
223 llvm::APInt(1,
static_cast<uint64_t
>(boolAttr.getValue()));
227 if (
auto valueAttr = mlir::dyn_cast<AttrTy>(eltAttr)) {
228 values[currentIndex++] = valueAttr.getValue();
232 if (
auto subArrayAttr = mlir::dyn_cast<cir::ConstArrayAttr>(eltAttr)) {
234 dimIndex, currentIndex);
235 currentIndex += elementsSizeInCurrentDim;
239 if (mlir::isa<cir::ZeroAttr, cir::UndefAttr>(eltAttr)) {
240 currentIndex += elementsSizeInCurrentDim;
246 if (
auto global = mlir::dyn_cast<cir::GlobalViewAttr>(eltAttr))
249 llvm_unreachable(
"unknown element in ConstArrayAttr");
254template <
typename AttrTy,
typename StorageTy>
257 mlir::Type elementType, mlir::Type convertedElementType) {
258 unsigned vectorSize = 1;
259 for (
auto dim : dims)
269 return mlir::DenseElementsAttr::get(
270 mlir::RankedTensorType::get(dims, convertedElementType),
278 mlir::SymbolTableCollection &symbolTables,
279 const mlir::TypeConverter *converter) {
280 if (gv.getIndices() || mlir::isa<cir::IntType, cir::VPtrType>(gv.getType()))
283 auto ptrTy = mlir::dyn_cast<cir::PointerType>(gv.getType());
287 unsigned sourceAddrSpace = 0;
288 mlir::Type sourceType;
289 auto sourceSymbol = symbolTables.lookupSymbolIn(moduleOp, gv.getSymbol());
290 if (
auto llvmSymbol = mlir::dyn_cast<mlir::LLVM::GlobalOp>(sourceSymbol)) {
291 sourceType = llvmSymbol.getType();
292 sourceAddrSpace = llvmSymbol.getAddrSpace();
293 }
else if (
auto cirSymbol = mlir::dyn_cast<cir::GlobalOp>(sourceSymbol)) {
294 sourceType = converter->convertType(cirSymbol.getSymType());
295 if (
auto targetAS = mlir::dyn_cast_if_present<cir::TargetAddressSpaceAttr>(
296 cirSymbol.getAddrSpaceAttr()))
297 sourceAddrSpace = targetAS.getValue();
304 auto llvmDstTy = converter->convertType<mlir::LLVM::LLVMPointerType>(ptrTy);
305 if (llvmDstTy.getAddressSpace() != sourceAddrSpace)
308 mlir::Type llvmEltTy = converter->convertType(ptrTy.getPointee());
309 if (llvmEltTy == sourceType)
311 if (
auto arrTy = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(sourceType))
312 return llvmEltTy == arrTy.getElementType();
320static std::optional<mlir::Attribute>
322 mlir::ModuleOp moduleOp,
323 mlir::SymbolTableCollection &symbolTables,
324 const mlir::TypeConverter *converter) {
325 if (
auto gv = mlir::dyn_cast<cir::GlobalViewAttr>(elt)) {
329 return gv.getSymbol();
331 if (
auto nullPtr = mlir::dyn_cast<cir::ConstPtrAttr>(elt)) {
332 if (nullPtr.isNullValue())
333 return mlir::LLVM::ZeroAttr::get(ctx);
340 if (mlir::isa<cir::PoisonAttr>(attr))
342 if (
auto elts = mlir::dyn_cast<mlir::ArrayAttr>(attr))
344 if (
auto constArr = mlir::dyn_cast<cir::ConstArrayAttr>(attr)) {
345 if (mlir::isa<mlir::StringAttr>(constArr.getElts()))
347 if (
auto elts = mlir::dyn_cast<mlir::ArrayAttr>(constArr.getElts()))
359 if (mlir::isa<cir::BlockAddrInfoAttr, cir::BlockAddrDiffAttr>(attr))
361 if (
auto elts = mlir::dyn_cast<mlir::ArrayAttr>(attr))
363 if (
auto constArr = mlir::dyn_cast<cir::ConstArrayAttr>(attr)) {
364 if (mlir::isa<mlir::StringAttr>(constArr.getElts()))
366 if (
auto elts = mlir::dyn_cast<mlir::ArrayAttr>(constArr.getElts()))
373 mlir::Attribute attr, mlir::SymbolTableCollection &symbolTables,
374 const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp);
377 cir::ConstArrayAttr constArr, mlir::SymbolTableCollection &symbolTables,
378 const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp) {
380 const auto typedConstArr = mlir::cast<mlir::TypedAttr>(constArr);
383 const auto cirArrayType = mlir::cast<cir::ArrayType>(typedConstArr.getType());
386 mlir::Type type = cirArrayType;
388 while (
auto arrayType = mlir::dyn_cast<cir::ArrayType>(type)) {
389 dims.push_back(arrayType.getSize());
390 type = arrayType.getElementType();
401 if (mlir::isa<mlir::StringAttr>(constArr.getElts()))
403 converter->convertType(type));
404 if (mlir::isa<cir::IntType>(type)) {
408 if (mlir::cast<cir::IntType>(type).isBitInt())
411 constArr, dims, type, converter->convertType(type));
414 if (mlir::isa<cir::BoolType>(type))
416 constArr, dims, type, converter->convertType(type));
418 if (mlir::isa<cir::FPTypeInterface>(type))
420 constArr, dims, type, converter->convertType(type));
422 if (mlir::isa<cir::PointerType>(type)) {
425 if (constArr.getTrailingZerosNum() > 0)
427 auto eltsArr = mlir::dyn_cast<mlir::ArrayAttr>(constArr.getElts());
431 lowered.reserve(eltsArr.size());
432 mlir::MLIRContext *ctx = constArr.getContext();
433 for (mlir::Attribute elt : eltsArr) {
434 std::optional<mlir::Attribute> llvmElt =
438 lowered.push_back(*llvmElt);
440 return mlir::ArrayAttr::get(ctx, lowered);
443 if (mlir::isa<cir::RecordType>(type)) {
445 auto eltsArr = mlir::dyn_cast<mlir::ArrayAttr>(constArr.getElts());
450 loweredElts.reserve(cirArrayType.getSize());
452 for (mlir::Attribute elt : eltsArr) {
453 std::optional<mlir::Attribute> llvmElt =
457 loweredElts.push_back(*llvmElt);
463 while (loweredElts.size() < cirArrayType.getSize())
464 loweredElts.push_back(mlir::LLVM::ZeroAttr::get(constArr.getContext()));
465 return mlir::ArrayAttr::get(constArr.getContext(), loweredElts);
479 mlir::Attribute attr, mlir::SymbolTableCollection &symbolTables,
480 const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp) {
481 mlir::MLIRContext *ctx = attr.getContext();
483 if (
auto arrayAttr = mlir::dyn_cast<cir::ConstArrayAttr>(attr))
486 if (
auto recordAttr = mlir::dyn_cast<cir::ConstRecordAttr>(attr))
489 if (mlir::isa<cir::ZeroAttr>(attr))
490 return mlir::LLVM::ZeroAttr::get(ctx);
492 if (mlir::isa<cir::UndefAttr>(attr))
493 return mlir::LLVM::UndefAttr::get(ctx);
495 if (
auto intAttr = mlir::dyn_cast<cir::IntAttr>(attr)) {
498 if (mlir::cast<cir::IntType>(intAttr.getType()).isBitInt())
500 return mlir::IntegerAttr::get(converter->convertType(intAttr.getType()),
504 if (
auto boolAttr = mlir::dyn_cast<cir::BoolAttr>(attr))
505 return mlir::IntegerAttr::get(converter->convertType(boolAttr.getType()),
506 boolAttr.getValue() ? 1 : 0);
508 if (
auto fpAttr = mlir::dyn_cast<cir::FPAttr>(attr))
509 return mlir::FloatAttr::get(converter->convertType(fpAttr.getType()),
528 uint64_t maxAlign = 1;
529 uint64_t totalSize = 0;
530 for (mlir::Type member : members) {
531 uint64_t align = dataLayout.getTypeABIAlignment(member);
532 maxAlign = std::max(maxAlign, align);
533 uint64_t size = dataLayout.getTypeSize(member).getFixedValue();
535 if (llvm::alignTo(totalSize, align) != totalSize)
540 return llvm::alignTo(totalSize, maxAlign) != totalSize;
559 mlir::LLVM::LLVMStructType structTy, cir::ConstRecordAttr constRecord,
560 const mlir::TypeConverter &converter,
const mlir::DataLayout &dataLayout,
562 assert(paddingAddedIndexes.empty() &&
563 "Not for accumulation, just single depth");
565 constRecord.getMembers().getValue();
568 bool packed = structTy.isPacked();
569 uint64_t curOffset = 0;
570 bool changed =
false;
576 for (
auto [idx, member] : llvm::enumerate(initMembers)) {
577 if (idx >= origBody.size())
579 mlir::Type adjusted =
581 unsigned adjustedAlign = dataLayout.getTypeABIAlignment(adjusted);
583 if (adjusted != origBody[idx]) {
587 unsigned origAlign = dataLayout.getTypeABIAlignment(origBody[idx]);
589 uint64_t origOffset =
590 packed ? curOffset : llvm::alignTo(curOffset, origAlign);
591 uint64_t adjustedOffset =
592 packed ? curOffset : llvm::alignTo(curOffset, adjustedAlign);
594 if (adjustedOffset != origOffset) {
598 assert(adjustedOffset < origOffset);
602 uint64_t difference = origOffset - curOffset;
603 newBody.push_back(mlir::LLVM::LLVMArrayType::get(
604 mlir::IntegerType::get(structTy.getContext(), 8), difference));
605 paddingAddedIndexes.push_back(idx);
606 curOffset = origOffset;
610 newBody.push_back(adjusted);
613 curOffset = llvm::alignTo(curOffset, adjustedAlign);
614 curOffset += dataLayout.getTypeSize(adjusted).getFixedValue();
623 bool widenedFAM =
false;
625 mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(structTy.getBody().back());
626 fam && fam.getNumElements() == 0) {
627 mlir::Type lastInitType =
628 mlir::cast<mlir::TypedAttr>(initMembers.back()).getType();
629 if (mlir::cast<cir::ArrayType>(lastInitType).getSize() != 0) {
632 initMembers.back(), converter, dataLayout);
647 uint64_t declaredSize = dataLayout.getTypeSize(structTy).getFixedValue();
648 assert(curOffset <= declaredSize &&
"body bigger than type?");
649 if (curOffset < declaredSize)
650 newBody.push_back(mlir::LLVM::LLVMArrayType::get(
651 mlir::IntegerType::get(structTy.getContext(), 8),
652 declaredSize - curOffset));
655 return mlir::LLVM::LLVMStructType::getLiteral(structTy.getContext(), newBody,
668 mlir::LLVM::LLVMStructType structTy, cir::ConstRecordAttr constRecord,
669 const mlir::TypeConverter &converter,
const mlir::DataLayout &dataLayout) {
671 auto unionTy = mlir::cast<cir::UnionType>(constRecord.getType());
674 assert(constRecord.getMembers().size() == 1);
675 mlir::Attribute member = constRecord.getMembers()[0];
677 converter, dataLayout, mlir::cast<mlir::TypedAttr>(member).
getType());
687 if (memberTy == structTy.getBody().front())
690 uint64_t unionSize = dataLayout.getTypeSize(unionTy).getFixedValue();
691 uint64_t initSize = dataLayout.getTypeSize(memberTy).getFixedValue();
692 assert(initSize <= unionSize &&
"union initializer larger than the union");
695 newBody.push_back(memberTy);
698 if (initSize < unionSize)
699 newBody.push_back(mlir::LLVM::LLVMArrayType::get(
700 mlir::IntegerType::get(structTy.getContext(), 8),
701 unionSize - initSize));
703 return mlir::LLVM::LLVMStructType::getLiteral(structTy.getContext(), newBody,
704 unionTy.getPacked());
711 mlir::LLVM::LLVMArrayType arrayTy, cir::ConstArrayAttr arrayInit,
712 const mlir::TypeConverter &converter,
const mlir::DataLayout &dataLayout) {
713 auto elts = mlir::dyn_cast<mlir::ArrayAttr>(arrayInit.getElts());
718 mlir::Type origEltTy = arrayTy.getElementType();
721 bool changed =
false;
723 for (
auto [idx, elt] : llvm::enumerate(elts)) {
724 mlir::Type adjusted =
727 if (idx >= arrayTy.getNumElements()) {
728 adjustedElts.push_back(adjusted);
730 }
else if (adjusted != origEltTy) {
731 adjustedElts[idx] = adjusted;
739 if (llvm::all_equal(adjustedElts))
740 return mlir::LLVM::LLVMArrayType::get(adjustedElts.front(),
741 adjustedElts.size());
744 return mlir::LLVM::LLVMStructType::getLiteral(
745 arrayTy.getContext(), adjustedElts,
true);
751 const mlir::TypeConverter &converter,
752 const mlir::DataLayout &dataLayout,
754 if (
auto arrayInit = mlir::dyn_cast_if_present<cir::ConstArrayAttr>(init)) {
755 auto arrayTy = mlir::dyn_cast<mlir::LLVM::LLVMArrayType>(llvmType);
763 auto constRecord = mlir::dyn_cast_if_present<cir::ConstRecordAttr>(init);
769 auto structTy = mlir::dyn_cast<mlir::LLVM::LLVMStructType>(llvmType);
770 if (!structTy || structTy.getBody().empty())
774 if (mlir::isa<cir::StructType>(constRecord.getType()))
776 dataLayout, paddingAddedIndexes);
777 if (mlir::isa<cir::UnionType>(constRecord.getType()))
784 const mlir::TypeConverter &converter,
785 const mlir::DataLayout &dataLayout) {
788 ignoredAddedIndexes);
792 cir::ConstRecordAttr constRecord, mlir::SymbolTableCollection &symbolTables,
793 const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp) {
799 mlir::ArrayAttr memberAttrs = constRecord.getMembers();
801 loweredMembers.reserve(memberAttrs.size());
802 for (mlir::Attribute member : memberAttrs) {
803 std::optional<mlir::Attribute> lowered =
807 loweredMembers.push_back(*lowered);
825 converter->convertType(constRecord.getType()), constRecord, *converter,
826 mlir::DataLayout(moduleOp), paddingAddedIndexes);
831 for (
unsigned paddedElt : llvm::reverse(paddingAddedIndexes))
832 loweredMembers.insert(loweredMembers.begin() + paddedElt,
833 mlir::LLVM::ZeroAttr::get(constRecord.getContext()));
838 if (
auto structTy = mlir::dyn_cast<mlir::LLVM::LLVMStructType>(adjustedTy))
839 while (loweredMembers.size() < structTy.getBody().size())
840 loweredMembers.push_back(
841 mlir::LLVM::ZeroAttr::get(constRecord.getContext()));
843 return mlir::ArrayAttr::get(constRecord.getContext(), loweredMembers);
847 mlir::Type typ,
const llvm::APInt &val) {
848 return mlir::LLVM::ConstantOp::create(bld, loc, typ, val);
851mlir::Value
getConst(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ,
853 return mlir::LLVM::ConstantOp::create(bld, loc, typ, val);
856mlir::Value
createShL(mlir::OpBuilder &bld, mlir::Value lhs,
unsigned rhs) {
859 mlir::Value rhsVal =
getConst(bld, lhs.getLoc(), lhs.getType(), rhs);
860 return mlir::LLVM::ShlOp::create(bld, lhs.getLoc(), lhs, rhsVal);
863mlir::Value
createAShR(mlir::OpBuilder &bld, mlir::Value lhs,
unsigned rhs) {
866 mlir::Value rhsVal =
getConst(bld, lhs.getLoc(), lhs.getType(), rhs);
867 return mlir::LLVM::AShrOp::create(bld, lhs.getLoc(), lhs, rhsVal);
870mlir::Value
createAnd(mlir::OpBuilder &bld, mlir::Value lhs,
871 const llvm::APInt &rhs) {
872 mlir::Value rhsVal =
getConstAPInt(bld, lhs.getLoc(), lhs.getType(), rhs);
873 return mlir::LLVM::AndOp::create(bld, lhs.getLoc(), lhs, rhsVal);
876mlir::Value
createLShR(mlir::OpBuilder &bld, mlir::Value lhs,
unsigned rhs) {
879 mlir::Value rhsVal =
getConst(bld, lhs.getLoc(), lhs.getType(), rhs);
880 return mlir::LLVM::LShrOp::create(bld, lhs.getLoc(), lhs, rhsVal);
static StringRef bytes(const std::vector< T, Allocator > &v)
mlir::DenseElementsAttr convertStringAttrToDenseElementsAttr(cir::ConstArrayAttr attr, mlir::Type type)
mlir::Type convertTypeForMemory(const mlir::TypeConverter &converter, mlir::DataLayout const &dataLayout, mlir::Type type)
static bool globalViewMatchesPointerLeaf(cir::GlobalViewAttr gv, mlir::ModuleOp moduleOp, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter)
Return true when gv can be lowered to a FlatSymbolRefAttr leaf without addrspacecast or bitcast (mirr...
mlir::Value createLShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
mlir::Value createShL(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
mlir::Value getConst(mlir::OpBuilder &bld, mlir::Location loc, mlir::Type typ, unsigned val)
static mlir::Type adjustGlobalStructTypeForInit(mlir::LLVM::LLVMStructType structTy, cir::ConstRecordAttr constRecord, 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)
std::optional< mlir::DenseElementsAttr > convertToDenseElementsAttr(cir::ConstArrayAttr attr, const llvm::SmallVectorImpl< int64_t > &dims, mlir::Type elementType, mlir::Type convertedElementType)
std::optional< mlir::Attribute > lowerConstArrayAttr(cir::ConstArrayAttr constArr, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp)
mlir::Type adjustGlobalTypeForInit(mlir::Type llvmType, mlir::Attribute init, const mlir::TypeConverter &converter, const mlir::DataLayout &dataLayout, llvm::SmallVectorImpl< unsigned > &paddingAddedIndexes)
static mlir::Type adjustGlobalArrayTypeForInit(mlir::LLVM::LLVMArrayType arrayTy, cir::ConstArrayAttr arrayInit, const mlir::TypeConverter &converter, const mlir::DataLayout &dataLayout)
static bool containsPoison(mlir::Attribute attr)
static std::optional< mlir::Attribute > lowerPointerElementAttr(mlir::Attribute elt, mlir::MLIRContext *ctx, mlir::ModuleOp moduleOp, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter)
Lower a single pointer-element of a cir.const_array to an LLVM-dialect constant leaf suitable for a b...
mlir::Value createAShR(mlir::OpBuilder &bld, mlir::Value lhs, unsigned rhs)
std::optional< mlir::Attribute > lowerConstRecordAttr(cir::ConstRecordAttr constRecord, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp)
static std::optional< mlir::Attribute > lowerConstRecordMemberAttr(mlir::Attribute attr, mlir::SymbolTableCollection &symbolTables, const mlir::TypeConverter *converter, mlir::ModuleOp moduleOp)
Lower a constant attribute that initializes a single member of a record (or a leaf of a nested aggreg...
mlir::Value createAnd(mlir::OpBuilder &bld, mlir::Value lhs, const llvm::APInt &rhs)
bool convertToDenseElementsAttrImpl(cir::ConstArrayAttr attr, llvm::SmallVectorImpl< StorageTy > &values, const llvm::SmallVectorImpl< int64_t > ¤tDims, int64_t dimIndex, int64_t currentIndex)
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...
static bool shouldPackFAMStruct(const mlir::DataLayout &dataLayout, llvm::ArrayRef< mlir::Type > members)
static bool containsBlockAddress(mlir::Attribute attr)
Block-address attributes (address-of-label and label differences) are lowered to relocation expressio...
static mlir::Type adjustGlobalUnionTypeForInit(mlir::LLVM::LLVMStructType structTy, cir::ConstRecordAttr constRecord, const mlir::TypeConverter &converter, const mlir::DataLayout &dataLayout)
mlir::Attribute getBitIntStorageAttr(mlir::ConversionPatternRewriter &rewriter, cir::IntAttr attr, const mlir::DataLayout &dataLayout)
mlir::APInt getZeroInitFromType(mlir::Type ty)
static unsigned getIntOrBoolBitWidth(mlir::Type ty)
StorageTy getZeroInitFromType(mlir::Type ty)
void convertToDenseElementsAttrImpl(cir::ConstArrayAttr attr, llvm::SmallVectorImpl< StorageTy > &values)