Skip to content

Commit 634fbdc

Browse files
stevemerrbader
authored andcommitted
[SYCL] Remove incorrect source correlation from kernel instructions (#255)
Clear incorrect source locations from several instructions in the IR for the kernel. This includes the call to __init(), the call to operator() and the return statement. Signed-off-by: Steve Merritt <[email protected]>
1 parent 268fc2c commit 634fbdc

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,23 @@ class KernelBodyTransform : public TreeTransform<KernelBodyTransform> {
385385
auto NewDecl = MappingPair.second;
386386
return DeclRefExpr::Create(
387387
SemaRef.getASTContext(), DRE->getQualifierLoc(),
388-
DRE->getTemplateKeywordLoc(), NewDecl, false, DRE->getNameInfo(),
388+
DRE->getTemplateKeywordLoc(), NewDecl, false,
389+
DeclarationNameInfo(DRE->getNameInfo().getName(), SourceLocation(),
390+
DRE->getNameInfo().getInfo()),
389391
NewDecl->getType(), DRE->getValueKind());
390392
}
391393
return DRE;
392394
}
393395

396+
StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
397+
MultiStmtArg Statements,
398+
SourceLocation RBraceLoc,
399+
bool IsStmtExpr) {
400+
// Build a new compound statement but clear the source locations.
401+
return getSema().ActOnCompoundStmt(SourceLocation(), SourceLocation(),
402+
Statements, IsStmtExpr);
403+
}
404+
394405
private:
395406
std::pair<DeclaratorDecl *, DeclaratorDecl *> MappingPair;
396407
Sema &SemaRef;
@@ -520,8 +531,8 @@ static CompoundStmt *CreateOpenCLKernelBody(Sema &S,
520531
auto ME = MemberExpr::Create(
521532
S.Context, SpecialObjME, false, SourceLocation(),
522533
NestedNameSpecifierLoc(), SourceLocation(), InitMethod, MethodDAP,
523-
InitMethod->getNameInfo(), nullptr, InitMethod->getType(),
524-
VK_LValue, OK_Ordinary);
534+
DeclarationNameInfo(InitMethod->getDeclName(), SourceLocation()),
535+
nullptr, InitMethod->getType(), VK_LValue, OK_Ordinary);
525536

526537
// Not referenced -> not emitted
527538
S.MarkFunctionReferenced(SourceLocation(), InitMethod, true);
Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1-
// RUN: DISABLE_INFER_AS=1 %clang --sycl %s -S -emit-llvm -g -o - | FileCheck %s --check-prefixes CHECK,CHECK-OLD
2-
// RUN: %clang --sycl %s -S -emit-llvm -g -o - | FileCheck %s --check-prefixes CHECK,CHECK-NEW
1+
// RUN: %clang --sycl %s -S -I %S/Inputs -emit-llvm -g -o - | FileCheck %s
32
//
4-
// Verify the SYCL kernel routine is marked artificial.
3+
// Verify the SYCL kernel routine is marked artificial and has no source
4+
// correlation.
55
//
6-
// Since it has no source correlation of its own, the SYCL kernel needs to be
7-
// marked artificial or it will inherit source correlation from the surrounding
8-
// code.
6+
// The SYCL kernel should have no source correlation of its own, so it needs
7+
// to be marked artificial or it will inherit source correlation from the
8+
// surrounding code.
99
//
1010

11-
template <typename Name, typename Func>
12-
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
11+
#include <sycl.hpp>
12+
13+
template <typename name, typename Func>
14+
__attribute__((sycl_kernel)) void kernel(Func kernelFunc) {
1315
kernelFunc();
1416
}
1517

1618
int main() {
17-
int value = 0;
18-
int* captured = &value;
19-
kernel_single_task<class kernel_function>([=]() {
20-
*captured = 1;
21-
});
19+
cl::sycl::sampler Sampler;
20+
kernel<class use_kernel_for_test>([=]() {
21+
Sampler.use();
22+
});
2223
return 0;
2324
}
2425

25-
// CHECK-OLD: define{{.*}} spir_kernel {{.*}}void @_ZTSZ4mainE15kernel_function(i32*{{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
26-
// CHECK-NEW: define{{.*}} spir_kernel {{.*}}void @_ZTSZ4mainE15kernel_function(i32 addrspace(4)*{{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
26+
// CHECK: define{{.*}} spir_kernel {{.*}}19use_kernel_for_test({{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
27+
// CHECK: getelementptr inbounds %"class.{{.*}}.anon"{{.*}} !dbg [[LINE_A0:![0-9]+]]
28+
// CHECK: call spir_func void {{.*}}6__init{{.*}} !dbg [[LINE_A0]]
29+
// CHECK: call spir_func void @"_ZZ4mainENK3$_0clEv"{{.*}} !dbg [[LINE_B0:![0-9]+]]
30+
// CHECK: ret void, !dbg [[LINE_A0]]
2731
// CHECK: [[FILE:![0-9]+]] = !DIFile(filename: "{{.*}}debug-info-srcpos-kernel.cpp"{{.*}})
28-
// CHECK: [[KERNEL]] = {{.*}}!DISubprogram(name: "_ZTSZ4mainE15kernel_function"
32+
// CHECK: [[KERNEL]] = {{.*}}!DISubprogram(name: "{{.*}}19use_kernel_for_test"
2933
// CHECK-SAME: scope: [[FILE]]
3034
// CHECK-SAME: file: [[FILE]]
3135
// CHECK-SAME: flags: DIFlagArtificial | DIFlagPrototyped
36+
// CHECK: [[LINE_A0]] = !DILocation(line: 0
37+
// CHECK: [[LINE_B0]] = !DILocation(line: 0
38+

0 commit comments

Comments
 (0)