[Local] Promote an utility that could be used elsewhere. NFCI.

llvm-svn: 348804
This commit is contained in:
Davide Italiano 2018-12-10 22:17:04 +00:00
parent 588232858e
commit 8ec7709f58
3 changed files with 18 additions and 7 deletions

View File

@ -174,6 +174,12 @@ bool RecursivelyDeleteDeadPHINode(PHINode *PN,
bool SimplifyInstructionsInBlock(BasicBlock *BB,
const TargetLibraryInfo *TLI = nullptr);
/// Replace all the uses of an SSA value in @llvm.dbg intrinsics with
/// undef. This is useful for signaling that a variable, e.g. has been
/// found dead and hence it's unavailable at a given program point.
/// Returns true if the dbg values have been changed.
bool replaceDbgUsesWithUndef(Instruction *I);
//===----------------------------------------------------------------------===//
// Control Flow Graph Restructuring.
//

View File

@ -789,13 +789,7 @@ void ReassociatePass::RewriteExprTree(BinaryOperator *I,
// Discard any debug info related to the expressions that has changed (we
// can leave debug infor related to the root, since the result of the
// expression tree should be the same even after reassociation).
SmallVector<DbgVariableIntrinsic *, 1> DbgUsers;
findDbgUsers(DbgUsers, ExpressionChanged);
for (auto *DII : DbgUsers) {
Value *Undef = UndefValue::get(ExpressionChanged->getType());
DII->setOperand(0, MetadataAsValue::get(DII->getContext(),
ValueAsMetadata::get(Undef)));
}
replaceDbgUsesWithUndef(ExpressionChanged);
ExpressionChanged->moveBefore(I);
ExpressionChanged = cast<BinaryOperator>(*ExpressionChanged->user_begin());

View File

@ -476,6 +476,17 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(
}
}
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)));
}
return !DbgUsers.empty();
}
/// areAllUsesEqual - Check whether the uses of a value are all the same.
/// This is similar to Instruction::hasOneUse() except this will also return
/// true when there are no uses or multiple uses that all refer to the same