summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-12-03 17:28:42 +0000
committerChris Lattner <sabre@nondot.org>2001-12-03 17:28:42 +0000
commit6148c02591bd83da7b957589c4bbf6f9720d503f (patch)
tree3df89106300cd89ccbfcee5c9c833843420a03c6
parentc50df7e3aafee8830ea649df9b2e153fedc3bb2b (diff)
downloadllvm-6148c02591bd83da7b957589c4bbf6f9720d503f.tar.gz
llvm-6148c02591bd83da7b957589c4bbf6f9720d503f.tar.bz2
llvm-6148c02591bd83da7b957589c4bbf6f9720d503f.tar.xz
Initial checkin of indvar stuff
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1404 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/IndVarSimplify.cpp69
-rw-r--r--lib/Transforms/Scalar/Makefile6
2 files changed, 75 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/IndVarSimplify.cpp b/lib/Transforms/Scalar/IndVarSimplify.cpp
new file mode 100644
index 0000000000..7e465e560e
--- /dev/null
+++ b/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -0,0 +1,69 @@
+//===- IndVarSimplify.cpp - Induction Variable Elimination ----------------===//
+//
+// InductionVariableSimplify - Transform induction variables in a program
+// to all use a single cannonical induction variable per loop.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Transforms/Scalar/IndVarSimplify.h"
+#include "llvm/Analysis/InductionVariable.h"
+#include "llvm/Analysis/LoopInfo.h"
+#include "llvm/Analysis/Dominators.h"
+#include "llvm/iPHINode.h"
+#include "Support/STLExtras.h"
+
+static bool TransformLoop(cfg::LoopInfo *Loops, cfg::Loop *Loop) {
+ // Transform all subloops before this loop...
+ bool Changed = reduce_apply_bool(Loop->getSubLoops().begin(),
+ Loop->getSubLoops().end(),
+ std::bind1st(ptr_fun(TransformLoop), Loops));
+ // Get the header node for this loop. All of the phi nodes that could be
+ // induction variables must live in this basic block.
+ BasicBlock *Header = (BasicBlock*)Loop->getBlocks().front();
+
+ // Loop over all of the PHI nodes in the basic block, calculating the
+ // induction variables that they represent... stuffing the induction variable
+ // info into a vector...
+ //
+ vector<InductionVariable> IndVars; // Induction variables for block
+ for (BasicBlock::iterator I = Header->begin();
+ PHINode *PN = dyn_cast<PHINode>(*I); ++I)
+ IndVars.push_back(InductionVariable(PN, Loops));
+
+ // If there are phi nodes in this basic block, there can't be indvars...
+ if (IndVars.empty()) return Changed;
+
+ // Loop over the induction variables, looking for a cannonical induction
+ // variable, and checking to make sure they are not all unknown induction
+ // variables.
+ //
+ bool FoundIndVars = false;
+ InductionVariable *Cannonical = 0;
+ for (unsigned i = 0; i < IndVars.size(); ++i) {
+ if (IndVars[i].InductionType == InductionVariable::Cannonical)
+ Cannonical = &IndVars[i];
+ if (IndVars[i].InductionType != InductionVariable::Unknown)
+ FoundIndVars = true;
+ }
+
+ // No induction variables, bail early... don't add a cannonnical indvar
+ if (!FoundIndVars) return Changed;
+
+ // Okay, we want to convert other induction variables to use a cannonical
+ // indvar. If we don't have one, add one now...
+ if (!Cannonical) {
+
+ }
+
+ return Changed;
+}
+
+bool InductionVariableSimplify::doit(Method *M) {
+ // Figure out the loop structure of the method...
+ cfg::LoopInfo Loops(M);
+
+ // Induction Variables live in the header nodes of the loops of the method...
+ return reduce_apply_bool(Loops.getTopLevelLoops().begin(),
+ Loops.getTopLevelLoops().end(),
+ std::bind1st(std::ptr_fun(TransformLoop), &Loops));
+}
diff --git a/lib/Transforms/Scalar/Makefile b/lib/Transforms/Scalar/Makefile
new file mode 100644
index 0000000000..fed3412dfd
--- /dev/null
+++ b/lib/Transforms/Scalar/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../..
+
+LIBRARYNAME = scalaropts
+
+include $(LEVEL)/Makefile.common
+