Skip to content

Commit cbfac28

Browse files
committed
CodeGen: Remove data-sharing duplicates
closes llvm#27
1 parent 1394020 commit cbfac28

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

clang/lib/CodeGen/CGStmtOmpSs.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,28 @@ void CodeGenFunction::EmitOSSTaskwaitDirective(const OSSTaskwaitDirective &S) {
2626
CGM.getOmpSsRuntime().emitTaskwaitCall(*this, S.getBeginLoc());
2727
}
2828

29+
template<typename DSAKind>
30+
static void AddDSAData(const OSSTaskDirective &S, SmallVectorImpl<const Expr *> &Data) {
31+
// All DSA are DeclRefExpr
32+
llvm::SmallSet<const ValueDecl *, 8> DeclExpr;
33+
for (const auto *C : S.getClausesOfKind<DSAKind>()) {
34+
for (const Expr *Ref : C->varlists()) {
35+
if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Ref)) {
36+
const ValueDecl *VD = DRE->getDecl();
37+
if (DeclExpr.insert(VD).second)
38+
Data.push_back(Ref);
39+
}
40+
}
41+
}
42+
}
43+
2944
void CodeGenFunction::EmitOSSTaskDirective(const OSSTaskDirective &S) {
3045
OSSTaskDataTy Data;
31-
for (const auto *C : S.getClausesOfKind<OSSSharedClause>()) {
32-
for (const Expr *Ref : C->varlists())
33-
Data.SharedVars.push_back(Ref);
34-
}
35-
for (const auto *C : S.getClausesOfKind<OSSPrivateClause>()) {
36-
for (const Expr *Ref : C->varlists())
37-
Data.PrivateVars.push_back(Ref);
38-
}
39-
for (const auto *C : S.getClausesOfKind<OSSFirstprivateClause>()) {
40-
for (const Expr *Ref : C->varlists())
41-
Data.FirstprivateVars.push_back(Ref);
42-
}
46+
47+
AddDSAData<OSSSharedClause>(S, Data.SharedVars);
48+
AddDSAData<OSSPrivateClause>(S, Data.PrivateVars);
49+
AddDSAData<OSSFirstprivateClause>(S, Data.FirstprivateVars);
50+
4351
for (const auto *C : S.getClausesOfKind<OSSDependClause>()) {
4452
ArrayRef<OmpSsDependClauseKind> DepKinds = C->getDependencyKind();
4553
if (DepKinds.size() == 2) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -verify -fompss-2 -ferror-limit 100 %s -S -emit-llvm -o - | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
void foo() {
5+
int a;
6+
#pragma oss task shared(a) shared(a)
7+
{}
8+
#pragma oss task private(a) private(a)
9+
{}
10+
#pragma oss task firstprivate(a) firstprivate(a)
11+
{}
12+
}
13+
// CHECK: call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00"), "QUAL.OSS.SHARED"(i32* %a) ]
14+
// CHECK: call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00"), "QUAL.OSS.PRIVATE"(i32* %a) ]
15+
// CHECK: call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00"), "QUAL.OSS.FIRSTPRIVATE"(i32* %a) ]
16+

0 commit comments

Comments
 (0)