-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[WIP] Delayed privatization. #79862
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
Closed
Closed
[WIP] Delayed privatization. #79862
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
71 changes: 71 additions & 0 deletions
71
flang/test/Lower/OpenMP/FIR/delayed_privatization_hlfir.f90
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
! TODO Convert this file into a bunch of lit tests for each conversion step. | ||
|
||
! RUN: bbc -fopenmp -emit-hlfir --openmp-enable-delayed-privatization %s -o - | ||
|
||
subroutine delayed_privatization() | ||
implicit none | ||
integer :: var1 | ||
integer :: var2 | ||
|
||
var1 = 111 | ||
var2 = 222 | ||
|
||
!$OMP PARALLEL FIRSTPRIVATE(var1, var2) | ||
var1 = var1 + var2 + 2 | ||
!$OMP END PARALLEL | ||
|
||
end subroutine | ||
|
||
|
||
! ----------------------------------------- | ||
! ## This is what flang emits with the PoC: | ||
! ----------------------------------------- | ||
! | ||
! ---------------------------- | ||
! ### Conversion to HLFIR + OMP: | ||
! ---------------------------- | ||
!module { | ||
! func.func @_QPdelayed_privatization() { | ||
! %0 = fir.alloca i32 {bindc_name = "var1", uniq_name = "_QFdelayed_privatizationEvar1"} | ||
! %1:2 = hlfir.declare %0 {uniq_name = "_QFdelayed_privatizationEvar1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! %2 = fir.alloca i32 {bindc_name = "var2", uniq_name = "_QFdelayed_privatizationEvar2"} | ||
! %3:2 = hlfir.declare %2 {uniq_name = "_QFdelayed_privatizationEvar2"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! %c111_i32 = arith.constant 111 : i32 | ||
! hlfir.assign %c111_i32 to %1#0 : i32, !fir.ref<i32> | ||
! %c222_i32 = arith.constant 222 : i32 | ||
! hlfir.assign %c222_i32 to %3#0 : i32, !fir.ref<i32> | ||
! omp.parallel private(@var1.privatizer_0 %1#0, @var2.privatizer_0 %3#0 : !fir.ref<i32>, !fir.ref<i32>) { | ||
! ^bb0(%arg0: !fir.ref<i32>, %arg1: !fir.ref<i32>): | ||
! %4:2 = hlfir.declare %arg0 {uniq_name = "_QFdelayed_privatizationEvar1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! %5:2 = hlfir.declare %arg1 {uniq_name = "_QFdelayed_privatizationEvar2"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! %6 = fir.load %4#0 : !fir.ref<i32> | ||
! %7 = fir.load %5#0 : !fir.ref<i32> | ||
! %8 = arith.addi %6, %7 : i32 | ||
! %c2_i32 = arith.constant 2 : i32 | ||
! %9 = arith.addi %8, %c2_i32 : i32 | ||
! hlfir.assign %9 to %4#0 : i32, !fir.ref<i32> | ||
! omp.terminator | ||
! } | ||
! return | ||
! } | ||
! "omp.private"() <{function_type = (!fir.ref<i32>) -> !fir.ref<i32>, sym_name = "var1.privatizer_0"}> ({ | ||
! ^bb0(%arg0: !fir.ref<i32>): | ||
! %0 = fir.alloca i32 {bindc_name = "var1", pinned, uniq_name = "_QFdelayed_privatizationEvar1"} | ||
! %1:2 = hlfir.declare %0 {uniq_name = "_QFdelayed_privatizationEvar1"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! %2 = fir.load %arg0 : !fir.ref<i32> | ||
! hlfir.assign %2 to %1#0 temporary_lhs : i32, !fir.ref<i32> | ||
! omp.yield(%1#0 : !fir.ref<i32>) | ||
! }) : () -> () | ||
! "omp.private"() <{function_type = (!fir.ref<i32>) -> !fir.ref<i32>, sym_name = "var2.privatizer_0"}> ({ | ||
! ^bb0(%arg0: !fir.ref<i32>): | ||
! %0 = fir.alloca i32 {bindc_name = "var2", pinned, uniq_name = "_QFdelayed_privatizationEvar2"} | ||
! %1:2 = hlfir.declare %0 {uniq_name = "_QFdelayed_privatizationEvar2"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>) | ||
! %2 = fir.load %arg0 : !fir.ref<i32> | ||
! hlfir.assign %2 to %1#0 temporary_lhs : i32, !fir.ref<i32> | ||
! omp.yield(%1#0 : !fir.ref<i32>) | ||
! }) : () -> () | ||
!} | ||
! | ||
! | ||
! ### After lowring `hlfir` to `fir`, conversion to LLVM + OMP -> LLVM IR produces the exact same result as for | ||
! `delayed_privatization.f90`. |
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.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While experimenting with delayed privation for
hlfir
(so far I have been experimenting withfir
), I came across a small issue which is thatfir.declare
is not support when converting fromfir
tomlir
dialect. That's why I had to copy this conversion pattern fromPreCGRewrite.cpp
. SinceDeclareOpConversion
does not convert to op in thefir::cg
dialect, I think it would be nice to move it here to make conversion fromfir
tollvm
dialect more complete.Do you folks have any input on this?
If you agree to share the pass, I will open a separate PR with proper testing of course.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am surprised by this. In a quick experiment
flang-new -mmlir -mlir-pass-statistics -c [...]
gives me the same output both with and without-fopenmp
. Why isn'tCodeGenRewrite
doing the job for you? This pass should run earlier thanFIRToLLVMLowering
(CodeGen.cpp
).In @jeanPerier's commit adding
fir::DeclareOp
toPreCGRewrite.cpp
, he mentions that it was placed here to avoid adding support forfir.shape
to codegen. See c852174There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is
fir::createOpenMPFIRPassPipeline
, so I expect that I should be seeing some extra passes for OpenMP. It is weird that I didn't.Anyway that runs immediately after lowering so I don't think it should effect codegen for
fir.declare
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tblah for taking a look. I was referring to lowering using
fir-opt --fir-to-llvm-ir
for testing purposes. I expected that thefir-opt --fir-to-llvm-ir
should provide a more-or-less complete conversion pipeline fromfir
tollvm
. This is mostly to make testing and experimenting easier.I am a bit of newbie to the project so I might not be using the different tools and their flags properly yet.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No
fir-oppt --fir-to-llvm-ir
is not sufficient. The FIR pass pipeline is quite long (see https://github.com/llvm/llvm-project/blob/main/flang/test/Driver/mlir-pass-pipeline.f90). A few of these are optimizations (e.g. SimplifyIntrinsics, CSE, AliasTags), but several different passes are needed to convert FIR into LLVM (even more for HLFIR).Roughly, to get from FIR to LLVM you need the passes in
createDefaultFIRCodeGenPassPipeline
:llvm-project/flang/include/flang/Tools/CLOptions.inc
Line 302 in ac3bd2b
From the command line you can pipe FIR into
tco
and it will output LLVM IR.fir-opt
is more for running individual passes. The help text is a bit hard to follow, you can findtco
specific options at the top of this file https://github.com/llvm/llvm-project/blob/main/flang/tools/tco/tco.cpp#L41For example,
bbc -emit-hlfir -o - file.f90 | tco
is a bit like runningflang-new -fc1 -O2 -emit-llvm -o - file.f90