@@ -668,6 +668,16 @@ struct CUFDataTransferOpConversion
668
668
return mlir::success ();
669
669
}
670
670
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
+
671
681
// Conversion of data transfer involving at least one descriptor.
672
682
if (mlir::isa<fir::BaseBoxType>(dstTy)) {
673
683
// Transfer to a descriptor.
@@ -685,15 +695,7 @@ struct CUFDataTransferOpConversion
685
695
func = fir::runtime::getRuntimeFunc<mkRTKey (CUFDataTransferCstDesc)>(
686
696
loc, builder);
687
697
}
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
+
697
699
src = materializeBoxIfNeeded (src);
698
700
dst = materializeBoxIfNeeded (dst);
699
701
@@ -708,6 +710,7 @@ struct CUFDataTransferOpConversion
708
710
} else {
709
711
// Transfer from a descriptor.
710
712
mlir::Value dst = emboxDst (rewriter, op, symtab);
713
+ mlir::Value src = materializeBoxIfNeeded (op.getSrc ());
711
714
712
715
mlir::func::FuncOp func = fir::runtime::getRuntimeFunc<mkRTKey (
713
716
CUFDataTransferDescDescNoRealloc)>(loc, builder);
@@ -716,9 +719,8 @@ struct CUFDataTransferOpConversion
716
719
mlir::Value sourceFile = fir::factory::locationToFilename (builder, loc);
717
720
mlir::Value sourceLine =
718
721
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)};
722
724
builder.create <fir::CallOp>(loc, func, args);
723
725
rewriter.eraseOp (op);
724
726
}
0 commit comments