Skip to content

Commit 7701e07

Browse files
committed
Use more convenient function to get OpenMPLoopConstruct. Fix comments.
1 parent f1c260d commit 7701e07

File tree

2 files changed

+17
-22
lines changed

2 files changed

+17
-22
lines changed

flang/lib/Semantics/canonicalize-omp.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,19 @@ class CanonicalizationOfOmp {
137137
// Keep track of the loops to handle the end loop directives
138138
llvm::SmallVector<parser::OpenMPLoopConstruct *> loops;
139139
loops.push_back(&x);
140-
if (auto *innerConstruct{
141-
GetConstructIf<parser::OpenMPConstruct>(*nextIt)}) {
142-
if (auto *innerOmpLoop{
143-
std::get_if<parser::OpenMPLoopConstruct>(&innerConstruct->u)}) {
144-
auto &innerBeginDir{
145-
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
146-
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
147-
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
148-
auto &innerLoop = std::get<std::optional<
149-
common::Indirection<parser::OpenMPLoopConstruct>>>(
150-
loops.back()->t);
151-
innerLoop = std::move(*innerOmpLoop);
152-
// Retrieveing the address so that DoConstruct or inner loop can be
153-
// set later.
154-
loops.push_back(&(innerLoop.value().value()));
155-
nextIt = block.erase(nextIt);
156-
}
140+
if (auto *innerOmpLoop{GetOmpIf<parser::OpenMPLoopConstruct>(*nextIt)}) {
141+
auto &innerBeginDir{
142+
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
143+
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
144+
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
145+
auto &innerLoop = std::get<
146+
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
147+
loops.back()->t);
148+
innerLoop = std::move(*innerOmpLoop);
149+
// Retrieveing the address so that DoConstruct or inner loop can be
150+
// set later.
151+
loops.push_back(&(innerLoop.value().value()));
152+
nextIt = block.erase(nextIt);
157153
}
158154
}
159155

mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2991,7 +2991,6 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
29912991
loopInfos.push_back(*loopResult);
29922992
}
29932993

2994-
// llvm::OpenMPIRBuilder::InsertPointTy afterIP = builder.saveIP();
29952994
llvm::OpenMPIRBuilder::InsertPointTy afterIP =
29962995
loopInfos.front()->getAfterIP();
29972996

@@ -3012,10 +3011,10 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
30123011
std::vector<llvm::CanonicalLoopInfo *> NewLoops =
30133012
ompBuilder->tileLoops(ompLoc.DL, loopInfos, TileSizes);
30143013

3015-
// Collapse loops. Store the insertion point because LoopInfos may get
3016-
// invalidated.
3017-
auto AfterBB = NewLoops.front()->getAfter();
3018-
auto AfterAfterBB = AfterBB->getSingleSuccessor();
3014+
// Update afterIP to get the correct insertion point after
3015+
// tiling.
3016+
llvm::BasicBlock *AfterBB = NewLoops.front()->getAfter();
3017+
llvm::BasicBlock *AfterAfterBB = AfterBB->getSingleSuccessor();
30193018
afterIP = {AfterAfterBB, AfterAfterBB->begin()};
30203019
NewTopLoopInfo = NewLoops[0];
30213020

0 commit comments

Comments
 (0)