mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
Privatize the MDString uniquing table.
llvm-svn: 76113
This commit is contained in:
parent
7a21e4c812
commit
476adb2e49
@ -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) {}
|
||||
|
@ -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; }
|
||||
|
@ -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.
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
@ -78,4 +78,23 @@ 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));
|
||||
}
|
||||
|
@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user