summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-04-10 20:12:16 +0000
committerBill Wendling <isanbard@gmail.com>2012-04-10 20:12:16 +0000
commit3ecb447f52d169dea6663b95b5b5b43e9bb5826b (patch)
tree2e5526e4b3fbb284b6753241cd0f87769c7732b3 /include
parent7f1f1453895431f948abbb5d9bf09b4faf87926a (diff)
downloadllvm-3ecb447f52d169dea6663b95b5b5b43e9bb5826b.tar.gz
llvm-3ecb447f52d169dea6663b95b5b5b43e9bb5826b.tar.bz2
llvm-3ecb447f52d169dea6663b95b5b5b43e9bb5826b.tar.xz
The MDString class stored a StringRef to the string which was already in a
StringMap. This was redundant and unnecessarily bloated the MDString class. Because the MDString class is a "Value" and will never have a "name", and because the Name field in the Value class is a pointer to a StringMap entry, we repurpose the Name field for an MDString. It stores the StringMap entry in the Name field, and uses the normal methods to get the string (name) back. PR12474 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@154429 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/Metadata.h14
-rw-r--r--include/llvm/Value.h5
2 files changed, 8 insertions, 11 deletions
diff --git a/include/llvm/Metadata.h b/include/llvm/Metadata.h
index 29458ef346..0d438522ab 100644
--- a/include/llvm/Metadata.h
+++ b/include/llvm/Metadata.h
@@ -39,28 +39,24 @@ class MDString : public Value {
virtual void anchor();
MDString(const MDString &); // DO NOT IMPLEMENT
- StringRef Str;
- explicit MDString(LLVMContext &C, StringRef S);
-
+ explicit MDString(LLVMContext &C);
public:
static MDString *get(LLVMContext &Context, StringRef Str);
static MDString *get(LLVMContext &Context, const char *Str) {
return get(Context, Str ? StringRef(Str) : StringRef());
}
- StringRef getString() const { return Str; }
+ StringRef getString() const { return getName(); }
- unsigned getLength() const { return (unsigned)Str.size(); }
+ unsigned getLength() const { return (unsigned)getName().size(); }
typedef StringRef::iterator iterator;
/// begin() - Pointer to the first byte of the string.
- ///
- iterator begin() const { return Str.begin(); }
+ iterator begin() const { return getName().begin(); }
/// end() - Pointer to one byte past the end of the string.
- ///
- iterator end() const { return Str.end(); }
+ iterator end() const { return getName().end(); }
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MDString *) { return true; }
diff --git a/include/llvm/Value.h b/include/llvm/Value.h
index 84ed037ae7..a82ac45c49 100644
--- a/include/llvm/Value.h
+++ b/include/llvm/Value.h
@@ -107,9 +107,10 @@ public:
/// All values hold a context through their type.
LLVMContext &getContext() const;
- // All values can potentially be named...
- bool hasName() const { return Name != 0; }
+ // All values can potentially be named.
+ bool hasName() const { return Name != 0 && SubclassID != MDStringVal; }
ValueName *getValueName() const { return Name; }
+ void setValueName(ValueName *VN) { Name = VN; }
/// getName() - Return a constant reference to the value's name. This is cheap
/// and guaranteed to return the same reference as long as the value is not