diff options
| author | Chris Lattner <sabre@nondot.org> | 2003-12-10 18:06:47 +0000 |
|---|---|---|
| committer | Chris Lattner <sabre@nondot.org> | 2003-12-10 18:06:47 +0000 |
| commit | ccd9f3c1f817f2ec38e1d25bd12a9f1a352eb30a (patch) | |
| tree | e117d9646abc022f13554503d8733ebcd4b104c5 /llvm/lib/Transforms | |
| parent | 83fb097ed058f069b39c884c247170ef879f3b20 (diff) | |
| download | bcm5719-llvm-ccd9f3c1f817f2ec38e1d25bd12a9f1a352eb30a.tar.gz bcm5719-llvm-ccd9f3c1f817f2ec38e1d25bd12a9f1a352eb30a.zip | |
Finegrainify namespacification
Reorder #includes
Implement: IndVarsSimplify/2003-12-10-IndVarDeadCode.ll
llvm-svn: 10376
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/Scalar/IndVarSimplify.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp index 0777a1e09fd..369be476841 100644 --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -15,18 +15,18 @@ //===----------------------------------------------------------------------===// #include "llvm/Transforms/Scalar.h" -#include "llvm/Analysis/InductionVariable.h" -#include "llvm/Analysis/LoopInfo.h" +#include "llvm/Constants.h" +#include "llvm/Type.h" #include "llvm/iPHINode.h" #include "llvm/iOther.h" -#include "llvm/Type.h" -#include "llvm/Constants.h" +#include "llvm/Analysis/InductionVariable.h" +#include "llvm/Analysis/LoopInfo.h" #include "llvm/Support/CFG.h" +#include "llvm/Transforms/Utils/Local.h" #include "Support/Debug.h" #include "Support/Statistic.h" #include "Support/STLExtras.h" - -namespace llvm { +using namespace llvm; namespace { Statistic<> NumRemoved ("indvars", "Number of aux indvars removed"); @@ -185,8 +185,28 @@ static bool TransformLoop(LoopInfo *Loops, Loop *Loop) { IV->Phi->setName(""); Val->setName(OldName); + // Get the incoming values used by the PHI node + std::vector<Value*> PHIOps; + PHIOps.reserve(IV->Phi->getNumIncomingValues()); + for (unsigned i = 0, e = IV->Phi->getNumIncomingValues(); i != e; ++i) + PHIOps.push_back(IV->Phi->getIncomingValue(i)); + // Delete the old, now unused, phi node... Header->getInstList().erase(IV->Phi); + + // If the PHI is the last user of any instructions for computing PHI nodes + // that are irrelevant now, delete those instructions. + while (!PHIOps.empty()) { + Instruction *MaybeDead = dyn_cast<Instruction>(PHIOps.back()); + PHIOps.pop_back(); + + if (MaybeDead && isInstructionTriviallyDead(MaybeDead)) { + PHIOps.insert(PHIOps.end(), MaybeDead->op_begin(), + MaybeDead->op_end()); + MaybeDead->getParent()->getInstList().erase(MaybeDead); + } + } + Changed = true; ++NumRemoved; } @@ -216,8 +236,7 @@ namespace { "Canonicalize Induction Variables"); } -Pass *createIndVarSimplifyPass() { +Pass *llvm::createIndVarSimplifyPass() { return new InductionVariableSimplify(); } -} // End llvm namespace |

