Skip to content

Commit a88ea8f

Browse files
authored
[flang][cuda] Update memory effect on fir.cuda_allocate op (#88930)
Add MemRead effect on the box operand as the descriptor might be read when performing the allocation of the data. Also update the expected type of the box operand to be a reference. Check in the verifier that this is a reference to a box or class type. This addresses the comment made post commit on #88586
1 parent abd5e45 commit a88ea8f

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

flang/include/flang/Optimizer/Dialect/FIROps.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3200,7 +3200,7 @@ def fir_CUDAAllocateOp : fir_Op<"cuda_allocate", [AttrSizedOperandSegments,
32003200
is initialized before with the standard flang runtime calls.
32013201
}];
32023202

3203-
let arguments = (ins Arg<AnyRefOrBoxType, "", [MemWrite]>:$box,
3203+
let arguments = (ins Arg<fir_ReferenceType, "", [MemRead, MemWrite]>:$box,
32043204
Arg<Optional<AnyRefOrBoxType>, "", [MemWrite]>:$errmsg,
32053205
Optional<AnyIntegerType>:$stream,
32063206
Arg<Optional<AnyRefOrBoxType>, "", [MemWrite]>:$pinned,

flang/lib/Optimizer/Dialect/FIROps.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3998,7 +3998,7 @@ mlir::LogicalResult fir::CUDAAllocateOp::verify() {
39983998
return emitOpError("pinned and stream cannot appears at the same time");
39993999
if (!fir::unwrapRefType(getBox().getType()).isa<fir::BaseBoxType>())
40004000
return emitOpError(
4001-
"expect box to be a reference to/or a class or box type value");
4001+
"expect box to be a reference to a class or box type value");
40024002
if (getSource() &&
40034003
!fir::unwrapRefType(getSource().getType()).isa<fir::BaseBoxType>())
40044004
return emitOpError(

flang/test/Fir/cuf-invalid.fir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func.func @_QPsub1() {
1616

1717
func.func @_QPsub1() {
1818
%1 = fir.alloca i32
19-
// expected-error@+1{{'fir.cuda_allocate' op expect box to be a reference to/or a class or box type value}}
19+
// expected-error@+1{{'fir.cuda_allocate' op expect box to be a reference to a class or box type value}}
2020
%2 = fir.cuda_allocate %1 : !fir.ref<i32> {cuda_attr = #fir.cuda<device>} -> i32
2121
return
2222
}

0 commit comments

Comments
 (0)