aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-06-24 04:05:45 +0000
committerChris Lattner <sabre@nondot.org>2001-06-24 04:05:45 +0000
commitc9f39b26c0254f185ee69567bf07c8cea5fb801c (patch)
tree33a13114f3987d3a371048b437d44c048db0aab0 /lib/Transforms
parent107109c2cda7937d7169e3096f5dfc25daddf984 (diff)
downloadexternal_llvm-c9f39b26c0254f185ee69567bf07c8cea5fb801c.zip
external_llvm-c9f39b26c0254f185ee69567bf07c8cea5fb801c.tar.gz
external_llvm-c9f39b26c0254f185ee69567bf07c8cea5fb801c.tar.bz2
#include a different header due to Intervals.h splitting up
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@63 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InductionVars.cpp56
1 files changed, 47 insertions, 9 deletions
diff --git a/lib/Transforms/Scalar/InductionVars.cpp b/lib/Transforms/Scalar/InductionVars.cpp
index 4fd4e43..bd3bc11 100644
--- a/lib/Transforms/Scalar/InductionVars.cpp
+++ b/lib/Transforms/Scalar/InductionVars.cpp
@@ -18,11 +18,13 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/Analysis/Intervals.h"
+#include "llvm/ConstPoolVals.h"
+#include "llvm/Analysis/IntervalPartition.h"
#include "llvm/Opt/AllOpts.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Tools/STLExtras.h"
#include "llvm/iOther.h"
+#include <algorithm>
// isLoopInvariant - Return true if the specified value/basic block source is
// an interval invariant computation.
@@ -141,6 +143,14 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
if (Initializer->getValueType() != Value::ConstantVal)
return false;
+ if (Initializer->getType()->isSigned()) { // Signed constant value...
+ if (((ConstPoolSInt*)Initializer)->getValue() != 0) return false;
+ } else if (Initializer->getType()->isUnsigned()) { // Unsigned constant value
+ if (((ConstPoolUInt*)Initializer)->getValue() != 0) return false;
+ } else {
+ return false; // Not signed or unsigned? Must be FP type or something
+ }
+
// How do I check for 0 for any integral value? Use
// ConstPoolVal::getNullConstant?
@@ -157,9 +167,17 @@ static inline bool isSimpleInductionVar(PHINode *PN) {
Value *StepSize = I->getOperand(1);
if (StepSize->getValueType() != Value::ConstantVal) return false;
- // How do I check for 1 for any integral value?
+ if (StepSize->getType()->isSigned()) { // Signed constant value...
+ if (((ConstPoolSInt*)StepSize)->getValue() != 1) return false;
+ } else if (StepSize->getType()->isUnsigned()) { // Unsigned constant value
+ if (((ConstPoolUInt*)StepSize)->getValue() != 1) return false;
+ } else {
+ return false; // Not signed or unsigned? Must be FP type or something
+ }
- return false;
+ // At this point, we know the initializer is a constant value 0 and the step
+ // size is a constant value 1. This is our simple induction variable!
+ return true;
}
// ProcessInterval - This function is invoked once for each interval in the
@@ -242,25 +260,45 @@ static bool ProcessInterval(cfg::Interval *Int) {
// No induction variables found?
if (InductionVars.empty()) return false;
- cerr << "Found Interval Header with indvars: \n" << Header;
-
// Search to see if there is already a "simple" induction variable.
vector<PHINode*>::iterator It =
find_if(InductionVars.begin(), InductionVars.end(), isSimpleInductionVar);
+ PHINode *PrimaryIndVar;
+
// A simple induction variable was not found, inject one now...
if (It == InductionVars.end()) {
cerr << "WARNING, Induction variable injection not implemented yet!\n";
// TODO: Inject induction variable
- It = InductionVars.end(); --It; // Point it at the new indvar
+ PrimaryIndVar = 0; // Point it at the new indvar
+ } else {
+ // Move the PHI node for this induction variable to the start of the PHI
+ // list in HeaderNode... we do not need to do this for the inserted case
+ // because the inserted node will always be placed at the beginning of
+ // HeaderNode.
+ //
+ PrimaryIndVar = *It;
+ BasicBlock::InstListType::iterator i =
+ find(Header->getInstList().begin(), Header->getInstList().end(),
+ PrimaryIndVar);
+ assert(i != Header->getInstList().end() &&
+ "How could Primary IndVar not be in the header!?!!?");
+
+ if (i != Header->getInstList().begin())
+ iter_swap(i, Header->getInstList().begin());
}
- // Now we know that there is a simple induction variable *It. Simplify all
- // of the other induction variables to use this induction variable as their
- // counter, and destroy the PHI nodes that correspond to the old indvars.
+ // Now we know that there is a simple induction variable PrimaryIndVar.
+ // Simplify all of the other induction variables to use this induction
+ // variable as their counter, and destroy the PHI nodes that correspond to
+ // the old indvars.
//
// TODO
+
+ cerr << "Found Interval Header with indvars (primary indvar should be first "
+ << "phi): \n" << Header << "\nPrimaryIndVar = " << PrimaryIndVar;
+
return false; // TODO: true;
}