[flang-commits] [flang] f081248 - [flang][openacc] Support fixed form sentinel format (#69970)

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


Author: Valentin Clement (バレンタイン クレメン)
Date: 2023-10-23T14:27:39-07:00
New Revision: f0812480d2ae1c66dcc6879dba64bab7117f4f5a

URL: https://github.com/llvm/llvm-project/commit/f0812480d2ae1c66dcc6879dba64bab7117f4f5a
DIFF: https://github.com/llvm/llvm-project/commit/f0812480d2ae1c66dcc6879dba64bab7117f4f5a.diff

LOG: [flang][openacc] Support fixed form sentinel format (#69970)

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.

Added: 
    flang/test/Lower/OpenACC/acc-fixed-form.f

Modified: 
    flang/lib/Parser/openacc-parsers.cpp
    flang/tools/bbc/bbc.cpp

Removed: 
    


################################################################################
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);


        


More information about the flang-commits mailing list