mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-25 12:50:00 +00:00
Privatize the MDNode uniquing table.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76126 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
b8e9ac834a
commit
ce032b483c
@ -271,6 +271,7 @@ public:
|
||||
|
||||
// Methods for erasing constants
|
||||
void erase(MDString *M);
|
||||
void erase(MDNode *M);
|
||||
};
|
||||
|
||||
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user