Skip to content
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

[mlir][LLVM] erase call mappings in forgetMapping() #84955

Merged
merged 3 commits into from
Mar 20, 2024

Conversation

tblah
Copy link
Contributor

@tblah tblah commented Mar 12, 2024

It looks like the mappings for call instructions were forgotten here. This fixes a bug in OpenMP when in-lining a region containing call operations multiple times.

OpenMP array reductions 4/6
Previous PR: #84954
Next PR: #84957

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 12, 2024

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-mlir

Author: Tom Eccles (tblah)

Changes

It looks like the mappings for call instructions were forgotten here. This fixes a bug in OpenMP when in-lining a region containing call operations multiple times.

OpenMP array reductions 4/6


Full diff: https://github.com/llvm/llvm-project/pull/84955.diff

1 Files Affected:

  • (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+2)
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index c00628a420a000..995544238e4a3c 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -716,6 +716,8 @@ void ModuleTranslation::forgetMapping(Region &region) {
           branchMapping.erase(&op);
         if (isa<LLVM::GlobalOp>(op))
           globalsMapping.erase(&op);
+        if (isa<LLVM::CallOp>(op))
+          callMapping.erase(&op);
         llvm::append_range(
             toProcess,
             llvm::map_range(op.getRegions(), [](Region &r) { return &r; }));

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 12, 2024

@llvm/pr-subscribers-mlir-llvm

Author: Tom Eccles (tblah)

Changes

It looks like the mappings for call instructions were forgotten here. This fixes a bug in OpenMP when in-lining a region containing call operations multiple times.

OpenMP array reductions 4/6


Full diff: https://github.com/llvm/llvm-project/pull/84955.diff

1 Files Affected:

  • (modified) mlir/lib/Target/LLVMIR/ModuleTranslation.cpp (+2)
diff --git a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
index c00628a420a000..995544238e4a3c 100644
--- a/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/ModuleTranslation.cpp
@@ -716,6 +716,8 @@ void ModuleTranslation::forgetMapping(Region &region) {
           branchMapping.erase(&op);
         if (isa<LLVM::GlobalOp>(op))
           globalsMapping.erase(&op);
+        if (isa<LLVM::CallOp>(op))
+          callMapping.erase(&op);
         llvm::append_range(
             toProcess,
             llvm::map_range(op.getRegions(), [](Region &r) { return &r; }));

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

LGTM. Please wait a day incase others have comments.

@joker-eph
Copy link
Collaborator

We need a test here

Copy link
Contributor

@kiranchandramohan kiranchandramohan left a comment

Choose a reason for hiding this comment

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

Some minor comments about the test.

Comment on lines 18 to 23
atomic {
^bb2(%arg2: !llvm.ptr, %arg3: !llvm.ptr):
%2 = llvm.load %arg3 : !llvm.ptr -> f32
llvm.atomicrmw fadd %arg2, %2 monotonic : !llvm.ptr, f32
omp.yield
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the atomic region be removed?

%c1 = llvm.mlir.constant(1 : i32) : i32
%0 = llvm.alloca %c1 x i32 : (i32) -> !llvm.ptr
omp.parallel {
omp.wsloop reduction(@add_f32 %0 -> %prv : !llvm.ptr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the reduction be moved to omp.parallel? And the omp.wsloop removed?

@tblah tblah force-pushed the users/tblah/omp_array_reduction_4 branch from f2a649a to 02550e1 Compare March 18, 2024 17:34
@tblah
Copy link
Contributor Author

tblah commented Mar 18, 2024

Sorry about the force push. Github wasn't showing the new commit (02550e1). It is just a rebase onto the target branch.

@tblah tblah force-pushed the users/tblah/omp_array_reduction_3 branch 2 times, most recently from 83ad738 to 4eef5d2 Compare March 20, 2024 09:51
Base automatically changed from users/tblah/omp_array_reduction_3 to main March 20, 2024 09:52
tblah added a commit that referenced this pull request Mar 20, 2024
OpenMP reduction declare operations can contain FIR code which needs to
be lowered to LLVM. With array reductions, these regions can contain
more complicated operations which need PreCGRewriting. A similar extra
case was already needed for fir::GlobalOp.

OpenMP array reductions 3/6
Previous PR: #84953
Next PR: #84955
It looks like the mappings for call instructions were forgotten here.
This fixes a bug in OpenMP when inlining a region containing call
operations multiple times.
@tblah tblah force-pushed the users/tblah/omp_array_reduction_4 branch from 02550e1 to a726997 Compare March 20, 2024 10:02
@tblah tblah merged commit 27534d6 into main Mar 20, 2024
3 of 4 checks passed
@tblah tblah deleted the users/tblah/omp_array_reduction_4 branch March 20, 2024 10:03
tblah added a commit that referenced this pull request Mar 20, 2024
…code (#84957)

Moving extractSequenceType to FIRType.h so that this can also be used
from OpenMP.

OpenMP array reductions 5/6
Previous PR: #84955
Next PR: #84958
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
…84954)

OpenMP reduction declare operations can contain FIR code which needs to
be lowered to LLVM. With array reductions, these regions can contain
more complicated operations which need PreCGRewriting. A similar extra
case was already needed for fir::GlobalOp.

OpenMP array reductions 3/6
Previous PR: llvm#84953
Next PR: llvm#84955
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
It looks like the mappings for call instructions were forgotten here.
This fixes a bug in OpenMP when in-lining a region containing call
operations multiple times.

OpenMP array reductions 4/6
Previous PR: llvm#84954
Next PR: llvm#84957
chencha3 pushed a commit to chencha3/llvm-project that referenced this pull request Mar 23, 2024
…code (llvm#84957)

Moving extractSequenceType to FIRType.h so that this can also be used
from OpenMP.

OpenMP array reductions 5/6
Previous PR: llvm#84955
Next PR: llvm#84958
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants