Skip to content

Commit 1256b09

Browse files
committed
Moving Synchronization gen functions to MultiImageFortran
1 parent 3d18974 commit 1256b09

File tree

3 files changed

+115
-111
lines changed

3 files changed

+115
-111
lines changed

flang/include/flang/Lower/MultiImageFortran.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ struct Evaluation;
3434
} // namespace pft
3535

3636
//===----------------------------------------------------------------------===//
37-
// Synchronization
37+
// Synchronization statements
3838
//===----------------------------------------------------------------------===//
3939

4040
void genSyncAllStatement(AbstractConverter &, const parser::SyncAllStmt &);

flang/lib/Lower/MultiImageFortran.cpp

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,120 @@
2020
#include "flang/Parser/parse-tree.h"
2121
#include "flang/Semantics/expression.h"
2222

23+
/// Initializes values for STAT and ERRMSG
24+
static std::pair<mlir::Value, mlir::Value> getStatAndErrmsg(
25+
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
26+
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList) {
27+
Fortran::lower::StatementContext stmtCtx;
28+
29+
mlir::Value errMsgExpr, statExpr;
30+
for (const Fortran::parser::StatOrErrmsg &statOrErr : statOrErrList) {
31+
std::visit(Fortran::common::visitors{
32+
[&](const Fortran::parser::StatVariable &statVar) {
33+
statExpr = fir::getBase(converter.genExprAddr(
34+
loc, Fortran::semantics::GetExpr(statVar), stmtCtx));
35+
},
36+
[&](const Fortran::parser::MsgVariable &errMsgVar) {
37+
const Fortran::semantics::SomeExpr *expr =
38+
Fortran::semantics::GetExpr(errMsgVar);
39+
errMsgExpr = fir::getBase(
40+
converter.genExprBox(loc, *expr, stmtCtx));
41+
}},
42+
statOrErr.u);
43+
}
44+
45+
return {statExpr, errMsgExpr};
46+
}
47+
48+
//===----------------------------------------------------------------------===//
49+
// Synchronization statements
50+
//===----------------------------------------------------------------------===//
51+
52+
void Fortran::lower::genSyncAllStatement(
53+
Fortran::lower::AbstractConverter &converter,
54+
const Fortran::parser::SyncAllStmt &stmt) {
55+
mlir::Location loc = converter.getCurrentLocation();
56+
converter.checkCoarrayEnabled();
57+
58+
// Handle STAT and ERRMSG values
59+
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList = stmt.v;
60+
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
61+
62+
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
63+
mif::SyncAllOp::create(builder, loc, statAddr, errMsgAddr);
64+
}
65+
66+
void Fortran::lower::genSyncImagesStatement(
67+
Fortran::lower::AbstractConverter &converter,
68+
const Fortran::parser::SyncImagesStmt &stmt) {
69+
mlir::Location loc = converter.getCurrentLocation();
70+
converter.checkCoarrayEnabled();
71+
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
72+
73+
// Handle STAT and ERRMSG values
74+
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList =
75+
std::get<std::list<Fortran::parser::StatOrErrmsg>>(stmt.t);
76+
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
77+
78+
// SYNC_IMAGES(*) is passed as count == -1 while SYNC IMAGES([]) has count
79+
// == 0. Note further that SYNC IMAGES(*) is not semantically equivalent to
80+
// SYNC ALL.
81+
Fortran::lower::StatementContext stmtCtx;
82+
mlir::Value imageSet;
83+
const Fortran::parser::SyncImagesStmt::ImageSet &imgSet =
84+
std::get<Fortran::parser::SyncImagesStmt::ImageSet>(stmt.t);
85+
std::visit(Fortran::common::visitors{
86+
[&](const Fortran::parser::IntExpr &intExpr) {
87+
const SomeExpr *expr = Fortran::semantics::GetExpr(intExpr);
88+
imageSet =
89+
fir::getBase(converter.genExprBox(loc, *expr, stmtCtx));
90+
},
91+
[&](const Fortran::parser::Star &) {
92+
// Image set is not set.
93+
imageSet = mlir::Value{};
94+
}},
95+
imgSet.u);
96+
97+
mif::SyncImagesOp::create(builder, loc, imageSet, statAddr, errMsgAddr);
98+
}
99+
100+
void Fortran::lower::genSyncMemoryStatement(
101+
Fortran::lower::AbstractConverter &converter,
102+
const Fortran::parser::SyncMemoryStmt &stmt) {
103+
mlir::Location loc = converter.getCurrentLocation();
104+
converter.checkCoarrayEnabled();
105+
106+
// Handle STAT and ERRMSG values
107+
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList = stmt.v;
108+
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
109+
110+
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
111+
mif::SyncMemoryOp::create(builder, loc, statAddr, errMsgAddr);
112+
}
113+
114+
void Fortran::lower::genSyncTeamStatement(
115+
Fortran::lower::AbstractConverter &converter,
116+
const Fortran::parser::SyncTeamStmt &stmt) {
117+
mlir::Location loc = converter.getCurrentLocation();
118+
converter.checkCoarrayEnabled();
119+
120+
// Handle TEAM
121+
Fortran::lower::StatementContext stmtCtx;
122+
const Fortran::parser::TeamValue &teamValue =
123+
std::get<Fortran::parser::TeamValue>(stmt.t);
124+
const SomeExpr *teamExpr = Fortran::semantics::GetExpr(teamValue);
125+
mlir::Value team =
126+
fir::getBase(converter.genExprBox(loc, *teamExpr, stmtCtx));
127+
128+
// Handle STAT and ERRMSG values
129+
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList =
130+
std::get<std::list<Fortran::parser::StatOrErrmsg>>(stmt.t);
131+
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
132+
133+
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
134+
mif::SyncTeamOp::create(builder, loc, team, statAddr, errMsgAddr);
135+
}
136+
23137
//===----------------------------------------------------------------------===//
24138
// TEAM statements and constructs
25139
//===----------------------------------------------------------------------===//

flang/lib/Lower/Runtime.cpp

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,6 @@ static void genUnreachable(fir::FirOpBuilder &builder, mlir::Location loc) {
4848
builder.setInsertionPointToStart(newBlock);
4949
}
5050

51-
/// Initializes values for STAT and ERRMSG
52-
static std::pair<mlir::Value, mlir::Value> getStatAndErrmsg(
53-
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
54-
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList) {
55-
Fortran::lower::StatementContext stmtCtx;
56-
57-
mlir::Value errMsgExpr, statExpr;
58-
for (const Fortran::parser::StatOrErrmsg &statOrErr : statOrErrList) {
59-
std::visit(Fortran::common::visitors{
60-
[&](const Fortran::parser::StatVariable &statVar) {
61-
statExpr = fir::getBase(converter.genExprAddr(
62-
loc, Fortran::semantics::GetExpr(statVar), stmtCtx));
63-
},
64-
[&](const Fortran::parser::MsgVariable &errMsgVar) {
65-
const Fortran::semantics::SomeExpr *expr =
66-
Fortran::semantics::GetExpr(errMsgVar);
67-
errMsgExpr = fir::getBase(
68-
converter.genExprBox(loc, *expr, stmtCtx));
69-
}},
70-
statOrErr.u);
71-
}
72-
73-
return {statExpr, errMsgExpr};
74-
}
75-
7651
//===----------------------------------------------------------------------===//
7752
// Misc. Fortran statements that lower to runtime calls
7853
//===----------------------------------------------------------------------===//
@@ -193,91 +168,6 @@ void Fortran::lower::genUnlockStatement(
193168
TODO(converter.getCurrentLocation(), "coarray: UNLOCK runtime");
194169
}
195170

196-
void Fortran::lower::genSyncAllStatement(
197-
Fortran::lower::AbstractConverter &converter,
198-
const Fortran::parser::SyncAllStmt &stmt) {
199-
mlir::Location loc = converter.getCurrentLocation();
200-
converter.checkCoarrayEnabled();
201-
202-
// Handle STAT and ERRMSG values
203-
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList = stmt.v;
204-
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
205-
206-
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
207-
mif::SyncAllOp::create(builder, loc, statAddr, errMsgAddr);
208-
}
209-
210-
void Fortran::lower::genSyncImagesStatement(
211-
Fortran::lower::AbstractConverter &converter,
212-
const Fortran::parser::SyncImagesStmt &stmt) {
213-
mlir::Location loc = converter.getCurrentLocation();
214-
converter.checkCoarrayEnabled();
215-
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
216-
217-
// Handle STAT and ERRMSG values
218-
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList =
219-
std::get<std::list<Fortran::parser::StatOrErrmsg>>(stmt.t);
220-
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
221-
222-
// SYNC_IMAGES(*) is passed as count == -1 while SYNC IMAGES([]) has count
223-
// == 0. Note further that SYNC IMAGES(*) is not semantically equivalent to
224-
// SYNC ALL.
225-
Fortran::lower::StatementContext stmtCtx;
226-
mlir::Value imageSet;
227-
const Fortran::parser::SyncImagesStmt::ImageSet &imgSet =
228-
std::get<Fortran::parser::SyncImagesStmt::ImageSet>(stmt.t);
229-
std::visit(Fortran::common::visitors{
230-
[&](const Fortran::parser::IntExpr &intExpr) {
231-
const SomeExpr *expr = Fortran::semantics::GetExpr(intExpr);
232-
imageSet =
233-
fir::getBase(converter.genExprBox(loc, *expr, stmtCtx));
234-
},
235-
[&](const Fortran::parser::Star &) {
236-
// Image set is not set.
237-
imageSet = mlir::Value{};
238-
}},
239-
imgSet.u);
240-
241-
mif::SyncImagesOp::create(builder, loc, imageSet, statAddr, errMsgAddr);
242-
}
243-
244-
void Fortran::lower::genSyncMemoryStatement(
245-
Fortran::lower::AbstractConverter &converter,
246-
const Fortran::parser::SyncMemoryStmt &stmt) {
247-
mlir::Location loc = converter.getCurrentLocation();
248-
converter.checkCoarrayEnabled();
249-
250-
// Handle STAT and ERRMSG values
251-
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList = stmt.v;
252-
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
253-
254-
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
255-
mif::SyncMemoryOp::create(builder, loc, statAddr, errMsgAddr);
256-
}
257-
258-
void Fortran::lower::genSyncTeamStatement(
259-
Fortran::lower::AbstractConverter &converter,
260-
const Fortran::parser::SyncTeamStmt &stmt) {
261-
mlir::Location loc = converter.getCurrentLocation();
262-
converter.checkCoarrayEnabled();
263-
264-
// Handle TEAM
265-
Fortran::lower::StatementContext stmtCtx;
266-
const Fortran::parser::TeamValue &teamValue =
267-
std::get<Fortran::parser::TeamValue>(stmt.t);
268-
const SomeExpr *teamExpr = Fortran::semantics::GetExpr(teamValue);
269-
mlir::Value team =
270-
fir::getBase(converter.genExprBox(loc, *teamExpr, stmtCtx));
271-
272-
// Handle STAT and ERRMSG values
273-
const std::list<Fortran::parser::StatOrErrmsg> &statOrErrList =
274-
std::get<std::list<Fortran::parser::StatOrErrmsg>>(stmt.t);
275-
auto [statAddr, errMsgAddr] = getStatAndErrmsg(converter, loc, statOrErrList);
276-
277-
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
278-
mif::SyncTeamOp::create(builder, loc, team, statAddr, errMsgAddr);
279-
}
280-
281171
void Fortran::lower::genPauseStatement(
282172
Fortran::lower::AbstractConverter &converter,
283173
const Fortran::parser::PauseStmt &) {

0 commit comments

Comments
 (0)