// Create an induction variable for the specified value. If it is a PHI, and
// if it's recognizable, classify it and fill in instance variables.
//
- InductionVariable(Instruction *V, cfg::LoopInfo *LoopInfo = 0);
-
+ InductionVariable(PHINode *PN, cfg::LoopInfo *LoopInfo = 0);
// Classify Induction
static enum iType Classify(const Value *Start, const Value *Step,
const cfg::Loop *L = 0);
-
-
};
#endif
// Create an induction variable for the specified value. If it is a PHI, and
// if it's recognizable, classify it and fill in instance variables.
//
-InductionVariable::InductionVariable(Instruction *V, cfg::LoopInfo *LoopInfo) {
+InductionVariable::InductionVariable(PHINode *P, cfg::LoopInfo *LoopInfo) {
InductionType = Unknown; // Assume the worst
+ Phi = P;
- // If this instruction is not a PHINode, it can't be an induction variable.
- // Also, if the PHI node has more than two predecessors, we don't know how to
+ // If the PHI node has more than two predecessors, we don't know how to
// handle it.
//
- Phi = dyn_cast<PHINode>(V);
- if (!Phi || Phi->getNumIncomingValues() != 2) return;
+ if (Phi->getNumIncomingValues() != 2) return;
// If we have loop information, make sure that this PHI node is in the header
// of a loop...
#include "llvm/Instruction.h"
#include "llvm/Module.h"
#include "llvm/Method.h"
+#include "llvm/iPHINode.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Assembly/Parser.h"
#include "llvm/Analysis/Writer.h"
static void PrintInductionVariables(Method *M) {
cfg::LoopInfo LI(M);
for (Method::inst_iterator I = M->inst_begin(), E = M->inst_end();
- I != E; ++I) {
- InductionVariable IV(*I, &LI);
- if (IV.InductionType != InductionVariable::Unknown)
- cout << IV;
- }
+ I != E; ++I)
+ if (PHINode *PN = dyn_cast<PHINode>(*I)) {
+ InductionVariable IV(PN, &LI);
+ if (IV.InductionType != InductionVariable::Unknown)
+ cout << IV;
+ }
}