Skip to content

Commit e2141ff

Browse files
committed
refactor code to parse in OpenACC.cpp
1 parent fa52cbb commit e2141ff

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

flang/include/flang/Lower/OpenACC.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ 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 &);
127+
125128
/// Checks whether the current insertion point is inside OpenACC loop.
126129
bool isInOpenACCLoop(fir::FirOpBuilder &);
127130

flang/lib/Lower/Bridge.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3222,15 +3222,17 @@ class FirConverter : public Fortran::lower::AbstractConverter {
32223222
const Fortran::parser::AccClauseList &clauseList =
32233223
std::get<Fortran::parser::AccClauseList>(beginLoopDir.t);
32243224
loopCount = Fortran::lower::getLoopCountForCollapseAndTile(clauseList);
3225-
std::tie(collapseForce, collapseDepth) = parseCollapse(clauseList);
3225+
collapseDepth = Fortran::lower::getLoopCountForCollapse(clauseList);
3226+
std::tie(collapseForce, std::ignore) = parseCollapse(clauseList);
32263227
} else if (accCombined) {
32273228
const Fortran::parser::AccBeginCombinedDirective &beginCombinedDir =
32283229
std::get<Fortran::parser::AccBeginCombinedDirective>(
32293230
accCombined->t);
32303231
const Fortran::parser::AccClauseList &clauseList =
32313232
std::get<Fortran::parser::AccClauseList>(beginCombinedDir.t);
32323233
loopCount = Fortran::lower::getLoopCountForCollapseAndTile(clauseList);
3233-
std::tie(collapseForce, collapseDepth) = parseCollapse(clauseList);
3234+
collapseDepth = Fortran::lower::getLoopCountForCollapse(clauseList);
3235+
std::tie(collapseForce, std::ignore) = parseCollapse(clauseList);
32343236
}
32353237

32363238
if (curEval->lowerAsStructured()) {

flang/lib/Lower/OpenACC.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4889,6 +4889,20 @@ uint64_t Fortran::lower::getLoopCountForCollapseAndTile(
48894889
return collapseLoopCount;
48904890
}
48914891

4892+
uint64_t Fortran::lower::getLoopCountForCollapse(
4893+
const Fortran::parser::AccClauseList &clauseList) {
4894+
for (const Fortran::parser::AccClause &clause : clauseList.v) {
4895+
if (const auto *collapseClause =
4896+
std::get_if<Fortran::parser::AccClause::Collapse>(&clause.u)) {
4897+
const Fortran::parser::AccCollapseArg &arg = collapseClause->v;
4898+
const auto &collapseValue =
4899+
std::get<Fortran::parser::ScalarIntConstantExpr>(arg.t);
4900+
return *Fortran::semantics::GetIntValue(collapseValue);
4901+
}
4902+
}
4903+
return 1;
4904+
}
4905+
48924906
/// Create an ACC loop operation for a DO construct when inside ACC compute
48934907
/// constructs This serves as a bridge between regular DO construct handling and
48944908
/// ACC loop creation

0 commit comments

Comments
 (0)