Skip to content

Commit 5536a2c

Browse files
committed
Fix merge problems related to the different representations used for nested
loop constructs.
1 parent 90e4b8b commit 5536a2c

File tree

4 files changed

+56
-68
lines changed

4 files changed

+56
-68
lines changed

flang/lib/Lower/OpenMP/OpenMP.cpp

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -421,14 +421,19 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
421421

422422
// FIXME(JAN): For now we check if there is an inner
423423
// OpenMPLoopConstruct, and extract the size clause from there
424-
const auto &innerOptional = std::get<std::optional<
425-
common::Indirection<parser::OpenMPLoopConstruct>>>(
426-
ompConstruct.t);
427-
if (innerOptional.has_value()) {
428-
const auto &innerLoopDirective = innerOptional.value().value();
424+
const auto &nestedOptional =
425+
std::get<std::optional<parser::NestedConstruct>>(
426+
ompConstruct.t);
427+
assert(nestedOptional.has_value() &&
428+
"Expected a DoConstruct or OpenMPLoopConstruct");
429+
const auto *innerConstruct =
430+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
431+
&(nestedOptional.value()));
432+
if (innerConstruct) {
433+
const auto &innerLoopConstruct = innerConstruct->value();
429434
const auto &innerBegin =
430435
std::get<parser::OmpBeginLoopDirective>(
431-
innerLoopDirective.t);
436+
innerLoopConstruct.t);
432437
const auto &innerDirective =
433438
std::get<parser::OmpLoopDirective>(innerBegin.t);
434439
if (innerDirective.v == llvm::omp::Directive::OMPD_tile) {
@@ -2276,41 +2281,6 @@ static void genUnrollOp(Fortran::lower::AbstractConverter &converter,
22762281
// Apply unrolling to it
22772282
auto cli = canonLoop.getCli();
22782283
mlir::omp::UnrollHeuristicOp::create(firOpBuilder, loc, cli);
2279-
2280-
static mlir::omp::LoopOp genTiledLoopOp(lower::AbstractConverter &converter,
2281-
lower::SymMap &symTable,
2282-
semantics::SemanticsContext &semaCtx,
2283-
lower::pft::Evaluation &eval,
2284-
mlir::Location loc,
2285-
const ConstructQueue &queue,
2286-
ConstructQueue::const_iterator item) {
2287-
mlir::omp::LoopOperands loopClauseOps;
2288-
llvm::SmallVector<const semantics::Symbol *> loopReductionSyms;
2289-
genLoopClauses(converter, semaCtx, item->clauses, loc, loopClauseOps,
2290-
loopReductionSyms);
2291-
2292-
DataSharingProcessor dsp(converter, semaCtx, item->clauses, eval,
2293-
/*shouldCollectPreDeterminedSymbols=*/true,
2294-
/*useDelayedPrivatization=*/true, symTable);
2295-
dsp.processStep1(&loopClauseOps);
2296-
2297-
mlir::omp::LoopNestOperands loopNestClauseOps;
2298-
llvm::SmallVector<const semantics::Symbol *> iv;
2299-
genLoopNestClauses(converter, semaCtx, eval, item->clauses, loc,
2300-
loopNestClauseOps, iv);
2301-
2302-
EntryBlockArgs loopArgs;
2303-
loopArgs.priv.syms = dsp.getDelayedPrivSymbols();
2304-
loopArgs.priv.vars = loopClauseOps.privateVars;
2305-
loopArgs.reduction.syms = loopReductionSyms;
2306-
loopArgs.reduction.vars = loopClauseOps.reductionVars;
2307-
2308-
auto loopOp =
2309-
genWrapperOp<mlir::omp::LoopOp>(converter, loc, loopClauseOps, loopArgs);
2310-
genLoopNestOp(converter, symTable, semaCtx, eval, loc, queue, item,
2311-
loopNestClauseOps, iv, {{loopOp, loopArgs}},
2312-
llvm::omp::Directive::OMPD_loop, dsp);
2313-
return loopOp;
23142284
}
23152285

23162286
static mlir::omp::MaskedOp

flang/lib/Lower/OpenMP/Utils.cpp

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,15 @@ void collectTileSizesFromOpenMPConstruct(
644644
return;
645645

646646
if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u)}) {
647-
const auto &innerOptional = std::get<
648-
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
649-
ompLoop->t);
650-
if (innerOptional.has_value()) {
651-
const auto &innerLoopDirective = innerOptional.value().value();
647+
const auto &nestedOptional =
648+
std::get<std::optional<parser::NestedConstruct>>(ompLoop->t);
649+
assert(nestedOptional.has_value() &&
650+
"Expected a DoConstruct or OpenMPLoopConstruct");
651+
const auto *innerConstruct =
652+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
653+
&(nestedOptional.value()));
654+
if (innerConstruct) {
655+
const auto &innerLoopDirective = innerConstruct->value();
652656
const auto &innerBegin =
653657
std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
654658
const auto &innerDirective =
@@ -697,11 +701,15 @@ bool collectLoopRelatedInfo(
697701
std::int64_t sizesLengthValue = 0l;
698702
if (auto *ompCons{eval.getIf<parser::OpenMPConstruct>()}) {
699703
if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u)}) {
700-
const auto &innerOptional = std::get<
701-
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
702-
ompLoop->t);
703-
if (innerOptional.has_value()) {
704-
const auto &innerLoopDirective = innerOptional.value().value();
704+
const auto &nestedOptional =
705+
std::get<std::optional<parser::NestedConstruct>>(ompLoop->t);
706+
assert(nestedOptional.has_value() &&
707+
"Expected a DoConstruct or OpenMPLoopConstruct");
708+
const auto *innerConstruct =
709+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
710+
&(nestedOptional.value()));
711+
if (innerConstruct) {
712+
const auto &innerLoopDirective = innerConstruct->value();
705713
const auto &innerBegin =
706714
std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
707715
const auto &innerDirective =

flang/lib/Semantics/canonicalize-omp.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,15 @@ class CanonicalizationOfOmp {
157157
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
158158
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
159159
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
160-
auto &innerLoop = std::get<
161-
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
162-
loops.back()->t);
160+
auto &innerLoopVariant =
161+
std::get<std::optional<parser::NestedConstruct>>(loops.back()->t);
162+
auto &innerLoop =
163+
std::get<common::Indirection<parser::OpenMPLoopConstruct>>(
164+
innerLoopVariant.value());
163165
innerLoop = std::move(*innerOmpLoop);
164166
// Retrieveing the address so that DoConstruct or inner loop can be
165167
// set later.
166-
loops.push_back(&(innerLoop.value().value()));
168+
loops.push_back(&(innerLoop.value()));
167169
nextIt = block.erase(nextIt);
168170
}
169171
}

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,12 +2057,18 @@ void OmpAttributeVisitor::CollectAssociatedLoopLevelsFromInnerLoopContruct(
20572057
const parser::OpenMPLoopConstruct &x,
20582058
llvm::SmallVector<std::int64_t> &levels,
20592059
llvm::SmallVector<const parser::OmpClause *> &clauses) {
2060-
const auto &innerOptional =
2061-
std::get<std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
2062-
x.t);
2063-
if (innerOptional.has_value()) {
2060+
2061+
const auto &nestedOptional =
2062+
std::get<std::optional<parser::NestedConstruct>>(x.t);
2063+
assert(nestedOptional.has_value() &&
2064+
"Expected a DoConstruct or OpenMPLoopConstruct");
2065+
const auto *innerConstruct =
2066+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
2067+
&(nestedOptional.value()));
2068+
2069+
if (innerConstruct) {
20642070
CollectAssociatedLoopLevelsFromLoopConstruct(
2065-
innerOptional.value().value(), levels, clauses);
2071+
innerConstruct->value(), levels, clauses);
20662072
}
20672073
}
20682074

@@ -2127,17 +2133,19 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
21272133
bool hasCollapseClause{
21282134
clause ? (clause->Id() == llvm::omp::OMPC_collapse) : false};
21292135
const parser::OpenMPLoopConstruct *innerMostLoop = &x;
2130-
2136+
const parser::NestedConstruct *innerMostNest = nullptr;
21312137
while (auto &optLoopCons{
2132-
std::get<std::optional<parser::NestedConstruct>>(x.t)}) {
2133-
if (const auto &innerLoop{
2134-
std::get_if < parser::OpenMPLoopConstruct >>> (innerMostLoop->t)}) {
2135-
innerMostLoop = &innerLoop.value().value();
2138+
std::get<std::optional<parser::NestedConstruct>>(innerMostLoop->t)}) {
2139+
innerMostNest = &(optLoopCons.value());
2140+
if (const auto *innerLoop{
2141+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
2142+
innerMostNest)}) {
2143+
innerMostLoop = &(innerLoop->value());
21362144
}
21372145
}
21382146

2139-
if (optLoopCons.has_value()) {
2140-
if (const auto &outer{std::get_if<parser::DoConstruct>(innerMostLoop->t)}) {
2147+
if (innerMostNest) {
2148+
if (const auto &outer{std::get_if<parser::DoConstruct>(innerMostNest)}) {
21412149
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0;
21422150
--level) {
21432151
if (loop->IsDoConcurrent()) {
@@ -2173,7 +2181,7 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
21732181
CheckAssocLoopLevel(level, GetAssociatedClause());
21742182
} else if (const auto &loop{std::get_if<
21752183
common::Indirection<parser::OpenMPLoopConstruct>>(
2176-
&*optLoopCons)}) {
2184+
innerMostNest)}) {
21772185
auto &beginDirective =
21782186
std::get<parser::OmpBeginLoopDirective>(loop->value().t);
21792187
auto &beginLoopDirective =

0 commit comments

Comments
 (0)