Debian Codegraph @

clang/test/CodeGenHLSL/inline-functions.hlsl

raw
1 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE,OPT_ATTR
2 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,OPT_ATTR
3 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,NOOPT_ATTR
4 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,NOINLINE
5 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O0 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,OPT_ATTR
6 // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute %s -emit-llvm -O1 -o - | FileCheck %s --check-prefixes=CHECK,INLINE,NOOPT_ATTR
7
8 // Tests that user functions will always be inlined.
9 // This includes exported functions and mangled entry point implementation functions.
10 // The unmangled entry functions must not be alwaysinlined.
11
12 #define MAX 100
13
14 float nums[MAX];
15
16 // Verify that all functions have the alwaysinline attribute
17 // NOINLINE: Function Attrs: alwaysinline
18 // NOINLINE: define hidden void @_Z4swapA100_jjj(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %ix1, i32 noundef %ix2) [[Attr:\#[0-9]+]]
19 // NOINLINE: ret void
20 // Swap the values of Buf at indices ix1 and ix2
21 void swap(unsigned Buf[MAX], unsigned ix1, unsigned ix2) {
22 float tmp = Buf[ix1];
23 Buf[ix1] = Buf[ix2];
24 Buf[ix2] = tmp;
25 }
26
27 // NOINLINE: Function Attrs: alwaysinline
28 // NOINLINE: define hidden void @_Z10BubbleSortA100_jj(ptr noundef byval([100 x i32]) align 4 %Buf, i32 noundef %size) [[Attr]]
29 // NOINLINE: ret void
30 // Inefficiently sort Buf in place
31 void BubbleSort(unsigned Buf[MAX], unsigned size) {
32 bool swapped = true;
33 while (swapped) {
34 swapped = false;
35 for (unsigned i = 1; i < size; i++) {
36 if (Buf[i] < Buf[i-1]) {
37 swap(Buf, i, i-1);
38 swapped = true;
39 }
40 }
41 }
42 }
43
44 // Note ExtAttr is the inlined export set of attribs
45 // CHECK: Function Attrs: alwaysinline
46 // CHECK: define noundef i32 @_Z11RemoveDupesA100_jj(ptr {{[a-z_ ]*}}noundef byval([100 x i32]) align 4 {{.*}}%Buf, i32 noundef %size) {{[a-z_ ]*}}[[Attr:\#[0-9]+]]
47 // CHECK: ret i32
48 // Sort Buf and remove any duplicate values
49 // returns the number of values left
50 export
51 unsigned RemoveDupes(unsigned Buf[MAX], unsigned size) {
52 BubbleSort(Buf, size);
53 unsigned insertPt = 0;
54 for (unsigned i = 1; i < size; i++) {
55 if (Buf[i] == Buf[i-1])
56 insertPt++;
57 else
58 Buf[insertPt] = Buf[i];
59 }
60 return insertPt;
61 }
62
63
64 RWBuffer<unsigned> Indices;
65
66 // The mangled version of main only remains without inlining
67 // because it has internal linkage from the start
68 // Note main functions get the alwaysinline attrib, which Attr reflects
69 // NOINLINE: Function Attrs: alwaysinline
70 // NOINLINE: define internal void @_Z4mainj(i32 noundef %GI) [[Attr]]
71 // NOINLINE: ret void
72
73 // The unmangled version is not inlined, EntryAttr reflects that
74 // OPT_ATTR: Function Attrs: {{.*}}optnone
75 // NOOPT_ATTR-NOT: Function Attrs: {{.*}}optnone
76 // CHECK: define void @main() {{[a-z_ ]*}}[[EntryAttr:\#[0-9]+]]
77 // Make sure function calls are inlined when AlwaysInline is run
78 // This only leaves calls to llvm. intrinsics
79 // INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}
80 // CHECK: ret void
81
82 [numthreads(1,1,1)]
83 [shader("compute")]
84 void main(unsigned int GI : SV_GroupIndex) {
85 unsigned tmpIndices[MAX];
86 if (GI > MAX) return;
87 for (unsigned i = 1; i < GI; i++)
88 tmpIndices[i] = Indices[i];
89 RemoveDupes(tmpIndices, GI);
90 for (unsigned i = 1; i < GI; i++)
91 tmpIndices[i] = Indices[i];
92 }
93
94 // The mangled version of main only remains without inlining
95 // because it has internal linkage from the start
96 // Note main functions get the alwaysinline attrib, which Attr reflects
97 // NOINLINE: Function Attrs: alwaysinline
98 // NOINLINE: define internal void @_Z6main10v() [[Attr]]
99 // NOINLINE: ret void
100
101 // The unmangled version is not inlined, EntryAttr reflects that
102 // OPT_ATTR: Function Attrs: {{.*}}optnone
103 // NOOPT_ATTR-NOT: Function Attrs: {{.*}}optnone
104 // CHECK: define void @main10() {{[a-z_ ]*}}[[EntryAttr]]
105 // Make sure function calls are inlined when AlwaysInline is run
106 // This only leaves calls to llvm. intrinsics
107 // INLINE-NOT: call {{[^@]*}} @{{[^l][^l][^v][^m][^\.]}}
108 // CHECK: ret void
109
110 [numthreads(1,1,1)]
111 [shader("compute")]
112 void main10() {
113 main(10);
114 }
115
116 // CHECK: attributes [[Attr]] = {{.*}} alwaysinline
117 // CHECK: attributes [[EntryAttr]] = {{.*}} noinline