Skip to content

Commit 356c166

Browse files
committed
Use more convenient function to get OpenMPLoopConstruct. Fix comments.
1 parent 219595f commit 356c166

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
@@ -152,23 +152,19 @@ class CanonicalizationOfOmp {
152152
// Keep track of the loops to handle the end loop directives
153153
llvm::SmallVector<parser::OpenMPLoopConstruct *> loops;
154154
loops.push_back(&x);
155-
if (auto *innerConstruct{
156-
GetConstructIf<parser::OpenMPConstruct>(*nextIt)}) {
157-
if (auto *innerOmpLoop{
158-
std::get_if<parser::OpenMPLoopConstruct>(&innerConstruct->u)}) {
159-
auto &innerBeginDir{
160-
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
161-
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
162-
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
163-
auto &innerLoop = std::get<std::optional<
164-
common::Indirection<parser::OpenMPLoopConstruct>>>(
165-
loops.back()->t);
166-
innerLoop = std::move(*innerOmpLoop);
167-
// Retrieveing the address so that DoConstruct or inner loop can be
168-
// set later.
169-
loops.push_back(&(innerLoop.value().value()));
170-
nextIt = block.erase(nextIt);
171-
}
155+
if (auto *innerOmpLoop{GetOmpIf<parser::OpenMPLoopConstruct>(*nextIt)}) {
156+
auto &innerBeginDir{
157+
std::get<parser::OmpBeginLoopDirective>(innerOmpLoop->t)};
158+
auto &innerDir{std::get<parser::OmpLoopDirective>(innerBeginDir.t)};
159+
if (innerDir.v == llvm::omp::Directive::OMPD_tile) {
160+
auto &innerLoop = std::get<
161+
std::optional<common::Indirection<parser::OpenMPLoopConstruct>>>(
162+
loops.back()->t);
163+
innerLoop = std::move(*innerOmpLoop);
164+
// Retrieveing the address so that DoConstruct or inner loop can be
165+
// set later.
166+
loops.push_back(&(innerLoop.value().value()));
167+
nextIt = block.erase(nextIt);
172168
}
173169
}
174170

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

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

3037-
// llvm::OpenMPIRBuilder::InsertPointTy afterIP = builder.saveIP();
30383037
llvm::OpenMPIRBuilder::InsertPointTy afterIP =
30393038
loopInfos.front()->getAfterIP();
30403039

@@ -3055,10 +3054,10 @@ convertOmpLoopNest(Operation &opInst, llvm::IRBuilderBase &builder,
30553054
std::vector<llvm::CanonicalLoopInfo *> NewLoops =
30563055
ompBuilder->tileLoops(ompLoc.DL, loopInfos, TileSizes);
30573056

3058-
// Collapse loops. Store the insertion point because LoopInfos may get
3059-
// invalidated.
3060-
auto AfterBB = NewLoops.front()->getAfter();
3061-
auto AfterAfterBB = AfterBB->getSingleSuccessor();
3057+
// Update afterIP to get the correct insertion point after
3058+
// tiling.
3059+
llvm::BasicBlock *AfterBB = NewLoops.front()->getAfter();
3060+
llvm::BasicBlock *AfterAfterBB = AfterBB->getSingleSuccessor();
30623061
afterIP = {AfterAfterBB, AfterAfterBB->begin()};
30633062
NewTopLoopInfo = NewLoops[0];
30643063

0 commit comments

Comments
 (0)