[flang-commits] [flang] [flang][openacc] Support fixed form sentinal format (PR #69970)

via flang-commits flang-commits at lists.llvm.org
Mon Oct 23 14:03:07 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-fir-hlfir

Author: Valentin Clement (バレンタイン クレメン) (clementval)

<details>
<summary>Changes</summary>

The OpenACC standard mentions directive format for fixed form source files. The following sentinels are accepted:

```
!$acc directive-name [clause-list]
c$acc directive-name [clause-list]
*$acc directive-name [clause-list]
```

Update the parser to accepts these. A new option is added to `bbc` so the change can be tested.


---
Full diff: https://github.com/llvm/llvm-project/pull/69970.diff


3 Files Affected:

- (modified) flang/lib/Parser/openacc-parsers.cpp (+2-1) 
- (added) flang/test/Lower/OpenACC/acc-fixed-form.f (+36) 
- (modified) flang/tools/bbc/bbc.cpp (+8) 


``````````diff
diff --git a/flang/lib/Parser/openacc-parsers.cpp b/flang/lib/Parser/openacc-parsers.cpp
index bd5dcd8405e8f9f..131f7332a69701a 100644
--- a/flang/lib/Parser/openacc-parsers.cpp
+++ b/flang/lib/Parser/openacc-parsers.cpp
@@ -19,7 +19,8 @@
 // OpenACC Directives and Clauses
 namespace Fortran::parser {
 
-constexpr auto startAccLine = skipStuffBeforeStatement >> "!$ACC "_sptok;
+constexpr auto startAccLine = skipStuffBeforeStatement >>
+    ("!$ACC "_sptok || "C$ACC "_sptok || "*$ACC "_sptok);
 constexpr auto endAccLine = space >> endOfLine;
 
 // Autogenerated clauses parser. Information is taken from ACC.td and the
diff --git a/flang/test/Lower/OpenACC/acc-fixed-form.f b/flang/test/Lower/OpenACC/acc-fixed-form.f
new file mode 100644
index 000000000000000..41c000d108b7134
--- /dev/null
+++ b/flang/test/Lower/OpenACC/acc-fixed-form.f
@@ -0,0 +1,36 @@
+! RUN: bbc -ffixed-form -fopenacc -emit-fir %s -o - | FileCheck %s
+! RUN: bbc -ffixed-form -fopenacc -emit-hlfir %s -o - | FileCheck %s
+
+      subroutine sub1()
+      real :: a(10, 10)
+      integer :: i, j
+
+      a = 0.0
+
+c$acc parallel
+      do j = 1, 10
+        do i = 1, 10
+          a(i,j) = i*j
+        end do
+      end do
+c$acc end parallel
+
+*$acc parallel
+      do j = 1, 10
+        do i = 1, 10
+          a(i,j) = i*j
+        end do
+      end do
+*$acc end parallel
+
+!$acc parallel
+      do j = 1, 10
+        do i = 1, 10
+          a(i,j) = i*j
+        end do
+      end do
+!$acc end parallel
+
+      end subroutine
+
+! CHECK-COUNT-3: acc.parallel
diff --git a/flang/tools/bbc/bbc.cpp b/flang/tools/bbc/bbc.cpp
index 6752d2cf53532c3..378216bd1e51f8f 100644
--- a/flang/tools/bbc/bbc.cpp
+++ b/flang/tools/bbc/bbc.cpp
@@ -199,6 +199,10 @@ static llvm::cl::opt<bool> enableCUDA("fcuda",
                                       llvm::cl::desc("enable CUDA Fortran"),
                                       llvm::cl::init(false));
 
+static llvm::cl::opt<bool> fixedForm("ffixed-form",
+                                     llvm::cl::desc("enable fixed form"),
+                                     llvm::cl::init(false));
+
 #define FLANG_EXCLUDE_CODEGEN
 #include "flang/Tools/CLOptions.inc"
 
@@ -433,6 +437,10 @@ int main(int argc, char **argv) {
     options.features.Enable(Fortran::common::LanguageFeature::CUDA);
   }
 
+  if (fixedForm) {
+    options.isFixedForm = fixedForm;
+  }
+
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
   Fortran::parser::AllSources allSources;
   Fortran::parser::AllCookedSources allCookedSources(allSources);

``````````

</details>


https://github.com/llvm/llvm-project/pull/69970


More information about the flang-commits mailing list