[DebugInfo] Reduce SalvageDebugInfo() functions

- Now all SalvageDebugInfo() calls will mark undef if the salvage
  attempt fails.

 Reviewed by: vsk, Orlando

 Differential Revision: https://reviews.llvm.org/D78369
This commit is contained in:
Chris Jackson 2020-06-08 18:44:11 +01:00
parent 4615abc11f
commit c6c65164af
10 changed files with 16 additions and 19 deletions

View File

@ -368,13 +368,10 @@ AllocaInst *findAllocaForValue(Value *V,
DenseMap<Value *, AllocaInst *> &AllocaForValue);
/// Assuming the instruction \p I is going to be deleted, attempt to salvage
/// debug users of \p I by writing the effect of \p I in a DIExpression.
/// Returns true if any debug users were updated.
bool salvageDebugInfo(Instruction &I);
/// debug users of \p I by writing the effect of \p I in a DIExpression. If it
/// cannot be salvaged changes its debug uses to undef.
void salvageDebugInfo(Instruction &I);
/// Salvage all debug users of the instruction \p I or mark it as undef if it
/// cannot be salvaged.
void salvageDebugInfoOrMarkUndef(Instruction &I);
/// Implementation of salvageDebugInfo, applying only to instructions in
/// \p Insns, rather than all debug users of \p I.

View File

@ -721,7 +721,7 @@ public:
Instruction *eraseInstFromFunction(Instruction &I) {
LLVM_DEBUG(dbgs() << "IC: ERASE " << I << '\n');
assert(I.use_empty() && "Cannot erase instruction that is used!");
salvageDebugInfoOrMarkUndef(I);
salvageDebugInfo(I);
// Make sure that we reprocess all operands now that we reduced their
// use counts.

View File

@ -88,7 +88,7 @@ bool InstCombiner::SimplifyDemandedBits(Instruction *I, unsigned OpNo,
Depth, I);
if (!NewVal) return false;
if (Instruction* OpInst = dyn_cast<Instruction>(U))
salvageDebugInfoOrMarkUndef(*OpInst);
salvageDebugInfo(*OpInst);
replaceUse(U, NewVal);
return true;

View File

@ -3650,7 +3650,7 @@ static bool prepareICWorklistFromFunction(Function &F, const DataLayout &DL,
if (isInstructionTriviallyDead(Inst, TLI)) {
++NumDeadInst;
LLVM_DEBUG(dbgs() << "IC: DCE: " << *Inst << '\n');
salvageDebugInfoOrMarkUndef(*Inst);
salvageDebugInfo(*Inst);
Inst->eraseFromParent();
MadeIRChange = true;
continue;

View File

@ -102,7 +102,7 @@ static bool bitTrackingDCE(Function &F, DemandedBits &DB) {
(I.getType()->isIntOrIntVectorTy() &&
DB.getDemandedBits(&I).isNullValue() &&
wouldInstructionBeTriviallyDead(&I))) {
salvageDebugInfoOrMarkUndef(I);
salvageDebugInfo(I);
Worklist.push_back(&I);
I.dropAllReferences();
Changed = true;

View File

@ -146,7 +146,7 @@ deleteDeadInstruction(Instruction *I, BasicBlock::iterator *BBI,
++NumFastOther;
// Try to preserve debug information attached to the dead instruction.
salvageDebugInfoOrMarkUndef(*DeadInst);
salvageDebugInfo(*DeadInst);
salvageKnowledge(DeadInst);
// This instruction is dead, zap it, in stages. Start by removing it from

View File

@ -966,7 +966,7 @@ bool EarlyCSE::processNode(DomTreeNode *Node) {
}
salvageKnowledge(&Inst, &AC);
salvageDebugInfoOrMarkUndef(Inst);
salvageDebugInfo(Inst);
removeMSSA(Inst);
Inst.eraseFromParent();
Changed = true;

View File

@ -504,7 +504,7 @@ bool llvm::sinkRegion(DomTreeNode *N, AliasAnalysis *AA, LoopInfo *LI,
if (sink(I, LI, DT, CurLoop, SafetyInfo, MSSAU, ORE)) {
if (!FreeInLoop) {
++II;
salvageDebugInfoOrMarkUndef(I);
salvageDebugInfo(I);
eraseInstruction(I, *SafetyInfo, CurAST, MSSAU);
}
Changed = true;

View File

@ -1903,7 +1903,7 @@ void ReassociatePass::RecursivelyEraseDeadInsts(Instruction *I,
ValueRankMap.erase(I);
Insts.remove(I);
RedoInsts.remove(I);
llvm::salvageDebugInfoOrMarkUndef(*I);
llvm::salvageDebugInfo(*I);
I->eraseFromParent();
for (auto Op : Ops)
if (Instruction *OpInst = dyn_cast<Instruction>(Op))
@ -1920,7 +1920,7 @@ void ReassociatePass::EraseInst(Instruction *I) {
// Erase the dead instruction.
ValueRankMap.erase(I);
RedoInsts.remove(I);
llvm::salvageDebugInfoOrMarkUndef(*I);
llvm::salvageDebugInfo(*I);
I->eraseFromParent();
// Optimize its operands.
SmallPtrSet<Instruction *, 8> Visited; // Detect self-referential nodes.

View File

@ -1628,7 +1628,7 @@ static MetadataAsValue *wrapValueInMetadata(LLVMContext &C, Value *V) {
return MetadataAsValue::get(C, ValueAsMetadata::get(V));
}
bool llvm::salvageDebugInfo(Instruction &I) {
static bool attemptToSalvageDebugInfo(Instruction &I) {
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
findDbgUsers(DbgUsers, &I);
if (DbgUsers.empty())
@ -1637,8 +1637,8 @@ bool llvm::salvageDebugInfo(Instruction &I) {
return salvageDebugInfoForDbgValues(I, DbgUsers);
}
void llvm::salvageDebugInfoOrMarkUndef(Instruction &I) {
if (!salvageDebugInfo(I))
void llvm::salvageDebugInfo(Instruction &I) {
if (!attemptToSalvageDebugInfo(I))
replaceDbgUsesWithUndef(&I);
}
@ -1822,7 +1822,7 @@ static bool rewriteDebugUsers(
if (!UndefOrSalvage.empty()) {
// Try to salvage the remaining debug users.
salvageDebugInfoOrMarkUndef(From);
salvageDebugInfo(From);
Changed = true;
}