This patch adds an initial support to the lastprivate clause for worksharing loop. The patch creates necessary control flow to guarantee the store of the value from the logical last iteration of the workshare loop.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The test along with this patch is failing. Please have a look.
flang/lib/Lower/OpenMP.cpp | ||
---|---|---|
108–116 | Can we use FIR/SCF/CF operations here instead of llvm dialect operations? Did you face any issue if we put the store in an scf.if/fir.if operation close to the omp.yield? | |
159–190 | Here and else where please use MLIR coding guidelines (camelBack syntax). https://mlir.llvm.org/getting_started/DeveloperGuide/#style-guide |
Patch looks good. The main concern remaining is the resetting and resetting of insertion points and passing state around that. If we can reduce this it will be great.
flang/lib/Lower/Bridge.cpp | ||
---|---|---|
515–530 | Nit: remove auto. | |
516 | ||
547 | ||
flang/lib/Lower/OpenMP.cpp | ||
89 | Can we inline this now, that the code is not big? | |
116 | Can you add a hard TODO for the else case? | |
117–121 | I think the loop is not necessary. Will the following work? firOpBuilder.setInsertionPoint(&op->region().back().back()); Also, I am assuming that you expect this to go before the Yield instruction, if so it would be good to and get the terminator explicitly and assert that it is the Yield terminator. | |
125 | I guess, this will not work with collapse, Can you add a hard TODO for that? | |
457–470 | Not for this patch: I think we need to clean this up a bit. Can you leave a TODO comment to clean up the setting/resetting of the insertion point? | |
flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90 | ||
2 | Can you add a test with | |
4 | Nit: You can use the default CHECK prefix. |
The setting and resetting can be cleaned up in a separate patch. Add a TODO for that.
Can you add a test with
-> a lastprivate and firstprivate?
-> multiple lastprivate clauses?
If these do not work then add appropriate TODOs.
Can you get this ready for submission today?
flang/lib/Lower/Bridge.cpp | ||
---|---|---|
497–498 | Please add a FIXME: Generalize this function.. Ideally, this function should be generic so not to restricted only for OpenMP lastprivate lause. | |
flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90 | ||
2 |
You may use the code from D128595. |
Addressing all reviewers comments and adding TODOs and more test cases as per suggestion.
This looks mostly good. A few more comments to address before submission.
flang/include/flang/Lower/AbstractConverter.h | ||
---|---|---|
64 | Nit: The style in this file seems to be to use the namespace along with the type. Can you use mlir along with Block and remove this using namespace | |
flang/lib/Lower/OpenMP.cpp | ||
149 | Nit: spelling: presence | |
152 | Nit: I missed this before, please use the arithmetic dialect comparison. It is probably very similar to the LLVM one. | |
flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90 | ||
173 | Nit: I meant a test where the list item variable is the same. Also add a check for the barrier between the two. If we finally remove the barrier for firstprivate, the barrier when both are present should exist. If there are issues, please add a TODO. If a list item appears in both firstprivate and lastprivate clauses, the update required for the lastprivate clause occurs after all initializations for the firstprivate clause. A list item may not appear in more than one clause on the same directive, except that it may be specified in both firstprivate and lastprivate clauses. |
flang/test/Lower/OpenMP/omp-parallel-lastprivate-clause-scalar.f90 | ||
---|---|---|
173 | I see, thanks for the suggestion. Currently same var being firstprivate and lastprivate has issues. I will submit a separate patch to fix the issue. Adding a TODO here. |
GCC 9.3.0 is complaining:
flang/lib/Lower/OpenMP.cpp:66:41: error: parameter 'lastPrivBlock' set but not used [-Werror=unused-but-set-parameter] 66 | Block *lastPrivBlock = nullptr) { | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
flang/lib/Lower/OpenMP.cpp | ||
---|---|---|
66 | The complain is from here. The if conditions on line 77 and 79 gets evaluated at compile time and so when T is not Lastprivate, lastPrivBlock isn't used. You can add maybe_unused to handle this, example here |
Nit: The style in this file seems to be to use the namespace along with the type. Can you use mlir along with Block and remove this using namespace