aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorstozer <stephen.tozer@sony.com>2019-12-05 10:01:47 +0000
committerstozer <stephen.tozer@sony.com>2019-12-10 13:33:32 +0000
commitf2ba93971ccc236c0eef5323704d31f48107e04f (patch)
treec60835aa3767ac116349865d4e847027eb45b644 /llvm/lib/Transforms/Utils/Local.cpp
parent14f3d13412cb2eac87f1c0ae74ed2af7ace1580f (diff)
downloadllvm-f2ba93971ccc236c0eef5323704d31f48107e04f.zip
llvm-f2ba93971ccc236c0eef5323704d31f48107e04f.tar.gz
llvm-f2ba93971ccc236c0eef5323704d31f48107e04f.tar.bz2
Reapply: [DebugInfo] Recover debug intrinsics when killing duplicated/empty...
basic blocks Originally applied in 72ce759928e6dfee6a9efa310b966c19722352ba. Fixed a build failure caused by incorrect use of cast instead of dyn_cast. This reverts commit 8b0780f795eb58fca0a2456e308adaaa1a0b5013.
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 41f1dd9..c9d60ad 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 = dyn_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