[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.68 - 1.69 --- Log message: Add a new Value::getNameStr method, which is preferred over getName. --- Diffs of the changes: (+1 -1) Value.cpp |2 +- 1 files changed, 1 insertion(+), 1 deletion(-) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.68 llvm/lib/VMCore/Value.cpp:1.69 --- llvm/lib/VMCore/Value.cpp:1.68 Tue Feb 13 01:53:34 2007 +++ llvm/lib/VMCore/Value.cpp Thu Feb 15 12:53:54 2007 @@ -112,7 +112,7 @@ return false; } -std::string Value::getName() const { +std::string Value::getNameStr() const { if (Name == 0) return ; return std::string(Name-getKeyData(), Name-getKeyData()+Name-getKeyLength()); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.69 - 1.70 --- Log message: rewrite Value::takeName to take advantage of the new symtab stuff. This causes it to require no allocations and no symtab lookups in the common case. This speeds up instcombine 9.2% on 447.dealII. --- Diffs of the changes: (+55 -6) Value.cpp | 61 +++-- 1 files changed, 55 insertions(+), 6 deletions(-) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.69 llvm/lib/VMCore/Value.cpp:1.70 --- llvm/lib/VMCore/Value.cpp:1.69 Thu Feb 15 12:53:54 2007 +++ llvm/lib/VMCore/Value.cpp Thu Feb 15 14:01:43 2007 @@ -185,15 +185,64 @@ /// 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) { - if (!V-hasName()) { -if (hasName()) - setName(); + ValueSymbolTable *ST = 0; + // If this value has a name, drop it. + if (hasName()) { +// Get the symtab this is in. +if (getSymTab(this, ST)) { + // We can't set a name on this value, but we need to clear V's name if + // it has one. + if (V-hasName()) V-setName(0, 0); + return; // Cannot set a name on this value (e.g. constant). +} + +// Remove old name. +if (ST) + ST-removeValueName(Name); +Name-Destroy(); +Name = 0; + } + + // Now we know that this has no name. + + // If V has no name either, we're done. + if (!V-hasName()) return; + + // Get this's symtab if we didn't before. + if (!ST) { +if (getSymTab(this, ST)) { + // Clear V's name. + V-setName(0, 0); + return; // Cannot set a name on this value (e.g. constant). +} + } + + // Get V's ST, this should always succed, because V has a name. + ValueSymbolTable *VST; + bool Failure = getSymTab(V, VST); + assert(!Failure V has a name, so it should have a ST!); + + // If these values are both in the same symtab, we can do this very fast. + // This works even if both values have no symtab yet. + if (ST == VST) { +// Take the name! +Name = V-Name; +V-Name = 0; +Name-setValue(this); return; } - std::string Name = V-getName(); - V-setName(); - setName(Name); + // Otherwise, things are slightly more complex. Remove V's name from VST and + // then reinsert it into ST. + + if (VST) +VST-removeValueName(V-Name); + Name = V-Name; + V-Name = 0; + Name-setValue(this); + + if (ST) +ST-reinsertValue(this); } ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.66 - 1.67 --- Log message: Add new setName accessor which doesn't require creating a string. --- Diffs of the changes: (+28 -20) Value.cpp | 48 1 files changed, 28 insertions(+), 20 deletions(-) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.66 llvm/lib/VMCore/Value.cpp:1.67 --- llvm/lib/VMCore/Value.cpp:1.66 Sun Feb 11 23:18:08 2007 +++ llvm/lib/VMCore/Value.cpp Mon Feb 12 12:52:59 2007 @@ -119,33 +119,40 @@ } void Value::setName(const std::string name) { - if (name.empty() !hasName()) return; + setName(name[0], name.size()); +} + +void Value::setName(const char *NameStr, unsigned NameLen) { + if (NameLen == 0 !hasName()) return; if (getType() != Type::VoidTy Cannot assign a name to void values!); - // Get the symbol table to update for this object. ValueSymbolTable *ST; if (getSymTab(this, ST)) return; // Cannot set a name on this value (e.g. constant). if (!ST) { // No symbol table to update? Just do the change. -if (name.empty()) { +if (NameLen == 0) { // Free the name for this value. Name-Destroy(); Name = 0; -} else { - if (Name) { -// Name isn't changing. -if (name.size() == Name-getKeyLength() -!memcmp(Name-getKeyData(), name[0], name.size())) - return; -Name-Destroy(); - } - - // Create the new name. - Name = ValueName::Create(name[0], name[name.size()]); - Name-setValue(this); + return; } + +if (Name) { + // Name isn't changing? + if (NameLen == Name-getKeyLength() + !memcmp(Name-getKeyData(), NameStr, NameLen)) +return; + Name-Destroy(); +} + +// NOTE: Could optimize for the case the name is shrinking to not deallocate +// then reallocated. + +// Create the new name. +Name = ValueName::Create(NameStr, NameStr+NameLen); +Name-setValue(this); return; } @@ -153,8 +160,8 @@ // then reallocated. if (hasName()) { // Name isn't changing? -if (name.size() == Name-getKeyLength() -!memcmp(Name-getKeyData(), name[0], name.size())) +if (NameLen == Name-getKeyLength() +!memcmp(Name-getKeyData(), NameStr, NameLen)) return; // Remove old name. @@ -162,14 +169,15 @@ Name-Destroy(); Name = 0; -if (name.empty()) - return; +if (NameLen == 0) + return; } // Name is changing to something new. - Name = ST-createValueName(name[0], name.size(), this); + Name = ST-createValueName(NameStr, NameLen, this); } + /// 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) { ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.67 - 1.68 --- Log message: add a setName variant that takes a null-terminated string. This can be used to avoid std::string allocations in common cases. --- Diffs of the changes: (+4 -0) Value.cpp |4 1 files changed, 4 insertions(+) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.67 llvm/lib/VMCore/Value.cpp:1.68 --- llvm/lib/VMCore/Value.cpp:1.67 Mon Feb 12 12:52:59 2007 +++ llvm/lib/VMCore/Value.cpp Tue Feb 13 01:53:34 2007 @@ -122,6 +122,10 @@ setName(name[0], name.size()); } +void Value::setName(const char *Name) { + setName(Name, Name ? strlen(Name) : 0); +} + void Value::setName(const char *NameStr, unsigned NameLen) { if (NameLen == 0 !hasName()) return; if (getType() != Type::VoidTy Cannot assign a name to void values!); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.64 - 1.65 --- Log message: fix uninitialized variable --- Diffs of the changes: (+1 -0) Value.cpp |1 + 1 files changed, 1 insertion(+) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.64 llvm/lib/VMCore/Value.cpp:1.65 --- llvm/lib/VMCore/Value.cpp:1.64 Sat Feb 10 19:04:09 2007 +++ llvm/lib/VMCore/Value.cpp Sun Feb 11 13:12:18 2007 @@ -93,6 +93,7 @@ } static bool getSymTab(Value *V, ValueSymbolTable *ST) { + ST = 0; if (Instruction *I = dyn_castInstruction(V)) { if (BasicBlock *P = I-getParent()) if (Function *PP = P-getParent()) ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.62 - 1.63 --- Log message: add a helper method: Value::takeName --- Diffs of the changes: (+26 -12) Value.cpp | 38 ++ 1 files changed, 26 insertions(+), 12 deletions(-) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.62 llvm/lib/VMCore/Value.cpp:1.63 --- llvm/lib/VMCore/Value.cpp:1.62 Wed Feb 7 00:13:49 2007 +++ llvm/lib/VMCore/Value.cpp Sat Feb 10 18:37:27 2007 @@ -92,29 +92,34 @@ return (unsigned)std::distance(use_begin(), use_end()); } - -void Value::setName(const std::string name) { - if (Name == name) return; // Name is already set. - - // Get the symbol table to update for this object. - ValueSymbolTable *ST = 0; - if (Instruction *I = dyn_castInstruction(this)) { +static bool getSymTab(Value *V, ValueSymbolTable *ST) { + if (Instruction *I = dyn_castInstruction(V)) { if (BasicBlock *P = I-getParent()) if (Function *PP = P-getParent()) ST = PP-getValueSymbolTable(); - } else if (BasicBlock *BB = dyn_castBasicBlock(this)) { + } else if (BasicBlock *BB = dyn_castBasicBlock(V)) { if (Function *P = BB-getParent()) ST = P-getValueSymbolTable(); - } else if (GlobalValue *GV = dyn_castGlobalValue(this)) { + } else if (GlobalValue *GV = dyn_castGlobalValue(V)) { if (Module *P = GV-getParent()) ST = P-getValueSymbolTable(); - } else if (Argument *A = dyn_castArgument(this)) { + } else if (Argument *A = dyn_castArgument(V)) { if (Function *P = A-getParent()) ST = P-getValueSymbolTable(); } else { -assert(isaConstant(this) Unknown value type!); -return; // no name is setable for this. +assert(isaConstant(V) Unknown value type!); +return true; // no name is setable for this. } + return false; +} + +void Value::setName(const std::string name) { + if (Name == name) return; // Name is already set. + + // Get the symbol table to update for this object. + ValueSymbolTable *ST; + if (getSymTab(this, ST)) +return; // Cannot set a name on this value (e.g. constant). if (!ST) // No symbol table to update? Just do the change. Name = name; @@ -133,6 +138,15 @@ } } +/// 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) { + std::string Name = V-getName(); + V-setName(); + setName(Name); +} + + // uncheckedReplaceAllUsesWith - This is exactly the same as replaceAllUsesWith, // except that it doesn't have all of the asserts. The asserts fail because we // are half-way done resolving types, which causes some types to exist as two ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.63 - 1.64 --- Log message: add an optimization for the case where the src has no name --- Diffs of the changes: (+6 -0) Value.cpp |6 ++ 1 files changed, 6 insertions(+) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.63 llvm/lib/VMCore/Value.cpp:1.64 --- llvm/lib/VMCore/Value.cpp:1.63 Sat Feb 10 18:37:27 2007 +++ llvm/lib/VMCore/Value.cpp Sat Feb 10 19:04:09 2007 @@ -141,6 +141,12 @@ /// 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) { + if (!V-hasName()) { +if (hasName()) + setName(); +return; + } + std::string Name = V-getName(); V-setName(); setName(Name); ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
[llvm-commits] CVS: llvm/lib/VMCore/Value.cpp ValueSymbolTable.cpp
Changes in directory llvm/lib/VMCore: Value.cpp updated: 1.61 - 1.62 ValueSymbolTable.cpp updated: 1.6 - 1.7 --- Log message: eliminate ValueSymbolTable::rename, it has no advantage over using remove+insert. Make insert/remove assert if used incorrectly instead of returning a bool. --- Diffs of the changes: (+5 -42) Value.cpp|4 +++- ValueSymbolTable.cpp | 43 ++- 2 files changed, 5 insertions(+), 42 deletions(-) Index: llvm/lib/VMCore/Value.cpp diff -u llvm/lib/VMCore/Value.cpp:1.61 llvm/lib/VMCore/Value.cpp:1.62 --- llvm/lib/VMCore/Value.cpp:1.61 Mon Feb 5 14:47:20 2007 +++ llvm/lib/VMCore/Value.cpp Wed Feb 7 00:13:49 2007 @@ -120,7 +120,9 @@ Name = name; else if (hasName()) { if (!name.empty()) {// Replacing name. - ST-rename(this, name); + ST-remove(this); + Name = name; + ST-insert(this); } else {// Transitioning from hasName - noname. ST-remove(this); Name.clear(); Index: llvm/lib/VMCore/ValueSymbolTable.cpp diff -u llvm/lib/VMCore/ValueSymbolTable.cpp:1.6 llvm/lib/VMCore/ValueSymbolTable.cpp:1.7 --- llvm/lib/VMCore/ValueSymbolTable.cpp:1.6Tue Feb 6 23:52:51 2007 +++ llvm/lib/VMCore/ValueSymbolTable.cppWed Feb 7 00:13:49 2007 @@ -103,54 +103,15 @@ } // Remove a value -bool ValueSymbolTable::remove(Value *V) { +void ValueSymbolTable::remove(Value *V) { assert(V-hasName() Value doesn't have name!); iterator Entry = vmap.find(V-getName()); - if (Entry == vmap.end()) -return false; + assert(Entry != vmap.end() Entry was not in the symtab!); DEBUG(DOUT Removing Value: Entry-second-getName() \n); // Remove the value from the plane... vmap.erase(Entry); - return true; -} - - -// rename - Given a value with a non-empty name, remove its existing entry -// from the symbol table and insert a new one for Name. This is equivalent to -// doing remove(V), V-Name = Name, insert(V), -// -bool ValueSymbolTable::rename(Value *V, const std::string name) { - assert(V Can't rename a null Value); - assert(V-hasName() Can't rename a nameless Value); - assert(!V-getName().empty() Can't rename an Value with null name); - assert(V-getName() != name Can't rename a Value with same name); - assert(!name.empty() Can't rename a named Value with a null name); - - // Find the name - iterator VI = vmap.find(V-getName()); - - // If we didn't find it, we're done - if (VI == vmap.end()) -return false; - - // Remove the old entry. - vmap.erase(VI); - - // See if we can insert the new name. - VI = vmap.lower_bound(name); - - // Is there a naming conflict? - if (VI != vmap.end() VI-first == name) { -V-Name = getUniqueName( name); -vmap.insert(make_pair(V-Name, V)); - } else { -V-Name = name; -vmap.insert(VI, make_pair(V-Name, V)); - } - - return true; } // DumpVal - a std::for_each function for dumping a value ___ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits