This is an archive of the discontinued LLVM Phabricator instance.

[Clang][OpenMP] Allow loop iteration var with threadprivate directive
AcceptedPublic

Authored by jyu2 on Oct 21 2021, 8:12 PM.

Details

Summary

Loop iteration var with threadprivate is predetermined as threadprivate.

Current clang emit error when loop var that appear in threadprivate
directives.

According to OpenMP 5.1 [2.21.1.1]

For first predetermined rule is:
Variables that appear in threadprivate directives or variables with the
_Thread_local (in C) or thread_local (in C++) storage-class specifier
are threadprivate

The error should not be emitted.

To fix this, add two line condition to check OMPC_threadprivate for the loops.

Diff Detail

Event Timeline

jyu2 created this revision.Oct 21 2021, 8:12 PM
jyu2 requested review of this revision.Oct 21 2021, 8:12 PM
ABataev added inline comments.Oct 22 2021, 6:15 AM
clang/lib/Sema/SemaOpenMP.cpp
8660

Why need this change?

8669–8674

Again, why do we need this?

jyu2 added a comment.Oct 22 2021, 7:56 AM

Hi Alexey, Thanks for review.

clang/lib/Sema/SemaOpenMP.cpp
8660

The rule:
The loop iteration variable in any associated loop of a loop construct is lastprivate.

So if there is lastprivate clause, should be predetermined as lastprivate.

8669–8674

In the comment: for OpenMP 5.0 and up:

If a simd construct has just one associated loop, the variable may be listed in a private, lastprivate or linear.

The linear part is set on line 8652, there just need to set private and lastprivate.

ABataev added inline comments.Oct 22 2021, 7:58 AM
clang/lib/Sema/SemaOpenMP.cpp
8660

The patch is for threadprivates, better to do it in a separate patch(or patches).

8669–8674

Same here, better to split this change

jyu2 added inline comments.Oct 22 2021, 8:05 AM
clang/lib/Sema/SemaOpenMP.cpp
8660

That is already there but in different in the if statement on line 8657 in old code:

DVar.CKind != OMPC_lastprivate)) &

I just want to merge that into PredetermindCKind.

8669–8674

It is also in old code on line 8650: I just want to merge them into PredetermindCKind.

(LangOpts.OpenMP <= 45 || (DVar.CKind != OMPC_lastprivate &&

DVar.CKind != OMPC_private)))
ABataev added inline comments.Oct 22 2021, 8:08 AM
clang/lib/Sema/SemaOpenMP.cpp
8660

Can you do it in a separate NFC patch (if this is actually NFC)?

jyu2 updated this revision to Diff 381564.Oct 22 2021, 8:39 AM
jyu2 edited the summary of this revision. (Show Details)
jyu2 added inline comments.
clang/lib/Sema/SemaOpenMP.cpp
8660

Okay, will do in sperate change.

ABataev accepted this revision.Oct 22 2021, 9:13 AM

LG with a nit.

clang/lib/Sema/SemaOpenMP.cpp
8658

Need to fix the formatting.

This revision is now accepted and ready to land.Oct 22 2021, 9:13 AM

In which standard version was that rule introduced, is this missing some checks for the OpenMP version?

jyu2 added a comment.Oct 22 2021, 9:26 AM

In which standard version was that rule introduced, is this missing some checks for the OpenMP version?

I check back to omp 45, the rule was there.

jyu2 updated this revision to Diff 381604.Oct 22 2021, 11:05 AM

fix format problem.

There still exists a restriction that the loop variable must not be threadprivate in OpenMP 5.1. See Canonical Loop Nest restrictions, p125, line 7:

The loop iteration variable may not appear in a threadprivate directive.

jyu2 added a comment.Oct 22 2021, 1:26 PM

Good point. I did not find that. At this point, I don't know if we need this change. I checked gnu, gnu allow this.... :-(