Make it illegal to call getDependency* on non-memory instructions
[oota-llvm.git] / include / llvm / Analysis / ScalarEvolutionExpander.h
index ed520f5dc2aec8781d4b0b416224f7861fda2c8b..7ecf5332edd8839ff9ec0116e89d8d38787022ae 100644 (file)
 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_EXPANDER_H
 #define LLVM_ANALYSIS_SCALAREVOLUTION_EXPANDER_H
 
-#include "llvm/BasicBlock.h"
-#include "llvm/Constants.h"
 #include "llvm/Instructions.h"
 #include "llvm/Type.h"
 #include "llvm/Analysis/ScalarEvolution.h"
 #include "llvm/Analysis/ScalarEvolutionExpressions.h"
-#include "llvm/Support/CFG.h"
 
 namespace llvm {
   /// SCEVExpander - This class uses information about analyze scalars to
@@ -78,11 +75,7 @@ namespace llvm {
     /// expandCodeFor - Insert code to directly compute the specified SCEV
     /// expression into the program.  The inserted code is inserted into the
     /// specified block.
-    Value *expandCodeFor(SCEVHandle SH, Instruction *IP) {
-      // Expand the code for this SCEV.
-      this->InsertPt = IP;
-      return expand(SH);
-    }
+    Value *expandCodeFor(SCEVHandle SH, Instruction *IP);
 
     /// InsertCastOfTo - Insert a cast of V to the specified type, doing what
     /// we can to share the casts.
@@ -91,7 +84,7 @@ namespace llvm {
     /// InsertBinop - Insert the specified binary operator, doing a small amount
     /// of work to avoid inserting an obviously redundant operation.
     static Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS,
-                              Value *RHS, Instruction *&InsertPt);
+                              Value *RHS, Instruction *InsertPt);
   protected:
     Value *expand(SCEV *S);
     
@@ -99,38 +92,19 @@ namespace llvm {
       return S->getValue();
     }
 
-    Value *visitTruncateExpr(SCEVTruncateExpr *S) {
-      Value *V = expand(S->getOperand());
-      return CastInst::CreateTruncOrBitCast(V, S->getType(), "tmp.", InsertPt);
-    }
-
-    Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S) {
-      Value *V = expand(S->getOperand());
-      return CastInst::CreateZExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
-    }
+    Value *visitTruncateExpr(SCEVTruncateExpr *S);
 
-    Value *visitSignExtendExpr(SCEVSignExtendExpr *S) {
-      Value *V = expand(S->getOperand());
-      return CastInst::CreateSExtOrBitCast(V, S->getType(), "tmp.", InsertPt);
-    }
+    Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S);
 
-    Value *visitAddExpr(SCEVAddExpr *S) {
-      Value *V = expand(S->getOperand(S->getNumOperands()-1));
+    Value *visitSignExtendExpr(SCEVSignExtendExpr *S);
 
-      // Emit a bunch of add instructions
-      for (int i = S->getNumOperands()-2; i >= 0; --i)
-        V = InsertBinop(Instruction::Add, V, expand(S->getOperand(i)),
-                        InsertPt);
-      return V;
-    }
+    Value *visitAddExpr(SCEVAddExpr *S);
 
     Value *visitMulExpr(SCEVMulExpr *S);
 
-    Value *visitUDivExpr(SCEVUDivExpr *S) {
-      Value *LHS = expand(S->getLHS());
-      Value *RHS = expand(S->getRHS());
-      return InsertBinop(Instruction::UDiv, LHS, RHS, InsertPt);
-    }
+    Value *visitUDivExpr(SCEVUDivExpr *S);
+
+    Value *visitSDivExpr(SCEVSDivExpr *S);
 
     Value *visitAddRecExpr(SCEVAddRecExpr *S);