Move more functionality over to LLVMContext.
authorOwen Anderson <resistor@mac.com>
Mon, 13 Jul 2009 20:58:05 +0000 (20:58 +0000)
committerOwen Anderson <resistor@mac.com>
Mon, 13 Jul 2009 20:58:05 +0000 (20:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75497 91177308-0d34-0410-b5e6-96231b3b80d8

17 files changed:
include/llvm/Constant.h
include/llvm/Constants.h
include/llvm/InstrTypes.h
include/llvm/LLVMContext.h
include/llvm/Support/IRBuilder.h
lib/Analysis/ScalarEvolution.cpp
lib/Target/X86/X86InstrInfo.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/PredicateSimplifier.cpp
lib/Transforms/Scalar/Reassociate.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Scalar/SimplifyLibCalls.cpp
lib/Transforms/Utils/SimplifyCFG.cpp
lib/VMCore/Constants.cpp
lib/VMCore/Instructions.cpp
lib/VMCore/LLVMContext.cpp

index 05a66232007bc40827a1019f2c69c940f66bb296..bccd417f07905cfb1f8333f41a4f62eb522511d2 100644 (file)
@@ -60,11 +60,6 @@ protected:
 
   void destroyConstantImpl();
 public:
-  /// Static constructor to get a '-1' constant.  This supports integers and
-  /// vectors.
-  ///
-  static Constant *getAllOnesValue(const Type *Ty);
-  
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const = 0;
index 77124d897446b6cd60368d3175469efba225dcd7..ac0b0fb3148c50f1b5346e0d4008af1e4bdd9dad 100644 (file)
@@ -227,11 +227,6 @@ public:
     return Val.getLimitedValue(Limit);
   }
 
-  /// @returns the value for an integer constant of the given type that has all
-  /// its bits set to true.
-  /// @brief Get the all ones value
-  static ConstantInt *getAllOnesValue(const Type *Ty);
-
   /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
   static inline bool classof(const ConstantInt *) { return true; }
   static bool classof(const Value *V) {
@@ -487,11 +482,6 @@ public:
   inline const VectorType *getType() const {
     return reinterpret_cast<const VectorType*>(Value::getType());
   }
-
-  /// @returns the value for a vector integer constant of the given type that
-  /// has all its bits set to true.
-  /// @brief Get the all ones value
-  static ConstantVector *getAllOnesValue(const VectorType *Ty);
   
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.  This always returns false because zero vectors are always
@@ -702,7 +692,6 @@ public:
   /// ConstantExpr::get* - Return some common constants without having to
   /// specify the full Instruction::OPCODE identifier.
   ///
-  static Constant *getNot(Constant *C);
   static Constant *getAdd(Constant *C1, Constant *C2);
   static Constant *getFAdd(Constant *C1, Constant *C2);
   static Constant *getSub(Constant *C1, Constant *C2);
index 9c1f8fc804a5208272e91b33df939ba6128d113c..eb0b7b6e5b6a686f1ca0fa3f338a78b06ca3ab61 100644 (file)
@@ -214,9 +214,11 @@ public:
   static BinaryOperator *CreateFNeg(LLVMContext &Context,
                                     Value *Op, const std::string &Name,
                                     BasicBlock *InsertAtEnd);
-  static BinaryOperator *CreateNot(Value *Op, const std::string &Name = "",
+  static BinaryOperator *CreateNot(LLVMContext &Context,
+                                   Value *Op, const std::string &Name = "",
                                    Instruction *InsertBefore = 0);
-  static BinaryOperator *CreateNot(Value *Op, const std::string &Name,
+  static BinaryOperator *CreateNot(LLVMContext &Context,
+                                   Value *Op, const std::string &Name,
                                    BasicBlock *InsertAtEnd);
 
   /// isNeg, isFNeg, isNot - Check if the given Value is a
index e441d189c2f65a34b619e9310caa8a91c4851e8d..55eead4621c27f6e3c1c1b193b5a8e4cec9d9783 100644 (file)
@@ -58,6 +58,10 @@ public:
   
   // Constant accessors
   Constant* getNullValue(const Type* Ty);
+  
+  /// @returns the value for an integer constant of the given type that has all
+  /// its bits set to true.
+  /// @brief Get the all ones value
   Constant* getAllOnesValue(const Type* Ty);
   
   // UndefValue accessors
@@ -73,7 +77,6 @@ public:
   ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
   ConstantInt* getConstantInt(const APInt& V);
   Constant* getConstantInt(const Type* Ty, const APInt& V);
-  ConstantInt* getConstantIntAllOnesValue(const Type* Ty);
   
   // ConstantPointerNull accessors
   ConstantPointerNull* getConstantPointerNull(const PointerType* T);
@@ -188,7 +191,6 @@ public:
                               const std::vector<Constant*>& V);
   Constant* getConstantVector(const std::vector<Constant*>& V);
   Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
-  ConstantVector* getConstantVectorAllOnesValue(const VectorType* Ty);
   
   // MDNode accessors
   MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
index 5de33eb2cb1fdcd8818b6b17590fc677b3051270..2ef13a789f30444abedcebb1781416b031d198e4 100644 (file)
@@ -311,17 +311,17 @@ public:
   Value *CreateNeg(Value *V, const char *Name = "") {
     if (Constant *VC = dyn_cast<Constant>(V))
       return Folder.CreateNeg(VC);
-    return Insert(BinaryOperator::CreateNeg(getGlobalContext(), V), Name);
+    return Insert(BinaryOperator::CreateNeg(Context, V), Name);
   }
   Value *CreateFNeg(Value *V, const char *Name = "") {
     if (Constant *VC = dyn_cast<Constant>(V))
       return Folder.CreateFNeg(VC);
-    return Insert(BinaryOperator::CreateFNeg(getGlobalContext(), V), Name);
+    return Insert(BinaryOperator::CreateFNeg(Context, V), Name);
   }
   Value *CreateNot(Value *V, const char *Name = "") {
     if (Constant *VC = dyn_cast<Constant>(V))
       return Folder.CreateNot(VC);
-    return Insert(BinaryOperator::CreateNot(V), Name);
+    return Insert(BinaryOperator::CreateNot(Context, V), Name);
   }
 
   //===--------------------------------------------------------------------===//
index 6a028c19faf152b62e82e3da1f22aa470cf6827c..2db39c4e0c4b10b7ac18be18e8a086dc13cb0ee0 100644 (file)
@@ -2067,17 +2067,20 @@ const SCEV *ScalarEvolution::getNegativeSCEV(const SCEV *V) {
 
   const Type *Ty = V->getType();
   Ty = getEffectiveSCEVType(Ty);
-  return getMulExpr(V, getConstant(ConstantInt::getAllOnesValue(Ty)));
+  return getMulExpr(V,
+                  getConstant(cast<ConstantInt>(Context->getAllOnesValue(Ty))));
 }
 
 /// getNotSCEV - Return a SCEV corresponding to ~V = -1-V
 const SCEV *ScalarEvolution::getNotSCEV(const SCEV *V) {
   if (const SCEVConstant *VC = dyn_cast<SCEVConstant>(V))
-    return getConstant(cast<ConstantInt>(ConstantExpr::getNot(VC->getValue())));
+    return getConstant(
+                cast<ConstantInt>(Context->getConstantExprNot(VC->getValue())));
 
   const Type *Ty = V->getType();
   Ty = getEffectiveSCEVType(Ty);
-  const SCEV *AllOnes = getConstant(ConstantInt::getAllOnesValue(Ty));
+  const SCEV *AllOnes =
+                   getConstant(cast<ConstantInt>(Context->getAllOnesValue(Ty)));
   return getMinusSCEV(AllOnes, V);
 }
 
index cb98c057c4af566d26572ddbc94cd90bb6033bbc..06e2b8dff0609b8c0cc1f04530a6b31ba418dff4 100644 (file)
@@ -2314,7 +2314,7 @@ MachineInstr* X86InstrInfo::foldMemoryOperandImpl(MachineFunction &MF,
     const VectorType *Ty = VectorType::get(Type::Int32Ty, 4);
     Constant *C = LoadMI->getOpcode() == X86::V_SET0 ?
                     MF.getFunction()->getContext()->getNullValue(Ty) :
-                    ConstantVector::getAllOnesValue(Ty);
+                    MF.getFunction()->getContext()->getAllOnesValue(Ty);
     unsigned CPI = MCP.getConstantPoolIndex(C, 16);
 
     // Create operands to load from the constant pool entry.
index 57a8d281e06b1cb59a71f93cdad3d0f269abf413..1b8db42bcac0880b30dc291ef7dd940b82136c7f 100644 (file)
@@ -891,7 +891,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
           case ICmpInst::ICMP_ULE:
           case ICmpInst::ICMP_SLE:
           case ICmpInst::ICMP_EQ:
-            LV = BinaryOperator::CreateNot(LV, "notinit", CI);
+            LV = BinaryOperator::CreateNot(*Context, LV, "notinit", CI);
             break;
           case ICmpInst::ICMP_NE:
           case ICmpInst::ICMP_UGE:
index 99f315fcda10bccc32a76fc4721afedfc11062ad..4397540c22f5cc03032352e2dd35db5387afc160 100644 (file)
@@ -2107,7 +2107,7 @@ Instruction *InstCombiner::visitAdd(BinaryOperator &I) {
             ZI->getOperand(0)->getType() == Type::Int1Ty)
           return SelectInst::Create(ZI->getOperand(0),
                                     Context->getNullValue(I.getType()),
-                              Context->getConstantIntAllOnesValue(I.getType()));
+                              Context->getAllOnesValue(I.getType()));
     }
 
     if (isa<PHINode>(LHS))
@@ -2485,7 +2485,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
   if (ConstantInt *C = dyn_cast<ConstantInt>(Op0)) {
     // Replace (-1 - A) with (~A)...
     if (C->isAllOnesValue())
-      return BinaryOperator::CreateNot(Op1);
+      return BinaryOperator::CreateNot(*Context, Op1);
 
     // C - ~X == X + (1+C)
     Value *X = 0;
@@ -2567,7 +2567,8 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
         Value *OtherOp = Op1I->getOperand(Op1I->getOperand(0) == Op0);
 
         Value *NewNot =
-          InsertNewInstBefore(BinaryOperator::CreateNot(OtherOp, "B.not"), I);
+          InsertNewInstBefore(BinaryOperator::CreateNot(*Context, 
+                                                        OtherOp, "B.not"), I);
         return BinaryOperator::CreateAnd(Op0, NewNot);
       }
 
@@ -3219,7 +3220,7 @@ Instruction *InstCombiner::visitURem(BinaryOperator &I) {
     if (RHSI->getOpcode() == Instruction::Shl &&
         isa<ConstantInt>(RHSI->getOperand(0))) {
       if (cast<ConstantInt>(RHSI->getOperand(0))->getValue().isPowerOf2()) {
-        Constant *N1 = Context->getConstantIntAllOnesValue(I.getType());
+        Constant *N1 = Context->getAllOnesValue(I.getType());
         Value *Add = InsertNewInstBefore(BinaryOperator::CreateAdd(RHSI, N1,
                                                                    "tmp"), I);
         return BinaryOperator::CreateAnd(Op0, Add);
@@ -4128,7 +4129,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
     Instruction *Or = BinaryOperator::CreateOr(Op0NotVal, Op1NotVal,
                                                I.getName()+".demorgan");
     InsertNewInstBefore(Or, I);
-    return BinaryOperator::CreateNot(Or);
+    return BinaryOperator::CreateNot(*Context, Or);
   }
   
   {
@@ -4174,7 +4175,7 @@ Instruction *InstCombiner::visitAnd(BinaryOperator &I) {
         std::swap(A, B);
       }
       if (A == Op0) {                                // A&(A^B) -> A & ~B
-        Instruction *NotB = BinaryOperator::CreateNot(B, "tmp");
+        Instruction *NotB = BinaryOperator::CreateNot(*Context, B, "tmp");
         InsertNewInstBefore(NotB, I);
         return BinaryOperator::CreateAnd(A, NotB);
       }
@@ -4902,7 +4903,7 @@ Instruction *InstCombiner::visitOr(BinaryOperator &I) {
     if (A && isOnlyUse(Op0) && isOnlyUse(Op1)) {
       Value *And = InsertNewInstBefore(BinaryOperator::CreateAnd(A, B,
                                               I.getName()+".demorgan"), I);
-      return BinaryOperator::CreateNot(And);
+      return BinaryOperator::CreateNot(*Context, And);
     }
   }
 
@@ -5056,7 +5057,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
         if (dyn_castNotVal(Op0I->getOperand(1), Context)) Op0I->swapOperands();
         if (Value *Op0NotVal = dyn_castNotVal(Op0I->getOperand(0), Context)) {
           Instruction *NotY =
-            BinaryOperator::CreateNot(Op0I->getOperand(1),
+            BinaryOperator::CreateNot(*Context, Op0I->getOperand(1),
                                       Op0I->getOperand(1)->getName()+".not");
           InsertNewInstBefore(NotY, I);
           if (Op0I->getOpcode() == Instruction::And)
@@ -5202,7 +5203,8 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
         std::swap(A, B);
       if (B == Op1) {                                // (A|B)^B == A & ~B
         Instruction *NotB =
-          InsertNewInstBefore(BinaryOperator::CreateNot(Op1, "tmp"), I);
+          InsertNewInstBefore(BinaryOperator::CreateNot(*Context, 
+                                                        Op1, "tmp"), I);
         return BinaryOperator::CreateAnd(A, NotB);
       }
     } else if (match(Op0I, m_Xor(m_Specific(Op1), m_Value(B)), *Context)) {
@@ -5216,7 +5218,7 @@ Instruction *InstCombiner::visitXor(BinaryOperator &I) {
       if (B == Op1 &&                                      // (B&A)^A == ~B & A
           !isa<ConstantInt>(Op1)) {  // Canonical form is (B&C)^C
         Instruction *N =
-          InsertNewInstBefore(BinaryOperator::CreateNot(A, "tmp"), I);
+          InsertNewInstBefore(BinaryOperator::CreateNot(*Context, A, "tmp"), I);
         return BinaryOperator::CreateAnd(N, Op1);
       }
     }
@@ -6006,7 +6008,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
     case ICmpInst::ICMP_EQ: {               // icmp eq i1 A, B -> ~(A^B)
       Instruction *Xor = BinaryOperator::CreateXor(Op0, Op1, I.getName()+"tmp");
       InsertNewInstBefore(Xor, I);
-      return BinaryOperator::CreateNot(Xor);
+      return BinaryOperator::CreateNot(*Context, Xor);
     }
     case ICmpInst::ICMP_NE:                  // icmp eq i1 A, B -> A^B
       return BinaryOperator::CreateXor(Op0, Op1);
@@ -6015,7 +6017,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
       std::swap(Op0, Op1);                   // Change icmp ugt -> icmp ult
       // FALL THROUGH
     case ICmpInst::ICMP_ULT:{               // icmp ult i1 A, B -> ~A & B
-      Instruction *Not = BinaryOperator::CreateNot(Op0, I.getName()+"tmp");
+      Instruction *Not = BinaryOperator::CreateNot(*Context,
+                                                   Op0, I.getName()+"tmp");
       InsertNewInstBefore(Not, I);
       return BinaryOperator::CreateAnd(Not, Op1);
     }
@@ -6023,7 +6026,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
       std::swap(Op0, Op1);                   // Change icmp sgt -> icmp slt
       // FALL THROUGH
     case ICmpInst::ICMP_SLT: {               // icmp slt i1 A, B -> A & ~B
-      Instruction *Not = BinaryOperator::CreateNot(Op1, I.getName()+"tmp");
+      Instruction *Not = BinaryOperator::CreateNot(*Context, 
+                                                   Op1, I.getName()+"tmp");
       InsertNewInstBefore(Not, I);
       return BinaryOperator::CreateAnd(Not, Op0);
     }
@@ -6031,7 +6035,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
       std::swap(Op0, Op1);                   // Change icmp uge -> icmp ule
       // FALL THROUGH
     case ICmpInst::ICMP_ULE: {               //  icmp ule i1 A, B -> ~A | B
-      Instruction *Not = BinaryOperator::CreateNot(Op0, I.getName()+"tmp");
+      Instruction *Not = BinaryOperator::CreateNot(*Context,
+                                                   Op0, I.getName()+"tmp");
       InsertNewInstBefore(Not, I);
       return BinaryOperator::CreateOr(Not, Op1);
     }
@@ -6039,7 +6044,8 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
       std::swap(Op0, Op1);                   // Change icmp sge -> icmp sle
       // FALL THROUGH
     case ICmpInst::ICMP_SLE: {               //  icmp sle i1 A, B -> A | ~B
-      Instruction *Not = BinaryOperator::CreateNot(Op1, I.getName()+"tmp");
+      Instruction *Not = BinaryOperator::CreateNot(*Context,
+                                                   Op1, I.getName()+"tmp");
       InsertNewInstBefore(Not, I);
       return BinaryOperator::CreateOr(Not, Op0);
     }
@@ -6168,7 +6174,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
         // (x <u 2147483648) -> (x >s -1)  -> true if sign bit clear
         if (CI->isMinValue(true))
           return new ICmpInst(*Context, ICmpInst::ICMP_SGT, Op0,
-                           Context->getConstantIntAllOnesValue(Op0->getType()));
+                           Context->getAllOnesValue(Op0->getType()));
       }
       break;
     case ICmpInst::ICMP_UGT:
@@ -7298,7 +7304,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
     if (isSignedExt) {
       // We're performing an unsigned comp with a sign extended value.
       // This is true if the input is >= 0. [aka >s -1]
-      Constant *NegOne = Context->getConstantIntAllOnesValue(SrcTy);
+      Constant *NegOne = Context->getAllOnesValue(SrcTy);
       Result = InsertNewInstBefore(new ICmpInst(*Context, ICmpInst::ICMP_SGT, 
                                    LHSCIOp, NegOne, ICI.getName()), ICI);
     } else {
@@ -7317,7 +7323,7 @@ Instruction *InstCombiner::visitICmpInstWithCastAndCast(ICmpInst &ICI) {
          "ICmp should be folded!");
   if (Constant *CI = dyn_cast<Constant>(Result))
     return ReplaceInstUsesWith(ICI, Context->getConstantExprNot(CI));
-  return BinaryOperator::CreateNot(Result);
+  return BinaryOperator::CreateNot(*Context, Result);
 }
 
 Instruction *InstCombiner::visitShl(BinaryOperator &I) {
@@ -8718,7 +8724,7 @@ Instruction *InstCombiner::visitSExt(SExtInst &CI) {
   // Canonicalize sign-extend from i1 to a select.
   if (Src->getType() == Type::Int1Ty)
     return SelectInst::Create(Src,
-                              Context->getConstantIntAllOnesValue(CI.getType()),
+                              Context->getAllOnesValue(CI.getType()),
                               Context->getNullValue(CI.getType()));
 
   // See if the value being truncated is already sign extended.  If so, just
@@ -9373,7 +9379,7 @@ Instruction *InstCombiner::visitSelectInstWithICmp(SelectInst &SI,
                                              true/*SExt*/, "tmp", ICI);
     
           if (Pred == ICmpInst::ICMP_SGT)
-            In = InsertNewInstBefore(BinaryOperator::CreateNot(In,
+            In = InsertNewInstBefore(BinaryOperator::CreateNot(*Context, In,
                                        In->getName()+".not"), *ICI);
     
           return ReplaceInstUsesWith(SI, In);
@@ -9438,7 +9444,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
       } else {
         // Change: A = select B, false, C --> A = and !B, C
         Value *NotCond =
-          InsertNewInstBefore(BinaryOperator::CreateNot(CondVal,
+          InsertNewInstBefore(BinaryOperator::CreateNot(*Context, CondVal,
                                              "not."+CondVal->getName()), SI);
         return BinaryOperator::CreateAnd(NotCond, FalseVal);
       }
@@ -9449,7 +9455,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
       } else {
         // Change: A = select B, C, true --> A = or !B, C
         Value *NotCond =
-          InsertNewInstBefore(BinaryOperator::CreateNot(CondVal,
+          InsertNewInstBefore(BinaryOperator::CreateNot(*Context, CondVal,
                                              "not."+CondVal->getName()), SI);
         return BinaryOperator::CreateOr(NotCond, TrueVal);
       }
@@ -9472,7 +9478,7 @@ Instruction *InstCombiner::visitSelectInst(SelectInst &SI) {
       } else if (TrueValC->isZero() && FalseValC->getValue() == 1) {
         // select C, 0, 1 -> zext !C to int
         Value *NotCond =
-          InsertNewInstBefore(BinaryOperator::CreateNot(CondVal,
+          InsertNewInstBefore(BinaryOperator::CreateNot(*Context, CondVal,
                                                "not."+CondVal->getName()), SI);
         return CastInst::Create(Instruction::ZExt, NotCond, SI.getType());
       }
index 24ac7bf30b703d242a5407b843335e23cb458b42..4116c66dbaf7b9597ca6fff7aff0fb943f49f050 100644 (file)
@@ -1754,7 +1754,7 @@ namespace {
         switch (BO->getOpcode()) {
           case Instruction::And: {
             // "and i32 %a, %b" EQ -1 then %a EQ -1 and %b EQ -1
-            ConstantInt *CI = ConstantInt::getAllOnesValue(Ty);
+            ConstantInt *CI = cast<ConstantInt>(Context->getAllOnesValue(Ty));
             if (Canonical == CI) {
               add(CI, Op0, ICmpInst::ICMP_EQ, NewContext);
               add(CI, Op1, ICmpInst::ICMP_EQ, NewContext);
@@ -1892,7 +1892,7 @@ namespace {
 
         Constant *Zero = Context->getNullValue(Ty);
         Constant *One = ConstantInt::get(Ty, 1);
-        ConstantInt *AllOnes = ConstantInt::getAllOnesValue(Ty);
+        ConstantInt *AllOnes = cast<ConstantInt>(Context->getAllOnesValue(Ty));
 
         switch (Opcode) {
           default: break;
index 054e09d3c5b7b5de0d2a64b64500a712434e93bb..6465fc1b96e0f6e94eefd9ea4dc40919bdfa0ad4 100644 (file)
@@ -201,7 +201,7 @@ static BinaryOperator *isReassociableOp(Value *V, unsigned Opcode) {
 static Instruction *LowerNegateToMultiply(Instruction *Neg,
                               std::map<AssertingVH<>, unsigned> &ValueRankMap,
                               LLVMContext *Context) {
-  Constant *Cst = Context->getConstantIntAllOnesValue(Neg->getType());
+  Constant *Cst = Context->getAllOnesValue(Neg->getType());
 
   Instruction *Res = BinaryOperator::CreateMul(Neg->getOperand(1), Cst, "",Neg);
   ValueRankMap.erase(Neg);
@@ -626,7 +626,7 @@ Value *Reassociate::OptimizeExpression(BinaryOperator *I,
             return Context->getNullValue(X->getType());
           } else if (Opcode == Instruction::Or) {   // ...|X|~X = -1
             ++NumAnnihil;
-            return Context->getConstantIntAllOnesValue(X->getType());
+            return Context->getAllOnesValue(X->getType());
           }
         }
       }
index e521be2db253a95a03e7518fa39d1081c81cae0c..830895c790e568bfe06f12f3863478ecfc89ce01 100644 (file)
@@ -814,10 +814,10 @@ void SCCPSolver::visitBinaryOperator(Instruction &I) {
           if (I.getOpcode() == Instruction::And)
             markConstant(IV, &I, Context->getNullValue(I.getType()));
           else if (const VectorType *PT = dyn_cast<VectorType>(I.getType()))
-            markConstant(IV, &I, Context->getConstantVectorAllOnesValue(PT));
+            markConstant(IV, &I, Context->getAllOnesValue(PT));
           else
             markConstant(IV, &I,
-                         Context->getConstantIntAllOnesValue(I.getType()));
+                         Context->getAllOnesValue(I.getType()));
           return;
         } else {
           if (I.getOpcode() == Instruction::And) {
@@ -1388,9 +1388,9 @@ bool SCCPSolver::ResolvedUndefsIn(Function &F) {
         // undef | X -> -1.   X could be -1.
         if (const VectorType *PTy = dyn_cast<VectorType>(ITy))
           markForcedConstant(LV, I,
-                             Context->getConstantVectorAllOnesValue(PTy));
+                             Context->getAllOnesValue(PTy));
         else          
-          markForcedConstant(LV, I, Context->getConstantIntAllOnesValue(ITy));
+          markForcedConstant(LV, I, Context->getAllOnesValue(ITy));
         return true;
 
       case Instruction::SDiv:
index a2f9a82f334e2a877db86b61fb2afc69a2b747e5..8a28ca23b1b2c78bd997fd53eb196666a2447759 100644 (file)
@@ -1225,7 +1225,7 @@ struct VISIBILITY_HIDDEN AbsOpt : public LibCallOptimization {
     // abs(x) -> x >s -1 ? x : -x
     Value *Op = CI->getOperand(1);
     Value *Pos = B.CreateICmpSGT(Op, 
-                             Context->getConstantIntAllOnesValue(Op->getType()),
+                             Context->getAllOnesValue(Op->getType()),
                                  "ispos");
     Value *Neg = B.CreateNeg(Op, "neg");
     return B.CreateSelect(Pos, Op, Neg);
index a898d2df2bb6ff7230cc182dcca5e02f39952034..55e1bf225c2ef1fb0554279e0246f3fe08d48161 100644 (file)
@@ -1570,7 +1570,8 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI) {
     // If we need to invert the condition in the pred block to match, do so now.
     if (InvertPredCond) {
       Value *NewCond =
-        BinaryOperator::CreateNot(PBI->getCondition(),
+        BinaryOperator::CreateNot(*BI->getParent()->getContext(), 
+                                  PBI->getCondition(), 
                                   PBI->getCondition()->getName()+".not", PBI);
       PBI->setCondition(NewCond);
       BasicBlock *OldTrue = PBI->getSuccessor(0);
@@ -1726,12 +1727,12 @@ static bool SimplifyCondBranchToCondBranch(BranchInst *PBI, BranchInst *BI) {
   // Make sure we get to CommonDest on True&True directions.
   Value *PBICond = PBI->getCondition();
   if (PBIOp)
-    PBICond = BinaryOperator::CreateNot(PBICond,
+    PBICond = BinaryOperator::CreateNot(*Context, PBICond,
                                         PBICond->getName()+".not",
                                         PBI);
   Value *BICond = BI->getCondition();
   if (BIOp)
-    BICond = BinaryOperator::CreateNot(BICond,
+    BICond = BinaryOperator::CreateNot(*Context, BICond,
                                        BICond->getName()+".not",
                                        PBI);
   // Merge the conditions.
index f8ae2bd79f484ae04e915f19f1bb25e112379f09..a1b4c93268d58bd26130038b810f7f02497283ac 100644 (file)
@@ -128,31 +128,6 @@ bool Constant::ContainsRelocations(unsigned Kind) const {
   return false;
 }
 
-Constant *Constant::getAllOnesValue(const Type *Ty) {
-  if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
-    return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
-  return ConstantVector::getAllOnesValue(cast<VectorType>(Ty));
-}
-
-// Static constructor to create an integral constant with all bits set
-ConstantInt *ConstantInt::getAllOnesValue(const Type *Ty) {
-  if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
-    return ConstantInt::get(APInt::getAllOnesValue(ITy->getBitWidth()));
-  return 0;
-}
-
-/// @returns the value for a vector integer constant of the given type that
-/// has all its bits set to true.
-/// @brief Get the all ones value
-ConstantVector *ConstantVector::getAllOnesValue(const VectorType *Ty) {
-  std::vector<Constant*> Elts;
-  Elts.resize(Ty->getNumElements(),
-              ConstantInt::getAllOnesValue(Ty->getElementType()));
-  assert(Elts[0] && "Not a vector integer type!");
-  return cast<ConstantVector>(ConstantVector::get(Elts));
-}
-
-
 /// getVectorElements - This method, which is only valid on constant of vector
 /// type, returns the elements of the vector in the specified smallvector.
 /// This handles breaking down a vector undef into undef elements, etc.  For
@@ -797,12 +772,6 @@ const SmallVector<unsigned, 4> &ConstantExpr::getIndices() const {
   return cast<InsertValueConstantExpr>(this)->Indices;
 }
 
-Constant *ConstantExpr::getNot(Constant *C) {
-  assert(C->getType()->isIntOrIntVector() &&
-         "Cannot NOT a nonintegral value!");
-  return get(Instruction::Xor, C,
-             Constant::getAllOnesValue(C->getType()));
-}
 Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2) {
   return get(Instruction::Add, C1, C2);
 }
index 74bcc100417eb74576cab7a20af068ea0d69d6db..7c98d213aed002f062d2ef7d055fd5132f58a14d 100644 (file)
@@ -1669,30 +1669,32 @@ BinaryOperator *BinaryOperator::CreateFNeg(LLVMContext &Context,
                             Op->getType(), Name, InsertAtEnd);
 }
 
-BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
+                                          Value *Op, const std::string &Name,
                                           Instruction *InsertBefore) {
   Constant *C;
   if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
-    C = ConstantInt::getAllOnesValue(PTy->getElementType());
+    C = Context.getAllOnesValue(PTy->getElementType());
     C = ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), C));
   } else {
-    C = ConstantInt::getAllOnesValue(Op->getType());
+    C = Context.getAllOnesValue(Op->getType());
   }
   
   return new BinaryOperator(Instruction::Xor, Op, C,
                             Op->getType(), Name, InsertBefore);
 }
 
-BinaryOperator *BinaryOperator::CreateNot(Value *Op, const std::string &Name,
+BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
+                                          Value *Op, const std::string &Name,
                                           BasicBlock *InsertAtEnd) {
   Constant *AllOnes;
   if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
     // Create a vector of all ones values.
-    Constant *Elt = ConstantInt::getAllOnesValue(PTy->getElementType());
+    Constant *Elt = Context.getAllOnesValue(PTy->getElementType());
     AllOnes = 
       ConstantVector::get(std::vector<Constant*>(PTy->getNumElements(), Elt));
   } else {
-    AllOnes = ConstantInt::getAllOnesValue(Op->getType());
+    AllOnes = Context.getAllOnesValue(Op->getType());
   }
   
   return new BinaryOperator(Instruction::Xor, Op, AllOnes,
index a8a8928cdfe605bf2949bbe26ef2230eccb7de8e..a7df2affe3123632300e4bc1674fb710ac7ec9cb 100644 (file)
@@ -64,7 +64,14 @@ Constant* LLVMContext::getNullValue(const Type* Ty) {
 }
 
 Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
-  return Constant::getAllOnesValue(Ty);
+  if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
+    return getConstantInt(APInt::getAllOnesValue(ITy->getBitWidth()));
+  
+  std::vector<Constant*> Elts;
+  const VectorType* VTy = cast<VectorType>(Ty);
+  Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
+  assert(Elts[0] && "Not a vector integer type!");
+  return cast<ConstantVector>(getConstantVector(Elts));
 }
 
 // UndefValue accessors.
@@ -105,11 +112,6 @@ Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
   return ConstantInt::get(Ty, V);
 }
 
-ConstantInt* LLVMContext::getConstantIntAllOnesValue(const Type* Ty) {
-  return ConstantInt::getAllOnesValue(Ty);
-}
-
-
 // ConstantPointerNull accessors.
 ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
   return ConstantPointerNull::get(T);
@@ -285,7 +287,9 @@ Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
 }
 
 Constant* LLVMContext::getConstantExprNot(Constant* C) {
-  return ConstantExpr::getNot(C);
+  assert(C->getType()->isIntOrIntVector() &&
+         "Cannot NOT a nonintegral value!");
+  return getConstantExpr(Instruction::Xor, C, getAllOnesValue(C->getType()));
 }
 
 Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
@@ -464,11 +468,6 @@ Constant* LLVMContext::getConstantVector(Constant* const* Vals,
   return ConstantVector::get(Vals, NumVals);
 }
 
-ConstantVector* LLVMContext::getConstantVectorAllOnesValue(
-                                                         const VectorType* Ty) {
-  return ConstantVector::getAllOnesValue(Ty);
-}
-
 // MDNode accessors
 MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
   return MDNode::get(Vals, NumVals);