diff options
author | Owen Anderson <resistor@mac.com> | 2009-07-16 23:44:30 +0000 |
---|---|---|
committer | Owen Anderson <resistor@mac.com> | 2009-07-16 23:44:30 +0000 |
commit | d92c6dd218b1d5e46be25eac70d03ffd6664a608 (patch) | |
tree | 786a371b3156bf0711bb6843d058d1392f268977 | |
parent | 24270fab43b2f3314cc6be7b14bfc8e5f2a8828b (diff) | |
download | external_llvm-d92c6dd218b1d5e46be25eac70d03ffd6664a608.zip external_llvm-d92c6dd218b1d5e46be25eac70d03ffd6664a608.tar.gz external_llvm-d92c6dd218b1d5e46be25eac70d03ffd6664a608.tar.bz2 |
Privatize the MDNode uniquing table.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76126 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/llvm/LLVMContext.h | 1 | ||||
-rw-r--r-- | include/llvm/MDNode.h | 7 | ||||
-rw-r--r-- | lib/VMCore/Constants.cpp | 31 | ||||
-rw-r--r-- | lib/VMCore/LLVMContext.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.cpp | 30 | ||||
-rw-r--r-- | lib/VMCore/LLVMContextImpl.h | 7 |
6 files changed, 49 insertions, 33 deletions
diff --git a/include/llvm/LLVMContext.h b/include/llvm/LLVMContext.h index 7578918..d4cd891 100644 --- a/include/llvm/LLVMContext.h +++ b/include/llvm/LLVMContext.h @@ -271,6 +271,7 @@ public: // Methods for erasing constants void erase(MDString *M); + void erase(MDNode *M); }; /// FOR BACKWARDS COMPATIBILITY - Returns a global context. diff --git a/include/llvm/MDNode.h b/include/llvm/MDNode.h index 6c8f755..e394436 100644 --- a/include/llvm/MDNode.h +++ b/include/llvm/MDNode.h @@ -46,6 +46,8 @@ namespace llvm { class MDNode : public Constant, public FoldingSetNode { MDNode(const MDNode &); // DO NOT IMPLEMENT + friend class LLVMContextImpl; + friend class ElementVH; struct ElementVH : public CallbackVH { MDNode *OwningNode; @@ -72,15 +74,12 @@ class MDNode : public Constant, public FoldingSetNode { SmallVector<ElementVH, 4> Node; typedef SmallVectorImpl<ElementVH>::iterator elem_iterator; + protected: explicit MDNode(Value*const* Vals, unsigned NumVals); public: typedef SmallVectorImpl<ElementVH>::const_iterator const_elem_iterator; - /// get() - Static factory methods - Return objects of the specified value. - /// - static MDNode *get(Value*const* Vals, unsigned NumVals); - Value *getElement(unsigned i) const { return Node[i]; } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index cf01a9f..7631e3c 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1443,8 +1443,6 @@ void MDString::destroyConstant() { //---- MDNode::get() implementation // -static ManagedStatic<FoldingSet<MDNode> > MDNodeSet; - MDNode::MDNode(Value*const* Vals, unsigned NumVals) : Constant(Type::MetadataTy, MDNodeVal, 0, 0) { for (unsigned i = 0; i != NumVals; ++i) @@ -1456,32 +1454,8 @@ void MDNode::Profile(FoldingSetNodeID &ID) const { ID.AddPointer(*I); } -MDNode *MDNode::get(Value*const* Vals, unsigned NumVals) { - FoldingSetNodeID ID; - for (unsigned i = 0; i != NumVals; ++i) - ID.AddPointer(Vals[i]); - - ConstantsLock->reader_acquire(); - void *InsertPoint; - MDNode *N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint); - ConstantsLock->reader_release(); - - if (!N) { - sys::SmartScopedWriter<true> Writer(*ConstantsLock); - N = MDNodeSet->FindNodeOrInsertPos(ID, InsertPoint); - if (!N) { - // InsertPoint will have been set by the FindNodeOrInsertPos call. - N = new(0) MDNode(Vals, NumVals); - MDNodeSet->InsertNode(N, InsertPoint); - } - } - return N; -} - void MDNode::destroyConstant() { - sys::SmartScopedWriter<true> Writer(*ConstantsLock); - MDNodeSet->RemoveNode(this); - + getType()->getContext().erase(this); destroyConstantImpl(); } @@ -2519,7 +2493,8 @@ void MDNode::replaceElement(Value *From, Value *To) { Values.push_back(Val); } - MDNode *Replacement = MDNode::get(&Values[0], Values.size()); + MDNode *Replacement = + getType()->getContext().getMDNode(&Values[0], Values.size()); assert(Replacement != this && "I didn't contain From!"); uncheckedReplaceAllUsesWith(Replacement); diff --git a/lib/VMCore/LLVMContext.cpp b/lib/VMCore/LLVMContext.cpp index 7bce6f5..f7f8add 100644 --- a/lib/VMCore/LLVMContext.cpp +++ b/lib/VMCore/LLVMContext.cpp @@ -543,7 +543,7 @@ Constant* LLVMContext::getConstantVector(Constant* const* Vals, // MDNode accessors MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) { - return MDNode::get(Vals, NumVals); + return pImpl->getMDNode(Vals, NumVals); } // MDString accessors @@ -640,4 +640,8 @@ const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) { void LLVMContext::erase(MDString *M) { pImpl->erase(M); +} + +void LLVMContext::erase(MDNode *M) { + pImpl->erase(M); }
\ No newline at end of file diff --git a/lib/VMCore/LLVMContextImpl.cpp b/lib/VMCore/LLVMContextImpl.cpp index 93b9e7d..f34aba7 100644 --- a/lib/VMCore/LLVMContextImpl.cpp +++ b/lib/VMCore/LLVMContextImpl.cpp @@ -16,6 +16,7 @@ #include "llvm/Constants.h" #include "llvm/DerivedTypes.h" #include "llvm/LLVMContext.h" +#include "llvm/MDNode.h" using namespace llvm; // Get a ConstantInt from an APInt. Note that the value stored in the DenseMap @@ -92,9 +93,38 @@ MDString *LLVMContextImpl::getMDString(const char *StrBegin, return S; } +MDNode *LLVMContextImpl::getMDNode(Value*const* Vals, unsigned NumVals) { + FoldingSetNodeID ID; + for (unsigned i = 0; i != NumVals; ++i) + ID.AddPointer(Vals[i]); + + ConstantsLock.reader_acquire(); + void *InsertPoint; + MDNode *N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); + ConstantsLock.reader_release(); + + if (!N) { + sys::SmartScopedWriter<true> Writer(ConstantsLock); + N = MDNodeSet.FindNodeOrInsertPos(ID, InsertPoint); + if (!N) { + // InsertPoint will have been set by the FindNodeOrInsertPos call. + N = new(0) MDNode(Vals, NumVals); + MDNodeSet.InsertNode(N, InsertPoint); + } + } + + return N; +} + + // *** erase methods *** void LLVMContextImpl::erase(MDString *M) { sys::SmartScopedWriter<true> Writer(ConstantsLock); MDStringCache.erase(MDStringCache.find(M->StrBegin, M->StrEnd)); } + +void LLVMContextImpl::erase(MDNode *M) { + sys::SmartScopedWriter<true> Writer(ConstantsLock); + MDNodeSet.RemoveNode(M); +} diff --git a/lib/VMCore/LLVMContextImpl.h b/lib/VMCore/LLVMContextImpl.h index 3a5f7c1..129a759 100644 --- a/lib/VMCore/LLVMContextImpl.h +++ b/lib/VMCore/LLVMContextImpl.h @@ -19,6 +19,7 @@ #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/StringMap.h" namespace llvm { @@ -26,8 +27,10 @@ namespace llvm { class ConstantInt; class ConstantFP; class MDString; +class MDNode; class LLVMContext; class Type; +class Value; struct DenseMapAPIntKeyInfo { struct KeyTy { @@ -94,6 +97,8 @@ class LLVMContextImpl { StringMap<MDString*> MDStringCache; + FoldingSet<MDNode> MDNodeSet; + LLVMContext &Context; LLVMContextImpl(); LLVMContextImpl(const LLVMContextImpl&); @@ -108,8 +113,10 @@ public: MDString *getMDString(const char *StrBegin, const char *StrEnd); + MDNode *getMDNode(Value*const* Vals, unsigned NumVals); void erase(MDString *M); + void erase(MDNode *M); }; } |