xref: /aosp_15_r20/external/llvm/test/Bitcode/metadata-function-blocks.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llvm-as < %s | llvm-bcanalyzer -dump | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker; Test that metadata only used by a single function is serialized in that
3*9880d681SAndroid Build Coastguard Worker; function instead of in the global pool.
4*9880d681SAndroid Build Coastguard Worker;
5*9880d681SAndroid Build Coastguard Worker; In order to make the bitcode records easy to follow, nodes in this testcase
6*9880d681SAndroid Build Coastguard Worker; are named after the ids they are given in the bitcode.  Nodes local to a
7*9880d681SAndroid Build Coastguard Worker; function have offsets of 100 or 200 (depending on the function) so that they
8*9880d681SAndroid Build Coastguard Worker; remain unique within this textual IR.
9*9880d681SAndroid Build Coastguard Worker
10*9880d681SAndroid Build Coastguard Worker; Check for strings in the global pool.
11*9880d681SAndroid Build Coastguard Worker; CHECK:      <METADATA_BLOCK
12*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <STRINGS
13*9880d681SAndroid Build Coastguard Worker; CHECK-SAME:           /> num-strings = 3 {
14*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     'named'
15*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     'named and foo'
16*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     'foo and bar'
17*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   }
18*9880d681SAndroid Build Coastguard Worker
19*9880d681SAndroid Build Coastguard Worker; Each node gets a new number.  Bottom-up traversal of nodes.
20*9880d681SAndroid Build Coastguard Worker!named = !{!6}
21*9880d681SAndroid Build Coastguard Worker
22*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <NODE op0=1/>
23*9880d681SAndroid Build Coastguard Worker!4 = !{!"named"}
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <NODE op0=2/>
26*9880d681SAndroid Build Coastguard Worker!5 = !{!"named and foo"}
27*9880d681SAndroid Build Coastguard Worker
28*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <NODE op0=1 op1=4 op2=5/>
29*9880d681SAndroid Build Coastguard Worker!6 = !{!"named", !4, !5}
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <NODE op0=3/>
32*9880d681SAndroid Build Coastguard Worker!7 = !{!"foo and bar"}
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker; CHECK-NOT:    <NODE
35*9880d681SAndroid Build Coastguard Worker; CHECK:      </METADATA_BLOCK
36*9880d681SAndroid Build Coastguard Worker
37*9880d681SAndroid Build Coastguard Worker; Look at metadata local to @foo, starting with strings.
38*9880d681SAndroid Build Coastguard Worker; CHECK:      <FUNCTION_BLOCK
39*9880d681SAndroid Build Coastguard Worker; CHECK:        <METADATA_BLOCK
40*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     <STRINGS
41*9880d681SAndroid Build Coastguard Worker; CHECK-SAME:             /> num-strings = 1 {
42*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:       'foo'
43*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     }
44*9880d681SAndroid Build Coastguard Worker
45*9880d681SAndroid Build Coastguard Worker; Function-local nodes start at 9 (strings at 8).
46*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     <NODE op0=8/>
47*9880d681SAndroid Build Coastguard Worker!109 = !{!"foo"}
48*9880d681SAndroid Build Coastguard Worker
49*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     <NODE op0=8 op1=3 op2=9 op3=7 op4=5/>
50*9880d681SAndroid Build Coastguard Worker!110 = !{!"foo", !"foo and bar", !109, !7, !5}
51*9880d681SAndroid Build Coastguard Worker
52*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   </METADATA_BLOCK
53*9880d681SAndroid Build Coastguard Workerdefine void @foo() !foo !110 {
54*9880d681SAndroid Build Coastguard Worker  unreachable
55*9880d681SAndroid Build Coastguard Worker}
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Worker; Look at metadata local to @bar, starting with strings.
58*9880d681SAndroid Build Coastguard Worker; CHECK:    <FUNCTION_BLOCK
59*9880d681SAndroid Build Coastguard Worker; CHECK:      <METADATA_BLOCK
60*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <STRINGS
61*9880d681SAndroid Build Coastguard Worker; CHECK-SAME:           /> num-strings = 1 {
62*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:     'bar'
63*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   }
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Worker; Function-local nodes start at 9 (strings at 8).
66*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <NODE op0=8/>
67*9880d681SAndroid Build Coastguard Worker!209 = !{!"bar"}
68*9880d681SAndroid Build Coastguard Worker
69*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   <NODE op0=8 op1=3 op2=9 op3=7/>
70*9880d681SAndroid Build Coastguard Worker!210 = !{!"bar", !"foo and bar", !209, !7}
71*9880d681SAndroid Build Coastguard Worker
72*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: </METADATA_BLOCK
73*9880d681SAndroid Build Coastguard Workerdefine void @bar() {
74*9880d681SAndroid Build Coastguard Worker  unreachable, !bar !210
75*9880d681SAndroid Build Coastguard Worker}
76