Skip to content

Commit 9e13ed3

Browse files
committed
[MLIR][OpenMP] Refactor translation of omp.loop_nest
The `omp.loop_nest` operation is always wrapped by a set of one or more OpenMP loop wrapper operations (i.e. implementing the `omp::LoopWrapperInterface`), which impact how it must be lowered. However, the creation of the list of canonical loop objects and processing of the `collapse` information (plus potentially other loop transformations when supported in the future) have to be performed in the same way regardless of the loop wrappers applied. This patch extracts this common handling out of the translation functions for `omp.wsloop` and `omp.simd` and makes some infrastructure changes in preparation for handling multiple wrappers (i.e. composite constructs). This work uncovered a couple bugs that are also addressed: - `LoopNestOp::gatherWrappers()` would include `omp.parallel` when not taking a loop wrapper role. - Translation to LLVM IR of `omp.loop_nest` inside of `omp.simd` always assumed the stop value was included, which wasn't caught due to a broken unit test. This patch is implemented assuming `omp.parallel` remains a loop wrapper operation, which is currently under discussion in this [RFC](https://discourse.llvm.org/t/rfc-disambiguation-between-loop-and-block-associated-omp-parallelop/79972). Until consensus is reached there, this will remain as a draft PR.
1 parent 82ee7ae commit 9e13ed3

File tree

3 files changed

+184
-143
lines changed

3 files changed

+184
-143
lines changed

mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2144,6 +2144,12 @@ void LoopNestOp::gatherWrappers(
21442144
wrappers.push_back(wrapper);
21452145
parent = parent->getParentOp();
21462146
}
2147+
2148+
// omp.parallel can be misidentified as a loop wrapper when it's not taking
2149+
// that role but it contains no other operations in its region (e.g. parallel
2150+
// do/for).
2151+
if (llvm::isa<omp::ParallelOp>(wrappers.back()))
2152+
wrappers.pop_back();
21472153
}
21482154

21492155
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)