From df89f6efbc5d2b40b4997a84ae12ab86baa2d9cb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 3 Dec 2001 17:27:42 +0000 Subject: [PATCH] Induction variables must be phi nodes git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1402 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/InductionVariable.h | 5 +---- lib/Analysis/InductionVariable.cpp | 9 ++++----- tools/analyze/analyze.cpp | 12 +++++++----- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/llvm/Analysis/InductionVariable.h b/include/llvm/Analysis/InductionVariable.h index 02fa6deedd5..51399550b43 100644 --- a/include/llvm/Analysis/InductionVariable.h +++ b/include/llvm/Analysis/InductionVariable.h @@ -40,14 +40,11 @@ public: // 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 diff --git a/lib/Analysis/InductionVariable.cpp b/lib/Analysis/InductionVariable.cpp index 706c778a4da..b64daa25b30 100644 --- a/lib/Analysis/InductionVariable.cpp +++ b/lib/Analysis/InductionVariable.cpp @@ -59,15 +59,14 @@ InductionVariable::Classify(const Value *Start, const Value *Step, // 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(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... diff --git a/tools/analyze/analyze.cpp b/tools/analyze/analyze.cpp index da7de6ec9af..9a53bd45af1 100644 --- a/tools/analyze/analyze.cpp +++ b/tools/analyze/analyze.cpp @@ -13,6 +13,7 @@ #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" @@ -67,11 +68,12 @@ static void PrintClassifiedExprs(Method *M) { 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(*I)) { + InductionVariable IV(PN, &LI); + if (IV.InductionType != InductionVariable::Unknown) + cout << IV; + } }