llvm.org GIT mirror llvm / 40131a7
[Utils] Salvage debug info in recursive inst deletion In stage2 -O3 builds of llc, this results in a 0.3% increase in the number of variables with locations, and a 0.2% increase in the number of unique source variables overall. The size of the .debug_loc section of the llc dsym increases by 0.5%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326621 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 2 years ago
2 changed file(s) with 62 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
430430
431431 do {
432432 I = DeadInsts.pop_back_val();
433 salvageDebugInfo(*I);
433434
434435 // Null out all of the instruction's operands to see if any operand becomes
435436 // dead as we go.
330330 runWithDomTree(*M, "indirectbr_repeated", CFAllTerminators);
331331 runWithDomTree(*M, "indirectbr_unreachable", CFAllTerminators);
332332 }
333
334 TEST(Local, SalvageDebugValuesInRecursiveInstDeletion) {
335 LLVMContext C;
336
337 std::unique_ptr M = parseIR(C,
338 R"(
339 define void @f() !dbg !8 {
340 entry:
341 %x = add i32 0, 1
342 %y = add i32 %x, 2
343 call void @llvm.dbg.value(metadata i32 %x, metadata !11, metadata !DIExpression()), !dbg !13
344 call void @llvm.dbg.value(metadata i32 %y, metadata !11, metadata !DIExpression()), !dbg !13
345 ret void, !dbg !14
346 }
347 declare void @llvm.dbg.value(metadata, metadata, metadata)
348 !llvm.dbg.cu = !{!0}
349 !llvm.module.flags = !{!3, !4}
350 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
351 !1 = !DIFile(filename: "t2.c", directory: "foo")
352 !2 = !{}
353 !3 = !{i32 2, !"Dwarf Version", i32 4}
354 !4 = !{i32 2, !"Debug Info Version", i32 3}
355 !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)
356 !9 = !DISubroutineType(types: !10)
357 !10 = !{null}
358 !11 = !DILocalVariable(name: "x", scope: !8, file: !1, line: 2, type: !12)
359 !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
360 !13 = !DILocation(line: 2, column: 7, scope: !8)
361 !14 = !DILocation(line: 3, column: 1, scope: !8)
362 )");
363 auto *GV = M->getNamedValue("f");
364 ASSERT_TRUE(GV);
365 auto *F = dyn_cast(GV);
366 ASSERT_TRUE(F);
367 Instruction *Inst = &F->front().front();
368 Inst = Inst->getNextNode();
369 ASSERT_TRUE(Inst);
370 bool Deleted = RecursivelyDeleteTriviallyDeadInstructions(Inst);
371 ASSERT_TRUE(Deleted);
372
373 // The debug values should have been salvaged.
374 bool FoundX = false;
375 bool FoundY = false;
376 uint64_t X_expr[] = {dwarf::DW_OP_plus_uconst, 1, dwarf::DW_OP_stack_value};
377 uint64_t Y_expr[] = {dwarf::DW_OP_plus_uconst, 1, dwarf::DW_OP_plus_uconst, 2,
378 dwarf::DW_OP_stack_value};
379 for (const Instruction &I : F->front()) {
380 auto DI = dyn_cast(&I);
381 if (!DI)
382 continue;
383 EXPECT_EQ(DI->getVariable()->getName(), "x");
384 ASSERT_TRUE(cast(DI->getValue())->isZero());
385 ArrayRef ExprElts = DI->getExpression()->getElements();
386 if (ExprElts.equals(X_expr))
387 FoundX = true;
388 else if (ExprElts.equals(Y_expr))
389 FoundY = true;
390 }
391 ASSERT_TRUE(FoundX);
392 ASSERT_TRUE(FoundY);
393 }