Skip to content

Commit eb69458

Browse files
committed
[flang] Add FIR attributes and apply them to dummy arguments
To determine if a function's dummy argument is nocapture, add the asynchronous attribute to the FIR attribute. The volatile attribute will also be used to determine nocapture assignment, but this will remain a TODO until other processing using volatile is implemented.
1 parent 3e30b36 commit eb69458

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

flang/include/flang/Optimizer/Dialect/FIROpsSupport.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ constexpr llvm::StringRef getOptionalAttrName() { return "fir.optional"; }
7575
/// Attribute to mark Fortran entities with the TARGET attribute.
7676
static constexpr llvm::StringRef getTargetAttrName() { return "fir.target"; }
7777

78+
/// Attribute to mark Fortran entities with the ASYNCHRONOUS attribute.
79+
static constexpr llvm::StringRef getAsynchronousAttrName() {
80+
return "fir.asynchronous";
81+
}
82+
83+
/// Attribute to mark Fortran entities with the VOLATILE attribute.
84+
static constexpr llvm::StringRef getVolatileAttrName() {
85+
return "fir.volatile";
86+
}
87+
7888
/// Attribute to mark that a function argument is a character dummy procedure.
7989
/// Character dummy procedure have special ABI constraints.
8090
static constexpr llvm::StringRef getCharacterProcedureDummyAttrName() {

flang/lib/Lower/CallInterface.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,8 +1116,12 @@ class Fortran::lower::CallInterfaceImpl {
11161116
addMLIRAttr(fir::getContiguousAttrName());
11171117
if (obj.attrs.test(Attrs::Value))
11181118
isValueAttr = true; // TODO: do we want an mlir::Attribute as well?
1119-
if (obj.attrs.test(Attrs::Volatile))
1119+
if (obj.attrs.test(Attrs::Volatile)) {
11201120
TODO(loc, "VOLATILE in procedure interface");
1121+
addMLIRAttr(fir::getVolatileAttrName());
1122+
}
1123+
if (obj.attrs.test(Attrs::Asynchronous))
1124+
addMLIRAttr(fir::getAsynchronousAttrName());
11211125
if (obj.attrs.test(Attrs::Target))
11221126
addMLIRAttr(fir::getTargetAttrName());
11231127
if (obj.cudaDataAttr)

flang/test/Lower/HLFIR/select-rank.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ subroutine test_branching(x)
416416
! CHECK: }
417417

418418
! CHECK-LABEL: func.func @_QPtest_rank_star_attributes(
419-
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x", fir.optional, fir.target}) {
419+
! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.asynchronous, fir.bindc_name = "x", fir.optional, fir.target}) {
420420
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope
421421
! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare %[[VAL_0]] dummy_scope %[[VAL_1]] {fortran_attrs = #fir.var_attrs<asynchronous, optional, target>, uniq_name = "_QFtest_rank_star_attributesEx"} : (!fir.box<!fir.array<*:f32>>, !fir.dscope) -> (!fir.box<!fir.array<*:f32>>, !fir.box<!fir.array<*:f32>>)
422422
! CHECK: %[[VAL_3:.*]] = arith.constant 2 : i8

flang/test/Lower/attributes.f90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ subroutine foo2(x, i)
2727
subroutine foo3(x)
2828
real, optional, contiguous :: x(:)
2929
end subroutine
30+
31+
! CHECK-LABEL: func @_QPfoo4
32+
! CHECK-SAME: %arg0: !fir.ref<f32> {fir.bindc_name = "x", fir.target}
33+
! CHECK-SAME: %arg1: !fir.ref<f32> {fir.asynchronous, fir.bindc_name = "y"}
34+
subroutine foo4(x, y)
35+
real, target :: x
36+
real, asynchronous :: y
37+
end subroutine

0 commit comments

Comments
 (0)