1 ; RUN: opt -S -mtriple=amdgcn-- -passes=amdgpu-lower-ctor-dtor < %s | FileCheck %s
2 ; RUN: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx700 -filetype=obj -o - < %s | llvm-readelf -s - 2>&1 | FileCheck %s -check-prefix=CHECK-VIS
4 ; Make sure that we don't modify the functions if amdgcn.device.init or
5 ; amdgcn.device.fini already exit.
7 @llvm.global_ctors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @foo, ptr null }]
8 @llvm.global_dtors = appending addrspace(1) global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 1, ptr @bar, ptr null }]
10 ; CHECK-LABEL: amdgpu_kernel void @amdgcn.device.init() #0 {
11 ; CHECK-NEXT: store volatile i32 1, ptr addrspace(1) null
12 ; CHECK-NEXT: ret void
15 ; CHECK-LABEL: define amdgpu_kernel void @amdgcn.device.fini() #1 {
16 ; CHECK-NEXT: store volatile i32 0, ptr addrspace(1) null
17 ; CHECK-NEXT: ret void
20 ; CHECK-NOT: amdgcn.device.
22 ; CHECK-VIS: FUNC GLOBAL PROTECTED {{.*}} amdgcn.device.init{{$}}
23 ; CHECK-VIS: OBJECT GLOBAL DEFAULT {{.*}} amdgcn.device.init.kd{{$}}
24 ; CHECK-VIS: FUNC GLOBAL PROTECTED {{.*}} amdgcn.device.fini{{$}}
25 ; CHECK-VIS: OBJECT GLOBAL DEFAULT {{.*}} amdgcn.device.fini.kd{{$}}
27 define internal void @foo() {
31 define internal void @bar() {
35 define amdgpu_kernel void @amdgcn.device.init() #0 {
36 store volatile i32 1, ptr addrspace(1) null
40 define amdgpu_kernel void @amdgcn.device.fini() #1 {
41 store volatile i32 0, ptr addrspace(1) null
45 attributes #0 = { "device-init" }
46 attributes #1 = { "device-fini" }
47 ; CHECK: attributes #0 = { "device-init" }
48 ; CHECK: attributes #1 = { "device-fini" }