xref: /llvm-project/llvm/test/Bitcode/metadata-function-blocks.ll (revision e98f9258349aeb8414a556326aeee8ba94a7c839)
1*e98f9258SMehdi Amini; RUN: llvm-as < %s -bitcode-mdindex-threshold=0 | llvm-bcanalyzer -dump | FileCheck %s
2520f8542SDuncan P. N. Exon Smith; Test that metadata only used by a single function is serialized in that
3520f8542SDuncan P. N. Exon Smith; function instead of in the global pool.
4520f8542SDuncan P. N. Exon Smith;
5520f8542SDuncan P. N. Exon Smith; In order to make the bitcode records easy to follow, nodes in this testcase
6520f8542SDuncan P. N. Exon Smith; are named after the ids they are given in the bitcode.  Nodes local to a
7520f8542SDuncan P. N. Exon Smith; function have offsets of 100 or 200 (depending on the function) so that they
8520f8542SDuncan P. N. Exon Smith; remain unique within this textual IR.
9520f8542SDuncan P. N. Exon Smith
10520f8542SDuncan P. N. Exon Smith; Check for strings in the global pool.
11520f8542SDuncan P. N. Exon Smith; CHECK:      <METADATA_BLOCK
12520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   <STRINGS
13520f8542SDuncan P. N. Exon Smith; CHECK-SAME:           /> num-strings = 3 {
14520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     'named'
15520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     'named and foo'
16520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     'foo and bar'
17520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   }
18520f8542SDuncan P. N. Exon Smith
19520f8542SDuncan P. N. Exon Smith; Each node gets a new number.  Bottom-up traversal of nodes.
20520f8542SDuncan P. N. Exon Smith!named = !{!6}
21520f8542SDuncan P. N. Exon Smith
22*e98f9258SMehdi Amini; Before the records we emit an offset to the index for the block
23*e98f9258SMehdi Amini; CHECK-NEXT:   <INDEX_OFFSET
24*e98f9258SMehdi Amini
259695eb32SDuncan P. N. Exon Smith; CHECK-NEXT:   <NODE op0=1/>
26c196531eSDuncan P. N. Exon Smith!4 = !{!"named"}
279695eb32SDuncan P. N. Exon Smith
28c196531eSDuncan P. N. Exon Smith; CHECK-NEXT:   <NODE op0=2/>
29c196531eSDuncan P. N. Exon Smith!5 = !{!"named and foo"}
30c196531eSDuncan P. N. Exon Smith
31c196531eSDuncan P. N. Exon Smith; CHECK-NEXT:   <NODE op0=1 op1=4 op2=5/>
32c196531eSDuncan P. N. Exon Smith!6 = !{!"named", !4, !5}
33520f8542SDuncan P. N. Exon Smith
34520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   <NODE op0=3/>
35520f8542SDuncan P. N. Exon Smith!7 = !{!"foo and bar"}
36520f8542SDuncan P. N. Exon Smith
37520f8542SDuncan P. N. Exon Smith; CHECK-NOT:    <NODE
38520f8542SDuncan P. N. Exon Smith; CHECK:      </METADATA_BLOCK
39520f8542SDuncan P. N. Exon Smith
40520f8542SDuncan P. N. Exon Smith; Look at metadata local to @foo, starting with strings.
41520f8542SDuncan P. N. Exon Smith; CHECK:      <FUNCTION_BLOCK
42520f8542SDuncan P. N. Exon Smith; CHECK:        <METADATA_BLOCK
43520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     <STRINGS
44520f8542SDuncan P. N. Exon Smith; CHECK-SAME:             /> num-strings = 1 {
45520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:       'foo'
46520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     }
47520f8542SDuncan P. N. Exon Smith
48520f8542SDuncan P. N. Exon Smith; Function-local nodes start at 9 (strings at 8).
49520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     <NODE op0=8/>
50520f8542SDuncan P. N. Exon Smith!109 = !{!"foo"}
51520f8542SDuncan P. N. Exon Smith
52520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     <NODE op0=8 op1=3 op2=9 op3=7 op4=5/>
53520f8542SDuncan P. N. Exon Smith!110 = !{!"foo", !"foo and bar", !109, !7, !5}
54520f8542SDuncan P. N. Exon Smith
55520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   </METADATA_BLOCK
56520f8542SDuncan P. N. Exon Smithdefine void @foo() !foo !110 {
57520f8542SDuncan P. N. Exon Smith  unreachable
58520f8542SDuncan P. N. Exon Smith}
59520f8542SDuncan P. N. Exon Smith
60520f8542SDuncan P. N. Exon Smith; Look at metadata local to @bar, starting with strings.
61520f8542SDuncan P. N. Exon Smith; CHECK:    <FUNCTION_BLOCK
62520f8542SDuncan P. N. Exon Smith; CHECK:      <METADATA_BLOCK
63520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   <STRINGS
64520f8542SDuncan P. N. Exon Smith; CHECK-SAME:           /> num-strings = 1 {
65520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:     'bar'
66520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   }
67520f8542SDuncan P. N. Exon Smith
68520f8542SDuncan P. N. Exon Smith; Function-local nodes start at 9 (strings at 8).
69520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   <NODE op0=8/>
70520f8542SDuncan P. N. Exon Smith!209 = !{!"bar"}
71520f8542SDuncan P. N. Exon Smith
72520f8542SDuncan P. N. Exon Smith; CHECK-NEXT:   <NODE op0=8 op1=3 op2=9 op3=7/>
73520f8542SDuncan P. N. Exon Smith!210 = !{!"bar", !"foo and bar", !209, !7}
74520f8542SDuncan P. N. Exon Smith
75520f8542SDuncan P. N. Exon Smith; CHECK-NEXT: </METADATA_BLOCK
76520f8542SDuncan P. N. Exon Smithdefine void @bar() {
77520f8542SDuncan P. N. Exon Smith  unreachable, !bar !210
78520f8542SDuncan P. N. Exon Smith}
79