LangRef.html says that inttoptr and ptrtoint always use zero-extension
[oota-llvm.git] / lib / Transforms / InstCombine / InstCombine.h
index 4af0236d18711e425172a9d5245be25990e8b9f4..536790004e864a77edc8f219857edcfa26ff9dce 100644 (file)
@@ -32,6 +32,20 @@ enum SelectPatternFlavor {
   SPF_SMAX, SPF_UMAX
   //SPF_ABS - TODO.
 };
+  
+/// getComplexity:  Assign a complexity or rank value to LLVM Values...
+///   0 -> undef, 1 -> Const, 2 -> Other, 3 -> Arg, 3 -> Unary, 4 -> OtherInst
+static inline unsigned getComplexity(Value *V) {
+  if (isa<Instruction>(V)) {
+    if (BinaryOperator::isNeg(V) ||
+        BinaryOperator::isFNeg(V) ||
+        BinaryOperator::isNot(V))
+      return 3;
+    return 4;
+  }
+  if (isa<Argument>(V)) return 3;
+  return isa<Constant>(V) ? (isa<UndefValue>(V) ? 0 : 1) : 2;
+}
 
   
 /// InstCombineIRInserter - This is an IRBuilder insertion helper that works
@@ -74,11 +88,8 @@ public:
   
   bool DoOneIteration(Function &F, unsigned ItNum);
 
-  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.addPreservedID(LCSSAID);
-    AU.setPreservesCFG();
-  }
-
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const;
+                                 
   TargetData *getTargetData() const { return TD; }
 
   // Visitation implementation - Implement instruction combining for different
@@ -139,7 +150,6 @@ public:
   Instruction *FoldShiftByConstant(Value *Op0, ConstantInt *Op1,
                                    BinaryOperator &I);
   Instruction *commonCastTransforms(CastInst &CI);
-  Instruction *commonIntCastTransforms(CastInst &CI);
   Instruction *commonPointerCastTransforms(CastInst &CI);
   Instruction *visitTrunc(TruncInst &CI);
   Instruction *visitZExt(ZExtInst &CI);
@@ -182,6 +192,19 @@ public:
   Instruction *visitInstruction(Instruction &I) { return 0; }
 
 private:
+  bool ShouldChangeType(const Type *From, const Type *To) const;
+  Value *dyn_castNegVal(Value *V) const;
+  Value *dyn_castFNegVal(Value *V) const;
+  const Type *FindElementAtOffset(const Type *Ty, int64_t Offset, 
+                                  SmallVectorImpl<Value*> &NewIndices);
+  Instruction *FoldOpIntoSelect(Instruction &Op, SelectInst *SI);
+                                 
+  /// ValueRequiresCast - Return true if the cast from "V to Ty" actually
+  /// results in any code being generated.  It does not require codegen if V is
+  /// simple enough or if the cast can be folded into other casts.
+  bool ValueRequiresCast(Instruction::CastOps opcode,const Value *V,
+                         const Type *Ty);
+
   Instruction *visitCallSite(CallSite CS);
   bool transformConstExprCastCall(CallSite CS);
   Instruction *transformCallThroughTrampoline(CallSite CS);
@@ -189,7 +212,7 @@ private:
                                  bool DoXform = true);
   bool WillNotOverflowSignedAdd(Value *LHS, Value *RHS);
   DbgDeclareInst *hasOneUsePlusDeclare(Value *V);
-
+  Value *EmitGEPOffset(User *GEP);
 
 public:
   // InsertNewInstBefore - insert an instruction New before instruction Old
@@ -314,8 +337,6 @@ private:
 
   Value *EvaluateInDifferentType(Value *V, const Type *Ty, bool isSigned);
 
-  bool CanEvaluateInDifferentType(Value *V, const Type *Ty,
-                                  unsigned CastOpc, int &NumCastsRemoved);
   unsigned GetOrEnforceKnownAlignment(Value *V,
                                       unsigned PrefAlign = 0);