llvm-project/clang/test/CodeGenHLSL/GlobalConstructorFunction.hlsl
Thurston Dang b89bb7775d Reapply "[HLSL] set alwaysinline on HLSL functions (#106588)"
This reverts commit 4a63f4d301c0e044073e1b1f8f110015ec1778a1.

It was reverted because of a buildbot breakage, but the fix-forward has
landed (https://github.com/llvm/llvm-project/pull/109023).
2024-09-17 22:54:52 +00:00

43 lines
1.4 KiB
HLSL

// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -disable-llvm-passes %s -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -emit-llvm -O0 %s -o - | FileCheck %s --check-prefixes=CHECK,INLINE
int i;
__attribute__((constructor)) void call_me_first(void) {
i = 12;
}
__attribute__((constructor)) void then_call_me(void) {
i = 13;
}
__attribute__((destructor)) void call_me_last(void) {
i = 0;
}
[numthreads(1,1,1)]
void main(unsigned GI : SV_GroupIndex) {}
// Make sure global variable for ctors/dtors removed.
// CHECK-NOT:@llvm.global_ctors
// CHECK-NOT:@llvm.global_dtors
// CHECK: define void @main()
// CHECK-NEXT: entry:
// Verify function constructors are emitted
// NOINLINE-NEXT: call void @"?call_me_first@@YAXXZ"()
// NOINLINE-NEXT: call void @"?then_call_me@@YAXXZ"()
// NOINLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
// NOINLINE-NEXT: call void @"?main@@YAXI@Z"(i32 %0)
// NOINLINE-NEXT: call void @"?call_me_last@@YAXXZ"(
// NOINLINE-NEXT: ret void
// Verify constructor calls are inlined when AlwaysInline is run
// INLINE-NEXT: alloca
// INLINE-NEXT: store i32 12
// INLINE-NEXT: store i32 13
// INLINE-NEXT: %0 = call i32 @llvm.dx.flattened.thread.id.in.group()
// INLINE-NEXT: store i32 %
// INLINE-NEXT: store i32 0
// INLINE: ret void