1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

add a helper function.

llvm-svn: 93251
This commit is contained in:
Chris Lattner 2010-01-12 19:40:54 +00:00
parent 1d9c156df2
commit 87f86498c3
2 changed files with 32 additions and 0 deletions

View File

@ -74,6 +74,14 @@ bool RecursivelyDeleteTriviallyDeadInstructions(Value *V);
/// too, recursively. Return true if the PHI node is actually deleted.
bool RecursivelyDeleteDeadPHINode(PHINode *PN);
/// SimplifyInstructionsInBlock - Scan the specified basic block and try to
/// simplify any instructions in it and recursively delete dead instructions.
///
/// This returns true if it changed the code, note that it can delete
/// instructions in other blocks as well in this block.
bool SimplifyInstructionsInBlock(BasicBlock *BB, const TargetData *TD = 0);
//===----------------------------------------------------------------------===//
// Control Flow Graph Restructuring.
//

View File

@ -335,6 +335,30 @@ llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
return Changed;
}
/// SimplifyInstructionsInBlock - Scan the specified basic block and try to
/// simplify any instructions in it and recursively delete dead instructions.
///
/// This returns true if it changed the code, note that it can delete
/// instructions in other blocks as well in this block.
bool llvm::SimplifyInstructionsInBlock(BasicBlock *BB, const TargetData *TD) {
bool MadeChange = false;
for (BasicBlock::iterator BI = BB->begin(), E = BB->end(); BI != E; ) {
Instruction *Inst = BI++;
if (Value *V = SimplifyInstruction(Inst, TD)) {
WeakVH BIHandle(BI);
ReplaceAndSimplifyAllUses(Inst, V, TD);
MadeChange = true;
if (BIHandle == 0)
BI = BB->begin();
continue;
}
MadeChange |= RecursivelyDeleteTriviallyDeadInstructions(Inst);
}
return MadeChange;
}
//===----------------------------------------------------------------------===//
// Control Flow Graph Restructuring.
//