Skip to content

[mlir][OpenMP] Translation support for taskloop construct - #174386

Merged
tblah merged 16 commits into
mainfrom
users/tblah/taskloop-no-clauses
Jan 8, 2026
Merged

tblah merged 16 commits into
mainfrom
users/tblah/taskloop-no-clauses

Conversation

@tblah

@tblah tblah commented Jan 5, 2026

Copy link
Copy Markdown
Contributor

This PR replaces #166903

This implements translation for taskloop, along with DSA clauses. Other clauses will follow immediately after this is merged.

This patch was collaborative work by myself, @kaviya2510, and @Stylie777. I’ve left the commits unsquashed to make authorship clear. My only changes to other author’s commits are to rebase and run clang-format.

The taskloop implementation in the runtime works roughly like this: if the number of loop iterations to perform are more than some threshold, the current task is duplicated and both resulting tasks gets half of the loop range. This continues recursively until each task has a small enough loop range to run itself in a single thread.

This leads to two implementation complexities:

  • The runtime needs to be able to update the loop bounds used when executing the loop inside of the task. This has been implemented by forcing them to always have a fixed location inside of the structure produced when outlining the task.
  • When a task is duplicated, all data stored for the task’s (first)private variables needs to also be duplicated and appropriate constructors run. This is handled by a task duplication function invoked by the runtime.

With regards to testing, most existing tests in the gfortran and fujitsu test suites require the reduction clause (not part of OpenMP 4.5). I wrote some tests of my own and was satisfied that it seems to be working.

Co-authored-by: Kaviya Rajendiran [email protected]
Co-authored-by: Jack Styles [email protected]

@tblah

tblah commented Jan 5, 2026 •

Copy link
Copy Markdown
Contributor Author

I'm not sure why the bot didn't post.

@llvm/pr-subscribers-mlir-openmp
@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-flang-openmp

@tblah
tblah requested review from Stylie777 and kaviya2510 January 5, 2026 12:25
@tblah

tblah commented Jan 5, 2026

Copy link
Copy Markdown
Contributor Author

See also #174105, which fixes one of the usual patterns for using taskloop.

@tblah

tblah commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

Follow up PR, kept separate because it effects ordinary tasks too #174588

@tblah

tblah commented Jan 6, 2026

Copy link
Copy Markdown
Contributor Author

Windows CI failure is unrelated:

2026-01-06T13:31:42.3654163Z FAIL: LLVM :: CodeGen/RISCV/riscv-macho.ll (24213 of 62120)

@github-actions

github-actions Bot commented Jan 6, 2026 •

Copy link
Copy Markdown

🪟 Windows x64 Test Results

  • 129196 tests passed
  • 2844 tests skipped

✅ The build succeeded and all tests passed.

@tblah
tblah force-pushed the users/tblah/taskloop-no-clauses branch from 803ade3 to 912d1d2 Compare January 7, 2026 10:58

@NimishMishra NimishMishra left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @kaviya2510, @Stylie777, and @tblah for all the work on this. LGTM

tblah added 6 commits January 8, 2026 10:29
The body of taskloop is outlined and so OutlinableOpenMPOpInterface is
needed to ensure that language frontends know not to hoist allocas
outside of the body of taskloop.

The complication here is that taskloop is also a loop wrapper. Currently
some code assumes that taskloop contains only the wrapped loop, and so
there is no place to put the allocas other than in the loop body. This
is obviously not good. Unfortunately LLVM does not seem to be able to
hoist these allocas back out of the loop. The taskloop loop body will
need to contain stack saves and restores, which unfortunately hinder
some optimizations.

I think it is better to land some taskloop in LLVM 22 than not at all.
It will take more work to find an appropriate MLIR representation for
allocas inside of outlinable loop wrappers.
This was my mistake whilst tidying something up. We can have an empty
context structure at the point when this is run, and the helper is still
required to add enough dummy entries to the geps array so that its
dimensions match the size of the privatization decls. I've added a
regression test.
@tblah
tblah force-pushed the users/tblah/taskloop-no-clauses branch from b5f5567 to a875bb7 Compare January 8, 2026 10:34
@tblah
tblah enabled auto-merge (squash) January 8, 2026 10:35
@tblah
tblah merged commit 1af1cc2 into main Jan 8, 2026
@tblah
tblah deleted the users/tblah/taskloop-no-clauses branch January 8, 2026 11:08
ronlieb added a commit to ROCm/llvm-project that referenced this pull request Jan 8, 2026
tblah added a commit to tblah/llvm-project that referenced this pull request Jan 8, 2026
This is a fix for the asan bot after llvm#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.
tblah added a commit that referenced this pull request Jan 8, 2026
…174983)

This is a fix for the asan bot after
#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.
llvm-sync Bot pushed a commit to arm/arm-toolchain that referenced this pull request Jan 8, 2026
…Callback (#174983)

This is a fix for the asan bot after
llvm/llvm-project#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.
navaneethshan pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Jan 8, 2026
…174983)

This is a fix for the asan bot after
llvm/llvm-project#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.
ergawy pushed a commit to ROCm/llvm-project that referenced this pull request Jan 9, 2026
This PR replaces llvm#166903

This implements translation for taskloop, along with DSA clauses. Other
clauses will follow immediately after this is merged.

This patch was collaborative work by myself, @kaviya2510, and
@Stylie777. I’ve left the commits unsquashed to make authorship clear.
My only changes to other author’s commits are to rebase and run
clang-format.

The taskloop implementation in the runtime works roughly like this: if
the number of loop iterations to perform are more than some threshold,
the current task is duplicated and both resulting tasks gets half of the
loop range. This continues recursively until each task has a small
enough loop range to run itself in a single thread.

This leads to two implementation complexities:
- The runtime needs to be able to update the loop bounds used when
executing the loop inside of the task. This has been implemented by
forcing them to always have a fixed location inside of the structure
produced when outlining the task.
- When a task is duplicated, all data stored for the task’s
(first)private variables needs to also be duplicated and appropriate
constructors run. This is handled by a task duplication function invoked
by the runtime.

With regards to testing, most existing tests in the gfortran and fujitsu
test suites require the reduction clause (not part of OpenMP 4.5). I
wrote some tests of my own and was satisfied that it seems to be
working.

Co-authored-by: Kaviya Rajendiran <[email protected]>
Co-authored-by: Jack Styles <[email protected]>

---------

Co-authored-by: Kaviya Rajendiran <[email protected]>
Co-authored-by: Jack Styles <[email protected]>
ergawy pushed a commit to ROCm/llvm-project that referenced this pull request Jan 9, 2026
…lvm#174983)

This is a fix for the asan bot after
llvm#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.
ronlieb added a commit to ROCm/llvm-project that referenced this pull request Jan 9, 2026
navaneethshan pushed a commit to qualcomm/cpullvm-toolchain that referenced this pull request Jan 9, 2026
…174983)

This is a fix for the asan bot after
llvm/llvm-project#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.

(cherry picked from commit cc1bb84)
Stylie777 added a commit that referenced this pull request Feb 5, 2026
Following work completed in #174386 and #174623, this patch adds support
for collapse to Taskloop. Collapse allows for the user to compress
multiple loop nests into a single loop, and for this to work with
Taskloop, there needs to be some changes to how we process the loops,
and the tasks that run them.

This patch brings Taskloop equivalent to OpenMP 4.5 support for MLIR and
Flang.
rishabhmadan19 pushed a commit to rishabhmadan19/llvm-project that referenced this pull request Feb 9, 2026
Following work completed in llvm#174386 and llvm#174623, this patch adds support
for collapse to Taskloop. Collapse allows for the user to compress
multiple loop nests into a single loop, and for this to work with
Taskloop, there needs to be some changes to how we process the loops,
and the tasks that run them.

This patch brings Taskloop equivalent to OpenMP 4.5 support for MLIR and
Flang.
markrvmurray pushed a commit to markrvmurray/llvm-mc6809 that referenced this pull request Jun 14, 2026
…174983)

This is a fix for the asan bot after
llvm/llvm-project#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.
nekoshirro pushed a commit to nekoshirro/Alchemist-LLVM that referenced this pull request Jul 30, 2026
…174983)

This is a fix for the asan bot after
llvm/llvm-project#174386

Failing bot: https://lab.llvm.org/buildbot/#/builders/24/builds/16371

This commit undoes a simplification I thought reduced copied+pasted
code. I will merge it like this now to unblock the bot, and then work
separately on a different way to share code between both callbacks.
Signed-off-by: Hafidz Muzakky <[email protected]>
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.

4 participants