Skip to content

Commit 0d1dd2d

Browse files
authored
[SYCL] Add a module flag for device compilations (#13880)
Add a module flag "-sycl-device" for SYCL device compilations. The flag is not added for host compilations. This helps optimization reports identify target device compilations.
1 parent 01e1526 commit 0d1dd2d

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,8 +1308,10 @@ void CodeGenModule::Release() {
13081308
getTarget().getTargetOpts().NVVMCudaPrecSqrt);
13091309
}
13101310

1311-
if (LangOpts.SYCLIsDevice && LangOpts.SYCLIsNativeCPU) {
1312-
getModule().addModuleFlag(llvm::Module::Error, "is-native-cpu", 1);
1311+
if (LangOpts.SYCLIsDevice) {
1312+
getModule().addModuleFlag(llvm::Module::Error, "sycl-device", 1);
1313+
if (LangOpts.SYCLIsNativeCPU)
1314+
getModule().addModuleFlag(llvm::Module::Error, "is-native-cpu", 1);
13131315
}
13141316

13151317
if (LangOpts.EHAsynch)

clang/test/CodeGenSYCL/function-attrs.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
int foo();
66

77
// CHECK-LABEL: define linkonce_odr spir_func void @_Z3barv(
8-
// CHECK-SAME: ) #[[ATTR2:[0-9]+]] !srcloc !5 {
8+
// CHECK-SAME: ) #[[ATTR2:[0-9]+]] !srcloc ![[MD1:[0-9]+]] {
99
// CHECK-NEXT: entry:
1010
// CHECK-NEXT: [[A:%.*]] = alloca i32, align 4
1111
// CHECK-NEXT: [[A_ASCAST:%.*]] = addrspacecast ptr [[A]] to ptr addrspace(4)
@@ -18,7 +18,7 @@ void bar() {
1818
}
1919

2020
// CHECK-LABEL: define linkonce_odr spir_func noundef i32 @_Z3foov(
21-
// CHECK-SAME: ) #[[ATTR2]] !srcloc !6 {
21+
// CHECK-SAME: ) #[[ATTR2]] !srcloc ![[MD2:[0-9]+]] {
2222
// CHECK-NEXT: entry:
2323
// CHECK-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
2424
// CHECK-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr [[RETVAL]] to ptr addrspace(4)
@@ -43,11 +43,11 @@ int main() {
4343
// CHECK: attributes #2 = { convergent mustprogress noinline norecurse nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
4444
// CHECK: attributes #3 = { convergent nounwind }
4545
//.
46-
// CHECK: !0 = !{i32 1, !"wchar_size", i32 4}
47-
// CHECK: !1 = !{i32 1, i32 2}
48-
// CHECK: !2 = !{i32 4, i32 100000}
49-
// CHECK: !3 = !{i32 {{.*}}}
50-
// CHECK: !4 = !{}
51-
// CHECK: !5 = !{i32 {{.*}}}
52-
// CHECK: !6 = !{i32 {{.*}}}
46+
// CHECK: !{{[0-9]+}} = !{i32 1, !"wchar_size", i32 4}
47+
// CHECK: !{{[0-9]+}} = !{i32 1, i32 2}
48+
// CHECK: !{{[0-9]+}} = !{i32 4, i32 100000}
49+
// CHECK: !{{[0-9]+}} = !{i32 {{.*}}}
50+
// CHECK: !{{[0-9]+}} = !{}
51+
// CHECK: ![[MD1]] = !{i32 {{.*}}}
52+
// CHECK: ![[MD2]] = !{i32 {{.*}}}
5353
//.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -emit-llvm -internal-isystem %S/Inputs -o - %s | FileCheck %s
2+
// RUN: %clang_cc1 -fsycl-is-host -emit-llvm -internal-isystem %S/Inputs -o - %s | FileCheck %s --check-prefixes=HOST
3+
4+
// This test checks if the sycl-device module flag is created for device
5+
// compilations and not for host compilations.
6+
#include "sycl.hpp"
7+
8+
void foo() {
9+
sycl::handler h;
10+
h.single_task([]() {});
11+
}
12+
13+
// Check for the presence of sycl-device module flag in device
14+
// compilations and its absence in host compilations.
15+
// CHECK: !{{[0-9]*}} = !{i32 1, !"sycl-device", i32 1}
16+
// HOST-NOT: !"sycl-device"

0 commit comments

Comments
 (0)