[flang] Add OpenMP flag to bbc
authorValentin Clement <clementval@gmail.com>
Wed, 9 Mar 2022 17:30:46 +0000 (18:30 +0100)
committerValentin Clement <clementval@gmail.com>
Wed, 9 Mar 2022 17:34:04 +0000 (18:34 +0100)
Add `-fopenmp` flag to the `bbc` tool.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: schweitz, awarzynski

Differential Revision: https://reviews.llvm.org/D121118

flang/test/Lower/OpenMP/pre-fir-tree01.f90 [new file with mode: 0644]
flang/tools/bbc/bbc.cpp

diff --git a/flang/test/Lower/OpenMP/pre-fir-tree01.f90 b/flang/test/Lower/OpenMP/pre-fir-tree01.f90
new file mode 100644 (file)
index 0000000..fc81794
--- /dev/null
@@ -0,0 +1,19 @@
+! RUN: bbc -fopenmp -pft-test -o %t %s | FileCheck %s
+! RUN: %flang_fc1 -fopenmp -fdebug-dump-pft -o %t %s | FileCheck %s
+
+! Test structure of the Pre-FIR tree with OpenMP
+
+subroutine sub1(a, b, n)
+  real :: a(:), b(:)
+  integer :: n, i
+  !$omp parallel do
+  do i = 1, n
+    b(i) = exp(a(i))
+  end do
+  !$omp end parallel do
+end subroutine
+
+! CHECK-LABEL: Subroutine sub1
+! CHECK:       <<OpenMPConstruct>>
+! CHECK:       <<DoConstruct>>
+! CHECK:       <<End OpenMPConstruct>>
index 99e67fa..a4a7785 100644 (file)
@@ -80,6 +80,10 @@ static llvm::cl::opt<bool> pftDumpTest(
     llvm::cl::desc("parse the input, create a PFT, dump it, and exit"),
     llvm::cl::init(false));
 
+static llvm::cl::opt<bool> enableOpenMP("fopenmp",
+                                        llvm::cl::desc("enable openmp"),
+                                        llvm::cl::init(false));
+
 #define FLANG_EXCLUDE_CODEGEN
 #include "flang/Tools/CLOptions.inc"
 
@@ -241,6 +245,12 @@ int main(int argc, char **argv) {
   options.predefinitions.emplace_back(
       "__flang_patchlevel__"s, std::string{FLANG_VERSION_PATCHLEVEL_STRING});
 
+  // enable parsing of OpenMP
+  if (enableOpenMP) {
+    options.features.Enable(Fortran::common::LanguageFeature::OpenMP);
+    options.predefinitions.emplace_back("_OPENMP", "201511");
+  }
+
   Fortran::common::IntrinsicTypeDefaultKinds defaultKinds;
   Fortran::parser::AllSources allSources;
   Fortran::parser::AllCookedSources allCookedSources(allSources);