aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorstozer <stephen.tozer@sony.com>2019-12-04 09:44:02 +0000
committerstozer <stephen.tozer@sony.com>2019-12-04 16:01:49 +0000
commit72ce759928e6dfee6a9efa310b966c19722352ba (patch)
tree7ca2b21eabffe17458b139055ff7f56bdfc51a85 /llvm/lib/Transforms/Utils/Local.cpp
parentb3b37783034cab31db2d60cf79d0c1c82a8c3419 (diff)
downloadllvm-72ce759928e6dfee6a9efa310b966c19722352ba.zip
llvm-72ce759928e6dfee6a9efa310b966c19722352ba.tar.gz
llvm-72ce759928e6dfee6a9efa310b966c19722352ba.tar.bz2
[DebugInfo] Recover debug intrinsics when killing duplicated/empty basic blocks
When basic blocks are killed, either due to being empty or to being an if.then or if.else block whose complement contains identical instructions, some of the debug intrinsics in that block are lost. This patch sinks those intrinsics into the single successor block, setting them Undef if necessary to prevent debug info from falling out-of-date. Differential Revision: https://reviews.llvm.org/D70318
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index eaccaa1..94edf8c 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -485,15 +485,19 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(
I.eraseFromParent();
}
}
+void llvm::setDbgVariableUndef(DbgVariableIntrinsic *DVI) {
+ Value *DbgValue = DVI->getVariableLocation(false);
+ Value *Undef = UndefValue::get(DbgValue ? DbgValue->getType()
+ : Type::getInt1Ty(DVI->getContext()));
+ DVI->setOperand(
+ 0, MetadataAsValue::get(DVI->getContext(), ValueAsMetadata::get(Undef)));
+}
bool llvm::replaceDbgUsesWithUndef(Instruction *I) {
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
findDbgUsers(DbgUsers, I);
- for (auto *DII : DbgUsers) {
- Value *Undef = UndefValue::get(I->getType());
- DII->setOperand(0, MetadataAsValue::get(DII->getContext(),
- ValueAsMetadata::get(Undef)));
- }
+ for (auto *DII : DbgUsers)
+ setDbgVariableUndef(DII);
return !DbgUsers.empty();
}
@@ -1040,6 +1044,19 @@ bool llvm::TryToSimplifyUncondBranchFromEmptyBlock(BasicBlock *BB,
assert(PN->use_empty() && "There shouldn't be any uses here!");
PN->eraseFromParent();
}
+ // If Succ has multiple predecessors, each debug intrinsic in BB may or may
+ // not be valid when we reach Succ, so the debug variable should be set
+ // undef since its value is unknown.
+ Instruction *DbgInsertPoint = Succ->getFirstNonPHI();
+ while (DbgInfoIntrinsic *DI = dyn_cast<DbgInfoIntrinsic>(&BB->front())) {
+ if (auto DVI = cast<DbgVariableIntrinsic>(DI)) {
+ if (!isa<DbgDeclareInst>(DVI))
+ setDbgVariableUndef(DVI);
+ DVI->moveBefore(DbgInsertPoint);
+ } else {
+ break;
+ }
+ }
}
// If the unconditional branch we replaced contains llvm.loop metadata, we