15
15
#include " flang/Lower/FIRBuilder.h"
16
16
#include " flang/Lower/PFTBuilder.h"
17
17
#include " flang/Parser/parse-tree.h"
18
+ #include " flang/Semantics/tools.h"
19
+ #include " mlir/Dialect/OpenACC/OpenACC.h"
18
20
#include " llvm/Frontend/OpenACC/ACC.h.inc"
19
21
20
22
#define TODO () llvm_unreachable(" not yet implemented" )
21
23
24
+ static void genACC (Fortran::lower::AbstractConverter &absConv,
25
+ Fortran::lower::pft::Evaluation &eval,
26
+ const Fortran::parser::OpenACCLoopConstruct &loopConstruct) {
27
+
28
+ const auto &beginLoopDirective =
29
+ std::get<Fortran::parser::AccBeginLoopDirective>(loopConstruct.t );
30
+ const auto &loopDirective =
31
+ std::get<Fortran::parser::AccLoopDirective>(beginLoopDirective.t );
32
+
33
+ if (loopDirective.v == llvm::acc::ACCD_loop) {
34
+ auto &firOpBuilder = absConv.getFirOpBuilder ();
35
+ auto currentLocation = absConv.getCurrentLocation ();
36
+ llvm::ArrayRef<mlir::Type> argTy;
37
+ mlir::ValueRange range;
38
+ // Temporarly set to default 0 as operands are not generated yet.
39
+ llvm::SmallVector<int32_t , 2 > operandSegmentSizes (/* Size=*/ 2 ,
40
+ /* Value=*/ 0 );
41
+ auto loopOp =
42
+ firOpBuilder.create <mlir::acc::LoopOp>(currentLocation, argTy, range);
43
+ loopOp.setAttr (mlir::acc::LoopOp::getOperandSegmentSizeAttr (),
44
+ firOpBuilder.getI32VectorAttr (operandSegmentSizes));
45
+ firOpBuilder.createBlock (&loopOp.getRegion ());
46
+ auto &block = loopOp.getRegion ().back ();
47
+ firOpBuilder.setInsertionPointToStart (&block);
48
+ // ensure the block is well-formed.
49
+ firOpBuilder.create <mlir::acc::YieldOp>(currentLocation);
50
+
51
+ // Add attribute extracted from clauses.
52
+ const auto &accClauseList =
53
+ std::get<Fortran::parser::AccClauseList>(beginLoopDirective.t );
54
+
55
+ //
56
+ for (const auto &clause : accClauseList.v ) {
57
+ if (const auto *collapseClause =
58
+ std::get_if<Fortran::parser::AccClause::Collapse>(&clause.u )) {
59
+
60
+ const auto *expr = Fortran::semantics::GetExpr (collapseClause->v );
61
+ const auto collapseValue = Fortran::evaluate::ToInt64 (*expr);
62
+ if (collapseValue.has_value ()) {
63
+ loopOp.setAttr (mlir::acc::LoopOp::getCollapseAttrName (),
64
+ firOpBuilder.getI64IntegerAttr (collapseValue.value ()));
65
+ }
66
+ } else if (const auto *seqClause =
67
+ std::get_if<Fortran::parser::AccClause::Seq>(&clause.u )) {
68
+ } else if (const auto *gangClause =
69
+ std::get_if<Fortran::parser::AccClause::Gang>(&clause.u )) {
70
+ } else if (const auto *vectorClause =
71
+ std::get_if<Fortran::parser::AccClause::Vector>(&clause.u )) {
72
+ } else if (const auto *workerClause =
73
+ std::get_if<Fortran::parser::AccClause::Worker>(&clause.u )) {
74
+ }
75
+
76
+
77
+ }
78
+
79
+ // Place the insertion point to the start of the first block.
80
+ firOpBuilder.setInsertionPointToStart (&block);
81
+ }
82
+ }
83
+
22
84
void Fortran::lower::genOpenACCConstruct (
23
- Fortran::lower::AbstractConverter &absConv ,
85
+ Fortran::lower::AbstractConverter &converter ,
24
86
Fortran::lower::pft::Evaluation &eval,
25
- const Fortran::parser::OpenACCConstruct &accConstruct) {
26
-
87
+ const Fortran::parser::OpenACCConstruct &acc) {
27
88
std::visit (
28
- common::visitors{
89
+ Fortran:: common::visitors{
29
90
[&](const Fortran::parser::OpenACCBlockConstruct &blockConstruct) {
30
91
TODO ();
31
92
},
32
93
[&](const Fortran::parser::OpenACCCombinedConstruct
33
94
&combinedConstruct) { TODO (); },
34
95
[&](const Fortran::parser::OpenACCLoopConstruct &loopConstruct) {
35
- TODO ( );
96
+ genACC (converter, eval, loopConstruct );
36
97
},
37
98
[&](const Fortran::parser::OpenACCStandaloneConstruct
38
99
&standaloneConstruct) { TODO (); },
@@ -44,9 +105,8 @@ void Fortran::lower::genOpenACCConstruct(
44
105
[&](const Fortran::parser::OpenACCWaitConstruct &waitConstruct) {
45
106
TODO ();
46
107
},
47
- [&](const Fortran::parser::OpenACCAtomicConstruct &atomicConstruct) {
48
- TODO ();
49
- },
108
+ [&](const Fortran::parser::OpenACCAtomicConstruct
109
+ &atomicConstruct) { TODO (); },
50
110
},
51
- accConstruct .u );
111
+ acc .u );
52
112
}
0 commit comments