From: Owen Anderson Date: Fri, 31 Jul 2009 22:45:43 +0000 (+0000) Subject: Privatize all but one of the remaining constant tables. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7e3142b0126abc86dc4da350e8b84b001c3eedde;p=oota-llvm.git Privatize all but one of the remaining constant tables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77748 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 038ee35aee0..05f0ddb489b 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -63,6 +63,9 @@ class LLVMContext { friend class ConstantAggregateZero; friend class MDNode; friend class MDString; + friend class ConstantPointerNull; + friend class UndefValue; + friend class ConstantExpr; public: LLVMContext(); ~LLVMContext(); diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 4f0c411e2fa..7482154d839 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -40,9 +40,6 @@ using namespace llvm; // Constant Class //===----------------------------------------------------------------------===// -// Becomes a no-op when multithreading is disabled. -ManagedStatic > ConstantsLock; - // Constructor to create a '0' constant of arbitrary type... static const uint64_t zero[2] = {0, 0}; Constant* Constant::getNullValue(const Type* Ty) { @@ -1208,30 +1205,6 @@ Constant *ConstantVector::getSplatValue() { //---- ConstantPointerNull::get() implementation... // -namespace llvm { - // ConstantPointerNull does not take extra "value" argument... - template - struct ConstantCreator { - static ConstantPointerNull *create(const PointerType *Ty, const ValType &V){ - return new ConstantPointerNull(Ty); - } - }; - - template<> - struct ConvertConstantType { - static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) { - // Make everyone now use a constant of the new type... - Constant *New = ConstantPointerNull::get(NewTy); - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } - }; -} - -static ManagedStatic > NullPtrConstants; - static char getValType(ConstantPointerNull *) { return 0; } @@ -1239,14 +1212,14 @@ static char getValType(ConstantPointerNull *) { ConstantPointerNull *ConstantPointerNull::get(const PointerType *Ty) { // Implicitly locked. - return NullPtrConstants->getOrCreate(Ty, 0); + return Ty->getContext().pImpl->NullPtrConstants.getOrCreate(Ty, 0); } // destroyConstant - Remove the constant from the constant table... // void ConstantPointerNull::destroyConstant() { // Implicitly locked. - NullPtrConstants->remove(this); + getType()->getContext().pImpl->NullPtrConstants.remove(this); destroyConstantImpl(); } @@ -1254,44 +1227,20 @@ void ConstantPointerNull::destroyConstant() { //---- UndefValue::get() implementation... // -namespace llvm { - // UndefValue does not take extra "value" argument... - template - struct ConstantCreator { - static UndefValue *create(const Type *Ty, const ValType &V) { - return new UndefValue(Ty); - } - }; - - template<> - struct ConvertConstantType { - static void convert(UndefValue *OldC, const Type *NewTy) { - // Make everyone now use a constant of the new type. - Constant *New = UndefValue::get(NewTy); - assert(New != OldC && "Didn't replace constant??"); - OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. - } - }; -} - -static ManagedStatic > UndefValueConstants; - static char getValType(UndefValue *) { return 0; } - UndefValue *UndefValue::get(const Type *Ty) { // Implicitly locked. - return UndefValueConstants->getOrCreate(Ty, 0); + return Ty->getContext().pImpl->UndefValueConstants.getOrCreate(Ty, 0); } // destroyConstant - Remove the constant from the constant table. // void UndefValue::destroyConstant() { // Implicitly locked. - UndefValueConstants->remove(this); + getType()->getContext().pImpl->UndefValueConstants.remove(this); destroyConstantImpl(); } diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index 7a29a8421f4..6d189339eb0 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -70,6 +70,20 @@ struct ConstantCreator { } }; +template<> +struct ConvertConstantType { + static void convert(ConstantVector *OldC, const VectorType *NewTy) { + // Make everyone now use a constant of the new type... + std::vector C; + for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) + C.push_back(cast(OldC->getOperand(i))); + 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. + } +}; + template<> struct ConvertConstantType { static void convert(ConstantAggregateZero *OldC, const Type *NewTy) { @@ -110,17 +124,41 @@ struct ConvertConstantType { } }; +// ConstantPointerNull does not take extra "value" argument... +template +struct ConstantCreator { + static ConstantPointerNull *create(const PointerType *Ty, const ValType &V){ + return new ConstantPointerNull(Ty); + } +}; + template<> -struct ConvertConstantType { - static void convert(ConstantVector *OldC, const VectorType *NewTy) { +struct ConvertConstantType { + static void convert(ConstantPointerNull *OldC, const PointerType *NewTy) { // Make everyone now use a constant of the new type... - std::vector C; - for (unsigned i = 0, e = OldC->getNumOperands(); i != e; ++i) - C.push_back(cast(OldC->getOperand(i))); - Constant *New = ConstantVector::get(NewTy, C); + Constant *New = ConstantPointerNull::get(NewTy); assert(New != OldC && "Didn't replace constant??"); OldC->uncheckedReplaceAllUsesWith(New); - OldC->destroyConstant(); // This constant is now dead, destroy it. + OldC->destroyConstant(); // This constant is now dead, destroy it. + } +}; + +// UndefValue does not take extra "value" argument... +template +struct ConstantCreator { + static UndefValue *create(const Type *Ty, const ValType &V) { + return new UndefValue(Ty); + } +}; + +template<> +struct ConvertConstantType { + static void convert(UndefValue *OldC, const Type *NewTy) { + // Make everyone now use a constant of the new type. + Constant *New = UndefValue::get(NewTy); + assert(New != OldC && "Didn't replace constant??"); + OldC->uncheckedReplaceAllUsesWith(New); + OldC->destroyConstant(); // This constant is now dead, destroy it. } }; @@ -449,6 +487,10 @@ class LLVMContextImpl { ConstantVector> VectorConstantsTy; VectorConstantsTy VectorConstants; + ValueMap NullPtrConstants; + + ValueMap UndefValueConstants; + LLVMContext &Context; ConstantInt *TheTrueVal; ConstantInt *TheFalseVal; @@ -464,6 +506,8 @@ class LLVMContextImpl { friend class ConstantAggregateZero; friend class MDNode; friend class MDString; + friend class ConstantPointerNull; + friend class UndefValue; public: LLVMContextImpl(LLVMContext &C); };