@@ -3356,7 +3356,7 @@ class ArrayExprLowering {
3356
3356
auto loc = getLoc ();
3357
3357
// Once the loop extents have been computed, which may require being inside
3358
3358
// some explicit loops, lazily allocate the expression on the heap.
3359
- ccPrelude = [=](llvm::ArrayRef<mlir::Value> shape) -> mlir::Value {
3359
+ ccPrelude = [=](llvm::ArrayRef<mlir::Value> shape) {
3360
3360
auto load = builder.create <fir::LoadOp>(loc, var);
3361
3361
auto eleTy = fir::unwrapRefType (load.getType ());
3362
3362
auto unknown = fir::SequenceType::getUnknownExtent ();
@@ -3365,15 +3365,14 @@ class ArrayExprLowering {
3365
3365
auto toTy = fir::HeapType::get (seqTy);
3366
3366
auto castTo = builder.createConvert (loc, toTy, load);
3367
3367
auto cmp = builder.genIsNull (loc, castTo);
3368
- auto ifOp = builder.create <fir::IfOp>(loc, cmp, /* withElseRegion=*/ false );
3369
- auto insPt = builder.saveInsertionPoint ();
3370
- builder.setInsertionPointToStart (&ifOp.thenRegion ().front ());
3371
- auto mem = builder.create <fir::AllocMemOp>(loc, seqTy, " .lazy.mask" ,
3372
- llvm::None, shape);
3373
- auto uncast = builder.createConvert (loc, load.getType (), mem);
3374
- builder.create <fir::StoreOp>(loc, uncast, var);
3375
- builder.restoreInsertionPoint (insPt);
3376
- return mem;
3368
+ builder.genIfThen (loc, cmp)
3369
+ .genThen ([&]() {
3370
+ auto mem = builder.create <fir::AllocMemOp>(loc, seqTy, " .lazy.mask" ,
3371
+ llvm::None, shape);
3372
+ auto uncast = builder.createConvert (loc, load.getType (), mem);
3373
+ builder.create <fir::StoreOp>(loc, uncast, var);
3374
+ })
3375
+ .end ();
3377
3376
};
3378
3377
// Create a dummy array_load before the loop. We're storing to a lazy
3379
3378
// temporary, so there will be no conflict and no copy-in.
@@ -3603,7 +3602,7 @@ class ArrayExprLowering {
3603
3602
// Mask expressions are array expressions too.
3604
3603
for (const auto *e : implicitSpace->getExprs ())
3605
3604
if (e && !implicitSpace->isLowered (e)) {
3606
- if (auto var = implicitSpace->lookupVariable (e)) {
3605
+ if (auto var = implicitSpace->lookupMaskVariable (e)) {
3607
3606
// Allocate the mask buffer lazily.
3608
3607
auto tmp = Fortran::lower::createLazyArrayTempValue (
3609
3608
converter, *e, var, symMap, stmtCtx);
@@ -3660,10 +3659,8 @@ class ArrayExprLowering {
3660
3659
llvm::SmallVector<mlir::Value> ivars;
3661
3660
if (loopDepth > 0 ) {
3662
3661
// Generate the lazy mask allocation, if one was given.
3663
- if (ccPrelude.hasValue ()) {
3664
- [[maybe_unused]] auto allocMem = ccPrelude.getValue ()(shape);
3665
- assert (allocMem && " mask buffer allocation failure" );
3666
- }
3662
+ if (ccPrelude.hasValue ())
3663
+ ccPrelude.getValue ()(shape);
3667
3664
3668
3665
auto *startBlock = builder.getBlock ();
3669
3666
for (auto i : llvm::enumerate (llvm::reverse (loopUppers))) {
@@ -5540,8 +5537,7 @@ class ArrayExprLowering {
5540
5537
Fortran::lower::SymMap &symMap;
5541
5538
// / The continuation to generate code to update the destination.
5542
5539
llvm::Optional<CC> ccStoreToDest;
5543
- llvm::Optional<std::function<mlir::Value(llvm::ArrayRef<mlir::Value>)>>
5544
- ccPrelude;
5540
+ llvm::Optional<std::function<void (llvm::ArrayRef<mlir::Value>)>> ccPrelude;
5545
5541
llvm::Optional<std::function<fir::ArrayLoadOp(llvm::ArrayRef<mlir::Value>)>>
5546
5542
ccLoadDest;
5547
5543
// / The destination is the loaded array into which the results will be
0 commit comments