File tree Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 21
21
#include " flang/Lower/FIRBuilder.h"
22
22
#include " flang/Lower/IO.h"
23
23
#include " flang/Lower/Mangler.h"
24
+ #include " flang/Lower/OpenACC.h"
24
25
#include " flang/Lower/OpenMP.h"
25
26
#include " flang/Lower/PFTBuilder.h"
26
27
#include " flang/Lower/Runtime.h"
@@ -1057,7 +1058,13 @@ class FirConverter : public Fortran::lower::AbstractConverter {
1057
1058
mlir::emitWarning (toLocation (), " ignoring all compiler directives" );
1058
1059
}
1059
1060
1060
- void genFIR (const Fortran::parser::OpenACCConstruct &) { TODO (); }
1061
+ void genFIR (const Fortran::parser::OpenACCConstruct &acc) {
1062
+ auto insertPt = builder->saveInsertionPoint ();
1063
+ genOpenACCConstruct (*this , getEval (), acc);
1064
+ for (auto &e : getEval ().getNestedEvaluations ())
1065
+ genFIR (e);
1066
+ builder->restoreInsertionPoint (insertPt);
1067
+ }
1061
1068
1062
1069
void genFIR (const Fortran::parser::OpenMPConstruct &omp) {
1063
1070
genOpenMPConstruct (*this , getEval (), omp);
Original file line number Diff line number Diff line change
1
+ ! This test checks lowering of OpenACC loop directive.
2
+
3
+ ! RUN: bbc -fopenacc -emit-fir %s -o - | FileCheck %s
4
+
5
+ program acc_loop
6
+
7
+ integer :: i, j
8
+ integer , parameter :: n = 10
9
+ real , dimension (n) :: a, b
10
+ real , dimension (n, n) :: c, d
11
+
12
+
13
+ ! $acc loop
14
+ DO i = 1 , n
15
+ a(i) = b(i)
16
+ END DO
17
+
18
+ ! CHECK: acc.loop {
19
+ ! CHECK: fir.do_loop
20
+ ! CHECK: acc.yield
21
+ ! CHECK-NEXT: }
22
+
23
+ ! $acc loop collapse(2)
24
+ DO i = 1 , n
25
+ DO j = 1 , n
26
+ c(i, j) = d(i, j)
27
+ END DO
28
+ END DO
29
+
30
+ ! CHECK: acc.loop {
31
+ ! CHECK: fir.do_loop
32
+ ! CHECK: fir.do_loop
33
+ ! CHECK: acc.yield
34
+ ! CHECK-NEXT: } attributes {collapse = 2 : i64}
35
+
36
+ ! $acc loop
37
+ DO i = 1 , n
38
+ ! $acc loop
39
+ DO j = 1 , n
40
+ c(i, j) = d(i, j)
41
+ END DO
42
+ END DO
43
+
44
+ ! CHECK: acc.loop {
45
+ ! CHECK: fir.do_loop
46
+ ! CHECK: acc.loop {
47
+ ! CHECK: fir.do_loop
48
+ ! CHECK: acc.yield
49
+ ! CHECK-NEXT: }
50
+ ! CHECK: acc.yield
51
+ ! CHECK-NEXT: }
52
+
53
+ end program
54
+
Original file line number Diff line number Diff line change @@ -116,6 +116,10 @@ static llvm::cl::opt<bool> enableOpenMP("fopenmp",
116
116
llvm::cl::desc (" enable openmp" ),
117
117
llvm::cl::init(false ));
118
118
119
+ static llvm::cl::opt<bool > enableOpenACC (" fopenacc" ,
120
+ llvm::cl::desc (" enable openacc" ),
121
+ llvm::cl::init(false ));
122
+
119
123
static llvm::cl::opt<bool > dumpModuleOnFailure (" dump-module-on-failure" ,
120
124
llvm::cl::init (false ));
121
125
@@ -153,6 +157,12 @@ static mlir::LogicalResult convertFortranSourceToMLIR(
153
157
options.predefinitions .emplace_back (" _OPENMP" , " 201511" );
154
158
}
155
159
160
+ // enable parsing of OpenACC
161
+ if (enableOpenACC) {
162
+ options.features .Enable (Fortran::common::LanguageFeature::OpenACC);
163
+ options.predefinitions .emplace_back (" _OPENACC" , " 201911" );
164
+ }
165
+
156
166
// prep for prescan and parse
157
167
options.searchDirectories = includeDirs;
158
168
Fortran::parser::Parsing parsing{semanticsContext.allSources ()};
You can’t perform that action at this time.
0 commit comments