llvm.org GIT mirror llvm / 3ca5091
[unittests] Make some parseIR calls more readable, NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326620 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 2 years ago
1 changed file(s) with 140 addition(s) and 146 deletion(s). Raw diff Collapse all Expand all
112112
113113 // Original C source to get debug info for a local variable:
114114 // void f() { int x; }
115 std::unique_ptr M = parseIR(
116 C,
117 "define void @f() !dbg !8 {\n"
118 "entry:\n"
119 " %x = alloca i32, align 4\n"
120 " call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata "
121 "!DIExpression()), !dbg !13\n"
122 " call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata "
123 "!DIExpression()), !dbg !13\n"
124 " ret void, !dbg !14\n"
125 "}\n"
126 "declare void @llvm.dbg.declare(metadata, metadata, metadata)\n"
127 "!llvm.dbg.cu = !{!0}\n"
128 "!llvm.module.flags = !{!3, !4}\n"
129 "!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "
130 "\"clang version 6.0.0 \", isOptimized: false, runtimeVersion: 0, "
131 "emissionKind: FullDebug, enums: !2)\n"
132 "!1 = !DIFile(filename: \"t2.c\", directory: \"foo\")\n"
133 "!2 = !{}\n"
134 "!3 = !{i32 2, !\"Dwarf Version\", i32 4}\n"
135 "!4 = !{i32 2, !\"Debug Info Version\", i32 3}\n"
136 "!8 = distinct !DISubprogram(name: \"f\", scope: !1, file: !1, line: 1, "
137 "type: !9, isLocal: false, isDefinition: true, scopeLine: 1, "
138 "isOptimized: false, unit: !0, variables: !2)\n"
139 "!9 = !DISubroutineType(types: !10)\n"
140 "!10 = !{null}\n"
141 "!11 = !DILocalVariable(name: \"x\", scope: !8, file: !1, line: 2, type: "
142 "!12)\n"
143 "!12 = !DIBasicType(name: \"int\", size: 32, encoding: DW_ATE_signed)\n"
144 "!13 = !DILocation(line: 2, column: 7, scope: !8)\n"
145 "!14 = !DILocation(line: 3, column: 1, scope: !8)\n");
115 std::unique_ptr M = parseIR(C,
116 R"(
117 define void @f() !dbg !8 {
118 entry:
119 %x = alloca i32, align 4
120 call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata !DIExpression()), !dbg !13
121 call void @llvm.dbg.declare(metadata i32* %x, metadata !11, metadata !DIExpression()), !dbg !13
122 ret void, !dbg !14
123 }
124 declare void @llvm.dbg.declare(metadata, metadata, metadata)
125 !llvm.dbg.cu = !{!0}
126 !llvm.module.flags = !{!3, !4}
127 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
128 !1 = !DIFile(filename: "t2.c", directory: "foo")
129 !2 = !{}
130 !3 = !{i32 2, !"Dwarf Version", i32 4}
131 !4 = !{i32 2, !"Debug Info Version", i32 3}
132 !8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !9, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, variables: !2)
133 !9 = !DISubroutineType(types: !10)
134 !10 = !{null}
135 !11 = !DILocalVariable(name: "x", scope: !8, file: !1, line: 2, type: !12)
136 !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
137 !13 = !DILocation(line: 2, column: 7, scope: !8)
138 !14 = !DILocation(line: 3, column: 1, scope: !8)
139 )");
146140 auto *GV = M->getNamedValue("f");
147141 ASSERT_TRUE(GV);
148142 auto *F = dyn_cast(GV);
181175 TEST(Local, MergeBasicBlockIntoOnlyPred) {
182176 LLVMContext C;
183177
184 std::unique_ptr M = parseIR(
185 C,
186 "define i32 @f(i8* %str) {\n"
187 "entry:\n"
188 " br label %bb2.i\n"
189 "bb2.i: ; preds = %bb4.i, %entry\n"
190 " br i1 false, label %bb4.i, label %base2flt.exit204\n"
191 "bb4.i: ; preds = %bb2.i\n"
192 " br i1 false, label %base2flt.exit204, label %bb2.i\n"
193 "bb10.i196.bb7.i197_crit_edge: ; No predecessors!\n"
194 " br label %bb7.i197\n"
195 "bb7.i197: ; preds = %bb10.i196.bb7.i197_crit_edge\n"
196 " %.reg2mem.0 = phi i32 [ %.reg2mem.0, %bb10.i196.bb7.i197_crit_edge ]\n"
197 " br i1 undef, label %base2flt.exit204, label %base2flt.exit204\n"
198 "base2flt.exit204: ; preds = %bb7.i197, %bb7.i197, %bb2.i, %bb4.i\n"
199 " ret i32 0\n"
200 "}\n");
178 std::unique_ptr M = parseIR(C,
179 R"(
180 define i32 @f(i8* %str) {
181 entry:
182 br label %bb2.i
183 bb2.i: ; preds = %bb4.i, %entry
184 br i1 false, label %bb4.i, label %base2flt.exit204
185 bb4.i: ; preds = %bb2.i
186 br i1 false, label %base2flt.exit204, label %bb2.i
187 bb10.i196.bb7.i197_crit_edge: ; No predecessors!
188 br label %bb7.i197
189 bb7.i197: ; preds = %bb10.i196.bb7.i197_crit_edge
190 %.reg2mem.0 = phi i32 [ %.reg2mem.0, %bb10.i196.bb7.i197_crit_edge ]
191 br i1 undef, label %base2flt.exit204, label %base2flt.exit204
192 base2flt.exit204: ; preds = %bb7.i197, %bb7.i197, %bb2.i, %bb4.i
193 ret i32 0
194 }
195 )");
201196 runWithDomTree(
202197 *M, "f", [&](Function &F, DominatorTree *DT) {
203198 for (Function::iterator I = F.begin(), E = F.end(); I != E;) {
215210 TEST(Local, ConstantFoldTerminator) {
216211 LLVMContext C;
217212
218 std::unique_ptr M = parseIR(
219 C,
220 "define void @br_same_dest() {\n"
221 "entry:\n"
222 " br i1 false, label %bb0, label %bb0\n"
223 "bb0:\n"
224 " ret void\n"
225 "}\n"
226 "\n"
227 "define void @br_different_dest() {\n"
228 "entry:\n"
229 " br i1 true, label %bb0, label %bb1\n"
230 "bb0:\n"
231 " br label %exit\n"
232 "bb1:\n"
233 " br label %exit\n"
234 "exit:\n"
235 " ret void\n"
236 "}\n"
237 "\n"
238 "define void @switch_2_different_dest() {\n"
239 "entry:\n"
240 " switch i32 0, label %default [ i32 0, label %bb0 ]\n"
241 "default:\n"
242 " ret void\n"
243 "bb0:\n"
244 " ret void\n"
245 "}\n"
246 "define void @switch_2_different_dest_default() {\n"
247 "entry:\n"
248 " switch i32 1, label %default [ i32 0, label %bb0 ]\n"
249 "default:\n"
250 " ret void\n"
251 "bb0:\n"
252 " ret void\n"
253 "}\n"
254 "define void @switch_3_different_dest() {\n"
255 "entry:\n"
256 " switch i32 0, label %default [ i32 0, label %bb0\n"
257 " i32 1, label %bb1 ]\n"
258 "default:\n"
259 " ret void\n"
260 "bb0:\n"
261 " ret void\n"
262 "bb1:\n"
263 " ret void\n"
264 "}\n"
265 "\n"
266 "define void @switch_variable_2_default_dest(i32 %arg) {\n"
267 "entry:\n"
268 " switch i32 %arg, label %default [ i32 0, label %default ]\n"
269 "default:\n"
270 " ret void\n"
271 "}\n"
272 "\n"
273 "define void @switch_constant_2_default_dest() {\n"
274 "entry:\n"
275 " switch i32 1, label %default [ i32 0, label %default ]\n"
276 "default:\n"
277 " ret void\n"
278 "}\n"
279 "\n"
280 "define void @switch_constant_3_repeated_dest() {\n"
281 "entry:\n"
282 " switch i32 0, label %default [ i32 0, label %bb0\n"
283 " i32 1, label %bb0 ]\n"
284 " bb0:\n"
285 " ret void\n"
286 "default:\n"
287 " ret void\n"
288 "}\n"
289 "\n"
290 "define void @indirectbr() {\n"
291 "entry:\n"
292 " indirectbr i8* blockaddress(@indirectbr, %bb0), [label %bb0, label %bb1]\n"
293 "bb0:\n"
294 " ret void\n"
295 "bb1:\n"
296 " ret void\n"
297 "}\n"
298 "\n"
299 "define void @indirectbr_repeated() {\n"
300 "entry:\n"
301 " indirectbr i8* blockaddress(@indirectbr_repeated, %bb0), [label %bb0, label %bb0]\n"
302 "bb0:\n"
303 " ret void\n"
304 "}\n"
305 "\n"
306 "define void @indirectbr_unreachable() {\n"
307 "entry:\n"
308 " indirectbr i8* blockaddress(@indirectbr_unreachable, %bb0), [label %bb1]\n"
309 "bb0:\n"
310 " ret void\n"
311 "bb1:\n"
312 " ret void\n"
313 "}\n"
314 "\n"
315 );
213 std::unique_ptr M = parseIR(C,
214 R"(
215 define void @br_same_dest() {
216 entry:
217 br i1 false, label %bb0, label %bb0
218 bb0:
219 ret void
220 }
221
222 define void @br_different_dest() {
223 entry:
224 br i1 true, label %bb0, label %bb1
225 bb0:
226 br label %exit
227 bb1:
228 br label %exit
229 exit:
230 ret void
231 }
232
233 define void @switch_2_different_dest() {
234 entry:
235 switch i32 0, label %default [ i32 0, label %bb0 ]
236 default:
237 ret void
238 bb0:
239 ret void
240 }
241 define void @switch_2_different_dest_default() {
242 entry:
243 switch i32 1, label %default [ i32 0, label %bb0 ]
244 default:
245 ret void
246 bb0:
247 ret void
248 }
249 define void @switch_3_different_dest() {
250 entry:
251 switch i32 0, label %default [ i32 0, label %bb0
252 i32 1, label %bb1 ]
253 default:
254 ret void
255 bb0:
256 ret void
257 bb1:
258 ret void
259 }
260
261 define void @switch_variable_2_default_dest(i32 %arg) {
262 entry:
263 switch i32 %arg, label %default [ i32 0, label %default ]
264 default:
265 ret void
266 }
267
268 define void @switch_constant_2_default_dest() {
269 entry:
270 switch i32 1, label %default [ i32 0, label %default ]
271 default:
272 ret void
273 }
274
275 define void @switch_constant_3_repeated_dest() {
276 entry:
277 switch i32 0, label %default [ i32 0, label %bb0
278 i32 1, label %bb0 ]
279 bb0:
280 ret void
281 default:
282 ret void
283 }
284
285 define void @indirectbr() {
286 entry:
287 indirectbr i8* blockaddress(@indirectbr, %bb0), [label %bb0, label %bb1]
288 bb0:
289 ret void
290 bb1:
291 ret void
292 }
293
294 define void @indirectbr_repeated() {
295 entry:
296 indirectbr i8* blockaddress(@indirectbr_repeated, %bb0), [label %bb0, label %bb0]
297 bb0:
298 ret void
299 }
300
301 define void @indirectbr_unreachable() {
302 entry:
303 indirectbr i8* blockaddress(@indirectbr_unreachable, %bb0), [label %bb1]
304 bb0:
305 ret void
306 bb1:
307 ret void
308 }
309 )");
316310
317311 auto CFAllTerminators = [&](Function &F, DominatorTree *DT) {
318312 DeferredDominance DDT(*DT);