Skip to content

Commit 4de58d3

Browse files
committed
CodeGen: Support 'this'
1 parent 59e5b7e commit 4de58d3

File tree

4 files changed

+83
-3
lines changed

4 files changed

+83
-3
lines changed

clang/lib/CodeGen/CGOmpSsRuntime.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,12 @@ static void EmitDSA(StringRef Name, CodeGenFunction &CGF, const Expr *E,
311311
}
312312
if (!FirstTime) // We have seen a vla, save dimensions
313313
DsaData.append(TmpDsaData.begin(), TmpDsaData.end());
314-
TaskInfo.emplace_back(Basename, DsaData);
315-
}
316-
else {
314+
} else if (const CXXThisExpr *ThisE = dyn_cast<CXXThisExpr>(E)) {
315+
DsaData.push_back(CGF.EmitScalarExpr(ThisE));
316+
} else {
317317
llvm_unreachable("Unhandled expression");
318318
}
319+
TaskInfo.emplace_back(Basename, DsaData);
319320
}
320321

321322
static void EmitDependency(StringRef Name, CodeGenFunction &CGF, const Expr *E,

clang/lib/CodeGen/CGStmtOmpSs.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ static void AddDSAData(const OSSTaskDirective &S, SmallVectorImpl<const Expr *>
3636
const ValueDecl *VD = DRE->getDecl();
3737
if (DeclExpr.insert(VD).second)
3838
Data.push_back(Ref);
39+
} else if (const CXXThisExpr *ThisE = dyn_cast<CXXThisExpr>(Ref)) {
40+
// 'this' expression is only allowed when it's generated by the compiler
41+
Data.push_back(ThisE);
3942
}
4043
}
4144
}

clang/test/OmpSs/AST/this.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %clang_cc1 -x c++ -verify -fompss-2 -ast-dump -ferror-limit 100 %s | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
struct S {
5+
int x;
6+
int y;
7+
void f(int _x) {
8+
#pragma oss task depend(out : x)
9+
{}
10+
#pragma oss task depend(in : this->x)
11+
{}
12+
#pragma oss task
13+
{ x = 1; }
14+
#pragma oss task
15+
{ this->x = 2; }
16+
}
17+
};
18+
19+
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:8:13, col:37>
20+
// CHECK-NEXT: OSSDependClause 0x{{[^ ]*}} <col:22, col:36>
21+
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:35> 'int' lvalue ->x 0x{{[^ ]*}}
22+
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <col:35> 'S *' implicit this
23+
// CHECK-NEXT: OSSSharedClause 0x{{[^ ]*}} <<invalid sloc>> <implicit>
24+
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <col:35> 'S *' implicit this
25+
26+
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:10:13, col:42>
27+
// CHECK-NEXT: OSSDependClause 0x{{[^ ]*}} <col:22, col:41>
28+
// CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:34, col:40> 'int' lvalue ->x 0x{{[^ ]*}}
29+
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <col:34> 'S *' this
30+
// CHECK-NEXT: OSSSharedClause 0x{{[^ ]*}} <<invalid sloc>> <implicit>
31+
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <col:34> 'S *' this
32+
33+
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:12:13, col:21>
34+
// CHECK-NEXT: OSSSharedClause 0x{{[^ ]*}} <<invalid sloc>> <implicit>
35+
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <line:13:7> 'S *' implicit this
36+
37+
// CHECK: OSSTaskDirective 0x{{[^ ]*}} <line:14:13, col:21>
38+
// CHECK-NEXT: OSSSharedClause 0x{{[^ ]*}} <<invalid sloc>> <implicit>
39+
// CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}} <line:15:7> 'S *' this
40+

clang/test/OmpSs/IR/this.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %clang_cc1 -x c++ -verify -fompss-2 -disable-llvm-passes -ferror-limit 100 %s -S -emit-llvm -o - | FileCheck %s
2+
// expected-no-diagnostics
3+
4+
struct S {
5+
int x = 43;
6+
int y;
7+
void f();
8+
};
9+
10+
void S::f() {
11+
#pragma oss task depend(out : x)
12+
{}
13+
#pragma oss task depend(in : this->x)
14+
{}
15+
#pragma oss task
16+
{ x = 3; }
17+
#pragma oss task
18+
{ this->x = 3; }
19+
}
20+
21+
// CHECK: %this1 = load %struct.S*, %struct.S** %this.addr, align 8
22+
// CHECK-NEXT: %x = getelementptr inbounds %struct.S, %struct.S* %this1, i32 0, i32 0
23+
// CHECK-NEXT: %0 = call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00"), "QUAL.OSS.SHARED"(%struct.S* %this1), "QUAL.OSS.DEP.OUT"(i32* %x, i64 4, i64 0, i64 4) ]
24+
// CHECK-NEXT: call void @llvm.directive.region.exit(token %0)
25+
// CHECK-NEXT: %x2 = getelementptr inbounds %struct.S, %struct.S* %this1, i32 0, i32 0
26+
// CHECK-NEXT: %1 = call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00"), "QUAL.OSS.SHARED"(%struct.S* %this1), "QUAL.OSS.DEP.IN"(i32* %x2, i64 4, i64 0, i64 4) ]
27+
// CHECK-NEXT: call void @llvm.directive.region.exit(token %1)
28+
// CHECK-NEXT: %2 = call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00"), "QUAL.OSS.SHARED"(%struct.S* %this1) ]
29+
// CHECK-NEXT: %x3 = getelementptr inbounds %struct.S, %struct.S* %this1, i32 0, i32 0
30+
// CHECK-NEXT: store i32 3, i32* %x3, align 4
31+
// CHECK-NEXT: call void @llvm.directive.region.exit(token %2)
32+
// CHECK-NEXT: %3 = call token @llvm.directive.region.entry() [ "DIR.OSS"([5 x i8] c"TASK\00"), "QUAL.OSS.SHARED"(%struct.S* %this1) ]
33+
// CHECK-NEXT: %x4 = getelementptr inbounds %struct.S, %struct.S* %this1, i32 0, i32 0
34+
// CHECK-NEXT: store i32 3, i32* %x4, align 4
35+
// CHECK-NEXT: call void @llvm.directive.region.exit(token %3)
36+

0 commit comments

Comments
 (0)