This is an archive of the discontinued LLVM Phabricator instance.

[flang][OpenMP] Support lowering of threadprivate directive for non global variables
ClosedPublic

Authored by peixin on Jun 4 2022, 4:48 AM.

Details

Summary

Non-global variable which can be in threadprivate directive must be one
variable in main program, and it has implicit SAVE attribute. Take it as
with SAVE attribute, so to create GlobalOp for it to simplify the
translation to LLVM IR.

Diff Detail

Event Timeline

peixin created this revision.Jun 4 2022, 4:48 AM
peixin requested review of this revision.Jun 4 2022, 4:48 AM

Thanks for the patch. I have a few comments and questions.

flang/lib/Lower/OpenMP.cpp
1681

Won't something like the following work:

mlir::Region &region = global.getRegion();
mlir::Block &block = region.back();
firOpBuilder.setInsertionPointToEnd(&block);
genInit(firOpBuilder);
1681

Maybe std::function<mlir::Value (fir::FirOpBuilder &)> genInit could be considered. Then a return box or a return undef could allow to take b.create<fir::HasValueOp>(currentLocation, ...); outside genInit (since the operation is anyway common).

flang/test/Lower/OpenMP/threadprivate-non-global.f90
28

Is the intent of keeping duplicate instances of w, a, and b to check if multiple instances to same instances is threadprivatized once? If so, do we need to check behaviour of the following:

integer, target :: x
integer, pointer :: a
a => x
30

Have we skipped FIR checks for this call? I don't suppose we need to check for the same, but confirming once anyway.

peixin added inline comments.Aug 22 2022, 4:43 AM
flang/lib/Lower/OpenMP.cpp
1681

I think no. There may be no block when instantiating the variables.

1681

Well, what you are proposing is the code style problem. This is following FIR lowering (flang/lib/Lower/ConvertVariable.cpp). I think it's better to keep the same style as FIR lowering.

flang/test/Lower/OpenMP/threadprivate-non-global.f90
28

Good catch. It's definitely a typo. Will remove it.

30

No. This call is not for FIR checking. Instead, it is for handling unassociated pointer (a) and unallocated allocatable (b). Printing an unassociated pointer or unallocated allocatable may cause one segfault in some cases if someone try to test execution of this test case. So, add one external call to handle it. Anyway, what I would like to do is to keep the test case simple and clean, but still meaningful in fortran.

peixin added inline comments.Aug 22 2022, 4:50 AM
flang/lib/Lower/OpenMP.cpp
1681

Will remove this lambda and reuse the function in ConvertVariable.cpp on next update.

NimishMishra added inline comments.Aug 22 2022, 5:06 AM
flang/test/Lower/OpenMP/threadprivate-non-global.f90
30

This makes sense. Thank you.

peixin updated this revision to Diff 454517.Aug 22 2022, 8:46 AM
peixin edited the summary of this revision. (Show Details)

Fix the typo and reuse the function in ConvertVariable.cpp.

NimishMishra accepted this revision.Aug 25 2022, 2:01 AM

I am OK with reusing createGlobalInitialization from ConvertVariable.cpp

This revision is now accepted and ready to land.Aug 25 2022, 2:01 AM