-
Notifications
You must be signed in to change notification settings - Fork 12.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flang][OpenMP] Fix handling of nested loop wrappers in LowerWorkshare #117275
Open
ivanradanov
wants to merge
1
commit into
main
Choose a base branch
from
users/ivanradanov/flang-workshare-nested-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+26
−5
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
flang
Flang issues not falling into any other category
flang:fir-hlfir
flang:openmp
labels
Nov 22, 2024
@llvm/pr-subscribers-flang-openmp Author: Ivan R. Ivanov (ivanradanov) ChangesFull diff: https://github.com/llvm/llvm-project/pull/117275.diff 2 Files Affected:
diff --git a/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp b/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
index 225c585a02d913..6e130a96eb8dd3 100644
--- a/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
+++ b/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
@@ -126,9 +126,9 @@ static bool mustParallelizeOp(Operation *op) {
// omp.workshare.loop_wrapper {}
//
// Therefore, we skip if we encounter a nested omp.workshare.
- if (isa<omp::WorkshareOp>(op))
+ if (isa<omp::WorkshareOp>(nested))
return WalkResult::skip();
- if (isa<omp::WorkshareLoopWrapperOp>(op))
+ if (isa<omp::WorkshareLoopWrapperOp>(nested))
return WalkResult::interrupt();
return WalkResult::advance();
})
@@ -253,8 +253,7 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
// Either we have already remapped it
bool remapped = rootMapping.contains(opr);
// Or it is available because it dominates `sr`
- bool dominates =
- di.properlyDominates(opr.getDefiningOp(), &*sr.begin);
+ bool dominates = di.properlyDominates(opr, &*sr.begin);
return remapped || dominates;
})) {
// Safe to parallelize operations which have all operands available in
@@ -405,7 +404,7 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
if (sourceRegion.hasOneBlock()) {
handleOneBlock(sourceRegion.front());
- } else {
+ } else if (!sourceRegion.empty()) {
auto &domTree = di.getDomTree(&sourceRegion);
for (auto node : llvm::breadth_first(domTree.getRootNode())) {
handleOneBlock(*node->getBlock());
diff --git a/flang/test/Transforms/OpenMP/lower-workshare-nested.mlir b/flang/test/Transforms/OpenMP/lower-workshare-nested.mlir
new file mode 100644
index 00000000000000..bfd65f04d94b12
--- /dev/null
+++ b/flang/test/Transforms/OpenMP/lower-workshare-nested.mlir
@@ -0,0 +1,22 @@
+// RUN: fir-opt --lower-workshare --allow-unregistered-dialect %s | FileCheck %s
+
+// Checks that the nested loop_wrapper gets parallelized
+func.func @wsfunc(%cond : i1) {
+ omp.workshare {
+ %c1 = arith.constant 1 : index
+ %c42 = arith.constant 42 : index
+ fir.if %cond {
+ omp.workshare.loop_wrapper {
+ omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) {
+ "test.test1"() : () -> ()
+ omp.yield
+ }
+ }
+ }
+ omp.terminator
+ }
+ return
+}
+
+// CHECK: fir.if
+// CHECK: omp.wsloop nowait
|
@llvm/pr-subscribers-flang-fir-hlfir Author: Ivan R. Ivanov (ivanradanov) ChangesFull diff: https://github.com/llvm/llvm-project/pull/117275.diff 2 Files Affected:
diff --git a/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp b/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
index 225c585a02d913..6e130a96eb8dd3 100644
--- a/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
+++ b/flang/lib/Optimizer/OpenMP/LowerWorkshare.cpp
@@ -126,9 +126,9 @@ static bool mustParallelizeOp(Operation *op) {
// omp.workshare.loop_wrapper {}
//
// Therefore, we skip if we encounter a nested omp.workshare.
- if (isa<omp::WorkshareOp>(op))
+ if (isa<omp::WorkshareOp>(nested))
return WalkResult::skip();
- if (isa<omp::WorkshareLoopWrapperOp>(op))
+ if (isa<omp::WorkshareLoopWrapperOp>(nested))
return WalkResult::interrupt();
return WalkResult::advance();
})
@@ -253,8 +253,7 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
// Either we have already remapped it
bool remapped = rootMapping.contains(opr);
// Or it is available because it dominates `sr`
- bool dominates =
- di.properlyDominates(opr.getDefiningOp(), &*sr.begin);
+ bool dominates = di.properlyDominates(opr, &*sr.begin);
return remapped || dominates;
})) {
// Safe to parallelize operations which have all operands available in
@@ -405,7 +404,7 @@ static void parallelizeRegion(Region &sourceRegion, Region &targetRegion,
if (sourceRegion.hasOneBlock()) {
handleOneBlock(sourceRegion.front());
- } else {
+ } else if (!sourceRegion.empty()) {
auto &domTree = di.getDomTree(&sourceRegion);
for (auto node : llvm::breadth_first(domTree.getRootNode())) {
handleOneBlock(*node->getBlock());
diff --git a/flang/test/Transforms/OpenMP/lower-workshare-nested.mlir b/flang/test/Transforms/OpenMP/lower-workshare-nested.mlir
new file mode 100644
index 00000000000000..bfd65f04d94b12
--- /dev/null
+++ b/flang/test/Transforms/OpenMP/lower-workshare-nested.mlir
@@ -0,0 +1,22 @@
+// RUN: fir-opt --lower-workshare --allow-unregistered-dialect %s | FileCheck %s
+
+// Checks that the nested loop_wrapper gets parallelized
+func.func @wsfunc(%cond : i1) {
+ omp.workshare {
+ %c1 = arith.constant 1 : index
+ %c42 = arith.constant 42 : index
+ fir.if %cond {
+ omp.workshare.loop_wrapper {
+ omp.loop_nest (%arg1) : index = (%c1) to (%c42) inclusive step (%c1) {
+ "test.test1"() : () -> ()
+ omp.yield
+ }
+ }
+ }
+ omp.terminator
+ }
+ return
+}
+
+// CHECK: fir.if
+// CHECK: omp.wsloop nowait
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.