llvm.org GIT mirror llvm / a931186
[Utils] Salvage debug info in block simplification In stage2 -O3 builds of llc, this results in small but measurable increases in the number of variables with locations, and in the number of unique source variables overall. (According to llvm-dwarfdump --statistics, there are 123 additional variables with locations, which is just a 0.006% improvement). The size of the .debug_loc section of the llc dsym increases by 0.004%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@326629 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 2 years ago
2 changed file(s) with 71 addition(s) and 32 deletion(s). Raw diff Collapse all Expand all
503503 const DataLayout &DL,
504504 const TargetLibraryInfo *TLI) {
505505 if (isInstructionTriviallyDead(I, TLI)) {
506 salvageDebugInfo(*I);
507
506508 // Null out all of the instruction's operands to see if any operand becomes
507509 // dead as we go.
508510 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i) {
331331 runWithDomTree(*M, "indirectbr_unreachable", CFAllTerminators);
332332 }
333333
334 TEST(Local, SalvageDebugValuesInRecursiveInstDeletion) {
335 LLVMContext C;
336
337 std::unique_ptr M = parseIR(C,
338 R"(
334 struct SalvageDebugInfoTest : ::testing::Test {
335 LLVMContext C;
336 std::unique_ptr M;
337 Function *F = nullptr;
338
339 void SetUp() {
340 M = parseIR(C,
341 R"(
339342 define void @f() !dbg !8 {
340343 entry:
341344 %x = add i32 0, 1
360363 !13 = !DILocation(line: 2, column: 7, scope: !8)
361364 !14 = !DILocation(line: 3, column: 1, scope: !8)
362365 )");
363 auto *GV = M->getNamedValue("f");
364 ASSERT_TRUE(GV);
365 auto *F = dyn_cast(GV);
366 ASSERT_TRUE(F);
366
367 auto *GV = M->getNamedValue("f");
368 ASSERT_TRUE(GV);
369 F = dyn_cast(GV);
370 ASSERT_TRUE(F);
371 }
372
373 bool doesDebugValueDescribeX(const DbgValueInst &DI) {
374 const auto &CI = *cast(DI.getValue());
375 if (CI.isZero())
376 return DI.getExpression()->getElements().equals(
377 {dwarf::DW_OP_plus_uconst, 1, dwarf::DW_OP_stack_value});
378 else if (CI.isOneValue())
379 return DI.getExpression()->getElements().empty();
380 return false;
381 }
382
383 bool doesDebugValueDescribeY(const DbgValueInst &DI) {
384 const auto &CI = *cast(DI.getValue());
385 if (CI.isZero())
386 return DI.getExpression()->getElements().equals(
387 {dwarf::DW_OP_plus_uconst, 1, dwarf::DW_OP_plus_uconst, 2,
388 dwarf::DW_OP_stack_value});
389 else if (CI.isOneValue())
390 return DI.getExpression()->getElements().equals(
391 {dwarf::DW_OP_plus_uconst, 2, dwarf::DW_OP_stack_value});
392 return false;
393 }
394
395 void verifyDebugValuesAreSalvaged() {
396 // Check that the debug values for %x and %y are preserved.
397 bool FoundX = false;
398 bool FoundY = false;
399 for (const Instruction &I : F->front()) {
400 auto DI = dyn_cast(&I);
401 if (!DI) {
402 // The function should only contain debug values and a terminator.
403 ASSERT_TRUE(isa(&I));
404 continue;
405 }
406 EXPECT_EQ(DI->getVariable()->getName(), "x");
407 FoundX |= doesDebugValueDescribeX(*DI);
408 FoundY |= doesDebugValueDescribeY(*DI);
409 }
410 ASSERT_TRUE(FoundX);
411 ASSERT_TRUE(FoundY);
412 }
413 };
414
415 TEST_F(SalvageDebugInfoTest, RecursiveInstDeletion) {
367416 Instruction *Inst = &F->front().front();
368 Inst = Inst->getNextNode();
417 Inst = Inst->getNextNode(); // Get %y = add ...
369418 ASSERT_TRUE(Inst);
370419 bool Deleted = RecursivelyDeleteTriviallyDeadInstructions(Inst);
371420 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 }
421 verifyDebugValuesAreSalvaged();
422 }
423
424 TEST_F(SalvageDebugInfoTest, RecursiveBlockSimplification) {
425 BasicBlock *BB = &F->front();
426 ASSERT_TRUE(BB);
427 bool Deleted = SimplifyInstructionsInBlock(BB);
428 ASSERT_TRUE(Deleted);
429 verifyDebugValuesAreSalvaged();
430 }