Skip to content

Conversation

@skatrak
Copy link
Member

@skatrak skatrak commented Jul 10, 2024

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. Until consensus is reached there, this will remain as a draft PR.

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.
Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look good

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the result of the RFC, is this PR still relevant?

// omp.parallel can be misidentified as a loop wrapper when it's not taking
// that role but it contains no other operations in its region (e.g. parallel
// do/for).
if (llvm::isa<omp::ParallelOp>(wrappers.back()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isa is one of the definitions that is also imported into the mlir namespace

Suggested change
if (llvm::isa<omp::ParallelOp>(wrappers.back()))
if (isa<omp::ParallelOp>(wrappers.back()))

@skatrak
Copy link
Member Author

skatrak commented Jul 25, 2024

With the result of the RFC, is this PR still relevant?

It will have to be updated, which is why I've kept it as a draft but the general idea of translating the loop on its own rather than as part of every loop wrapper should probably be still good.

@skatrak
Copy link
Member Author

skatrak commented Feb 19, 2025

Closing this PR, as it has been replaced by: #127217.

@skatrak skatrak closed this Feb 19, 2025
@skatrak skatrak deleted the loop-nest-llvmir branch February 19, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants