aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2009-07-16 23:44:30 +0000
committerOwen Anderson <resistor@mac.com>2009-07-16 23:44:30 +0000
commitce032b483ca96093b84f69178cdb2d047e124332 (patch)
tree786a371b3156bf0711bb6843d058d1392f268977 /lib
parentb8e9ac834a9c253e3f8f5caa8f229bafba0b4fcf (diff)
downloadexternal_llvm-ce032b483ca96093b84f69178cdb2d047e124332.zip
external_llvm-ce032b483ca96093b84f69178cdb2d047e124332.tar.gz
external_llvm-ce032b483ca96093b84f69178cdb2d047e124332.tar.bz2
Privatize the MDNode uniquing table.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76126 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/VMCore/Constants.cpp31
-rw-r--r--lib/VMCore/LLVMContext.cpp6
-rw-r--r--lib/VMCore/LLVMContextImpl.cpp30
-rw-r--r--lib/VMCore/LLVMContextImpl.h7
4 files changed, 45 insertions, 29 deletions
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);
};
}