File: implicit-norecurse-attrib.hlsl

package info (click to toggle)
llvm-toolchain-21 1%3A21.1.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 2,245,044 kB
  • sloc: cpp: 7,619,726; ansic: 1,434,018; asm: 1,058,748; python: 252,740; f90: 94,671; objc: 70,685; lisp: 42,813; pascal: 18,401; sh: 8,601; ml: 5,111; perl: 4,720; makefile: 3,666; awk: 3,523; javascript: 2,409; xml: 892; fortran: 770
file content (92 lines) | stat: -rw-r--r-- 2,924 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// RUN: %clang_cc1 -x hlsl -triple dxil-pc-shadermodel6.3-library  -finclude-default-header %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
// RUN: %clang_cc1 -x hlsl -triple dxil-pc-shadermodel6.0-compute  -finclude-default-header %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s

// Verify that a few different function types all get the NoRecurse attribute

#define MAX 100

struct Node {
  uint value;
  uint key;
  uint left, right;
};

// CHECK: Function Attrs:{{.*}}norecurse
// CHECK: define hidden noundef i32 @_Z4FindA100_4Nodej(ptr noundef byval([100 x %struct.Node]) align 1 %SortedTree, i32 noundef %key) [[Attr:\#[0-9]+]]
// CHECK: ret i32
// Find and return value corresponding to key in the SortedTree
uint Find(Node SortedTree[MAX], uint key) {
  uint nix = 0; // head
  while(true) {
    if (nix < 0)
      return 0.0; // Not found
    Node n = SortedTree[nix];
    if (n.key == key)
      return n.value;
    if (key < n.key)
      nix = n.left;
    else
      nix = n.right;
  }
}

// CHECK: Function Attrs:{{.*}}norecurse
// CHECK: define noundef i1 @_Z8InitTreeA100_4NodeN4hlsl8RWBufferIDv4_jEEj(ptr noundef byval([100 x %struct.Node]) align 1 %tree, ptr noundef byval(%"class.hlsl::RWBuffer") align 4 %encodedTree, i32 noundef %maxDepth) [[Attr:\#[0-9]+]]
// CHECK: ret i1
// Initialize tree with given buffer
// Imagine the inout works
export
bool InitTree(/*inout*/ Node tree[MAX], RWBuffer<uint4> encodedTree, uint maxDepth) {
  uint size = pow(2.f, (float)maxDepth) - 1;
  if (size > MAX) return false;
  for (uint i = 1; i < size; i++) {
    tree[i].value = encodedTree[i].x;
    tree[i].key   = encodedTree[i].y;
    tree[i].left  = encodedTree[i].z;
    tree[i].right = encodedTree[i].w;
  }
  return true;
}

RWBuffer<uint4> gTree;

// Mangled entry points are internal
// CHECK: Function Attrs:{{.*}}norecurse
// CHECK: define internal void @_Z4mainj(i32 noundef %GI) [[Attr]]
// CHECK: ret void

// Canonical entry points are external and shader attributed
// CHECK: Function Attrs:{{.*}}norecurse
// CHECK: define void @main() [[EntryAttr:\#[0-9]+]]
// CHECK: ret void

[numthreads(1,1,1)]
[shader("compute")]
void main(uint GI : SV_GroupIndex) {
  Node haystack[MAX];
  uint needle = 0;
  if (InitTree(haystack, gTree, GI))
    needle = Find(haystack, needle);
}

// Mangled entry points are internal
// CHECK: Function Attrs:{{.*}}norecurse
// CHECK: define internal void @_Z11defaultMainv() [[Attr]]
// CHECK: ret void

// Canonical entry points are external and shader attributed
// CHECK: Function Attrs:{{.*}}norecurse
// CHECK: define void @defaultMain() [[EntryAttr]]
// CHECK: ret void

[numthreads(1,1,1)]
[shader("compute")]
void defaultMain() {
  Node haystack[MAX];
  uint needle = 0;
  if (InitTree(haystack, gTree, 4))
    needle = Find(haystack, needle);
}

// CHECK: attributes [[Attr]] = {{.*}} norecurse
// CHECK: attributes [[EntryAttr]] = {{.*}} norecurse