diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-24 00:36:24 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-24 00:36:24 +0000 |
commit | 5bd68393ed87bcedc53f5998f1af9c906f5a1b4e (patch) | |
tree | 235459cdde1f0a882a34eb024e72dce11b333e3b /lib/VMCore/LLVMContextImpl.cpp | |
parent | fbd6687cf1fb3408e8e34994f13e69c754e5c15e (diff) |
Privatize the ConstantVector tables.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76922 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore/LLVMContextImpl.cpp')
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index 156d4cacd1..34fc6e52f8 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -37,6 +37,14 @@ static std::vector<Constant*> getValType(ConstantStruct *CS) { return Elements; } +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; +} + namespace llvm { template<typename T, typename Alloc> struct VISIBILITY_HIDDEN ConstantTraits< std::vector<T, Alloc> > { @@ -106,6 +114,20 @@ struct ConvertConstantType<ConstantStruct, StructType> { OldC->destroyConstant(); // This constant is now dead, destroy it. } }; + +template<> +struct ConvertConstantType<ConstantVector, VectorType> { + static void convert(ConstantVector *OldC, const VectorType *NewTy) { + // Make everyone now use a constant of the new type... + 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); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. + } +}; } template<class ValType, class TypeClass, class ConstantClass, @@ -348,12 +370,14 @@ LLVMContextImpl::LLVMContextImpl(LLVMContext &C) : AggZeroConstants = new ValueMap<char, Type, ConstantAggregateZero>(); ArrayConstants = new ArrayConstantsTy(); StructConstants = new StructConstantsTy(); + VectorConstants = new VectorConstantsTy(); } LLVMContextImpl::~LLVMContextImpl() { delete AggZeroConstants; delete ArrayConstants; delete StructConstants; + delete VectorConstants; } // Get a ConstantInt from an APInt. Note that the value stored in the DenseMap @@ -492,6 +516,32 @@ Constant *LLVMContextImpl::getConstantStruct(const StructType *Ty, return Context.getConstantAggregateZero(Ty); } +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) { @@ -517,6 +567,10 @@ void LLVMContextImpl::erase(ConstantStruct *S) { StructConstants->remove(S); } +void LLVMContextImpl::erase(ConstantVector *V) { + VectorConstants->remove(V); +} + // *** RAUW helpers *** Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantArray *CA, @@ -659,4 +713,4 @@ Constant *LLVMContextImpl::replaceUsesOfWithOnConstant(ConstantStruct *CS, assert(Replacement != CS && "I didn't contain From!"); return Replacement; -}
\ No newline at end of file +} |