summaryrefslogtreecommitdiffstats
path: root/lib/Support
diff options
context:
space:
mode:
authorrdivacky <rdivacky@FreeBSD.org>2010-01-15 15:37:28 +0000
committerrdivacky <rdivacky@FreeBSD.org>2010-01-15 15:37:28 +0000
commit3fba7d16b41dfbefe3b1be6bc0ab94c017728f79 (patch)
treebe5a687969f682edded4aa6f13594ffd9aa9030e /lib/Support
parenta16c51cee9225a354c999dd1076d5dba2aa79807 (diff)
downloadFreeBSD-src-3fba7d16b41dfbefe3b1be6bc0ab94c017728f79.zip
FreeBSD-src-3fba7d16b41dfbefe3b1be6bc0ab94c017728f79.tar.gz
Update LLVM to 93512.
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/APInt.cpp68
-rw-r--r--lib/Support/CommandLine.cpp8
-rw-r--r--lib/Support/ConstantRange.cpp3
-rw-r--r--lib/Support/ErrorHandling.cpp9
-rw-r--r--lib/Support/FormattedStream.cpp8
-rw-r--r--lib/Support/Statistic.cpp3
-rw-r--r--lib/Support/StringExtras.cpp59
-rw-r--r--lib/Support/StringRef.cpp25
-rw-r--r--lib/Support/Timer.cpp3
-rw-r--r--lib/Support/Twine.cpp15
10 files changed, 117 insertions, 84 deletions
diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp
index 9532e1e..9d14684 100644
--- a/lib/Support/APInt.cpp
+++ b/lib/Support/APInt.cpp
@@ -1580,12 +1580,12 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
uint64_t b = uint64_t(1) << 32;
#if 0
- DEBUG(errs() << "KnuthDiv: m=" << m << " n=" << n << '\n');
- DEBUG(errs() << "KnuthDiv: original:");
- DEBUG(for (int i = m+n; i >=0; i--) errs() << " " << u[i]);
- DEBUG(errs() << " by");
- DEBUG(for (int i = n; i >0; i--) errs() << " " << v[i-1]);
- DEBUG(errs() << '\n');
+ DEBUG(dbgs() << "KnuthDiv: m=" << m << " n=" << n << '\n');
+ DEBUG(dbgs() << "KnuthDiv: original:");
+ DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]);
+ DEBUG(dbgs() << " by");
+ DEBUG(for (int i = n; i >0; i--) dbgs() << " " << v[i-1]);
+ DEBUG(dbgs() << '\n');
#endif
// D1. [Normalize.] Set d = b / (v[n-1] + 1) and multiply all the digits of
// u and v by d. Note that we have taken Knuth's advice here to use a power
@@ -1612,17 +1612,17 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
}
u[m+n] = u_carry;
#if 0
- DEBUG(errs() << "KnuthDiv: normal:");
- DEBUG(for (int i = m+n; i >=0; i--) errs() << " " << u[i]);
- DEBUG(errs() << " by");
- DEBUG(for (int i = n; i >0; i--) errs() << " " << v[i-1]);
- DEBUG(errs() << '\n');
+ DEBUG(dbgs() << "KnuthDiv: normal:");
+ DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]);
+ DEBUG(dbgs() << " by");
+ DEBUG(for (int i = n; i >0; i--) dbgs() << " " << v[i-1]);
+ DEBUG(dbgs() << '\n');
#endif
// D2. [Initialize j.] Set j to m. This is the loop counter over the places.
int j = m;
do {
- DEBUG(errs() << "KnuthDiv: quotient digit #" << j << '\n');
+ DEBUG(dbgs() << "KnuthDiv: quotient digit #" << j << '\n');
// D3. [Calculate q'.].
// Set qp = (u[j+n]*b + u[j+n-1]) / v[n-1]. (qp=qprime=q')
// Set rp = (u[j+n]*b + u[j+n-1]) % v[n-1]. (rp=rprime=r')
@@ -1632,7 +1632,7 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
// value qp is one too large, and it eliminates all cases where qp is two
// too large.
uint64_t dividend = ((uint64_t(u[j+n]) << 32) + u[j+n-1]);
- DEBUG(errs() << "KnuthDiv: dividend == " << dividend << '\n');
+ DEBUG(dbgs() << "KnuthDiv: dividend == " << dividend << '\n');
uint64_t qp = dividend / v[n-1];
uint64_t rp = dividend % v[n-1];
if (qp == b || qp*v[n-2] > b*rp + u[j+n-2]) {
@@ -1641,7 +1641,7 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
if (rp < b && (qp == b || qp*v[n-2] > b*rp + u[j+n-2]))
qp--;
}
- DEBUG(errs() << "KnuthDiv: qp == " << qp << ", rp == " << rp << '\n');
+ DEBUG(dbgs() << "KnuthDiv: qp == " << qp << ", rp == " << rp << '\n');
// D4. [Multiply and subtract.] Replace (u[j+n]u[j+n-1]...u[j]) with
// (u[j+n]u[j+n-1]..u[j]) - qp * (v[n-1]...v[1]v[0]). This computation
@@ -1652,7 +1652,7 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
uint64_t u_tmp = uint64_t(u[j+i]) | (uint64_t(u[j+i+1]) << 32);
uint64_t subtrahend = uint64_t(qp) * uint64_t(v[i]);
bool borrow = subtrahend > u_tmp;
- DEBUG(errs() << "KnuthDiv: u_tmp == " << u_tmp
+ DEBUG(dbgs() << "KnuthDiv: u_tmp == " << u_tmp
<< ", subtrahend == " << subtrahend
<< ", borrow = " << borrow << '\n');
@@ -1666,12 +1666,12 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
k++;
}
isNeg |= borrow;
- DEBUG(errs() << "KnuthDiv: u[j+i] == " << u[j+i] << ", u[j+i+1] == " <<
+ DEBUG(dbgs() << "KnuthDiv: u[j+i] == " << u[j+i] << ", u[j+i+1] == " <<
u[j+i+1] << '\n');
}
- DEBUG(errs() << "KnuthDiv: after subtraction:");
- DEBUG(for (int i = m+n; i >=0; i--) errs() << " " << u[i]);
- DEBUG(errs() << '\n');
+ DEBUG(dbgs() << "KnuthDiv: after subtraction:");
+ DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]);
+ DEBUG(dbgs() << '\n');
// The digits (u[j+n]...u[j]) should be kept positive; if the result of
// this step is actually negative, (u[j+n]...u[j]) should be left as the
// true value plus b**(n+1), namely as the b's complement of
@@ -1684,9 +1684,9 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
carry = carry && u[i] == 0;
}
}
- DEBUG(errs() << "KnuthDiv: after complement:");
- DEBUG(for (int i = m+n; i >=0; i--) errs() << " " << u[i]);
- DEBUG(errs() << '\n');
+ DEBUG(dbgs() << "KnuthDiv: after complement:");
+ DEBUG(for (int i = m+n; i >=0; i--) dbgs() << " " << u[i]);
+ DEBUG(dbgs() << '\n');
// D5. [Test remainder.] Set q[j] = qp. If the result of step D4 was
// negative, go to step D6; otherwise go on to step D7.
@@ -1707,16 +1707,16 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
}
u[j+n] += carry;
}
- DEBUG(errs() << "KnuthDiv: after correction:");
- DEBUG(for (int i = m+n; i >=0; i--) errs() <<" " << u[i]);
- DEBUG(errs() << "\nKnuthDiv: digit result = " << q[j] << '\n');
+ DEBUG(dbgs() << "KnuthDiv: after correction:");
+ DEBUG(for (int i = m+n; i >=0; i--) dbgs() <<" " << u[i]);
+ DEBUG(dbgs() << "\nKnuthDiv: digit result = " << q[j] << '\n');
// D7. [Loop on j.] Decrease j by one. Now if j >= 0, go back to D3.
} while (--j >= 0);
- DEBUG(errs() << "KnuthDiv: quotient:");
- DEBUG(for (int i = m; i >=0; i--) errs() <<" " << q[i]);
- DEBUG(errs() << '\n');
+ DEBUG(dbgs() << "KnuthDiv: quotient:");
+ DEBUG(for (int i = m; i >=0; i--) dbgs() <<" " << q[i]);
+ DEBUG(dbgs() << '\n');
// D8. [Unnormalize]. Now q[...] is the desired quotient, and the desired
// remainder may be obtained by dividing u[...] by d. If r is non-null we
@@ -1727,22 +1727,22 @@ static void KnuthDiv(unsigned *u, unsigned *v, unsigned *q, unsigned* r,
// shift right here. In order to mak
if (shift) {
unsigned carry = 0;
- DEBUG(errs() << "KnuthDiv: remainder:");
+ DEBUG(dbgs() << "KnuthDiv: remainder:");
for (int i = n-1; i >= 0; i--) {
r[i] = (u[i] >> shift) | carry;
carry = u[i] << (32 - shift);
- DEBUG(errs() << " " << r[i]);
+ DEBUG(dbgs() << " " << r[i]);
}
} else {
for (int i = n-1; i >= 0; i--) {
r[i] = u[i];
- DEBUG(errs() << " " << r[i]);
+ DEBUG(dbgs() << " " << r[i]);
}
}
- DEBUG(errs() << '\n');
+ DEBUG(dbgs() << '\n');
}
#if 0
- DEBUG(errs() << '\n');
+ DEBUG(dbgs() << '\n');
#endif
}
@@ -2191,7 +2191,7 @@ void APInt::dump() const {
SmallString<40> S, U;
this->toStringUnsigned(U);
this->toStringSigned(S);
- errs() << "APInt(" << BitWidth << "b, "
+ dbgs() << "APInt(" << BitWidth << "b, "
<< U.str() << "u " << S.str() << "s)";
}
diff --git a/lib/Support/CommandLine.cpp b/lib/Support/CommandLine.cpp
index b6c0e08..fa692be8 100644
--- a/lib/Support/CommandLine.cpp
+++ b/lib/Support/CommandLine.cpp
@@ -354,7 +354,7 @@ static Option *HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value,
// we don't need to pass argc/argv in.
assert(PGOpt->getValueExpectedFlag() != cl::ValueRequired &&
"Option can not be cl::Grouping AND cl::ValueRequired!");
- int Dummy;
+ int Dummy = 0;
ErrorParsing |= ProvideOption(PGOpt, OneArgName,
StringRef(), 0, 0, Dummy);
@@ -778,10 +778,10 @@ void cl::ParseCommandLineOptions(int argc, char **argv,
free(*i);
}
- DEBUG(errs() << "Args: ";
+ DEBUG(dbgs() << "Args: ";
for (int i = 0; i < argc; ++i)
- errs() << argv[i] << ' ';
- errs() << '\n';
+ dbgs() << argv[i] << ' ';
+ dbgs() << '\n';
);
// If we had an error processing our arguments, don't let the program execute
diff --git a/lib/Support/ConstantRange.cpp b/lib/Support/ConstantRange.cpp
index e427f82..ddf14e3 100644
--- a/lib/Support/ConstantRange.cpp
+++ b/lib/Support/ConstantRange.cpp
@@ -22,6 +22,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/ConstantRange.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Instructions.h"
using namespace llvm;
@@ -655,7 +656,7 @@ void ConstantRange::print(raw_ostream &OS) const {
/// dump - Allow printing from a debugger easily...
///
void ConstantRange::dump() const {
- print(errs());
+ print(dbgs());
}
diff --git a/lib/Support/ErrorHandling.cpp b/lib/Support/ErrorHandling.cpp
index dff4f03..8bb1566 100644
--- a/lib/Support/ErrorHandling.cpp
+++ b/lib/Support/ErrorHandling.cpp
@@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Threading.h"
@@ -62,11 +63,11 @@ void llvm_unreachable_internal(const char *msg, const char *file,
// llvm_unreachable is intended to be used to indicate "impossible"
// situations, and not legitimate runtime errors.
if (msg)
- errs() << msg << "\n";
- errs() << "UNREACHABLE executed";
+ dbgs() << msg << "\n";
+ dbgs() << "UNREACHABLE executed";
if (file)
- errs() << " at " << file << ":" << line;
- errs() << "!\n";
+ dbgs() << " at " << file << ":" << line;
+ dbgs() << "!\n";
abort();
}
}
diff --git a/lib/Support/FormattedStream.cpp b/lib/Support/FormattedStream.cpp
index 70f2cfa..9ab3666 100644
--- a/lib/Support/FormattedStream.cpp
+++ b/lib/Support/FormattedStream.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Support/Debug.h"
#include "llvm/Support/FormattedStream.h"
using namespace llvm;
@@ -91,3 +92,10 @@ formatted_raw_ostream &llvm::ferrs() {
static formatted_raw_ostream S(errs());
return S;
}
+
+/// fdbgs() - This returns a reference to a formatted_raw_ostream for
+/// the debug stream. Use it like: fdbgs() << "foo" << "bar";
+formatted_raw_ostream &llvm::fdbgs() {
+ static formatted_raw_ostream S(dbgs());
+ return S;
+}
diff --git a/lib/Support/Statistic.cpp b/lib/Support/Statistic.cpp
index 14f94bc..e787670 100644
--- a/lib/Support/Statistic.cpp
+++ b/lib/Support/Statistic.cpp
@@ -23,6 +23,7 @@
#include "llvm/ADT/Statistic.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Mutex.h"
@@ -127,6 +128,6 @@ StatisticInfo::~StatisticInfo() {
OutStream << '\n'; // Flush the output stream...
OutStream.flush();
- if (&OutStream != &outs() && &OutStream != &errs())
+ if (&OutStream != &outs() && &OutStream != &errs() && &OutStream != &dbgs())
delete &OutStream; // Close the file.
}
diff --git a/lib/Support/StringExtras.cpp b/lib/Support/StringExtras.cpp
index 1b233ab..785e0ec 100644
--- a/lib/Support/StringExtras.cpp
+++ b/lib/Support/StringExtras.cpp
@@ -11,50 +11,53 @@
//
//===----------------------------------------------------------------------===//
-#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/SmallVector.h"
-#include <cstring>
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
using namespace llvm;
+/// StrInStrNoCase - Portable version of strcasestr. Locates the first
+/// occurrence of string 's1' in string 's2', ignoring case. Returns
+/// the offset of s2 in s1 or npos if s2 cannot be found.
+StringRef::size_type llvm::StrInStrNoCase(StringRef s1, StringRef s2) {
+ size_t N = s2.size(), M = s1.size();
+ if (N > M)
+ return StringRef::npos;
+ for (size_t i = 0, e = M - N + 1; i != e; ++i)
+ if (s1.substr(i, N).equals_lower(s2))
+ return i;
+ return StringRef::npos;
+}
+
/// getToken - This function extracts one token from source, ignoring any
/// leading characters that appear in the Delimiters string, and ending the
/// token at any of the characters that appear in the Delimiters string. If
/// there are no tokens in the source string, an empty string is returned.
-/// The Source source string is updated in place to remove the returned string
-/// and any delimiter prefix from it.
-std::string llvm::getToken(std::string &Source, const char *Delimiters) {
- size_t NumDelimiters = std::strlen(Delimiters);
-
+/// The function returns a pair containing the extracted token and the
+/// remaining tail string.
+std::pair<StringRef, StringRef> llvm::getToken(StringRef Source,
+ StringRef Delimiters) {
// Figure out where the token starts.
- std::string::size_type Start =
- Source.find_first_not_of(Delimiters, 0, NumDelimiters);
- if (Start == std::string::npos) Start = Source.size();
-
- // Find the next occurance of the delimiter.
- std::string::size_type End =
- Source.find_first_of(Delimiters, Start, NumDelimiters);
- if (End == std::string::npos) End = Source.size();
-
- // Create the return token.
- std::string Result = std::string(Source.begin()+Start, Source.begin()+End);
+ StringRef::size_type Start = Source.find_first_not_of(Delimiters);
+ if (Start == StringRef::npos) Start = Source.size();
- // Erase the token that we read in.
- Source.erase(Source.begin(), Source.begin()+End);
+ // Find the next occurrence of the delimiter.
+ StringRef::size_type End = Source.find_first_of(Delimiters, Start);
+ if (End == StringRef::npos) End = Source.size();
- return Result;
+ return std::make_pair(Source.substr(Start, End), Source.substr(End));
}
/// SplitString - Split up the specified string according to the specified
/// delimiters, appending the result fragments to the output list.
-void llvm::SplitString(const std::string &Source,
- std::vector<std::string> &OutFragments,
- const char *Delimiters) {
- std::string S = Source;
-
- std::string S2 = getToken(S, Delimiters);
+void llvm::SplitString(StringRef Source,
+ SmallVectorImpl<StringRef> &OutFragments,
+ StringRef Delimiters) {
+ StringRef S2, S;
+ tie(S2, S) = getToken(Source, Delimiters);
while (!S2.empty()) {
OutFragments.push_back(S2);
- S2 = getToken(S, Delimiters);
+ tie(S2, S) = getToken(S, Delimiters);
}
}
diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp
index e4a9984..ae2640b 100644
--- a/lib/Support/StringRef.cpp
+++ b/lib/Support/StringRef.cpp
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/SmallVector.h"
+
using namespace llvm;
// MSVC emits references to this into the translation units which reference it.
@@ -51,13 +51,18 @@ unsigned StringRef::edit_distance(llvm::StringRef Other,
size_type m = size();
size_type n = Other.size();
- SmallVector<unsigned, 32> previous(n+1, 0);
- for (SmallVector<unsigned, 32>::size_type i = 0; i <= n; ++i)
+ const unsigned SmallBufferSize = 64;
+ unsigned SmallBuffer[SmallBufferSize];
+ unsigned *Allocated = 0;
+ unsigned *previous = SmallBuffer;
+ if (2*(n + 1) > SmallBufferSize)
+ Allocated = previous = new unsigned [2*(n+1)];
+ unsigned *current = previous + (n + 1);
+
+ for (unsigned i = 0; i <= n; ++i)
previous[i] = i;
- SmallVector<unsigned, 32> current(n+1, 0);
for (size_type y = 1; y <= m; ++y) {
- current.assign(n+1, 0);
current[0] = y;
for (size_type x = 1; x <= n; ++x) {
if (AllowReplacements) {
@@ -69,10 +74,16 @@ unsigned StringRef::edit_distance(llvm::StringRef Other,
else current[x] = min(current[x-1], previous[x]) + 1;
}
}
- current.swap(previous);
+
+ unsigned *tmp = current;
+ current = previous;
+ previous = tmp;
}
- return previous[n];
+ unsigned Result = previous[n];
+ delete [] Allocated;
+
+ return Result;
}
//===----------------------------------------------------------------------===//
diff --git a/lib/Support/Timer.cpp b/lib/Support/Timer.cpp
index 7d32ee6..4bdfac2 100644
--- a/lib/Support/Timer.cpp
+++ b/lib/Support/Timer.cpp
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Support/Debug.h"
#include "llvm/Support/Timer.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
@@ -373,7 +374,7 @@ void TimerGroup::removeTimer() {
TimersToPrint.clear();
- if (OutStream != &errs() && OutStream != &outs())
+ if (OutStream != &errs() && OutStream != &outs() && OutStream != &dbgs())
delete OutStream; // Close the file...
}
}
diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp
index 292c0c2..21504e9 100644
--- a/lib/Support/Twine.cpp
+++ b/lib/Support/Twine.cpp
@@ -9,13 +9,13 @@
#include "llvm/ADT/Twine.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
std::string Twine::str() const {
SmallString<256> Vec;
- toVector(Vec);
- return std::string(Vec.begin(), Vec.end());
+ return toStringRef(Vec).str();
}
void Twine::toVector(SmallVectorImpl<char> &Out) const {
@@ -23,6 +23,13 @@ void Twine::toVector(SmallVectorImpl<char> &Out) const {
print(OS);
}
+StringRef Twine::toStringRef(SmallVectorImpl<char> &Out) const {
+ if (isSingleStringRef())
+ return getSingleStringRef();
+ toVector(Out);
+ return StringRef(Out.data(), Out.size());
+}
+
void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
NodeKind Kind) const {
switch (Kind) {
@@ -125,9 +132,9 @@ void Twine::printRepr(raw_ostream &OS) const {
}
void Twine::dump() const {
- print(llvm::errs());
+ print(llvm::dbgs());
}
void Twine::dumpRepr() const {
- printRepr(llvm::errs());
+ printRepr(llvm::dbgs());
}
OpenPOWER on IntegriCloud