[flang-commits] [flang] b27ab9c - [flang][openacc] Skeleton for OpenACC construct lowering

via flang-commits flang-commits at lists.llvm.org
Wed Jul 22 18:34:30 PDT 2020


Author: Valentin Clement
Date: 2020-07-22T21:34:22-04:00
New Revision: b27ab9ce744fdf99902e3f7b09cf4f9407a340a0

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

LOG: [flang][openacc] Skeleton for OpenACC construct lowering

Summary:
This patch introduce the basic infrastructure to be able to lower
OpenACC constructs to the future OpenACC dialect.

Reviewers: schweitz, kiranchandramohan, DavidTruby, sscalpone, jdoerfert, ichoyjx

Reviewed By: ichoyjx

Subscribers: ichoyjx, SouraVX, mgorny, jfb, sstefan1, llvm-commits

Tags: #llvm, #flang

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

Added: 
    flang/include/flang/Lower/OpenACC.h
    flang/lib/Lower/OpenACC.cpp
    flang/test/Lower/pre-fir-tree05.f90

Modified: 
    flang/include/flang/Lower/PFTBuilder.h
    flang/lib/Lower/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Lower/OpenACC.h b/flang/include/flang/Lower/OpenACC.h
new file mode 100644
index 000000000000..0148e78fed09
--- /dev/null
+++ b/flang/include/flang/Lower/OpenACC.h
@@ -0,0 +1,31 @@
+//===-- Lower/OpenACC.h -- lower OpenACC directives -------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef FORTRAN_LOWER_OPENACC_H
+#define FORTRAN_LOWER_OPENACC_H
+
+namespace Fortran {
+namespace parser {
+struct OpenACCConstruct;
+} // namespace parser
+
+namespace lower {
+
+class AbstractConverter;
+
+namespace pft {
+struct Evaluation;
+} // namespace pft
+
+void genOpenACCConstruct(AbstractConverter &, pft::Evaluation &,
+                         const parser::OpenACCConstruct &);
+
+} // namespace lower
+} // namespace Fortran
+
+#endif // FORTRAN_LOWER_OPENACC_H

diff  --git a/flang/include/flang/Lower/PFTBuilder.h b/flang/include/flang/Lower/PFTBuilder.h
index 1201470de704..3230d36e0e9a 100644
--- a/flang/include/flang/Lower/PFTBuilder.h
+++ b/flang/include/flang/Lower/PFTBuilder.h
@@ -131,8 +131,8 @@ using Constructs =
                parser::ForallConstruct>;
 
 using Directives =
-    std::tuple<parser::CompilerDirective, parser::OpenMPConstruct,
-               parser::OmpEndLoopDirective>;
+    std::tuple<parser::CompilerDirective, parser::OpenACCConstruct,
+               parser::OpenMPConstruct, parser::OmpEndLoopDirective>;
 
 template <typename A>
 static constexpr bool isActionStmt{common::HasMember<A, ActionStmts>};

diff  --git a/flang/lib/Lower/CMakeLists.txt b/flang/lib/Lower/CMakeLists.txt
index 975065c9ed7d..b28e0a299454 100644
--- a/flang/lib/Lower/CMakeLists.txt
+++ b/flang/lib/Lower/CMakeLists.txt
@@ -13,6 +13,7 @@ add_flang_library(FortranLower
   IntrinsicCall.cpp
   IO.cpp
   Mangler.cpp
+  OpenACC.cpp
   OpenMP.cpp
   PFTBuilder.cpp
 

diff  --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp
new file mode 100644
index 000000000000..805062eb297f
--- /dev/null
+++ b/flang/lib/Lower/OpenACC.cpp
@@ -0,0 +1,48 @@
+//===-- OpenMP.cpp -- OpenACC directive lowering --------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "flang/Lower/OpenACC.h"
+#include "flang/Lower/Bridge.h"
+#include "flang/Lower/FIRBuilder.h"
+#include "flang/Lower/PFTBuilder.h"
+#include "flang/Parser/parse-tree.h"
+#include "llvm/Frontend/OpenACC/ACC.h.inc"
+
+#define TODO() llvm_unreachable("not yet implemented")
+
+void Fortran::lower::genOpenACCConstruct(
+    Fortran::lower::AbstractConverter &absConv,
+    Fortran::lower::pft::Evaluation &eval,
+    const Fortran::parser::OpenACCConstruct &accConstruct) {
+
+  std::visit(
+      common::visitors{
+          [&](const Fortran::parser::OpenACCBlockConstruct &blockConstruct) {
+            TODO();
+          },
+          [&](const Fortran::parser::OpenACCCombinedConstruct
+                  &combinedConstruct) { TODO(); },
+          [&](const Fortran::parser::OpenACCLoopConstruct &loopConstruct) {
+            TODO();
+          },
+          [&](const Fortran::parser::OpenACCStandaloneConstruct
+                  &standaloneConstruct) { TODO(); },
+          [&](const Fortran::parser::OpenACCRoutineConstruct
+                  &routineConstruct) { TODO(); },
+          [&](const Fortran::parser::OpenACCCacheConstruct &cacheConstruct) {
+            TODO();
+          },
+          [&](const Fortran::parser::OpenACCWaitConstruct &waitConstruct) {
+            TODO();
+          },
+          [&](const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
+            TODO();
+          },
+      },
+      accConstruct.u);
+}

diff  --git a/flang/test/Lower/pre-fir-tree05.f90 b/flang/test/Lower/pre-fir-tree05.f90
new file mode 100644
index 000000000000..f635785e3274
--- /dev/null
+++ b/flang/test/Lower/pre-fir-tree05.f90
@@ -0,0 +1,33 @@
+! RUN: %f18 -fdebug-pre-fir-tree -fparse-only -fopenacc %s | FileCheck %s
+
+! Test structure of the Pre-FIR tree with OpenACC construct
+
+! CHECK: Subroutine foo
+subroutine foo()
+  ! CHECK-NEXT: <<OpenACCConstruct>>
+  ! CHECK-NEXT: <<OpenACCConstruct>>
+  !$acc parallel
+  !$acc loop
+  ! CHECK-NEXT: <<DoConstruct>>
+  ! CHECK-NEXT: NonLabelDoStmt
+  do i=1,5
+    ! CHECK-NEXT: PrintStmt
+    print *, "hey"
+    ! CHECK-NEXT: <<DoConstruct>>
+    ! CHECK-NEXT: NonLabelDoStmt
+    do j=1,5
+      ! CHECK-NEXT: PrintStmt
+      print *, "hello", i, j
+    ! CHECK-NEXT: EndDoStmt
+    ! CHECK-NEXT: <<End DoConstruct>>
+    end do
+  ! CHECK-NEXT: EndDoStmt
+  ! CHECK-NEXT: <<End DoConstruct>>
+  end do
+  !$acc end parallel
+  ! CHECK-NEXT: <<End OpenACCConstruct>>
+  ! CHECK-NEXT: <<End OpenACCConstruct>>
+  ! CHECK-NEXT: ContinueStmt
+end subroutine
+! CHECK-NEXT: EndSubroutine foo
+


        


More information about the flang-commits mailing list