This patch introduces a new code object metadata field, ".kind" which is used to add support for init and fini kernels. HSAStreamer will use function attributes, "device-init" and "device-fini" to distinguish between init and fini kernels from the regular kernels and will emit metadata with ".kind" set to "init" and "fini" respectively. To reduce the number of init and fini kernels, the ctors and dtors present in the llvm's global.ctors and global.dtors lists are called from a single init and fini kernel respectively. Reviewed by: yaxunl Differential Revision: https://reviews.llvm.org/D105682
22 lines
712 B
LLVM
22 lines
712 B
LLVM
; RUN: opt -S -mtriple=amdgcn-- -amdgpu-lower-ctor-dtor < %s | FileCheck %s
|
|
|
|
@llvm.global_ctors = appending addrspace(1) global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @foo, i8* null }]
|
|
@llvm.global_dtors = appending addrspace(1) global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @bar, i8* null }]
|
|
|
|
; CHECK-LABEL: amdgpu_kernel void @amdgcn.device.init() #0
|
|
; CHECK-NEXT: call void @foo
|
|
|
|
; CHECK-LABEL: amdgpu_kernel void @amdgcn.device.fini() #1
|
|
; CHECK-NEXT: call void @bar
|
|
|
|
define internal void @foo() {
|
|
ret void
|
|
}
|
|
|
|
define internal void @bar() {
|
|
ret void
|
|
}
|
|
|
|
; CHECK: attributes #0 = { "device-init" }
|
|
; CHECK: attributes #1 = { "device-fini" }
|