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 | ba4f3f6a419326df190599421fa149c90235cb72 (patch) | |
tree | 97c39456fe82ca3f72e7ab7ddde6c8478591c02d /lib | |
parent | 01b2d6131145bfa3c9c4c1598edeaac13155e1a5 (diff) | |
download | external_llvm-ba4f3f6a419326df190599421fa149c90235cb72.zip external_llvm-ba4f3f6a419326df190599421fa149c90235cb72.tar.gz external_llvm-ba4f3f6a419326df190599421fa149c90235cb72.tar.bz2 |
Finegrainify namespacification
Reorder #includes
Implement: IndVarsSimplify/2003-12-10-IndVarDeadCode.ll
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@10376 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Transforms/Scalar/IndVarSimplify.cpp | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp index 0777a1e..369be47 100644 --- a/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/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 |