[llvm-commits] [llvm] r76113 - in /llvm/trunk: include/llvm/Constant.h include/llvm/Constants.h include/llvm/LLVMContext.h lib/VMCore/Constants.cpp lib/VMCore/LLVMContext.cpp lib/VMCore/LLVMContextImpl.cpp lib/VMCore/LLVMContextImpl.h
Owen Anderson
resistor at mac.com
Thu Jul 16 15:11:27 PDT 2009
Author: resistor
Date: Thu Jul 16 17:11:26 2009
New Revision: 76113
URL: http://llvm.org/viewvc/llvm-project?rev=76113&view=rev
Log:
Privatize the MDString uniquing table.
Modified:
llvm/trunk/include/llvm/Constant.h
llvm/trunk/include/llvm/Constants.h
llvm/trunk/include/llvm/LLVMContext.h
llvm/trunk/lib/VMCore/Constants.cpp
llvm/trunk/lib/VMCore/LLVMContext.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.h
Modified: llvm/trunk/include/llvm/Constant.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constant.h?rev=76113&r1=76112&r2=76113&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constant.h (original)
+++ llvm/trunk/include/llvm/Constant.h Thu Jul 16 17:11:26 2009
@@ -54,6 +54,7 @@
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) {}
Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=76113&r1=76112&r2=76113&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Thu Jul 16 17:11:26 2009
@@ -745,17 +745,13 @@
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; }
Modified: llvm/trunk/include/llvm/LLVMContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LLVMContext.h?rev=76113&r1=76112&r2=76113&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LLVMContext.h (original)
+++ llvm/trunk/include/llvm/LLVMContext.h Thu Jul 16 17:11:26 2009
@@ -268,6 +268,9 @@
// 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.
Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=76113&r1=76112&r2=76113&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Thu Jul 16 17:11:26 2009
@@ -1435,33 +1435,8 @@
: 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();
}
Modified: llvm/trunk/lib/VMCore/LLVMContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContext.cpp?rev=76113&r1=76112&r2=76113&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContext.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContext.cpp Thu Jul 16 17:11:26 2009
@@ -548,11 +548,11 @@
// 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 @@
}
return Type::Int1Ty;
}
+
+void LLVMContext::erase(MDString *M) {
+ pImpl->erase(M);
+}
\ No newline at end of file
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=76113&r1=76112&r2=76113&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Thu Jul 16 17:11:26 2009
@@ -78,4 +78,23 @@
}
return Slot;
-}
\ No newline at end of file
+}
+
+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));
+}
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.h?rev=76113&r1=76112&r2=76113&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.h (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.h Thu Jul 16 17:11:26 2009
@@ -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 @@
DenseMapAPFloatKeyInfo> FPMapTy;
FPMapTy FPConstants;
+ StringMap<MDString*> MDStringCache;
+
LLVMContext &Context;
LLVMContextImpl();
LLVMContextImpl(const LLVMContextImpl&);
@@ -101,6 +105,11 @@
ConstantInt *getConstantInt(const APInt &V);
ConstantFP *getConstantFP(const APFloat &V);
+
+ MDString *getMDString(const char *StrBegin, const char *StrEnd);
+
+
+ void erase(MDString *M);
};
}
More information about the llvm-commits
mailing list