diff options
author | Vedant Kumar <vsk@apple.com> | 2018-03-02 21:36:35 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-03-02 21:36:35 +0000 |
commit | 40131a7149e661460396300caa090768e019023c (patch) | |
tree | 1993bfbac8e9eaa0941a62f2cfaee172dfa4861c /unittests/Transforms/Utils | |
parent | 3ca5091556a3059a9239d7e34aeccb195c3dade9 (diff) |
[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
Diffstat (limited to 'unittests/Transforms/Utils')
-rw-r--r-- | unittests/Transforms/Utils/Local.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/unittests/Transforms/Utils/Local.cpp b/unittests/Transforms/Utils/Local.cpp index 2343c46057e..679a7a3c3ff 100644 --- a/unittests/Transforms/Utils/Local.cpp +++ b/unittests/Transforms/Utils/Local.cpp @@ -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); +} |