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

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Mon Oct 23 14:01:56 PDT 2023


https://github.com/clementval created https://github.com/llvm/llvm-project/pull/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]
```

>From 44c8021292e55b99420ebd3d63b3e4480df0df82 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 23 Oct 2023 13:13:49 -0700
Subject: [PATCH] [flang][openacc] Support fixed form sentinal format

---
 flang/lib/Parser/openacc-parsers.cpp      |  3 +-
 flang/test/Lower/OpenACC/acc-fixed-form.f | 36 +++++++++++++++++++++++
 flang/tools/bbc/bbc.cpp                   |  8 +++++
 3 files changed, 46 insertions(+), 1 deletion(-)
 create mode 100644 flang/test/Lower/OpenACC/acc-fixed-form.f

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