[llvm-commits] [llvm] r60191 - in /llvm/trunk: include/llvm/Transforms/Utils/Local.h lib/Transforms/Scalar/CodeGenPrepare.cpp lib/Transforms/Utils/Local.cpp
Chris Lattner
sabre at nondot.org
Thu Nov 27 14:57:53 PST 2008
Author: lattner
Date: Thu Nov 27 16:57:53 2008
New Revision: 60191
URL: http://llvm.org/viewvc/llvm-project?rev=60191&view=rev
Log:
remove doConstantPropagation and dceInstruction, they are just
wrappers around the interesting code and use an obscure iterator
abstraction that dates back many many years.
Move EraseDeadInstructions to Transforms/Utils and name it
RecursivelyDeleteTriviallyDeadInstructions.
Modified:
llvm/trunk/include/llvm/Transforms/Utils/Local.h
llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
llvm/trunk/lib/Transforms/Utils/Local.cpp
Modified: llvm/trunk/include/llvm/Transforms/Utils/Local.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/Utils/Local.h?rev=60191&r1=60190&r2=60191&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/Utils/Local.h (original)
+++ llvm/trunk/include/llvm/Transforms/Utils/Local.h Thu Nov 27 16:57:53 2008
@@ -26,14 +26,9 @@
class TargetData;
//===----------------------------------------------------------------------===//
-// Local constant propagation...
+// Local constant propagation.
//
-/// doConstantPropagation - Constant prop a specific instruction. Returns true
-/// and potentially moves the iterator if constant propagation was performed.
-///
-bool doConstantPropagation(BasicBlock::iterator &I, const TargetData *TD = 0);
-
/// ConstantFoldTerminator - If a terminator instruction is predicated on a
/// constant value, convert it into an unconditional branch to the constant
/// destination. This is a nontrivial operation because the successors of this
@@ -42,7 +37,7 @@
bool ConstantFoldTerminator(BasicBlock *BB);
//===----------------------------------------------------------------------===//
-// Local dead code elimination...
+// Local dead code elimination.
//
/// isInstructionTriviallyDead - Return true if the result produced by the
@@ -50,14 +45,12 @@
///
bool isInstructionTriviallyDead(Instruction *I);
-
-/// dceInstruction - Inspect the instruction at *BBI and figure out if it
-/// isTriviallyDead. If so, remove the instruction and update the iterator to
-/// point to the instruction that immediately succeeded the original
-/// instruction.
-///
-bool dceInstruction(BasicBlock::iterator &BBI);
-
+
+/// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
+/// trivially dead instruction, delete it. If that makes any of its operands
+/// trivially dead, delete them too, recursively.
+void RecursivelyDeleteTriviallyDeadInstructions(Value *V);
+
//===----------------------------------------------------------------------===//
// Control Flow Graph Restructuring...
//
Modified: llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp?rev=60191&r1=60190&r2=60191&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/CodeGenPrepare.cpp Thu Nov 27 16:57:53 2008
@@ -454,26 +454,6 @@
return MadeChange;
}
-/// EraseDeadInstructions - Erase any dead instructions, recursively.
-static void EraseDeadInstructions(Value *V) {
- Instruction *I = dyn_cast<Instruction>(V);
- if (!I || !I->use_empty()) return;
-
- SmallPtrSet<Instruction*, 16> Insts;
- Insts.insert(I);
-
- while (!Insts.empty()) {
- I = *Insts.begin();
- Insts.erase(I);
- if (isInstructionTriviallyDead(I)) {
- for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
- if (Instruction *U = dyn_cast<Instruction>(I->getOperand(i)))
- Insts.insert(U);
- I->eraseFromParent();
- }
- }
-}
-
//===----------------------------------------------------------------------===//
// Addressing Mode Analysis and Optimization
//===----------------------------------------------------------------------===//
@@ -1234,7 +1214,7 @@
MemoryInst->replaceUsesOfWith(Addr, SunkAddr);
if (Addr->use_empty())
- EraseDeadInstructions(Addr);
+ RecursivelyDeleteTriviallyDeadInstructions(Addr);
return true;
}
Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=60191&r1=60190&r2=60191&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Thu Nov 27 16:57:53 2008
@@ -22,30 +22,13 @@
#include "llvm/Target/TargetData.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/MathExtras.h"
-#include <cerrno>
+#include "llvm/ADT/SmallPtrSet.h"
using namespace llvm;
//===----------------------------------------------------------------------===//
-// Local constant propagation...
+// Local constant propagation.
//
-/// doConstantPropagation - If an instruction references constants, try to fold
-/// them together...
-///
-bool llvm::doConstantPropagation(BasicBlock::iterator &II,
- const TargetData *TD) {
- if (Constant *C = ConstantFoldInstruction(II, TD)) {
- // Replaces all of the uses of a variable with uses of the constant.
- II->replaceAllUsesWith(C);
-
- // Remove the instruction from the basic block...
- II = II->getParent()->getInstList().erase(II);
- return true;
- }
-
- return false;
-}
-
// ConstantFoldTerminator - If a terminator instruction is predicated on a
// constant value, convert it into an unconditional branch to the constant
// destination.
@@ -171,6 +154,9 @@
// Local dead code elimination...
//
+/// isInstructionTriviallyDead - Return true if the result produced by the
+/// instruction is not used, and the instruction has no side effects.
+///
bool llvm::isInstructionTriviallyDead(Instruction *I) {
if (!I->use_empty() || isa<TerminatorInst>(I)) return false;
@@ -187,20 +173,29 @@
return false;
}
-// dceInstruction - Inspect the instruction at *BBI and figure out if it's
-// [trivially] dead. If so, remove the instruction and update the iterator
-// to point to the instruction that immediately succeeded the original
-// instruction.
-//
-bool llvm::dceInstruction(BasicBlock::iterator &BBI) {
- // Look for un"used" definitions...
- if (isInstructionTriviallyDead(BBI)) {
- BBI = BBI->getParent()->getInstList().erase(BBI); // Bye bye
- return true;
+/// RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a
+/// trivially dead instruction, delete it. If that makes any of its operands
+/// trivially dead, delete them too, recursively.
+void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) {
+ Instruction *I = dyn_cast<Instruction>(V);
+ if (!I || !I->use_empty()) return;
+
+ SmallPtrSet<Instruction*, 16> Insts;
+ Insts.insert(I);
+
+ while (!Insts.empty()) {
+ I = *Insts.begin();
+ Insts.erase(I);
+ if (isInstructionTriviallyDead(I)) {
+ for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
+ if (Instruction *U = dyn_cast<Instruction>(I->getOperand(i)))
+ Insts.insert(U);
+ I->eraseFromParent();
+ }
}
- return false;
}
+
//===----------------------------------------------------------------------===//
// Control Flow Graph Restructuring...
//
More information about the llvm-commits
mailing list