diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-30 23:03:37 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-30 23:03:37 +0000 |
commit | 9e9a0d5fc26878e51a58a8b57900fcbf952c2691 (patch) | |
tree | 477eb7b58abe6134ff6accc805279396a77892e8 /lib/VMCore | |
parent | 124e6eb09d47674a4bac48a522e83e4513a970e5 (diff) | |
download | external_llvm-9e9a0d5fc26878e51a58a8b57900fcbf952c2691.zip external_llvm-9e9a0d5fc26878e51a58a8b57900fcbf952c2691.tar.gz external_llvm-9e9a0d5fc26878e51a58a8b57900fcbf952c2691.tar.bz2 |
Move more code back to 2.5 APIs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77635 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/AutoUpgrade.cpp | 3 | ||||
-rw-r--r-- | lib/VMCore/BasicBlock.cpp | 2 | ||||
-rw-r--r-- | lib/VMCore/ConstantFold.cpp | 46 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 27 | ||||
-rw-r--r-- | lib/VMCore/Core.cpp | 4 | ||||
-rw-r--r-- | lib/VMCore/Instructions.cpp | 7 | ||||
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 23 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 15 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 6 |
9 files changed, 53 insertions, 80 deletions
diff --git a/lib/VMCore/AutoUpgrade.cpp b/lib/VMCore/AutoUpgrade.cpp index 81d143a..7f6c7e1 100644 --- a/lib/VMCore/AutoUpgrade.cpp +++ b/lib/VMCore/AutoUpgrade.cpp @@ -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); diff --git a/lib/VMCore/BasicBlock.cpp b/lib/VMCore/BasicBlock.cpp index d0fa02c..d7ff3bc 100644 --- a/lib/VMCore/BasicBlock.cpp +++ b/lib/VMCore/BasicBlock.cpp @@ -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 } diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index ab00160..6e6c9b0 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -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())); } } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 1ff596f..f7d6946 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -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); diff --git a/lib/VMCore/Core.cpp b/lib/VMCore/Core.cpp index 59aeb87..be71d37 100644 --- a/lib/VMCore/Core.cpp +++ b/lib/VMCore/Core.cpp @@ -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 ......................................--*/ diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index 08b4396..3689146 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -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 diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index 8bd45b2..23c73c5 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -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); -} diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index 23d8ca3..bba5861 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -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); -} diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index c092603..f2cdcf4 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -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); }; } |