diff options
Diffstat (limited to 'llvm/lib/VMCore')
-rw-r--r-- | llvm/lib/VMCore/AutoUpgrade.cpp | 10 | ||||
-rw-r--r-- | llvm/lib/VMCore/ConstantFold.cpp | 52 | ||||
-rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 61 | ||||
-rw-r--r-- | llvm/lib/VMCore/Core.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/VMCore/Instructions.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/VMCore/LLVMContext.cpp | 23 | ||||
-rw-r--r-- | llvm/lib/VMCore/LLVMContextImpl.cpp | 39 | ||||
-rw-r--r-- | llvm/lib/VMCore/LLVMContextImpl.h | 6 |
8 files changed, 91 insertions, 106 deletions
diff --git a/llvm/lib/VMCore/AutoUpgrade.cpp b/llvm/lib/VMCore/AutoUpgrade.cpp index c771500d914..fc86e54682d 100644 --- a/llvm/lib/VMCore/AutoUpgrade.cpp +++ b/llvm/lib/VMCore/AutoUpgrade.cpp @@ -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); } diff --git a/llvm/lib/VMCore/ConstantFold.cpp b/llvm/lib/VMCore/ConstantFold.cpp index 3c0d94e4e3a..2fdf08d394e 100644 --- a/llvm/lib/VMCore/ConstantFold.cpp +++ b/llvm/lib/VMCore/ConstantFold.cpp @@ -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()) { diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index ec1bf13e5d2..31a82e59f2f 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -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. diff --git a/llvm/lib/VMCore/Core.cpp b/llvm/lib/VMCore/Core.cpp index a262f40c496..d1e6fb26f63 100644 --- a/llvm/lib/VMCore/Core.cpp +++ b/llvm/lib/VMCore/Core.cpp @@ -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)); } diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp index a90bb4afcbd..0b242415054 100644 --- a/llvm/lib/VMCore/Instructions.cpp +++ b/llvm/lib/VMCore/Instructions.cpp @@ -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()); diff --git a/llvm/lib/VMCore/LLVMContext.cpp b/llvm/lib/VMCore/LLVMContext.cpp index 97857c5dda7..14a891fb906 100644 --- a/llvm/lib/VMCore/LLVMContext.cpp +++ b/llvm/lib/VMCore/LLVMContext.cpp @@ -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); -} diff --git a/llvm/lib/VMCore/LLVMContextImpl.cpp b/llvm/lib/VMCore/LLVMContextImpl.cpp index 72e415cd66b..5efc1ebe5e7 100644 --- a/llvm/lib/VMCore/LLVMContextImpl.cpp +++ b/llvm/lib/VMCore/LLVMContextImpl.cpp @@ -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); -} diff --git a/llvm/lib/VMCore/LLVMContextImpl.h b/llvm/lib/VMCore/LLVMContextImpl.h index eea495d1dbe..ebcb8a44f1b 100644 --- a/llvm/lib/VMCore/LLVMContextImpl.h +++ b/llvm/lib/VMCore/LLVMContextImpl.h @@ -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; |