1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-26 04:32:44 +01:00

Privatize the MDString uniquing table.

llvm-svn: 76113
This commit is contained in:
Owen Anderson 2009-07-16 22:11:26 +00:00
parent 7a21e4c812
commit 476adb2e49
7 changed files with 41 additions and 34 deletions

View File

@ -54,6 +54,7 @@ namespace llvm {
class Constant : public User {
void operator=(const Constant &); // Do not implement
Constant(const Constant &); // Do not implement
protected:
Constant(const Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
: User(ty, vty, Ops, NumOps) {}

View File

@ -745,17 +745,13 @@ class MDString : public Constant {
MDString(const char *begin, const char *end);
const char *StrBegin, *StrEnd;
friend class LLVMContextImpl;
protected:
// allocate space for exactly zero operands
void *operator new(size_t s) {
return User::operator new(s, 0);
}
public:
/// get() - Static factory methods - Return objects of the specified value.
///
static MDString *get(const char *StrBegin, const char *StrEnd);
static MDString *get(const std::string &Str);
/// size() - The length of this string.
///
intptr_t size() const { return StrEnd - StrBegin; }

View File

@ -268,6 +268,9 @@ public:
// Other helpers
/// @brief Create a result type for fcmp/icmp
const Type* makeCmpResultType(const Type* opnd_type);
// Methods for erasing constants
void erase(MDString *M);
};
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.

View File

@ -1435,33 +1435,8 @@ MDString::MDString(const char *begin, const char *end)
: Constant(Type::MetadataTy, MDStringVal, 0, 0),
StrBegin(begin), StrEnd(end) {}
static ManagedStatic<StringMap<MDString*> > MDStringCache;
MDString *MDString::get(const char *StrBegin, const char *StrEnd) {
sys::SmartScopedWriter<true> Writer(*ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
StrBegin, StrEnd);
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Entry.getKeyData(),
Entry.getKeyData() + Entry.getKeyLength());
return S;
}
MDString *MDString::get(const std::string &Str) {
sys::SmartScopedWriter<true> Writer(*ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache->GetOrCreateValue(
Str.data(), Str.data() + Str.size());
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Entry.getKeyData(),
Entry.getKeyData() + Entry.getKeyLength());
return S;
}
void MDString::destroyConstant() {
sys::SmartScopedWriter<true> Writer(*ConstantsLock);
MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));
getType()->getContext().erase(this);
destroyConstantImpl();
}

View File

@ -548,11 +548,11 @@ MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
// MDString accessors
MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
return MDString::get(StrBegin, StrEnd);
return pImpl->getMDString(StrBegin, StrEnd);
}
MDString* LLVMContext::getMDString(const std::string &Str) {
return MDString::get(Str);
return getMDString(Str.data(), Str.data()+Str.size());
}
// FunctionType accessors
@ -637,3 +637,7 @@ const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
}
return Type::Int1Ty;
}
void LLVMContext::erase(MDString *M) {
pImpl->erase(M);
}

View File

@ -79,3 +79,22 @@ ConstantFP *LLVMContextImpl::getConstantFP(const APFloat &V) {
return Slot;
}
MDString *LLVMContextImpl::getMDString(const char *StrBegin,
const char *StrEnd) {
sys::SmartScopedWriter<true> Writer(ConstantsLock);
StringMapEntry<MDString *> &Entry = MDStringCache.GetOrCreateValue(
StrBegin, StrEnd);
MDString *&S = Entry.getValue();
if (!S) S = new MDString(Entry.getKeyData(),
Entry.getKeyData() + Entry.getKeyLength());
return S;
}
// *** erase methods ***
void LLVMContextImpl::erase(MDString *M) {
sys::SmartScopedWriter<true> Writer(ConstantsLock);
MDStringCache.erase(MDStringCache.find(M->StrBegin, M->StrEnd));
}

View File

@ -19,11 +19,13 @@
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
namespace llvm {
class ConstantInt;
class ConstantFP;
class MDString;
class LLVMContext;
class Type;
@ -90,6 +92,8 @@ class LLVMContextImpl {
DenseMapAPFloatKeyInfo> FPMapTy;
FPMapTy FPConstants;
StringMap<MDString*> MDStringCache;
LLVMContext &Context;
LLVMContextImpl();
LLVMContextImpl(const LLVMContextImpl&);
@ -101,6 +105,11 @@ public:
ConstantInt *getConstantInt(const APInt &V);
ConstantFP *getConstantFP(const APFloat &V);
MDString *getMDString(const char *StrBegin, const char *StrEnd);
void erase(MDString *M);
};
}