diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/VMCore/LLVMContextImpl.h | 2 | ||||
-rw-r--r-- | llvm/lib/VMCore/Metadata.cpp | 13 | ||||
-rw-r--r-- | llvm/lib/VMCore/Value.cpp | 7 |
3 files changed, 14 insertions, 8 deletions
diff --git a/llvm/lib/VMCore/LLVMContextImpl.h b/llvm/lib/VMCore/LLVMContextImpl.h index f98526de650..1a4bf6d7b44 100644 --- a/llvm/lib/VMCore/LLVMContextImpl.h +++ b/llvm/lib/VMCore/LLVMContextImpl.h @@ -234,7 +234,7 @@ public: DenseMapAPFloatKeyInfo> FPMapTy; FPMapTy FPConstants; - StringMap<MDString*> MDStringCache; + StringMap<Value*> MDStringCache; FoldingSet<MDNode> MDNodeSet; // MDNodes may be uniqued or not uniqued. When they're not uniqued, they diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp index e6fd64c0afa..55de0dc6515 100644 --- a/llvm/lib/VMCore/Metadata.cpp +++ b/llvm/lib/VMCore/Metadata.cpp @@ -31,16 +31,17 @@ using namespace llvm; void MDString::anchor() { } -MDString::MDString(LLVMContext &C, StringRef S) - : Value(Type::getMetadataTy(C), Value::MDStringVal), Str(S) {} +MDString::MDString(LLVMContext &C) + : Value(Type::getMetadataTy(C), Value::MDStringVal) {} MDString *MDString::get(LLVMContext &Context, StringRef Str) { LLVMContextImpl *pImpl = Context.pImpl; - StringMapEntry<MDString *> &Entry = + StringMapEntry<Value*> &Entry = pImpl->MDStringCache.GetOrCreateValue(Str); - MDString *&S = Entry.getValue(); - if (!S) S = new MDString(Context, Entry.getKey()); - return S; + Value *&S = Entry.getValue(); + if (!S) S = new MDString(Context); + S->setValueName(&Entry); + return cast<MDString>(S); } //===----------------------------------------------------------------------===// diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp index 788f4191f5b..4006b2c5541 100644 --- a/llvm/lib/VMCore/Value.cpp +++ b/llvm/lib/VMCore/Value.cpp @@ -76,7 +76,7 @@ Value::~Value() { // If this value is named, destroy the name. This should not be in a symtab // at this point. - if (Name) + if (Name && SubclassID != MDStringVal) Name->Destroy(); // There should be no uses of this object anymore, remove it. @@ -170,6 +170,9 @@ StringRef Value::getName() const { } void Value::setName(const Twine &NewName) { + assert(SubclassID != MDStringVal && + "Cannot set the name of MDString with this method!"); + // Fast path for common IRBuilder case of setName("") when there is no name. if (NewName.isTriviallyEmpty() && !hasName()) return; @@ -228,6 +231,8 @@ void Value::setName(const Twine &NewName) { /// takeName - transfer the name from V to this value, setting V's name to /// empty. It is an error to call V->takeName(V). void Value::takeName(Value *V) { + assert(SubclassID != MDStringVal && "Cannot take the name of an MDString!"); + ValueSymbolTable *ST = 0; // If this value has a name, drop it. if (hasName()) { |