Skip to content

Commit d674eb2

Browse files
committed
Consider only entry points when emitting optLevel property
1 parent ec37831 commit d674eb2

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; This test checks, that 'optLevel' property is only emitted based on the module
2+
; entry points
3+
;
4+
; In this test we have functions 'foo' and 'boo' defined in different
5+
; translation units. They are both entry points and 'foo' calls 'boo'.
6+
; As a result, we expect two modules:
7+
; - module with 'foo' (as entry point) and 'bar' (included as dependency) with
8+
; 'optLevel' set to 1 (taken from 'foo')
9+
; - module with 'bar' (as entry point) with 'optLevel' set to 2 (taken from
10+
; 'bar')
11+
12+
; RUN: sycl-post-link -split=source -symbols -S < %s -o %t.table
13+
; RUN: FileCheck %s -input-file=%t.table
14+
; RUN: FileCheck %s -input-file=%t_0.prop --check-prefixes CHECK-OPT-LEVEL-PROP-0
15+
; RUN: FileCheck %s -input-file=%t_1.prop --check-prefixes CHECK-OPT-LEVEL-PROP-1
16+
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-SYM-0
17+
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-SYM-1
18+
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefix CHECK-IR-0
19+
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefix CHECK-IR-1
20+
21+
; CHECK: [Code|Properties|Symbols]
22+
; CHECK: {{.*}}_0.ll|{{.*}}_0.prop|{{.*}}_0.sym
23+
; CHECK: {{.*}}_1.ll|{{.*}}_1.prop|{{.*}}_1.sym
24+
; CHECK-EMPTY:
25+
26+
; CHECK-OPT-LEVEL-PROP-0: optLevel=1|1
27+
; CHECK-OPT-LEVEL-PROP-1: optLevel=1|2
28+
; CHECK-SYM-0: _Z3fooii
29+
; CHECK-SYM-0-EMPTY:
30+
; CHECK-SYM-1: _Z3barii
31+
;
32+
; CHECK-IR-0-DAG: define {{.*}} @_Z3fooii{{.*}} #[[#ATTR0:]]
33+
; CHECK-IR-0-DAG: define {{.*}} @_Z3barii{{.*}} #[[#ATTR1:]]
34+
; CHECK-IR-0-DAG: attributes #[[#ATTR0]] = { {{.*}} "sycl-optlevel"="1" }
35+
; CHECK-IR-0-DAG: attributes #[[#ATTR1]] = { {{.*}} "sycl-optlevel"="2" }
36+
;
37+
; CHECK-IR-1: define {{.*}} @_Z3barii{{.*}} #[[#ATTR0:]]
38+
; CHECK-IR-1: attributes #[[#ATTR0]] = { {{.*}} "sycl-optlevel"="2" }
39+
40+
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
41+
target triple = "spir64-unknown-unknown"
42+
43+
define dso_local spir_func noundef i32 @_Z3fooii(i32 noundef %a, i32 noundef %b) local_unnamed_addr #0 {
44+
entry:
45+
%call = call i32 @_Z3barii(i32 %a, i32 %b)
46+
%sub = sub nsw i32 %a, %call
47+
ret i32 %sub
48+
}
49+
50+
define dso_local spir_func noundef i32 @_Z3barii(i32 noundef %a, i32 noundef %b) #1 {
51+
entry:
52+
%retval = alloca i32, align 4
53+
%a.addr = alloca i32, align 4
54+
%b.addr = alloca i32, align 4
55+
%retval.ascast = addrspacecast i32* %retval to i32 addrspace(4)*
56+
%a.addr.ascast = addrspacecast i32* %a.addr to i32 addrspace(4)*
57+
%b.addr.ascast = addrspacecast i32* %b.addr to i32 addrspace(4)*
58+
store i32 %a, i32 addrspace(4)* %a.addr.ascast, align 4
59+
store i32 %b, i32 addrspace(4)* %b.addr.ascast, align 4
60+
%0 = load i32, i32 addrspace(4)* %a.addr.ascast, align 4
61+
%1 = load i32, i32 addrspace(4)* %b.addr.ascast, align 4
62+
%add = add nsw i32 %0, %1
63+
ret i32 %add
64+
}
65+
66+
attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) "sycl-module-id"="test3.cpp" "sycl-optlevel"="1" }
67+
attributes #1 = { convergent mustprogress noinline norecurse nounwind optnone "sycl-module-id"="test2.cpp" "sycl-optlevel"="2" }
68+

llvm/tools/sycl-post-link/sycl-post-link.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,12 +466,12 @@ std::string saveModuleProperties(module_split::ModuleDesc &MD,
466466
{
467467
// Handle sycl-optlevel property
468468
int OptLevel = -1;
469-
for (const Function &F : M.functions()) {
470-
if (!F.hasFnAttribute(llvm::sycl::utils::ATTR_SYCL_OPTLEVEL))
469+
for (const Function *F : MD.entries()) {
470+
if (!F->hasFnAttribute(llvm::sycl::utils::ATTR_SYCL_OPTLEVEL))
471471
continue;
472472

473473
// getAsInteger returns true on error
474-
if (!F.getFnAttribute(llvm::sycl::utils::ATTR_SYCL_OPTLEVEL)
474+
if (!F->getFnAttribute(llvm::sycl::utils::ATTR_SYCL_OPTLEVEL)
475475
.getValueAsString()
476476
.getAsInteger(10, OptLevel)) {
477477
// It is expected that device-code split has separated kernels with

0 commit comments

Comments
 (0)