Skip to content

Commit a0501d0

Browse files
committed
Fix merge problems related to the different representations used for nested
loop constructs.
1 parent 955ccf6 commit a0501d0

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
@@ -422,14 +422,19 @@ static void processHostEvalClauses(lower::AbstractConverter &converter,
422422

423423
// FIXME(JAN): For now we check if there is an inner
424424
// OpenMPLoopConstruct, and extract the size clause from there
425-
const auto &innerOptional = std::get<std::optional<
426-
common::Indirection<parser::OpenMPLoopConstruct>>>(
427-
ompConstruct.t);
428-
if (innerOptional.has_value()) {
429-
const auto &innerLoopDirective = innerOptional.value().value();
425+
const auto &nestedOptional =
426+
std::get<std::optional<parser::NestedConstruct>>(
427+
ompConstruct.t);
428+
assert(nestedOptional.has_value() &&
429+
"Expected a DoConstruct or OpenMPLoopConstruct");
430+
const auto *innerConstruct =
431+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
432+
&(nestedOptional.value()));
433+
if (innerConstruct) {
434+
const auto &innerLoopConstruct = innerConstruct->value();
430435
const auto &innerBegin =
431436
std::get<parser::OmpBeginLoopDirective>(
432-
innerLoopDirective.t);
437+
innerLoopConstruct.t);
433438
const auto &innerDirective =
434439
std::get<parser::OmpLoopDirective>(innerBegin.t);
435440
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
@@ -645,11 +645,15 @@ void collectTileSizesFromOpenMPConstruct(
645645
return;
646646

647647
if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u)}) {
648-
const auto &innerOptional = std::get<
649-
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
650-
ompLoop->t);
651-
if (innerOptional.has_value()) {
652-
const auto &innerLoopDirective = innerOptional.value().value();
648+
const auto &nestedOptional =
649+
std::get<std::optional<parser::NestedConstruct>>(ompLoop->t);
650+
assert(nestedOptional.has_value() &&
651+
"Expected a DoConstruct or OpenMPLoopConstruct");
652+
const auto *innerConstruct =
653+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
654+
&(nestedOptional.value()));
655+
if (innerConstruct) {
656+
const auto &innerLoopDirective = innerConstruct->value();
653657
const auto &innerBegin =
654658
std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
655659
const auto &innerDirective =
@@ -698,11 +702,15 @@ bool collectLoopRelatedInfo(
698702
std::int64_t sizesLengthValue = 0l;
699703
if (auto *ompCons{eval.getIf<parser::OpenMPConstruct>()}) {
700704
if (auto *ompLoop{std::get_if<parser::OpenMPLoopConstruct>(&ompCons->u)}) {
701-
const auto &innerOptional = std::get<
702-
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
703-
ompLoop->t);
704-
if (innerOptional.has_value()) {
705-
const auto &innerLoopDirective = innerOptional.value().value();
705+
const auto &nestedOptional =
706+
std::get<std::optional<parser::NestedConstruct>>(ompLoop->t);
707+
assert(nestedOptional.has_value() &&
708+
"Expected a DoConstruct or OpenMPLoopConstruct");
709+
const auto *innerConstruct =
710+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
711+
&(nestedOptional.value()));
712+
if (innerConstruct) {
713+
const auto &innerLoopDirective = innerConstruct->value();
706714
const auto &innerBegin =
707715
std::get<parser::OmpBeginLoopDirective>(innerLoopDirective.t);
708716
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
@@ -2060,12 +2060,18 @@ void OmpAttributeVisitor::CollectAssociatedLoopLevelsFromInnerLoopContruct(
20602060
const parser::OpenMPLoopConstruct &x,
20612061
llvm::SmallVector<std::int64_t> &levels,
20622062
llvm::SmallVector<const parser::OmpClause *> &clauses) {
2063-
const auto &innerOptional =
2064-
std::get<std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
2065-
x.t);
2066-
if (innerOptional.has_value()) {
2063+
2064+
const auto &nestedOptional =
2065+
std::get<std::optional<parser::NestedConstruct>>(x.t);
2066+
assert(nestedOptional.has_value() &&
2067+
"Expected a DoConstruct or OpenMPLoopConstruct");
2068+
const auto *innerConstruct =
2069+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
2070+
&(nestedOptional.value()));
2071+
2072+
if (innerConstruct) {
20672073
CollectAssociatedLoopLevelsFromLoopConstruct(
2068-
innerOptional.value().value(), levels, clauses);
2074+
innerConstruct->value(), levels, clauses);
20692075
}
20702076
}
20712077

@@ -2130,17 +2136,19 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
21302136
bool hasCollapseClause{
21312137
clause ? (clause->Id() == llvm::omp::OMPC_collapse) : false};
21322138
const parser::OpenMPLoopConstruct *innerMostLoop = &x;
2133-
2139+
const parser::NestedConstruct *innerMostNest = nullptr;
21342140
while (auto &optLoopCons{
2135-
std::get<std::optional<parser::NestedConstruct>>(x.t)}) {
2136-
if (const auto &innerLoop{
2137-
std::get_if < parser::OpenMPLoopConstruct >>> (innerMostLoop->t)}) {
2138-
innerMostLoop = &innerLoop.value().value();
2141+
std::get<std::optional<parser::NestedConstruct>>(innerMostLoop->t)}) {
2142+
innerMostNest = &(optLoopCons.value());
2143+
if (const auto *innerLoop{
2144+
std::get_if<common::Indirection<parser::OpenMPLoopConstruct>>(
2145+
innerMostNest)}) {
2146+
innerMostLoop = &(innerLoop->value());
21392147
}
21402148
}
21412149

2142-
if (optLoopCons.has_value()) {
2143-
if (const auto &outer{std::get_if<parser::DoConstruct>(innerMostLoop->t)}) {
2150+
if (innerMostNest) {
2151+
if (const auto &outer{std::get_if<parser::DoConstruct>(innerMostNest)}) {
21442152
for (const parser::DoConstruct *loop{&*outer}; loop && level > 0;
21452153
--level) {
21462154
if (loop->IsDoConcurrent()) {
@@ -2176,7 +2184,7 @@ void OmpAttributeVisitor::PrivatizeAssociatedLoopIndexAndCheckLoopLevel(
21762184
CheckAssocLoopLevel(level, GetAssociatedClause());
21772185
} else if (const auto &loop{std::get_if<
21782186
common::Indirection<parser::OpenMPLoopConstruct>>(
2179-
&*optLoopCons)}) {
2187+
innerMostNest)}) {
21802188
auto &beginDirective =
21812189
std::get<parser::OmpBeginLoopDirective>(loop->value().t);
21822190
auto &beginLoopDirective =

0 commit comments

Comments
 (0)