mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-03-01 01:30:36 +00:00
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
This commit is contained in:
parent
7f1f145389
commit
3ecb447f52
@ -39,28 +39,24 @@ class MDString : public Value {
|
|||||||
virtual void anchor();
|
virtual void anchor();
|
||||||
MDString(const MDString &); // DO NOT IMPLEMENT
|
MDString(const MDString &); // DO NOT IMPLEMENT
|
||||||
|
|
||||||
StringRef Str;
|
explicit MDString(LLVMContext &C);
|
||||||
explicit MDString(LLVMContext &C, StringRef S);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static MDString *get(LLVMContext &Context, StringRef Str);
|
static MDString *get(LLVMContext &Context, StringRef Str);
|
||||||
static MDString *get(LLVMContext &Context, const char *Str) {
|
static MDString *get(LLVMContext &Context, const char *Str) {
|
||||||
return get(Context, Str ? StringRef(Str) : StringRef());
|
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;
|
typedef StringRef::iterator iterator;
|
||||||
|
|
||||||
/// begin() - Pointer to the first byte of the string.
|
/// begin() - Pointer to the first byte of the string.
|
||||||
///
|
iterator begin() const { return getName().begin(); }
|
||||||
iterator begin() const { return Str.begin(); }
|
|
||||||
|
|
||||||
/// end() - Pointer to one byte past the end of the string.
|
/// end() - Pointer to one byte past the end of the string.
|
||||||
///
|
iterator end() const { return getName().end(); }
|
||||||
iterator end() const { return Str.end(); }
|
|
||||||
|
|
||||||
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
/// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
static inline bool classof(const MDString *) { return true; }
|
static inline bool classof(const MDString *) { return true; }
|
||||||
|
@ -107,9 +107,10 @@ public:
|
|||||||
/// All values hold a context through their type.
|
/// All values hold a context through their type.
|
||||||
LLVMContext &getContext() const;
|
LLVMContext &getContext() const;
|
||||||
|
|
||||||
// All values can potentially be named...
|
// All values can potentially be named.
|
||||||
bool hasName() const { return Name != 0; }
|
bool hasName() const { return Name != 0 && SubclassID != MDStringVal; }
|
||||||
ValueName *getValueName() const { return Name; }
|
ValueName *getValueName() const { return Name; }
|
||||||
|
void setValueName(ValueName *VN) { Name = VN; }
|
||||||
|
|
||||||
/// getName() - Return a constant reference to the value's name. This is cheap
|
/// 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
|
/// and guaranteed to return the same reference as long as the value is not
|
||||||
|
@ -234,7 +234,7 @@ public:
|
|||||||
DenseMapAPFloatKeyInfo> FPMapTy;
|
DenseMapAPFloatKeyInfo> FPMapTy;
|
||||||
FPMapTy FPConstants;
|
FPMapTy FPConstants;
|
||||||
|
|
||||||
StringMap<MDString*> MDStringCache;
|
StringMap<Value*> MDStringCache;
|
||||||
|
|
||||||
FoldingSet<MDNode> MDNodeSet;
|
FoldingSet<MDNode> MDNodeSet;
|
||||||
// MDNodes may be uniqued or not uniqued. When they're not uniqued, they
|
// MDNodes may be uniqued or not uniqued. When they're not uniqued, they
|
||||||
|
@ -31,16 +31,17 @@ using namespace llvm;
|
|||||||
|
|
||||||
void MDString::anchor() { }
|
void MDString::anchor() { }
|
||||||
|
|
||||||
MDString::MDString(LLVMContext &C, StringRef S)
|
MDString::MDString(LLVMContext &C)
|
||||||
: Value(Type::getMetadataTy(C), Value::MDStringVal), Str(S) {}
|
: Value(Type::getMetadataTy(C), Value::MDStringVal) {}
|
||||||
|
|
||||||
MDString *MDString::get(LLVMContext &Context, StringRef Str) {
|
MDString *MDString::get(LLVMContext &Context, StringRef Str) {
|
||||||
LLVMContextImpl *pImpl = Context.pImpl;
|
LLVMContextImpl *pImpl = Context.pImpl;
|
||||||
StringMapEntry<MDString *> &Entry =
|
StringMapEntry<Value*> &Entry =
|
||||||
pImpl->MDStringCache.GetOrCreateValue(Str);
|
pImpl->MDStringCache.GetOrCreateValue(Str);
|
||||||
MDString *&S = Entry.getValue();
|
Value *&S = Entry.getValue();
|
||||||
if (!S) S = new MDString(Context, Entry.getKey());
|
if (!S) S = new MDString(Context);
|
||||||
return S;
|
S->setValueName(&Entry);
|
||||||
|
return cast<MDString>(S);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
@ -76,7 +76,7 @@ Value::~Value() {
|
|||||||
|
|
||||||
// If this value is named, destroy the name. This should not be in a symtab
|
// If this value is named, destroy the name. This should not be in a symtab
|
||||||
// at this point.
|
// at this point.
|
||||||
if (Name)
|
if (Name && SubclassID != MDStringVal)
|
||||||
Name->Destroy();
|
Name->Destroy();
|
||||||
|
|
||||||
// There should be no uses of this object anymore, remove it.
|
// 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) {
|
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.
|
// Fast path for common IRBuilder case of setName("") when there is no name.
|
||||||
if (NewName.isTriviallyEmpty() && !hasName())
|
if (NewName.isTriviallyEmpty() && !hasName())
|
||||||
return;
|
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
|
/// takeName - transfer the name from V to this value, setting V's name to
|
||||||
/// empty. It is an error to call V->takeName(V).
|
/// empty. It is an error to call V->takeName(V).
|
||||||
void Value::takeName(Value *V) {
|
void Value::takeName(Value *V) {
|
||||||
|
assert(SubclassID != MDStringVal && "Cannot take the name of an MDString!");
|
||||||
|
|
||||||
ValueSymbolTable *ST = 0;
|
ValueSymbolTable *ST = 0;
|
||||||
// If this value has a name, drop it.
|
// If this value has a name, drop it.
|
||||||
if (hasName()) {
|
if (hasName()) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user