Skip to content

Commit 3911810

Browse files
committed
Revert "[OpenMP] Patch for Support to loop bind clause : Checking Parent Region"
This reverts commit 85f6b2f.
1 parent a1e9777 commit 3911810

File tree

4 files changed

+33
-227
lines changed

4 files changed

+33
-227
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11307,7 +11307,6 @@ class Sema final {
1130711307
/// on the parameter of the bind clause. In the methods for the
1130811308
/// mapped directives, check the parameters of the lastprivate clause.
1130911309
bool checkLastPrivateForMappedDirectives(ArrayRef<OMPClause *> Clauses);
11310-
1131111310
/// Depending on the bind clause of OMPD_loop map the directive to new
1131211311
/// directives.
1131311312
/// 1) loop bind(parallel) --> OMPD_for
@@ -11317,12 +11316,9 @@ class Sema final {
1131711316
/// rigorous semantic checking in the new mapped directives.
1131811317
bool mapLoopConstruct(llvm::SmallVector<OMPClause *> &ClausesWithoutBind,
1131911318
ArrayRef<OMPClause *> Clauses,
11320-
OpenMPBindClauseKind &BindKind,
11319+
OpenMPBindClauseKind BindKind,
1132111320
OpenMPDirectiveKind &Kind,
11322-
OpenMPDirectiveKind &PrevMappedDirective,
11323-
SourceLocation StartLoc, SourceLocation EndLoc,
11324-
const DeclarationNameInfo &DirName,
11325-
OpenMPDirectiveKind CancelRegion);
11321+
OpenMPDirectiveKind &PrevMappedDirective);
1132611322

1132711323
public:
1132811324
/// The declarator \p D defines a function in the scope \p S which is nested

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5062,18 +5062,6 @@ static bool checkNestingOfRegions(Sema &SemaRef, const DSAStackTy *Stack,
50625062
CurrentRegion != OMPD_cancellation_point &&
50635063
CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_scan)
50645064
return false;
5065-
// Checks needed for mapping "loop" construct. Please check mapLoopConstruct
5066-
// for a detailed explanation
5067-
if (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion == OMPD_loop &&
5068-
((BindKind == OMPC_BIND_parallel) || (BindKind == OMPC_BIND_teams)) &&
5069-
(isOpenMPWorksharingDirective(ParentRegion) ||
5070-
ParentRegion == OMPD_loop)) {
5071-
int ErrorMsgNumber = (BindKind == OMPC_BIND_parallel) ? 1 : 4;
5072-
SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
5073-
<< true << getOpenMPDirectiveName(ParentRegion) << ErrorMsgNumber
5074-
<< getOpenMPDirectiveName(CurrentRegion);
5075-
return true;
5076-
}
50775065
if (CurrentRegion == OMPD_cancellation_point ||
50785066
CurrentRegion == OMPD_cancel) {
50795067
// OpenMP [2.16, Nesting of Regions]
@@ -6126,40 +6114,35 @@ processImplicitMapsWithDefaultMappers(Sema &S, DSAStackTy *Stack,
61266114

61276115
bool Sema::mapLoopConstruct(llvm::SmallVector<OMPClause *> &ClausesWithoutBind,
61286116
ArrayRef<OMPClause *> Clauses,
6129-
OpenMPBindClauseKind &BindKind,
6117+
OpenMPBindClauseKind BindKind,
61306118
OpenMPDirectiveKind &Kind,
6131-
OpenMPDirectiveKind &PrevMappedDirective,
6132-
SourceLocation StartLoc, SourceLocation EndLoc,
6133-
const DeclarationNameInfo &DirName,
6134-
OpenMPDirectiveKind CancelRegion) {
6119+
OpenMPDirectiveKind &PrevMappedDirective) {
61356120

61366121
bool UseClausesWithoutBind = false;
61376122

61386123
// Restricting to "#pragma omp loop bind"
61396124
if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) {
6140-
6141-
const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
6142-
61436125
if (BindKind == OMPC_BIND_unknown) {
61446126
// Setting the enclosing teams or parallel construct for the loop
61456127
// directive without bind clause.
61466128
BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is unknown
61476129

6130+
const OpenMPDirectiveKind ParentDirective =
6131+
DSAStack->getParentDirective();
61486132
if (ParentDirective == OMPD_unknown) {
61496133
Diag(DSAStack->getDefaultDSALocation(),
61506134
diag::err_omp_bind_required_on_loop);
6151-
} else if (isOpenMPParallelDirective(ParentDirective) &&
6152-
!isOpenMPTeamsDirective(ParentDirective)) {
6135+
} else if (ParentDirective == OMPD_parallel ||
6136+
ParentDirective == OMPD_target_parallel) {
61536137
BindKind = OMPC_BIND_parallel;
6154-
} else if (isOpenMPNestingTeamsDirective(ParentDirective) ||
6155-
(ParentDirective == OMPD_target_teams)) {
6138+
} else if (ParentDirective == OMPD_teams ||
6139+
ParentDirective == OMPD_target_teams) {
61566140
BindKind = OMPC_BIND_teams;
61576141
}
61586142
} else {
6159-
// bind clause is present in loop directive. When the loop directive is
6160-
// changed to a new directive the bind clause is not used. So, we should
6161-
// set flag indicating to only use the clauses that aren't the
6162-
// bind clause.
6143+
// bind clause is present, so we should set flag indicating to only
6144+
// use the clauses that aren't the bind clause for the new directive that
6145+
// loop is lowered to.
61636146
UseClausesWithoutBind = true;
61646147
}
61656148

@@ -6220,35 +6203,26 @@ StmtResult Sema::ActOnOpenMPExecutableDirective(
62206203
OpenMPDirectiveKind PrevMappedDirective) {
62216204
StmtResult Res = StmtError();
62226205
OpenMPBindClauseKind BindKind = OMPC_BIND_unknown;
6223-
llvm::SmallVector<OMPClause *> ClausesWithoutBind;
6224-
bool UseClausesWithoutBind = false;
6225-
62266206
if (const OMPBindClause *BC =
62276207
OMPExecutableDirective::getSingleClause<OMPBindClause>(Clauses))
62286208
BindKind = BC->getBindKind();
6229-
6230-
// Variable used to note down the DirectiveKind because mapLoopConstruct may
6231-
// change "Kind" variable, due to mapping of "omp loop" to other directives.
6232-
OpenMPDirectiveKind DK = Kind;
6233-
if ((Kind == OMPD_loop) || (PrevMappedDirective == OMPD_loop)) {
6234-
UseClausesWithoutBind = mapLoopConstruct(
6235-
ClausesWithoutBind, Clauses, BindKind, Kind, PrevMappedDirective,
6236-
StartLoc, EndLoc, DirName, CancelRegion);
6237-
DK = OMPD_loop;
6238-
}
6239-
62406209
// First check CancelRegion which is then used in checkNestingOfRegions.
62416210
if (checkCancelRegion(*this, Kind, CancelRegion, StartLoc) ||
6242-
checkNestingOfRegions(*this, DSAStack, DK, DirName, CancelRegion,
6243-
BindKind, StartLoc)) {
6211+
checkNestingOfRegions(*this, DSAStack, Kind, DirName, CancelRegion,
6212+
BindKind, StartLoc))
62446213
return StmtError();
6245-
}
62466214

62476215
// Report affected OpenMP target offloading behavior when in HIP lang-mode.
62486216
if (getLangOpts().HIP && (isOpenMPTargetExecutionDirective(Kind) ||
62496217
isOpenMPTargetDataManagementDirective(Kind)))
62506218
Diag(StartLoc, diag::warn_hip_omp_target_directives);
62516219

6220+
llvm::SmallVector<OMPClause *> ClausesWithoutBind;
6221+
bool UseClausesWithoutBind = false;
6222+
6223+
UseClausesWithoutBind = mapLoopConstruct(ClausesWithoutBind, Clauses,
6224+
BindKind, Kind, PrevMappedDirective);
6225+
62526226
llvm::SmallVector<OMPClause *, 8> ClausesWithImplicit;
62536227
VarsWithInheritedDSAType VarsWithInheritedDSA;
62546228
bool ErrorFound = false;

clang/test/OpenMP/loop_bind_messages.cpp

Lines changed: 10 additions & 170 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#define NNN 50
66
int aaa[NNN];
7-
int aaa2[NNN][NNN];
87

98
void parallel_loop() {
109
#pragma omp parallel
@@ -16,91 +15,6 @@ void parallel_loop() {
1615
}
1716
}
1817

19-
void parallel_for_AND_loop_bind() {
20-
#pragma omp parallel for
21-
for (int i = 0 ; i < NNN ; i++) {
22-
#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
23-
for (int j = 0 ; j < NNN ; j++) {
24-
aaa2[i][j] = i+j;
25-
}
26-
}
27-
}
28-
29-
void parallel_nowait() {
30-
#pragma omp parallel
31-
#pragma omp for nowait
32-
for (int i = 0 ; i < NNN ; i++) {
33-
#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
34-
for (int j = 0 ; j < NNN ; j++) {
35-
aaa2[i][j] = i+j;
36-
}
37-
}
38-
}
39-
40-
void parallel_for_with_nothing() {
41-
#pragma omp parallel for
42-
for (int i = 0 ; i < NNN ; i++) {
43-
#pragma omp nothing
44-
#pragma omp loop // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
45-
for (int j = 0 ; j < NNN ; j++) {
46-
aaa2[i][j] = i+j;
47-
}
48-
}
49-
}
50-
51-
void parallel_targetfor_with_loop_bind() {
52-
#pragma omp target teams distribute parallel for
53-
for (int i = 0 ; i < NNN ; i++) {
54-
#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'target teams distribute parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
55-
for (int j = 0 ; j < NNN ; j++) {
56-
aaa2[i][j] = i+j;
57-
}
58-
}
59-
}
60-
61-
void parallel_targetparallel_with_loop() {
62-
#pragma omp target parallel
63-
for (int i = 0 ; i < NNN ; i++) {
64-
#pragma omp loop bind(parallel)
65-
for (int j = 0 ; j < NNN ; j++) {
66-
aaa2[i][j] = i+j;
67-
}
68-
}
69-
}
70-
71-
void loop_bind_AND_loop_bind() {
72-
#pragma omp parallel for
73-
for (int i = 0; i < 100; ++i) {
74-
#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
75-
for (int i = 0 ; i < NNN ; i++) {
76-
#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'loop' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
77-
for (int j = 0 ; j < NNN ; j++) {
78-
aaa[j] = j*NNN;
79-
}
80-
}
81-
}
82-
}
83-
84-
void parallel_with_sections_loop() {
85-
#pragma omp parallel
86-
{
87-
#pragma omp sections
88-
{
89-
for (int i = 0 ; i < NNN ; i++) {
90-
#pragma omp loop bind(parallel) // expected-error{{region cannot be closely nested inside 'sections' region; perhaps you forget to enclose 'omp loop' directive into a parallel region?}}
91-
for (int j = 0 ; j < NNN ; j++) {
92-
aaa2[i][j] = i+j;
93-
}
94-
}
95-
96-
#pragma omp section
97-
{
98-
aaa[NNN-1] = NNN;
99-
}
100-
}
101-
}
102-
}
103-
10418
void teams_loop() {
10519
int var1, var2;
10620

@@ -120,23 +34,17 @@ void teams_loop() {
12034
}
12135
}
12236

123-
void teams_targetteams_with_loop() {
124-
#pragma omp target teams
125-
for (int i = 0 ; i < NNN ; i++) {
126-
#pragma omp loop bind(teams)
127-
for (int j = 0 ; j < NNN ; j++) {
128-
aaa2[i][j] = i+j;
129-
}
37+
void orphan_loop_with_bind() {
38+
#pragma omp loop bind(parallel)
39+
for (int j = 0 ; j < NNN ; j++) {
40+
aaa[j] = j*NNN;
13041
}
13142
}
13243

133-
void teams_targetfor_with_loop_bind() {
134-
#pragma omp target teams distribute parallel for
135-
for (int i = 0 ; i < NNN ; i++) {
136-
#pragma omp loop bind(teams) // expected-error{{region cannot be closely nested inside 'target teams distribute parallel for' region; perhaps you forget to enclose 'omp loop' directive into a teams region?}}
137-
for (int j = 0 ; j < NNN ; j++) {
138-
aaa2[i][j] = i+j;
139-
}
44+
void orphan_loop_no_bind() {
45+
#pragma omp loop // expected-error{{expected 'bind' clause for 'loop' construct without an enclosing OpenMP construct}}
46+
for (int j = 0 ; j < NNN ; j++) {
47+
aaa[j] = j*NNN;
14048
}
14149
}
14250

@@ -157,80 +65,12 @@ void teams_loop_reduction() {
15765
}
15866
}
15967

160-
void teams_loop_distribute() {
161-
int total = 0;
162-
163-
#pragma omp teams num_teams(8) thread_limit(256)
164-
#pragma omp distribute parallel for dist_schedule(static, 1024) \
165-
schedule(static, 64)
166-
for (int i = 0; i < NNN; i++) {
167-
#pragma omp loop bind(teams) // expected-error{{'distribute parallel for' region; perhaps you forget to enclose 'omp loop' directive into a teams region?}}
168-
for (int j = 0; j < NNN; j++) {
169-
aaa2[i][j] = i+j;
170-
}
171-
}
172-
}
173-
174-
void parallel_for_with_loop_teams_bind(){
175-
#pragma omp parallel for
176-
for (int i = 0; i < NNN; i++) {
177-
#pragma omp loop bind(teams) // expected-error{{region cannot be closely nested inside 'parallel for' region; perhaps you forget to enclose 'omp loop' directive into a teams region?}}
178-
for (int j = 0 ; j < NNN ; j++) {
179-
aaa[i] = i+i*NNN;
180-
}
181-
}
182-
}
183-
184-
void teams_with_loop_thread_bind(){
185-
#pragma omp teams
186-
for (int i = 0; i < NNN; i++) {
187-
#pragma omp loop bind(thread)
188-
for (int j = 0 ; j < NNN ; j++) {
189-
aaa[i] = i+i*NNN;
190-
}
191-
}
192-
}
193-
194-
void orphan_loop_no_bind() {
195-
#pragma omp loop // expected-error{{expected 'bind' clause for 'loop' construct without an enclosing OpenMP construct}}
196-
for (int j = 0 ; j < NNN ; j++) {
197-
aaa[j] = j*NNN;
198-
}
199-
}
200-
201-
void orphan_loop_parallel_bind() {
202-
#pragma omp loop bind(parallel)
203-
for (int j = 0 ; j < NNN ; j++) {
204-
aaa[j] = j*NNN;
205-
}
206-
}
207-
208-
void orphan_loop_teams_bind(){
209-
#pragma omp loop bind(teams)
210-
for (int i = 0; i < NNN; i++) {
211-
aaa[i] = i+i*NNN;
212-
}
213-
}
214-
21568
int main(int argc, char *argv[]) {
21669
parallel_loop();
217-
parallel_for_AND_loop_bind();
218-
parallel_nowait();
219-
parallel_for_with_nothing();
220-
parallel_targetfor_with_loop_bind();
221-
parallel_targetparallel_with_loop();
222-
loop_bind_AND_loop_bind();
223-
parallel_with_sections_loop();
22470
teams_loop();
225-
teams_targetteams_with_loop();
226-
teams_targetfor_with_loop_bind();
227-
teams_loop_reduction();
228-
teams_loop_distribute();
229-
parallel_for_with_loop_teams_bind();
230-
teams_with_loop_thread_bind();
71+
orphan_loop_with_bind();
23172
orphan_loop_no_bind();
232-
orphan_loop_parallel_bind();
233-
orphan_loop_teams_bind();
73+
teams_loop_reduction();
23474
}
23575

23676
#endif

clang/test/PCH/pragma-loop.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,9 @@ class pragma_test {
116116

117117
inline void run10(int *List, int Length) {
118118
int i = 0;
119-
int j = 0;
120-
#pragma omp teams
119+
#pragma omp loop bind(teams)
121120
for (int i = 0; i < Length; i++) {
122-
#pragma omp loop bind(teams)
123-
for (int j = 0; j < Length; j++) {
124-
List[i] = i+j;
125-
}
121+
List[i] = i;
126122
}
127123
}
128124

0 commit comments

Comments
 (0)