[llvm-commits] [llvm] r87020 - in /llvm/trunk: include/llvm/ADT/StringRef.h lib/CodeGen/SelectionDAG/TargetLowering.cpp lib/Support/StringRef.cpp lib/Target/X86/X86ISelLowering.cpp tools/bugpoint/ToolRunner.cpp
Benjamin Kramer
benny.kra at googlemail.com
Thu Nov 12 12:37:00 PST 2009
Author: d0k
Date: Thu Nov 12 14:36:59 2009
New Revision: 87020
URL: http://llvm.org/viewvc/llvm-project?rev=87020&view=rev
Log:
Add compare_lower and equals_lower methods to StringRef. Switch all users of
StringsEqualNoCase (from StringExtras.h) to it.
Modified:
llvm/trunk/include/llvm/ADT/StringRef.h
llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/trunk/lib/Support/StringRef.cpp
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
llvm/trunk/tools/bugpoint/ToolRunner.cpp
Modified: llvm/trunk/include/llvm/ADT/StringRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=87020&r1=87019&r2=87020&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Thu Nov 12 14:36:59 2009
@@ -97,6 +97,11 @@
memcmp(Data, RHS.Data, RHS.Length) == 0);
}
+ /// equals_lower - Check for string equality, ignoring case.
+ bool equals_lower(StringRef RHS) const {
+ return Length == RHS.Length && compare_lower(RHS) == 0;
+ }
+
/// compare - Compare two strings; the result is -1, 0, or 1 if this string
/// is lexicographically less than, equal to, or greater than the \arg RHS.
int compare(StringRef RHS) const {
@@ -110,6 +115,9 @@
return Length < RHS.Length ? -1 : 1;
}
+ /// compare_lower - Compare two strings, ignoring case.
+ int compare_lower(StringRef RHS) const;
+
/// str - Get the contents as an std::string.
std::string str() const { return std::string(Data, Length); }
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=87020&r1=87019&r2=87020&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Thu Nov 12 14:36:59 2009
@@ -22,7 +22,6 @@
#include "llvm/DerivedTypes.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/SelectionDAG.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MathExtras.h"
@@ -2365,7 +2364,7 @@
assert(*(Constraint.end()-1) == '}' && "Not a brace enclosed constraint?");
// Remove the braces from around the name.
- std::string RegName(Constraint.begin()+1, Constraint.end()-1);
+ StringRef RegName(Constraint.data()+1, Constraint.size()-2);
// Figure out which register class contains this reg.
const TargetRegisterInfo *RI = TM.getRegisterInfo();
@@ -2388,7 +2387,7 @@
for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end();
I != E; ++I) {
- if (StringsEqualNoCase(RegName, RI->getName(*I)))
+ if (RegName.equals_lower(RI->getName(*I)))
return std::make_pair(*I, RC);
}
}
Modified: llvm/trunk/lib/Support/StringRef.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRef.cpp?rev=87020&r1=87019&r2=87020&view=diff
==============================================================================
--- llvm/trunk/lib/Support/StringRef.cpp (original)
+++ llvm/trunk/lib/Support/StringRef.cpp Thu Nov 12 14:36:59 2009
@@ -15,6 +15,26 @@
const size_t StringRef::npos;
#endif
+static char ascii_tolower(char x) {
+ if (x >= 'A' && x <= 'Z')
+ return x - 'A' + 'a';
+ return x;
+}
+
+/// compare_lower - Compare strings, ignoring case.
+int StringRef::compare_lower(StringRef RHS) const {
+ for (size_t I = 0, E = std::min(Length, RHS.Length); I != E; ++I) {
+ char LHC = ascii_tolower(Data[I]);
+ char RHC = ascii_tolower(RHS.Data[I]);
+ if (LHC != RHC)
+ return LHC < RHC ? -1 : 1;
+ }
+
+ if (Length == RHS.Length)
+ return 0;
+ return Length < RHS.Length ? -1 : 1;
+}
+
//===----------------------------------------------------------------------===//
// String Searching
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=87020&r1=87019&r2=87020&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Thu Nov 12 14:36:59 2009
@@ -9595,14 +9595,14 @@
}
// GCC allows "st(0)" to be called just plain "st".
- if (StringsEqualNoCase("{st}", Constraint)) {
+ if (StringRef("{st}").equals_lower(Constraint)) {
Res.first = X86::ST0;
Res.second = X86::RFP80RegisterClass;
return Res;
}
// flags -> EFLAGS
- if (StringsEqualNoCase("{flags}", Constraint)) {
+ if (StringRef("{flags}").equals_lower(Constraint)) {
Res.first = X86::EFLAGS;
Res.second = X86::CCRRegisterClass;
return Res;
Modified: llvm/trunk/tools/bugpoint/ToolRunner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ToolRunner.cpp?rev=87020&r1=87019&r2=87020&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ToolRunner.cpp (original)
+++ llvm/trunk/tools/bugpoint/ToolRunner.cpp Thu Nov 12 14:36:59 2009
@@ -18,7 +18,6 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/ADT/StringExtras.h"
#include "llvm/Config/config.h" // for HAVE_LINK_R
#include <fstream>
#include <sstream>
@@ -610,9 +609,10 @@
{
for (std::vector<std::string>::const_iterator
I = Args.begin(), E = Args.end(); I != E; ++I) {
- if (!StringsEqualNoCase(*I, "-arch")) {
+ StringRef S(*I);
+ if (!S.equals_lower("-arch")) {
++I;
- if ((I != E) && !StringsEqualNoCase(I->c_str(), "arm", strlen("arm"))) {
+ if (I != E && !S.substr(0, strlen("arm")).equals_lower("arm")) {
return true;
}
}
More information about the llvm-commits
mailing list