Move more code back to 2.5 APIs.
authorOwen Anderson <resistor@mac.com>
Thu, 30 Jul 2009 23:03:37 +0000 (23:03 +0000)
committerOwen Anderson <resistor@mac.com>
Thu, 30 Jul 2009 23:03:37 +0000 (23:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77635 91177308-0d34-0410-b5e6-96231b3b80d8

47 files changed:
include/llvm/Constants.h
include/llvm/LLVMContext.h
include/llvm/Support/IRBuilder.h
lib/Analysis/ConstantFolding.cpp
lib/Analysis/DebugInfo.cpp
lib/Analysis/ValueTracking.cpp
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/Transforms/IPO/DeadArgumentElimination.cpp
lib/Transforms/IPO/GlobalOpt.cpp
lib/Transforms/IPO/IPConstantPropagation.cpp
lib/Transforms/IPO/LowerSetJmp.cpp
lib/Transforms/IPO/PruneEH.cpp
lib/Transforms/IPO/RaiseAllocations.cpp
lib/Transforms/IPO/StripSymbols.cpp
lib/Transforms/Instrumentation/ProfilingUtils.cpp
lib/Transforms/Scalar/GVN.cpp
lib/Transforms/Scalar/IndVarSimplify.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/JumpThreading.cpp
lib/Transforms/Scalar/LICM.cpp
lib/Transforms/Scalar/LoopUnswitch.cpp
lib/Transforms/Scalar/Reassociate.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp
lib/Transforms/Scalar/SimplifyCFGPass.cpp
lib/Transforms/Utils/BasicBlockUtils.cpp
lib/Transforms/Utils/CloneFunction.cpp
lib/Transforms/Utils/InlineFunction.cpp
lib/Transforms/Utils/LCSSA.cpp
lib/Transforms/Utils/Local.cpp
lib/Transforms/Utils/LoopSimplify.cpp
lib/Transforms/Utils/PromoteMemoryToRegister.cpp
lib/Transforms/Utils/SimplifyCFG.cpp
lib/VMCore/AutoUpgrade.cpp
lib/VMCore/BasicBlock.cpp
lib/VMCore/ConstantFold.cpp
lib/VMCore/Constants.cpp
lib/VMCore/Core.cpp
lib/VMCore/Instructions.cpp
lib/VMCore/LLVMContext.cpp
lib/VMCore/LLVMContextImpl.cpp
lib/VMCore/LLVMContextImpl.h
tools/bugpoint/ExtractFunction.cpp
tools/bugpoint/Miscompilation.cpp
unittests/VMCore/ConstantsTest.cpp

index e8ecfa3bada4a915e4c45c311d19cf515d5c24c5..dfcc707b5e3c3019b8524dcb252d75cbe94e1f0b 100644 (file)
@@ -305,6 +305,8 @@ protected:
     return User::operator new(s, 0);
   }
 public:
+  static ConstantAggregateZero* get(const Type* Ty);
+  
   /// isNullValue - Return true if this is the value that would be returned by
   /// getNullValue.
   virtual bool isNullValue() const { return true; }
index 00a6581dab06bd57c66b21abb254d5e35511b119..ab2df1b70ae46e2406f007d08d0a0f0398cada44 100644 (file)
@@ -60,6 +60,7 @@ class LLVMContext {
   friend class ConstantStruct;
   friend class ConstantArray;
   friend class ConstantVector;
+  friend class ConstantAggregateZero;
 public:
   LLVMContext();
   ~LLVMContext();
@@ -72,19 +73,10 @@ public:
   /// @brief Get the all ones value
   Constant* getAllOnesValue(const Type* Ty);
   
-  // UndefValue accessors
-  UndefValue* getUndef(const Type* Ty);
-  
   // ConstantInt accessors
   ConstantInt* getTrue();
   ConstantInt* getFalse();
-  
-  // ConstantPointerNull accessors
-  ConstantPointerNull* getConstantPointerNull(const PointerType* T);
-                              
-  // ConstantAggregateZero accessors
-  ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
-                             
+        
   // MDNode accessors
   MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
   
@@ -95,7 +87,6 @@ public:
   // Methods for erasing constants
   void erase(MDString *M);
   void erase(MDNode *M);
-  void erase(ConstantAggregateZero *Z);
 };
 
 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
index 058a9bbd1edb29d4bb1ffec12687655ed2b02005..223fe028e209376013a4f8a502c058ec765f2c8e 100644 (file)
@@ -146,7 +146,7 @@ public:
   ///
   ReturnInst *CreateAggregateRet(Value * const* retVals, unsigned N) {
     const Type *RetType = BB->getParent()->getReturnType();
-    Value *V = Context.getUndef(RetType);
+    Value *V = UndefValue::get(RetType);
     for (unsigned i = 0; i != N; ++i)
       V = CreateInsertValue(V, retVals[i], i, "mrv");
     return Insert(ReturnInst::Create(V));
index 126f850331026bae4a89b006ae196cd3e98b9633..12ef0174e4a2907538361991ba4778e489fd373f 100644 (file)
@@ -286,7 +286,7 @@ Constant *llvm::ConstantFoldInstruction(Instruction *I, LLVMContext &Context,
                                         const TargetData *TD) {
   if (PHINode *PN = dyn_cast<PHINode>(I)) {
     if (PN->getNumIncomingValues() == 0)
-      return Context.getUndef(PN->getType());
+      return UndefValue::get(PN->getType());
 
     Constant *Result = dyn_cast<Constant>(PN->getIncomingValue(0));
     if (Result == 0) return 0;
@@ -560,7 +560,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
       } else if (isa<ConstantAggregateZero>(C)) {
         C = Context.getNullValue(STy->getElementType(El));
       } else if (isa<UndefValue>(C)) {
-        C = Context.getUndef(STy->getElementType(El));
+        C = UndefValue::get(STy->getElementType(El));
       } else {
         return 0;
       }
@@ -573,7 +573,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
         else if (isa<ConstantAggregateZero>(C))
           C = Context.getNullValue(ATy->getElementType());
         else if (isa<UndefValue>(C))
-          C = Context.getUndef(ATy->getElementType());
+          C = UndefValue::get(ATy->getElementType());
         else
           return 0;
       } else if (const VectorType *PTy = dyn_cast<VectorType>(*I)) {
@@ -584,7 +584,7 @@ Constant *llvm::ConstantFoldLoadThroughGEPConstantExpr(Constant *C,
         else if (isa<ConstantAggregateZero>(C))
           C = Context.getNullValue(PTy->getElementType());
         else if (isa<UndefValue>(C))
-          C = Context.getUndef(PTy->getElementType());
+          C = UndefValue::get(PTy->getElementType());
         else
           return 0;
       } else {
index 635b6b9ee84d88044fed5847fbcad55eb6eccc7b..18996232870402b7e91ae8e4075f5e77ff99a19a 100644 (file)
@@ -497,7 +497,7 @@ Constant *DIFactory::GetStringConstant(const std::string &String) {
   
   // If empty string then use a i8* null instead.
   if (String.empty())
-    return Slot = VMContext.getConstantPointerNull(DestTy);
+    return Slot = ConstantPointerNull::get(DestTy);
 
   // Construct string as an llvm constant.
   Constant *ConstStr = ConstantArray::get(String);
index fcb81889e040feb3863c5f66500e8858b074e574..70f11f4f72ae9ca4322e2e5d6007b29b4b96f74f 100644 (file)
@@ -884,7 +884,7 @@ Value *BuildSubAggregate(Value *From, const unsigned *idx_begin,
   const Type *IndexedType = ExtractValueInst::getIndexedType(From->getType(),
                                                              idx_begin,
                                                              idx_end);
-  Value *To = Context.getUndef(IndexedType);
+  Value *To = UndefValue::get(IndexedType);
   SmallVector<unsigned, 10> Idxs(idx_begin, idx_end);
   unsigned IdxSkip = Idxs.size();
 
@@ -913,7 +913,7 @@ Value *llvm::FindInsertedValue(Value *V, const unsigned *idx_begin,
   const CompositeType *PTy = cast<CompositeType>(V->getType());
 
   if (isa<UndefValue>(V))
-    return Context.getUndef(ExtractValueInst::getIndexedType(PTy,
+    return UndefValue::get(ExtractValueInst::getIndexedType(PTy,
                                                               idx_begin,
                                                               idx_end));
   else if (isa<ConstantAggregateZero>(V))
index 359a733cd91450ee820bea3cccf86ec9a9e77643..d8ff4cc462b5339b2cf659c3a5fbd70d3beba0cb 100644 (file)
@@ -1481,7 +1481,7 @@ LLParser::PerFunctionState::~PerFunctionState() {
        I = ForwardRefVals.begin(), E = ForwardRefVals.end(); I != E; ++I)
     if (!isa<BasicBlock>(I->second.first)) {
       I->second.first->replaceAllUsesWith(
-                           P.getContext().getUndef(I->second.first->getType()));
+                           UndefValue::get(I->second.first->getType()));
       delete I->second.first;
       I->second.first = 0;
     }
@@ -1490,7 +1490,7 @@ LLParser::PerFunctionState::~PerFunctionState() {
        I = ForwardRefValIDs.begin(), E = ForwardRefValIDs.end(); I != E; ++I)
     if (!isa<BasicBlock>(I->second.first)) {
       I->second.first->replaceAllUsesWith(
-                           P.getContext().getUndef(I->second.first->getType()));
+                           UndefValue::get(I->second.first->getType()));
       delete I->second.first;
       I->second.first = 0;
     }
@@ -2193,19 +2193,19 @@ bool LLParser::ConvertGlobalValIDToValue(const Type *Ty, ValID &ID,
   case ValID::t_Null:
     if (!isa<PointerType>(Ty))
       return Error(ID.Loc, "null must be a pointer type");
-    V = Context.getConstantPointerNull(cast<PointerType>(Ty));
+    V = ConstantPointerNull::get(cast<PointerType>(Ty));
     return false;
   case ValID::t_Undef:
     // FIXME: LabelTy should not be a first-class type.
     if ((!Ty->isFirstClassType() || Ty == Type::LabelTy) &&
         !isa<OpaqueType>(Ty))
       return Error(ID.Loc, "invalid type for undef constant");
-    V = Context.getUndef(Ty);
+    V = UndefValue::get(Ty);
     return false;
   case ValID::t_EmptyArray:
     if (!isa<ArrayType>(Ty) || cast<ArrayType>(Ty)->getNumElements() != 0)
       return Error(ID.Loc, "invalid empty array initializer");
-    V = Context.getUndef(Ty);
+    V = UndefValue::get(Ty);
     return false;
   case ValID::t_Zero:
     // FIXME: LabelTy should not be a first-class type.
@@ -2764,7 +2764,7 @@ bool LLParser::ParseRet(Instruction *&Inst, BasicBlock *BB,
       RVs.push_back(RV);
     }
 
-    RV = Context.getUndef(PFS.getFunction().getReturnType());
+    RV = UndefValue::get(PFS.getFunction().getReturnType());
     for (unsigned i = 0, e = RVs.size(); i != e; ++i) {
       Instruction *I = InsertValueInst::Create(RV, RVs[i], i, "mrv");
       BB->getInstList().push_back(I);
index 35fe7b27c5258c9247991006c48dccbb10936766..a58e68f1837de8248de14aa1d8541514ead7f5b1 100644 (file)
@@ -142,7 +142,7 @@ namespace {
     }
     explicit ConstantPlaceHolder(const Type *Ty, LLVMContext& Context)
       : ConstantExpr(Ty, Instruction::UserOp1, &Op<0>(), 1) {
-      Op<0>() = Context.getUndef(Type::Int32Ty);
+      Op<0>() = UndefValue::get(Type::Int32Ty);
     }
     
     /// @brief Methods to support type inquiry through isa, cast, and dyn_cast.
@@ -888,7 +888,7 @@ bool BitcodeReader::ParseConstants() {
     switch (BitCode) {
     default:  // Default behavior: unknown constant
     case bitc::CST_CODE_UNDEF:     // UNDEF
-      V = Context.getUndef(CurTy);
+      V = UndefValue::get(CurTy);
       break;
     case bitc::CST_CODE_SETTYPE:   // SETTYPE: [typeid]
       if (Record.empty())
@@ -937,7 +937,7 @@ bool BitcodeReader::ParseConstants() {
       else if (CurTy == Type::PPC_FP128Ty)
         V = ConstantFP::get(Context, APFloat(APInt(128, 2, &Record[0])));
       else
-        V = Context.getUndef(CurTy);
+        V = UndefValue::get(CurTy);
       break;
     }
       
@@ -964,7 +964,7 @@ bool BitcodeReader::ParseConstants() {
           Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
         V = ConstantVector::get(Elts);
       } else {
-        V = Context.getUndef(CurTy);
+        V = UndefValue::get(CurTy);
       }
       break;
     }
@@ -1001,7 +1001,7 @@ bool BitcodeReader::ParseConstants() {
       if (Record.size() < 3) return Error("Invalid CE_BINOP record");
       int Opc = GetDecodedBinaryOpcode(Record[0], CurTy);
       if (Opc < 0) {
-        V = Context.getUndef(CurTy);  // Unknown binop.
+        V = UndefValue::get(CurTy);  // Unknown binop.
       } else {
         Constant *LHS = ValueList.getConstantFwdRef(Record[1], CurTy);
         Constant *RHS = ValueList.getConstantFwdRef(Record[2], CurTy);
@@ -1015,7 +1015,7 @@ bool BitcodeReader::ParseConstants() {
       if (Record.size() < 3) return Error("Invalid CE_CAST record");
       int Opc = GetDecodedCastOpcode(Record[0]);
       if (Opc < 0) {
-        V = Context.getUndef(CurTy);  // Unknown cast.
+        V = UndefValue::get(CurTy);  // Unknown cast.
       } else {
         const Type *OpTy = getTypeByID(Record[1]);
         if (!OpTy) return Error("Invalid CE_CAST record");
@@ -1780,7 +1780,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
         if (Vs.size() > 1 ||
             (isa<StructType>(ReturnType) &&
              (Vs.empty() || Vs[0]->getType() != ReturnType))) {
-          Value *RV = Context.getUndef(ReturnType);
+          Value *RV = UndefValue::get(ReturnType);
           for (unsigned i = 0, e = Vs.size(); i != e; ++i) {
             I = InsertValueInst::Create(RV, Vs[i], i, "mrv");
             CurBB->getInstList().push_back(I);
@@ -2060,7 +2060,7 @@ bool BitcodeReader::ParseFunctionBody(Function *F) {
       // We found at least one unresolved value.  Nuke them all to avoid leaks.
       for (unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){
         if ((A = dyn_cast<Argument>(ValueList.back())) && A->getParent() == 0) {
-          A->replaceAllUsesWith(Context.getUndef(A->getType()));
+          A->replaceAllUsesWith(UndefValue::get(A->getType()));
           delete A;
         }
       }
index 7293144b4e734b5b5b6ef24b86e5f540a7b65eba..189d2556b9e48e08943a10c860374316572c17ca 100644 (file)
@@ -1789,7 +1789,6 @@ SDValue SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) {
 /// ExpandBUILD_VECTOR - Expand a BUILD_VECTOR node on targets that don't
 /// support the operation, but do support the resultant vector type.
 SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
-  LLVMContext *Context = DAG.getContext();
   unsigned NumElems = Node->getNumOperands();
   SDValue Value1, Value2;
   DebugLoc dl = Node->getDebugLoc();
@@ -1840,7 +1839,7 @@ SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
       } else {
         assert(Node->getOperand(i).getOpcode() == ISD::UNDEF);
         const Type *OpNTy = OpVT.getTypeForMVT();
-        CV.push_back(Context->getUndef(OpNTy));
+        CV.push_back(UndefValue::get(OpNTy));
       }
     }
     Constant *CP = ConstantVector::get(CV);
index 0b7e9d987430b177f6cfca6173ef4332103c588a..fbdca723f64caeae9aa86d24f69d7f878bcb4749 100644 (file)
@@ -758,7 +758,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
       }
 
     if (ExtraArgHack)
-      Args.push_back(Context.getUndef(Type::Int32Ty));
+      Args.push_back(UndefValue::get(Type::Int32Ty));
 
     // Push any varargs arguments on the list. Don't forget their attributes.
     for (CallSite::arg_iterator E = CS.arg_end(); I != E; ++I, ++i) {
@@ -814,7 +814,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
         // extract/insertvalue chaining and let instcombine clean that up.
         //
         // Start out building up our return value from undef
-        Value *RetVal = Context.getUndef(RetTy);
+        Value *RetVal = UndefValue::get(RetTy);
         for (unsigned i = 0; i != RetCount; ++i)
           if (NewRetIdxs[i] != -1) {
             Value *V;
@@ -881,7 +881,7 @@ bool DAE::RemoveDeadStuffFromFunction(Function *F) {
           // clean that up.
           Value *OldRet = RI->getOperand(0);
           // Start out building up our return value from undef
-          RetVal = Context.getUndef(NRetTy);
+          RetVal = UndefValue::get(NRetTy);
           for (unsigned i = 0; i != RetCount; ++i)
             if (NewRetIdxs[i] != -1) {
               ExtractValueInst *EV = ExtractValueInst::Create(OldRet, i,
index e0e5b60b0efb8e192a5d0310d3ce77002eafa8ec..d2a53138cbcf743e692d852f62dd4816bf9715b4 100644 (file)
@@ -269,10 +269,10 @@ static Constant *getAggregateConstantElement(Constant *Agg, Constant *Idx,
   } else if (isa<UndefValue>(Agg)) {
     if (const StructType *STy = dyn_cast<StructType>(Agg->getType())) {
       if (IdxV < STy->getNumElements())
-        return Context.getUndef(STy->getElementType(IdxV));
+        return UndefValue::get(STy->getElementType(IdxV));
     } else if (const SequentialType *STy =
                dyn_cast<SequentialType>(Agg->getType())) {
-      return Context.getUndef(STy->getElementType());
+      return UndefValue::get(STy->getElementType());
     }
   }
   return 0;
@@ -844,7 +844,7 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV,
   // FIXME: This new global should have the alignment returned by malloc.  Code
   // could depend on malloc returning large alignment (on the mac, 16 bytes) but
   // this would only guarantee some lower alignment.
-  Constant *Init = Context.getUndef(MI->getAllocatedType());
+  Constant *Init = UndefValue::get(MI->getAllocatedType());
   GlobalVariable *NewGV = new GlobalVariable(*GV->getParent(), 
                                              MI->getAllocatedType(), false,
                                              GlobalValue::InternalLinkage, Init,
@@ -2056,7 +2056,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
         Elts.push_back(Context.getNullValue(STy->getElementType(i)));
     } else if (isa<UndefValue>(Init)) {
       for (unsigned i = 0, e = STy->getNumElements(); i != e; ++i)
-        Elts.push_back(Context.getUndef(STy->getElementType(i)));
+        Elts.push_back(UndefValue::get(STy->getElementType(i)));
     } else {
       llvm_unreachable("This code is out of sync with "
              " ConstantFoldLoadThroughGEPConstantExpr");
@@ -2083,7 +2083,7 @@ static Constant *EvaluateStoreInto(Constant *Init, Constant *Val,
       Constant *Elt = Context.getNullValue(ATy->getElementType());
       Elts.assign(ATy->getNumElements(), Elt);
     } else if (isa<UndefValue>(Init)) {
-      Constant *Elt = Context.getUndef(ATy->getElementType());
+      Constant *Elt = UndefValue::get(ATy->getElementType());
       Elts.assign(ATy->getNumElements(), Elt);
     } else {
       llvm_unreachable("This code is out of sync with "
@@ -2227,7 +2227,7 @@ static bool EvaluateFunction(Function *F, Constant *&RetVal,
       const Type *Ty = AI->getType()->getElementType();
       AllocaTmps.push_back(new GlobalVariable(Context, Ty, false,
                                               GlobalValue::InternalLinkage,
-                                              Context.getUndef(Ty),
+                                              UndefValue::get(Ty),
                                               AI->getName()));
       InstResult = AllocaTmps.back();     
     } else if (CallInst *CI = dyn_cast<CallInst>(CurInst)) {
index adb52426397915b9bad946a4a8989576bd4dfe79..4edecc2b23c2226059d620b9520b27fd08fa4a2d 100644 (file)
@@ -134,7 +134,7 @@ bool IPCP::PropagateConstantsIntoArguments(Function &F) {
       continue;
   
     Value *V = ArgumentConstants[i].first;
-    if (V == 0) V = F.getContext().getUndef(AI->getType());
+    if (V == 0) V = UndefValue::get(AI->getType());
     AI->replaceAllUsesWith(V);
     ++NumArgumentsProped;
     MadeChange = true;
@@ -167,9 +167,9 @@ bool IPCP::PropagateConstantReturn(Function &F) {
   const StructType *STy = dyn_cast<StructType>(F.getReturnType());
   if (STy)
     for (unsigned i = 0, e = STy->getNumElements(); i < e; ++i) 
-      RetVals.push_back(Context.getUndef(STy->getElementType(i)));
+      RetVals.push_back(UndefValue::get(STy->getElementType(i)));
   else
-    RetVals.push_back(Context.getUndef(F.getReturnType()));
+    RetVals.push_back(UndefValue::get(F.getReturnType()));
 
   unsigned NumNonConstant = 0;
   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB)
index d2837a30ed3f527ce021b0573979fb0d8239ff3e..3a65ac7a8f596ab6a1c26b705f4b13c0412f89c0 100644 (file)
@@ -289,8 +289,7 @@ void LowerSetJmp::TransformLongJmpCall(CallInst* Inst)
     Removed = &BB->back();
     // If the removed instructions have any users, replace them now.
     if (!Removed->use_empty())
-      Removed->replaceAllUsesWith(
-        Inst->getContext().getUndef(Removed->getType()));
+      Removed->replaceAllUsesWith(UndefValue::get(Removed->getType()));
     Removed->eraseFromParent();
   } while (Removed != Inst);
 
index a98a79346167753ecab0243bc99020eebad00347..d2a6530cd9edad2043d143f20c41c4e26a0b7e03 100644 (file)
@@ -243,7 +243,7 @@ void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
     } else if (InvokeInst *II = dyn_cast<InvokeInst>(I))
       CGN->removeCallEdgeFor(II);
     if (!I->use_empty())
-      I->replaceAllUsesWith(BB->getContext().getUndef(I->getType()));
+      I->replaceAllUsesWith(UndefValue::get(I->getType()));
   }
 
   // Get the list of successors of this block.
index 943d3cf1605d737701ab729fe4b3ad7d9624f4ab..0ef0991637983878ebfe70ed2a13bae70016f732 100644 (file)
@@ -142,8 +142,6 @@ bool RaiseAllocations::runOnModule(Module &M) {
   // Find the malloc/free prototypes...
   doInitialization(M);
   
-  LLVMContext &Context = M.getContext();
-
   bool Changed = false;
 
   // First, process all of the malloc calls...
@@ -233,7 +231,7 @@ bool RaiseAllocations::runOnModule(Module &M) {
 
           // Delete the old call site
           if (I->getType() != Type::VoidTy)
-            I->replaceAllUsesWith(Context.getUndef(I->getType()));
+            I->replaceAllUsesWith(UndefValue::get(I->getType()));
           I->eraseFromParent();
           Changed = true;
           ++NumRaised;
index f2b561da80a6743b856f0c1261378d4c76edf560..1bbda3cd22dba2989ecd4e6994ed73321dbc5336 100644 (file)
@@ -232,7 +232,7 @@ bool StripDebugInfo(Module &M) {
     if (!GV) continue;
     if (!GV->use_empty() && llvmUsedValues.count(I) == 0) {
       if (GV->getName().startswith("llvm.dbg")) {
-        GV->replaceAllUsesWith(M.getContext().getUndef(GV->getType()));
+        GV->replaceAllUsesWith(UndefValue::get(GV->getType()));
       }
     }
   }
index d5752b72d2dbbfadd5e256e48b6f66aad26b61d1..6e5b523d6c41485a375ea62eb1f1a10ed485f91d 100644 (file)
@@ -53,7 +53,7 @@ void llvm::InsertProfilingInitCall(Function *MainFn, const char *FnName,
   } else {
     // If this profiling instrumentation doesn't have a constant array, just
     // pass null.
-    Args[2] = Context.getConstantPointerNull(UIntPtr);
+    Args[2] = ConstantPointerNull::get(UIntPtr);
   }
   Args[3] = ConstantInt::get(Type::Int32Ty, NumElements);
 
index 0b0968af21c108234cde179a55db93f4881fbe3f..ea8108153ca7bb2ae451941baf3f61c5d68b3949 100644 (file)
@@ -798,7 +798,7 @@ Value *GVN::GetValueForBlock(BasicBlock *BB, Instruction* orig,
   // If the block is unreachable, just return undef, since this path
   // can't actually occur at runtime.
   if (!DT->isReachableFromEntry(BB))
-    return Phis[BB] = BB->getContext().getUndef(orig->getType());
+    return Phis[BB] = UndefValue::get(orig->getType());
   
   if (BasicBlock *Pred = BB->getSinglePredecessor()) {
     Value *ret = GetValueForBlock(Pred, orig, Phis);
@@ -985,8 +985,8 @@ bool GVN::processNonLocalLoad(LoadInst *LI,
     
     // Loading the allocation -> undef.
     if (isa<AllocationInst>(DepInst)) {
-      ValuesPerBlock.push_back(std::make_pair(DepBB, 
-                                DepBB->getContext().getUndef(LI->getType())));
+      ValuesPerBlock.push_back(std::make_pair(DepBB,  
+                               UndefValue::get(LI->getType())));
       continue;
     }
   
@@ -1273,7 +1273,7 @@ bool GVN::processLoad(LoadInst *L, SmallVectorImpl<Instruction*> &toErase) {
   // undef value.  This can happen when loading for a fresh allocation with no
   // intervening stores, for example.
   if (isa<AllocationInst>(DepInst)) {
-    L->replaceAllUsesWith(DepInst->getContext().getUndef(L->getType()));
+    L->replaceAllUsesWith(UndefValue::get(L->getType()));
     toErase.push_back(L);
     NumGVNLoad++;
     return true;
index a4b7da23d41bc6985665409973ce2a0bbc4017b3..b33c805903b3dd059eac959074f89da95df8028a 100644 (file)
@@ -713,8 +713,6 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) {
   }
   if (NewPred == CmpInst::BAD_ICMP_PREDICATE) return;
 
-  LLVMContext &Context = PH->getContext();
-
   // Insert new integer induction variable.
   PHINode *NewPHI = PHINode::Create(Type::Int32Ty,
                                     PH->getName()+".int", PH);
@@ -745,7 +743,7 @@ void IndVarSimplify::HandleFloatingPointIV(Loop *L, PHINode *PH) {
   RecursivelyDeleteTriviallyDeadInstructions(EC);
 
   // Delete old, floating point, increment instruction.
-  Incr->replaceAllUsesWith(Context.getUndef(Incr->getType()));
+  Incr->replaceAllUsesWith(UndefValue::get(Incr->getType()));
   RecursivelyDeleteTriviallyDeadInstructions(Incr);
 
   // Replace floating induction variable, if it isn't already deleted.
index 554591ac252ef8424aa60412f872cf5611c71472..e0dfe29e0fe605a3c3b5d95cb69c62146b7def1e 100644 (file)
@@ -147,7 +147,7 @@ namespace {
         if (Instruction *Op = dyn_cast<Instruction>(*i)) {
           AddToWorkList(Op);
           // Set the operand to undef to drop the use.
-          *i = Context->getUndef(Op->getType());
+          *i = UndefValue::get(Op->getType());
         }
       
       return R;
@@ -312,7 +312,7 @@ namespace {
       } else {
         // If we are replacing the instruction with itself, this must be in a
         // segment of unreachable code, so just clobber the instruction.
-        I.replaceAllUsesWith(Context->getUndef(I.getType()));
+        I.replaceAllUsesWith(UndefValue::get(I.getType()));
         return &I;
       }
     }
@@ -815,7 +815,7 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
   if (DemandedMask == 0) {   // Not demanding any bits from V.
     if (isa<UndefValue>(V))
       return 0;
-    return Context->getUndef(VTy);
+    return UndefValue::get(VTy);
   }
   
   if (Depth == 6)        // Limit search depth.
@@ -1437,13 +1437,13 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
     return 0;
   } else if (DemandedElts == 0) { // If nothing is demanded, provide undef.
     UndefElts = EltMask;
-    return Context->getUndef(V->getType());
+    return UndefValue::get(V->getType());
   }
 
   UndefElts = 0;
   if (ConstantVector *CP = dyn_cast<ConstantVector>(V)) {
     const Type *EltTy = cast<VectorType>(V->getType())->getElementType();
-    Constant *Undef = Context->getUndef(EltTy);
+    Constant *Undef = UndefValue::get(EltTy);
 
     std::vector<Constant*> Elts;
     for (unsigned i = 0; i != VWidth; ++i)
@@ -1471,7 +1471,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
     
     const Type *EltTy = cast<VectorType>(V->getType())->getElementType();
     Constant *Zero = Context->getNullValue(EltTy);
-    Constant *Undef = Context->getUndef(EltTy);
+    Constant *Undef = UndefValue::get(EltTy);
     std::vector<Constant*> Elts;
     for (unsigned i = 0; i != VWidth; ++i) {
       Constant *Elt = DemandedElts[i] ? Zero : Undef;
@@ -1592,7 +1592,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
       std::vector<Constant*> Elts;
       for (unsigned i = 0; i < VWidth; ++i) {
         if (UndefElts[i])
-          Elts.push_back(Context->getUndef(Type::Int32Ty));
+          Elts.push_back(UndefValue::get(Type::Int32Ty));
         else
           Elts.push_back(ConstantInt::get(Type::Int32Ty,
                                           Shuffle->getMaskValue(i)));
@@ -1745,7 +1745,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
           
           Instruction *New =
             InsertElementInst::Create(
-              Context->getUndef(II->getType()), TmpV,
+              UndefValue::get(II->getType()), TmpV,
               ConstantInt::get(Type::Int32Ty, 0U, false), II->getName());
           InsertNewInstBefore(New, *II);
           AddSoonDeadInstToWorklist(*II, 0);
@@ -3138,7 +3138,7 @@ Instruction *InstCombiner::commonIRemTransforms(BinaryOperator &I) {
   if (ConstantInt *RHS = dyn_cast<ConstantInt>(Op1)) {
     // X % 0 == undef, we don't need to preserve faults!
     if (RHS->equalsInt(0))
-      return ReplaceInstUsesWith(I, Context->getUndef(I.getType()));
+      return ReplaceInstUsesWith(I, UndefValue::get(I.getType()));
     
     if (RHS->equalsInt(1))  // X % 1 == 0
       return ReplaceInstUsesWith(I, Context->getNullValue(I.getType()));
@@ -5907,7 +5907,7 @@ Instruction *InstCombiner::visitFCmpInst(FCmpInst &I) {
   }
     
   if (isa<UndefValue>(Op1))                  // fcmp pred X, undef -> undef
-    return ReplaceInstUsesWith(I, Context->getUndef(Type::Int1Ty));
+    return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
 
   // Handle fcmp with constant RHS
   if (Constant *RHSC = dyn_cast<Constant>(Op1)) {
@@ -5981,7 +5981,7 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
                                                    I.isTrueWhenEqual()));
 
   if (isa<UndefValue>(Op1))                  // X icmp undef -> undef
-    return ReplaceInstUsesWith(I, Context->getUndef(Type::Int1Ty));
+    return ReplaceInstUsesWith(I, UndefValue::get(Type::Int1Ty));
   
   // icmp <global/alloca*/null>, <global/alloca*/null> - Global/Stack value
   // addresses never equal each other!  We already know that Op0 != Op1.
@@ -8995,7 +8995,7 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) {
       if (!isa<VectorType>(SrcTy)) {
         Value *Elem = InsertCastBefore(Instruction::BitCast, Src,
                                        DestVTy->getElementType(), CI);
-        return InsertElementInst::Create(Context->getUndef(DestTy), Elem,
+        return InsertElementInst::Create(UndefValue::get(DestTy), Elem,
                                          Context->getNullValue(Type::Int32Ty));
       }
       // FIXME: Canonicalize bitcast(insertelement) -> insertelement(bitcast)
@@ -9936,7 +9936,7 @@ Instruction *InstCombiner::visitCallInst(CallInst &CI) {
         // Cast the input vectors to byte vectors.
         Value *Op0 =InsertBitCastBefore(II->getOperand(1),Mask->getType(),CI);
         Value *Op1 =InsertBitCastBefore(II->getOperand(2),Mask->getType(),CI);
-        Value *Result = Context->getUndef(Op0->getType());
+        Value *Result = UndefValue::get(Op0->getType());
         
         // Only extract each element once.
         Value *ExtractedElts[32];
@@ -10062,10 +10062,10 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
       // If the call and callee calling conventions don't match, this call must
       // be unreachable, as the call is undefined.
       new StoreInst(Context->getTrue(),
-                Context->getUndef(PointerType::getUnqual(Type::Int1Ty)), 
+                UndefValue::get(PointerType::getUnqual(Type::Int1Ty)), 
                                   OldCall);
       if (!OldCall->use_empty())
-        OldCall->replaceAllUsesWith(Context->getUndef(OldCall->getType()));
+        OldCall->replaceAllUsesWith(UndefValue::get(OldCall->getType()));
       if (isa<CallInst>(OldCall))   // Not worth removing an invoke here.
         return EraseInstFromFunction(*OldCall);
       return 0;
@@ -10076,12 +10076,12 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
     // undef so that we know that this code is not reachable, despite the fact
     // that we can't modify the CFG here.
     new StoreInst(Context->getTrue(),
-               Context->getUndef(PointerType::getUnqual(Type::Int1Ty)),
+               UndefValue::get(PointerType::getUnqual(Type::Int1Ty)),
                   CS.getInstruction());
 
     if (!CS.getInstruction()->use_empty())
       CS.getInstruction()->
-        replaceAllUsesWith(Context->getUndef(CS.getInstruction()->getType()));
+        replaceAllUsesWith(UndefValue::get(CS.getInstruction()->getType()));
 
     if (InvokeInst *II = dyn_cast<InvokeInst>(CS.getInstruction())) {
       // Don't break the CFG, insert a dummy cond branch.
@@ -10333,7 +10333,7 @@ bool InstCombiner::transformConstExprCastCall(CallSite CS) {
       }
       AddUsersToWorkList(*Caller);
     } else {
-      NV = Context->getUndef(Caller->getType());
+      NV = UndefValue::get(Caller->getType());
     }
   }
 
@@ -10921,7 +10921,7 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
       SmallPtrSet<PHINode*, 16> PotentiallyDeadPHIs;
       PotentiallyDeadPHIs.insert(&PN);
       if (DeadPHICycle(PU, PotentiallyDeadPHIs))
-        return ReplaceInstUsesWith(PN, Context->getUndef(PN.getType()));
+        return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType()));
     }
    
     // If this phi has a single use, and if that use just computes a value for
@@ -10933,7 +10933,7 @@ Instruction *InstCombiner::visitPHINode(PHINode &PN) {
     if (PHIUser->hasOneUse() &&
         (isa<BinaryOperator>(PHIUser) || isa<GetElementPtrInst>(PHIUser)) &&
         PHIUser->use_back() == &PN) {
-      return ReplaceInstUsesWith(PN, Context->getUndef(PN.getType()));
+      return ReplaceInstUsesWith(PN, UndefValue::get(PN.getType()));
     }
   }
 
@@ -10997,7 +10997,7 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
     return ReplaceInstUsesWith(GEP, PtrOp);
 
   if (isa<UndefValue>(GEP.getOperand(0)))
-    return ReplaceInstUsesWith(GEP, Context->getUndef(GEP.getType()));
+    return ReplaceInstUsesWith(GEP, UndefValue::get(GEP.getType()));
 
   bool HasZeroPointerIndex = false;
   if (Constant *C = dyn_cast<Constant>(GEP.getOperand(1)))
@@ -11426,7 +11426,7 @@ Instruction *InstCombiner::visitFreeInst(FreeInst &FI) {
   if (isa<UndefValue>(Op)) {
     // Insert a new store to null because we cannot modify the CFG here.
     new StoreInst(Context->getTrue(),
-           Context->getUndef(PointerType::getUnqual(Type::Int1Ty)), &FI);
+           UndefValue::get(PointerType::getUnqual(Type::Int1Ty)), &FI);
     return EraseInstFromFunction(FI);
   }
   
@@ -11587,9 +11587,9 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
       // that this code is not reachable.  We do this instead of inserting
       // an unreachable instruction directly because we cannot modify the
       // CFG.
-      new StoreInst(Context->getUndef(LI.getType()),
+      new StoreInst(UndefValue::get(LI.getType()),
                     Context->getNullValue(Op->getType()), &LI);
-      return ReplaceInstUsesWith(LI, Context->getUndef(LI.getType()));
+      return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
     }
   } 
 
@@ -11601,9 +11601,9 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
       // Insert a new store to null instruction before the load to indicate that
       // this code is not reachable.  We do this instead of inserting an
       // unreachable instruction directly because we cannot modify the CFG.
-      new StoreInst(Context->getUndef(LI.getType()),
+      new StoreInst(UndefValue::get(LI.getType()),
                     Context->getNullValue(Op->getType()), &LI);
-      return ReplaceInstUsesWith(LI, Context->getUndef(LI.getType()));
+      return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
     }
 
     // Instcombine load (constant global) into the value loaded.
@@ -11625,9 +11625,9 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
           // that this code is not reachable.  We do this instead of inserting
           // an unreachable instruction directly because we cannot modify the
           // CFG.
-          new StoreInst(Context->getUndef(LI.getType()),
+          new StoreInst(UndefValue::get(LI.getType()),
                         Context->getNullValue(Op->getType()), &LI);
-          return ReplaceInstUsesWith(LI, Context->getUndef(LI.getType()));
+          return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
         }
 
       } else if (CE->isCast()) {
@@ -11644,7 +11644,7 @@ Instruction *InstCombiner::visitLoadInst(LoadInst &LI) {
       if (GV->getInitializer()->isNullValue())
         return ReplaceInstUsesWith(LI, Context->getNullValue(LI.getType()));
       else if (isa<UndefValue>(GV->getInitializer()))
-        return ReplaceInstUsesWith(LI, Context->getUndef(LI.getType()));
+        return ReplaceInstUsesWith(LI, UndefValue::get(LI.getType()));
     }
   }
 
@@ -11941,7 +11941,7 @@ Instruction *InstCombiner::visitStoreInst(StoreInst &SI) {
   if (isa<ConstantPointerNull>(Ptr) &&
       cast<PointerType>(Ptr->getType())->getAddressSpace() == 0) {
     if (!isa<UndefValue>(Val)) {
-      SI.setOperand(0, Context->getUndef(Val->getType()));
+      SI.setOperand(0, UndefValue::get(Val->getType()));
       if (Instruction *U = dyn_cast<Instruction>(Val))
         AddToWorkList(U);  // Dropped a use.
       ++NumCombined;
@@ -12187,7 +12187,7 @@ Instruction *InstCombiner::visitExtractValueInst(ExtractValueInst &EV) {
 
   if (Constant *C = dyn_cast<Constant>(Agg)) {
     if (isa<UndefValue>(C))
-      return ReplaceInstUsesWith(EV, Context->getUndef(EV.getType()));
+      return ReplaceInstUsesWith(EV, UndefValue::get(EV.getType()));
       
     if (isa<ConstantAggregateZero>(C))
       return ReplaceInstUsesWith(EV, Context->getNullValue(EV.getType()));
@@ -12332,10 +12332,10 @@ static Value *FindScalarElement(Value *V, unsigned EltNo,
   const VectorType *PTy = cast<VectorType>(V->getType());
   unsigned Width = PTy->getNumElements();
   if (EltNo >= Width)  // Out of range access.
-    return Context->getUndef(PTy->getElementType());
+    return UndefValue::get(PTy->getElementType());
   
   if (isa<UndefValue>(V))
-    return Context->getUndef(PTy->getElementType());
+    return UndefValue::get(PTy->getElementType());
   else if (isa<ConstantAggregateZero>(V))
     return Context->getNullValue(PTy->getElementType());
   else if (ConstantVector *CP = dyn_cast<ConstantVector>(V))
@@ -12363,7 +12363,7 @@ static Value *FindScalarElement(Value *V, unsigned EltNo,
     else if (InEl < LHSWidth*2)
       return FindScalarElement(SVI->getOperand(1), InEl - LHSWidth, Context);
     else
-      return Context->getUndef(PTy->getElementType());
+      return UndefValue::get(PTy->getElementType());
   }
   
   // Otherwise, we don't know.
@@ -12373,7 +12373,7 @@ static Value *FindScalarElement(Value *V, unsigned EltNo,
 Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
   // If vector val is undef, replace extract with scalar undef.
   if (isa<UndefValue>(EI.getOperand(0)))
-    return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType()));
+    return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType()));
 
   // If vector val is constant 0, replace extract with scalar 0.
   if (isa<ConstantAggregateZero>(EI.getOperand(0)))
@@ -12403,7 +12403,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
     // If this is extracting an invalid index, turn this into undef, to avoid
     // crashing the code below.
     if (IndexVal >= VectorWidth)
-      return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType()));
+      return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType()));
     
     // This instruction only demands the single element from the input vector.
     // If the input vector has a single use, simplify it based on this use
@@ -12490,7 +12490,7 @@ Instruction *InstCombiner::visitExtractElementInst(ExtractElementInst &EI) {
           SrcIdx -= LHSWidth;
           Src = SVI->getOperand(1);
         } else {
-          return ReplaceInstUsesWith(EI, Context->getUndef(EI.getType()));
+          return ReplaceInstUsesWith(EI, UndefValue::get(EI.getType()));
         }
         return ExtractElementInst::Create(Src,
                          ConstantInt::get(Type::Int32Ty, SrcIdx, false));
@@ -12512,7 +12512,7 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
   unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
 
   if (isa<UndefValue>(V)) {
-    Mask.assign(NumElts, Context->getUndef(Type::Int32Ty));
+    Mask.assign(NumElts, UndefValue::get(Type::Int32Ty));
     return true;
   } else if (V == LHS) {
     for (unsigned i = 0; i != NumElts; ++i)
@@ -12537,7 +12537,7 @@ static bool CollectSingleShuffleElements(Value *V, Value *LHS, Value *RHS,
       // transitively ok.
       if (CollectSingleShuffleElements(VecOp, LHS, RHS, Mask, Context)) {
         // If so, update the mask to reflect the inserted undef.
-        Mask[InsertedIdx] = Context->getUndef(Type::Int32Ty);
+        Mask[InsertedIdx] = UndefValue::get(Type::Int32Ty);
         return true;
       }      
     } else if (ExtractElementInst *EI = dyn_cast<ExtractElementInst>(ScalarOp)){
@@ -12583,7 +12583,7 @@ static Value *CollectShuffleElements(Value *V, std::vector<Constant*> &Mask,
   unsigned NumElts = cast<VectorType>(V->getType())->getNumElements();
 
   if (isa<UndefValue>(V)) {
-    Mask.assign(NumElts, Context->getUndef(Type::Int32Ty));
+    Mask.assign(NumElts, UndefValue::get(Type::Int32Ty));
     return V;
   } else if (isa<ConstantAggregateZero>(V)) {
     Mask.assign(NumElts, ConstantInt::get(Type::Int32Ty, 0));
@@ -12662,7 +12662,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
         return ReplaceInstUsesWith(IE, VecOp);
       
       if (InsertedIdx >= NumVectorElts)  // Out of range insert.
-        return ReplaceInstUsesWith(IE, Context->getUndef(IE.getType()));
+        return ReplaceInstUsesWith(IE, UndefValue::get(IE.getType()));
       
       // If we are extracting a value from a vector, then inserting it right
       // back into the same place, just use the input vector.
@@ -12679,7 +12679,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
         // Build a new shuffle mask.
         std::vector<Constant*> Mask;
         if (isa<UndefValue>(VecOp))
-          Mask.assign(NumVectorElts, Context->getUndef(Type::Int32Ty));
+          Mask.assign(NumVectorElts, UndefValue::get(Type::Int32Ty));
         else {
           assert(isa<ConstantAggregateZero>(VecOp) && "Unknown thing");
           Mask.assign(NumVectorElts, ConstantInt::get(Type::Int32Ty,
@@ -12697,7 +12697,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
         std::vector<Constant*> Mask;
         Value *RHS = 0;
         Value *LHS = CollectShuffleElements(&IE, Mask, RHS, Context);
-        if (RHS == 0) RHS = Context->getUndef(LHS->getType());
+        if (RHS == 0) RHS = UndefValue::get(LHS->getType());
         // We now have a shuffle of LHS, RHS, Mask.
         return new ShuffleVectorInst(LHS, RHS,
                                      ConstantVector::get(Mask));
@@ -12724,7 +12724,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
 
   // Undefined shuffle mask -> undefined value.
   if (isa<UndefValue>(SVI.getOperand(2)))
-    return ReplaceInstUsesWith(SVI, Context->getUndef(SVI.getType()));
+    return ReplaceInstUsesWith(SVI, UndefValue::get(SVI.getType()));
 
   unsigned VWidth = cast<VectorType>(SVI.getType())->getNumElements();
 
@@ -12751,12 +12751,12 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
     std::vector<Constant*> Elts;
     for (unsigned i = 0, e = Mask.size(); i != e; ++i) {
       if (Mask[i] >= 2*e)
-        Elts.push_back(Context->getUndef(Type::Int32Ty));
+        Elts.push_back(UndefValue::get(Type::Int32Ty));
       else {
         if ((Mask[i] >= e && isa<UndefValue>(RHS)) ||
             (Mask[i] <  e && isa<UndefValue>(LHS))) {
           Mask[i] = 2*e;     // Turn into undef.
-          Elts.push_back(Context->getUndef(Type::Int32Ty));
+          Elts.push_back(UndefValue::get(Type::Int32Ty));
         } else {
           Mask[i] = Mask[i] % e;  // Force to LHS.
           Elts.push_back(ConstantInt::get(Type::Int32Ty, Mask[i]));
@@ -12764,7 +12764,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
       }
     }
     SVI.setOperand(0, SVI.getOperand(1));
-    SVI.setOperand(1, Context->getUndef(RHS->getType()));
+    SVI.setOperand(1, UndefValue::get(RHS->getType()));
     SVI.setOperand(2, ConstantVector::get(Elts));
     LHS = SVI.getOperand(0);
     RHS = SVI.getOperand(1);
@@ -12815,7 +12815,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
         std::vector<Constant*> Elts;
         for (unsigned i = 0, e = NewMask.size(); i != e; ++i) {
           if (NewMask[i] >= LHSInNElts*2) {
-            Elts.push_back(Context->getUndef(Type::Int32Ty));
+            Elts.push_back(UndefValue::get(Type::Int32Ty));
           } else {
             Elts.push_back(ConstantInt::get(Type::Int32Ty, NewMask[i]));
           }
@@ -12992,7 +12992,7 @@ bool InstCombiner::DoOneIteration(Function &F, unsigned Iteration) {
             Changed = true;
           }
           if (!I->use_empty())
-            I->replaceAllUsesWith(Context->getUndef(I->getType()));
+            I->replaceAllUsesWith(UndefValue::get(I->getType()));
           I->eraseFromParent();
         }
       }
index 2360ea9c6ba67e71b5701b5bd36f43fafa7c5efd..5cdd0947ab79842e5b00502492cfa588a8bfc8e2 100644 (file)
@@ -564,8 +564,7 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
     
     // If the returned value is the load itself, replace with an undef. This can
     // only happen in dead loops.
-    if (AvailableVal == LI) AvailableVal = 
-                            AvailableVal->getContext().getUndef(LI->getType());
+    if (AvailableVal == LI) AvailableVal = UndefValue::get(LI->getType());
     LI->replaceAllUsesWith(AvailableVal);
     LI->eraseFromParent();
     return true;
index dc34cf0cc47d25ad0b4e119050b1c5c78e7104de..02a33a7889e01833b8865243529ddb751e40c19e 100644 (file)
@@ -486,7 +486,7 @@ void LICM::sink(Instruction &I) {
       // Instruction is not used, just delete it.
       CurAST->deleteValue(&I);
       if (!I.use_empty())  // If I has users in unreachable blocks, eliminate.
-        I.replaceAllUsesWith(Context.getUndef(I.getType()));
+        I.replaceAllUsesWith(UndefValue::get(I.getType()));
       I.eraseFromParent();
     } else {
       // Move the instruction to the start of the exit block, after any PHI
@@ -500,7 +500,7 @@ void LICM::sink(Instruction &I) {
     // The instruction is actually dead if there ARE NO exit blocks.
     CurAST->deleteValue(&I);
     if (!I.use_empty())  // If I has users in unreachable blocks, eliminate.
-      I.replaceAllUsesWith(Context.getUndef(I.getType()));
+      I.replaceAllUsesWith(UndefValue::get(I.getType()));
     I.eraseFromParent();
   } else {
     // Otherwise, if we have multiple exits, use the PromoteMem2Reg function to
index 5bba625009bd5b1759c4d8bf1c97aa714377672d..95eb3cf2185ebcc6a848075c4d1f1695852fd90d 100644 (file)
@@ -821,7 +821,7 @@ void LoopUnswitch::RemoveBlockIfDead(BasicBlock *BB,
     // Anything that uses the instructions in this basic block should have their
     // uses replaced with undefs.
     if (!I->use_empty())
-      I->replaceAllUsesWith(I->getContext().getUndef(I->getType()));
+      I->replaceAllUsesWith(UndefValue::get(I->getType()));
   }
   
   // If this is the edge to the header block for a loop, remove the loop and
index 24fadb6003fdd323b6824934b396510128d6dde2..cade3e6c04e2340189c3be81c3a3b5f1aa5c4894 100644 (file)
@@ -285,8 +285,8 @@ void Reassociate::LinearizeExprTree(BinaryOperator *I,
       Ops.push_back(ValueEntry(getRank(RHS), RHS));
       
       // Clear the leaves out.
-      I->setOperand(0, Context.getUndef(I->getType()));
-      I->setOperand(1, Context.getUndef(I->getType()));
+      I->setOperand(0, UndefValue::get(I->getType()));
+      I->setOperand(1, UndefValue::get(I->getType()));
       return;
     } else {
       // Turn X+(Y+Z) -> (Y+Z)+X
@@ -321,7 +321,7 @@ void Reassociate::LinearizeExprTree(BinaryOperator *I,
   Ops.push_back(ValueEntry(getRank(RHS), RHS));
   
   // Clear the RHS leaf out.
-  I->setOperand(1, Context.getUndef(I->getType()));
+  I->setOperand(1, UndefValue::get(I->getType()));
 }
 
 // RewriteExprTree - Now that the operands for this expression tree are
index c3a1ae2ce315db86dbfb8fc20edf81105e88e265..91fcd209b2523812e2ef2ae152d45832af12bfa4 100644 (file)
@@ -1578,7 +1578,7 @@ bool SCCP::runOnFunction(Function &F) {
         Instruction *I = Insts.back();
         Insts.pop_back();
         if (!I->use_empty())
-          I->replaceAllUsesWith(F.getContext().getUndef(I->getType()));
+          I->replaceAllUsesWith(UndefValue::get(I->getType()));
         BB->getInstList().erase(I);
         MadeChanges = true;
         ++NumInstRemoved;
@@ -1598,7 +1598,7 @@ bool SCCP::runOnFunction(Function &F) {
           continue;
         
         Constant *Const = IV.isConstant()
-          ? IV.getConstant() : F.getContext().getUndef(Inst->getType());
+          ? IV.getConstant() : UndefValue::get(Inst->getType());
         DEBUG(errs() << "  Constant: " << *Const << " = " << *Inst);
 
         // Replaces all of the uses of a variable with uses of the constant.
@@ -1717,7 +1717,7 @@ bool IPSCCP::runOnModule(Module &M) {
         LatticeVal &IV = Values[AI];
         if (IV.isConstant() || IV.isUndefined()) {
           Constant *CST = IV.isConstant() ?
-            IV.getConstant() : Context->getUndef(AI->getType());
+            IV.getConstant() : UndefValue::get(AI->getType());
           DEBUG(errs() << "***  Arg " << *AI << " = " << *CST <<"\n");
 
           // Replaces all of the uses of a variable with uses of the
@@ -1742,7 +1742,7 @@ bool IPSCCP::runOnModule(Module &M) {
           Instruction *I = Insts.back();
           Insts.pop_back();
           if (!I->use_empty())
-            I->replaceAllUsesWith(Context->getUndef(I->getType()));
+            I->replaceAllUsesWith(UndefValue::get(I->getType()));
           BB->getInstList().erase(I);
           MadeChanges = true;
           ++IPNumInstRemoved;
@@ -1754,7 +1754,7 @@ bool IPSCCP::runOnModule(Module &M) {
             TI->getSuccessor(i)->removePredecessor(BB);
         }
         if (!TI->use_empty())
-          TI->replaceAllUsesWith(Context->getUndef(TI->getType()));
+          TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
         BB->getInstList().erase(TI);
 
         if (&*BB != &F->front())
@@ -1773,7 +1773,7 @@ bool IPSCCP::runOnModule(Module &M) {
             continue;
           
           Constant *Const = IV.isConstant()
-            ? IV.getConstant() : Context->getUndef(Inst->getType());
+            ? IV.getConstant() : UndefValue::get(Inst->getType());
           DEBUG(errs() << "  Constant: " << *Const << " = " << *Inst);
 
           // Replaces all of the uses of a variable with uses of the
@@ -1847,7 +1847,7 @@ bool IPSCCP::runOnModule(Module &M) {
       for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
         if (ReturnInst *RI = dyn_cast<ReturnInst>(BB->getTerminator()))
           if (!isa<UndefValue>(RI->getOperand(0)))
-            RI->setOperand(0, Context->getUndef(F->getReturnType()));
+            RI->setOperand(0, UndefValue::get(F->getReturnType()));
     }
 
   // If we infered constant or undef values for globals variables, we can delete
index 7eec908ac582f9e6433516763dede07c149e193f..7877db4e4f4e5a090085eb7f811ad12f35f53c73 100644 (file)
@@ -371,7 +371,7 @@ void SROA::DoScalarReplacement(AllocationInst *AI,
     //   %insert = insertvalue { i32, i32 } %insert.0, i32 %load.1, 1 
     // (Also works for arrays instead of structs)
     if (LoadInst *LI = dyn_cast<LoadInst>(User)) {
-      Value *Insert = Context.getUndef(LI->getType());
+      Value *Insert = UndefValue::get(LI->getType());
       for (unsigned i = 0, e = ElementAllocas.size(); i != e; ++i) {
         Value *Load = new LoadInst(ElementAllocas[i], "load", LI);
         Insert = InsertValueInst::Create(Insert, Load, i, "insert", LI);
@@ -1540,8 +1540,6 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType,
   if (FromVal->getType() == ToType && Offset == 0)
     return FromVal;
 
-  LLVMContext &Context = FromVal->getContext();
-
   // If the result alloca is a vector type, this is either an element
   // access or a bitcast to another vector type of the same size.
   if (const VectorType *VTy = dyn_cast<VectorType>(FromVal->getType())) {
@@ -1568,7 +1566,7 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType,
   // use insertvalue's to form the FCA.
   if (const StructType *ST = dyn_cast<StructType>(ToType)) {
     const StructLayout &Layout = *TD->getStructLayout(ST);
-    Value *Res = Context.getUndef(ST);
+    Value *Res = UndefValue::get(ST);
     for (unsigned i = 0, e = ST->getNumElements(); i != e; ++i) {
       Value *Elt = ConvertScalar_ExtractValue(FromVal, ST->getElementType(i),
                                         Offset+Layout.getElementOffsetInBits(i),
@@ -1580,7 +1578,7 @@ Value *SROA::ConvertScalar_ExtractValue(Value *FromVal, const Type *ToType,
   
   if (const ArrayType *AT = dyn_cast<ArrayType>(ToType)) {
     uint64_t EltSize = TD->getTypeAllocSizeInBits(AT->getElementType());
-    Value *Res = Context.getUndef(AT);
+    Value *Res = UndefValue::get(AT);
     for (unsigned i = 0, e = AT->getNumElements(); i != e; ++i) {
       Value *Elt = ConvertScalar_ExtractValue(FromVal, AT->getElementType(),
                                               Offset+i*EltSize, Builder);
index 3596ed6b14fbf370e1295b5608481f4ed033dc5d..3ea6ddd67c2d8e705a4ed5d35da612acbac3e25a 100644 (file)
@@ -71,7 +71,7 @@ static void ChangeToUnreachable(Instruction *I, LLVMContext &Context) {
   BasicBlock::iterator BBI = I, BBE = BB->end();
   while (BBI != BBE) {
     if (!BBI->use_empty())
-      BBI->replaceAllUsesWith(Context.getUndef(BBI->getType()));
+      BBI->replaceAllUsesWith(UndefValue::get(BBI->getType()));
     BB->getInstList().erase(BBI++);
   }
 }
index 5f6edcf336dcb5587a6f4ddea856f42e9a5dbd78..e6522749bccfc6562630c55cb34a9be60eac21b8 100644 (file)
@@ -51,7 +51,7 @@ void llvm::DeleteDeadBlock(BasicBlock *BB) {
     // contained within it must dominate their uses, that all uses will
     // eventually be removed (they are themselves dead).
     if (!I.use_empty())
-      I.replaceAllUsesWith(BB->getContext().getUndef(I.getType()));
+      I.replaceAllUsesWith(UndefValue::get(I.getType()));
     BB->getInstList().pop_back();
   }
   
@@ -71,7 +71,7 @@ void llvm::FoldSingleEntryPHINodes(BasicBlock *BB) {
     if (PN->getIncomingValue(0) != PN)
       PN->replaceAllUsesWith(PN->getIncomingValue(0));
     else
-      PN->replaceAllUsesWith(BB->getContext().getUndef(PN->getType()));
+      PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
     PN->eraseFromParent();
   }
 }
@@ -387,8 +387,7 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
   if (NumPreds == 0) {
     // Insert dummy values as the incoming value.
     for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
-      cast<PHINode>(I)->addIncoming(BB->getContext().getUndef(I->getType()), 
-                                    NewBB);
+      cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB);
     return NewBB;
   }
   
index 7b8a8a498bc8430325cec57c2327ae5e12475ed9..2b2fcb1052c2ea117ed8c87848d62c9fa465f86a 100644 (file)
@@ -489,7 +489,7 @@ void llvm::CloneAndPruneFunctionInto(Function *NewFunc, const Function *OldFunc,
       BasicBlock::iterator I = NewBB->begin();
       BasicBlock::const_iterator OldI = OldBB->begin();
       while ((PN = dyn_cast<PHINode>(I++))) {
-        Value *NV = OldFunc->getContext().getUndef(PN->getType());
+        Value *NV = UndefValue::get(PN->getType());
         PN->replaceAllUsesWith(NV);
         assert(ValueMap[OldI] == PN && "ValueMap mismatch");
         ValueMap[OldI] = NV;
index 43b996af3f5049a4aae2427ca0bee18c32493d31..d6382af379c0a5c493fe67f2e6df5a97e72dca01 100644 (file)
@@ -521,7 +521,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
     if (!TheCall->use_empty()) {
       ReturnInst *R = Returns[0];
       if (TheCall == R->getReturnValue())
-        TheCall->replaceAllUsesWith(Context.getUndef(TheCall->getType()));
+        TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
       else
         TheCall->replaceAllUsesWith(R->getReturnValue());
     }
@@ -614,7 +614,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
     // using the return value of the call with the computed value.
     if (!TheCall->use_empty()) {
       if (TheCall == Returns[0]->getReturnValue())
-        TheCall->replaceAllUsesWith(Context.getUndef(TheCall->getType()));
+        TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
       else
         TheCall->replaceAllUsesWith(Returns[0]->getReturnValue());
     }
@@ -634,7 +634,7 @@ bool llvm::InlineFunction(CallSite CS, CallGraph *CG, const TargetData *TD) {
   } else if (!TheCall->use_empty()) {
     // No returns, but something is using the return value of the call.  Just
     // nuke the result.
-    TheCall->replaceAllUsesWith(Context.getUndef(TheCall->getType()));
+    TheCall->replaceAllUsesWith(UndefValue::get(TheCall->getType()));
   }
 
   // Since we are now done with the Call/Invoke, we can delete it.
index 1b72849528ff9f1ead2b6f3f374c55a1a1bb0ad1..84fcc643bfb2ec8a10f9871e6705a95b41320847 100644 (file)
@@ -243,7 +243,7 @@ Value *LCSSA::GetValueForBlock(DomTreeNode *BB, Instruction *OrigInst,
                                DenseMap<DomTreeNode*, Value*> &Phis) {
   // If there is no dominator info for this BB, it is unreachable.
   if (BB == 0)
-    return OrigInst->getContext().getUndef(OrigInst->getType());
+    return UndefValue::get(OrigInst->getType());
                                  
   // If we have already computed this value, return the previously computed val.
   if (Phis.count(BB)) return Phis[BB];
index e9be0e263b80fa0f1bbb2b6aec8f3b05b6da4642..18ce81d143760f9e665ae8ef3c335fcd8052a126 100644 (file)
@@ -263,8 +263,6 @@ void llvm::RecursivelyDeleteTriviallyDeadInstructions(Value *V) {
 /// too, recursively.
 void
 llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
-  LLVMContext &Context = PN->getContext();
-  
   // We can remove a PHI if it is on a cycle in the def-use graph
   // where each node in the cycle has degree one, i.e. only one use,
   // and is an instruction with no side effects.
@@ -281,7 +279,7 @@ llvm::RecursivelyDeleteDeadPHINode(PHINode *PN) {
     if (PHINode *JP = dyn_cast<PHINode>(J))
       if (!PHIs.insert(cast<PHINode>(JP))) {
         // Break the cycle and delete the PHI and its operands.
-        JP->replaceAllUsesWith(Context.getUndef(JP->getType()));
+        JP->replaceAllUsesWith(UndefValue::get(JP->getType()));
         RecursivelyDeleteTriviallyDeadInstructions(JP);
         break;
       }
@@ -301,7 +299,7 @@ void llvm::MergeBasicBlockIntoOnlyPred(BasicBlock *DestBB) {
   while (PHINode *PN = dyn_cast<PHINode>(DestBB->begin())) {
     Value *NewVal = PN->getIncomingValue(0);
     // Replace self referencing PHI with undef, it must be dead.
-    if (NewVal == PN) NewVal = DestBB->getContext().getUndef(PN->getType());
+    if (NewVal == PN) NewVal = UndefValue::get(PN->getType());
     PN->replaceAllUsesWith(NewVal);
     PN->eraseFromParent();
   }
index 045b428df930226fd004f94d2cd35d1b90e44d2c..69a208405dff6b14694f382929eea7332e47c936 100644 (file)
@@ -166,7 +166,7 @@ bool LoopSimplify::runOnFunction(Function &F) {
     // Delete the dead terminator.
     if (AA) AA->deleteValue(TI);
     if (!TI->use_empty())
-      TI->replaceAllUsesWith(F.getContext().getUndef(TI->getType()));
+      TI->replaceAllUsesWith(UndefValue::get(TI->getType()));
     TI->eraseFromParent();
     Changed |= true;
   }
index 5645110db666657af8d8abb89ff2f7d06f8a8000..3cfaed6a663a4304acd81bb10563b794a81e4927 100644 (file)
@@ -448,7 +448,7 @@ void PromoteMem2Reg::run() {
   //
   RenamePassData::ValVector Values(Allocas.size());
   for (unsigned i = 0, e = Allocas.size(); i != e; ++i)
-    Values[i] = Context.getUndef(Allocas[i]->getAllocatedType());
+    Values[i] = UndefValue::get(Allocas[i]->getAllocatedType());
 
   // Walks all basic blocks in the function performing the SSA rename algorithm
   // and inserting the phi nodes we marked as necessary
@@ -475,7 +475,7 @@ void PromoteMem2Reg::run() {
     // Just delete the users now.
     //
     if (!A->use_empty())
-      A->replaceAllUsesWith(Context.getUndef(A->getType()));
+      A->replaceAllUsesWith(UndefValue::get(A->getType()));
     if (AST) AST->deleteValue(A);
     A->eraseFromParent();
   }
@@ -561,7 +561,7 @@ void PromoteMem2Reg::run() {
     BasicBlock::iterator BBI = BB->begin();
     while ((SomePHI = dyn_cast<PHINode>(BBI++)) &&
            SomePHI->getNumIncomingValues() == NumBadPreds) {
-      Value *UndefVal = Context.getUndef(SomePHI->getType());
+      Value *UndefVal = UndefValue::get(SomePHI->getType());
       for (unsigned pred = 0, e = Preds.size(); pred != e; ++pred)
         SomePHI->addIncoming(UndefVal, Preds[pred]);
     }
@@ -807,7 +807,7 @@ void PromoteMem2Reg::PromoteSingleBlockAlloca(AllocaInst *AI, AllocaInfo &Info,
   if (StoresByIndex.empty()) {
     for (Value::use_iterator UI = AI->use_begin(), E = AI->use_end(); UI != E;) 
       if (LoadInst *LI = dyn_cast<LoadInst>(*UI++)) {
-        LI->replaceAllUsesWith(Context.getUndef(LI->getType()));
+        LI->replaceAllUsesWith(UndefValue::get(LI->getType()));
         if (AST && isa<PointerType>(LI->getType()))
           AST->deleteValue(LI);
         LBI.deleteValue(LI);
index b0643d60965ae46e3cd884241500583ca28e6e40..0f9493dac264dbe9afc3d7bcaea8a286693d5e16 100644 (file)
@@ -1266,8 +1266,6 @@ static bool FoldCondBranchOnPHI(BranchInst *BI) {
 /// FoldTwoEntryPHINode - Given a BB that starts with the specified two-entry
 /// PHI node, see if we can eliminate it.
 static bool FoldTwoEntryPHINode(PHINode *PN) {
-  LLVMContext &Context = PN->getParent()->getContext();
-  
   // Ok, this is a two entry PHI node.  Check to see if this is a simple "if
   // statement", which has a very simple dominance structure.  Basically, we
   // are trying to find the condition that is being branched on, which
@@ -1305,7 +1303,7 @@ static bool FoldTwoEntryPHINode(PHINode *PN) {
       if (PN->getIncomingValue(0) != PN)
         PN->replaceAllUsesWith(PN->getIncomingValue(0));
       else
-        PN->replaceAllUsesWith(Context.getUndef(PN->getType()));
+        PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
     } else if (!DominatesMergePoint(PN->getIncomingValue(0), BB,
                                     &AggressiveInsts) ||
                !DominatesMergePoint(PN->getIncomingValue(1), BB,
index 81d143a58a3b2b5d80030717ac778008f375d0e0..7f6c7e167ee7aa3b7843fd9b85f9e36e271f512e 100644 (file)
@@ -230,7 +230,6 @@ bool llvm::UpgradeIntrinsicFunction(Function *F, Function *&NewFn) {
 // order to seamlessly integrate with existing context.
 void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
   Function *F = CI->getCalledFunction();
-  LLVMContext &Context = F->getContext();
   
   assert(F && "CallInst has no function associated with it.");
 
@@ -264,7 +263,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
       Value *Op0 = CI->getOperand(1);
       ShuffleVectorInst *SI = NULL;
       if (isLoadH || isLoadL) {
-        Value *Op1 = Context.getUndef(Op0->getType());
+        Value *Op1 = UndefValue::get(Op0->getType());
         Value *Addr = new BitCastInst(CI->getOperand(2), 
                                   PointerType::getUnqual(Type::DoubleTy),
                                       "upgraded.", CI);
index d0fa02ce1cd94fa7fc59a22fa89a9bd203627f2b..d7ff3bc8cf5fcbd9bf28caae156b7ac226adfe42 100644 (file)
@@ -203,7 +203,7 @@ void BasicBlock::removePredecessor(BasicBlock *Pred,
           PN->replaceAllUsesWith(PN->getOperand(0));
         else
           // We are left with an infinite loop with no entries: kill the PHI.
-          PN->replaceAllUsesWith(getContext().getUndef(PN->getType()));
+          PN->replaceAllUsesWith(UndefValue::get(PN->getType()));
         getInstList().pop_front();    // Remove the PHI node
       }
 
index ab0016059ed5baa397dca9aa06fc4dd5311bd348..6e6c9b09c3f47240a63337c6e42973d8b5db66d4 100644 (file)
@@ -151,7 +151,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
   // Finally, implement bitcast folding now.   The code below doesn't handle
   // bitcast right.
   if (isa<ConstantPointerNull>(V))  // ptr->ptr cast.
-    return Context.getConstantPointerNull(cast<PointerType>(DestTy));
+    return ConstantPointerNull::get(cast<PointerType>(DestTy));
   
   // Handle integral constant input.
   if (const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
@@ -187,7 +187,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
     if (opc == Instruction::ZExt || opc == Instruction::SExt ||
         opc == Instruction::UIToFP || opc == Instruction::SIToFP)
       return Context.getNullValue(DestTy);
-    return Context.getUndef(DestTy);
+    return UndefValue::get(DestTy);
   }
   // No compile-time operations on this type yet.
   if (V->getType() == Type::PPC_FP128Ty || DestTy == Type::PPC_FP128Ty)
@@ -263,7 +263,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
     return 0; // Can't fold.
   case Instruction::IntToPtr:   //always treated as unsigned
     if (V->isNullValue())       // Is it an integral null value?
-      return Context.getConstantPointerNull(cast<PointerType>(DestTy));
+      return ConstantPointerNull::get(cast<PointerType>(DestTy));
     return 0;                   // Other pointer types cannot be casted
   case Instruction::PtrToInt:   // always treated as unsigned
     if (V->isNullValue())       // is it a null pointer value?
@@ -335,7 +335,7 @@ Constant *llvm::ConstantFoldExtractElementInstruction(LLVMContext &Context,
                                                       const Constant *Val,
                                                       const Constant *Idx) {
   if (isa<UndefValue>(Val))  // ee(undef, x) -> undef
-    return Context.getUndef(cast<VectorType>(Val->getType())->getElementType());
+    return UndefValue::get(cast<VectorType>(Val->getType())->getElementType());
   if (Val->isNullValue())  // ee(zero, x) -> zero
     return Context.getNullValue(
                           cast<VectorType>(Val->getType())->getElementType());
@@ -371,7 +371,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
     Ops.reserve(numOps);
     for (unsigned i = 0; i < numOps; ++i) {
       const Constant *Op =
-        (idxVal == i) ? Elt : Context.getUndef(Elt->getType());
+        (idxVal == i) ? Elt : UndefValue::get(Elt->getType());
       Ops.push_back(const_cast<Constant*>(Op));
     }
     return ConstantVector::get(Ops);
@@ -420,7 +420,7 @@ static Constant *GetVectorElement(LLVMContext &Context, const Constant *C,
   if (isa<ConstantAggregateZero>(C))
     return Context.getNullValue(EltTy);
   if (isa<UndefValue>(C))
-    return Context.getUndef(EltTy);
+    return UndefValue::get(EltTy);
   return 0;
 }
 
@@ -429,7 +429,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
                                                      const Constant *V2,
                                                      const Constant *Mask) {
   // Undefined shuffle mask -> undefined value.
-  if (isa<UndefValue>(Mask)) return Context.getUndef(V1->getType());
+  if (isa<UndefValue>(Mask)) return UndefValue::get(V1->getType());
 
   unsigned MaskNumElts = cast<VectorType>(Mask->getType())->getNumElements();
   unsigned SrcNumElts = cast<VectorType>(V1->getType())->getNumElements();
@@ -442,11 +442,11 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
     if (InElt == 0) return 0;
 
     if (isa<UndefValue>(InElt))
-      InElt = Context.getUndef(EltTy);
+      InElt = UndefValue::get(EltTy);
     else if (ConstantInt *CI = dyn_cast<ConstantInt>(InElt)) {
       unsigned Elt = CI->getZExtValue();
       if (Elt >= SrcNumElts*2)
-        InElt = Context.getUndef(EltTy);
+        InElt = UndefValue::get(EltTy);
       else if (Elt >= SrcNumElts)
         InElt = GetVectorElement(Context, V2, Elt - SrcNumElts);
       else
@@ -471,7 +471,7 @@ Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context,
     return const_cast<Constant *>(Agg);
 
   if (isa<UndefValue>(Agg))  // ev(undef, x) -> undef
-    return Context.getUndef(ExtractValueInst::getIndexedType(Agg->getType(),
+    return UndefValue::get(ExtractValueInst::getIndexedType(Agg->getType(),
                                                             Idxs,
                                                             Idxs + NumIdx));
 
@@ -513,9 +513,9 @@ Constant *llvm::ConstantFoldInsertValueInstruction(LLVMContext &Context,
       const Type *MemberTy = AggTy->getTypeAtIndex(i);
       const Constant *Op =
         (*Idxs == i) ?
-        ConstantFoldInsertValueInstruction(Context, Context.getUndef(MemberTy),
+        ConstantFoldInsertValueInstruction(Context, UndefValue::get(MemberTy),
                                            Val, Idxs+1, NumIdx-1) :
-        Context.getUndef(MemberTy);
+        UndefValue::get(MemberTy);
       Ops[i] = const_cast<Constant*>(Op);
     }
     if (isa<StructType>(AggTy))
@@ -594,7 +594,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
       // Fallthrough
     case Instruction::Add:
     case Instruction::Sub:
-      return Context.getUndef(C1->getType());
+      return UndefValue::get(C1->getType());
     case Instruction::Mul:
     case Instruction::And:
       return Context.getNullValue(C1->getType());
@@ -646,14 +646,14 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
       if (CI2->equalsInt(1))
         return const_cast<Constant*>(C1);                     // X / 1 == X
       if (CI2->equalsInt(0))
-        return Context.getUndef(CI2->getType());               // X / 0 == undef
+        return UndefValue::get(CI2->getType());               // X / 0 == undef
       break;
     case Instruction::URem:
     case Instruction::SRem:
       if (CI2->equalsInt(1))
         return Context.getNullValue(CI2->getType());        // X % 1 == 0
       if (CI2->equalsInt(0))
-        return Context.getUndef(CI2->getType());               // X % 0 == undef
+        return UndefValue::get(CI2->getType());               // X % 0 == undef
       break;
     case Instruction::And:
       if (CI2->isZero()) return const_cast<Constant*>(C2);    // X & 0 == 0
@@ -732,7 +732,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
       case Instruction::SDiv:
         assert(!CI2->isNullValue() && "Div by zero handled above");
         if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
-          return Context.getUndef(CI1->getType());   // MIN_INT / -1 -> undef
+          return UndefValue::get(CI1->getType());   // MIN_INT / -1 -> undef
         return ConstantInt::get(Context, C1V.sdiv(C2V));
       case Instruction::URem:
         assert(!CI2->isNullValue() && "Div by zero handled above");
@@ -740,7 +740,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
       case Instruction::SRem:
         assert(!CI2->isNullValue() && "Div by zero handled above");
         if (C2V.isAllOnesValue() && C1V.isMinSignedValue())
-          return Context.getUndef(CI1->getType());   // MIN_INT % -1 -> undef
+          return UndefValue::get(CI1->getType());   // MIN_INT % -1 -> undef
         return ConstantInt::get(Context, C1V.srem(C2V));
       case Instruction::And:
         return ConstantInt::get(Context, C1V & C2V);
@@ -753,21 +753,21 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
         if (shiftAmt < C1V.getBitWidth())
           return ConstantInt::get(Context, C1V.shl(shiftAmt));
         else
-          return Context.getUndef(C1->getType()); // too big shift is undef
+          return UndefValue::get(C1->getType()); // too big shift is undef
       }
       case Instruction::LShr: {
         uint32_t shiftAmt = C2V.getZExtValue();
         if (shiftAmt < C1V.getBitWidth())
           return ConstantInt::get(Context, C1V.lshr(shiftAmt));
         else
-          return Context.getUndef(C1->getType()); // too big shift is undef
+          return UndefValue::get(C1->getType()); // too big shift is undef
       }
       case Instruction::AShr: {
         uint32_t shiftAmt = C2V.getZExtValue();
         if (shiftAmt < C1V.getBitWidth())
           return ConstantInt::get(Context, C1V.ashr(shiftAmt));
         else
-          return Context.getUndef(C1->getType()); // too big shift is undef
+          return UndefValue::get(C1->getType()); // too big shift is undef
       }
       }
     }
@@ -1386,7 +1386,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
 
   // Handle some degenerate cases first
   if (isa<UndefValue>(C1) || isa<UndefValue>(C2))
-    return Context.getUndef(ResultTy);
+    return UndefValue::get(ResultTy);
 
   // No compile-time operations on this type yet.
   if (C1->getType() == Type::PPC_FP128Ty)
@@ -1677,7 +1677,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
                                                        (Value **)Idxs,
                                                        (Value **)Idxs+NumIdx);
     assert(Ty != 0 && "Invalid indices for GEP!");
-    return Context.getUndef(PointerType::get(Ty, Ptr->getAddressSpace()));
+    return UndefValue::get(PointerType::get(Ty, Ptr->getAddressSpace()));
   }
 
   Constant *Idx0 = Idxs[0];
@@ -1694,7 +1694,7 @@ Constant *llvm::ConstantFoldGetElementPtr(LLVMContext &Context,
                                                          (Value**)Idxs,
                                                          (Value**)Idxs+NumIdx);
       assert(Ty != 0 && "Invalid indices for GEP!");
-      return  Context.getConstantPointerNull(
+      return  ConstantPointerNull::get(
                             PointerType::get(Ty,Ptr->getAddressSpace()));
     }
   }
index 1ff596fb710eeb9a407ccc22c9f2f5ef5c59cee0..f7d6946f18120709c1df3c5ff55ce2ef80988147 100644 (file)
@@ -153,7 +153,7 @@ void Constant::getVectorElements(LLVMContext &Context,
   }
   
   if (isa<UndefValue>(this)) {
-    Elts.assign(VT->getNumElements(), Context.getUndef(VT->getElementType()));
+    Elts.assign(VT->getNumElements(), UndefValue::get(VT->getElementType()));
     return;
   }
   
@@ -391,7 +391,7 @@ Constant *ConstantArray::get(const ArrayType *Ty,
       }
   }
   
-  return Ty->getContext().getConstantAggregateZero(Ty);
+  return ConstantAggregateZero::get(Ty);
 }
 
 
@@ -455,7 +455,7 @@ Constant* ConstantStruct::get(const StructType* T,
       // Implicitly locked.
       return pImpl->StructConstants.getOrCreate(T, V);
 
-  return T->getContext().getConstantAggregateZero(T);
+  return ConstantAggregateZero::get(T);
 }
 
 Constant* ConstantStruct::get(const std::vector<Constant*>& V, bool packed) {
@@ -511,9 +511,9 @@ Constant* ConstantVector::get(const VectorType* T,
   }
   
   if (isZero)
-    return Context.getConstantAggregateZero(T);
+    return ConstantAggregateZero::get(T);
   if (isUndef)
-    return Context.getUndef(T);
+    return UndefValue::get(T);
     
   // Implicitly locked.
   return pImpl->VectorConstants.getOrCreate(T, V);
@@ -1018,11 +1018,22 @@ bool ConstantFP::isValueValidForType(const Type *Ty, const APFloat& Val) {
 //===----------------------------------------------------------------------===//
 //                      Factory Function Implementation
 
+static char getValType(ConstantAggregateZero *CPZ) { return 0; }
+
+ConstantAggregateZero* ConstantAggregateZero::get(const Type* Ty) {
+  assert((isa<StructType>(Ty) || isa<ArrayType>(Ty) || isa<VectorType>(Ty)) &&
+         "Cannot create an aggregate zero of non-aggregate type!");
+  
+  LLVMContextImpl *pImpl = Ty->getContext().pImpl;
+  // Implicitly locked.
+  return pImpl->AggZeroConstants.getOrCreate(Ty, 0);
+}
+
 /// destroyConstant - Remove the constant from the constant table...
 ///
 void ConstantAggregateZero::destroyConstant() {
   // Implicitly locked.
-  getType()->getContext().erase(this);
+  getType()->getContext().pImpl->AggZeroConstants.remove(this);
   destroyConstantImpl();
 }
 
@@ -2154,7 +2165,7 @@ void ConstantArray::replaceUsesOfWithOnConstant(Value *From, Value *To,
   
   Constant *Replacement = 0;
   if (isAllZeros) {
-    Replacement = Context.getConstantAggregateZero(getType());
+    Replacement = ConstantAggregateZero::get(getType());
   } else {
     // Check to see if we have this array type already.
     sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
@@ -2241,7 +2252,7 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
   
   Constant *Replacement = 0;
   if (isAllZeros) {
-    Replacement = Context.getConstantAggregateZero(getType());
+    Replacement = ConstantAggregateZero::get(getType());
   } else {
     // Check to see if we have this array type already.
     sys::SmartScopedWriter<true> Writer(pImpl->ConstantsLock);
index 59aeb878007acefa622b3fade7060d2d619dbe27..be71d3794739fc11e0519105a77cec9237aa6ad8 100644 (file)
@@ -335,7 +335,7 @@ LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
 }
 
 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
-  return wrap(getGlobalContext().getUndef(unwrap(Ty)));
+  return wrap(UndefValue::get(unwrap(Ty)));
 }
 
 int LLVMIsConstant(LLVMValueRef Ty) {
@@ -354,7 +354,7 @@ int LLVMIsUndef(LLVMValueRef Val) {
 
 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
   return
-      wrap(getGlobalContext().getConstantPointerNull(unwrap<PointerType>(Ty)));
+      wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
 }
 
 /*--.. Operations on scalar constants ......................................--*/
index 08b439630749547da07e72a520b5ede7549c6331..368914652debeb93aad55bbc4b3382973c1a0b82 100644 (file)
@@ -187,7 +187,7 @@ Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
   // If the PHI node is dead, because it has zero entries, nuke it now.
   if (NumOps == 2 && DeletePHIIfEmpty) {
     // If anyone is using this PHI, make them use a dummy value instead...
-    replaceAllUsesWith(getType()->getContext().getUndef(getType()));
+    replaceAllUsesWith(UndefValue::get(getType()));
     eraseFromParent();
   }
   return Removed;
@@ -231,8 +231,7 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
     if (getIncomingValue(0) != this)   // not  X = phi X
       return getIncomingValue(0);
     else
-      return
-        getType()->getContext().getUndef(getType());  // Self cycle is dead.
+      return UndefValue::get(getType());  // Self cycle is dead.
   }
       
   // Otherwise if all of the incoming values are the same for the PHI, replace
@@ -254,7 +253,7 @@ Value *PHINode::hasConstantValue(bool AllowNonDominatingInstruction) const {
   // that only has entries for itself.  In this case, there is no entry into the
   // loop, so kill the PHI.
   //
-  if (InVal == 0) InVal = getType()->getContext().getUndef(getType());
+  if (InVal == 0) InVal = UndefValue::get(getType());
   
   // If we have a PHI node like phi(X, undef, X), where X is defined by some
   // instruction, we cannot always return X as the result of the PHI node.  Only
index 8bd45b2954d27a445a29fb731708e359dcf56c83..23c73c5fd5d2f1f8a8292f49f134cda1d202068a 100644 (file)
@@ -52,11 +52,11 @@ Constant* LLVMContext::getNullValue(const Type* Ty) {
   case Type::PPC_FP128TyID:
     return ConstantFP::get(Ty->getContext(), APFloat(APInt(128, 2, zero)));
   case Type::PointerTyID:
-    return getConstantPointerNull(cast<PointerType>(Ty));
+    return ConstantPointerNull::get(cast<PointerType>(Ty));
   case Type::StructTyID:
   case Type::ArrayTyID:
   case Type::VectorTyID:
-    return getConstantAggregateZero(Ty);
+    return ConstantAggregateZero::get(Ty);
   default:
     // Function, Label, or Opaque type?
     assert(!"Cannot create a null constant of that type!");
@@ -75,11 +75,6 @@ Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
   return cast<ConstantVector>(ConstantVector::get(Elts));
 }
 
-// UndefValue accessors.
-UndefValue* LLVMContext::getUndef(const Type* Ty) {
-  return UndefValue::get(Ty);
-}
-
 // ConstantInt accessors.
 ConstantInt* LLVMContext::getTrue() {
   assert(this && "Context not initialized!");
@@ -93,16 +88,6 @@ ConstantInt* LLVMContext::getFalse() {
   return pImpl->getFalse();
 }
 
-// ConstantPointerNull accessors.
-ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
-  return ConstantPointerNull::get(T);
-}
-
-// ConstantAggregateZero accessors.
-ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
-  return pImpl->getConstantAggregateZero(Ty);
-}
-
 // MDNode accessors
 MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
   return pImpl->getMDNode(Vals, NumVals);
@@ -120,7 +105,3 @@ void LLVMContext::erase(MDString *M) {
 void LLVMContext::erase(MDNode *M) {
   pImpl->erase(M);
 }
-
-void LLVMContext::erase(ConstantAggregateZero *Z) {
-  pImpl->erase(Z);
-}
index 23d8ca3105fbe75db8eab6d41a18147c7a30fd31..bba5861cc0f7c0d8790b138f50b4c4b5ce04349f 100644 (file)
@@ -19,8 +19,6 @@
 #include "llvm/Metadata.h"
 using namespace llvm;
 
-static char getValType(ConstantAggregateZero *CPZ) { return 0; }
-
 LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
     Context(C), TheTrueVal(0), TheFalseVal(0) { }
 
@@ -59,15 +57,6 @@ MDNode *LLVMContextImpl::getMDNode(Value*const* Vals, unsigned NumVals) {
   return N;
 }
 
-ConstantAggregateZero*
-LLVMContextImpl::getConstantAggregateZero(const Type *Ty) {
-  assert((isa<StructType>(Ty) || isa<ArrayType>(Ty) || isa<VectorType>(Ty)) &&
-         "Cannot create an aggregate zero of non-aggregate type!");
-
-  // Implicitly locked.
-  return AggZeroConstants.getOrCreate(Ty, 0);
-}
-
 // *** erase methods ***
 
 void LLVMContextImpl::erase(MDString *M) {
@@ -79,7 +68,3 @@ void LLVMContextImpl::erase(MDNode *M) {
   sys::SmartScopedWriter<true> Writer(ConstantsLock);
   MDNodeSet.RemoveNode(M);
 }
-
-void LLVMContextImpl::erase(ConstantAggregateZero *Z) {
-  AggZeroConstants.remove(Z);
-}
index c09260333537f77c34ffd790188b5d290ce11de0..f2cdcf4a0d36b0b6caa4020100f6e59eebaf2cfb 100644 (file)
@@ -74,7 +74,7 @@ template<>
 struct ConvertConstantType<ConstantAggregateZero, Type> {
   static void convert(ConstantAggregateZero *OldC, const Type *NewTy) {
     // Make everyone now use a constant of the new type...
-    Constant *New = NewTy->getContext().getConstantAggregateZero(NewTy);
+    Constant *New = ConstantAggregateZero::get(NewTy);
     assert(New != OldC && "Didn't replace constant??");
     OldC->uncheckedReplaceAllUsesWith(New);
     OldC->destroyConstant();     // This constant is now dead, destroy it.
@@ -461,6 +461,7 @@ class LLVMContextImpl {
   friend class ConstantStruct;
   friend class ConstantArray;
   friend class ConstantVector;
+  friend class ConstantAggregateZero;
 public:
   LLVMContextImpl(LLVMContext &C);
   
@@ -468,8 +469,6 @@ public:
   
   MDNode *getMDNode(Value*const* Vals, unsigned NumVals);
   
-  ConstantAggregateZero *getConstantAggregateZero(const Type *Ty);
-  
   ConstantInt *getTrue() {
     if (TheTrueVal)
       return TheTrueVal;
@@ -486,7 +485,6 @@ public:
   
   void erase(MDString *M);
   void erase(MDNode *M);
-  void erase(ConstantAggregateZero *Z);
 };
 
 }
index ea40caaf3d92aaf5a5b539cf337d554a64ec144d..f443f36d0b1d6069e3445a6f07abdaa89b7d4573 100644 (file)
@@ -72,7 +72,7 @@ Module *BugDriver::deleteInstructionFromProgram(const Instruction *I,
 
   // If this instruction produces a value, replace any users with null values
   if (isa<StructType>(TheInst->getType()))
-    TheInst->replaceAllUsesWith(Context.getUndef(TheInst->getType()));
+    TheInst->replaceAllUsesWith(UndefValue::get(TheInst->getType()));
   else if (TheInst->getType() != Type::VoidTy)
     TheInst->replaceAllUsesWith(Context.getNullValue(TheInst->getType()));
 
index c021418905aead7c2ea9ba95ab244080e85ccd33..0fedfe343923103fea325f8e3f77dd2b131cdcc8 100644 (file)
@@ -733,7 +733,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
         // function that dynamically resolves the calls to F via our JIT API
         if (!F->use_empty()) {
           // Create a new global to hold the cached function pointer.
-          Constant *NullPtr = Context.getConstantPointerNull(F->getType());
+          Constant *NullPtr = ConstantPointerNull::get(F->getType());
           GlobalVariable *Cache =
             new GlobalVariable(*F->getParent(), F->getType(), 
                                false, GlobalValue::InternalLinkage,
index 8879d3bdf46895dc714c7c4e47a66b003d58a93a..42bb6cc2ecd17f685d70d70b7f3c0255abfd4026 100644 (file)
@@ -21,7 +21,7 @@ TEST(ConstantsTest, Integer_i1) {
   Constant* Zero = ConstantInt::get(Int1, 0);
   Constant* NegOne = ConstantInt::get(Int1, static_cast<uint64_t>(-1), true);
   EXPECT_EQ(NegOne, ConstantInt::getSigned(Int1, -1));
-  Constant* Undef = getGlobalContext().getUndef(Int1);
+  Constant* Undef = UndefValue::get(Int1);
 
   // Input:  @b = constant i1 add(i1 1 , i1 1)
   // Output: @b = constant i1 false