Return ConstantVector to 2.5 API.
authorOwen Anderson <resistor@mac.com>
Tue, 28 Jul 2009 21:19:26 +0000 (21:19 +0000)
committerOwen Anderson <resistor@mac.com>
Tue, 28 Jul 2009 21:19:26 +0000 (21:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77366 91177308-0d34-0410-b5e6-96231b3b80d8

21 files changed:
include/llvm/Constants.h
include/llvm/LLVMContext.h
lib/Analysis/ConstantFolding.cpp
lib/AsmParser/LLParser.cpp
lib/Bitcode/Reader/BitcodeReader.cpp
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuild.cpp
lib/Linker/LinkModules.cpp
lib/Target/CellSPU/SPUISelDAGToDAG.cpp
lib/Target/X86/X86ISelLowering.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/Transforms/Scalar/ScalarReplAggregates.cpp
lib/Transforms/Utils/ValueMapper.cpp
lib/VMCore/AutoUpgrade.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

index 442472acb3def091e0938e0dbc043d65e92556df..a3bd5517900b2fc7d50704da1558bec34969db1b 100644 (file)
@@ -448,6 +448,11 @@ class ConstantVector : public Constant {
 protected:
   ConstantVector(const VectorType *T, const std::vector<Constant*> &Val);
 public:
+  // ConstantVector accessors
+  static Constant* get(const VectorType* T, const std::vector<Constant*>& V);
+  static Constant* get(const std::vector<Constant*>& V);
+  static Constant* get(Constant* const* Vals, unsigned NumVals);
+  
   /// Transparently provide more efficient getOperand methods.
   DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Constant);
 
index 03de906c14a3e04bfc5ee4e8058666ff91941ff6..de118aae6469e39d2242012819e5aa99a47d24bb 100644 (file)
@@ -59,6 +59,7 @@ class LLVMContext {
   friend class ConstantFP;
   friend class ConstantStruct;
   friend class ConstantArray;
+  friend class ConstantVector;
 public:
   LLVMContext();
   ~LLVMContext();
@@ -160,12 +161,6 @@ public:
   ///
   Constant* getConstantExprSizeOf(const Type* Ty);
   
-  // ConstantVector accessors
-  Constant* getConstantVector(const VectorType* T,
-                              const std::vector<Constant*>& V);
-  Constant* getConstantVector(const std::vector<Constant*>& V);
-  Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
-  
   // MDNode accessors
   MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
   
@@ -211,7 +206,6 @@ public:
   void erase(MDString *M);
   void erase(MDNode *M);
   void erase(ConstantAggregateZero *Z);
-  void erase(ConstantVector *V);
 };
 
 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
index 31d4f8230b03e740a40237bf89ee0ac0d5e33d0d..b3c8a771b359587c3fabec1f7e9b855ad52f5964 100644 (file)
@@ -264,7 +264,7 @@ static Constant *FoldBitCast(Constant *C, const Type *DestTy,
         }
       }
       
-      return Context.getConstantVector(Result.data(), Result.size());
+      return ConstantVector::get(Result.data(), Result.size());
     }
   }
   
index fc58dbccc6d84da30f0546c077a2e48bcbb79730..430253746efa59f7920e7e07f8ab9a425070db3f 100644 (file)
@@ -1777,7 +1777,7 @@ bool LLParser::ParseValID(ValID &ID) {
                      "vector element #" + utostr(i) +
                     " is not of type '" + Elts[0]->getType()->getDescription());
     
-    ID.ConstantVal = Context.getConstantVector(Elts.data(), Elts.size());
+    ID.ConstantVal = ConstantVector::get(Elts.data(), Elts.size());
     ID.Kind = ValID::t_Constant;
     return false;
   }
index 117a8758d047fe2cb6902e2ef042951a67629b26..ed2e303870286445a27b44c034ed723a8c07b1fa 100644 (file)
@@ -294,7 +294,7 @@ void BitcodeReaderValueList::ResolveConstantForwardRefs() {
         NewC = ConstantStruct::get(&NewOps[0], NewOps.size(),
                                          UserCS->getType()->isPacked());
       } else if (isa<ConstantVector>(UserC)) {
-        NewC = Context.getConstantVector(&NewOps[0], NewOps.size());
+        NewC = ConstantVector::get(&NewOps[0], NewOps.size());
       } else {
         assert(isa<ConstantExpr>(UserC) && "Must be a ConstantExpr.");
         NewC = cast<ConstantExpr>(UserC)->getWithOperands(&NewOps[0],
@@ -935,7 +935,7 @@ bool BitcodeReader::ParseConstants() {
         const Type *EltTy = VTy->getElementType();
         for (unsigned i = 0; i != Size; ++i)
           Elts.push_back(ValueList.getConstantFwdRef(Record[i], EltTy));
-        V = Context.getConstantVector(Elts);
+        V = ConstantVector::get(Elts);
       } else {
         V = Context.getUndef(CurTy);
       }
index 4f4c255b082e6fb3bd32055a1c10f33b6d8a56d6..32f70a74caf6d2e445923fd52a0b91cb2db8bad4 100644 (file)
@@ -1849,7 +1849,7 @@ SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
         CV.push_back(Context->getUndef(OpNTy));
       }
     }
-    Constant *CP = Context->getConstantVector(CV);
+    Constant *CP = ConstantVector::get(CV);
     SDValue CPIdx = DAG.getConstantPool(CP, TLI.getPointerTy());
     unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
     return DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
index 3a8b782564c161ce9fa333a58e10ccd7c8107cbb..7134938060e74effc1b823b567fc710d04950cea 100644 (file)
@@ -2149,7 +2149,7 @@ void SelectionDAGLowering::visitFSub(User &I) {
       const Type *ElTy = DestTy->getElementType();
       unsigned VL = DestTy->getNumElements();
       std::vector<Constant*> NZ(VL, ConstantFP::getNegativeZero(ElTy));
-      Constant *CNZ = DAG.getContext()->getConstantVector(&NZ[0], NZ.size());
+      Constant *CNZ = ConstantVector::get(&NZ[0], NZ.size());
       if (CV == CNZ) {
         SDValue Op2 = getValue(I.getOperand(1));
         setValue(&I, DAG.getNode(ISD::FNEG, getCurDebugLoc(),
index 0e9976f1ca9f161e6db09d4239c6dbf9c565b293..858b8d18f170ace0784d6ec07f33e95b3895c9e6 100644 (file)
@@ -384,7 +384,7 @@ static Value *RemapOperand(const Value *In,
       for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
         Operands[i] = cast<Constant>(RemapOperand(CP->getOperand(i), ValueMap,
                                      Context));
-      Result = Context.getConstantVector(Operands);
+      Result = ConstantVector::get(Operands);
     } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CPV)) {
       std::vector<Constant*> Ops;
       for (unsigned i = 0, e = CE->getNumOperands(); i != e; ++i)
index 97b16dd608de1d836c888af80b53edc689e22691..d29ddaac4b3ca31f484fa7681ea6b6b9065bd317 100644 (file)
@@ -306,7 +306,7 @@ namespace {
         CV.push_back(const_cast<ConstantInt *> (V->getConstantIntValue()));
       }
 
-      Constant *CP = CurDAG->getContext()->getConstantVector(CV);
+      Constant *CP = ConstantVector::get(CV);
       SDValue CPIdx = CurDAG->getConstantPool(CP, SPUtli.getPointerTy());
       unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
       SDValue CGPoolOffset =
index f34deb1f4640d61e1201dbe58ecbf3a21143ba49..2322814b924c5a11c650d081e47d8a2058bd7e18 100644 (file)
@@ -4909,7 +4909,7 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) {
   CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x43300000)));
   CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
   CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
-  Constant *C0 = Context->getConstantVector(CV0);
+  Constant *C0 = ConstantVector::get(CV0);
   SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16);
 
   std::vector<Constant*> CV1;
@@ -4917,7 +4917,7 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op, SelectionDAG &DAG) {
     ConstantFP::get(*Context, APFloat(APInt(64, 0x4530000000000000ULL))));
   CV1.push_back(
     ConstantFP::get(*Context, APFloat(APInt(64, 0x4330000000000000ULL))));
-  Constant *C1 = Context->getConstantVector(CV1);
+  Constant *C1 = ConstantVector::get(CV1);
   SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16);
 
   SDValue XR1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v4i32,
@@ -5139,7 +5139,7 @@ SDValue X86TargetLowering::LowerFABS(SDValue Op, SelectionDAG &DAG) {
     CV.push_back(C);
     CV.push_back(C);
   }
-  Constant *C = Context->getConstantVector(CV);
+  Constant *C = ConstantVector::get(CV);
   SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
   SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
                                PseudoSourceValue::getConstantPool(), 0,
@@ -5169,7 +5169,7 @@ SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) {
     CV.push_back(C);
     CV.push_back(C);
   }
-  Constant *C = Context->getConstantVector(CV);
+  Constant *C = ConstantVector::get(CV);
   SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
   SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
                                PseudoSourceValue::getConstantPool(), 0,
@@ -5218,7 +5218,7 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) {
     CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
     CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
   }
-  Constant *C = Context->getConstantVector(CV);
+  Constant *C = ConstantVector::get(CV);
   SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
   SDValue Mask1 = DAG.getLoad(SrcVT, dl, DAG.getEntryNode(), CPIdx,
                                 PseudoSourceValue::getConstantPool(), 0,
@@ -5247,7 +5247,7 @@ SDValue X86TargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) {
     CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
     CV.push_back(ConstantFP::get(*Context, APFloat(APInt(32, 0))));
   }
-  C = Context->getConstantVector(CV);
+  C = ConstantVector::get(CV);
   CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
   SDValue Mask2 = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
                                 PseudoSourceValue::getConstantPool(), 0,
index be43c55d6bcef05186bd9560a8209b0c291278d5..28a226ccc9e4f58cd6da338cf19b699970e9ebf2 100644 (file)
@@ -1458,7 +1458,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
       }
 
     // If we changed the constant, return it.
-    Constant *NewCP = Context->getConstantVector(Elts);
+    Constant *NewCP = ConstantVector::get(Elts);
     return NewCP != CP ? NewCP : 0;
   } else if (isa<ConstantAggregateZero>(V)) {
     // Simplify the CAZ to a ConstantVector where the non-demanded elements are
@@ -1478,7 +1478,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
       Elts.push_back(Elt);
     }
     UndefElts = DemandedElts ^ EltMask;
-    return Context->getConstantVector(Elts);
+    return ConstantVector::get(Elts);
   }
   
   // Limit search depth.
@@ -1597,7 +1597,7 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
           Elts.push_back(ConstantInt::get(Type::Int32Ty,
                                           Shuffle->getMaskValue(i)));
       }
-      I->setOperand(2, Context->getConstantVector(Elts));
+      I->setOperand(2, ConstantVector::get(Elts));
       MadeChange = true;
     }
     break;
@@ -2926,7 +2926,7 @@ Instruction *InstCombiner::commonIDivTransforms(BinaryOperator &I) {
     if (const VectorType *Ty = dyn_cast<VectorType>(I.getType())) {
       Constant *CI = ConstantInt::get(Ty->getElementType(), 1);
       std::vector<Constant*> Elts(Ty->getNumElements(), CI);
-      return ReplaceInstUsesWith(I, Context->getConstantVector(Elts));
+      return ReplaceInstUsesWith(I, ConstantVector::get(Elts));
     }
 
     Constant *CI = ConstantInt::get(I.getType(), 1);
@@ -3259,7 +3259,7 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
         }
       }
 
-      Constant *NewRHSV = Context->getConstantVector(Elts);
+      Constant *NewRHSV = ConstantVector::get(Elts);
       if (NewRHSV != RHSV) {
         AddUsesToWorkList(I);
         I.setOperand(1, NewRHSV);
@@ -12689,7 +12689,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
         Mask[InsertedIdx] = 
                            ConstantInt::get(Type::Int32Ty, ExtractedIdx);
         return new ShuffleVectorInst(EI->getOperand(0), VecOp,
-                                     Context->getConstantVector(Mask));
+                                     ConstantVector::get(Mask));
       }
       
       // If this insertelement isn't used by some other insertelement, turn it
@@ -12701,7 +12701,7 @@ Instruction *InstCombiner::visitInsertElementInst(InsertElementInst &IE) {
         if (RHS == 0) RHS = Context->getUndef(LHS->getType());
         // We now have a shuffle of LHS, RHS, Mask.
         return new ShuffleVectorInst(LHS, RHS,
-                                     Context->getConstantVector(Mask));
+                                     ConstantVector::get(Mask));
       }
     }
   }
@@ -12766,7 +12766,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
     }
     SVI.setOperand(0, SVI.getOperand(1));
     SVI.setOperand(1, Context->getUndef(RHS->getType()));
-    SVI.setOperand(2, Context->getConstantVector(Elts));
+    SVI.setOperand(2, ConstantVector::get(Elts));
     LHS = SVI.getOperand(0);
     RHS = SVI.getOperand(1);
     MadeChange = true;
@@ -12823,7 +12823,7 @@ Instruction *InstCombiner::visitShuffleVectorInst(ShuffleVectorInst &SVI) {
         }
         return new ShuffleVectorInst(LHSSVI->getOperand(0),
                                      LHSSVI->getOperand(1),
-                                     Context->getConstantVector(Elts));
+                                     ConstantVector::get(Elts));
       }
     }
   }
index a182943c784fab0c6ea7eea65e5c6923148267f5..5fdc497727c986cc054c5c5b30789be2d1961cb9 100644 (file)
@@ -850,7 +850,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *BCInst,
           if (EltTy != ValTy) {
             unsigned NumElts = cast<VectorType>(ValTy)->getNumElements();
             SmallVector<Constant*, 16> Elts(NumElts, StoreVal);
-            StoreVal = Context.getConstantVector(&Elts[0], NumElts);
+            StoreVal = ConstantVector::get(&Elts[0], NumElts);
           }
         }
         new StoreInst(StoreVal, EltPtr, MI);
index 673bb0b58e027b0cacd62bea61adde3458bfdd41..3bef8124e176c507e37866e075ad3baedff9eb71 100644 (file)
@@ -101,7 +101,7 @@ Value *llvm::MapValue(const Value *V, ValueMapTy &VM, LLVMContext &Context) {
           Values.push_back(cast<Constant>(MV));
           for (++i; i != e; ++i)
             Values.push_back(cast<Constant>(MapValue(*i, VM, Context)));
-          return VM[V] = Context.getConstantVector(Values);
+          return VM[V] = ConstantVector::get(Values);
         }
       }
       return VM[V] = C;
index c771500d91411e6bc922354c6c107d75e6a5bc37..fc86e54682d023d2f82474adc8a2bd75eb15e2cb 100644 (file)
@@ -281,7 +281,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
           Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
           Idxs.push_back(ConstantInt::get(Type::Int32Ty, 1));
         }
-        Value *Mask = Context.getConstantVector(Idxs);
+        Value *Mask = ConstantVector::get(Idxs);
         SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
       } else if (isMovL) {
         Constant *Zero = ConstantInt::get(Type::Int32Ty, 0);
@@ -289,14 +289,14 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
         Idxs.push_back(Zero);
         Idxs.push_back(Zero);
         Idxs.push_back(Zero);
-        Value *ZeroV = Context.getConstantVector(Idxs);
+        Value *ZeroV = ConstantVector::get(Idxs);
 
         Idxs.clear(); 
         Idxs.push_back(ConstantInt::get(Type::Int32Ty, 4));
         Idxs.push_back(ConstantInt::get(Type::Int32Ty, 5));
         Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
         Idxs.push_back(ConstantInt::get(Type::Int32Ty, 3));
-        Value *Mask = Context.getConstantVector(Idxs);
+        Value *Mask = ConstantVector::get(Idxs);
         SI = new ShuffleVectorInst(ZeroV, Op0, Mask, "upgraded.", CI);
       } else if (isMovSD ||
                  isUnpckhPD || isUnpcklPD || isPunpckhQPD || isPunpcklQPD) {
@@ -311,7 +311,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
           Idxs.push_back(ConstantInt::get(Type::Int32Ty, 0));
           Idxs.push_back(ConstantInt::get(Type::Int32Ty, 2));
         }
-        Value *Mask = Context.getConstantVector(Idxs);
+        Value *Mask = ConstantVector::get(Idxs);
         SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
       } else if (isShufPD) {
         Value *Op1 = CI->getOperand(2);
@@ -319,7 +319,7 @@ void llvm::UpgradeIntrinsicCall(CallInst *CI, Function *NewFn) {
         Idxs.push_back(ConstantInt::get(Type::Int32Ty, MaskVal & 1));
         Idxs.push_back(ConstantInt::get(Type::Int32Ty,
                                                ((MaskVal >> 1) & 1)+2));
-        Value *Mask = Context.getConstantVector(Idxs);
+        Value *Mask = ConstantVector::get(Idxs);
         SI = new ShuffleVectorInst(Op0, Op1, Mask, "upgraded.", CI);
       }
 
index 3c0d94e4e3ae5c7095ff7d94af7c24c5991e01ae..2fdf08d394e2cc7c315d121f485030a0ad48bed4 100644 (file)
@@ -63,7 +63,7 @@ static Constant *BitCastConstantVector(LLVMContext &Context, ConstantVector *CV,
   for (unsigned i = 0; i != NumElts; ++i)
     Result.push_back(Context.getConstantExprBitCast(CV->getOperand(i),
                                                     DstEltTy));
-  return Context.getConstantVector(Result);
+  return ConstantVector::get(Result);
 }
 
 /// This function determines which opcode to use to fold two constant cast 
@@ -145,7 +145,7 @@ static Constant *FoldBitCast(LLVMContext &Context,
     // can only be handled by Analysis/ConstantFolding.cpp).
     if (isa<ConstantInt>(V) || isa<ConstantFP>(V))
       return Context.getConstantExprBitCast(
-                                     Context.getConstantVector(&V, 1), DestPTy);
+                                     ConstantVector::get(&V, 1), DestPTy);
   }
   
   // Finally, implement bitcast folding now.   The code below doesn't handle
@@ -228,7 +228,7 @@ Constant *llvm::ConstantFoldCastInstruction(LLVMContext &Context,
       for (unsigned i = 0, e = CV->getType()->getNumElements(); i != e; ++i)
         res.push_back(Context.getConstantExprCast(opc,
                                             CV->getOperand(i), DstEltTy));
-      return Context.getConstantVector(DestVecTy, res);
+      return ConstantVector::get(DestVecTy, res);
     }
 
   // We actually have to do a cast now. Perform the cast according to the
@@ -374,7 +374,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
         (idxVal == i) ? Elt : Context.getUndef(Elt->getType());
       Ops.push_back(const_cast<Constant*>(Op));
     }
-    return Context.getConstantVector(Ops);
+    return ConstantVector::get(Ops);
   }
   if (isa<ConstantAggregateZero>(Val)) {
     // Insertion of scalar constant into vector aggregate zero
@@ -392,7 +392,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
         (idxVal == i) ? Elt : Context.getNullValue(Elt->getType());
       Ops.push_back(const_cast<Constant*>(Op));
     }
-    return Context.getConstantVector(Ops);
+    return ConstantVector::get(Ops);
   }
   if (const ConstantVector *CVal = dyn_cast<ConstantVector>(Val)) {
     // Insertion of scalar constant into vector constant
@@ -403,7 +403,7 @@ Constant *llvm::ConstantFoldInsertElementInstruction(LLVMContext &Context,
         (idxVal == i) ? Elt : cast<Constant>(CVal->getOperand(i));
       Ops.push_back(const_cast<Constant*>(Op));
     }
-    return Context.getConstantVector(Ops);
+    return ConstantVector::get(Ops);
   }
 
   return 0;
@@ -459,7 +459,7 @@ Constant *llvm::ConstantFoldShuffleVectorInstruction(LLVMContext &Context,
     Result.push_back(InElt);
   }
 
-  return Context.getConstantVector(&Result[0], Result.size());
+  return ConstantVector::get(&Result[0], Result.size());
 }
 
 Constant *llvm::ConstantFoldExtractValueInstruction(LLVMContext &Context,
@@ -829,7 +829,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprAdd(const_cast<Constant*>(C1),
                                                    const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::FAdd:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -837,7 +837,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprFAdd(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::Sub:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -845,7 +845,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprSub(const_cast<Constant*>(C1),
                                                    const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::FSub:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -853,7 +853,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprFSub(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::Mul:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -861,7 +861,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprMul(const_cast<Constant*>(C1),
                                                    const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::FMul:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -869,7 +869,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprFMul(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::UDiv:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -877,7 +877,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprUDiv(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::SDiv:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -885,7 +885,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprSDiv(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::FDiv:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -893,7 +893,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprFDiv(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::URem:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -901,7 +901,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprURem(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::SRem:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -909,7 +909,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprSRem(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::FRem:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -917,7 +917,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprFRem(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::And: 
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -925,7 +925,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprAnd(const_cast<Constant*>(C1),
                                                    const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::Or:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -933,7 +933,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprOr(const_cast<Constant*>(C1),
                                                   const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::Xor:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -941,7 +941,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprXor(const_cast<Constant*>(C1),
                                                    const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::LShr:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -949,7 +949,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprLShr(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::AShr:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -957,7 +957,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprAShr(const_cast<Constant*>(C1),
                                                     const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       case Instruction::Shl:
         for (unsigned i = 0, e = VTy->getNumElements(); i != e; ++i) {
           C1 = CP1 ? CP1->getOperand(i) : Context.getNullValue(EltTy);
@@ -965,7 +965,7 @@ Constant *llvm::ConstantFoldBinaryInstruction(LLVMContext &Context,
           Res.push_back(Context.getConstantExprShl(const_cast<Constant*>(C1),
                                                    const_cast<Constant*>(C2)));
         }
-        return Context.getConstantVector(Res);
+        return ConstantVector::get(Res);
       }
     }
   }
@@ -1496,7 +1496,7 @@ Constant *llvm::ConstantFoldCompareInstruction(LLVMContext &Context,
       ResElts.push_back(
                     Context.getConstantExprCompare(pred, C1Elts[i], C2Elts[i]));
     }
-    return Context.getConstantVector(&ResElts[0], ResElts.size());
+    return ConstantVector::get(&ResElts[0], ResElts.size());
   }
 
   if (C1->getType()->isFloatingPoint()) {
index ec1bf13e5d268203f8684c8efbdaaa69063ba7fd..31a82e59f2f0390b561c4a7148c034318011aaf4 100644 (file)
@@ -206,7 +206,7 @@ Constant* ConstantInt::get(const Type* Ty, uint64_t V, bool isSigned) {
 
   // For vectors, broadcast the value.
   if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
-    return Ty->getContext().getConstantVector(
+    return ConstantVector::get(
       std::vector<Constant *>(VTy->getNumElements(), C));
 
   return C;
@@ -232,7 +232,7 @@ Constant* ConstantInt::get(const Type* Ty, const APInt& V) {
 
   // For vectors, broadcast the value.
   if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
-    return Ty->getContext().getConstantVector(
+    return ConstantVector::get(
       std::vector<Constant *>(VTy->getNumElements(), C));
 
   return C;
@@ -270,7 +270,7 @@ Constant* ConstantFP::get(const Type* Ty, double V) {
 
   // For vectors, broadcast the value.
   if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
-    return Context.getConstantVector(
+    return ConstantVector::get(
       std::vector<Constant *>(VTy->getNumElements(), C));
 
   return C;
@@ -290,7 +290,7 @@ Constant* ConstantFP::getZeroValueForNegation(const Type* Ty) {
     if (PTy->getElementType()->isFloatingPoint()) {
       std::vector<Constant*> zeros(PTy->getNumElements(),
                            getNegativeZero(PTy->getElementType()));
-      return Context.getConstantVector(PTy, zeros);
+      return ConstantVector::get(PTy, zeros);
     }
 
   if (Ty->isFloatingPoint()) 
@@ -490,6 +490,46 @@ ConstantVector::ConstantVector(const VectorType *T,
   }
 }
 
+// ConstantVector accessors.
+Constant* ConstantVector::get(const VectorType* T,
+                              const std::vector<Constant*>& V) {
+   assert(!V.empty() && "Vectors can't be empty");
+   LLVMContext &Context = T->getContext();
+   LLVMContextImpl *pImpl = Context.pImpl;
+   
+  // If this is an all-undef or alll-zero vector, return a
+  // ConstantAggregateZero or UndefValue.
+  Constant *C = V[0];
+  bool isZero = C->isNullValue();
+  bool isUndef = isa<UndefValue>(C);
+
+  if (isZero || isUndef) {
+    for (unsigned i = 1, e = V.size(); i != e; ++i)
+      if (V[i] != C) {
+        isZero = isUndef = false;
+        break;
+      }
+  }
+  
+  if (isZero)
+    return Context.getConstantAggregateZero(T);
+  if (isUndef)
+    return Context.getUndef(T);
+    
+  // Implicitly locked.
+  return pImpl->VectorConstants.getOrCreate(T, V);
+}
+
+Constant* ConstantVector::get(const std::vector<Constant*>& V) {
+  assert(!V.empty() && "Cannot infer type if V is empty");
+  return get(VectorType::get(V.front()->getType(),V.size()), V);
+}
+
+Constant* ConstantVector::get(Constant* const* Vals, unsigned NumVals) {
+  // FIXME: make this the primary ctor method.
+  return get(std::vector<Constant*>(Vals, Vals+NumVals));
+}
+
 
 namespace llvm {
 // We declare several classes private to this file, so use an anonymous
@@ -1064,7 +1104,7 @@ void ConstantStruct::destroyConstant() {
 //
 void ConstantVector::destroyConstant() {
   // Implicitly locked.
-  getType()->getContext().erase(this);
+  getType()->getContext().pImpl->VectorConstants.remove(this);
   destroyConstantImpl();
 }
 
@@ -2127,6 +2167,14 @@ void ConstantStruct::replaceUsesOfWithOnConstant(Value *From, Value *To,
   destroyConstant();
 }
 
+static std::vector<Constant*> getValType(ConstantVector *CP) {
+  std::vector<Constant*> Elements;
+  Elements.reserve(CP->getNumOperands());
+  for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
+    Elements.push_back(CP->getOperand(i));
+  return Elements;
+}
+
 void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To,
                                                  Use *U) {
   assert(isa<Constant>(To) && "Cannot make Constant refer to non-constant!");
@@ -2139,8 +2187,7 @@ void ConstantVector::replaceUsesOfWithOnConstant(Value *From, Value *To,
     Values.push_back(Val);
   }
   
-  Constant *Replacement =
-    getType()->getContext().getConstantVector(getType(), Values);
+  Constant *Replacement = get(getType(), Values);
   assert(Replacement != this && "I didn't contain From!");
   
   // Everyone using this now uses the replacement.
index a262f40c496860171de1ef7537aaae239261e615..d1e6fb26f63d477918493c9ba3a779c992ef1fbd 100644 (file)
@@ -421,7 +421,7 @@ LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
 }
 
 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
-  return wrap(getGlobalContext().getConstantVector(
+  return wrap(ConstantVector::get(
                             unwrap<Constant>(ScalarConstantVals, Size), Size));
 }
 
index a90bb4afcbddb198668dc108eff12fbfdb940fdd..0b242415054401e1dc8d566b8eaff664ddb6d1a8 100644 (file)
@@ -1616,7 +1616,7 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
   Constant *C;
   if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
     C = Context.getAllOnesValue(PTy->getElementType());
-    C = Context.getConstantVector(
+    C = ConstantVector::get(
                               std::vector<Constant*>(PTy->getNumElements(), C));
   } else {
     C = Context.getAllOnesValue(Op->getType());
@@ -1633,7 +1633,7 @@ BinaryOperator *BinaryOperator::CreateNot(LLVMContext &Context,
   if (const VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
     // Create a vector of all ones values.
     Constant *Elt = Context.getAllOnesValue(PTy->getElementType());
-    AllOnes = Context.getConstantVector(
+    AllOnes = ConstantVector::get(
                             std::vector<Constant*>(PTy->getNumElements(), Elt));
   } else {
     AllOnes = Context.getAllOnesValue(Op->getType());
index 97857c5dda70a919e8abe1187b1992590d9f42f4..14a891fb90659f2de0ae2a9a488e6f767335dd1d 100644 (file)
@@ -72,7 +72,7 @@ Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
   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));
+  return cast<ConstantVector>(ConstantVector::get(Elts));
 }
 
 // UndefValue accessors.
@@ -367,23 +367,6 @@ Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
   return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
 }
 
-// ConstantVector accessors.
-Constant* LLVMContext::getConstantVector(const VectorType* T,
-                            const std::vector<Constant*>& V) {
-  return pImpl->getConstantVector(T, V);
-}
-
-Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
-  assert(!V.empty() && "Cannot infer type if V is empty");
-  return getConstantVector(getVectorType(V.front()->getType(),V.size()), V);
-}
-
-Constant* LLVMContext::getConstantVector(Constant* const* Vals,
-                                         unsigned NumVals) {
-  // FIXME: make this the primary ctor method.
-  return getConstantVector(std::vector<Constant*>(Vals, Vals+NumVals));
-}
-
 // MDNode accessors
 MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
   return pImpl->getMDNode(Vals, NumVals);
@@ -488,7 +471,3 @@ void LLVMContext::erase(MDNode *M) {
 void LLVMContext::erase(ConstantAggregateZero *Z) {
   pImpl->erase(Z);
 }
-
-void LLVMContext::erase(ConstantVector *V) {
-  pImpl->erase(V);
-}
index 72e415cd66b66fbd1f40097312845df70fd493f9..5efc1ebe5e7648f3b80f30c198d122d7265dd547 100644 (file)
@@ -21,15 +21,6 @@ using namespace llvm;
 
 static char getValType(ConstantAggregateZero *CPZ) { return 0; }
 
-static std::vector<Constant*> getValType(ConstantVector *CP) {
-  std::vector<Constant*> Elements;
-  Elements.reserve(CP->getNumOperands());
-  for (unsigned i = 0, e = CP->getNumOperands(); i != e; ++i)
-    Elements.push_back(CP->getOperand(i));
-  return Elements;
-}
-
-
 LLVMContextImpl::LLVMContextImpl(LLVMContext &C) :
     Context(C), TheTrueVal(0), TheFalseVal(0) { }
 
@@ -77,32 +68,6 @@ LLVMContextImpl::getConstantAggregateZero(const Type *Ty) {
   return AggZeroConstants.getOrCreate(Ty, 0);
 }
 
-Constant *LLVMContextImpl::getConstantVector(const VectorType *Ty,
-                              const std::vector<Constant*> &V) {
-  assert(!V.empty() && "Vectors can't be empty");
-  // If this is an all-undef or alll-zero vector, return a
-  // ConstantAggregateZero or UndefValue.
-  Constant *C = V[0];
-  bool isZero = C->isNullValue();
-  bool isUndef = isa<UndefValue>(C);
-
-  if (isZero || isUndef) {
-    for (unsigned i = 1, e = V.size(); i != e; ++i)
-      if (V[i] != C) {
-        isZero = isUndef = false;
-        break;
-      }
-  }
-  
-  if (isZero)
-    return Context.getConstantAggregateZero(Ty);
-  if (isUndef)
-    return Context.getUndef(Ty);
-    
-  // Implicitly locked.
-  return VectorConstants.getOrCreate(Ty, V);
-}
-
 // *** erase methods ***
 
 void LLVMContextImpl::erase(MDString *M) {
@@ -118,7 +83,3 @@ void LLVMContextImpl::erase(MDNode *M) {
 void LLVMContextImpl::erase(ConstantAggregateZero *Z) {
   AggZeroConstants.remove(Z);
 }
-
-void LLVMContextImpl::erase(ConstantVector *V) {
-  VectorConstants.remove(V);
-}
index eea495d1dbefe096300b10ab60ebb7da3bd83207..ebcb8a44f1b381ee6047b9ac8e954e89060378c9 100644 (file)
@@ -117,7 +117,7 @@ struct ConvertConstantType<ConstantVector, VectorType> {
     std::vector<Constant*> C;
     for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i)
       C.push_back(cast<Constant>(OldC->getOperand(i)));
-    Constant *New = OldC->getContext().getConstantVector(NewTy, C);
+    Constant *New = ConstantVector::get(NewTy, C);
     assert(New != OldC && "Didn't replace constant??");
     OldC->uncheckedReplaceAllUsesWith(New);
     OldC->destroyConstant();    // This constant is now dead, destroy it.
@@ -460,6 +460,7 @@ class LLVMContextImpl {
   friend class ConstantFP;
   friend class ConstantStruct;
   friend class ConstantArray;
+  friend class ConstantVector;
 public:
   LLVMContextImpl(LLVMContext &C);
   
@@ -469,9 +470,6 @@ public:
   
   ConstantAggregateZero *getConstantAggregateZero(const Type *Ty);
   
-  Constant *getConstantVector(const VectorType *Ty,
-                              const std::vector<Constant*> &V);
-  
   ConstantInt *getTrue() {
     if (TheTrueVal)
       return TheTrueVal;