xref: /llvm-project/llvm/test/Transforms/StructurizeCFG/structurizecfg-debug-loc.ll (revision bf6f82a9df6a1693a5399039dcadd7fc00dab65e)
1; RUN: opt -S -o - -structurizecfg %s | FileCheck %s
2
3define void @if_then_else(ptr addrspace(1) %out, i1 %arg) !dbg !7 {
4; CHECK: @if_then_else(
5; CHECK:  entry:
6; CHECK:    br i1 {{.*}}, label %if.else, label %Flow, !dbg [[ITE_ENTRY_DL:![0-9]+]]
7; CHECK:  Flow:
8; CHECK:    br i1 {{.*}}, label %if.then, label %exit, !dbg [[ITE_ENTRY_DL]]
9; CHECK:  if.then:
10; CHECK:    br label %exit, !dbg [[ITE_IFTHEN_DL:![0-9]+]]
11; CHECK:  if.else:
12; CHECK:    br label %Flow, !dbg [[ITE_IFELSE_DL:![0-9]+]]
13; CHECK:  exit:
14;
15entry:
16  br i1 %arg, label %if.then, label %if.else, !dbg !8
17
18if.then:
19  store i32 0, ptr addrspace(1) %out, !dbg !9
20  br label %exit, !dbg !10
21
22if.else:
23  store i32 1, ptr addrspace(1) %out, !dbg !11
24  br label %exit, !dbg !12
25
26exit:
27  ret void, !dbg !13
28}
29
30define void @while_loop(ptr addrspace(1) %out) !dbg !14 {
31; CHECK: @while_loop(
32; CHECK:  entry:
33; CHECK:    br label %while.header, !dbg [[WHILE_ENTRY_DL:![0-9]+]]
34; CHECK:  while.header:
35; CHECK:    br i1 {{.*}}, label %while.body, label %Flow, !dbg [[WHILE_HEADER_DL:![0-9]+]]
36; CHECK:  while.body:
37; CHECK:    br label %Flow, !dbg [[WHILE_BODY_DL:![0-9]+]]
38; CHECK:  Flow:
39; CHECK:    br i1 {{.*}}, label %exit, label %while.header, !dbg [[WHILE_HEADER_DL]]
40; CHECK:  exit:
41;
42entry:
43  br label %while.header, !dbg !15
44
45while.header:
46  %cond = call i1 @loop_condition(), !dbg !16
47  br i1 %cond, label %while.body, label %exit, !dbg !17
48
49while.body:
50  store i32 1, ptr addrspace(1) %out, !dbg !18
51  br label %while.header, !dbg !19
52
53exit:
54  ret void, !dbg !20
55}
56
57define void @while_multiple_exits(ptr addrspace(1) %out) !dbg !21 {
58; CHECK: @while_multiple_exits(
59; CHECK:  entry:
60; CHECK:    br label %while.header, !dbg [[WHILEME_ENTRY_DL:![0-9]+]]
61; CHECK:  while.header:
62; CHECK:    br i1 {{.*}}, label %while.exiting, label %Flow, !dbg [[WHILEME_HEADER_DL:![0-9]+]]
63; CHECK:  while.exiting:
64; CHECK:    br label %Flow, !dbg [[WHILEME_EXITING_DL:![0-9]+]]
65; CHECK:  Flow:
66; CHECK:    br i1 {{.*}}, label %exit, label %while.header, !dbg [[WHILEME_HEADER_DL]]
67; CHECK:  exit:
68;
69entry:
70  br label %while.header, !dbg !22
71
72while.header:
73  %cond0 = call i1 @loop_condition(), !dbg !23
74  br i1 %cond0, label %while.exiting, label %exit, !dbg !24
75
76while.exiting:
77  %cond1 = call i1 @loop_condition(), !dbg !25
78  br i1 %cond1, label %while.header, label %exit, !dbg !26
79
80exit:
81  ret void, !dbg !27
82}
83
84define void @nested_if_then_else(ptr addrspace(1) %out, i1 %a, i1 %b) !dbg !28 {
85; CHECK: @nested_if_then_else(
86; CHECK:  entry:
87; CHECK:    br i1 {{.*}}, label %if.else, label %Flow4, !dbg [[NESTED_ENTRY_DL:![0-9]+]]
88; CHECK:  Flow4:
89; CHECK:    br i1 {{.*}}, label %if.then, label %exit, !dbg [[NESTED_ENTRY_DL]]
90; CHECK:  if.then:
91; CHECK:    br i1 {{.*}}, label %if.then.else, label %Flow2, !dbg [[NESTED_IFTHEN_DL:![0-9]+]]
92; CHECK:  Flow2:
93; CHECK:    br i1 {{.*}}, label %if.then.then, label %Flow3, !dbg [[NESTED_IFTHEN_DL]]
94; CHECK:  if.then.then:
95; CHECK:    br label %Flow3, !dbg [[NESTED_IFTHENTHEN_DL:![0-9]+]]
96; CHECK:  if.then.else:
97; CHECK:    br label %Flow2, !dbg [[NESTED_IFTHENELSE_DL:![0-9]+]]
98; CHECK:  if.else:
99; CHECK:    br i1 {{.*}}, label %if.else.else, label %Flow, !dbg [[NESTED_IFELSE_DL:![0-9]+]]
100; CHECK:  Flow:
101; CHECK:    br i1 {{.*}}, label %if.else.then, label %Flow1, !dbg [[NESTED_IFELSE_DL]]
102; CHECK:  if.else.then:
103; CHECK:    br label %Flow1, !dbg [[NESTED_IFELSETHEN_DL:![0-9]+]]
104; CHECK:  if.else.else:
105; CHECK:    br label %Flow, !dbg [[NESTED_IFELSEELSE_DL:![0-9]+]]
106; CHECK:  Flow1:
107; CHECK:    br label %Flow4, !dbg [[NESTED_IFELSE_DL]]
108; CHECK:  Flow3:
109; CHECK:    br label %exit, !dbg [[NESTED_IFTHEN_DL]]
110; CHECK:  exit:
111;
112entry:
113  br i1 %a, label %if.then, label %if.else, !dbg !29
114
115if.then:
116  br i1 %b, label %if.then.then, label %if.then.else, !dbg !30
117
118if.then.then:
119  store i32 0, ptr addrspace(1) %out, !dbg !31
120  br label %exit, !dbg !32
121
122if.then.else:
123  store i32 1, ptr addrspace(1) %out, !dbg !33
124  br label %exit, !dbg !34
125
126if.else:
127  br i1 %b, label %if.else.then, label %if.else.else, !dbg !35
128
129if.else.then:
130  store i32 2, ptr addrspace(1) %out, !dbg !36
131  br label %exit, !dbg !37
132
133if.else.else:
134  store i32 3, ptr addrspace(1) %out, !dbg !38
135  br label %exit, !dbg !39
136
137exit:
138  ret void, !dbg !40
139}
140
141declare i1 @loop_condition()
142
143!llvm.dbg.cu = !{!2}
144!llvm.module.flags = !{!4, !5}
145
146; CHECK: [[ITE_ENTRY_DL]] = !DILocation(line: 2
147; CHECK: [[ITE_IFTHEN_DL]] = !DILocation(line: 4
148; CHECK: [[ITE_IFELSE_DL]] = !DILocation(line: 6
149; CHECK: [[WHILE_ENTRY_DL]] = !DILocation(line: 2
150; CHECK: [[WHILE_HEADER_DL]] = !DILocation(line: 4
151; CHECK: [[WHILE_BODY_DL]] = !DILocation(line: 6
152; CHECK: [[WHILEME_ENTRY_DL]] = !DILocation(line: 2
153; CHECK: [[WHILEME_HEADER_DL]] = !DILocation(line: 4
154; CHECK: [[WHILEME_EXITING_DL]] = !DILocation(line: 6
155; CHECK: [[NESTED_ENTRY_DL]] = !DILocation(line: 2
156; CHECK: [[NESTED_IFTHEN_DL]] = !DILocation(line: 3
157; CHECK: [[NESTED_IFTHENTHEN_DL]] = !DILocation(line: 5
158; CHECK: [[NESTED_IFTHENELSE_DL]] = !DILocation(line: 7
159; CHECK: [[NESTED_IFELSE_DL]] = !DILocation(line: 8
160; CHECK: [[NESTED_IFELSETHEN_DL]] = !DILocation(line: 10
161; CHECK: [[NESTED_IFELSEELSE_DL]] = !DILocation(line: 12
162
163!0 = !{}
164!1 = !DIFile(filename: "dummy.ll", directory: "/some/random/directory")
165!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !0)
166!4 = !{i32 2, !"Dwarf Version", i32 5}
167!5 = !{i32 2, !"Debug Info Version", i32 3}
168!6 = !DISubroutineType(types: !0)
169!7 = distinct !DISubprogram(name: "dummy", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !2, retainedNodes: !0)
170!8 = !DILocation(line: 2, scope: !7)
171!9 = !DILocation(line: 3, scope: !7)
172!10 = !DILocation(line: 4, scope: !7)
173!11 = !DILocation(line: 5, scope: !7)
174!12 = !DILocation(line: 6, scope: !7)
175!13 = !DILocation(line: 7, scope: !7)
176!14 = distinct !DISubprogram(name: "dummy", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !2, retainedNodes: !0)
177!15 = !DILocation(line: 2, scope: !14)
178!16 = !DILocation(line: 3, scope: !14)
179!17 = !DILocation(line: 4, scope: !14)
180!18 = !DILocation(line: 5, scope: !14)
181!19 = !DILocation(line: 6, scope: !14)
182!20 = !DILocation(line: 7, scope: !14)
183!21 = distinct !DISubprogram(name: "dummy", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !2, retainedNodes: !0)
184!22 = !DILocation(line: 2, scope: !21)
185!23 = !DILocation(line: 3, scope: !21)
186!24 = !DILocation(line: 4, scope: !21)
187!25 = !DILocation(line: 5, scope: !21)
188!26 = !DILocation(line: 6, scope: !21)
189!27 = !DILocation(line: 7, scope: !21)
190!28 = distinct !DISubprogram(name: "dummy", scope: !1, file: !1, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !2, retainedNodes: !0)
191!29 = !DILocation(line: 2, scope: !28)
192!30 = !DILocation(line: 3, scope: !28)
193!31 = !DILocation(line: 4, scope: !28)
194!32 = !DILocation(line: 5, scope: !28)
195!33 = !DILocation(line: 6, scope: !28)
196!34 = !DILocation(line: 7, scope: !28)
197!35 = !DILocation(line: 8, scope: !28)
198!36 = !DILocation(line: 9, scope: !28)
199!37 = !DILocation(line: 10, scope: !28)
200!38 = !DILocation(line: 11, scope: !28)
201!39 = !DILocation(line: 12, scope: !28)
202!40 = !DILocation(line: 13, scope: !28)
203