Change the interface to SCEVExpander::InsertCastOfTo to take a cast opcode
so the decision of which opcode to use is pushed upward to the caller.
Adjust the callers to pass the expected opcode.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32535 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/ScalarEvolutionExpander.cpp b/lib/Analysis/ScalarEvolutionExpander.cpp
index db23a24..5e395db 100644
--- a/lib/Analysis/ScalarEvolutionExpander.cpp
+++ b/lib/Analysis/ScalarEvolutionExpander.cpp
@@ -19,25 +19,8 @@
 
 /// InsertCastOfTo - Insert a cast of V to the specified type, doing what
 /// we can to share the casts.
-Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
-  // Compute the Cast opcode to use
-  Instruction::CastOps opcode = Instruction::BitCast;
-  if (Ty->isIntegral()) {
-    if (V->getType()->getTypeID() == Type::PointerTyID)
-      opcode = Instruction::PtrToInt;
-    else {
-      unsigned SrcBits = V->getType()->getPrimitiveSizeInBits();
-      unsigned DstBits = Ty->getPrimitiveSizeInBits();
-      opcode = (SrcBits > DstBits ? Instruction::Trunc : 
-                (SrcBits == DstBits ? Instruction::BitCast :
-                 (V->getType()->isSigned() ? Instruction::SExt : 
-                  Instruction::ZExt)));
-    }
-  } else if (Ty->isFloatingPoint())
-    opcode = Instruction::UIToFP;
-  else if (Ty->getTypeID() == Type::PointerTyID && V->getType()->isIntegral())
-    opcode = Instruction::IntToPtr;
-
+Value *SCEVExpander::InsertCastOfTo(Instruction::CastOps opcode, Value *V, 
+                                    const Type *Ty) {
   // FIXME: keep track of the cast instruction.
   if (Constant *C = dyn_cast<Constant>(V))
     return ConstantExpr::getCast(opcode, C, Ty);