mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
Privatize the MDString uniquing table.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76113 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
24cd3c4711
commit
aad3fb7362
@ -54,6 +54,7 @@ namespace llvm {
|
|||||||
class Constant : public User {
|
class Constant : public User {
|
||||||
void operator=(const Constant &); // Do not implement
|
void operator=(const Constant &); // Do not implement
|
||||||
Constant(const Constant &); // Do not implement
|
Constant(const Constant &); // Do not implement
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Constant(const Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
|
Constant(const Type *ty, ValueTy vty, Use *Ops, unsigned NumOps)
|
||||||
: User(ty, vty, Ops, NumOps) {}
|
: User(ty, vty, Ops, NumOps) {}
|
||||||
|
@ -745,17 +745,13 @@ class MDString : public Constant {
|
|||||||
MDString(const char *begin, const char *end);
|
MDString(const char *begin, const char *end);
|
||||||
|
|
||||||
const char *StrBegin, *StrEnd;
|
const char *StrBegin, *StrEnd;
|
||||||
|
friend class LLVMContextImpl;
|
||||||
protected:
|
protected:
|
||||||
// allocate space for exactly zero operands
|
// allocate space for exactly zero operands
|
||||||
void *operator new(size_t s) {
|
void *operator new(size_t s) {
|
||||||
return User::operator new(s, 0);
|
return User::operator new(s, 0);
|
||||||
}
|
}
|
||||||
public:
|
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.
|
/// size() - The length of this string.
|
||||||
///
|
///
|
||||||
intptr_t size() const { return StrEnd - StrBegin; }
|
intptr_t size() const { return StrEnd - StrBegin; }
|
||||||
|
@ -268,6 +268,9 @@ public:
|
|||||||
// Other helpers
|
// Other helpers
|
||||||
/// @brief Create a result type for fcmp/icmp
|
/// @brief Create a result type for fcmp/icmp
|
||||||
const Type* makeCmpResultType(const Type* opnd_type);
|
const Type* makeCmpResultType(const Type* opnd_type);
|
||||||
|
|
||||||
|
// Methods for erasing constants
|
||||||
|
void erase(MDString *M);
|
||||||
};
|
};
|
||||||
|
|
||||||
/// FOR BACKWARDS COMPATIBILITY - Returns a global context.
|
/// 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),
|
: Constant(Type::MetadataTy, MDStringVal, 0, 0),
|
||||||
StrBegin(begin), StrEnd(end) {}
|
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() {
|
void MDString::destroyConstant() {
|
||||||
sys::SmartScopedWriter<true> Writer(*ConstantsLock);
|
getType()->getContext().erase(this);
|
||||||
MDStringCache->erase(MDStringCache->find(StrBegin, StrEnd));
|
|
||||||
destroyConstantImpl();
|
destroyConstantImpl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,11 +548,11 @@ MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
|
|||||||
|
|
||||||
// MDString accessors
|
// MDString accessors
|
||||||
MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
|
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) {
|
MDString* LLVMContext::getMDString(const std::string &Str) {
|
||||||
return MDString::get(Str);
|
return getMDString(Str.data(), Str.data()+Str.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// FunctionType accessors
|
// FunctionType accessors
|
||||||
@ -637,3 +637,7 @@ const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
|
|||||||
}
|
}
|
||||||
return Type::Int1Ty;
|
return Type::Int1Ty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LLVMContext::erase(MDString *M) {
|
||||||
|
pImpl->erase(M);
|
||||||
|
}
|
@ -79,3 +79,22 @@ ConstantFP *LLVMContextImpl::getConstantFP(const APFloat &V) {
|
|||||||
|
|
||||||
return Slot;
|
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/APFloat.h"
|
||||||
#include "llvm/ADT/APInt.h"
|
#include "llvm/ADT/APInt.h"
|
||||||
#include "llvm/ADT/DenseMap.h"
|
#include "llvm/ADT/DenseMap.h"
|
||||||
|
#include "llvm/ADT/StringMap.h"
|
||||||
|
|
||||||
namespace llvm {
|
namespace llvm {
|
||||||
|
|
||||||
class ConstantInt;
|
class ConstantInt;
|
||||||
class ConstantFP;
|
class ConstantFP;
|
||||||
|
class MDString;
|
||||||
class LLVMContext;
|
class LLVMContext;
|
||||||
class Type;
|
class Type;
|
||||||
|
|
||||||
@ -90,6 +92,8 @@ class LLVMContextImpl {
|
|||||||
DenseMapAPFloatKeyInfo> FPMapTy;
|
DenseMapAPFloatKeyInfo> FPMapTy;
|
||||||
FPMapTy FPConstants;
|
FPMapTy FPConstants;
|
||||||
|
|
||||||
|
StringMap<MDString*> MDStringCache;
|
||||||
|
|
||||||
LLVMContext &Context;
|
LLVMContext &Context;
|
||||||
LLVMContextImpl();
|
LLVMContextImpl();
|
||||||
LLVMContextImpl(const LLVMContextImpl&);
|
LLVMContextImpl(const LLVMContextImpl&);
|
||||||
@ -101,6 +105,11 @@ public:
|
|||||||
ConstantInt *getConstantInt(const APInt &V);
|
ConstantInt *getConstantInt(const APInt &V);
|
||||||
|
|
||||||
ConstantFP *getConstantFP(const APFloat &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