[llvm] r326621 - [Utils] Salvage debug info in recursive inst deletion
Vedant Kumar via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 2 13:36:35 PST 2018
Author: vedantk
Date: Fri Mar 2 13:36:35 2018
New Revision: 326621
URL: http://llvm.org/viewvc/llvm-project?rev=326621&view=rev
Log:
[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%.
Modified:
llvm/trunk/lib/Transforms/Utils/Local.cpp
llvm/trunk/unittests/Transforms/Utils/Local.cpp
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=326621&r1=326620&r2=326621&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Fri Mar 2 13:36:35 2018
@@ -431,6 +431,7 @@ llvm::RecursivelyDeleteTriviallyDeadInst
do {
I = DeadInsts.pop_back_val();
+ salvageDebugInfo(*I);
// Null out all of the instruction's operands to see if any operand becomes
// dead as we go.
Modified: llvm/trunk/unittests/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Transforms/Utils/Local.cpp?rev=326621&r1=326620&r2=326621&view=diff
==============================================================================
--- llvm/trunk/unittests/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/unittests/Transforms/Utils/Local.cpp Fri Mar 2 13:36:35 2018
@@ -331,3 +331,64 @@ TEST(Local, ConstantFoldTerminator) {
runWithDomTree(*M, "indirectbr_repeated", CFAllTerminators);
runWithDomTree(*M, "indirectbr_unreachable", CFAllTerminators);
}
+
+TEST(Local, SalvageDebugValuesInRecursiveInstDeletion) {
+ LLVMContext C;
+
+ std::unique_ptr<Module> M = parseIR(C,
+ R"(
+ define void @f() !dbg !8 {
+ entry:
+ %x = add i32 0, 1
+ %y = add i32 %x, 2
+ call void @llvm.dbg.value(metadata i32 %x, metadata !11, metadata !DIExpression()), !dbg !13
+ call void @llvm.dbg.value(metadata i32 %y, metadata !11, metadata !DIExpression()), !dbg !13
+ ret void, !dbg !14
+ }
+ declare void @llvm.dbg.value(metadata, metadata, metadata)
+ !llvm.dbg.cu = !{!0}
+ !llvm.module.flags = !{!3, !4}
+ !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+ !1 = !DIFile(filename: "t2.c", directory: "foo")
+ !2 = !{}
+ !3 = !{i32 2, !"Dwarf Version", i32 4}
+ !4 = !{i32 2, !"Debug Info Version", i32 3}
+ !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)
+ !9 = !DISubroutineType(types: !10)
+ !10 = !{null}
+ !11 = !DILocalVariable(name: "x", scope: !8, file: !1, line: 2, type: !12)
+ !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+ !13 = !DILocation(line: 2, column: 7, scope: !8)
+ !14 = !DILocation(line: 3, column: 1, scope: !8)
+ )");
+ auto *GV = M->getNamedValue("f");
+ ASSERT_TRUE(GV);
+ auto *F = dyn_cast<Function>(GV);
+ ASSERT_TRUE(F);
+ Instruction *Inst = &F->front().front();
+ Inst = Inst->getNextNode();
+ ASSERT_TRUE(Inst);
+ bool Deleted = RecursivelyDeleteTriviallyDeadInstructions(Inst);
+ ASSERT_TRUE(Deleted);
+
+ // The debug values should have been salvaged.
+ bool FoundX = false;
+ bool FoundY = false;
+ uint64_t X_expr[] = {dwarf::DW_OP_plus_uconst, 1, dwarf::DW_OP_stack_value};
+ uint64_t Y_expr[] = {dwarf::DW_OP_plus_uconst, 1, dwarf::DW_OP_plus_uconst, 2,
+ dwarf::DW_OP_stack_value};
+ for (const Instruction &I : F->front()) {
+ auto DI = dyn_cast<DbgValueInst>(&I);
+ if (!DI)
+ continue;
+ EXPECT_EQ(DI->getVariable()->getName(), "x");
+ ASSERT_TRUE(cast<ConstantInt>(DI->getValue())->isZero());
+ ArrayRef<uint64_t> ExprElts = DI->getExpression()->getElements();
+ if (ExprElts.equals(X_expr))
+ FoundX = true;
+ else if (ExprElts.equals(Y_expr))
+ FoundY = true;
+ }
+ ASSERT_TRUE(FoundX);
+ ASSERT_TRUE(FoundY);
+}
More information about the llvm-commits
mailing list