52
52
#include " llvm/ADT/APInt.h"
53
53
#include " llvm/ADT/ArrayRef.h"
54
54
#include " llvm/ADT/STLExtras.h"
55
- #include " llvm/ADT/SmallVector.h"
56
55
#include " llvm/ADT/StringRef.h"
57
56
#include " llvm/ADT/Twine.h"
58
57
#include " llvm/ADT/TypeSwitch.h"
@@ -2353,10 +2352,10 @@ mlir::LogicalResult CIRToLLVMSwitchFlatOpLowering::matchAndRewrite(
2353
2352
// / insertion point to the end of the initializer block.
2354
2353
void CIRToLLVMGlobalOpLowering::createRegionInitializedLLVMGlobalOp (
2355
2354
cir::GlobalOp op, mlir::Attribute attr,
2356
- mlir::ConversionPatternRewriter &rewriter) const {
2355
+ mlir::ConversionPatternRewriter &rewriter,
2356
+ SmallVector<mlir::NamedAttribute> attributes) const {
2357
2357
const auto llvmType =
2358
2358
convertTypeForMemory (*getTypeConverter (), dataLayout, op.getSymType ());
2359
- SmallVector<mlir::NamedAttribute> attributes;
2360
2359
auto newGlobalOp = rewriter.replaceOpWithNewOp <mlir::LLVM::GlobalOp>(
2361
2360
op, llvmType, op.getConstant (), convertLinkage (op.getLinkage ()),
2362
2361
op.getSymName (), nullptr ,
@@ -2433,7 +2432,8 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
2433
2432
// TODO(cir): once LLVM's dialect has proper equivalent attributes this
2434
2433
// should be updated. For now, we use a custom op to initialize globals
2435
2434
// to the appropriate value.
2436
- createRegionInitializedLLVMGlobalOp (op, init.value (), rewriter);
2435
+ createRegionInitializedLLVMGlobalOp (op, init.value (), rewriter,
2436
+ attributes);
2437
2437
return mlir::success ();
2438
2438
} else if (auto constArr =
2439
2439
mlir::dyn_cast<cir::ConstArrayAttr>(init.value ())) {
@@ -2448,7 +2448,8 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
2448
2448
// Failed to use a compact attribute as an initializer:
2449
2449
// initialize elements individually.
2450
2450
if (!(init = lowerConstArrayAttr (constArr, getTypeConverter ()))) {
2451
- createRegionInitializedLLVMGlobalOp (op, constArr, rewriter);
2451
+ createRegionInitializedLLVMGlobalOp (op, constArr, rewriter,
2452
+ attributes);
2452
2453
return mlir::success ();
2453
2454
}
2454
2455
} else {
@@ -2466,6 +2467,7 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
2466
2467
auto abiOp = mlir::cast<GlobalOp>(rewriter.clone (*op.getOperation ()));
2467
2468
abiOp.setInitialValueAttr (abiValue);
2468
2469
abiOp.setSymType (abiValue.getType ());
2470
+ abiOp->setAttrs (attributes);
2469
2471
rewriter.replaceOp (op, abiOp);
2470
2472
return mlir::success ();
2471
2473
} else {
0 commit comments