@@ -668,6 +668,16 @@ struct CUFDataTransferOpConversion
668668 return mlir::success ();
669669 }
670670
671+ auto materializeBoxIfNeeded = [&](mlir::Value val) -> mlir::Value {
672+ if (mlir::isa<fir::EmboxOp, fir::ReboxOp>(val.getDefiningOp ())) {
673+ // Materialize the box to memory to be able to call the runtime.
674+ mlir::Value box = builder.createTemporary (loc, val.getType ());
675+ builder.create <fir::StoreOp>(loc, val, box);
676+ return box;
677+ }
678+ return val;
679+ };
680+
671681 // Conversion of data transfer involving at least one descriptor.
672682 if (mlir::isa<fir::BaseBoxType>(dstTy)) {
673683 // Transfer to a descriptor.
@@ -685,15 +695,7 @@ struct CUFDataTransferOpConversion
685695 func = fir::runtime::getRuntimeFunc<mkRTKey (CUFDataTransferCstDesc)>(
686696 loc, builder);
687697 }
688- auto materializeBoxIfNeeded = [&](mlir::Value val) -> mlir::Value {
689- if (mlir::isa<fir::EmboxOp, fir::ReboxOp>(val.getDefiningOp ())) {
690- // Materialize the box to memory to be able to call the runtime.
691- mlir::Value box = builder.createTemporary (loc, val.getType ());
692- builder.create <fir::StoreOp>(loc, val, box);
693- return box;
694- }
695- return val;
696- };
698+
697699 src = materializeBoxIfNeeded (src);
698700 dst = materializeBoxIfNeeded (dst);
699701
@@ -708,6 +710,7 @@ struct CUFDataTransferOpConversion
708710 } else {
709711 // Transfer from a descriptor.
710712 mlir::Value dst = emboxDst (rewriter, op, symtab);
713+ mlir::Value src = materializeBoxIfNeeded (op.getSrc ());
711714
712715 mlir::func::FuncOp func = fir::runtime::getRuntimeFunc<mkRTKey (
713716 CUFDataTransferDescDescNoRealloc)>(loc, builder);
@@ -716,9 +719,8 @@ struct CUFDataTransferOpConversion
716719 mlir::Value sourceFile = fir::factory::locationToFilename (builder, loc);
717720 mlir::Value sourceLine =
718721 fir::factory::locationToLineNo (builder, loc, fTy .getInput (4 ));
719- llvm::SmallVector<mlir::Value> args{
720- fir::runtime::createArguments (builder, loc, fTy , dst, op.getSrc (),
721- modeValue, sourceFile, sourceLine)};
722+ llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments (
723+ builder, loc, fTy , dst, src, modeValue, sourceFile, sourceLine)};
722724 builder.create <fir::CallOp>(loc, func, args);
723725 rewriter.eraseOp (op);
724726 }
0 commit comments