Hi Benjamin,<div><br></div><div>There is a bug in your changes: the Module::getPointerSize function now returns AnyPointerSize for the following data layout:</div><div>e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32<br>
<br></div><div>It should return Pointer32.</div><div><br></div><div>I will try to investigate a bit more.</div><div><br></div><div>Cheers,</div><div>Nicolas</div><div><br><div class="gmail_quote">On Mon, Jan 11, 2010 at 7:03 PM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com">benny.kra@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Author: d0k<br>
Date: Mon Jan 11 12:03:24 2010<br>
New Revision: 93161<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=93161&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=93161&view=rev</a><br>
Log:<br>
Reimplement getToken and SplitString as "StringRef helper functions"<br>
<br>
- getToken is modeled after StringRef::split but it can split on multiple<br>
separator chars and skips leading seperators.<br>
- SplitString is a StringRef::split variant for more than 2 elements with the<br>
same behaviour as getToken.<br>
<br>
Modified:<br>
llvm/trunk/include/llvm/ADT/StringExtras.h<br>
llvm/trunk/lib/Support/StringExtras.cpp<br>
llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
llvm/trunk/lib/VMCore/Module.cpp<br>
llvm/trunk/tools/lto/LTOCodeGenerator.cpp<br>
llvm/trunk/utils/TableGen/CodeGenInstruction.cpp<br>
<br>
Modified: llvm/trunk/include/llvm/ADT/StringExtras.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=93161&r1=93160&r2=93161&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringExtras.h?rev=93161&r1=93160&r2=93161&view=diff</a><br>
<br>
==============================================================================<br>
--- llvm/trunk/include/llvm/ADT/StringExtras.h (original)<br>
+++ llvm/trunk/include/llvm/ADT/StringExtras.h Mon Jan 11 12:03:24 2010<br>
@@ -20,9 +20,9 @@<br>
#include <cctype><br>
#include <cstdio><br>
#include <string><br>
-#include <vector><br>
<br>
namespace llvm {<br>
+template<typename T> class SmallVectorImpl;<br>
<br>
/// hexdigit - Return the (uppercase) hexadecimal character for the<br>
/// given number \arg X (which should be less than 16).<br>
@@ -206,16 +206,16 @@<br>
/// leading characters that appear in the Delimiters string, and ending the<br>
/// token at any of the characters that appear in the Delimiters string. If<br>
/// there are no tokens in the source string, an empty string is returned.<br>
-/// The Source source string is updated in place to remove the returned string<br>
-/// and any delimiter prefix from it.<br>
-std::string getToken(std::string &Source,<br>
- const char *Delimiters = " \t\n\v\f\r");<br>
+/// The function returns a pair containing the extracted token and the<br>
+/// remaining tail string.<br>
+std::pair<StringRef, StringRef> getToken(StringRef Source,<br>
+ StringRef Delimiters = " \t\n\v\f\r");<br>
<br>
/// SplitString - Split up the specified string according to the specified<br>
/// delimiters, appending the result fragments to the output list.<br>
-void SplitString(const std::string &Source,<br>
- std::vector<std::string> &OutFragments,<br>
- const char *Delimiters = " \t\n\v\f\r");<br>
+void SplitString(StringRef Source,<br>
+ SmallVectorImpl<StringRef> &OutFragments,<br>
+ StringRef Delimiters = " \t\n\v\f\r");<br>
<br>
/// HashString - Hash funtion for strings.<br>
///<br>
<br>
Modified: llvm/trunk/lib/Support/StringExtras.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringExtras.cpp?rev=93161&r1=93160&r2=93161&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringExtras.cpp?rev=93161&r1=93160&r2=93161&view=diff</a><br>
<br>
==============================================================================<br>
--- llvm/trunk/lib/Support/StringExtras.cpp (original)<br>
+++ llvm/trunk/lib/Support/StringExtras.cpp Mon Jan 11 12:03:24 2010<br>
@@ -11,50 +11,40 @@<br>
//<br>
//===----------------------------------------------------------------------===//<br>
<br>
-#include "llvm/ADT/StringExtras.h"<br>
#include "llvm/ADT/SmallVector.h"<br>
-#include <cstring><br>
+#include "llvm/ADT/STLExtras.h"<br>
+#include "llvm/ADT/StringExtras.h"<br>
using namespace llvm;<br>
<br>
/// getToken - This function extracts one token from source, ignoring any<br>
/// leading characters that appear in the Delimiters string, and ending the<br>
/// token at any of the characters that appear in the Delimiters string. If<br>
/// there are no tokens in the source string, an empty string is returned.<br>
-/// The Source source string is updated in place to remove the returned string<br>
-/// and any delimiter prefix from it.<br>
-std::string llvm::getToken(std::string &Source, const char *Delimiters) {<br>
- size_t NumDelimiters = std::strlen(Delimiters);<br>
-<br>
+/// The function returns a pair containing the extracted token and the<br>
+/// remaining tail string.<br>
+std::pair<StringRef, StringRef> llvm::getToken(StringRef Source,<br>
+ StringRef Delimiters) {<br>
// Figure out where the token starts.<br>
- std::string::size_type Start =<br>
- Source.find_first_not_of(Delimiters, 0, NumDelimiters);<br>
- if (Start == std::string::npos) Start = Source.size();<br>
-<br>
- // Find the next occurance of the delimiter.<br>
- std::string::size_type End =<br>
- Source.find_first_of(Delimiters, Start, NumDelimiters);<br>
- if (End == std::string::npos) End = Source.size();<br>
-<br>
- // Create the return token.<br>
- std::string Result = std::string(Source.begin()+Start, Source.begin()+End);<br>
+ StringRef::size_type Start = Source.find_first_not_of(Delimiters);<br>
+ if (Start == StringRef::npos) Start = Source.size();<br>
<br>
- // Erase the token that we read in.<br>
- Source.erase(Source.begin(), Source.begin()+End);<br>
+ // Find the next occurrence of the delimiter.<br>
+ StringRef::size_type End = Source.find_first_of(Delimiters, Start);<br>
+ if (End == StringRef::npos) End = Source.size();<br>
<br>
- return Result;<br>
+ return std::make_pair(Source.substr(Start, End), Source.substr(End));<br>
}<br>
<br>
/// SplitString - Split up the specified string according to the specified<br>
/// delimiters, appending the result fragments to the output list.<br>
-void llvm::SplitString(const std::string &Source,<br>
- std::vector<std::string> &OutFragments,<br>
- const char *Delimiters) {<br>
- std::string S = Source;<br>
-<br>
- std::string S2 = getToken(S, Delimiters);<br>
+void llvm::SplitString(StringRef Source,<br>
+ SmallVectorImpl<StringRef> &OutFragments,<br>
+ StringRef Delimiters) {<br>
+ StringRef S2, S;<br>
+ tie(S2, S) = getToken(Source, Delimiters);<br>
while (!S2.empty()) {<br>
OutFragments.push_back(S2);<br>
- S2 = getToken(S, Delimiters);<br>
+ tie(S2, S) = getToken(S, Delimiters);<br>
}<br>
}<br>
<br>
<br>
Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=93161&r1=93160&r2=93161&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=93161&r1=93160&r2=93161&view=diff</a><br>
<br>
==============================================================================<br>
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)<br>
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Mon Jan 11 12:03:24 2010<br>
@@ -9538,7 +9538,7 @@<br>
std::string AsmStr = IA->getAsmString();<br>
<br>
// TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"<br>
- std::vector<std::string> AsmPieces;<br>
+ SmallVector<StringRef, 4> AsmPieces;<br>
SplitString(AsmStr, AsmPieces, "\n"); // ; as separator?<br>
<br>
switch (AsmPieces.size()) {<br>
@@ -9575,7 +9575,7 @@<br>
Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&<br>
Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {<br>
// bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64<br>
- std::vector<std::string> Words;<br>
+ SmallVector<StringRef, 4> Words;<br>
SplitString(AsmPieces[0], Words, " \t");<br>
if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {<br>
Words.clear();<br>
<br>
Modified: llvm/trunk/lib/VMCore/Module.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=93161&r1=93160&r2=93161&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Module.cpp?rev=93161&r1=93160&r2=93161&view=diff</a><br>
<br>
==============================================================================<br>
--- llvm/trunk/lib/VMCore/Module.cpp (original)<br>
+++ llvm/trunk/lib/VMCore/Module.cpp Mon Jan 11 12:03:24 2010<br>
@@ -76,11 +76,12 @@<br>
<br>
/// Target endian information...<br>
Module::Endianness Module::getEndianness() const {<br>
- std::string temp = DataLayout;<br>
+ StringRef temp = DataLayout;<br>
Module::Endianness ret = AnyEndianness;<br>
<br>
while (!temp.empty()) {<br>
- std::string token = getToken(temp, "-");<br>
+ StringRef token = DataLayout;<br>
+ tie(token, temp) = getToken(DataLayout, "-");<br>
<br>
if (token[0] == 'e') {<br>
ret = LittleEndian;<br>
@@ -94,15 +95,17 @@<br>
<br>
/// Target Pointer Size information...<br>
Module::PointerSize Module::getPointerSize() const {<br>
- std::string temp = DataLayout;<br>
+ StringRef temp = DataLayout;<br>
Module::PointerSize ret = AnyPointerSize;<br>
<br>
while (!temp.empty()) {<br>
- std::string token = getToken(temp, "-");<br>
- char signal = getToken(token, ":")[0];<br>
+ StringRef token, signalToken;<br>
+ tie(token, temp) = getToken(temp, "-");<br>
+ tie(signalToken, token) = getToken(token, ":");<br>
<br>
- if (signal == 'p') {<br>
- int size = atoi(getToken(token, ":").c_str());<br>
+ if (signalToken[0] == 'p') {<br>
+ int size = 0;<br>
+ getToken(token, ":").first.getAsInteger(10, size);<br>
if (size == 32)<br>
ret = Pointer32;<br>
else if (size == 64)<br>
<br>
Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=93161&r1=93160&r2=93161&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=93161&r1=93160&r2=93161&view=diff</a><br>
<br>
==============================================================================<br>
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)<br>
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Mon Jan 11 12:03:24 2010<br>
@@ -443,12 +443,12 @@<br>
/// Optimize merged modules using various IPO passes<br>
void LTOCodeGenerator::setCodeGenDebugOptions(const char* options)<br>
{<br>
- std::string ops(options);<br>
- for (std::string o = getToken(ops); !o.empty(); o = getToken(ops)) {<br>
+ for (std::pair<StringRef, StringRef> o = getToken(options);<br>
+ !o.first.empty(); o = getToken(o.second)) {<br>
// ParseCommandLineOptions() expects argv[0] to be program name.<br>
// Lazily add that.<br>
if ( _codegenOptions.empty() )<br>
_codegenOptions.push_back("libLTO");<br>
- _codegenOptions.push_back(strdup(o.c_str()));<br>
+ _codegenOptions.push_back(strdup(o.first.str().c_str()));<br>
}<br>
}<br>
<br>
Modified: llvm/trunk/utils/TableGen/CodeGenInstruction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenInstruction.cpp?rev=93161&r1=93160&r2=93161&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenInstruction.cpp?rev=93161&r1=93160&r2=93161&view=diff</a><br>
<br>
==============================================================================<br>
--- llvm/trunk/utils/TableGen/CodeGenInstruction.cpp (original)<br>
+++ llvm/trunk/utils/TableGen/CodeGenInstruction.cpp Mon Jan 11 12:03:24 2010<br>
@@ -14,6 +14,7 @@<br>
#include "CodeGenInstruction.h"<br>
#include "Record.h"<br>
#include "llvm/ADT/StringExtras.h"<br>
+#include "llvm/ADT/STLExtras.h"<br>
#include <set><br>
using namespace llvm;<br>
<br>
@@ -224,7 +225,8 @@<br>
// Parse the DisableEncoding field.<br>
std::string DisableEncoding = R->getValueAsString("DisableEncoding");<br>
while (1) {<br>
- std::string OpName = getToken(DisableEncoding, " ,\t");<br>
+ std::string OpName;<br>
+ tie(OpName, DisableEncoding) = getToken(DisableEncoding, " ,\t");<br>
if (OpName.empty()) break;<br>
<br>
// Figure out which operand this is.<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>