[flang-commits] [flang] [flang] Add FIR attributes and apply them to dummy arguments (PR #115686)
via flang-commits
flang-commits at lists.llvm.org
Sun Nov 10 20:17:44 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: None (s-watanabe314)
<details>
<summary>Changes</summary>
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.
I will post another patch to apply nocapture. See also the discussion in the following discourse post.
https://discourse.llvm.org/t/applying-the-nocapture-attribute-to-reference-passed-arguments-in-fortran-subroutines/81401
---
Full diff: https://github.com/llvm/llvm-project/pull/115686.diff
4 Files Affected:
- (modified) flang/include/flang/Optimizer/Dialect/FIROpsSupport.h (+10)
- (modified) flang/lib/Lower/CallInterface.cpp (+5-1)
- (modified) flang/test/Lower/HLFIR/select-rank.f90 (+1-1)
- (modified) flang/test/Lower/attributes.f90 (+8)
``````````diff
diff --git a/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h b/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
index fb7b1d16f62f3a..f7f0a3067b318a 100644
--- a/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
+++ b/flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
@@ -75,6 +75,16 @@ constexpr llvm::StringRef getOptionalAttrName() { return "fir.optional"; }
/// Attribute to mark Fortran entities with the TARGET attribute.
static constexpr llvm::StringRef getTargetAttrName() { return "fir.target"; }
+/// Attribute to mark Fortran entities with the ASYNCHRONOUS attribute.
+static constexpr llvm::StringRef getAsynchronousAttrName() {
+ return "fir.asynchronous";
+}
+
+/// Attribute to mark Fortran entities with the VOLATILE attribute.
+static constexpr llvm::StringRef getVolatileAttrName() {
+ return "fir.volatile";
+}
+
/// Attribute to mark that a function argument is a character dummy procedure.
/// Character dummy procedure have special ABI constraints.
static constexpr llvm::StringRef getCharacterProcedureDummyAttrName() {
diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp
index 7fc6b14f9c6606..1f07be4a5d3e34 100644
--- a/flang/lib/Lower/CallInterface.cpp
+++ b/flang/lib/Lower/CallInterface.cpp
@@ -1116,8 +1116,12 @@ class Fortran::lower::CallInterfaceImpl {
addMLIRAttr(fir::getContiguousAttrName());
if (obj.attrs.test(Attrs::Value))
isValueAttr = true; // TODO: do we want an mlir::Attribute as well?
- if (obj.attrs.test(Attrs::Volatile))
+ if (obj.attrs.test(Attrs::Volatile)) {
TODO(loc, "VOLATILE in procedure interface");
+ addMLIRAttr(fir::getVolatileAttrName());
+ }
+ if (obj.attrs.test(Attrs::Asynchronous))
+ addMLIRAttr(fir::getAsynchronousAttrName());
if (obj.attrs.test(Attrs::Target))
addMLIRAttr(fir::getTargetAttrName());
if (obj.cudaDataAttr)
diff --git a/flang/test/Lower/HLFIR/select-rank.f90 b/flang/test/Lower/HLFIR/select-rank.f90
index 7135c248ea44db..175c6688e89f3f 100644
--- a/flang/test/Lower/HLFIR/select-rank.f90
+++ b/flang/test/Lower/HLFIR/select-rank.f90
@@ -416,7 +416,7 @@ subroutine test_branching(x)
! CHECK: }
! CHECK-LABEL: func.func @_QPtest_rank_star_attributes(
-! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.bindc_name = "x", fir.optional, fir.target}) {
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>> {fir.asynchronous, fir.bindc_name = "x", fir.optional, fir.target}) {
! CHECK: %[[VAL_1:.*]] = fir.dummy_scope : !fir.dscope
! 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>>)
! CHECK: %[[VAL_3:.*]] = arith.constant 2 : i8
diff --git a/flang/test/Lower/attributes.f90 b/flang/test/Lower/attributes.f90
index 16e42ab282daeb..413024d0a44993 100644
--- a/flang/test/Lower/attributes.f90
+++ b/flang/test/Lower/attributes.f90
@@ -27,3 +27,11 @@ subroutine foo2(x, i)
subroutine foo3(x)
real, optional, contiguous :: x(:)
end subroutine
+
+! CHECK-LABEL: func @_QPfoo4
+! CHECK-SAME: %arg0: !fir.ref<f32> {fir.bindc_name = "x", fir.target}
+! CHECK-SAME: %arg1: !fir.ref<f32> {fir.asynchronous, fir.bindc_name = "y"}
+subroutine foo4(x, y)
+ real, target :: x
+ real, asynchronous :: y
+end subroutine
``````````
</details>
https://github.com/llvm/llvm-project/pull/115686
More information about the flang-commits
mailing list