diff options
author | Vedant Kumar <vsk@apple.com> | 2018-02-09 19:19:55 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-02-09 19:19:55 +0000 |
commit | 04386d8e3de6c9fe79d0f911841ff94368bd61cc (patch) | |
tree | b2a5d6cbcfc7acb0dcd25730e737ea7177d1ea9f /llvm/lib | |
parent | 9b48e8d233e9013dc6a38e628350c6d76c46a58a (diff) | |
download | bcm5719-llvm-04386d8e3de6c9fe79d0f911841ff94368bd61cc.tar.gz bcm5719-llvm-04386d8e3de6c9fe79d0f911841ff94368bd61cc.zip |
[Utils] Salvage debug info from dead 'or' instructions
Extend salvageDebugInfo to preserve the debug info from a dead 'or'
with a constant.
Patch by Ismail Badawi!
Differential Revision: https://reviews.llvm.org/D43129
llvm-svn: 324764
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/IR/DebugInfoMetadata.cpp | 7 | ||||
-rw-r--r-- | llvm/lib/Transforms/Utils/Local.cpp | 31 |
3 files changed, 32 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp index 68d25fe37b4..ec9340ce75c 100644 --- a/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp @@ -341,6 +341,7 @@ void DwarfExpression::addExpression(DIExpressionCursor &&ExprCursor, case dwarf::DW_OP_plus: case dwarf::DW_OP_minus: case dwarf::DW_OP_mul: + case dwarf::DW_OP_or: emitOp(Op->getOp()); break; case dwarf::DW_OP_deref: diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp index db097e1487d..c44bc75e02c 100644 --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -706,6 +706,7 @@ bool DIExpression::isValid() const { case dwarf::DW_OP_plus: case dwarf::DW_OP_minus: case dwarf::DW_OP_mul: + case dwarf::DW_OP_or: case dwarf::DW_OP_deref: case dwarf::DW_OP_xderef: break; @@ -772,6 +773,12 @@ DIExpression *DIExpression::prepend(const DIExpression *Expr, bool DerefBefore, if (DerefAfter) Ops.push_back(dwarf::DW_OP_deref); + return doPrepend(Expr, Ops, StackValue); +} + +DIExpression *DIExpression::doPrepend(const DIExpression *Expr, + SmallVectorImpl<uint64_t> &Ops, + bool StackValue) { if (Expr) for (auto Op : Expr->expr_ops()) { // A DW_OP_stack_value comes at the end, but before a DW_OP_LLVM_fragment. diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp index 337ee0e9ef5..39169f931b7 100644 --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1497,16 +1497,27 @@ void llvm::salvageDebugInfo(Instruction &I) { return MetadataAsValue::get(I.getContext(), ValueAsMetadata::get(V)); }; - auto applyOffset = [&](DbgInfoIntrinsic *DII, uint64_t Offset) { + auto doSalvage = [&](DbgInfoIntrinsic *DII, SmallVectorImpl<uint64_t> &Ops) { auto *DIExpr = DII->getExpression(); - DIExpr = DIExpression::prepend(DIExpr, DIExpression::NoDeref, Offset, - DIExpression::NoDeref, - DIExpression::WithStackValue); + DIExpr = DIExpression::doPrepend(DIExpr, Ops, + DIExpression::WithStackValue); DII->setOperand(0, wrapMD(I.getOperand(0))); DII->setOperand(2, MetadataAsValue::get(I.getContext(), DIExpr)); DEBUG(dbgs() << "SALVAGE: " << *DII << '\n'); }; + auto applyOffset = [&](DbgInfoIntrinsic *DII, uint64_t Offset) { + SmallVector<uint64_t, 8> Ops; + DIExpression::appendOffset(Ops, Offset); + doSalvage(DII, Ops); + }; + + auto applyOps = [&](DbgInfoIntrinsic *DII, + std::initializer_list<uint64_t> Opcodes) { + SmallVector<uint64_t, 8> Ops(Opcodes); + doSalvage(DII, Ops); + }; + if (isa<BitCastInst>(&I) || isa<IntToPtrInst>(&I)) { // Bitcasts are entirely irrelevant for debug info. Rewrite dbg.value, // dbg.addr, and dbg.declare to use the cast's source. @@ -1525,11 +1536,17 @@ void llvm::salvageDebugInfo(Instruction &I) { for (auto *DII : DbgUsers) applyOffset(DII, Offset.getSExtValue()); } else if (auto *BI = dyn_cast<BinaryOperator>(&I)) { - if (BI->getOpcode() == Instruction::Add) + if (BI->getOpcode() == Instruction::Add || + BI->getOpcode() == Instruction::Or) if (auto *ConstInt = dyn_cast<ConstantInt>(I.getOperand(1))) - if (ConstInt->getBitWidth() <= 64) + if (ConstInt->getBitWidth() <= 64) { + uint64_t Val = ConstInt->getSExtValue(); for (auto *DII : DbgUsers) - applyOffset(DII, ConstInt->getSExtValue()); + if (BI->getOpcode() == Instruction::Add) + applyOffset(DII, Val); + else if (BI->getOpcode() == Instruction::Or) + applyOps(DII, {dwarf::DW_OP_constu, Val, dwarf::DW_OP_or}); + } } else if (isa<LoadInst>(&I)) { MetadataAsValue *AddrMD = wrapMD(I.getOperand(0)); for (auto *DII : DbgUsers) { |