@@ -1002,16 +1002,15 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
1002
1002
// The ancestor OpenMP Op which is outlineable.
1003
1003
// The ancestor LLVM Function Op.
1004
1004
if (auto iface =
1005
- thisBlock->getParent ()
1006
- ->getParentOfType <
1007
- mlir::omp::OutlineableOpenMPOpInterface>()) {
1008
- rewriter.setInsertionPointToStart (iface.getAllocaBlock ());
1009
- } else {
1010
- auto func = mlir::isa<mlir::LLVM::LLVMFuncOp>(op) ?
1011
- mlir::cast<mlir::LLVM::LLVMFuncOp>(op) :
1012
- op->getParentOfType <mlir::LLVM::LLVMFuncOp>();
1013
- rewriter.setInsertionPointToStart (&func.front ());
1014
- }
1005
+ thisBlock->getParent ()
1006
+ ->getParentOfType <mlir::omp::OutlineableOpenMPOpInterface>()) {
1007
+ rewriter.setInsertionPointToStart (iface.getAllocaBlock ());
1008
+ } else {
1009
+ auto func = mlir::isa<mlir::LLVM::LLVMFuncOp>(op)
1010
+ ? mlir::cast<mlir::LLVM::LLVMFuncOp>(op)
1011
+ : op->getParentOfType <mlir::LLVM::LLVMFuncOp>();
1012
+ rewriter.setInsertionPointToStart (&func.front ());
1013
+ }
1015
1014
auto sz = this ->genConstantOffset (loc, rewriter, 1 );
1016
1015
auto al = rewriter.create <mlir::LLVM::AllocaOp>(loc, toTy, sz, alignment);
1017
1016
rewriter.restoreInsertionPoint (thisPt);
@@ -1111,13 +1110,12 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
1111
1110
return doCharacter (charWidth, len);
1112
1111
}
1113
1112
assert (!lenParams.empty ());
1114
- return doCharacter (charWidth, lenParams[ 0 ] );
1113
+ return doCharacter (charWidth, lenParams. back () );
1115
1114
}
1116
1115
if (auto ty = boxEleTy.dyn_cast <fir::LogicalType>())
1117
1116
return doLogical (getKindMap ().getLogicalBitsize (ty.getFKind ()));
1118
- if (auto seqTy = boxEleTy.dyn_cast <fir::SequenceType>()) {
1117
+ if (auto seqTy = boxEleTy.dyn_cast <fir::SequenceType>())
1119
1118
return getSizeAndTypeCode (loc, rewriter, seqTy.getEleTy (), lenParams);
1120
- }
1121
1119
if (boxEleTy.isa <fir::RecordType>()) {
1122
1120
auto ptrTy = mlir::LLVM::LLVMPointerType::get (
1123
1121
this ->lowerTy ().convertType (boxEleTy));
@@ -1228,9 +1226,15 @@ struct EmboxCommonConversion : public FIROpConversion<OP> {
1228
1226
auto llvmBoxTy = llvmBoxPtrTy.getElementType ();
1229
1227
mlir::Value dest = rewriter.create <mlir::LLVM::UndefOp>(loc, llvmBoxTy);
1230
1228
1229
+ llvm::SmallVector<mlir::Value> typeparams = lenParams;
1230
+ if constexpr (!std::is_same_v<BOX, fir::EmboxOp>) {
1231
+ if (!box.substr ().empty () && fir::hasDynamicSize (boxTy.getEleTy ()))
1232
+ typeparams.push_back (box.substr ()[1 ]);
1233
+ }
1234
+
1231
1235
// Write each of the fields with the appropriate values
1232
1236
auto [eleSize, cfiTy] =
1233
- getSizeAndTypeCode (loc, rewriter, boxTy.getEleTy (), lenParams );
1237
+ getSizeAndTypeCode (loc, rewriter, boxTy.getEleTy (), typeparams );
1234
1238
dest = insertField (rewriter, loc, dest, {1 }, eleSize);
1235
1239
dest = insertField (rewriter, loc, dest, {2 },
1236
1240
this ->genConstantOffset (loc, rewriter, CFI_VERSION));
@@ -1447,7 +1451,7 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
1447
1451
if (hasSlice)
1448
1452
sliceOff += 3 ;
1449
1453
}
1450
- if (hasSlice || hasSubcomp) {
1454
+ if (hasSlice || hasSubcomp || !xbox. substr (). empty () ) {
1451
1455
llvm::SmallVector<mlir::Value> args = {base, ptrOffset};
1452
1456
args.append (gepArgs.rbegin (), gepArgs.rend ());
1453
1457
if (hasSubcomp) {
@@ -1461,6 +1465,10 @@ struct XEmboxOpConversion : public EmboxCommonConversion<fir::cg::XEmboxOp> {
1461
1465
const auto *lastOffset = beginOffset + xbox.subcomponent ().size ();
1462
1466
args.append (beginOffset, lastOffset);
1463
1467
}
1468
+ if (!xbox.substr ().empty ()) {
1469
+ // Append the substring starting offset.
1470
+ args.push_back (xbox.substr ()[0 ]);
1471
+ }
1464
1472
base = rewriter.create <mlir::LLVM::GEPOp>(loc, base.getType (), args);
1465
1473
}
1466
1474
dest = insertBaseAddress (rewriter, loc, dest, base);
@@ -2458,7 +2466,7 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
2458
2466
auto &gr = g.getInitializerRegion ();
2459
2467
rewriter.inlineRegionBefore (global.region (), gr, gr.end ());
2460
2468
if (!gr.empty ()) {
2461
- // Replace insert_on_range with a constant dense attribute if the
2469
+ // Replace insert_on_range with a constant dense attribute if the
2462
2470
// initialization is on the full range.
2463
2471
auto insertOnRangeOps = gr.front ().getOps <fir::InsertOnRangeOp>();
2464
2472
for (auto insertOp : insertOnRangeOps) {
@@ -2467,11 +2475,11 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
2467
2475
auto *op = insertOp.val ().getDefiningOp ();
2468
2476
auto constant = mlir::dyn_cast<mlir::arith::ConstantOp>(op);
2469
2477
if (!constant) {
2470
- auto convertOp = mlir::dyn_cast<fir::ConvertOp>(op);
2471
- if (!convertOp)
2472
- continue ;
2473
- constant =
2474
- cast<mlir::arith::ConstantOp>(convertOp.value ().getDefiningOp ());
2478
+ auto convertOp = mlir::dyn_cast<fir::ConvertOp>(op);
2479
+ if (!convertOp)
2480
+ continue ;
2481
+ constant =
2482
+ cast<mlir::arith::ConstantOp>(convertOp.value ().getDefiningOp ());
2475
2483
}
2476
2484
mlir::Type vecType = mlir::VectorType::get (
2477
2485
insertOp.getType ().getShape (), constant.getType ());
@@ -2491,10 +2499,10 @@ struct GlobalOpConversion : public FIROpConversion<fir::GlobalOp> {
2491
2499
auto extents = seqTy.getShape ();
2492
2500
if (indexes.size () / 2 != extents.size ())
2493
2501
return false ;
2494
- for (unsigned i = 0 ; i < indexes.size (); i+= 2 ) {
2502
+ for (unsigned i = 0 ; i < indexes.size (); i += 2 ) {
2495
2503
if (indexes[i].cast <IntegerAttr>().getInt () != 0 )
2496
2504
return false ;
2497
- if (indexes[i+ 1 ].cast <IntegerAttr>().getInt () != extents[i/ 2 ] - 1 )
2505
+ if (indexes[i + 1 ].cast <IntegerAttr>().getInt () != extents[i / 2 ] - 1 )
2498
2506
return false ;
2499
2507
}
2500
2508
return true ;
0 commit comments