@@ -244,17 +244,16 @@ static void createDeclareAllocFuncWithArg(mlir::OpBuilder &modBuilder,
244244 if (unwrapFirBox)
245245 asFortranDesc << accFirDescriptorPostfix.str ();
246246
247- // Updating descriptor must occur before the mapping of the data so that
248- // attached data pointer is not overwritten.
249- mlir::acc::UpdateDeviceOp updateDeviceOp =
250- createDataEntryOp<mlir::acc::UpdateDeviceOp>(
251- builder, loc, registerFuncOp.getArgument (0 ), asFortranDesc, bounds,
252- /* structured=*/ false , /* implicit=*/ true ,
253- mlir::acc::DataClause::acc_update_device, descTy,
254- /* async=*/ {}, /* asyncDeviceTypes=*/ {}, /* asyncOnlyDeviceTypes=*/ {});
255- llvm::SmallVector<int32_t > operandSegments{0 , 0 , 0 , 1 };
256- llvm::SmallVector<mlir::Value> operands{updateDeviceOp.getResult ()};
257- createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments);
247+ // Use declare_enter for the descriptor so the runtime mirrors allocation
248+ // semantics instead of issuing an update. This ensures the descriptor's
249+ // device-side metadata is established via a structured begin.
250+ EntryOp descEntryOp = createDataEntryOp<EntryOp>(
251+ builder, loc, registerFuncOp.getArgument (0 ), asFortranDesc, bounds,
252+ /* structured=*/ false , /* implicit=*/ true , clause, descTy,
253+ /* async=*/ {}, /* asyncDeviceTypes=*/ {}, /* asyncOnlyDeviceTypes=*/ {});
254+ mlir::acc::DeclareEnterOp::create (
255+ builder, loc, mlir::acc::DeclareTokenType::get (descEntryOp.getContext ()),
256+ mlir::ValueRange (descEntryOp.getAccVar ()));
258257
259258 if (unwrapFirBox) {
260259 mlir::Value desc =
@@ -3989,17 +3988,16 @@ static void createDeclareAllocFunc(mlir::OpBuilder &modBuilder,
39893988 asFortranDesc << accFirDescriptorPostfix.str ();
39903989 llvm::SmallVector<mlir::Value> bounds;
39913990
3992- // Updating descriptor must occur before the mapping of the data so that
3993- // attached data pointer is not overwritten.
3994- mlir::acc::UpdateDeviceOp updateDeviceOp =
3995- createDataEntryOp<mlir::acc::UpdateDeviceOp>(
3996- builder, loc, addrOp, asFortranDesc, bounds,
3997- /* structured=*/ false , /* implicit=*/ true ,
3998- mlir::acc::DataClause::acc_update_device, addrOp.getType (),
3999- /* async=*/ {}, /* asyncDeviceTypes=*/ {}, /* asyncOnlyDeviceTypes=*/ {});
4000- llvm::SmallVector<int32_t > operandSegments{0 , 0 , 0 , 1 };
4001- llvm::SmallVector<mlir::Value> operands{updateDeviceOp.getResult ()};
4002- createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments);
3991+ // Use declare_enter for the descriptor so the runtime mirrors allocation
3992+ // semantics instead of issuing an update. This ensures the descriptor's
3993+ // device-side metadata is established via a structured begin.
3994+ EntryOp descEntryOp = createDataEntryOp<EntryOp>(
3995+ builder, loc, addrOp, asFortranDesc, bounds,
3996+ /* structured=*/ false , /* implicit=*/ true , clause, addrOp.getType (),
3997+ /* async=*/ {}, /* asyncDeviceTypes=*/ {}, /* asyncOnlyDeviceTypes=*/ {});
3998+ mlir::acc::DeclareEnterOp::create (
3999+ builder, loc, mlir::acc::DeclareTokenType::get (descEntryOp.getContext ()),
4000+ mlir::ValueRange (descEntryOp.getAccVar ()));
40034001
40044002 if (unwrapFirBox) {
40054003 auto loadOp = fir::LoadOp::create (builder, loc, addrOp.getResult ());
@@ -4092,15 +4090,15 @@ static void createDeclareDeallocFunc(mlir::OpBuilder &modBuilder,
40924090 if (unwrapFirBox)
40934091 asFortran << accFirDescriptorPostfix.str ();
40944092 llvm::SmallVector<mlir::Value> bounds;
4095- mlir::acc::UpdateDeviceOp updateDeviceOp =
4096- createDataEntryOp<mlir::acc::UpdateDeviceOp>(
4093+ // Use declare_exit for the descriptor to end the structured declare region
4094+ // instead of issuing an update.
4095+ mlir::acc::GetDevicePtrOp descEntryOp =
4096+ createDataEntryOp<mlir::acc::GetDevicePtrOp>(
40974097 builder, loc, addrOp, asFortran, bounds,
4098- /* structured=*/ false , /* implicit=*/ true ,
4099- mlir::acc::DataClause::acc_update_device, addrOp.getType (),
4098+ /* structured=*/ false , /* implicit=*/ true , clause, addrOp.getType (),
41004099 /* async=*/ {}, /* asyncDeviceTypes=*/ {}, /* asyncOnlyDeviceTypes=*/ {});
4101- llvm::SmallVector<int32_t > operandSegments{0 , 0 , 0 , 1 };
4102- llvm::SmallVector<mlir::Value> operands{updateDeviceOp.getResult ()};
4103- createSimpleOp<mlir::acc::UpdateOp>(builder, loc, operands, operandSegments);
4100+ mlir::acc::DeclareExitOp::create (builder, loc, mlir::Value{},
4101+ mlir::ValueRange (descEntryOp.getAccVar ()));
41044102 modBuilder.setInsertionPointAfter (postDeallocOp);
41054103}
41064104
0 commit comments