Skip to content

[sycl-post-link] Do not drop SYCL_EXTERNAL functions #3793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions llvm/test/tools/sycl-post-link/erase_used.ll
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ target triple = "spir64-unknown-unknown-sycldevice"
; CHECK-NOT: llvm.used
@llvm.used = appending global [2 x i8*] [i8* bitcast (void ()* @foo to i8*), i8* bitcast (void ()* @bar to i8*)], section "llvm.metadata"

define weak_odr spir_kernel void @foo() {
define weak_odr spir_kernel void @foo() #0 {
ret void
}

define weak_odr spir_kernel void @bar() {
define weak_odr spir_kernel void @bar() #0 {
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,27 @@

declare dso_local spir_func zeroext i1 @_Z33__sycl_getScalarSpecConstantValueIbET_PKc(i8 addrspace(4)*)

define dso_local spir_kernel void @KERNEL_AAA() {
define dso_local spir_kernel void @KERNEL_AAA() #0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, why do we need to add the attribute to this test. Why It wasn't here before? Is it not possible to process the code without the attribute?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this is how we detect whether the function should be considered as an entry point or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct.

%1 = call spir_func zeroext i1 @_Z33__sycl_getScalarSpecConstantValueIbET_PKc(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @SCSymID, i64 0, i64 0) to i8 addrspace(4)*))
; CHECK-IR0: %{{[0-9]+}} = call i1 @_Z20__spirv_SpecConstantib(i32 1, i1 false)
%2 = call spir_func zeroext i1 @_Z33__sycl_getScalarSpecConstantValueIbET_PKc(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([11 x i8], [11 x i8]* @SCSymID2, i64 0, i64 0) to i8 addrspace(4)*))
; CHECK-IR0: %{{[0-9]+}} = call i1 @_Z20__spirv_SpecConstantib(i32 0, i1 false)
ret void
}

define dso_local spir_kernel void @KERNEL_BBB() {
define dso_local spir_kernel void @KERNEL_BBB() #0 {
%1 = call spir_func zeroext i1 @_Z33__sycl_getScalarSpecConstantValueIbET_PKc(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([10 x i8], [10 x i8]* @SCSymID, i64 0, i64 0) to i8 addrspace(4)*))
; CHECK-IR1: %{{[0-9]+}} = call i1 @_Z20__spirv_SpecConstantib(i32 0, i1 false)
ret void
}

define dso_local spir_kernel void @KERNEL_CCC() {
define dso_local spir_kernel void @KERNEL_CCC() #0 {
; CHECK-IR2: define{{.*}}spir_kernel void @KERNEL_CCC
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

; CHECK-IR0: !sycl.specialization-constants = !{![[#MD0:]], ![[#MD1:]]}
; CHECK-IR0: ![[#MD0:]] = !{!"SpecConst2", i32 0, i32 0, i32 1}
; CHECK-IR0: ![[#MD1:]] = !{!"SpecConst", i32 1, i32 0, i32 1}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
; RUN: sycl-post-link -ir-output-only -split=auto -S %s -o %t.ll
; RUN: FileCheck %s -input-file=%t.ll

; This test checks that known SPIRV and SYCL builtin functions
; (that are also marked with SYCL_EXTRENAL) are not considered
; as module entry points and thus are not added as entry to the
; device binary symbol table. So, they can be dropped if
; unreferenced.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

define dso_local spir_func void @_Z28__spirv_GlobalInvocationId_xv() #0 {
ret void
}
define dso_local spir_func void @_Z28__spXrv_GlobalInvocationId_xv() #0 {
ret void
}

define dso_local spir_func void @_Z33__sycl_getScalarSpecConstantValue() #0 {
ret void
}
define dso_local spir_func void @_Z33__sXcl_getScalarSpecConstantValue() #0 {
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

; CHECK-NOT: define dso_local spir_func void @_Z28__spirv_GlobalInvocationId_xv()
; CHECK-NOT: define dso_local spir_func void @_Z33__sycl_getScalarSpecConstantValue()

; CHECK-DAG: define dso_local spir_func void @_Z28__spXrv_GlobalInvocationId_xv()
; CHECK-DAG: define dso_local spir_func void @_Z33__sXcl_getScalarSpecConstantValue()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
; RUN: sycl-post-link -ir-output-only -split=auto -S %s -o %t.ll
; RUN: FileCheck %s -input-file=%t.ll

; This test checks that unreferenced functions without sycl-module-id
; attribute are dropped from the module after splitting.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

define dso_local spir_func void @externalDeviceFunc() #0 {
ret void
}

define dso_local spir_func void @unreferencedFunc() {
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

; CHECK: define dso_local spir_func void @externalDeviceFunc()
; CHECK-NOT: define dso_local spir_func void @unreferencedFunc()
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
; RUN: sycl-post-link -ir-output-only -split=auto -S %s -o %t.ll
; RUN: FileCheck %s -input-file=%t.ll

; This test checks that indirectly referenced functions (with sycl-module-id
; attribute) are not dropped from the module.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

define dso_local spir_func void @indRefDeviceFunc() #0 {
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" "referenced-indirectly"}

; CHECK: define dso_local spir_func void @indRefDeviceFunc()
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; RUN: sycl-post-link -split=auto -split-esimd -lower-esimd -O0 -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t_esimd_0.ll

; This test checks that unreferenced functions with sycl-module-id
; attribute are not dropped from the module and ESIMD lowering
; happens for them as well.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

@__spirv_BuiltInGlobalInvocationId = external dso_local local_unnamed_addr addrspace(1) constant <3 x i64>, align 32

define dso_local spir_func void @externalESIMDDeviceFunc() #0 !sycl_explicit_simd !0 {
entry:
%0 = load <3 x i64>, <3 x i64> addrspace(4)* addrspacecast (<3 x i64> addrspace(1)* @__spirv_BuiltInGlobalInvocationId to <3 x i64> addrspace(4)*), align 32
%1 = extractelement <3 x i64> %0, i64 0
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

!0 = !{}

; CHECK: define dso_local spir_func void @externalESIMDDeviceFunc()
; CHECK: entry:
; CHECK: call <3 x i32> @llvm.genx.local.id.v3i32()
; CHECK: call <3 x i32> @llvm.genx.local.size.v3i32()
; CHECK: call i32 @llvm.genx.group.id.x()
; CHECK: ret void
; CHECK: }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; RUN: sycl-post-link -ir-output-only -split=auto -S %s -o %t.ll
; RUN: FileCheck %s -input-file=%t.ll

; This test checks that unreferenced functions with sycl-module-id
; attribute are not dropped from the module after splitting
; in global mode.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

define dso_local spir_func void @externalDeviceFunc() #0 {
ret void
}

define dso_local spir_kernel void @kernel1() #0 {
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

; CHECK-DAG: define dso_local spir_func void @externalDeviceFunc()
; CHECK-DAG: define dso_local spir_kernel void @kernel1()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
; RUN: sycl-post-link -split=kernel -symbols -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-IR1
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-IR2
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-SYM1
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-SYM2

; This test checks that unreferenced functions with sycl-module-id
; attribute are not dropped from the module after splitting
; in per-kernel mode.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

define dso_local spir_func void @externalDeviceFunc() #0 {
ret void
}

define dso_local spir_kernel void @kernel1() #0 {
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

; CHECK-IR1: define dso_local spir_func void @externalDeviceFunc()
; CHECK-IR2: define dso_local spir_kernel void @kernel1()

; CHECK-SYM1: externalDeviceFunc
; CHECK-SYM2: kernel1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
; RUN: sycl-post-link -split=source -symbols -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-IR1
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-IR2
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-SYM1
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-SYM2

; This test checks that unreferenced functions with sycl-module-id
; attribute are not dropped from the module after splitting
; in per-source mode.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

define dso_local spir_func void @externalDeviceFunc() #0 {
ret void
}

define dso_local spir_kernel void @kernel1() #1 {
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }
attributes #1 = { "sycl-module-id"="b.cpp" }

; CHECK-IR1: define dso_local spir_func void @externalDeviceFunc()
; CHECK-IR2: define dso_local spir_kernel void @kernel1()

; CHECK-SYM1: externalDeviceFunc
; CHECK-SYM2: kernel1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
; RUN: sycl-post-link -split=source -symbols -S %s -o %t.table
; RUN: FileCheck %s -input-file=%t_0.ll --check-prefixes CHECK-IR1
; RUN: FileCheck %s -input-file=%t_1.ll --check-prefixes CHECK-IR2
; RUN: FileCheck %s -input-file=%t_0.sym --check-prefixes CHECK-SYM1
; RUN: FileCheck %s -input-file=%t_1.sym --check-prefixes CHECK-SYM2

; This test checks that the definition of function externalDeviceFunc is
; present in both resulting modules when per-source split is requested.

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spir64-unknown-linux-sycldevice"

define dso_local spir_func void @externalDeviceFunc() #0 {
ret void
}

define dso_local spir_kernel void @kernel1() #1 {
call void @externalDeviceFunc()
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }
attributes #1 = { "sycl-module-id"="b.cpp" }

; CHECK-IR1: define dso_local spir_func void @externalDeviceFunc()
; CHECK-IR2: define dso_local spir_func void @externalDeviceFunc()
; CHECK-IR2: define dso_local spir_kernel void @kernel1()

; CHECK-SYM1: externalDeviceFunc
; CHECK-SYM2: kernel1
6 changes: 4 additions & 2 deletions llvm/test/tools/sycl-post-link/sym_but_no_split.ll
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
; RUN: FileCheck %s -input-file=%t.files.table --check-prefixes CHECK-TABLE
; RUN: FileCheck %s -input-file=%t.files_0.sym --match-full-lines --check-prefixes CHECK-SYM

define dso_local spir_kernel void @KERNEL_AAA() {
define dso_local spir_kernel void @KERNEL_AAA() #0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

; CHECK-SYM-NOT: {{[a-zA-Z0-9._@]+}}
; CHECK-SYM: KERNEL_AAA
entry:
ret void
}

define dso_local spir_kernel void @KERNEL_BBB() {
define dso_local spir_kernel void @KERNEL_BBB() #0 {
; CHECK-SYM-NEXT: KERNEL_BBB
; CHECK-SYM-EMPTY:
entry:
ret void
}

attributes #0 = { "sycl-module-id"="a.cpp" }

; CHECK-TABLE: [Code|Properties|Symbols]
; CHECK-TABLE-NEXT: {{.*}}files_0.sym
; CHECK-TABLE-EMPTY:
Loading