Skip to content

Commit 822dd15

Browse files
author
Sunil Kuravinakop
committed
1) In the default clause, changing check for allocatable type in
variable category. 2) Adding a new test case clang/test/OpenMP/parallel_default_variableCategory_codegen.cpp 3) Taking care of new comments in llvm#157063
1 parent 0590c9e commit 822dd15

File tree

2 files changed

+137
-5
lines changed

2 files changed

+137
-5
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,22 @@ static std::string getOpenMPClauseNameForDiag(OpenMPClauseKind C) {
13141314
return getOpenMPClauseName(C).str();
13151315
}
13161316

1317+
bool isAllocatableType(QualType QT) {
1318+
if (QT->isPointerType())
1319+
return true;
1320+
QT = QT.getCanonicalType().getUnqualifiedType();
1321+
if (const CXXRecordDecl *RD = QT->getAsCXXRecordDecl()) {
1322+
if (isa<ClassTemplateSpecializationDecl>(RD)) {
1323+
std::string QName = RD->getQualifiedNameAsString();
1324+
return (QName == "std::vector" || QName == "vector" ||
1325+
QName == "std::unique_ptr" || QName == "unique_ptr" ||
1326+
QName == "std::shared_ptr" || QName == "shared_ptr" ||
1327+
QName == "llvm::SmallVector" || QName == "SmallVector");
1328+
}
1329+
}
1330+
return false;
1331+
}
1332+
13171333
DSAStackTy::DSAVarData DSAStackTy::getDSA(const_iterator &Iter,
13181334
ValueDecl *D) const {
13191335
D = getCanonicalDecl(D);
@@ -1370,20 +1386,19 @@ DSAStackTy::DSAVarData DSAStackTy::getDSA(const_iterator &Iter,
13701386
DefaultDataSharingAttributes IterDA = Iter->DefaultAttr;
13711387
switch (Iter->DefaultVCAttr) {
13721388
case DSA_VC_aggregate:
1373-
if (!VD->getType()->isAggregateType())
1389+
if (!D->getType()->isAggregateType())
13741390
IterDA = DSA_none;
13751391
break;
13761392
case DSA_VC_allocatable:
1377-
if (!(VD->getType()->isPointerType() ||
1378-
VD->getType()->isVariableArrayType()))
1393+
if (!isAllocatableType(D->getType()))
13791394
IterDA = DSA_none;
13801395
break;
13811396
case DSA_VC_pointer:
1382-
if (!VD->getType()->isPointerType())
1397+
if (!D->getType()->isPointerType())
13831398
IterDA = DSA_none;
13841399
break;
13851400
case DSA_VC_scalar:
1386-
if (!VD->getType()->isScalarType())
1401+
if (!D->getType()->isScalarType())
13871402
IterDA = DSA_none;
13881403
break;
13891404
case DSA_VC_all:
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// RUN: %clangxx -DOMP60 -Xclang -verify -Wno-vla -fopenmp -fopenmp-version=60 -x c++ -S -emit-llvm %s -o - | FileCheck --check-prefixes=OMP60 %s
2+
// expected-no-diagnostics
3+
#ifndef HEADER
4+
#define HEADER
5+
6+
#include <vector>
7+
8+
int global;
9+
#define VECTOR_SIZE 4
10+
int main (int argc, char **argv) {
11+
int i,n;
12+
int x;
13+
14+
n = VECTOR_SIZE;
15+
16+
#pragma omp parallel masked firstprivate(x) num_threads(2)
17+
{
18+
int *xPtr = nullptr;
19+
// scalar
20+
#pragma omp task default(shared:scalar)
21+
{
22+
xPtr = &x;
23+
}
24+
#pragma omp taskwait
25+
26+
// pointer
27+
#pragma omp task default(shared:pointer) shared(x)
28+
{
29+
xPtr = &x;
30+
}
31+
#pragma omp taskwait
32+
}
33+
34+
int *aggregate[VECTOR_SIZE] = {0,0,0,0};
35+
std::vector<int *> arr(VECTOR_SIZE,0);
36+
37+
#pragma omp parallel masked num_threads(2)
38+
{
39+
// aggregate
40+
#pragma omp task default(shared:aggregate)
41+
for(i=0;i<n;i++) {
42+
aggregate[i] = &x;
43+
}
44+
#pragma omp taskwait
45+
46+
#pragma omp task default(shared:aggregate) shared(x)
47+
for(i=0;i<n;i++) {
48+
aggregate[i] = &x;
49+
}
50+
#pragma omp taskwait
51+
52+
// allocatable
53+
#pragma omp task default(shared:allocatable)
54+
for(i=0;i<n;i++) {
55+
arr[i] = &x;
56+
}
57+
#pragma omp taskwait
58+
59+
#pragma omp task default(shared:allocatable) shared(x)
60+
for(i=0;i<n;i++) {
61+
arr[i] = &x;
62+
}
63+
#pragma omp taskwait
64+
65+
// all
66+
#pragma omp task default(shared:all)
67+
for(i=0;i<n;i++) {
68+
aggregate[i] = &x;
69+
}
70+
#pragma omp taskwait
71+
}
72+
}
73+
74+
#endif
75+
76+
// OMP60-LABEL: define {{.*}}main.omp_outlined{{.*}}
77+
// OMP60-NEXT: entry:
78+
// OMP60-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
79+
// OMP60-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
80+
// OMP60: [[X_ADDR:%.*]] = alloca{{.*}}
81+
// OMP60: [[xPTR:%.*]] = alloca{{.*}}
82+
// OMP60: store ptr null, ptr [[xPTR]]{{.*}}
83+
// OMP60: store ptr [[xPTR]]{{.*}}
84+
// OMP60: store ptr [[X_ADDR]]{{.*}}
85+
// OMP60-NEXT: {{.*}}call{{.*}}__kmpc_omp_task_alloc{{.*}}
86+
// OMP60: ret void
87+
//
88+
// OMP60: define {{.*}}main.omp_outlined{{.*}}
89+
// OMP60-NEXT: entry:
90+
// OMP60-NEXT: [[DOTGLOBAL_TID__ADDR:%.*]] = alloca ptr, align 8
91+
// OMP60-NEXT: [[DOTBOUND_TID__ADDR:%.*]] = alloca ptr, align 8
92+
// OMP60: [[I_ADDR:%.*]] = alloca{{.*}}
93+
// OMP60-NEXT: [[N_ADDR:%.*]] = alloca{{.*}}
94+
// OMP60-NEXT: [[AGGREGATE_ADDR:%.*]] = alloca{{.*}}
95+
// OMP60-NEXT: [[X_ADDR:%.*]] = alloca{{.*}}
96+
// OMP60-NEXT: [[ARR_ADDR:%.*]] = alloca{{.*}}
97+
// OMP60: [[TMP0:%.*]] = load{{.*}}[[I_ADDR]]
98+
// OMP60-NEXT: [[TMP1:%.*]] = load{{.*}}[[N_ADDR]]
99+
// OMP60-NEXT: [[TMP2:%.*]] = load{{.*}}[[AGGREGATE_ADDR]]
100+
// OMP60-NEXT: [[TMP3:%.*]] = load{{.*}}[[X_ADDR]]
101+
// OMP60-NEXT: [[TMP4:%.*]] = load{{.*}}[[ARR_ADDR]]
102+
// OMP60: store ptr [[TMP2]]{{.*}}
103+
// OMP60-NEXT: {{.*}}call{{.*}}__kmpc_omp_task_alloc{{.*}}
104+
// OMP60: store ptr [[TMP2]]{{.*}}
105+
// OMP60: store ptr [[TMP3]]{{.*}}
106+
// OMP60-NEXT: {{.*}}call{{.*}}__kmpc_omp_task_alloc{{.*}}
107+
// OMP60: store ptr [[TMP4]]{{.*}}
108+
// OMP60-NEXT: {{.*}}call{{.*}}__kmpc_omp_task_alloc{{.*}}
109+
// OMP60: store ptr [[TMP4]]{{.*}}
110+
// OMP60: store ptr [[TMP3]]{{.*}}
111+
// OMP60-NEXT: {{.*}}call{{.*}}__kmpc_omp_task_alloc{{.*}}
112+
// OMP60: store ptr [[TMP0]]{{.*}}
113+
// OMP60: store ptr [[TMP1]]{{.*}}
114+
// OMP60: store ptr [[TMP2]]{{.*}}
115+
// OMP60: store ptr [[TMP3]]{{.*}}
116+
// OMP60-NEXT: {{.*}}call{{.*}}__kmpc_omp_task_alloc{{.*}}
117+
// OMP60: ret void

0 commit comments

Comments
 (0)