[llvm-commits] [llvm] r76126 - in /llvm/trunk: include/llvm/LLVMContext.h include/llvm/MDNode.h lib/VMCore/Constants.cpp lib/VMCore/LLVMContext.cpp lib/VMCore/LLVMContextImpl.cpp lib/VMCore/LLVMContextImpl.h
Owen Anderson
resistor at mac.com
Thu Jul 16 16:44:30 PDT 2009
Author: resistor
Date: Thu Jul 16 18:44:30 2009
New Revision: 76126
URL: http://llvm.org/viewvc/llvm-project?rev=76126&view=rev
Log:
Privatize the MDNode uniquing table.
Modified:
llvm/trunk/include/llvm/LLVMContext.h
llvm/trunk/include/llvm/MDNode.h
llvm/trunk/lib/VMCore/Constants.cpp
llvm/trunk/lib/VMCore/LLVMContext.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.h
Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=76126&r1=76125&r2=76126&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Thu Jul 16 18:44:30 2009
@@ -271,6 +271,7 @@
// Methods for erasing constants
void erase(MDString *M);
+ void erase(MDNode *M);
};
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.
Modified: llvm/trunk/include/llvm/MDNode.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MDNode.h?rev=76126&r1=76125&r2=76126&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MDNode.h (original)
+++ llvm/trunk/include/llvm/MDNode.h Thu Jul 16 18:44:30 2009
@@ -46,6 +46,8 @@
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 @@
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];
}
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=76126&r1=76125&r2=76126&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Thu Jul 16 18:44:30 2009
@@ -1443,8 +1443,6 @@
//---- 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 @@
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 @@
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);
Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=76126&r1=76125&r2=76126&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Thu Jul 16 18:44:30 2009
@@ -543,7 +543,7 @@
// 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 @@
void LLVMContext::erase(MDString *M) {
pImpl->erase(M);
+}
+
+void LLVMContext::erase(MDNode *M) {
+ pImpl->erase(M);
}
\ No newline at end of file
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=76126&r1=76125&r2=76126&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Thu Jul 16 18:44:30 2009
@@ -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 @@
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);
+}
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=76126&r1=76125&r2=76126&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Thu Jul 16 18:44:30 2009
@@ -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 @@
class ConstantInt;
class ConstantFP;
class MDString;
+class MDNode;
class LLVMContext;
class Type;
+class Value;
struct DenseMapAPIntKeyInfo {
struct KeyTy {
@@ -94,6 +97,8 @@
StringMap<MDString*> MDStringCache;
+ FoldingSet<MDNode> MDNodeSet;
+
LLVMContext &Context;
LLVMContextImpl();
LLVMContextImpl(const LLVMContextImpl&);
@@ -108,8 +113,10 @@
MDString *getMDString(const char *StrBegin, const char *StrEnd);
+ MDNode *getMDNode(Value*const* Vals, unsigned NumVals);
void erase(MDString *M);
+ void erase(MDNode *M);
};
}
More information about the llvm-commits
mailing list