@@ -665,6 +665,16 @@ struct CUFDataTransferOpConversion
665665 return mlir::success ();
666666 }
667667
668+ auto materializeBoxIfNeeded = [&](mlir::Value val) -> mlir::Value {
669+ if (mlir::isa<fir::EmboxOp, fir::ReboxOp>(val.getDefiningOp ())) {
670+ // Materialize the box to memory to be able to call the runtime.
671+ mlir::Value box = builder.createTemporary (loc, val.getType ());
672+ builder.create <fir::StoreOp>(loc, val, box);
673+ return box;
674+ }
675+ return val;
676+ };
677+
668678 // Conversion of data transfer involving at least one descriptor.
669679 if (mlir::isa<fir::BaseBoxType>(dstTy)) {
670680 // Transfer to a descriptor.
@@ -682,15 +692,7 @@ struct CUFDataTransferOpConversion
682692 func = fir::runtime::getRuntimeFunc<mkRTKey (CUFDataTransferCstDesc)>(
683693 loc, builder);
684694 }
685- auto materializeBoxIfNeeded = [&](mlir::Value val) -> mlir::Value {
686- if (mlir::isa<fir::EmboxOp, fir::ReboxOp>(val.getDefiningOp ())) {
687- // Materialize the box to memory to be able to call the runtime.
688- mlir::Value box = builder.createTemporary (loc, val.getType ());
689- builder.create <fir::StoreOp>(loc, val, box);
690- return box;
691- }
692- return val;
693- };
695+
694696 src = materializeBoxIfNeeded (src);
695697 dst = materializeBoxIfNeeded (dst);
696698
@@ -705,6 +707,7 @@ struct CUFDataTransferOpConversion
705707 } else {
706708 // Transfer from a descriptor.
707709 mlir::Value dst = emboxDst (rewriter, op, symtab);
710+ mlir::Value src = materializeBoxIfNeeded (op.getSrc ());
708711
709712 mlir::func::FuncOp func = fir::runtime::getRuntimeFunc<mkRTKey (
710713 CUFDataTransferDescDescNoRealloc)>(loc, builder);
@@ -713,9 +716,8 @@ struct CUFDataTransferOpConversion
713716 mlir::Value sourceFile = fir::factory::locationToFilename (builder, loc);
714717 mlir::Value sourceLine =
715718 fir::factory::locationToLineNo (builder, loc, fTy .getInput (4 ));
716- llvm::SmallVector<mlir::Value> args{
717- fir::runtime::createArguments (builder, loc, fTy , dst, op.getSrc (),
718- modeValue, sourceFile, sourceLine)};
719+ llvm::SmallVector<mlir::Value> args{fir::runtime::createArguments (
720+ builder, loc, fTy , dst, src, modeValue, sourceFile, sourceLine)};
719721 builder.create <fir::CallOp>(loc, func, args);
720722 rewriter.eraseOp (op);
721723 }
0 commit comments