[llvm-commits] [llvm] r77098 - in /llvm/trunk: docs/ include/llvm/ lib/CodeGen/AsmPrinter/ lib/Linker/ lib/Target/ARM/AsmPrinter/ lib/Target/PowerPC/AsmPrinter/ lib/Target/X86/AsmPrinter/ lib/Transforms/Scalar/ lib/Transforms/Utils/ lib/VMCore/
Daniel Dunbar
daniel at zuster.org
Sat Jul 25 16:55:22 PDT 2009
Author: ddunbar
Date: Sat Jul 25 18:55:21 2009
New Revision: 77098
URL: http://llvm.org/viewvc/llvm-project?rev=77098&view=rev
Log:
Remove Value::{isName, getNameRef}.
Also, change MDString to use a StringRef.
Modified:
llvm/trunk/docs/ReleaseNotes-2.6.html
llvm/trunk/include/llvm/MDNode.h
llvm/trunk/include/llvm/Value.h
llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
llvm/trunk/lib/Transforms/Utils/InlineCost.cpp
llvm/trunk/lib/VMCore/AsmWriter.cpp
llvm/trunk/lib/VMCore/AutoUpgrade.cpp
llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
llvm/trunk/lib/VMCore/Value.cpp
llvm/trunk/lib/VMCore/ValueSymbolTable.cpp
Modified: llvm/trunk/docs/ReleaseNotes-2.6.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/ReleaseNotes-2.6.html?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/docs/ReleaseNotes-2.6.html (original)
+++ llvm/trunk/docs/ReleaseNotes-2.6.html Sat Jul 25 18:55:21 2009
@@ -484,6 +484,9 @@
treating the result as an <tt>std::string</tt>, you can either
uses <tt>Twine::str</tt> to get the result as an <tt>std::string</tt>, or
could move to a <tt>Twine</tt> based design.</li>
+
+ <li><tt>isName()</tt> should be replaced with comparison
+ against <tt>getName()</tt> (this is now efficient).</tt>
</ul>
</li>
Modified: llvm/trunk/include/llvm/MDNode.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MDNode.h?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MDNode.h (original)
+++ llvm/trunk/include/llvm/MDNode.h Sat Jul 25 18:55:21 2009
@@ -64,25 +64,25 @@
///
class MDString : public MetadataBase {
MDString(const MDString &); // DO NOT IMPLEMENT
- const char *StrBegin;
- unsigned StrLength;
+ StringRef Str;
friend class LLVMContextImpl;
protected:
explicit MDString(const char *begin, unsigned l)
- : MetadataBase(Type::MetadataTy, Value::MDStringVal),
- StrBegin(begin), StrLength(l) {}
+ : MetadataBase(Type::MetadataTy, Value::MDStringVal), Str(begin, l) {}
public:
- unsigned length() const { return StrLength; }
+ StringRef getString() const { return Str; }
+
+ unsigned length() const { return Str.size(); }
/// begin() - Pointer to the first byte of the string.
///
- const char *begin() const { return StrBegin; }
+ const char *begin() const { return Str.begin(); }
/// end() - Pointer to one byte past the end of the string.
///
- const char *end() const { return StrBegin + length(); }
+ const char *end() const { return Str.end(); }
/// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const MDString *) { return true; }
Modified: llvm/trunk/include/llvm/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Value.h?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Value.h (original)
+++ llvm/trunk/include/llvm/Value.h Sat Jul 25 18:55:21 2009
@@ -118,10 +118,6 @@
/// getNameEnd - Return a pointer to the end of the name.
const char *getNameEnd() const { return getNameStart() + getNameLen(); }
- /// isName - Return true if this value has the name specified by the provided
- /// nul terminated string.
- bool isName(const char *N) const;
-
/// getNameLen - Return the length of the string, correctly handling nul
/// characters embedded into them.
unsigned getNameLen() const;
@@ -131,7 +127,6 @@
/// construct a string, they are very expensive and should be avoided.
StringRef getName() const { return StringRef(getNameStart(), getNameLen()); }
std::string getNameStr() const;
- StringRef getNameRef() const;
void setName(const Twine &Name);
void setName(const char *Name, unsigned NameLen);
Modified: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp (original)
+++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp Sat Jul 25 18:55:21 2009
@@ -477,7 +477,7 @@
/// special global used by LLVM. If so, emit it and return true, otherwise
/// do nothing and return false.
bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
- if (GV->isName("llvm.used")) {
+ if (GV->getName() == "llvm.used") {
if (TAI->getUsedDirective() != 0) // No need to emit this at all.
EmitLLVMUsedList(GV->getInitializer());
return true;
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Sat Jul 25 18:55:21 2009
@@ -548,7 +548,7 @@
// Check to see if may have to link the global with the global, alias or
// function.
if (SGV->hasName() && !SGV->hasLocalLinkage())
- DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getNameRef()));
+ DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SGV->getName()));
// If we found a global with the same name in the dest module, but it has
// internal linkage, we are really not doing any linkage here.
@@ -941,7 +941,7 @@
// Check to see if may have to link the function with the global, alias or
// function.
if (SF->hasName() && !SF->hasLocalLinkage())
- DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getNameRef()));
+ DGV = cast_or_null<GlobalValue>(DestSymTab.lookup(SF->getName()));
// If we found a global with the same name in the dest module, but it has
// internal linkage, we are really not doing any linkage here.
Modified: llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp Sat Jul 25 18:55:21 2009
@@ -1104,9 +1104,9 @@
if (EmitSpecialLLVMGlobal(GVar)) {
if (Subtarget->isTargetDarwin() &&
TM.getRelocationModel() == Reloc::Static) {
- if (GVar->isName("llvm.global_ctors"))
+ if (GVar->getName() == "llvm.global_ctors")
O << ".reference .constructors_used\n";
- else if (GVar->isName("llvm.global_dtors"))
+ else if (GVar->getName() == "llvm.global_dtors")
O << ".reference .destructors_used\n";
}
return;
Modified: llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp Sat Jul 25 18:55:21 2009
@@ -874,9 +874,9 @@
// Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(GVar)) {
if (TM.getRelocationModel() == Reloc::Static) {
- if (GVar->isName("llvm.global_ctors"))
+ if (GVar->getName() == "llvm.global_ctors")
O << ".reference .constructors_used\n";
- else if (GVar->isName("llvm.global_dtors"))
+ else if (GVar->getName() == "llvm.global_dtors")
O << ".reference .destructors_used\n";
}
return;
Modified: llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp Sat Jul 25 18:55:21 2009
@@ -773,9 +773,9 @@
if (EmitSpecialLLVMGlobal(GVar)) {
if (Subtarget->isTargetDarwin() &&
TM.getRelocationModel() == Reloc::Static) {
- if (GVar->isName("llvm.global_ctors"))
+ if (GVar->getName() == "llvm.global_ctors")
O << ".reference .constructors_used\n";
- else if (GVar->isName("llvm.global_dtors"))
+ else if (GVar->getName() == "llvm.global_dtors")
O << ".reference .destructors_used\n";
}
return;
Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Sat Jul 25 18:55:21 2009
@@ -512,7 +512,7 @@
// Verify the caller is main, and that the result type of main matches the
// argument type of exit.
- if (!Caller->isName("main") || !Caller->hasExternalLinkage() ||
+ if (Caller->getName() != "main" || !Caller->hasExternalLinkage() ||
Caller->getReturnType() != CI->getOperand(1)->getType())
return 0;
Modified: llvm/trunk/lib/Transforms/Utils/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineCost.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineCost.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineCost.cpp Sat Jul 25 18:55:21 2009
@@ -125,7 +125,7 @@
// probably won't do this in callers.
if (Function *F = CS.getCalledFunction())
if (F->isDeclaration() &&
- (F->isName("setjmp") || F->isName("_setjmp"))) {
+ (F->getName() == "setjmp" || F->getName() == "_setjmp")) {
NeverInline = true;
return;
}
Modified: llvm/trunk/lib/VMCore/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AsmWriter.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AsmWriter.cpp (original)
+++ llvm/trunk/lib/VMCore/AsmWriter.cpp Sat Jul 25 18:55:21 2009
@@ -66,10 +66,9 @@
// PrintEscapedString - Print each character of the specified string, escaping
// it if it is not printable or if it is an escape char.
-static void PrintEscapedString(const char *Str, unsigned Length,
- raw_ostream &Out) {
- for (unsigned i = 0; i != Length; ++i) {
- unsigned char C = Str[i];
+static void PrintEscapedString(const StringRef &Name, raw_ostream &Out) {
+ for (unsigned i = 0, e = Name.size(); i != e; ++i) {
+ unsigned char C = Name[i];
if (isprint(C) && C != '\\' && C != '"')
Out << C;
else
@@ -77,12 +76,6 @@
}
}
-// PrintEscapedString - Print each character of the specified string, escaping
-// it if it is not printable or if it is an escape char.
-static void PrintEscapedString(const std::string &Str, raw_ostream &Out) {
- PrintEscapedString(Str.c_str(), Str.size(), Out);
-}
-
enum PrefixType {
GlobalPrefix,
LabelPrefix,
@@ -93,9 +86,9 @@
/// PrintLLVMName - Turn the specified name into an 'LLVM name', which is either
/// prefixed with % (if the string only contains simple characters) or is
/// surrounded with ""'s (if it has special chars in it). Print it out.
-static void PrintLLVMName(raw_ostream &OS, const char *NameStr,
- unsigned NameLen, PrefixType Prefix) {
- assert(NameStr && "Cannot get empty name!");
+static void PrintLLVMName(raw_ostream &OS, const StringRef &Name,
+ PrefixType Prefix) {
+ assert(Name.data() && "Cannot get empty name!");
switch (Prefix) {
default: llvm_unreachable("Bad prefix!");
case NoPrefix: break;
@@ -105,10 +98,10 @@
}
// Scan the name to see if it needs quotes first.
- bool NeedsQuotes = isdigit(NameStr[0]);
+ bool NeedsQuotes = isdigit(Name[0]);
if (!NeedsQuotes) {
- for (unsigned i = 0; i != NameLen; ++i) {
- char C = NameStr[i];
+ for (unsigned i = 0, e = Name.size(); i != e; ++i) {
+ char C = Name[i];
if (!isalnum(C) && C != '-' && C != '.' && C != '_') {
NeedsQuotes = true;
break;
@@ -118,14 +111,14 @@
// If we didn't need any quotes, just write out the name in one blast.
if (!NeedsQuotes) {
- OS.write(NameStr, NameLen);
+ OS << Name;
return;
}
// Okay, we need quotes. Output the quotes and escape any scary characters as
// needed.
OS << '"';
- PrintEscapedString(NameStr, NameLen, OS);
+ PrintEscapedString(Name, OS);
OS << '"';
}
@@ -133,7 +126,7 @@
/// prefixed with % (if the string only contains simple characters) or is
/// surrounded with ""'s (if it has special chars in it). Print it out.
static void PrintLLVMName(raw_ostream &OS, const Value *V) {
- PrintLLVMName(OS, V->getNameStart(), V->getNameLen(),
+ PrintLLVMName(OS, V->getName(),
isa<GlobalValue>(V) ? GlobalPrefix : LocalPrefix);
}
@@ -433,7 +426,7 @@
// Get the name as a string and insert it into TypeNames.
std::string NameStr;
raw_string_ostream NameOS(NameStr);
- PrintLLVMName(NameOS, TI->first.c_str(), TI->first.length(), LocalPrefix);
+ PrintLLVMName(NameOS, TI->first, LocalPrefix);
TP.addTypeName(Ty, NameOS.str());
}
@@ -1138,7 +1131,7 @@
if (const MDString *MDS = dyn_cast<MDString>(V)) {
Out << "!\"";
- PrintEscapedString(MDS->begin(), MDS->length(), Out);
+ PrintEscapedString(MDS->getString(), Out);
Out << '"';
return;
}
@@ -1474,7 +1467,7 @@
for (TypeSymbolTable::const_iterator TI = ST.begin(), TE = ST.end();
TI != TE; ++TI) {
Out << '\t';
- PrintLLVMName(Out, &TI->first[0], TI->first.size(), LocalPrefix);
+ PrintLLVMName(Out, TI->first, LocalPrefix);
Out << " = type ";
// Make sure we print out at least one level of the type structure, so
@@ -1605,7 +1598,7 @@
void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
if (BB->hasName()) { // Print out the label if it exists...
Out << "\n";
- PrintLLVMName(Out, BB->getNameStart(), BB->getNameLen(), LabelPrefix);
+ PrintLLVMName(Out, BB->getName(), LabelPrefix);
Out << ':';
} else if (!BB->use_empty()) { // Don't print block # of no uses...
Out << "\n; <label>:";
@@ -1982,7 +1975,7 @@
TypePrinter.print(MDS->getType(), OS);
OS << ' ';
OS << "!\"";
- PrintEscapedString(MDS->begin(), MDS->length(), OS);
+ PrintEscapedString(MDS->getString(), OS);
OS << '"';
} else if (const MDNode *N = dyn_cast<MDNode>(this)) {
SlotTracker SlotTable(N);
Modified: llvm/trunk/lib/VMCore/AutoUpgrade.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/AutoUpgrade.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/AutoUpgrade.cpp (original)
+++ llvm/trunk/lib/VMCore/AutoUpgrade.cpp Sat Jul 25 18:55:21 2009
@@ -241,23 +241,23 @@
bool isMovSD = false, isShufPD = false;
bool isUnpckhPD = false, isUnpcklPD = false;
bool isPunpckhQPD = false, isPunpcklQPD = false;
- if (strcmp(F->getNameStart(), "llvm.x86.sse2.loadh.pd") == 0)
+ if (F->getName() == "llvm.x86.sse2.loadh.pd")
isLoadH = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.loadl.pd") == 0)
+ else if (F->getName() == "llvm.x86.sse2.loadl.pd")
isLoadL = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.movl.dq") == 0)
+ else if (F->getName() == "llvm.x86.sse2.movl.dq")
isMovL = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.movs.d") == 0)
+ else if (F->getName() == "llvm.x86.sse2.movs.d")
isMovSD = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.shuf.pd") == 0)
+ else if (F->getName() == "llvm.x86.sse2.shuf.pd")
isShufPD = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.unpckh.pd") == 0)
+ else if (F->getName() == "llvm.x86.sse2.unpckh.pd")
isUnpckhPD = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.unpckl.pd") == 0)
+ else if (F->getName() == "llvm.x86.sse2.unpckl.pd")
isUnpcklPD = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.punpckh.qdq") == 0)
+ else if (F->getName() == "llvm.x86.sse2.punpckh.qdq")
isPunpckhQPD = true;
- else if (strcmp(F->getNameStart(), "llvm.x86.sse2.punpckl.qdq") == 0)
+ else if (F->getName() == "llvm.x86.sse2.punpckl.qdq")
isPunpcklQPD = true;
if (isLoadH || isLoadL || isMovL || isMovSD || isShufPD ||
Modified: llvm/trunk/lib/VMCore/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/LLVMContextImpl.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/VMCore/LLVMContextImpl.cpp Sat Jul 25 18:55:21 2009
@@ -188,8 +188,7 @@
void LLVMContextImpl::erase(MDString *M) {
sys::SmartScopedWriter<true> Writer(ConstantsLock);
- MDStringCache.erase(MDStringCache.find(StringRef(M->StrBegin,
- M->length())));
+ MDStringCache.erase(MDStringCache.find(M->getString()));
}
void LLVMContextImpl::erase(MDNode *M) {
Modified: llvm/trunk/lib/VMCore/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Value.cpp (original)
+++ llvm/trunk/lib/VMCore/Value.cpp Sat Jul 25 18:55:21 2009
@@ -165,13 +165,6 @@
return Name ? Name->getKeyLength() : 0;
}
-/// isName - Return true if this value has the name specified by the provided
-/// nul terminated string.
-bool Value::isName(const char *N) const {
- unsigned InLen = strlen(N);
- return InLen == getNameLen() && memcmp(getNameStart(), N, InLen) == 0;
-}
-
std::string Value::getNameStr() const {
if (Name == 0) return "";
@@ -179,11 +172,6 @@
Name->getKeyData()+Name->getKeyLength());
}
-StringRef Value::getNameRef() const {
- if (Name == 0) return StringRef();
- return StringRef(Name->getKeyData(), Name->getKeyLength());
-}
-
void Value::setName(const Twine &Name) {
SmallString<32> NameData;
Name.toVector(NameData);
Modified: llvm/trunk/lib/VMCore/ValueSymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/ValueSymbolTable.cpp?rev=77098&r1=77097&r2=77098&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/ValueSymbolTable.cpp (original)
+++ llvm/trunk/lib/VMCore/ValueSymbolTable.cpp Sat Jul 25 18:55:21 2009
@@ -43,7 +43,7 @@
}
// Otherwise, there is a naming conflict. Rename this value.
- SmallString<128> UniqueName(V->getNameStart(), V->getNameEnd());
+ SmallString<128> UniqueName(V->getName().begin(), V->getName().end());
// The name is too already used, just free it so we can allocate a new name.
V->Name->Destroy();
More information about the llvm-commits
mailing list