Skip to content

Commit 7cca8e4

Browse files
committed
refactor
1 parent 8c11d6f commit 7cca8e4

File tree

3 files changed

+16
-30
lines changed

3 files changed

+16
-30
lines changed

flang/include/flang/Lower/OpenACC.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ void genOpenACCTerminator(fir::FirOpBuilder &, mlir::Operation *,
122122
/// clause.
123123
uint64_t getLoopCountForCollapseAndTile(const Fortran::parser::AccClauseList &);
124124

125-
/// Returns only the collapse(N) depth (defaults to 1 when absent).
126-
uint64_t getLoopCountForCollapse(const Fortran::parser::AccClauseList &);
125+
/// Parse collapse clause and return {size, force}. If absent, returns
126+
/// {1,false}.
127+
std::pair<uint64_t, bool>
128+
getCollapseSizeAndForce(const Fortran::parser::AccClauseList &);
127129

128130
/// Checks whether the current insertion point is inside OpenACC loop.
129131
bool isInOpenACCLoop(fir::FirOpBuilder &);

flang/lib/Lower/Bridge.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3194,26 +3194,6 @@ class FirConverter : public Fortran::lower::AbstractConverter {
31943194
bool collapseForce = false;
31953195
uint64_t collapseDepth = 1;
31963196
uint64_t loopCount = 1;
3197-
auto parseCollapse = [&](const Fortran::parser::AccClauseList &cl)
3198-
-> std::pair<bool, uint64_t> {
3199-
bool force = false;
3200-
uint64_t depth = 1;
3201-
for (const Fortran::parser::AccClause &clause : cl.v) {
3202-
if (const auto *collapseClause =
3203-
std::get_if<Fortran::parser::AccClause::Collapse>(&clause.u)) {
3204-
const Fortran::parser::AccCollapseArg &arg = collapseClause->v;
3205-
force = std::get<bool>(arg.t);
3206-
const auto &intExpr =
3207-
std::get<Fortran::parser::ScalarIntConstantExpr>(arg.t);
3208-
if (const auto *expr = Fortran::semantics::GetExpr(intExpr)) {
3209-
if (auto v = Fortran::evaluate::ToInt64(*expr))
3210-
depth = *v;
3211-
}
3212-
break;
3213-
}
3214-
}
3215-
return {force, depth};
3216-
};
32173197

32183198
if (accLoop || accCombined) {
32193199
if (accLoop) {
@@ -3222,17 +3202,17 @@ class FirConverter : public Fortran::lower::AbstractConverter {
32223202
const Fortran::parser::AccClauseList &clauseList =
32233203
std::get<Fortran::parser::AccClauseList>(beginLoopDir.t);
32243204
loopCount = Fortran::lower::getLoopCountForCollapseAndTile(clauseList);
3225-
collapseDepth = Fortran::lower::getLoopCountForCollapse(clauseList);
3226-
std::tie(collapseForce, std::ignore) = parseCollapse(clauseList);
3205+
std::tie(collapseDepth, collapseForce) =
3206+
Fortran::lower::getCollapseSizeAndForce(clauseList);
32273207
} else if (accCombined) {
32283208
const Fortran::parser::AccBeginCombinedDirective &beginCombinedDir =
32293209
std::get<Fortran::parser::AccBeginCombinedDirective>(
32303210
accCombined->t);
32313211
const Fortran::parser::AccClauseList &clauseList =
32323212
std::get<Fortran::parser::AccClauseList>(beginCombinedDir.t);
32333213
loopCount = Fortran::lower::getLoopCountForCollapseAndTile(clauseList);
3234-
collapseDepth = Fortran::lower::getLoopCountForCollapse(clauseList);
3235-
std::tie(collapseForce, std::ignore) = parseCollapse(clauseList);
3214+
std::tie(collapseDepth, collapseForce) =
3215+
Fortran::lower::getCollapseSizeAndForce(clauseList);
32363216
}
32373217

32383218
if (curEval->lowerAsStructured()) {

flang/lib/Lower/OpenACC.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,7 +4869,7 @@ void Fortran::lower::genEarlyReturnInOpenACCLoop(fir::FirOpBuilder &builder,
48694869

48704870
uint64_t Fortran::lower::getLoopCountForCollapseAndTile(
48714871
const Fortran::parser::AccClauseList &clauseList) {
4872-
uint64_t collapseLoopCount = getLoopCountForCollapse(clauseList);
4872+
uint64_t collapseLoopCount = getCollapseSizeAndForce(clauseList).first;
48734873
uint64_t tileLoopCount = 1;
48744874
for (const Fortran::parser::AccClause &clause : clauseList.v) {
48754875
if (const auto *tileClause =
@@ -4881,18 +4881,22 @@ uint64_t Fortran::lower::getLoopCountForCollapseAndTile(
48814881
return tileLoopCount > collapseLoopCount ? tileLoopCount : collapseLoopCount;
48824882
}
48834883

4884-
uint64_t Fortran::lower::getLoopCountForCollapse(
4884+
std::pair<uint64_t, bool> Fortran::lower::getCollapseSizeAndForce(
48854885
const Fortran::parser::AccClauseList &clauseList) {
4886+
uint64_t size = 1;
4887+
bool force = false;
48864888
for (const Fortran::parser::AccClause &clause : clauseList.v) {
48874889
if (const auto *collapseClause =
48884890
std::get_if<Fortran::parser::AccClause::Collapse>(&clause.u)) {
48894891
const Fortran::parser::AccCollapseArg &arg = collapseClause->v;
4892+
force = std::get<bool>(arg.t);
48904893
const auto &collapseValue =
48914894
std::get<Fortran::parser::ScalarIntConstantExpr>(arg.t);
4892-
return *Fortran::semantics::GetIntValue(collapseValue);
4895+
size = *Fortran::semantics::GetIntValue(collapseValue);
4896+
break;
48934897
}
48944898
}
4895-
return 1;
4899+
return {size, force};
48964900
}
48974901

48984902
/// Create an ACC loop operation for a DO construct when inside ACC compute

0 commit comments

Comments
 (0)