Skip to content

Conversation

@tblah
Copy link
Contributor

@tblah tblah commented Jan 5, 2026

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

tblah commented Jan 5, 2026

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

tblah commented Jan 5, 2026

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

@tblah
Copy link
Contributor Author

tblah commented Jan 6, 2026

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

@tblah
Copy link
Contributor Author

tblah commented Jan 6, 2026

Windows CI failure is unrelated:

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

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

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

@NimishMishra NimishMishra left a comment

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 8 commits January 8, 2026 10:29
I decided not to fix the TODO about zero iteration taskloops because
this is part of a larger problem affecting similar constructs e.g.
ordinary tasks with an if clause that evaluates to false.
This is important so that the private var cleanup applies the right
cleanup region to the right variable.
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
9 of 10 checks passed
@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 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.
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.

5 participants