Add SwiftShader dump from Feb 6 2013
diff --git a/src/LLVM/unittests/ADT/APFloatTest.cpp b/src/LLVM/unittests/ADT/APFloatTest.cpp
new file mode 100644
index 0000000..b6e02e3
--- /dev/null
+++ b/src/LLVM/unittests/ADT/APFloatTest.cpp
@@ -0,0 +1,656 @@
+//===- llvm/unittest/ADT/APFloat.cpp - APFloat unit tests ---------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <ostream>
+#include <string>
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+
+using namespace llvm;
+
+static double convertToDoubleFromString(const char *Str) {
+  llvm::APFloat F(0.0);
+  F.convertFromString(Str, llvm::APFloat::rmNearestTiesToEven);
+  return F.convertToDouble();
+}
+
+static std::string convertToString(double d, unsigned Prec, unsigned Pad) {
+  llvm::SmallVector<char, 100> Buffer;
+  llvm::APFloat F(d);
+  F.toString(Buffer, Prec, Pad);
+  return std::string(Buffer.data(), Buffer.size());
+}
+
+namespace {
+
+TEST(APFloatTest, Zero) {
+  EXPECT_EQ(0.0f,  APFloat(0.0f).convertToFloat());
+  EXPECT_EQ(-0.0f, APFloat(-0.0f).convertToFloat());
+  EXPECT_TRUE(APFloat(-0.0f).isNegative());
+
+  EXPECT_EQ(0.0,  APFloat(0.0).convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(-0.0).convertToDouble());
+  EXPECT_TRUE(APFloat(-0.0).isNegative());
+}
+
+TEST(APFloatTest, fromZeroDecimalString) {
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0.").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  ".0").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0.0").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "00000.").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+00000.").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-00000.").convertToDouble());
+
+  EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, ".00000").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.00000").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.00000").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0000.00000").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0000.00000").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0000.00000").convertToDouble());
+}
+
+TEST(APFloatTest, fromZeroDecimalSingleExponentString) {
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,   "0e1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble,  "+0e1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble,  "-0e1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0e+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0e-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e-1").convertToDouble());
+
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,   "0.e1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble,  "+0.e1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble,  "-0.e1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0.e+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0.e-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.e-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.e-1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,   ".0e1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble,  "+.0e1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble,  "-.0e1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  ".0e+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  ".0e-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+.0e-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-.0e-1").convertToDouble());
+
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,   "0.0e1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble,  "+0.0e1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble,  "-0.0e1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0.0e+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0.0e-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0.0e-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0.0e-1").convertToDouble());
+
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "000.0000e1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+000.0000e+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-000.0000e+1").convertToDouble());
+}
+
+TEST(APFloatTest, fromZeroDecimalLargeExponentString) {
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0e1234").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e1234").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e1234").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0e+1234").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e+1234").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e+1234").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0e-1234").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0e-1234").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0e-1234").convertToDouble());
+
+  EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, "000.0000e1234").convertToDouble());
+  EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, "000.0000e-1234").convertToDouble());
+
+  EXPECT_EQ(0.0,  APFloat(APFloat::IEEEdouble, StringRef("0e1234\02", 6)).convertToDouble());
+}
+
+TEST(APFloatTest, fromZeroHexadecimalString) {
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0p1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0p+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0p-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0p-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p-1").convertToDouble());
+
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0.p1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0.p+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0.p-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.p-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.p-1").convertToDouble());
+
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x.0p1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x.0p+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x.0p-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x.0p-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x.0p-1").convertToDouble());
+
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0.0p1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0.0p+1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p+1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p+1").convertToDouble());
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble,  "0x0.0p-1").convertToDouble());
+  EXPECT_EQ(+0.0, APFloat(APFloat::IEEEdouble, "+0x0.0p-1").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0.0p-1").convertToDouble());
+
+
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x00000.p1").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0000.00000p1").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.00000p1").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0p1234").convertToDouble());
+  EXPECT_EQ(-0.0, APFloat(APFloat::IEEEdouble, "-0x0p1234").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x00000.p1234").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0000.00000p1234").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x.00000p1234").convertToDouble());
+  EXPECT_EQ( 0.0, APFloat(APFloat::IEEEdouble, "0x0.p1234").convertToDouble());
+}
+
+TEST(APFloatTest, fromDecimalString) {
+  EXPECT_EQ(1.0,      APFloat(APFloat::IEEEdouble, "1").convertToDouble());
+  EXPECT_EQ(2.0,      APFloat(APFloat::IEEEdouble, "2.").convertToDouble());
+  EXPECT_EQ(0.5,      APFloat(APFloat::IEEEdouble, ".5").convertToDouble());
+  EXPECT_EQ(1.0,      APFloat(APFloat::IEEEdouble, "1.0").convertToDouble());
+  EXPECT_EQ(-2.0,     APFloat(APFloat::IEEEdouble, "-2").convertToDouble());
+  EXPECT_EQ(-4.0,     APFloat(APFloat::IEEEdouble, "-4.").convertToDouble());
+  EXPECT_EQ(-0.5,     APFloat(APFloat::IEEEdouble, "-.5").convertToDouble());
+  EXPECT_EQ(-1.5,     APFloat(APFloat::IEEEdouble, "-1.5").convertToDouble());
+  EXPECT_EQ(1.25e12,  APFloat(APFloat::IEEEdouble, "1.25e12").convertToDouble());
+  EXPECT_EQ(1.25e+12, APFloat(APFloat::IEEEdouble, "1.25e+12").convertToDouble());
+  EXPECT_EQ(1.25e-12, APFloat(APFloat::IEEEdouble, "1.25e-12").convertToDouble());
+  EXPECT_EQ(1024.0,   APFloat(APFloat::IEEEdouble, "1024.").convertToDouble());
+  EXPECT_EQ(1024.05,  APFloat(APFloat::IEEEdouble, "1024.05000").convertToDouble());
+  EXPECT_EQ(0.05,     APFloat(APFloat::IEEEdouble, ".05000").convertToDouble());
+  EXPECT_EQ(2.0,      APFloat(APFloat::IEEEdouble, "2.").convertToDouble());
+  EXPECT_EQ(2.0e2,    APFloat(APFloat::IEEEdouble, "2.e2").convertToDouble());
+  EXPECT_EQ(2.0e+2,   APFloat(APFloat::IEEEdouble, "2.e+2").convertToDouble());
+  EXPECT_EQ(2.0e-2,   APFloat(APFloat::IEEEdouble, "2.e-2").convertToDouble());
+  EXPECT_EQ(2.05e2,    APFloat(APFloat::IEEEdouble, "002.05000e2").convertToDouble());
+  EXPECT_EQ(2.05e+2,   APFloat(APFloat::IEEEdouble, "002.05000e+2").convertToDouble());
+  EXPECT_EQ(2.05e-2,   APFloat(APFloat::IEEEdouble, "002.05000e-2").convertToDouble());
+  EXPECT_EQ(2.05e12,   APFloat(APFloat::IEEEdouble, "002.05000e12").convertToDouble());
+  EXPECT_EQ(2.05e+12,  APFloat(APFloat::IEEEdouble, "002.05000e+12").convertToDouble());
+  EXPECT_EQ(2.05e-12,  APFloat(APFloat::IEEEdouble, "002.05000e-12").convertToDouble());
+
+  // These are "carefully selected" to overflow the fast log-base
+  // calculations in APFloat.cpp
+  EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "99e99999").isInfinity());
+  EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "-99e99999").isInfinity());
+  EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "1e-99999").isPosZero());
+  EXPECT_TRUE(APFloat(APFloat::IEEEdouble, "-1e-99999").isNegZero());
+}
+
+TEST(APFloatTest, fromHexadecimalString) {
+  EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble,  "0x1p0").convertToDouble());
+  EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p0").convertToDouble());
+  EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p0").convertToDouble());
+
+  EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble,  "0x1p+0").convertToDouble());
+  EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p+0").convertToDouble());
+  EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p+0").convertToDouble());
+
+  EXPECT_EQ( 1.0, APFloat(APFloat::IEEEdouble,  "0x1p-0").convertToDouble());
+  EXPECT_EQ(+1.0, APFloat(APFloat::IEEEdouble, "+0x1p-0").convertToDouble());
+  EXPECT_EQ(-1.0, APFloat(APFloat::IEEEdouble, "-0x1p-0").convertToDouble());
+
+
+  EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble,  "0x1p1").convertToDouble());
+  EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble, "+0x1p1").convertToDouble());
+  EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-0x1p1").convertToDouble());
+
+  EXPECT_EQ( 2.0, APFloat(APFloat::IEEEdouble,  "0x1p+1").convertToDouble());
+  EXPECT_EQ(+2.0, APFloat(APFloat::IEEEdouble, "+0x1p+1").convertToDouble());
+  EXPECT_EQ(-2.0, APFloat(APFloat::IEEEdouble, "-0x1p+1").convertToDouble());
+
+  EXPECT_EQ( 0.5, APFloat(APFloat::IEEEdouble,  "0x1p-1").convertToDouble());
+  EXPECT_EQ(+0.5, APFloat(APFloat::IEEEdouble, "+0x1p-1").convertToDouble());
+  EXPECT_EQ(-0.5, APFloat(APFloat::IEEEdouble, "-0x1p-1").convertToDouble());
+
+
+  EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble,  "0x1.8p1").convertToDouble());
+  EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble, "+0x1.8p1").convertToDouble());
+  EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble, "-0x1.8p1").convertToDouble());
+
+  EXPECT_EQ( 3.0, APFloat(APFloat::IEEEdouble,  "0x1.8p+1").convertToDouble());
+  EXPECT_EQ(+3.0, APFloat(APFloat::IEEEdouble, "+0x1.8p+1").convertToDouble());
+  EXPECT_EQ(-3.0, APFloat(APFloat::IEEEdouble, "-0x1.8p+1").convertToDouble());
+
+  EXPECT_EQ( 0.75, APFloat(APFloat::IEEEdouble,  "0x1.8p-1").convertToDouble());
+  EXPECT_EQ(+0.75, APFloat(APFloat::IEEEdouble, "+0x1.8p-1").convertToDouble());
+  EXPECT_EQ(-0.75, APFloat(APFloat::IEEEdouble, "-0x1.8p-1").convertToDouble());
+
+
+  EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble,  "0x1000.000p1").convertToDouble());
+  EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p1").convertToDouble());
+  EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p1").convertToDouble());
+
+  EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble,  "0x1000.000p+1").convertToDouble());
+  EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p+1").convertToDouble());
+  EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p+1").convertToDouble());
+
+  EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble,  "0x1000.000p-1").convertToDouble());
+  EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble, "+0x1000.000p-1").convertToDouble());
+  EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble, "-0x1000.000p-1").convertToDouble());
+
+
+  EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble,  "0x1000p1").convertToDouble());
+  EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000p1").convertToDouble());
+  EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000p1").convertToDouble());
+
+  EXPECT_EQ( 8192.0, APFloat(APFloat::IEEEdouble,  "0x1000p+1").convertToDouble());
+  EXPECT_EQ(+8192.0, APFloat(APFloat::IEEEdouble, "+0x1000p+1").convertToDouble());
+  EXPECT_EQ(-8192.0, APFloat(APFloat::IEEEdouble, "-0x1000p+1").convertToDouble());
+
+  EXPECT_EQ( 2048.0, APFloat(APFloat::IEEEdouble,  "0x1000p-1").convertToDouble());
+  EXPECT_EQ(+2048.0, APFloat(APFloat::IEEEdouble, "+0x1000p-1").convertToDouble());
+  EXPECT_EQ(-2048.0, APFloat(APFloat::IEEEdouble, "-0x1000p-1").convertToDouble());
+
+
+  EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble,  "0x10p10").convertToDouble());
+  EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble, "+0x10p10").convertToDouble());
+  EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble, "-0x10p10").convertToDouble());
+
+  EXPECT_EQ( 16384.0, APFloat(APFloat::IEEEdouble,  "0x10p+10").convertToDouble());
+  EXPECT_EQ(+16384.0, APFloat(APFloat::IEEEdouble, "+0x10p+10").convertToDouble());
+  EXPECT_EQ(-16384.0, APFloat(APFloat::IEEEdouble, "-0x10p+10").convertToDouble());
+
+  EXPECT_EQ( 0.015625, APFloat(APFloat::IEEEdouble,  "0x10p-10").convertToDouble());
+  EXPECT_EQ(+0.015625, APFloat(APFloat::IEEEdouble, "+0x10p-10").convertToDouble());
+  EXPECT_EQ(-0.015625, APFloat(APFloat::IEEEdouble, "-0x10p-10").convertToDouble());
+
+  EXPECT_EQ(1.0625, APFloat(APFloat::IEEEdouble, "0x1.1p0").convertToDouble());
+  EXPECT_EQ(1.0, APFloat(APFloat::IEEEdouble, "0x1p0").convertToDouble());
+
+  EXPECT_EQ(2.71828, convertToDoubleFromString("2.71828"));
+}
+
+TEST(APFloatTest, toString) {
+  ASSERT_EQ("10", convertToString(10.0, 6, 3));
+  ASSERT_EQ("1.0E+1", convertToString(10.0, 6, 0));
+  ASSERT_EQ("10100", convertToString(1.01E+4, 5, 2));
+  ASSERT_EQ("1.01E+4", convertToString(1.01E+4, 4, 2));
+  ASSERT_EQ("1.01E+4", convertToString(1.01E+4, 5, 1));
+  ASSERT_EQ("0.0101", convertToString(1.01E-2, 5, 2));
+  ASSERT_EQ("0.0101", convertToString(1.01E-2, 4, 2));
+  ASSERT_EQ("1.01E-2", convertToString(1.01E-2, 5, 1));
+  ASSERT_EQ("0.7853981633974483", convertToString(0.78539816339744830961, 0, 3));
+  ASSERT_EQ("4.940656458412465E-324", convertToString(4.9406564584124654e-324, 0, 3));
+  ASSERT_EQ("873.1834", convertToString(873.1834, 0, 1));
+  ASSERT_EQ("8.731834E+2", convertToString(873.1834, 0, 0));
+}
+
+TEST(APFloatTest, toInteger) {
+  bool isExact = false;
+  APSInt result(5, /*isUnsigned=*/true);
+
+  EXPECT_EQ(APFloat::opOK,
+            APFloat(APFloat::IEEEdouble, "10")
+            .convertToInteger(result, APFloat::rmTowardZero, &isExact));
+  EXPECT_TRUE(isExact);
+  EXPECT_EQ(APSInt(APInt(5, 10), true), result);
+
+  EXPECT_EQ(APFloat::opInvalidOp,
+            APFloat(APFloat::IEEEdouble, "-10")
+            .convertToInteger(result, APFloat::rmTowardZero, &isExact));
+  EXPECT_FALSE(isExact);
+  EXPECT_EQ(APSInt::getMinValue(5, true), result);
+
+  EXPECT_EQ(APFloat::opInvalidOp,
+            APFloat(APFloat::IEEEdouble, "32")
+            .convertToInteger(result, APFloat::rmTowardZero, &isExact));
+  EXPECT_FALSE(isExact);
+  EXPECT_EQ(APSInt::getMaxValue(5, true), result);
+
+  EXPECT_EQ(APFloat::opInexact,
+            APFloat(APFloat::IEEEdouble, "7.9")
+            .convertToInteger(result, APFloat::rmTowardZero, &isExact));
+  EXPECT_FALSE(isExact);
+  EXPECT_EQ(APSInt(APInt(5, 7), true), result);
+
+  result.setIsUnsigned(false);
+  EXPECT_EQ(APFloat::opOK,
+            APFloat(APFloat::IEEEdouble, "-10")
+            .convertToInteger(result, APFloat::rmTowardZero, &isExact));
+  EXPECT_TRUE(isExact);
+  EXPECT_EQ(APSInt(APInt(5, -10, true), false), result);
+
+  EXPECT_EQ(APFloat::opInvalidOp,
+            APFloat(APFloat::IEEEdouble, "-17")
+            .convertToInteger(result, APFloat::rmTowardZero, &isExact));
+  EXPECT_FALSE(isExact);
+  EXPECT_EQ(APSInt::getMinValue(5, false), result);
+
+  EXPECT_EQ(APFloat::opInvalidOp,
+            APFloat(APFloat::IEEEdouble, "16")
+            .convertToInteger(result, APFloat::rmTowardZero, &isExact));
+  EXPECT_FALSE(isExact);
+  EXPECT_EQ(APSInt::getMaxValue(5, false), result);
+}
+
+static APInt nanbits(const fltSemantics &Sem,
+                     bool SNaN, bool Negative, uint64_t fill) {
+  APInt apfill(64, fill);
+  if (SNaN)
+    return APFloat::getSNaN(Sem, Negative, &apfill).bitcastToAPInt();
+  else
+    return APFloat::getQNaN(Sem, Negative, &apfill).bitcastToAPInt();
+}
+
+TEST(APFloatTest, makeNaN) {
+  ASSERT_EQ(0x7fc00000, nanbits(APFloat::IEEEsingle, false, false, 0));
+  ASSERT_EQ(0xffc00000, nanbits(APFloat::IEEEsingle, false, true, 0));
+  ASSERT_EQ(0x7fc0ae72, nanbits(APFloat::IEEEsingle, false, false, 0xae72));
+  ASSERT_EQ(0x7fffae72, nanbits(APFloat::IEEEsingle, false, false, 0xffffae72));
+  ASSERT_EQ(0x7fa00000, nanbits(APFloat::IEEEsingle, true, false, 0));
+  ASSERT_EQ(0xffa00000, nanbits(APFloat::IEEEsingle, true, true, 0));
+  ASSERT_EQ(0x7f80ae72, nanbits(APFloat::IEEEsingle, true, false, 0xae72));
+  ASSERT_EQ(0x7fbfae72, nanbits(APFloat::IEEEsingle, true, false, 0xffffae72));
+
+  ASSERT_EQ(0x7ff8000000000000ULL, nanbits(APFloat::IEEEdouble, false, false, 0));
+  ASSERT_EQ(0xfff8000000000000ULL, nanbits(APFloat::IEEEdouble, false, true, 0));
+  ASSERT_EQ(0x7ff800000000ae72ULL, nanbits(APFloat::IEEEdouble, false, false, 0xae72));
+  ASSERT_EQ(0x7fffffffffffae72ULL, nanbits(APFloat::IEEEdouble, false, false, 0xffffffffffffae72ULL));
+  ASSERT_EQ(0x7ff4000000000000ULL, nanbits(APFloat::IEEEdouble, true, false, 0));
+  ASSERT_EQ(0xfff4000000000000ULL, nanbits(APFloat::IEEEdouble, true, true, 0));
+  ASSERT_EQ(0x7ff000000000ae72ULL, nanbits(APFloat::IEEEdouble, true, false, 0xae72));
+  ASSERT_EQ(0x7ff7ffffffffae72ULL, nanbits(APFloat::IEEEdouble, true, false, 0xffffffffffffae72ULL));
+}
+
+#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
+TEST(APFloatTest, SemanticsDeath) {
+  EXPECT_DEATH(APFloat(APFloat::IEEEsingle, 0.0f).convertToDouble(), "Float semantics are not IEEEdouble");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, 0.0 ).convertToFloat(),  "Float semantics are not IEEEsingle");
+}
+
+TEST(APFloatTest, StringDecimalDeath) {
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  ""), "Invalid string length");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+"), "String has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-"), "String has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("\0", 1)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\0", 2)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\02", 3)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1\02e1", 5)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e\0", 3)), "Invalid character in exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e1\0", 4)), "Invalid character in exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("1e1\02", 5)), "Invalid character in exponent");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0f"), "Invalid character in significand");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".."), "String contains multiple dots");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "..0"), "String contains multiple dots");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0.0"), "String contains multiple dots");
+}
+
+TEST(APFloatTest, StringDecimalSignificandDeath) {
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "."), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+."), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-."), "Significand has no digits");
+
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "e"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+e"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-e"), "Significand has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "e1"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+e1"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-e1"), "Significand has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  ".e1"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.e1"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.e1"), "Significand has no digits");
+
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  ".e"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+.e"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-.e"), "Significand has no digits");
+}
+
+TEST(APFloatTest, StringDecimalExponentDeath) {
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,   "1e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "+1e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "-1e"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,   "1.e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "+1.e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "-1.e"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,   ".1e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "+.1e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "-.1e"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,   "1.1e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "+1.1e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "-1.1e"), "Exponent has no digits");
+
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1e-"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  ".1e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, ".1e-"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "1.0e"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "1.0e-"), "Exponent has no digits");
+}
+
+TEST(APFloatTest, StringHexadecimalDeath) {
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x"), "Invalid string");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x"), "Invalid string");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x"), "Invalid string");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x0"), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0"), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0"), "Hex strings require an exponent");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x0."), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0."), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0."), "Hex strings require an exponent");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x.0"), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.0"), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.0"), "Hex strings require an exponent");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x0.0"), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x0.0"), "Hex strings require an exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x0.0"), "Hex strings require an exponent");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x\0", 3)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\0", 4)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\02", 5)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1\02p1", 7)), "Invalid character in significand");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p\0", 5)), "Invalid character in exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p1\0", 6)), "Invalid character in exponent");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, StringRef("0x1p1\02", 7)), "Invalid character in exponent");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1p0f"), "Invalid character in exponent");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x..p1"), "String contains multiple dots");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x..0p1"), "String contains multiple dots");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "0x1.0.0p1"), "String contains multiple dots");
+}
+
+TEST(APFloatTest, StringHexadecimalSignificandDeath) {
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x."), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x."), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x."), "Significand has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0xp"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp"), "Significand has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0xp+"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp+"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp+"), "Significand has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0xp-"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0xp-"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0xp-"), "Significand has no digits");
+
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x.p"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p"), "Significand has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x.p+"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p+"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p+"), "Significand has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x.p-"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.p-"), "Significand has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.p-"), "Significand has no digits");
+}
+
+TEST(APFloatTest, StringHexadecimalExponentDeath) {
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p+"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1p-"), "Exponent has no digits");
+
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1.p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1.p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p+"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1.p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.p-"), "Exponent has no digits");
+
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x.1p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x.1p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p+"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x.1p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x.1p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x.1p-"), "Exponent has no digits");
+
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1.1p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1.1p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p+"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p+"), "Exponent has no digits");
+
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble,  "0x1.1p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "+0x1.1p-"), "Exponent has no digits");
+  EXPECT_DEATH(APFloat(APFloat::IEEEdouble, "-0x1.1p-"), "Exponent has no digits");
+}
+#endif
+#endif
+
+TEST(APFloatTest, exactInverse) {
+  APFloat inv(0.0f);
+
+  // Trivial operation.
+  EXPECT_TRUE(APFloat(2.0).getExactInverse(&inv));
+  EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(0.5)));
+  EXPECT_TRUE(APFloat(2.0f).getExactInverse(&inv));
+  EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(0.5f)));
+
+  // FLT_MIN
+  EXPECT_TRUE(APFloat(1.17549435e-38f).getExactInverse(&inv));
+  EXPECT_TRUE(inv.bitwiseIsEqual(APFloat(8.5070592e+37f)));
+
+  // Large float, inverse is a denormal.
+  EXPECT_FALSE(APFloat(1.7014118e38f).getExactInverse(0));
+  // Zero
+  EXPECT_FALSE(APFloat(0.0).getExactInverse(0));
+  // Denormalized float
+  EXPECT_FALSE(APFloat(1.40129846e-45f).getExactInverse(0));
+}
+
+TEST(APFloatTest, getLargest) {
+  EXPECT_EQ(3.402823466e+38f, APFloat::getLargest(APFloat::IEEEsingle).convertToFloat());
+  EXPECT_EQ(1.7976931348623158e+308, APFloat::getLargest(APFloat::IEEEdouble).convertToDouble());
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/APIntTest.cpp b/src/LLVM/unittests/ADT/APIntTest.cpp
new file mode 100644
index 0000000..490811d
--- /dev/null
+++ b/src/LLVM/unittests/ADT/APIntTest.cpp
@@ -0,0 +1,453 @@
+//===- llvm/unittest/ADT/APInt.cpp - APInt unit tests ---------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <ostream>
+#include "gtest/gtest.h"
+#include "llvm/ADT/APInt.h"
+#include "llvm/ADT/SmallString.h"
+
+using namespace llvm;
+
+namespace {
+
+// Test that APInt shift left works when bitwidth > 64 and shiftamt == 0
+TEST(APIntTest, ShiftLeftByZero) {
+  APInt One = APInt::getNullValue(65) + 1;
+  APInt Shl = One.shl(0);
+  EXPECT_TRUE(Shl[0]);
+  EXPECT_FALSE(Shl[1]);
+}
+
+TEST(APIntTest, i128_NegativeCount) {
+  APInt Minus3(128, static_cast<uint64_t>(-3), true);
+  EXPECT_EQ(126u, Minus3.countLeadingOnes());
+  EXPECT_EQ(-3, Minus3.getSExtValue());
+
+  APInt Minus1(128, static_cast<uint64_t>(-1), true);
+  EXPECT_EQ(0u, Minus1.countLeadingZeros());
+  EXPECT_EQ(128u, Minus1.countLeadingOnes());
+  EXPECT_EQ(128u, Minus1.getActiveBits());
+  EXPECT_EQ(0u, Minus1.countTrailingZeros());
+  EXPECT_EQ(128u, Minus1.countTrailingOnes());
+  EXPECT_EQ(128u, Minus1.countPopulation());
+  EXPECT_EQ(-1, Minus1.getSExtValue());
+}
+
+// XFAIL this test on FreeBSD where the system gcc-4.2.1 seems to miscompile it.
+#if defined(__llvm__) || !defined(__FreeBSD__)
+
+TEST(APIntTest, i33_Count) {
+  APInt i33minus2(33, static_cast<uint64_t>(-2), true);
+  EXPECT_EQ(0u, i33minus2.countLeadingZeros());
+  EXPECT_EQ(32u, i33minus2.countLeadingOnes());
+  EXPECT_EQ(33u, i33minus2.getActiveBits());
+  EXPECT_EQ(1u, i33minus2.countTrailingZeros());
+  EXPECT_EQ(32u, i33minus2.countPopulation());
+  EXPECT_EQ(-2, i33minus2.getSExtValue());
+  EXPECT_EQ(((uint64_t)-2)&((1ull<<33) -1), i33minus2.getZExtValue());
+}
+
+#endif
+
+TEST(APIntTest, i65_Count) {
+  APInt i65minus(65, 0, true);
+  i65minus.setBit(64);
+  EXPECT_EQ(0u, i65minus.countLeadingZeros());
+  EXPECT_EQ(1u, i65minus.countLeadingOnes());
+  EXPECT_EQ(65u, i65minus.getActiveBits());
+  EXPECT_EQ(64u, i65minus.countTrailingZeros());
+  EXPECT_EQ(1u, i65minus.countPopulation());
+}
+
+TEST(APIntTest, i128_PositiveCount) {
+  APInt u128max = APInt::getAllOnesValue(128);
+  EXPECT_EQ(128u, u128max.countLeadingOnes());
+  EXPECT_EQ(0u, u128max.countLeadingZeros());
+  EXPECT_EQ(128u, u128max.getActiveBits());
+  EXPECT_EQ(0u, u128max.countTrailingZeros());
+  EXPECT_EQ(128u, u128max.countTrailingOnes());
+  EXPECT_EQ(128u, u128max.countPopulation());
+
+  APInt u64max(128, static_cast<uint64_t>(-1), false);
+  EXPECT_EQ(64u, u64max.countLeadingZeros());
+  EXPECT_EQ(0u, u64max.countLeadingOnes());
+  EXPECT_EQ(64u, u64max.getActiveBits());
+  EXPECT_EQ(0u, u64max.countTrailingZeros());
+  EXPECT_EQ(64u, u64max.countTrailingOnes());
+  EXPECT_EQ(64u, u64max.countPopulation());
+  EXPECT_EQ((uint64_t)~0ull, u64max.getZExtValue());
+
+  APInt zero(128, 0, true);
+  EXPECT_EQ(128u, zero.countLeadingZeros());
+  EXPECT_EQ(0u, zero.countLeadingOnes());
+  EXPECT_EQ(0u, zero.getActiveBits());
+  EXPECT_EQ(128u, zero.countTrailingZeros());
+  EXPECT_EQ(0u, zero.countTrailingOnes());
+  EXPECT_EQ(0u, zero.countPopulation());
+  EXPECT_EQ(0u, zero.getSExtValue());
+  EXPECT_EQ(0u, zero.getZExtValue());
+
+  APInt one(128, 1, true);
+  EXPECT_EQ(127u, one.countLeadingZeros());
+  EXPECT_EQ(0u, one.countLeadingOnes());
+  EXPECT_EQ(1u, one.getActiveBits());
+  EXPECT_EQ(0u, one.countTrailingZeros());
+  EXPECT_EQ(1u, one.countTrailingOnes());
+  EXPECT_EQ(1u, one.countPopulation());
+  EXPECT_EQ(1, one.getSExtValue());
+  EXPECT_EQ(1u, one.getZExtValue());
+}
+
+TEST(APIntTest, i1) {
+  const APInt neg_two(1, static_cast<uint64_t>(-2), true);
+  const APInt neg_one(1, static_cast<uint64_t>(-1), true);
+  const APInt zero(1, 0);
+  const APInt one(1, 1);
+  const APInt two(1, 2);
+
+  EXPECT_EQ(0, neg_two.getSExtValue());
+  EXPECT_EQ(-1, neg_one.getSExtValue());
+  EXPECT_EQ(1u, neg_one.getZExtValue());
+  EXPECT_EQ(0u, zero.getZExtValue());
+  EXPECT_EQ(-1, one.getSExtValue());
+  EXPECT_EQ(1u, one.getZExtValue());
+  EXPECT_EQ(0u, two.getZExtValue());
+  EXPECT_EQ(0, two.getSExtValue());
+
+  // Basic equalities for 1-bit values.
+  EXPECT_EQ(zero, two);
+  EXPECT_EQ(zero, neg_two);
+  EXPECT_EQ(one, neg_one);
+  EXPECT_EQ(two, neg_two);
+
+  // Additions.
+  EXPECT_EQ(two, one + one);
+  EXPECT_EQ(zero, neg_one + one);
+  EXPECT_EQ(neg_two, neg_one + neg_one);
+
+  // Subtractions.
+  EXPECT_EQ(neg_two, neg_one - one);
+  EXPECT_EQ(two, one - neg_one);
+  EXPECT_EQ(zero, one - one);
+
+  // Shifts.
+  EXPECT_EQ(zero, one << one);
+  EXPECT_EQ(one, one << zero);
+  EXPECT_EQ(zero, one.shl(1));
+  EXPECT_EQ(one, one.shl(0));
+  EXPECT_EQ(zero, one.lshr(1));
+  EXPECT_EQ(zero, one.ashr(1));
+
+  // Multiplies.
+  EXPECT_EQ(neg_one, neg_one * one);
+  EXPECT_EQ(neg_one, one * neg_one);
+  EXPECT_EQ(one, neg_one * neg_one);
+  EXPECT_EQ(one, one * one);
+
+  // Divides.
+  EXPECT_EQ(neg_one, one.sdiv(neg_one));
+  EXPECT_EQ(neg_one, neg_one.sdiv(one));
+  EXPECT_EQ(one, neg_one.sdiv(neg_one));
+  EXPECT_EQ(one, one.sdiv(one));
+
+  EXPECT_EQ(neg_one, one.udiv(neg_one));
+  EXPECT_EQ(neg_one, neg_one.udiv(one));
+  EXPECT_EQ(one, neg_one.udiv(neg_one));
+  EXPECT_EQ(one, one.udiv(one));
+
+  // Remainders.
+  EXPECT_EQ(zero, neg_one.srem(one));
+  EXPECT_EQ(zero, neg_one.urem(one));
+  EXPECT_EQ(zero, one.srem(neg_one));
+}
+
+TEST(APIntTest, fromString) {
+  EXPECT_EQ(APInt(32, 0), APInt(32,   "0", 2));
+  EXPECT_EQ(APInt(32, 1), APInt(32,   "1", 2));
+  EXPECT_EQ(APInt(32, 2), APInt(32,  "10", 2));
+  EXPECT_EQ(APInt(32, 3), APInt(32,  "11", 2));
+  EXPECT_EQ(APInt(32, 4), APInt(32, "100", 2));
+
+  EXPECT_EQ(APInt(32, 0), APInt(32,   "+0", 2));
+  EXPECT_EQ(APInt(32, 1), APInt(32,   "+1", 2));
+  EXPECT_EQ(APInt(32, 2), APInt(32,  "+10", 2));
+  EXPECT_EQ(APInt(32, 3), APInt(32,  "+11", 2));
+  EXPECT_EQ(APInt(32, 4), APInt(32, "+100", 2));
+
+  EXPECT_EQ(APInt(32, uint64_t(-0LL)), APInt(32,   "-0", 2));
+  EXPECT_EQ(APInt(32, uint64_t(-1LL)), APInt(32,   "-1", 2));
+  EXPECT_EQ(APInt(32, uint64_t(-2LL)), APInt(32,  "-10", 2));
+  EXPECT_EQ(APInt(32, uint64_t(-3LL)), APInt(32,  "-11", 2));
+  EXPECT_EQ(APInt(32, uint64_t(-4LL)), APInt(32, "-100", 2));
+
+
+  EXPECT_EQ(APInt(32,  0), APInt(32,  "0",  8));
+  EXPECT_EQ(APInt(32,  1), APInt(32,  "1",  8));
+  EXPECT_EQ(APInt(32,  7), APInt(32,  "7",  8));
+  EXPECT_EQ(APInt(32,  8), APInt(32,  "10", 8));
+  EXPECT_EQ(APInt(32, 15), APInt(32,  "17", 8));
+  EXPECT_EQ(APInt(32, 16), APInt(32,  "20", 8));
+
+  EXPECT_EQ(APInt(32,  +0), APInt(32,  "+0",  8));
+  EXPECT_EQ(APInt(32,  +1), APInt(32,  "+1",  8));
+  EXPECT_EQ(APInt(32,  +7), APInt(32,  "+7",  8));
+  EXPECT_EQ(APInt(32,  +8), APInt(32,  "+10", 8));
+  EXPECT_EQ(APInt(32, +15), APInt(32,  "+17", 8));
+  EXPECT_EQ(APInt(32, +16), APInt(32,  "+20", 8));
+
+  EXPECT_EQ(APInt(32,  uint64_t(-0LL)), APInt(32,  "-0",  8));
+  EXPECT_EQ(APInt(32,  uint64_t(-1LL)), APInt(32,  "-1",  8));
+  EXPECT_EQ(APInt(32,  uint64_t(-7LL)), APInt(32,  "-7",  8));
+  EXPECT_EQ(APInt(32,  uint64_t(-8LL)), APInt(32,  "-10", 8));
+  EXPECT_EQ(APInt(32, uint64_t(-15LL)), APInt(32,  "-17", 8));
+  EXPECT_EQ(APInt(32, uint64_t(-16LL)), APInt(32,  "-20", 8));
+
+
+  EXPECT_EQ(APInt(32,  0), APInt(32,  "0", 10));
+  EXPECT_EQ(APInt(32,  1), APInt(32,  "1", 10));
+  EXPECT_EQ(APInt(32,  9), APInt(32,  "9", 10));
+  EXPECT_EQ(APInt(32, 10), APInt(32, "10", 10));
+  EXPECT_EQ(APInt(32, 19), APInt(32, "19", 10));
+  EXPECT_EQ(APInt(32, 20), APInt(32, "20", 10));
+
+  EXPECT_EQ(APInt(32,  uint64_t(-0LL)), APInt(32,  "-0", 10));
+  EXPECT_EQ(APInt(32,  uint64_t(-1LL)), APInt(32,  "-1", 10));
+  EXPECT_EQ(APInt(32,  uint64_t(-9LL)), APInt(32,  "-9", 10));
+  EXPECT_EQ(APInt(32, uint64_t(-10LL)), APInt(32, "-10", 10));
+  EXPECT_EQ(APInt(32, uint64_t(-19LL)), APInt(32, "-19", 10));
+  EXPECT_EQ(APInt(32, uint64_t(-20LL)), APInt(32, "-20", 10));
+
+
+  EXPECT_EQ(APInt(32,  0), APInt(32,  "0", 16));
+  EXPECT_EQ(APInt(32,  1), APInt(32,  "1", 16));
+  EXPECT_EQ(APInt(32, 15), APInt(32,  "F", 16));
+  EXPECT_EQ(APInt(32, 16), APInt(32, "10", 16));
+  EXPECT_EQ(APInt(32, 31), APInt(32, "1F", 16));
+  EXPECT_EQ(APInt(32, 32), APInt(32, "20", 16));
+
+  EXPECT_EQ(APInt(32,  uint64_t(-0LL)), APInt(32,  "-0", 16));
+  EXPECT_EQ(APInt(32,  uint64_t(-1LL)), APInt(32,  "-1", 16));
+  EXPECT_EQ(APInt(32, uint64_t(-15LL)), APInt(32,  "-F", 16));
+  EXPECT_EQ(APInt(32, uint64_t(-16LL)), APInt(32, "-10", 16));
+  EXPECT_EQ(APInt(32, uint64_t(-31LL)), APInt(32, "-1F", 16));
+  EXPECT_EQ(APInt(32, uint64_t(-32LL)), APInt(32, "-20", 16));
+
+  EXPECT_EQ(APInt(32,  0), APInt(32,  "0", 36));
+  EXPECT_EQ(APInt(32,  1), APInt(32,  "1", 36));
+  EXPECT_EQ(APInt(32, 35), APInt(32,  "Z", 36));
+  EXPECT_EQ(APInt(32, 36), APInt(32, "10", 36));
+  EXPECT_EQ(APInt(32, 71), APInt(32, "1Z", 36));
+  EXPECT_EQ(APInt(32, 72), APInt(32, "20", 36));
+  
+  EXPECT_EQ(APInt(32,  uint64_t(-0LL)), APInt(32,  "-0", 36));
+  EXPECT_EQ(APInt(32,  uint64_t(-1LL)), APInt(32,  "-1", 36));
+  EXPECT_EQ(APInt(32, uint64_t(-35LL)), APInt(32,  "-Z", 36));
+  EXPECT_EQ(APInt(32, uint64_t(-36LL)), APInt(32, "-10", 36));
+  EXPECT_EQ(APInt(32, uint64_t(-71LL)), APInt(32, "-1Z", 36));
+  EXPECT_EQ(APInt(32, uint64_t(-72LL)), APInt(32, "-20", 36));
+}
+
+TEST(APIntTest, FromArray) {
+  EXPECT_EQ(APInt(32, uint64_t(1)), APInt(32, ArrayRef<uint64_t>(1)));
+}
+
+TEST(APIntTest, StringBitsNeeded2) {
+  EXPECT_EQ(1U, APInt::getBitsNeeded(  "0", 2));
+  EXPECT_EQ(1U, APInt::getBitsNeeded(  "1", 2));
+  EXPECT_EQ(2U, APInt::getBitsNeeded( "10", 2));
+  EXPECT_EQ(2U, APInt::getBitsNeeded( "11", 2));
+  EXPECT_EQ(3U, APInt::getBitsNeeded("100", 2));
+
+  EXPECT_EQ(1U, APInt::getBitsNeeded(  "+0", 2));
+  EXPECT_EQ(1U, APInt::getBitsNeeded(  "+1", 2));
+  EXPECT_EQ(2U, APInt::getBitsNeeded( "+10", 2));
+  EXPECT_EQ(2U, APInt::getBitsNeeded( "+11", 2));
+  EXPECT_EQ(3U, APInt::getBitsNeeded("+100", 2));
+
+  EXPECT_EQ(2U, APInt::getBitsNeeded(  "-0", 2));
+  EXPECT_EQ(2U, APInt::getBitsNeeded(  "-1", 2));
+  EXPECT_EQ(3U, APInt::getBitsNeeded( "-10", 2));
+  EXPECT_EQ(3U, APInt::getBitsNeeded( "-11", 2));
+  EXPECT_EQ(4U, APInt::getBitsNeeded("-100", 2));
+}
+
+TEST(APIntTest, StringBitsNeeded8) {
+  EXPECT_EQ(3U, APInt::getBitsNeeded( "0", 8));
+  EXPECT_EQ(3U, APInt::getBitsNeeded( "7", 8));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("10", 8));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("17", 8));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("20", 8));
+
+  EXPECT_EQ(3U, APInt::getBitsNeeded( "+0", 8));
+  EXPECT_EQ(3U, APInt::getBitsNeeded( "+7", 8));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("+10", 8));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("+17", 8));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("+20", 8));
+
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "-0", 8));
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "-7", 8));
+  EXPECT_EQ(7U, APInt::getBitsNeeded("-10", 8));
+  EXPECT_EQ(7U, APInt::getBitsNeeded("-17", 8));
+  EXPECT_EQ(7U, APInt::getBitsNeeded("-20", 8));
+}
+
+TEST(APIntTest, StringBitsNeeded10) {
+  EXPECT_EQ(1U, APInt::getBitsNeeded( "0", 10));
+  EXPECT_EQ(2U, APInt::getBitsNeeded( "3", 10));
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "9", 10));
+  EXPECT_EQ(4U, APInt::getBitsNeeded("10", 10));
+  EXPECT_EQ(5U, APInt::getBitsNeeded("19", 10));
+  EXPECT_EQ(5U, APInt::getBitsNeeded("20", 10));
+
+  EXPECT_EQ(1U, APInt::getBitsNeeded( "+0", 10));
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "+9", 10));
+  EXPECT_EQ(4U, APInt::getBitsNeeded("+10", 10));
+  EXPECT_EQ(5U, APInt::getBitsNeeded("+19", 10));
+  EXPECT_EQ(5U, APInt::getBitsNeeded("+20", 10));
+
+  EXPECT_EQ(2U, APInt::getBitsNeeded( "-0", 10));
+  EXPECT_EQ(5U, APInt::getBitsNeeded( "-9", 10));
+  EXPECT_EQ(5U, APInt::getBitsNeeded("-10", 10));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("-19", 10));
+  EXPECT_EQ(6U, APInt::getBitsNeeded("-20", 10));
+}
+
+TEST(APIntTest, StringBitsNeeded16) {
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "0", 16));
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "F", 16));
+  EXPECT_EQ(8U, APInt::getBitsNeeded("10", 16));
+  EXPECT_EQ(8U, APInt::getBitsNeeded("1F", 16));
+  EXPECT_EQ(8U, APInt::getBitsNeeded("20", 16));
+
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "+0", 16));
+  EXPECT_EQ(4U, APInt::getBitsNeeded( "+F", 16));
+  EXPECT_EQ(8U, APInt::getBitsNeeded("+10", 16));
+  EXPECT_EQ(8U, APInt::getBitsNeeded("+1F", 16));
+  EXPECT_EQ(8U, APInt::getBitsNeeded("+20", 16));
+
+  EXPECT_EQ(5U, APInt::getBitsNeeded( "-0", 16));
+  EXPECT_EQ(5U, APInt::getBitsNeeded( "-F", 16));
+  EXPECT_EQ(9U, APInt::getBitsNeeded("-10", 16));
+  EXPECT_EQ(9U, APInt::getBitsNeeded("-1F", 16));
+  EXPECT_EQ(9U, APInt::getBitsNeeded("-20", 16));
+}
+
+TEST(APIntTest, toString) {
+  SmallString<16> S;
+  bool isSigned;
+
+  APInt(8, 0).toString(S, 2, true, true);
+  EXPECT_EQ(S.str().str(), "0b0");
+  S.clear();
+  APInt(8, 0).toString(S, 8, true, true);
+  EXPECT_EQ(S.str().str(), "00");
+  S.clear();
+  APInt(8, 0).toString(S, 10, true, true);
+  EXPECT_EQ(S.str().str(), "0");
+  S.clear();
+  APInt(8, 0).toString(S, 16, true, true);
+  EXPECT_EQ(S.str().str(), "0x0");
+  S.clear();
+  APInt(8, 0).toString(S, 36, true, true);
+  EXPECT_EQ(S.str().str(), "0");
+  S.clear();
+
+  isSigned = false;
+  APInt(8, 255, isSigned).toString(S, 2, isSigned, true);
+  EXPECT_EQ(S.str().str(), "0b11111111");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 8, isSigned, true);
+  EXPECT_EQ(S.str().str(), "0377");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 10, isSigned, true);
+  EXPECT_EQ(S.str().str(), "255");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 16, isSigned, true);
+  EXPECT_EQ(S.str().str(), "0xFF");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 36, isSigned, true);
+  EXPECT_EQ(S.str().str(), "73");
+  S.clear();
+
+  isSigned = true;
+  APInt(8, 255, isSigned).toString(S, 2, isSigned, true);
+  EXPECT_EQ(S.str().str(), "-0b1");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 8, isSigned, true);
+  EXPECT_EQ(S.str().str(), "-01");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 10, isSigned, true);
+  EXPECT_EQ(S.str().str(), "-1");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 16, isSigned, true);
+  EXPECT_EQ(S.str().str(), "-0x1");
+  S.clear();
+  APInt(8, 255, isSigned).toString(S, 36, isSigned, true);
+  EXPECT_EQ(S.str().str(), "-1");
+  S.clear();
+}
+
+TEST(APIntTest, Log2) {
+  EXPECT_EQ(APInt(15, 7).logBase2(), 2U);
+  EXPECT_EQ(APInt(15, 7).ceilLogBase2(), 3U);
+  EXPECT_EQ(APInt(15, 7).exactLogBase2(), -1);
+  EXPECT_EQ(APInt(15, 8).logBase2(), 3U);
+  EXPECT_EQ(APInt(15, 8).ceilLogBase2(), 3U);
+  EXPECT_EQ(APInt(15, 8).exactLogBase2(), 3);
+  EXPECT_EQ(APInt(15, 9).logBase2(), 3U);
+  EXPECT_EQ(APInt(15, 9).ceilLogBase2(), 4U);
+  EXPECT_EQ(APInt(15, 9).exactLogBase2(), -1);
+}
+
+TEST(APIntTest, magic) {
+  EXPECT_EQ(APInt(32, 3).magic().m, APInt(32, "55555556", 16));
+  EXPECT_EQ(APInt(32, 3).magic().s, 0U);
+  EXPECT_EQ(APInt(32, 5).magic().m, APInt(32, "66666667", 16));
+  EXPECT_EQ(APInt(32, 5).magic().s, 1U);
+  EXPECT_EQ(APInt(32, 7).magic().m, APInt(32, "92492493", 16));
+  EXPECT_EQ(APInt(32, 7).magic().s, 2U);
+}
+
+TEST(APIntTest, magicu) {
+  EXPECT_EQ(APInt(32, 3).magicu().m, APInt(32, "AAAAAAAB", 16));
+  EXPECT_EQ(APInt(32, 3).magicu().s, 1U);
+  EXPECT_EQ(APInt(32, 5).magicu().m, APInt(32, "CCCCCCCD", 16));
+  EXPECT_EQ(APInt(32, 5).magicu().s, 2U);
+  EXPECT_EQ(APInt(32, 7).magicu().m, APInt(32, "24924925", 16));
+  EXPECT_EQ(APInt(32, 7).magicu().s, 3U);
+  EXPECT_EQ(APInt(64, 25).magicu(1).m, APInt(64, "A3D70A3D70A3D70B", 16));
+  EXPECT_EQ(APInt(64, 25).magicu(1).s, 4U);
+}
+
+#ifdef GTEST_HAS_DEATH_TEST
+#ifndef NDEBUG
+TEST(APIntTest, StringDeath) {
+  EXPECT_DEATH(APInt(0, "", 0), "Bitwidth too small");
+  EXPECT_DEATH(APInt(32, "", 0), "Invalid string length");
+  EXPECT_DEATH(APInt(32, "0", 0), "Radix should be 2, 8, 10, 16, or 36!");
+  EXPECT_DEATH(APInt(32, "", 10), "Invalid string length");
+  EXPECT_DEATH(APInt(32, "-", 10), "String is only a sign, needs a value.");
+  EXPECT_DEATH(APInt(1, "1234", 10), "Insufficient bit width");
+  EXPECT_DEATH(APInt(32, "\0", 10), "Invalid string length");
+  EXPECT_DEATH(APInt(32, StringRef("1\02", 3), 10), "Invalid character in digit string");
+  EXPECT_DEATH(APInt(32, "1L", 10), "Invalid character in digit string");
+}
+#endif
+#endif
+
+TEST(APIntTest, mul_clear) {
+  APInt ValA(65, -1ULL);
+  APInt ValB(65, 4);
+  APInt ValC(65, 0);
+  ValC = ValA * ValB;
+  ValA *= ValB;
+  EXPECT_EQ(ValA.toString(10, false), ValC.toString(10, false));
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/BitVectorTest.cpp b/src/LLVM/unittests/ADT/BitVectorTest.cpp
new file mode 100644
index 0000000..fa66312
--- /dev/null
+++ b/src/LLVM/unittests/ADT/BitVectorTest.cpp
@@ -0,0 +1,201 @@
+//===- llvm/unittest/ADT/BitVectorTest.cpp - BitVector tests --------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// Some of these tests fail on PowerPC for unknown reasons.
+#ifndef __ppc__
+
+#include "llvm/ADT/BitVector.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(BitVectorTest, TrivialOperation) {
+  BitVector Vec;
+  EXPECT_EQ(0U, Vec.count());
+  EXPECT_EQ(0U, Vec.size());
+  EXPECT_FALSE(Vec.any());
+  EXPECT_TRUE(Vec.all());
+  EXPECT_TRUE(Vec.none());
+  EXPECT_TRUE(Vec.empty());
+
+  Vec.resize(5, true);
+  EXPECT_EQ(5U, Vec.count());
+  EXPECT_EQ(5U, Vec.size());
+  EXPECT_TRUE(Vec.any());
+  EXPECT_TRUE(Vec.all());
+  EXPECT_FALSE(Vec.none());
+  EXPECT_FALSE(Vec.empty());
+
+  Vec.resize(11);
+  EXPECT_EQ(5U, Vec.count());
+  EXPECT_EQ(11U, Vec.size());
+  EXPECT_TRUE(Vec.any());
+  EXPECT_FALSE(Vec.all());
+  EXPECT_FALSE(Vec.none());
+  EXPECT_FALSE(Vec.empty());
+
+  BitVector Inv = ~Vec;
+  EXPECT_EQ(6U, Inv.count());
+  EXPECT_EQ(11U, Inv.size());
+  EXPECT_TRUE(Inv.any());
+  EXPECT_FALSE(Inv.all());
+  EXPECT_FALSE(Inv.none());
+  EXPECT_FALSE(Inv.empty());
+
+  EXPECT_FALSE(Inv == Vec);
+  EXPECT_TRUE(Inv != Vec);
+  Vec = ~Vec;
+  EXPECT_TRUE(Inv == Vec);
+  EXPECT_FALSE(Inv != Vec);
+
+  // Add some "interesting" data to Vec.
+  Vec.resize(23, true);
+  Vec.resize(25, false);
+  Vec.resize(26, true);
+  Vec.resize(29, false);
+  Vec.resize(33, true);
+  Vec.resize(57, false);
+  unsigned Count = 0;
+  for (unsigned i = Vec.find_first(); i != -1u; i = Vec.find_next(i)) {
+    ++Count;
+    EXPECT_TRUE(Vec[i]);
+    EXPECT_TRUE(Vec.test(i));
+  }
+  EXPECT_EQ(Count, Vec.count());
+  EXPECT_EQ(Count, 23u);
+  EXPECT_FALSE(Vec[0]);
+  EXPECT_TRUE(Vec[32]);
+  EXPECT_FALSE(Vec[56]);
+  Vec.resize(61, false);
+
+  BitVector Copy = Vec;
+  BitVector Alt(3, false);
+  Alt.resize(6, true);
+  std::swap(Alt, Vec);
+  EXPECT_TRUE(Copy == Alt);
+  EXPECT_TRUE(Vec.size() == 6);
+  EXPECT_TRUE(Vec.count() == 3);
+  EXPECT_TRUE(Vec.find_first() == 3);
+  std::swap(Copy, Vec);
+
+  // Add some more "interesting" data.
+  Vec.resize(68, true);
+  Vec.resize(78, false);
+  Vec.resize(89, true);
+  Vec.resize(90, false);
+  Vec.resize(91, true);
+  Vec.resize(130, false);
+  Count = 0;
+  for (unsigned i = Vec.find_first(); i != -1u; i = Vec.find_next(i)) {
+    ++Count;
+    EXPECT_TRUE(Vec[i]);
+    EXPECT_TRUE(Vec.test(i));
+  }
+  EXPECT_EQ(Count, Vec.count());
+  EXPECT_EQ(Count, 42u);
+  EXPECT_FALSE(Vec[0]);
+  EXPECT_TRUE(Vec[32]);
+  EXPECT_FALSE(Vec[60]);
+  EXPECT_FALSE(Vec[129]);
+
+  Vec.flip(60);
+  EXPECT_TRUE(Vec[60]);
+  EXPECT_EQ(Count + 1, Vec.count());
+  Vec.flip(60);
+  EXPECT_FALSE(Vec[60]);
+  EXPECT_EQ(Count, Vec.count());
+
+  Vec.reset(32);
+  EXPECT_FALSE(Vec[32]);
+  EXPECT_EQ(Count - 1, Vec.count());
+  Vec.set(32);
+  EXPECT_TRUE(Vec[32]);
+  EXPECT_EQ(Count, Vec.count());
+
+  Vec.flip();
+  EXPECT_EQ(Vec.size() - Count, Vec.count());
+
+  Vec.reset();
+  EXPECT_EQ(0U, Vec.count());
+  EXPECT_EQ(130U, Vec.size());
+  EXPECT_FALSE(Vec.any());
+  EXPECT_FALSE(Vec.all());
+  EXPECT_TRUE(Vec.none());
+  EXPECT_FALSE(Vec.empty());
+
+  Inv = ~BitVector();
+  EXPECT_EQ(0U, Inv.count());
+  EXPECT_EQ(0U, Inv.size());
+  EXPECT_FALSE(Inv.any());
+  EXPECT_TRUE(Inv.all());
+  EXPECT_TRUE(Inv.none());
+  EXPECT_TRUE(Inv.empty());
+
+  Vec.clear();
+  EXPECT_EQ(0U, Vec.count());
+  EXPECT_EQ(0U, Vec.size());
+  EXPECT_FALSE(Vec.any());
+  EXPECT_TRUE(Vec.all());
+  EXPECT_TRUE(Vec.none());
+  EXPECT_TRUE(Vec.empty());
+}
+
+TEST(BitVectorTest, CompoundAssignment) {
+  BitVector A;
+  A.resize(10);
+  A.set(4);
+  A.set(7);
+
+  BitVector B;
+  B.resize(50);
+  B.set(5);
+  B.set(18);
+
+  A |= B;
+  EXPECT_TRUE(A.test(4));
+  EXPECT_TRUE(A.test(5));
+  EXPECT_TRUE(A.test(7));
+  EXPECT_TRUE(A.test(18));
+  EXPECT_EQ(4U, A.count());
+  EXPECT_EQ(50U, A.size());
+
+  B.resize(10);
+  B.set();
+  B.reset(2);
+  B.reset(7);
+  A &= B;
+  EXPECT_FALSE(A.test(2));
+  EXPECT_FALSE(A.test(7));
+  EXPECT_EQ(2U, A.count());
+  EXPECT_EQ(50U, A.size());
+
+  B.resize(100);
+  B.set();
+
+  A ^= B;
+  EXPECT_TRUE(A.test(2));
+  EXPECT_TRUE(A.test(7));
+  EXPECT_EQ(98U, A.count());
+  EXPECT_EQ(100U, A.size());
+}
+
+TEST(BitVectorTest, ProxyIndex) {
+  BitVector Vec(3);
+  EXPECT_TRUE(Vec.none());
+  Vec[0] = Vec[1] = Vec[2] = true;
+  EXPECT_EQ(Vec.size(), Vec.count());
+  Vec[2] = Vec[1] = Vec[0] = false;
+  EXPECT_TRUE(Vec.none());
+}
+
+}
+
+#endif
diff --git a/src/LLVM/unittests/ADT/DAGDeltaAlgorithmTest.cpp b/src/LLVM/unittests/ADT/DAGDeltaAlgorithmTest.cpp
new file mode 100644
index 0000000..370b7c2
--- /dev/null
+++ b/src/LLVM/unittests/ADT/DAGDeltaAlgorithmTest.cpp
@@ -0,0 +1,105 @@
+//===- llvm/unittest/ADT/DAGDeltaAlgorithmTest.cpp ------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/DAGDeltaAlgorithm.h"
+#include <algorithm>
+#include <cstdarg>
+using namespace llvm;
+
+namespace {
+
+typedef DAGDeltaAlgorithm::edge_ty edge_ty;
+
+class FixedDAGDeltaAlgorithm : public DAGDeltaAlgorithm {
+  changeset_ty FailingSet;
+  unsigned NumTests;
+
+protected:
+  virtual bool ExecuteOneTest(const changeset_ty &Changes) {
+    ++NumTests;
+    return std::includes(Changes.begin(), Changes.end(),
+                         FailingSet.begin(), FailingSet.end());
+  }
+
+public:
+  FixedDAGDeltaAlgorithm(const changeset_ty &_FailingSet)
+    : FailingSet(_FailingSet),
+      NumTests(0) {}
+
+  unsigned getNumTests() const { return NumTests; }
+};
+
+std::set<unsigned> fixed_set(unsigned N, ...) {
+  std::set<unsigned> S;
+  va_list ap;
+  va_start(ap, N);
+  for (unsigned i = 0; i != N; ++i)
+    S.insert(va_arg(ap, unsigned));
+  va_end(ap);
+  return S;
+}
+
+std::set<unsigned> range(unsigned Start, unsigned End) {
+  std::set<unsigned> S;
+  while (Start != End)
+    S.insert(Start++);
+  return S;
+}
+
+std::set<unsigned> range(unsigned N) {
+  return range(0, N);
+}
+
+TEST(DAGDeltaAlgorithmTest, Basic) {
+  std::vector<edge_ty> Deps;
+
+  // Dependencies:
+  //  1 - 3
+  Deps.clear();
+  Deps.push_back(std::make_pair(3, 1));
+
+  // P = {3,5,7} \in S,
+  //   [0, 20),
+  // should minimize to {1,3,5,7} in a reasonable number of tests.
+  FixedDAGDeltaAlgorithm FDA(fixed_set(3, 3, 5, 7));
+  EXPECT_EQ(fixed_set(4, 1, 3, 5, 7), FDA.Run(range(20), Deps));
+  EXPECT_GE(46U, FDA.getNumTests());
+
+  // Dependencies:
+  // 0 - 1
+  //  \- 2 - 3
+  //  \- 4
+  Deps.clear();
+  Deps.push_back(std::make_pair(1, 0));
+  Deps.push_back(std::make_pair(2, 0));
+  Deps.push_back(std::make_pair(4, 0));
+  Deps.push_back(std::make_pair(3, 2));
+
+  // This is a case where we must hold required changes.
+  //
+  // P = {1,3} \in S,
+  //   [0, 5),
+  // should minimize to {0,1,2,3} in a small number of tests.
+  FixedDAGDeltaAlgorithm FDA2(fixed_set(2, 1, 3));
+  EXPECT_EQ(fixed_set(4, 0, 1, 2, 3), FDA2.Run(range(5), Deps));
+  EXPECT_GE(9U, FDA2.getNumTests());
+
+  // This is a case where we should quickly prune part of the tree.
+  //
+  // P = {4} \in S,
+  //   [0, 5),
+  // should minimize to {0,4} in a small number of tests.
+  FixedDAGDeltaAlgorithm FDA3(fixed_set(1, 4));
+  EXPECT_EQ(fixed_set(2, 0, 4), FDA3.Run(range(5), Deps));
+  EXPECT_GE(6U, FDA3.getNumTests());
+}
+
+}
+
diff --git a/src/LLVM/unittests/ADT/DeltaAlgorithmTest.cpp b/src/LLVM/unittests/ADT/DeltaAlgorithmTest.cpp
new file mode 100644
index 0000000..a1884cd
--- /dev/null
+++ b/src/LLVM/unittests/ADT/DeltaAlgorithmTest.cpp
@@ -0,0 +1,100 @@
+//===- llvm/unittest/ADT/DeltaAlgorithmTest.cpp ---------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/DeltaAlgorithm.h"
+#include <algorithm>
+#include <cstdarg>
+using namespace llvm;
+
+namespace std {
+
+std::ostream &operator<<(std::ostream &OS,
+                         const std::set<unsigned> &S) {
+  OS << "{";
+  for (std::set<unsigned>::const_iterator it = S.begin(),
+         ie = S.end(); it != ie; ++it) {
+    if (it != S.begin())
+      OS << ",";
+    OS << *it;
+  }
+  OS << "}";
+  return OS;
+}
+
+}
+
+namespace {
+
+class FixedDeltaAlgorithm : public DeltaAlgorithm {
+  changeset_ty FailingSet;
+  unsigned NumTests;
+
+protected:
+  virtual bool ExecuteOneTest(const changeset_ty &Changes) {
+    ++NumTests;
+    return std::includes(Changes.begin(), Changes.end(),
+                         FailingSet.begin(), FailingSet.end());
+  }
+
+public:
+  FixedDeltaAlgorithm(const changeset_ty &_FailingSet)
+    : FailingSet(_FailingSet),
+      NumTests(0) {}
+
+  unsigned getNumTests() const { return NumTests; }
+};
+
+std::set<unsigned> fixed_set(unsigned N, ...) {
+  std::set<unsigned> S;
+  va_list ap;
+  va_start(ap, N);
+  for (unsigned i = 0; i != N; ++i)
+    S.insert(va_arg(ap, unsigned));
+  va_end(ap);
+  return S;
+}
+
+std::set<unsigned> range(unsigned Start, unsigned End) {
+  std::set<unsigned> S;
+  while (Start != End)
+    S.insert(Start++);
+  return S;
+}
+
+std::set<unsigned> range(unsigned N) {
+  return range(0, N);
+}
+
+TEST(DeltaAlgorithmTest, Basic) {
+  // P = {3,5,7} \in S
+  //   [0, 20) should minimize to {3,5,7} in a reasonable number of tests.
+  std::set<unsigned> Fails = fixed_set(3, 3, 5, 7);
+  FixedDeltaAlgorithm FDA(Fails);
+  EXPECT_EQ(fixed_set(3, 3, 5, 7), FDA.Run(range(20)));
+  EXPECT_GE(33U, FDA.getNumTests());
+
+  // P = {3,5,7} \in S
+  //   [10, 20) should minimize to [10,20)
+  EXPECT_EQ(range(10,20), FDA.Run(range(10,20)));
+
+  // P = [0,4) \in S
+  //   [0, 4) should minimize to [0,4) in 11 tests.
+  //
+  // 11 = |{ {},
+  //         {0}, {1}, {2}, {3},
+  //         {1, 2, 3}, {0, 2, 3}, {0, 1, 3}, {0, 1, 2}, 
+  //         {0, 1}, {2, 3} }|
+  FDA = FixedDeltaAlgorithm(range(10));
+  EXPECT_EQ(range(4), FDA.Run(range(4)));
+  EXPECT_EQ(11U, FDA.getNumTests());  
+}
+
+}
+
diff --git a/src/LLVM/unittests/ADT/DenseMapTest.cpp b/src/LLVM/unittests/ADT/DenseMapTest.cpp
new file mode 100644
index 0000000..afac651
--- /dev/null
+++ b/src/LLVM/unittests/ADT/DenseMapTest.cpp
@@ -0,0 +1,179 @@
+//===- llvm/unittest/ADT/DenseMapMap.cpp - DenseMap unit tests --*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/DenseMap.h"
+
+using namespace llvm;
+
+namespace {
+
+// Test fixture
+class DenseMapTest : public testing::Test {
+protected:
+  DenseMap<uint32_t, uint32_t> uintMap;
+  DenseMap<uint32_t *, uint32_t *> uintPtrMap;
+  uint32_t dummyInt;
+};
+
+// Empty map tests
+TEST_F(DenseMapTest, EmptyIntMapTest) {
+  // Size tests
+  EXPECT_EQ(0u, uintMap.size());
+  EXPECT_TRUE(uintMap.empty());
+
+  // Iterator tests
+  EXPECT_TRUE(uintMap.begin() == uintMap.end());
+
+  // Lookup tests
+  EXPECT_FALSE(uintMap.count(0u));
+  EXPECT_TRUE(uintMap.find(0u) == uintMap.end());
+  EXPECT_EQ(0u, uintMap.lookup(0u));
+}
+
+// Empty map tests for pointer map
+TEST_F(DenseMapTest, EmptyPtrMapTest) {
+  // Size tests
+  EXPECT_EQ(0u, uintPtrMap.size());
+  EXPECT_TRUE(uintPtrMap.empty());
+
+  // Iterator tests
+  EXPECT_TRUE(uintPtrMap.begin() == uintPtrMap.end());
+
+  // Lookup tests
+  EXPECT_FALSE(uintPtrMap.count(&dummyInt));
+  EXPECT_TRUE(uintPtrMap.find(&dummyInt) == uintPtrMap.begin());
+  EXPECT_EQ(0, uintPtrMap.lookup(&dummyInt));
+}
+
+// Constant map tests
+TEST_F(DenseMapTest, ConstEmptyMapTest) {
+  const DenseMap<uint32_t, uint32_t> & constUintMap = uintMap;
+  const DenseMap<uint32_t *, uint32_t *> & constUintPtrMap = uintPtrMap;
+  EXPECT_EQ(0u, constUintMap.size());
+  EXPECT_EQ(0u, constUintPtrMap.size());
+  EXPECT_TRUE(constUintMap.empty());
+  EXPECT_TRUE(constUintPtrMap.empty());
+  EXPECT_TRUE(constUintMap.begin() == constUintMap.end());
+  EXPECT_TRUE(constUintPtrMap.begin() == constUintPtrMap.end());
+}
+
+// A map with a single entry
+TEST_F(DenseMapTest, SingleEntryMapTest) {
+  uintMap[0] = 1;
+
+  // Size tests
+  EXPECT_EQ(1u, uintMap.size());
+  EXPECT_FALSE(uintMap.begin() == uintMap.end());
+  EXPECT_FALSE(uintMap.empty());
+
+  // Iterator tests
+  DenseMap<uint32_t, uint32_t>::iterator it = uintMap.begin();
+  EXPECT_EQ(0u, it->first);
+  EXPECT_EQ(1u, it->second);
+  ++it;
+  EXPECT_TRUE(it == uintMap.end());
+
+  // Lookup tests
+  EXPECT_TRUE(uintMap.count(0u));
+  EXPECT_TRUE(uintMap.find(0u) == uintMap.begin());
+  EXPECT_EQ(1u, uintMap.lookup(0u));
+  EXPECT_EQ(1u, uintMap[0]);
+}
+
+// Test clear() method
+TEST_F(DenseMapTest, ClearTest) {
+  uintMap[0] = 1;
+  uintMap.clear();
+
+  EXPECT_EQ(0u, uintMap.size());
+  EXPECT_TRUE(uintMap.empty());
+  EXPECT_TRUE(uintMap.begin() == uintMap.end());
+}
+
+// Test erase(iterator) method
+TEST_F(DenseMapTest, EraseTest) {
+  uintMap[0] = 1;
+  uintMap.erase(uintMap.begin());
+
+  EXPECT_EQ(0u, uintMap.size());
+  EXPECT_TRUE(uintMap.empty());
+  EXPECT_TRUE(uintMap.begin() == uintMap.end());
+}
+
+// Test erase(value) method
+TEST_F(DenseMapTest, EraseTest2) {
+  uintMap[0] = 1;
+  uintMap.erase(0);
+
+  EXPECT_EQ(0u, uintMap.size());
+  EXPECT_TRUE(uintMap.empty());
+  EXPECT_TRUE(uintMap.begin() == uintMap.end());
+}
+
+// Test insert() method
+TEST_F(DenseMapTest, InsertTest) {
+  uintMap.insert(std::make_pair(0u, 1u));
+  EXPECT_EQ(1u, uintMap.size());
+  EXPECT_EQ(1u, uintMap[0]);
+}
+
+// Test copy constructor method
+TEST_F(DenseMapTest, CopyConstructorTest) {
+  uintMap[0] = 1;
+  DenseMap<uint32_t, uint32_t> copyMap(uintMap);
+
+  EXPECT_EQ(1u, copyMap.size());
+  EXPECT_EQ(1u, copyMap[0]);
+}
+
+// Test assignment operator method
+TEST_F(DenseMapTest, AssignmentTest) {
+  uintMap[0] = 1;
+  DenseMap<uint32_t, uint32_t> copyMap = uintMap;
+
+  EXPECT_EQ(1u, copyMap.size());
+  EXPECT_EQ(1u, copyMap[0]);
+}
+
+// A more complex iteration test
+TEST_F(DenseMapTest, IterationTest) {
+  bool visited[100];
+
+  // Insert 100 numbers into the map
+  for (int i = 0; i < 100; ++i) {
+    visited[i] = false;
+    uintMap[i] = 3;
+  }
+
+  // Iterate over all numbers and mark each one found.
+  for (DenseMap<uint32_t, uint32_t>::iterator it = uintMap.begin();
+      it != uintMap.end(); ++it) {
+    visited[it->first] = true;
+  }
+
+  // Ensure every number was visited.
+  for (int i = 0; i < 100; ++i) {
+    ASSERT_TRUE(visited[i]) << "Entry #" << i << " was never visited";
+  }
+}
+
+// const_iterator test
+TEST_F(DenseMapTest, ConstIteratorTest) {
+  // Check conversion from iterator to const_iterator.
+  DenseMap<uint32_t, uint32_t>::iterator it = uintMap.begin();
+  DenseMap<uint32_t, uint32_t>::const_iterator cit(it);
+  EXPECT_TRUE(it == cit);
+
+  // Check copying of const_iterators.
+  DenseMap<uint32_t, uint32_t>::const_iterator cit2(cit);
+  EXPECT_TRUE(cit == cit2);
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/DenseSetTest.cpp b/src/LLVM/unittests/ADT/DenseSetTest.cpp
new file mode 100644
index 0000000..7a35f52
--- /dev/null
+++ b/src/LLVM/unittests/ADT/DenseSetTest.cpp
@@ -0,0 +1,30 @@
+//===- llvm/unittest/ADT/DenseSetTest.cpp - DenseSet unit tests --*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include <llvm/ADT/DenseSet.h>
+
+using namespace llvm;
+
+namespace {
+
+// Test fixture
+class DenseSetTest : public testing::Test {
+};
+
+// Test hashing with a set of only two entries.
+TEST_F(DenseSetTest, DoubleEntrySetTest) {
+  llvm::DenseSet<unsigned> set(2);
+  set.insert(0);
+  set.insert(1);
+  // Original failure was an infinite loop in this call:
+  EXPECT_EQ(0, set.count(2));
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/FoldingSet.cpp b/src/LLVM/unittests/ADT/FoldingSet.cpp
new file mode 100644
index 0000000..a18a0df
--- /dev/null
+++ b/src/LLVM/unittests/ADT/FoldingSet.cpp
@@ -0,0 +1,39 @@
+//===- llvm/unittest/ADT/FoldingSetTest.cpp -------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// FoldingSet unit tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/FoldingSet.h"
+#include <string>
+
+using namespace llvm;
+
+namespace {
+
+// Unaligned string test.
+TEST(FoldingSetTest, UnalignedStringTest) {
+  SCOPED_TRACE("UnalignedStringTest");
+
+  FoldingSetNodeID a, b;
+  // An aligned string
+  std::string str1= "a test string";
+  a.AddString(str1);
+
+  // An unaligned string
+  std::string str2 = ">" + str1;
+  b.AddString(str2.c_str() + 1);
+
+  EXPECT_EQ(a.ComputeHash(), b.ComputeHash());
+}
+
+}
+
diff --git a/src/LLVM/unittests/ADT/ImmutableSetTest.cpp b/src/LLVM/unittests/ADT/ImmutableSetTest.cpp
new file mode 100644
index 0000000..febd441
--- /dev/null
+++ b/src/LLVM/unittests/ADT/ImmutableSetTest.cpp
@@ -0,0 +1,201 @@
+//===----------- ImmutableSetTest.cpp - ImmutableSet unit tests ------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/ImmutableSet.h"
+
+using namespace llvm;
+
+namespace {
+class ImmutableSetTest : public testing::Test {
+protected:
+  // for callback tests
+  static char buffer[10];
+
+  struct MyIter {
+    int counter;
+    char *ptr;
+
+    MyIter() : counter(0), ptr(buffer) {
+      for (unsigned i=0; i<sizeof(buffer);++i) buffer[i]='\0';
+    }
+    void operator()(char c) {
+      *ptr++ = c;
+      ++counter;
+    }
+  };
+};
+char ImmutableSetTest::buffer[10];
+
+
+TEST_F(ImmutableSetTest, EmptyIntSetTest) {
+  ImmutableSet<int>::Factory f;
+
+  EXPECT_TRUE(f.getEmptySet() == f.getEmptySet());
+  EXPECT_FALSE(f.getEmptySet() != f.getEmptySet());
+  EXPECT_TRUE(f.getEmptySet().isEmpty());
+
+  ImmutableSet<int> S = f.getEmptySet();
+  EXPECT_EQ(0u, S.getHeight());
+  EXPECT_TRUE(S.begin() == S.end());
+  EXPECT_FALSE(S.begin() != S.end());
+}
+
+
+TEST_F(ImmutableSetTest, OneElemIntSetTest) {
+  ImmutableSet<int>::Factory f;
+  ImmutableSet<int> S = f.getEmptySet();
+
+  ImmutableSet<int> S2 = f.add(S, 3);
+  EXPECT_TRUE(S.isEmpty());
+  EXPECT_FALSE(S2.isEmpty());
+  EXPECT_FALSE(S == S2);
+  EXPECT_TRUE(S != S2);
+  EXPECT_FALSE(S.contains(3));
+  EXPECT_TRUE(S2.contains(3));
+  EXPECT_FALSE(S2.begin() == S2.end());
+  EXPECT_TRUE(S2.begin() != S2.end());
+
+  ImmutableSet<int> S3 = f.add(S, 2);
+  EXPECT_TRUE(S.isEmpty());
+  EXPECT_FALSE(S3.isEmpty());
+  EXPECT_FALSE(S == S3);
+  EXPECT_TRUE(S != S3);
+  EXPECT_FALSE(S.contains(2));
+  EXPECT_TRUE(S3.contains(2));
+
+  EXPECT_FALSE(S2 == S3);
+  EXPECT_TRUE(S2 != S3);
+  EXPECT_FALSE(S2.contains(2));
+  EXPECT_FALSE(S3.contains(3));
+}
+
+TEST_F(ImmutableSetTest, MultiElemIntSetTest) {
+  ImmutableSet<int>::Factory f;
+  ImmutableSet<int> S = f.getEmptySet();
+
+  ImmutableSet<int> S2 = f.add(f.add(f.add(S, 3), 4), 5);
+  ImmutableSet<int> S3 = f.add(f.add(f.add(S2, 9), 20), 43);
+  ImmutableSet<int> S4 = f.add(S2, 9);
+
+  EXPECT_TRUE(S.isEmpty());
+  EXPECT_FALSE(S2.isEmpty());
+  EXPECT_FALSE(S3.isEmpty());
+  EXPECT_FALSE(S4.isEmpty());
+
+  EXPECT_FALSE(S.contains(3));
+  EXPECT_FALSE(S.contains(9));
+
+  EXPECT_TRUE(S2.contains(3));
+  EXPECT_TRUE(S2.contains(4));
+  EXPECT_TRUE(S2.contains(5));
+  EXPECT_FALSE(S2.contains(9));
+  EXPECT_FALSE(S2.contains(0));
+
+  EXPECT_TRUE(S3.contains(43));
+  EXPECT_TRUE(S3.contains(20));
+  EXPECT_TRUE(S3.contains(9));
+  EXPECT_TRUE(S3.contains(3));
+  EXPECT_TRUE(S3.contains(4));
+  EXPECT_TRUE(S3.contains(5));
+  EXPECT_FALSE(S3.contains(0));
+
+  EXPECT_TRUE(S4.contains(9));
+  EXPECT_TRUE(S4.contains(3));
+  EXPECT_TRUE(S4.contains(4));
+  EXPECT_TRUE(S4.contains(5));
+  EXPECT_FALSE(S4.contains(20));
+  EXPECT_FALSE(S4.contains(43));
+}
+
+TEST_F(ImmutableSetTest, RemoveIntSetTest) {
+  ImmutableSet<int>::Factory f;
+  ImmutableSet<int> S = f.getEmptySet();
+
+  ImmutableSet<int> S2 = f.add(f.add(S, 4), 5);
+  ImmutableSet<int> S3 = f.add(S2, 3);
+  ImmutableSet<int> S4 = f.remove(S3, 3);
+
+  EXPECT_TRUE(S3.contains(3));
+  EXPECT_FALSE(S2.contains(3));
+  EXPECT_FALSE(S4.contains(3));
+
+  EXPECT_TRUE(S2 == S4);
+  EXPECT_TRUE(S3 != S2);
+  EXPECT_TRUE(S3 != S4);
+
+  EXPECT_TRUE(S3.contains(4));
+  EXPECT_TRUE(S3.contains(5));
+
+  EXPECT_TRUE(S4.contains(4));
+  EXPECT_TRUE(S4.contains(5));
+}
+
+TEST_F(ImmutableSetTest, CallbackCharSetTest) {
+  ImmutableSet<char>::Factory f;
+  ImmutableSet<char> S = f.getEmptySet();
+
+  ImmutableSet<char> S2 = f.add(f.add(f.add(S, 'a'), 'e'), 'i');
+  ImmutableSet<char> S3 = f.add(f.add(S2, 'o'), 'u');
+
+  S3.foreach<MyIter>();
+
+  ASSERT_STREQ("aeiou", buffer);
+}
+
+TEST_F(ImmutableSetTest, Callback2CharSetTest) {
+  ImmutableSet<char>::Factory f;
+  ImmutableSet<char> S = f.getEmptySet();
+
+  ImmutableSet<char> S2 = f.add(f.add(f.add(S, 'b'), 'c'), 'd');
+  ImmutableSet<char> S3 = f.add(f.add(f.add(S2, 'f'), 'g'), 'h');
+
+  MyIter obj;
+  S3.foreach<MyIter>(obj);
+  ASSERT_STREQ("bcdfgh", buffer);
+  ASSERT_EQ(6, obj.counter);
+
+  MyIter obj2;
+  S2.foreach<MyIter>(obj2);
+  ASSERT_STREQ("bcd", buffer);
+  ASSERT_EQ(3, obj2.counter);
+
+  MyIter obj3;
+  S.foreach<MyIter>(obj);
+  ASSERT_STREQ("", buffer);
+  ASSERT_EQ(0, obj3.counter);
+}
+
+TEST_F(ImmutableSetTest, IterLongSetTest) {
+  ImmutableSet<long>::Factory f;
+  ImmutableSet<long> S = f.getEmptySet();
+
+  ImmutableSet<long> S2 = f.add(f.add(f.add(S, 0), 1), 2);
+  ImmutableSet<long> S3 = f.add(f.add(f.add(S2, 3), 4), 5);
+
+  int i = 0;
+  for (ImmutableSet<long>::iterator I = S.begin(), E = S.end(); I != E; ++I) {
+    ASSERT_EQ(i++, *I);
+  }
+  ASSERT_EQ(0, i);
+
+  i = 0;
+  for (ImmutableSet<long>::iterator I = S2.begin(), E = S2.end(); I != E; ++I) {
+    ASSERT_EQ(i++, *I);
+  }
+  ASSERT_EQ(3, i);
+
+  i = 0;
+  for (ImmutableSet<long>::iterator I = S3.begin(), E = S3.end(); I != E; I++) {
+    ASSERT_EQ(i++, *I);
+  }
+  ASSERT_EQ(6, i);
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/IntEqClassesTest.cpp b/src/LLVM/unittests/ADT/IntEqClassesTest.cpp
new file mode 100644
index 0000000..fc908c1
--- /dev/null
+++ b/src/LLVM/unittests/ADT/IntEqClassesTest.cpp
@@ -0,0 +1,107 @@
+//===---- ADT/IntEqClassesTest.cpp - IntEqClasses unit tests ----*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/IntEqClasses.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(IntEqClasses, Simple) {
+  IntEqClasses ec(10);
+
+  ec.join(0, 1);
+  ec.join(3, 2);
+  ec.join(4, 5);
+  ec.join(7, 6);
+
+  EXPECT_EQ(0u, ec.findLeader(0));
+  EXPECT_EQ(0u, ec.findLeader(1));
+  EXPECT_EQ(2u, ec.findLeader(2));
+  EXPECT_EQ(2u, ec.findLeader(3));
+  EXPECT_EQ(4u, ec.findLeader(4));
+  EXPECT_EQ(4u, ec.findLeader(5));
+  EXPECT_EQ(6u, ec.findLeader(6));
+  EXPECT_EQ(6u, ec.findLeader(7));
+  EXPECT_EQ(8u, ec.findLeader(8));
+  EXPECT_EQ(9u, ec.findLeader(9));
+
+  // join two non-leaders.
+  ec.join(1, 3);
+
+  EXPECT_EQ(0u, ec.findLeader(0));
+  EXPECT_EQ(0u, ec.findLeader(1));
+  EXPECT_EQ(0u, ec.findLeader(2));
+  EXPECT_EQ(0u, ec.findLeader(3));
+  EXPECT_EQ(4u, ec.findLeader(4));
+  EXPECT_EQ(4u, ec.findLeader(5));
+  EXPECT_EQ(6u, ec.findLeader(6));
+  EXPECT_EQ(6u, ec.findLeader(7));
+  EXPECT_EQ(8u, ec.findLeader(8));
+  EXPECT_EQ(9u, ec.findLeader(9));
+
+  // join two leaders.
+  ec.join(4, 8);
+
+  EXPECT_EQ(0u, ec.findLeader(0));
+  EXPECT_EQ(0u, ec.findLeader(1));
+  EXPECT_EQ(0u, ec.findLeader(2));
+  EXPECT_EQ(0u, ec.findLeader(3));
+  EXPECT_EQ(4u, ec.findLeader(4));
+  EXPECT_EQ(4u, ec.findLeader(5));
+  EXPECT_EQ(6u, ec.findLeader(6));
+  EXPECT_EQ(6u, ec.findLeader(7));
+  EXPECT_EQ(4u, ec.findLeader(8));
+  EXPECT_EQ(9u, ec.findLeader(9));
+
+  // join mixed.
+  ec.join(9, 1);
+
+  EXPECT_EQ(0u, ec.findLeader(0));
+  EXPECT_EQ(0u, ec.findLeader(1));
+  EXPECT_EQ(0u, ec.findLeader(2));
+  EXPECT_EQ(0u, ec.findLeader(3));
+  EXPECT_EQ(4u, ec.findLeader(4));
+  EXPECT_EQ(4u, ec.findLeader(5));
+  EXPECT_EQ(6u, ec.findLeader(6));
+  EXPECT_EQ(6u, ec.findLeader(7));
+  EXPECT_EQ(4u, ec.findLeader(8));
+  EXPECT_EQ(0u, ec.findLeader(9));
+
+  // compressed map.
+  ec.compress();
+  EXPECT_EQ(3u, ec.getNumClasses());
+
+  EXPECT_EQ(0u, ec[0]);
+  EXPECT_EQ(0u, ec[1]);
+  EXPECT_EQ(0u, ec[2]);
+  EXPECT_EQ(0u, ec[3]);
+  EXPECT_EQ(1u, ec[4]);
+  EXPECT_EQ(1u, ec[5]);
+  EXPECT_EQ(2u, ec[6]);
+  EXPECT_EQ(2u, ec[7]);
+  EXPECT_EQ(1u, ec[8]);
+  EXPECT_EQ(0u, ec[9]);
+
+  // uncompressed map.
+  ec.uncompress();
+  EXPECT_EQ(0u, ec.findLeader(0));
+  EXPECT_EQ(0u, ec.findLeader(1));
+  EXPECT_EQ(0u, ec.findLeader(2));
+  EXPECT_EQ(0u, ec.findLeader(3));
+  EXPECT_EQ(4u, ec.findLeader(4));
+  EXPECT_EQ(4u, ec.findLeader(5));
+  EXPECT_EQ(6u, ec.findLeader(6));
+  EXPECT_EQ(6u, ec.findLeader(7));
+  EXPECT_EQ(4u, ec.findLeader(8));
+  EXPECT_EQ(0u, ec.findLeader(9));
+}
+
+} // end anonymous namespace
diff --git a/src/LLVM/unittests/ADT/IntervalMapTest.cpp b/src/LLVM/unittests/ADT/IntervalMapTest.cpp
new file mode 100644
index 0000000..b5556d2
--- /dev/null
+++ b/src/LLVM/unittests/ADT/IntervalMapTest.cpp
@@ -0,0 +1,716 @@
+//===---- ADT/IntervalMapTest.cpp - IntervalMap unit tests ------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/IntervalMap.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+typedef IntervalMap<unsigned, unsigned, 4> UUMap;
+
+// Empty map tests
+TEST(IntervalMapTest, EmptyMap) {
+  UUMap::Allocator allocator;
+  UUMap map(allocator);
+  EXPECT_TRUE(map.empty());
+
+  // Lookup on empty map.
+  EXPECT_EQ(0u, map.lookup(0));
+  EXPECT_EQ(7u, map.lookup(0, 7));
+  EXPECT_EQ(0u, map.lookup(~0u-1));
+  EXPECT_EQ(7u, map.lookup(~0u-1, 7));
+
+  // Iterators.
+  EXPECT_TRUE(map.begin() == map.begin());
+  EXPECT_TRUE(map.begin() == map.end());
+  EXPECT_TRUE(map.end() == map.end());
+  EXPECT_FALSE(map.begin() != map.begin());
+  EXPECT_FALSE(map.begin() != map.end());
+  EXPECT_FALSE(map.end() != map.end());
+  EXPECT_FALSE(map.begin().valid());
+  EXPECT_FALSE(map.end().valid());
+  UUMap::iterator I = map.begin();
+  EXPECT_FALSE(I.valid());
+  EXPECT_TRUE(I == map.end());
+
+  // Default constructor and cross-constness compares.
+  UUMap::const_iterator CI;
+  CI = map.begin();
+  EXPECT_TRUE(CI == I);
+  UUMap::iterator I2;
+  I2 = map.end();
+  EXPECT_TRUE(I2 == CI);
+}
+
+// Single entry map tests
+TEST(IntervalMapTest, SingleEntryMap) {
+  UUMap::Allocator allocator;
+  UUMap map(allocator);
+  map.insert(100, 150, 1);
+  EXPECT_FALSE(map.empty());
+
+  // Lookup around interval.
+  EXPECT_EQ(0u, map.lookup(0));
+  EXPECT_EQ(0u, map.lookup(99));
+  EXPECT_EQ(1u, map.lookup(100));
+  EXPECT_EQ(1u, map.lookup(101));
+  EXPECT_EQ(1u, map.lookup(125));
+  EXPECT_EQ(1u, map.lookup(149));
+  EXPECT_EQ(1u, map.lookup(150));
+  EXPECT_EQ(0u, map.lookup(151));
+  EXPECT_EQ(0u, map.lookup(200));
+  EXPECT_EQ(0u, map.lookup(~0u-1));
+
+  // Iterators.
+  EXPECT_TRUE(map.begin() == map.begin());
+  EXPECT_FALSE(map.begin() == map.end());
+  EXPECT_TRUE(map.end() == map.end());
+  EXPECT_TRUE(map.begin().valid());
+  EXPECT_FALSE(map.end().valid());
+
+  // Iter deref.
+  UUMap::iterator I = map.begin();
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(100u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  EXPECT_EQ(1u, I.value());
+
+  // Preincrement.
+  ++I;
+  EXPECT_FALSE(I.valid());
+  EXPECT_FALSE(I == map.begin());
+  EXPECT_TRUE(I == map.end());
+
+  // PreDecrement.
+  --I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(100u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  EXPECT_EQ(1u, I.value());
+  EXPECT_TRUE(I == map.begin());
+  EXPECT_FALSE(I == map.end());
+
+  // Change the value.
+  I.setValue(2);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(100u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  EXPECT_EQ(2u, I.value());
+
+  // Grow the bounds.
+  I.setStart(0);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(0u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  EXPECT_EQ(2u, I.value());
+
+  I.setStop(200);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(0u, I.start());
+  EXPECT_EQ(200u, I.stop());
+  EXPECT_EQ(2u, I.value());
+
+  // Shrink the bounds.
+  I.setStart(150);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(150u, I.start());
+  EXPECT_EQ(200u, I.stop());
+  EXPECT_EQ(2u, I.value());
+
+  I.setStop(160);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(150u, I.start());
+  EXPECT_EQ(160u, I.stop());
+  EXPECT_EQ(2u, I.value());
+
+  // Erase last elem.
+  I.erase();
+  EXPECT_TRUE(map.empty());
+  EXPECT_EQ(0, std::distance(map.begin(), map.end()));
+}
+
+// Flat coalescing tests.
+TEST(IntervalMapTest, RootCoalescing) {
+  UUMap::Allocator allocator;
+  UUMap map(allocator);
+  map.insert(100, 150, 1);
+
+  // Coalesce from the left.
+  map.insert(90, 99, 1);
+  EXPECT_EQ(1, std::distance(map.begin(), map.end()));
+  EXPECT_EQ(90u, map.start());
+  EXPECT_EQ(150u, map.stop());
+
+  // Coalesce from the right.
+  map.insert(151, 200, 1);
+  EXPECT_EQ(1, std::distance(map.begin(), map.end()));
+  EXPECT_EQ(90u, map.start());
+  EXPECT_EQ(200u, map.stop());
+
+  // Non-coalesce from the left.
+  map.insert(60, 89, 2);
+  EXPECT_EQ(2, std::distance(map.begin(), map.end()));
+  EXPECT_EQ(60u, map.start());
+  EXPECT_EQ(200u, map.stop());
+  EXPECT_EQ(2u, map.lookup(89));
+  EXPECT_EQ(1u, map.lookup(90));
+
+  UUMap::iterator I = map.begin();
+  EXPECT_EQ(60u, I.start());
+  EXPECT_EQ(89u, I.stop());
+  EXPECT_EQ(2u, I.value());
+  ++I;
+  EXPECT_EQ(90u, I.start());
+  EXPECT_EQ(200u, I.stop());
+  EXPECT_EQ(1u, I.value());
+  ++I;
+  EXPECT_FALSE(I.valid());
+
+  // Non-coalesce from the right.
+  map.insert(201, 210, 2);
+  EXPECT_EQ(3, std::distance(map.begin(), map.end()));
+  EXPECT_EQ(60u, map.start());
+  EXPECT_EQ(210u, map.stop());
+  EXPECT_EQ(2u, map.lookup(201));
+  EXPECT_EQ(1u, map.lookup(200));
+
+  // Erase from the left.
+  map.begin().erase();
+  EXPECT_EQ(2, std::distance(map.begin(), map.end()));
+  EXPECT_EQ(90u, map.start());
+  EXPECT_EQ(210u, map.stop());
+
+  // Erase from the right.
+  (--map.end()).erase();
+  EXPECT_EQ(1, std::distance(map.begin(), map.end()));
+  EXPECT_EQ(90u, map.start());
+  EXPECT_EQ(200u, map.stop());
+
+  // Add non-coalescing, then trigger coalescing with setValue.
+  map.insert(80, 89, 2);
+  map.insert(201, 210, 2);
+  EXPECT_EQ(3, std::distance(map.begin(), map.end()));
+  (++map.begin()).setValue(2);
+  EXPECT_EQ(1, std::distance(map.begin(), map.end()));
+  I = map.begin();
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(80u, I.start());
+  EXPECT_EQ(210u, I.stop());
+  EXPECT_EQ(2u, I.value());
+}
+
+// Flat multi-coalescing tests.
+TEST(IntervalMapTest, RootMultiCoalescing) {
+  UUMap::Allocator allocator;
+  UUMap map(allocator);
+  map.insert(140, 150, 1);
+  map.insert(160, 170, 1);
+  map.insert(100, 110, 1);
+  map.insert(120, 130, 1);
+  EXPECT_EQ(4, std::distance(map.begin(), map.end()));
+  EXPECT_EQ(100u, map.start());
+  EXPECT_EQ(170u, map.stop());
+
+  // Verify inserts.
+  UUMap::iterator I = map.begin();
+  EXPECT_EQ(100u, I.start());
+  EXPECT_EQ(110u, I.stop());
+  ++I;
+  EXPECT_EQ(120u, I.start());
+  EXPECT_EQ(130u, I.stop());
+  ++I;
+  EXPECT_EQ(140u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  ++I;
+  EXPECT_EQ(160u, I.start());
+  EXPECT_EQ(170u, I.stop());
+  ++I;
+  EXPECT_FALSE(I.valid());
+
+  // Test advanceTo on flat tree.
+  I = map.begin();
+  I.advanceTo(135);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(140u, I.start());
+  EXPECT_EQ(150u, I.stop());
+
+  I.advanceTo(145);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(140u, I.start());
+  EXPECT_EQ(150u, I.stop());
+
+  I.advanceTo(200);
+  EXPECT_FALSE(I.valid());
+
+  I.advanceTo(300);
+  EXPECT_FALSE(I.valid());
+
+  // Coalesce left with followers.
+  // [100;110] [120;130] [140;150] [160;170]
+  map.insert(111, 115, 1);
+  I = map.begin();
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(100u, I.start());
+  EXPECT_EQ(115u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(120u, I.start());
+  EXPECT_EQ(130u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(140u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(160u, I.start());
+  EXPECT_EQ(170u, I.stop());
+  ++I;
+  EXPECT_FALSE(I.valid());
+
+  // Coalesce right with followers.
+  // [100;115] [120;130] [140;150] [160;170]
+  map.insert(135, 139, 1);
+  I = map.begin();
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(100u, I.start());
+  EXPECT_EQ(115u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(120u, I.start());
+  EXPECT_EQ(130u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(135u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(160u, I.start());
+  EXPECT_EQ(170u, I.stop());
+  ++I;
+  EXPECT_FALSE(I.valid());
+
+  // Coalesce left and right with followers.
+  // [100;115] [120;130] [135;150] [160;170]
+  map.insert(131, 134, 1);
+  I = map.begin();
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(100u, I.start());
+  EXPECT_EQ(115u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(120u, I.start());
+  EXPECT_EQ(150u, I.stop());
+  ++I;
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(160u, I.start());
+  EXPECT_EQ(170u, I.stop());
+  ++I;
+  EXPECT_FALSE(I.valid());
+
+  // Test clear() on non-branched map.
+  map.clear();
+  EXPECT_TRUE(map.empty());
+  EXPECT_TRUE(map.begin() == map.end());
+}
+
+// Branched, non-coalescing tests.
+TEST(IntervalMapTest, Branched) {
+  UUMap::Allocator allocator;
+  UUMap map(allocator);
+
+  // Insert enough intervals to force a branched tree.
+  // This creates 9 leaf nodes with 11 elements each, tree height = 1.
+  for (unsigned i = 1; i < 100; ++i) {
+    map.insert(10*i, 10*i+5, i);
+    EXPECT_EQ(10u, map.start());
+    EXPECT_EQ(10*i+5, map.stop());
+  }
+
+  // Tree limits.
+  EXPECT_FALSE(map.empty());
+  EXPECT_EQ(10u, map.start());
+  EXPECT_EQ(995u, map.stop());
+
+  // Tree lookup.
+  for (unsigned i = 1; i < 100; ++i) {
+    EXPECT_EQ(0u, map.lookup(10*i-1));
+    EXPECT_EQ(i, map.lookup(10*i));
+    EXPECT_EQ(i, map.lookup(10*i+5));
+    EXPECT_EQ(0u, map.lookup(10*i+6));
+  }
+
+  // Forward iteration.
+  UUMap::iterator I = map.begin();
+  for (unsigned i = 1; i < 100; ++i) {
+    ASSERT_TRUE(I.valid());
+    EXPECT_EQ(10*i, I.start());
+    EXPECT_EQ(10*i+5, I.stop());
+    EXPECT_EQ(i, *I);
+    ++I;
+  }
+  EXPECT_FALSE(I.valid());
+  EXPECT_TRUE(I == map.end());
+
+  // Backwards iteration.
+  for (unsigned i = 99; i; --i) {
+    --I;
+    ASSERT_TRUE(I.valid());
+    EXPECT_EQ(10*i, I.start());
+    EXPECT_EQ(10*i+5, I.stop());
+    EXPECT_EQ(i, *I);
+  }
+  EXPECT_TRUE(I == map.begin());
+
+  // Test advanceTo in same node.
+  I.advanceTo(20);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(20u, I.start());
+  EXPECT_EQ(25u, I.stop());
+
+  // Change value, no coalescing.
+  I.setValue(0);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(20u, I.start());
+  EXPECT_EQ(25u, I.stop());
+  EXPECT_EQ(0u, I.value());
+
+  // Close the gap right, no coalescing.
+  I.setStop(29);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(20u, I.start());
+  EXPECT_EQ(29u, I.stop());
+  EXPECT_EQ(0u, I.value());
+
+  // Change value, no coalescing.
+  I.setValue(2);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(20u, I.start());
+  EXPECT_EQ(29u, I.stop());
+  EXPECT_EQ(2u, I.value());
+
+  // Change value, now coalescing.
+  I.setValue(3);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(20u, I.start());
+  EXPECT_EQ(35u, I.stop());
+  EXPECT_EQ(3u, I.value());
+
+  // Close the gap, now coalescing.
+  I.setValue(4);
+  ASSERT_TRUE(I.valid());
+  I.setStop(39);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(20u, I.start());
+  EXPECT_EQ(45u, I.stop());
+  EXPECT_EQ(4u, I.value());
+
+  // advanceTo another node.
+  I.advanceTo(200);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(200u, I.start());
+  EXPECT_EQ(205u, I.stop());
+
+  // Close the gap left, no coalescing.
+  I.setStart(196);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(196u, I.start());
+  EXPECT_EQ(205u, I.stop());
+  EXPECT_EQ(20u, I.value());
+
+  // Change value, no coalescing.
+  I.setValue(0);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(196u, I.start());
+  EXPECT_EQ(205u, I.stop());
+  EXPECT_EQ(0u, I.value());
+
+  // Change value, now coalescing.
+  I.setValue(19);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(190u, I.start());
+  EXPECT_EQ(205u, I.stop());
+  EXPECT_EQ(19u, I.value());
+
+  // Close the gap, now coalescing.
+  I.setValue(18);
+  ASSERT_TRUE(I.valid());
+  I.setStart(186);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(180u, I.start());
+  EXPECT_EQ(205u, I.stop());
+  EXPECT_EQ(18u, I.value());
+
+  // Erase from the front.
+  I = map.begin();
+  for (unsigned i = 0; i != 20; ++i) {
+    I.erase();
+    EXPECT_TRUE(I == map.begin());
+    EXPECT_FALSE(map.empty());
+    EXPECT_EQ(I.start(), map.start());
+    EXPECT_EQ(995u, map.stop());
+  }
+
+  // Test clear() on branched map.
+  map.clear();
+  EXPECT_TRUE(map.empty());
+  EXPECT_TRUE(map.begin() == map.end());
+}
+
+// Branched, high, non-coalescing tests.
+TEST(IntervalMapTest, Branched2) {
+  UUMap::Allocator allocator;
+  UUMap map(allocator);
+
+  // Insert enough intervals to force a height >= 2 tree.
+  for (unsigned i = 1; i < 1000; ++i)
+    map.insert(10*i, 10*i+5, i);
+
+  // Tree limits.
+  EXPECT_FALSE(map.empty());
+  EXPECT_EQ(10u, map.start());
+  EXPECT_EQ(9995u, map.stop());
+
+  // Tree lookup.
+  for (unsigned i = 1; i < 1000; ++i) {
+    EXPECT_EQ(0u, map.lookup(10*i-1));
+    EXPECT_EQ(i, map.lookup(10*i));
+    EXPECT_EQ(i, map.lookup(10*i+5));
+    EXPECT_EQ(0u, map.lookup(10*i+6));
+  }
+
+  // Forward iteration.
+  UUMap::iterator I = map.begin();
+  for (unsigned i = 1; i < 1000; ++i) {
+    ASSERT_TRUE(I.valid());
+    EXPECT_EQ(10*i, I.start());
+    EXPECT_EQ(10*i+5, I.stop());
+    EXPECT_EQ(i, *I);
+    ++I;
+  }
+  EXPECT_FALSE(I.valid());
+  EXPECT_TRUE(I == map.end());
+
+  // Backwards iteration.
+  for (unsigned i = 999; i; --i) {
+    --I;
+    ASSERT_TRUE(I.valid());
+    EXPECT_EQ(10*i, I.start());
+    EXPECT_EQ(10*i+5, I.stop());
+    EXPECT_EQ(i, *I);
+  }
+  EXPECT_TRUE(I == map.begin());
+
+  // Test advanceTo in same node.
+  I.advanceTo(20);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(20u, I.start());
+  EXPECT_EQ(25u, I.stop());
+
+  // advanceTo sibling leaf node.
+  I.advanceTo(200);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(200u, I.start());
+  EXPECT_EQ(205u, I.stop());
+
+  // advanceTo further.
+  I.advanceTo(2000);
+  ASSERT_TRUE(I.valid());
+  EXPECT_EQ(2000u, I.start());
+  EXPECT_EQ(2005u, I.stop());
+
+  // advanceTo beyond end()
+  I.advanceTo(20000);
+  EXPECT_FALSE(I.valid());
+
+  // end().advanceTo() is valid as long as x > map.stop()
+  I.advanceTo(30000);
+  EXPECT_FALSE(I.valid());
+
+  // Test clear() on branched map.
+  map.clear();
+  EXPECT_TRUE(map.empty());
+  EXPECT_TRUE(map.begin() == map.end());
+}
+
+// Random insertions, coalescing to a single interval.
+TEST(IntervalMapTest, RandomCoalescing) {
+  UUMap::Allocator allocator;
+  UUMap map(allocator);
+
+  // This is a poor PRNG with maximal period:
+  // x_n = 5 x_{n-1} + 1 mod 2^N
+
+  unsigned x = 100;
+  for (unsigned i = 0; i != 4096; ++i) {
+    map.insert(10*x, 10*x+9, 1);
+    EXPECT_GE(10*x, map.start());
+    EXPECT_LE(10*x+9, map.stop());
+    x = (5*x+1)%4096;
+  }
+
+  // Map should be fully coalesced after that exercise.
+  EXPECT_FALSE(map.empty());
+  EXPECT_EQ(0u, map.start());
+  EXPECT_EQ(40959u, map.stop());
+  EXPECT_EQ(1, std::distance(map.begin(), map.end()));
+
+}
+
+TEST(IntervalMapOverlapsTest, SmallMaps) {
+  typedef IntervalMapOverlaps<UUMap,UUMap> UUOverlaps;
+  UUMap::Allocator allocator;
+  UUMap mapA(allocator);
+  UUMap mapB(allocator);
+
+  // empty, empty.
+  EXPECT_FALSE(UUOverlaps(mapA, mapB).valid());
+
+  mapA.insert(1, 2, 3);
+
+  // full, empty
+  EXPECT_FALSE(UUOverlaps(mapA, mapB).valid());
+  // empty, full
+  EXPECT_FALSE(UUOverlaps(mapB, mapA).valid());
+
+  mapB.insert(3, 4, 5);
+
+  // full, full, non-overlapping
+  EXPECT_FALSE(UUOverlaps(mapA, mapB).valid());
+  EXPECT_FALSE(UUOverlaps(mapB, mapA).valid());
+
+  // Add an overlapping segment.
+  mapA.insert(4, 5, 6);
+
+  UUOverlaps AB(mapA, mapB);
+  ASSERT_TRUE(AB.valid());
+  EXPECT_EQ(4u, AB.a().start());
+  EXPECT_EQ(3u, AB.b().start());
+  ++AB;
+  EXPECT_FALSE(AB.valid());
+
+  UUOverlaps BA(mapB, mapA);
+  ASSERT_TRUE(BA.valid());
+  EXPECT_EQ(3u, BA.a().start());
+  EXPECT_EQ(4u, BA.b().start());
+  // advance past end.
+  BA.advanceTo(6);
+  EXPECT_FALSE(BA.valid());
+  // advance an invalid iterator.
+  BA.advanceTo(7);
+  EXPECT_FALSE(BA.valid());
+}
+
+TEST(IntervalMapOverlapsTest, BigMaps) {
+  typedef IntervalMapOverlaps<UUMap,UUMap> UUOverlaps;
+  UUMap::Allocator allocator;
+  UUMap mapA(allocator);
+  UUMap mapB(allocator);
+
+  // [0;4] [10;14] [20;24] ...
+  for (unsigned n = 0; n != 100; ++n)
+    mapA.insert(10*n, 10*n+4, n);
+
+  // [5;6] [15;16] [25;26] ...
+  for (unsigned n = 10; n != 20; ++n)
+    mapB.insert(10*n+5, 10*n+6, n);
+
+  // [208;209] [218;219] ...
+  for (unsigned n = 20; n != 30; ++n)
+    mapB.insert(10*n+8, 10*n+9, n);
+
+  // insert some overlapping segments.
+  mapB.insert(400, 400, 400);
+  mapB.insert(401, 401, 401);
+  mapB.insert(402, 500, 402);
+  mapB.insert(600, 601, 402);
+
+  UUOverlaps AB(mapA, mapB);
+  ASSERT_TRUE(AB.valid());
+  EXPECT_EQ(400u, AB.a().start());
+  EXPECT_EQ(400u, AB.b().start());
+  ++AB;
+  ASSERT_TRUE(AB.valid());
+  EXPECT_EQ(400u, AB.a().start());
+  EXPECT_EQ(401u, AB.b().start());
+  ++AB;
+  ASSERT_TRUE(AB.valid());
+  EXPECT_EQ(400u, AB.a().start());
+  EXPECT_EQ(402u, AB.b().start());
+  ++AB;
+  ASSERT_TRUE(AB.valid());
+  EXPECT_EQ(410u, AB.a().start());
+  EXPECT_EQ(402u, AB.b().start());
+  ++AB;
+  ASSERT_TRUE(AB.valid());
+  EXPECT_EQ(420u, AB.a().start());
+  EXPECT_EQ(402u, AB.b().start());
+  AB.skipB();
+  ASSERT_TRUE(AB.valid());
+  EXPECT_EQ(600u, AB.a().start());
+  EXPECT_EQ(600u, AB.b().start());
+  ++AB;
+  EXPECT_FALSE(AB.valid());
+
+  // Test advanceTo.
+  UUOverlaps AB2(mapA, mapB);
+  AB2.advanceTo(410);
+  ASSERT_TRUE(AB2.valid());
+  EXPECT_EQ(410u, AB2.a().start());
+  EXPECT_EQ(402u, AB2.b().start());
+
+  // It is valid to advanceTo with any monotonic sequence.
+  AB2.advanceTo(411);
+  ASSERT_TRUE(AB2.valid());
+  EXPECT_EQ(410u, AB2.a().start());
+  EXPECT_EQ(402u, AB2.b().start());
+
+  // Check reversed maps.
+  UUOverlaps BA(mapB, mapA);
+  ASSERT_TRUE(BA.valid());
+  EXPECT_EQ(400u, BA.b().start());
+  EXPECT_EQ(400u, BA.a().start());
+  ++BA;
+  ASSERT_TRUE(BA.valid());
+  EXPECT_EQ(400u, BA.b().start());
+  EXPECT_EQ(401u, BA.a().start());
+  ++BA;
+  ASSERT_TRUE(BA.valid());
+  EXPECT_EQ(400u, BA.b().start());
+  EXPECT_EQ(402u, BA.a().start());
+  ++BA;
+  ASSERT_TRUE(BA.valid());
+  EXPECT_EQ(410u, BA.b().start());
+  EXPECT_EQ(402u, BA.a().start());
+  ++BA;
+  ASSERT_TRUE(BA.valid());
+  EXPECT_EQ(420u, BA.b().start());
+  EXPECT_EQ(402u, BA.a().start());
+  BA.skipA();
+  ASSERT_TRUE(BA.valid());
+  EXPECT_EQ(600u, BA.b().start());
+  EXPECT_EQ(600u, BA.a().start());
+  ++BA;
+  EXPECT_FALSE(BA.valid());
+
+  // Test advanceTo.
+  UUOverlaps BA2(mapB, mapA);
+  BA2.advanceTo(410);
+  ASSERT_TRUE(BA2.valid());
+  EXPECT_EQ(410u, BA2.b().start());
+  EXPECT_EQ(402u, BA2.a().start());
+
+  BA2.advanceTo(411);
+  ASSERT_TRUE(BA2.valid());
+  EXPECT_EQ(410u, BA2.b().start());
+  EXPECT_EQ(402u, BA2.a().start());
+}
+
+} // namespace
diff --git a/src/LLVM/unittests/ADT/Makefile b/src/LLVM/unittests/ADT/Makefile
new file mode 100644
index 0000000..c255a0b
--- /dev/null
+++ b/src/LLVM/unittests/ADT/Makefile
@@ -0,0 +1,23 @@
+##===- unittests/ADT/Makefile ------------------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+LEVEL = ../..
+TESTNAME = ADT
+LINK_COMPONENTS := support
+
+include $(LEVEL)/Makefile.config
+
+# Xfail BitVectorTest for now on PPC Darwin.  7598360.
+ifeq ($(ARCH),PowerPC)
+ifeq ($(TARGET_OS),Darwin)
+CPP.Flags += -DXFAIL
+endif
+endif
+
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
diff --git a/src/LLVM/unittests/ADT/PackedVectorTest.cpp b/src/LLVM/unittests/ADT/PackedVectorTest.cpp
new file mode 100644
index 0000000..55b5d8d
--- /dev/null
+++ b/src/LLVM/unittests/ADT/PackedVectorTest.cpp
@@ -0,0 +1,115 @@
+//===- llvm/unittest/ADT/PackedVectorTest.cpp - PackedVector tests --------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// BitVectorTest tests fail on PowerPC for unknown reasons, so disable this
+// as well since it depends on a BitVector.
+#ifndef __ppc__
+
+#include "llvm/ADT/PackedVector.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(PackedVectorTest, Operation) {
+  PackedVector<unsigned, 2> Vec;
+  EXPECT_EQ(0U, Vec.size());
+  EXPECT_TRUE(Vec.empty());
+
+  Vec.resize(5);
+  EXPECT_EQ(5U, Vec.size());
+  EXPECT_FALSE(Vec.empty());
+
+  Vec.resize(11);
+  EXPECT_EQ(11U, Vec.size());
+  EXPECT_FALSE(Vec.empty());
+
+  PackedVector<unsigned, 2> Vec2(3);
+  EXPECT_EQ(3U, Vec2.size());
+  EXPECT_FALSE(Vec2.empty());
+
+  Vec.clear();
+  EXPECT_EQ(0U, Vec.size());
+  EXPECT_TRUE(Vec.empty());
+
+  Vec.push_back(2);
+  Vec.push_back(0);
+  Vec.push_back(1);
+  Vec.push_back(3);
+
+  EXPECT_EQ(2U, Vec[0]);
+  EXPECT_EQ(0U, Vec[1]);
+  EXPECT_EQ(1U, Vec[2]);
+  EXPECT_EQ(3U, Vec[3]);
+
+  EXPECT_FALSE(Vec == Vec2);
+  EXPECT_TRUE(Vec != Vec2);
+
+  Vec2.swap(Vec);
+  EXPECT_EQ(3U, Vec.size());
+  EXPECT_FALSE(Vec.empty());
+  EXPECT_EQ(0U, Vec[0]);
+  EXPECT_EQ(0U, Vec[1]);
+  EXPECT_EQ(0U, Vec[2]);
+
+  EXPECT_EQ(2U, Vec2[0]);
+  EXPECT_EQ(0U, Vec2[1]);
+  EXPECT_EQ(1U, Vec2[2]);
+  EXPECT_EQ(3U, Vec2[3]);
+
+  Vec = Vec2;
+  EXPECT_TRUE(Vec == Vec2);
+  EXPECT_FALSE(Vec != Vec2);
+
+  Vec[1] = 1;
+  Vec2[1] = 2;
+  Vec |= Vec2;
+  EXPECT_EQ(3U, Vec[1]);
+}
+
+#ifdef EXPECT_DEBUG_DEATH
+
+TEST(PackedVectorTest, UnsignedValues) {
+  PackedVector<unsigned, 2> Vec(1);
+  Vec[0] = 0;
+  Vec[0] = 1;
+  Vec[0] = 2;
+  Vec[0] = 3;
+  EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
+  EXPECT_DEBUG_DEATH(Vec[0] = -1, "value is too big");
+  EXPECT_DEBUG_DEATH(Vec[0] = 0x100, "value is too big");
+
+  PackedVector<unsigned, 3> Vec2(1);
+  Vec2[0] = 0;
+  Vec2[0] = 7;
+  EXPECT_DEBUG_DEATH(Vec[0] = 8, "value is too big");
+}
+
+TEST(PackedVectorTest, SignedValues) {
+  PackedVector<signed, 2> Vec(1);
+  Vec[0] = -2;
+  Vec[0] = -1;
+  Vec[0] = 0;
+  Vec[0] = 1;
+  EXPECT_DEBUG_DEATH(Vec[0] = -3, "value is too big");
+  EXPECT_DEBUG_DEATH(Vec[0] = 2, "value is too big");
+
+  PackedVector<signed, 3> Vec2(1);
+  Vec2[0] = -4;
+  Vec2[0] = 3;
+  EXPECT_DEBUG_DEATH(Vec[0] = -5, "value is too big");
+  EXPECT_DEBUG_DEATH(Vec[0] = 4, "value is too big");
+}
+
+#endif
+
+}
+
+#endif
diff --git a/src/LLVM/unittests/ADT/SCCIteratorTest.cpp b/src/LLVM/unittests/ADT/SCCIteratorTest.cpp
new file mode 100644
index 0000000..00fa066
--- /dev/null
+++ b/src/LLVM/unittests/ADT/SCCIteratorTest.cpp
@@ -0,0 +1,346 @@
+//===----- llvm/unittest/ADT/SCCIteratorTest.cpp - SCCIterator tests ------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <limits.h>
+#include "llvm/ADT/GraphTraits.h"
+#include "llvm/ADT/SCCIterator.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace llvm {
+
+/// Graph<N> - A graph with N nodes.  Note that N can be at most 8.
+template <unsigned N>
+class Graph {
+private:
+  // Disable copying.
+  Graph(const Graph&);
+  Graph& operator=(const Graph&);
+
+  static void ValidateIndex(unsigned Idx) {
+    assert(Idx < N && "Invalid node index!");
+  }
+public:
+
+  /// NodeSubset - A subset of the graph's nodes.
+  class NodeSubset {
+    typedef unsigned char BitVector; // Where the limitation N <= 8 comes from.
+    BitVector Elements;
+    NodeSubset(BitVector e) : Elements(e) {}
+  public:
+    /// NodeSubset - Default constructor, creates an empty subset.
+    NodeSubset() : Elements(0) {
+      assert(N <= sizeof(BitVector)*CHAR_BIT && "Graph too big!");
+    }
+    /// NodeSubset - Copy constructor.
+    NodeSubset(const NodeSubset &other) : Elements(other.Elements) {}
+
+    /// Comparison operators.
+    bool operator==(const NodeSubset &other) const {
+      return other.Elements == this->Elements;
+    }
+    bool operator!=(const NodeSubset &other) const {
+      return !(*this == other);
+    }
+
+    /// AddNode - Add the node with the given index to the subset.
+    void AddNode(unsigned Idx) {
+      ValidateIndex(Idx);
+      Elements |= 1U << Idx;
+    }
+
+    /// DeleteNode - Remove the node with the given index from the subset.
+    void DeleteNode(unsigned Idx) {
+      ValidateIndex(Idx);
+      Elements &= ~(1U << Idx);
+    }
+
+    /// count - Return true if the node with the given index is in the subset.
+    bool count(unsigned Idx) {
+      ValidateIndex(Idx);
+      return (Elements & (1U << Idx)) != 0;
+    }
+
+    /// isEmpty - Return true if this is the empty set.
+    bool isEmpty() const {
+      return Elements == 0;
+    }
+
+    /// isSubsetOf - Return true if this set is a subset of the given one.
+    bool isSubsetOf(const NodeSubset &other) const {
+      return (this->Elements | other.Elements) == other.Elements;
+    }
+
+    /// Complement - Return the complement of this subset.
+    NodeSubset Complement() const {
+      return ~(unsigned)this->Elements & ((1U << N) - 1);
+    }
+
+    /// Join - Return the union of this subset and the given one.
+    NodeSubset Join(const NodeSubset &other) const {
+      return this->Elements | other.Elements;
+    }
+
+    /// Meet - Return the intersection of this subset and the given one.
+    NodeSubset Meet(const NodeSubset &other) const {
+      return this->Elements & other.Elements;
+    }
+  };
+
+  /// NodeType - Node index and set of children of the node.
+  typedef std::pair<unsigned, NodeSubset> NodeType;
+
+private:
+  /// Nodes - The list of nodes for this graph.
+  NodeType Nodes[N];
+public:
+
+  /// Graph - Default constructor.  Creates an empty graph.
+  Graph() {
+    // Let each node know which node it is.  This allows us to find the start of
+    // the Nodes array given a pointer to any element of it.
+    for (unsigned i = 0; i != N; ++i)
+      Nodes[i].first = i;
+  }
+
+  /// AddEdge - Add an edge from the node with index FromIdx to the node with
+  /// index ToIdx.
+  void AddEdge(unsigned FromIdx, unsigned ToIdx) {
+    ValidateIndex(FromIdx);
+    Nodes[FromIdx].second.AddNode(ToIdx);
+  }
+
+  /// DeleteEdge - Remove the edge (if any) from the node with index FromIdx to
+  /// the node with index ToIdx.
+  void DeleteEdge(unsigned FromIdx, unsigned ToIdx) {
+    ValidateIndex(FromIdx);
+    Nodes[FromIdx].second.DeleteNode(ToIdx);
+  }
+
+  /// AccessNode - Get a pointer to the node with the given index.
+  NodeType *AccessNode(unsigned Idx) const {
+    ValidateIndex(Idx);
+    // The constant cast is needed when working with GraphTraits, which insists
+    // on taking a constant Graph.
+    return const_cast<NodeType *>(&Nodes[Idx]);
+  }
+
+  /// NodesReachableFrom - Return the set of all nodes reachable from the given
+  /// node.
+  NodeSubset NodesReachableFrom(unsigned Idx) const {
+    // This algorithm doesn't scale, but that doesn't matter given the small
+    // size of our graphs.
+    NodeSubset Reachable;
+
+    // The initial node is reachable.
+    Reachable.AddNode(Idx);
+    do {
+      NodeSubset Previous(Reachable);
+
+      // Add in all nodes which are children of a reachable node.
+      for (unsigned i = 0; i != N; ++i)
+        if (Previous.count(i))
+          Reachable = Reachable.Join(Nodes[i].second);
+
+      // If nothing changed then we have found all reachable nodes.
+      if (Reachable == Previous)
+        return Reachable;
+
+      // Rinse and repeat.
+    } while (1);
+  }
+
+  /// ChildIterator - Visit all children of a node.
+  class ChildIterator {
+    friend class Graph;
+
+    /// FirstNode - Pointer to first node in the graph's Nodes array.
+    NodeType *FirstNode;
+    /// Children - Set of nodes which are children of this one and that haven't
+    /// yet been visited.
+    NodeSubset Children;
+
+    ChildIterator(); // Disable default constructor.
+  protected:
+    ChildIterator(NodeType *F, NodeSubset C) : FirstNode(F), Children(C) {}
+
+  public:
+    /// ChildIterator - Copy constructor.
+    ChildIterator(const ChildIterator& other) : FirstNode(other.FirstNode),
+      Children(other.Children) {}
+
+    /// Comparison operators.
+    bool operator==(const ChildIterator &other) const {
+      return other.FirstNode == this->FirstNode &&
+        other.Children == this->Children;
+    }
+    bool operator!=(const ChildIterator &other) const {
+      return !(*this == other);
+    }
+
+    /// Prefix increment operator.
+    ChildIterator& operator++() {
+      // Find the next unvisited child node.
+      for (unsigned i = 0; i != N; ++i)
+        if (Children.count(i)) {
+          // Remove that child - it has been visited.  This is the increment!
+          Children.DeleteNode(i);
+          return *this;
+        }
+      assert(false && "Incrementing end iterator!");
+      return *this; // Avoid compiler warnings.
+    }
+
+    /// Postfix increment operator.
+    ChildIterator operator++(int) {
+      ChildIterator Result(*this);
+      ++(*this);
+      return Result;
+    }
+
+    /// Dereference operator.
+    NodeType *operator*() {
+      // Find the next unvisited child node.
+      for (unsigned i = 0; i != N; ++i)
+        if (Children.count(i))
+          // Return a pointer to it.
+          return FirstNode + i;
+      assert(false && "Dereferencing end iterator!");
+      return 0; // Avoid compiler warning.
+    }
+  };
+
+  /// child_begin - Return an iterator pointing to the first child of the given
+  /// node.
+  static ChildIterator child_begin(NodeType *Parent) {
+    return ChildIterator(Parent - Parent->first, Parent->second);
+  }
+
+  /// child_end - Return the end iterator for children of the given node.
+  static ChildIterator child_end(NodeType *Parent) {
+    return ChildIterator(Parent - Parent->first, NodeSubset());
+  }
+};
+
+template <unsigned N>
+struct GraphTraits<Graph<N> > {
+  typedef typename Graph<N>::NodeType NodeType;
+  typedef typename Graph<N>::ChildIterator ChildIteratorType;
+
+ static inline NodeType *getEntryNode(const Graph<N> &G) { return G.AccessNode(0); }
+ static inline ChildIteratorType child_begin(NodeType *Node) {
+   return Graph<N>::child_begin(Node);
+ }
+ static inline ChildIteratorType child_end(NodeType *Node) {
+   return Graph<N>::child_end(Node);
+ }
+};
+
+TEST(SCCIteratorTest, AllSmallGraphs) {
+  // Test SCC computation against every graph with NUM_NODES nodes or less.
+  // Since SCC considers every node to have an implicit self-edge, we only
+  // create graphs for which every node has a self-edge.
+#define NUM_NODES 4
+#define NUM_GRAPHS (NUM_NODES * (NUM_NODES - 1))
+  typedef Graph<NUM_NODES> GT;
+
+  /// Enumerate all graphs using NUM_GRAPHS bits.
+  assert(NUM_GRAPHS < sizeof(unsigned) * CHAR_BIT && "Too many graphs!");
+  for (unsigned GraphDescriptor = 0; GraphDescriptor < (1U << NUM_GRAPHS);
+       ++GraphDescriptor) {
+    GT G;
+
+    // Add edges as specified by the descriptor.
+    unsigned DescriptorCopy = GraphDescriptor;
+    for (unsigned i = 0; i != NUM_NODES; ++i)
+      for (unsigned j = 0; j != NUM_NODES; ++j) {
+        // Always add a self-edge.
+        if (i == j) {
+          G.AddEdge(i, j);
+          continue;
+        }
+        if (DescriptorCopy & 1)
+          G.AddEdge(i, j);
+        DescriptorCopy >>= 1;
+      }
+
+    // Test the SCC logic on this graph.
+
+    /// NodesInSomeSCC - Those nodes which are in some SCC.
+    GT::NodeSubset NodesInSomeSCC;
+
+    for (scc_iterator<GT> I = scc_begin(G), E = scc_end(G); I != E; ++I) {
+      std::vector<GT::NodeType*> &SCC = *I;
+
+      // Get the nodes in this SCC as a NodeSubset rather than a vector.
+      GT::NodeSubset NodesInThisSCC;
+      for (unsigned i = 0, e = SCC.size(); i != e; ++i)
+        NodesInThisSCC.AddNode(SCC[i]->first);
+
+      // There should be at least one node in every SCC.
+      EXPECT_FALSE(NodesInThisSCC.isEmpty());
+
+      // Check that every node in the SCC is reachable from every other node in
+      // the SCC.
+      for (unsigned i = 0; i != NUM_NODES; ++i)
+        if (NodesInThisSCC.count(i))
+          EXPECT_TRUE(NodesInThisSCC.isSubsetOf(G.NodesReachableFrom(i)));
+
+      // OK, now that we now that every node in the SCC is reachable from every
+      // other, this means that the set of nodes reachable from any node in the
+      // SCC is the same as the set of nodes reachable from every node in the
+      // SCC.  Check that for every node N not in the SCC but reachable from the
+      // SCC, no element of the SCC is reachable from N.
+      for (unsigned i = 0; i != NUM_NODES; ++i)
+        if (NodesInThisSCC.count(i)) {
+          GT::NodeSubset NodesReachableFromSCC = G.NodesReachableFrom(i);
+          GT::NodeSubset ReachableButNotInSCC =
+            NodesReachableFromSCC.Meet(NodesInThisSCC.Complement());
+
+          for (unsigned j = 0; j != NUM_NODES; ++j)
+            if (ReachableButNotInSCC.count(j))
+              EXPECT_TRUE(G.NodesReachableFrom(j).Meet(NodesInThisSCC).isEmpty());
+
+          // The result must be the same for all other nodes in this SCC, so
+          // there is no point in checking them.
+          break;
+        }
+
+      // This is indeed a SCC: a maximal set of nodes for which each node is
+      // reachable from every other.
+
+      // Check that we didn't already see this SCC.
+      EXPECT_TRUE(NodesInSomeSCC.Meet(NodesInThisSCC).isEmpty());
+
+      NodesInSomeSCC = NodesInSomeSCC.Join(NodesInThisSCC);
+
+      // Check a property that is specific to the LLVM SCC iterator and
+      // guaranteed by it: if a node in SCC S1 has an edge to a node in
+      // SCC S2, then S1 is visited *after* S2.  This means that the set
+      // of nodes reachable from this SCC must be contained either in the
+      // union of this SCC and all previously visited SCC's.
+
+      for (unsigned i = 0; i != NUM_NODES; ++i)
+        if (NodesInThisSCC.count(i)) {
+          GT::NodeSubset NodesReachableFromSCC = G.NodesReachableFrom(i);
+          EXPECT_TRUE(NodesReachableFromSCC.isSubsetOf(NodesInSomeSCC));
+          // The result must be the same for all other nodes in this SCC, so
+          // there is no point in checking them.
+          break;
+        }
+    }
+
+    // Finally, check that the nodes in some SCC are exactly those that are
+    // reachable from the initial node.
+    EXPECT_EQ(NodesInSomeSCC, G.NodesReachableFrom(0));
+  }
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/SmallBitVectorTest.cpp b/src/LLVM/unittests/ADT/SmallBitVectorTest.cpp
new file mode 100644
index 0000000..c4dda9e
--- /dev/null
+++ b/src/LLVM/unittests/ADT/SmallBitVectorTest.cpp
@@ -0,0 +1,196 @@
+//===- llvm/unittest/ADT/SmallBitVectorTest.cpp - SmallBitVector tests ----===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/SmallBitVector.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(SmallBitVectorTest, TrivialOperation) {
+  SmallBitVector Vec;
+  EXPECT_EQ(0U, Vec.count());
+  EXPECT_EQ(0U, Vec.size());
+  EXPECT_FALSE(Vec.any());
+  EXPECT_TRUE(Vec.all());
+  EXPECT_TRUE(Vec.none());
+  EXPECT_TRUE(Vec.empty());
+
+  Vec.resize(5, true);
+  EXPECT_EQ(5U, Vec.count());
+  EXPECT_EQ(5U, Vec.size());
+  EXPECT_TRUE(Vec.any());
+  EXPECT_TRUE(Vec.all());
+  EXPECT_FALSE(Vec.none());
+  EXPECT_FALSE(Vec.empty());
+
+  Vec.resize(11);
+  EXPECT_EQ(5U, Vec.count());
+  EXPECT_EQ(11U, Vec.size());
+  EXPECT_TRUE(Vec.any());
+  EXPECT_FALSE(Vec.all());
+  EXPECT_FALSE(Vec.none());
+  EXPECT_FALSE(Vec.empty());
+
+  SmallBitVector Inv = ~Vec;
+  EXPECT_EQ(6U, Inv.count());
+  EXPECT_EQ(11U, Inv.size());
+  EXPECT_TRUE(Inv.any());
+  EXPECT_FALSE(Inv.all());
+  EXPECT_FALSE(Inv.none());
+  EXPECT_FALSE(Inv.empty());
+
+  EXPECT_FALSE(Inv == Vec);
+  EXPECT_TRUE(Inv != Vec);
+  Vec = ~Vec;
+  EXPECT_TRUE(Inv == Vec);
+  EXPECT_FALSE(Inv != Vec);
+
+  // Add some "interesting" data to Vec.
+  Vec.resize(23, true);
+  Vec.resize(25, false);
+  Vec.resize(26, true);
+  Vec.resize(29, false);
+  Vec.resize(33, true);
+  Vec.resize(57, false);
+  unsigned Count = 0;
+  for (unsigned i = Vec.find_first(); i != -1u; i = Vec.find_next(i)) {
+    ++Count;
+    EXPECT_TRUE(Vec[i]);
+    EXPECT_TRUE(Vec.test(i));
+  }
+  EXPECT_EQ(Count, Vec.count());
+  EXPECT_EQ(Count, 23u);
+  EXPECT_FALSE(Vec[0]);
+  EXPECT_TRUE(Vec[32]);
+  EXPECT_FALSE(Vec[56]);
+  Vec.resize(61, false);
+
+  SmallBitVector Copy = Vec;
+  SmallBitVector Alt(3, false);
+  Alt.resize(6, true);
+  std::swap(Alt, Vec);
+  EXPECT_TRUE(Copy == Alt);
+  EXPECT_TRUE(Vec.size() == 6);
+  EXPECT_TRUE(Vec.count() == 3);
+  EXPECT_TRUE(Vec.find_first() == 3);
+  std::swap(Copy, Vec);
+
+  // Add some more "interesting" data.
+  Vec.resize(68, true);
+  Vec.resize(78, false);
+  Vec.resize(89, true);
+  Vec.resize(90, false);
+  Vec.resize(91, true);
+  Vec.resize(130, false);
+  Count = 0;
+  for (unsigned i = Vec.find_first(); i != -1u; i = Vec.find_next(i)) {
+    ++Count;
+    EXPECT_TRUE(Vec[i]);
+    EXPECT_TRUE(Vec.test(i));
+  }
+  EXPECT_EQ(Count, Vec.count());
+  EXPECT_EQ(Count, 42u);
+  EXPECT_FALSE(Vec[0]);
+  EXPECT_TRUE(Vec[32]);
+  EXPECT_FALSE(Vec[60]);
+  EXPECT_FALSE(Vec[129]);
+
+  Vec.flip(60);
+  EXPECT_TRUE(Vec[60]);
+  EXPECT_EQ(Count + 1, Vec.count());
+  Vec.flip(60);
+  EXPECT_FALSE(Vec[60]);
+  EXPECT_EQ(Count, Vec.count());
+
+  Vec.reset(32);
+  EXPECT_FALSE(Vec[32]);
+  EXPECT_EQ(Count - 1, Vec.count());
+  Vec.set(32);
+  EXPECT_TRUE(Vec[32]);
+  EXPECT_EQ(Count, Vec.count());
+
+  Vec.flip();
+  EXPECT_EQ(Vec.size() - Count, Vec.count());
+
+  Vec.reset();
+  EXPECT_EQ(0U, Vec.count());
+  EXPECT_EQ(130U, Vec.size());
+  EXPECT_FALSE(Vec.any());
+  EXPECT_FALSE(Vec.all());
+  EXPECT_TRUE(Vec.none());
+  EXPECT_FALSE(Vec.empty());
+
+  Inv = ~SmallBitVector();
+  EXPECT_EQ(0U, Inv.count());
+  EXPECT_EQ(0U, Inv.size());
+  EXPECT_FALSE(Inv.any());
+  EXPECT_TRUE(Inv.all());
+  EXPECT_TRUE(Inv.none());
+  EXPECT_TRUE(Inv.empty());
+
+  Vec.clear();
+  EXPECT_EQ(0U, Vec.count());
+  EXPECT_EQ(0U, Vec.size());
+  EXPECT_FALSE(Vec.any());
+  EXPECT_TRUE(Vec.all());
+  EXPECT_TRUE(Vec.none());
+  EXPECT_TRUE(Vec.empty());
+}
+
+TEST(SmallBitVectorTest, CompoundAssignment) {
+  SmallBitVector A;
+  A.resize(10);
+  A.set(4);
+  A.set(7);
+
+  SmallBitVector B;
+  B.resize(50);
+  B.set(5);
+  B.set(18);
+
+  A |= B;
+  EXPECT_TRUE(A.test(4));
+  EXPECT_TRUE(A.test(5));
+  EXPECT_TRUE(A.test(7));
+  EXPECT_TRUE(A.test(18));
+  EXPECT_EQ(4U, A.count());
+  EXPECT_EQ(50U, A.size());
+
+  B.resize(10);
+  B.set();
+  B.reset(2);
+  B.reset(7);
+  A &= B;
+  EXPECT_FALSE(A.test(2));
+  EXPECT_FALSE(A.test(7));
+  EXPECT_EQ(2U, A.count());
+  EXPECT_EQ(50U, A.size());
+
+  B.resize(100);
+  B.set();
+
+  A ^= B;
+  EXPECT_TRUE(A.test(2));
+  EXPECT_TRUE(A.test(7));
+  EXPECT_EQ(98U, A.count());
+  EXPECT_EQ(100U, A.size());
+}
+
+TEST(SmallBitVectorTest, ProxyIndex) {
+  SmallBitVector Vec(3);
+  EXPECT_TRUE(Vec.none());
+  Vec[0] = Vec[1] = Vec[2] = true;
+  EXPECT_EQ(Vec.size(), Vec.count());
+  Vec[2] = Vec[1] = Vec[0] = false;
+  EXPECT_TRUE(Vec.none());
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/SmallStringTest.cpp b/src/LLVM/unittests/ADT/SmallStringTest.cpp
new file mode 100644
index 0000000..099d815
--- /dev/null
+++ b/src/LLVM/unittests/ADT/SmallStringTest.cpp
@@ -0,0 +1,48 @@
+//===- llvm/unittest/ADT/SmallStringTest.cpp ------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// SmallString unit tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/SmallString.h"
+#include <stdarg.h>
+#include <climits>
+#include <cstring>
+
+using namespace llvm;
+
+namespace {
+
+// Test fixture class
+class SmallStringTest : public testing::Test {
+protected:
+  typedef SmallString<40> StringType;
+
+  StringType theString;
+
+  void assertEmpty(StringType & v) {
+    // Size tests
+    EXPECT_EQ(0u, v.size());
+    EXPECT_TRUE(v.empty());
+    // Iterator tests
+    EXPECT_TRUE(v.begin() == v.end());
+  }
+};
+
+// New string test.
+TEST_F(SmallStringTest, EmptyStringTest) {
+  SCOPED_TRACE("EmptyStringTest");
+  assertEmpty(theString);
+  EXPECT_TRUE(theString.rbegin() == theString.rend());
+}
+
+}
+
diff --git a/src/LLVM/unittests/ADT/SmallVectorTest.cpp b/src/LLVM/unittests/ADT/SmallVectorTest.cpp
new file mode 100644
index 0000000..d5bfe76
--- /dev/null
+++ b/src/LLVM/unittests/ADT/SmallVectorTest.cpp
@@ -0,0 +1,416 @@
+//===- llvm/unittest/ADT/SmallVectorTest.cpp ------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// SmallVector unit tests.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/Compiler.h"
+#include <stdarg.h>
+#include <list>
+
+using namespace llvm;
+
+namespace {
+
+/// A helper class that counts the total number of constructor and
+/// destructor calls.
+class Constructable {
+private:
+  static int numConstructorCalls;
+  static int numDestructorCalls;
+  static int numAssignmentCalls;
+
+  int value;
+
+public:
+  Constructable() : value(0) {
+    ++numConstructorCalls;
+  }
+
+  Constructable(int val) : value(val) {
+    ++numConstructorCalls;
+  }
+
+  Constructable(const Constructable & src) {
+    value = src.value;
+    ++numConstructorCalls;
+  }
+
+  ~Constructable() {
+    ++numDestructorCalls;
+  }
+
+  Constructable & operator=(const Constructable & src) {
+    value = src.value;
+    ++numAssignmentCalls;
+    return *this;
+  }
+
+  int getValue() const {
+    return abs(value);
+  }
+
+  static void reset() {
+    numConstructorCalls = 0;
+    numDestructorCalls = 0;
+    numAssignmentCalls = 0;
+  }
+
+  static int getNumConstructorCalls() {
+    return numConstructorCalls;
+  }
+
+  static int getNumDestructorCalls() {
+    return numDestructorCalls;
+  }
+
+  friend bool operator==(const Constructable & c0, const Constructable & c1) {
+    return c0.getValue() == c1.getValue();
+  }
+
+  friend bool LLVM_ATTRIBUTE_UNUSED
+  operator!=(const Constructable & c0, const Constructable & c1) {
+    return c0.getValue() != c1.getValue();
+  }
+};
+
+int Constructable::numConstructorCalls;
+int Constructable::numDestructorCalls;
+int Constructable::numAssignmentCalls;
+
+// Test fixture class
+class SmallVectorTest : public testing::Test {
+protected:
+  typedef SmallVector<Constructable, 4> VectorType;
+
+  VectorType theVector;
+  VectorType otherVector;
+
+  void SetUp() {
+    Constructable::reset();
+  }
+
+  void assertEmpty(VectorType & v) {
+    // Size tests
+    EXPECT_EQ(0u, v.size());
+    EXPECT_TRUE(v.empty());
+
+    // Iterator tests
+    EXPECT_TRUE(v.begin() == v.end());
+  }
+
+  // Assert that theVector contains the specified values, in order.
+  void assertValuesInOrder(VectorType & v, size_t size, ...) {
+    EXPECT_EQ(size, v.size());
+
+    va_list ap;
+    va_start(ap, size);
+    for (size_t i = 0; i < size; ++i) {
+      int value = va_arg(ap, int);
+      EXPECT_EQ(value, v[i].getValue());
+    }
+
+    va_end(ap);
+  }
+
+  // Generate a sequence of values to initialize the vector.
+  void makeSequence(VectorType & v, int start, int end) {
+    for (int i = start; i <= end; ++i) {
+      v.push_back(Constructable(i));
+    }
+  }
+};
+
+// New vector test.
+TEST_F(SmallVectorTest, EmptyVectorTest) {
+  SCOPED_TRACE("EmptyVectorTest");
+  assertEmpty(theVector);
+  EXPECT_TRUE(theVector.rbegin() == theVector.rend());
+  EXPECT_EQ(0, Constructable::getNumConstructorCalls());
+  EXPECT_EQ(0, Constructable::getNumDestructorCalls());
+}
+
+// Simple insertions and deletions.
+TEST_F(SmallVectorTest, PushPopTest) {
+  SCOPED_TRACE("PushPopTest");
+
+  // Push an element
+  theVector.push_back(Constructable(1));
+
+  // Size tests
+  assertValuesInOrder(theVector, 1u, 1);
+  EXPECT_FALSE(theVector.begin() == theVector.end());
+  EXPECT_FALSE(theVector.empty());
+
+  // Push another element
+  theVector.push_back(Constructable(2));
+  assertValuesInOrder(theVector, 2u, 1, 2);
+
+  // Insert at beginning
+  theVector.insert(theVector.begin(), theVector[1]);
+  assertValuesInOrder(theVector, 3u, 2, 1, 2);
+
+  // Pop one element
+  theVector.pop_back();
+  assertValuesInOrder(theVector, 2u, 2, 1);
+
+  // Pop remaining elements
+  theVector.pop_back();
+  theVector.pop_back();
+  assertEmpty(theVector);
+
+  // Check number of constructor calls. Should be 2 for each list element,
+  // one for the argument to push_back, one for the argument to insert,
+  // and one for the list element itself.
+  EXPECT_EQ(5, Constructable::getNumConstructorCalls());
+  EXPECT_EQ(5, Constructable::getNumDestructorCalls());
+}
+
+// Clear test.
+TEST_F(SmallVectorTest, ClearTest) {
+  SCOPED_TRACE("ClearTest");
+
+  makeSequence(theVector, 1, 2);
+  theVector.clear();
+
+  assertEmpty(theVector);
+  EXPECT_EQ(4, Constructable::getNumConstructorCalls());
+  EXPECT_EQ(4, Constructable::getNumDestructorCalls());
+}
+
+// Resize smaller test.
+TEST_F(SmallVectorTest, ResizeShrinkTest) {
+  SCOPED_TRACE("ResizeShrinkTest");
+
+  makeSequence(theVector, 1, 3);
+  theVector.resize(1);
+
+  assertValuesInOrder(theVector, 1u, 1);
+  EXPECT_EQ(6, Constructable::getNumConstructorCalls());
+  EXPECT_EQ(5, Constructable::getNumDestructorCalls());
+}
+
+// Resize bigger test.
+TEST_F(SmallVectorTest, ResizeGrowTest) {
+  SCOPED_TRACE("ResizeGrowTest");
+
+  theVector.resize(2);
+
+  // The extra constructor/destructor calls come from the temporary object used
+  // to initialize the contents of the resized array (via copy construction).
+  EXPECT_EQ(3, Constructable::getNumConstructorCalls());
+  EXPECT_EQ(1, Constructable::getNumDestructorCalls());
+  EXPECT_EQ(2u, theVector.size());
+}
+
+// Resize with fill value.
+TEST_F(SmallVectorTest, ResizeFillTest) {
+  SCOPED_TRACE("ResizeFillTest");
+
+  theVector.resize(3, Constructable(77));
+  assertValuesInOrder(theVector, 3u, 77, 77, 77);
+}
+
+// Overflow past fixed size.
+TEST_F(SmallVectorTest, OverflowTest) {
+  SCOPED_TRACE("OverflowTest");
+
+  // Push more elements than the fixed size.
+  makeSequence(theVector, 1, 10);
+
+  // Test size and values.
+  EXPECT_EQ(10u, theVector.size());
+  for (int i = 0; i < 10; ++i) {
+    EXPECT_EQ(i+1, theVector[i].getValue());
+  }
+
+  // Now resize back to fixed size.
+  theVector.resize(1);
+
+  assertValuesInOrder(theVector, 1u, 1);
+}
+
+// Iteration tests.
+TEST_F(SmallVectorTest, IterationTest) {
+  makeSequence(theVector, 1, 2);
+
+  // Forward Iteration
+  VectorType::iterator it = theVector.begin();
+  EXPECT_TRUE(*it == theVector.front());
+  EXPECT_TRUE(*it == theVector[0]);
+  EXPECT_EQ(1, it->getValue());
+  ++it;
+  EXPECT_TRUE(*it == theVector[1]);
+  EXPECT_TRUE(*it == theVector.back());
+  EXPECT_EQ(2, it->getValue());
+  ++it;
+  EXPECT_TRUE(it == theVector.end());
+  --it;
+  EXPECT_TRUE(*it == theVector[1]);
+  EXPECT_EQ(2, it->getValue());
+  --it;
+  EXPECT_TRUE(*it == theVector[0]);
+  EXPECT_EQ(1, it->getValue());
+
+  // Reverse Iteration
+  VectorType::reverse_iterator rit = theVector.rbegin();
+  EXPECT_TRUE(*rit == theVector[1]);
+  EXPECT_EQ(2, rit->getValue());
+  ++rit;
+  EXPECT_TRUE(*rit == theVector[0]);
+  EXPECT_EQ(1, rit->getValue());
+  ++rit;
+  EXPECT_TRUE(rit == theVector.rend());
+  --rit;
+  EXPECT_TRUE(*rit == theVector[0]);
+  EXPECT_EQ(1, rit->getValue());
+  --rit;
+  EXPECT_TRUE(*rit == theVector[1]);
+  EXPECT_EQ(2, rit->getValue());
+}
+
+// Swap test.
+TEST_F(SmallVectorTest, SwapTest) {
+  SCOPED_TRACE("SwapTest");
+
+  makeSequence(theVector, 1, 2);
+  std::swap(theVector, otherVector);
+
+  assertEmpty(theVector);
+  assertValuesInOrder(otherVector, 2u, 1, 2);
+}
+
+// Append test
+TEST_F(SmallVectorTest, AppendTest) {
+  SCOPED_TRACE("AppendTest");
+
+  makeSequence(otherVector, 2, 3);
+
+  theVector.push_back(Constructable(1));
+  theVector.append(otherVector.begin(), otherVector.end());
+
+  assertValuesInOrder(theVector, 3u, 1, 2, 3);
+}
+
+// Append repeated test
+TEST_F(SmallVectorTest, AppendRepeatedTest) {
+  SCOPED_TRACE("AppendRepeatedTest");
+
+  theVector.push_back(Constructable(1));
+  theVector.append(2, Constructable(77));
+  assertValuesInOrder(theVector, 3u, 1, 77, 77);
+}
+
+// Assign test
+TEST_F(SmallVectorTest, AssignTest) {
+  SCOPED_TRACE("AssignTest");
+
+  theVector.push_back(Constructable(1));
+  theVector.assign(2, Constructable(77));
+  assertValuesInOrder(theVector, 2u, 77, 77);
+}
+
+// Erase a single element
+TEST_F(SmallVectorTest, EraseTest) {
+  SCOPED_TRACE("EraseTest");
+
+  makeSequence(theVector, 1, 3);
+  theVector.erase(theVector.begin());
+  assertValuesInOrder(theVector, 2u, 2, 3);
+}
+
+// Erase a range of elements
+TEST_F(SmallVectorTest, EraseRangeTest) {
+  SCOPED_TRACE("EraseRangeTest");
+
+  makeSequence(theVector, 1, 3);
+  theVector.erase(theVector.begin(), theVector.begin() + 2);
+  assertValuesInOrder(theVector, 1u, 3);
+}
+
+// Insert a single element.
+TEST_F(SmallVectorTest, InsertTest) {
+  SCOPED_TRACE("InsertTest");
+
+  makeSequence(theVector, 1, 3);
+  theVector.insert(theVector.begin() + 1, Constructable(77));
+  assertValuesInOrder(theVector, 4u, 1, 77, 2, 3);
+}
+
+// Insert repeated elements.
+TEST_F(SmallVectorTest, InsertRepeatedTest) {
+  SCOPED_TRACE("InsertRepeatedTest");
+
+  makeSequence(theVector, 10, 15);
+  theVector.insert(theVector.begin() + 1, 2, Constructable(16));
+  assertValuesInOrder(theVector, 8u, 10, 16, 16, 11, 12, 13, 14, 15);
+}
+
+// Insert range.
+TEST_F(SmallVectorTest, InsertRangeTest) {
+  SCOPED_TRACE("InsertRepeatedTest");
+
+  makeSequence(theVector, 1, 3);
+  theVector.insert(theVector.begin() + 1, 3, Constructable(77));
+  assertValuesInOrder(theVector, 6u, 1, 77, 77, 77, 2, 3);
+}
+
+// Comparison tests.
+TEST_F(SmallVectorTest, ComparisonTest) {
+  SCOPED_TRACE("ComparisonTest");
+
+  makeSequence(theVector, 1, 3);
+  makeSequence(otherVector, 1, 3);
+
+  EXPECT_TRUE(theVector == otherVector);
+  EXPECT_FALSE(theVector != otherVector);
+
+  otherVector.clear();
+  makeSequence(otherVector, 2, 4);
+
+  EXPECT_FALSE(theVector == otherVector);
+  EXPECT_TRUE(theVector != otherVector);
+}
+
+// Constant vector tests.
+TEST_F(SmallVectorTest, ConstVectorTest) {
+  VectorType constVector;
+
+  EXPECT_EQ(0u, constVector.size());
+  EXPECT_TRUE(constVector.empty());
+  EXPECT_TRUE(constVector.begin() == constVector.end());
+}
+
+// Direct array access.
+TEST_F(SmallVectorTest, DirectVectorTest) {
+  EXPECT_EQ(0u, theVector.size());
+  EXPECT_LE(4u, theVector.capacity());
+  EXPECT_EQ(0, Constructable::getNumConstructorCalls());
+  theVector.end()[0] = 1;
+  theVector.end()[1] = 2;
+  theVector.end()[2] = 3;
+  theVector.end()[3] = 4;
+  theVector.set_size(4);
+  EXPECT_EQ(4u, theVector.size());
+  EXPECT_EQ(4, Constructable::getNumConstructorCalls());
+  EXPECT_EQ(1, theVector[0].getValue());
+  EXPECT_EQ(2, theVector[1].getValue());
+  EXPECT_EQ(3, theVector[2].getValue());
+  EXPECT_EQ(4, theVector[3].getValue());
+}
+
+TEST_F(SmallVectorTest, IteratorTest) {
+  std::list<int> L;
+  theVector.insert(theVector.end(), L.begin(), L.end());
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/SparseBitVectorTest.cpp b/src/LLVM/unittests/ADT/SparseBitVectorTest.cpp
new file mode 100644
index 0000000..d8fc5ce
--- /dev/null
+++ b/src/LLVM/unittests/ADT/SparseBitVectorTest.cpp
@@ -0,0 +1,36 @@
+//===- llvm/unittest/ADT/SparseBitVectorTest.cpp - SparseBitVector tests --===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/ADT/SparseBitVector.h"
+#include "gtest/gtest.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(SparseBitVectorTest, TrivialOperation) {
+  SparseBitVector<> Vec;
+  EXPECT_EQ(0U, Vec.count());
+  EXPECT_FALSE(Vec.test(17));
+  Vec.set(5);
+  EXPECT_TRUE(Vec.test(5));
+  EXPECT_FALSE(Vec.test(17));
+  Vec.reset(6);
+  EXPECT_TRUE(Vec.test(5));
+  EXPECT_FALSE(Vec.test(6));
+  Vec.reset(5);
+  EXPECT_FALSE(Vec.test(5));
+  EXPECT_TRUE(Vec.test_and_set(17));
+  EXPECT_FALSE(Vec.test_and_set(17));
+  EXPECT_TRUE(Vec.test(17));
+  Vec.clear();
+  EXPECT_FALSE(Vec.test(17));
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/StringMapTest.cpp b/src/LLVM/unittests/ADT/StringMapTest.cpp
new file mode 100644
index 0000000..2ae5820
--- /dev/null
+++ b/src/LLVM/unittests/ADT/StringMapTest.cpp
@@ -0,0 +1,207 @@
+//===- llvm/unittest/ADT/StringMapMap.cpp - StringMap unit tests ----------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/Support/DataTypes.h"
+using namespace llvm;
+
+namespace {
+
+// Test fixture
+class StringMapTest : public testing::Test {
+protected:
+  StringMap<uint32_t> testMap;
+
+  static const char testKey[];
+  static const uint32_t testValue;
+  static const char* testKeyFirst;
+  static size_t testKeyLength;
+  static const std::string testKeyStr;
+
+  void assertEmptyMap() {
+    // Size tests
+    EXPECT_EQ(0u, testMap.size());
+    EXPECT_TRUE(testMap.empty());
+
+    // Iterator tests
+    EXPECT_TRUE(testMap.begin() == testMap.end());
+
+    // Lookup tests
+    EXPECT_EQ(0u, testMap.count(testKey));
+    EXPECT_EQ(0u, testMap.count(StringRef(testKeyFirst, testKeyLength)));
+    EXPECT_EQ(0u, testMap.count(testKeyStr));
+    EXPECT_TRUE(testMap.find(testKey) == testMap.end());
+    EXPECT_TRUE(testMap.find(StringRef(testKeyFirst, testKeyLength)) == 
+                testMap.end());
+    EXPECT_TRUE(testMap.find(testKeyStr) == testMap.end());
+  }
+
+  void assertSingleItemMap() {
+    // Size tests
+    EXPECT_EQ(1u, testMap.size());
+    EXPECT_FALSE(testMap.begin() == testMap.end());
+    EXPECT_FALSE(testMap.empty());
+
+    // Iterator tests
+    StringMap<uint32_t>::iterator it = testMap.begin();
+    EXPECT_STREQ(testKey, it->first().data());
+    EXPECT_EQ(testValue, it->second);
+    ++it;
+    EXPECT_TRUE(it == testMap.end());
+
+    // Lookup tests
+    EXPECT_EQ(1u, testMap.count(testKey));
+    EXPECT_EQ(1u, testMap.count(StringRef(testKeyFirst, testKeyLength)));
+    EXPECT_EQ(1u, testMap.count(testKeyStr));
+    EXPECT_TRUE(testMap.find(testKey) == testMap.begin());
+    EXPECT_TRUE(testMap.find(StringRef(testKeyFirst, testKeyLength)) == 
+                testMap.begin());
+    EXPECT_TRUE(testMap.find(testKeyStr) == testMap.begin());
+  }
+};
+
+const char StringMapTest::testKey[] = "key";
+const uint32_t StringMapTest::testValue = 1u;
+const char* StringMapTest::testKeyFirst = testKey;
+size_t StringMapTest::testKeyLength = sizeof(testKey) - 1;
+const std::string StringMapTest::testKeyStr(testKey);
+
+// Empty map tests.
+TEST_F(StringMapTest, EmptyMapTest) {
+  SCOPED_TRACE("EmptyMapTest");
+  assertEmptyMap();
+}
+
+// Constant map tests.
+TEST_F(StringMapTest, ConstEmptyMapTest) {
+  const StringMap<uint32_t>& constTestMap = testMap;
+
+  // Size tests
+  EXPECT_EQ(0u, constTestMap.size());
+  EXPECT_TRUE(constTestMap.empty());
+
+  // Iterator tests
+  EXPECT_TRUE(constTestMap.begin() == constTestMap.end());
+
+  // Lookup tests
+  EXPECT_EQ(0u, constTestMap.count(testKey));
+  EXPECT_EQ(0u, constTestMap.count(StringRef(testKeyFirst, testKeyLength)));
+  EXPECT_EQ(0u, constTestMap.count(testKeyStr));
+  EXPECT_TRUE(constTestMap.find(testKey) == constTestMap.end());
+  EXPECT_TRUE(constTestMap.find(StringRef(testKeyFirst, testKeyLength)) ==
+              constTestMap.end());
+  EXPECT_TRUE(constTestMap.find(testKeyStr) == constTestMap.end());
+}
+
+// A map with a single entry.
+TEST_F(StringMapTest, SingleEntryMapTest) {
+  SCOPED_TRACE("SingleEntryMapTest");
+  testMap[testKey] = testValue;
+  assertSingleItemMap();
+}
+
+// Test clear() method.
+TEST_F(StringMapTest, ClearTest) {
+  SCOPED_TRACE("ClearTest");
+  testMap[testKey] = testValue;
+  testMap.clear();
+  assertEmptyMap();
+}
+
+// Test erase(iterator) method.
+TEST_F(StringMapTest, EraseIteratorTest) {
+  SCOPED_TRACE("EraseIteratorTest");
+  testMap[testKey] = testValue;
+  testMap.erase(testMap.begin());
+  assertEmptyMap();
+}
+
+// Test erase(value) method.
+TEST_F(StringMapTest, EraseValueTest) {
+  SCOPED_TRACE("EraseValueTest");
+  testMap[testKey] = testValue;
+  testMap.erase(testKey);
+  assertEmptyMap();
+}
+
+// Test inserting two values and erasing one.
+TEST_F(StringMapTest, InsertAndEraseTest) {
+  SCOPED_TRACE("InsertAndEraseTest");
+  testMap[testKey] = testValue;
+  testMap["otherKey"] = 2;
+  testMap.erase("otherKey");
+  assertSingleItemMap();
+}
+
+// A more complex iteration test.
+TEST_F(StringMapTest, IterationTest) {
+  bool visited[100];
+
+  // Insert 100 numbers into the map
+  for (int i = 0; i < 100; ++i) {
+    std::stringstream ss;
+    ss << "key_" << i;
+    testMap[ss.str()] = i;
+    visited[i] = false;
+  }
+
+  // Iterate over all numbers and mark each one found.
+  for (StringMap<uint32_t>::iterator it = testMap.begin();
+      it != testMap.end(); ++it) {
+    std::stringstream ss;
+    ss << "key_" << it->second;
+    ASSERT_STREQ(ss.str().c_str(), it->first().data());
+    visited[it->second] = true;
+  }
+
+  // Ensure every number was visited.
+  for (int i = 0; i < 100; ++i) {
+    ASSERT_TRUE(visited[i]) << "Entry #" << i << " was never visited";
+  }
+}
+
+} // end anonymous namespace
+
+namespace llvm {
+
+template <>
+class StringMapEntryInitializer<uint32_t> {
+public:
+  template <typename InitTy>
+  static void Initialize(StringMapEntry<uint32_t> &T, InitTy InitVal) {
+    T.second = InitVal;
+  }
+};
+
+} // end llvm namespace
+
+namespace {
+
+// Test StringMapEntry::Create() method.
+TEST_F(StringMapTest, StringMapEntryTest) {
+  StringMap<uint32_t>::value_type* entry =
+      StringMap<uint32_t>::value_type::Create(
+          testKeyFirst, testKeyFirst + testKeyLength, 1u);
+  EXPECT_STREQ(testKey, entry->first().data());
+  EXPECT_EQ(1u, entry->second);
+  free(entry);
+}
+
+// Test insert() method.
+TEST_F(StringMapTest, InsertTest) {
+  SCOPED_TRACE("InsertTest");
+  testMap.insert(
+      StringMap<uint32_t>::value_type::Create(
+          testKeyFirst, testKeyFirst + testKeyLength, 
+          testMap.getAllocator(), 1u));
+  assertSingleItemMap();
+}
+
+} // end anonymous namespace
diff --git a/src/LLVM/unittests/ADT/StringRefTest.cpp b/src/LLVM/unittests/ADT/StringRefTest.cpp
new file mode 100644
index 0000000..8364eac
--- /dev/null
+++ b/src/LLVM/unittests/ADT/StringRefTest.cpp
@@ -0,0 +1,288 @@
+//===- llvm/unittest/ADT/StringRefTest.cpp - StringRef unit tests ---------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/Support/raw_ostream.h"
+using namespace llvm;
+
+namespace llvm {
+
+std::ostream &operator<<(std::ostream &OS, const StringRef &S) {
+  OS << S.str();
+  return OS;
+}
+
+std::ostream &operator<<(std::ostream &OS,
+                         const std::pair<StringRef, StringRef> &P) {
+  OS << "(" << P.first << ", " << P.second << ")";
+  return OS;
+}
+
+}
+
+namespace {
+TEST(StringRefTest, Construction) {
+  EXPECT_EQ("", StringRef());
+  EXPECT_EQ("hello", StringRef("hello"));
+  EXPECT_EQ("hello", StringRef("hello world", 5));
+  EXPECT_EQ("hello", StringRef(std::string("hello")));
+}
+
+TEST(StringRefTest, Iteration) {
+  StringRef S("hello");
+  const char *p = "hello";
+  for (const char *it = S.begin(), *ie = S.end(); it != ie; ++it, ++p)
+    EXPECT_EQ(*it, *p);
+}
+
+TEST(StringRefTest, StringOps) {
+  const char *p = "hello";
+  EXPECT_EQ(p, StringRef(p, 0).data());
+  EXPECT_TRUE(StringRef().empty());
+  EXPECT_EQ((size_t) 5, StringRef("hello").size());
+  EXPECT_EQ(-1, StringRef("aab").compare("aad"));
+  EXPECT_EQ( 0, StringRef("aab").compare("aab"));
+  EXPECT_EQ( 1, StringRef("aab").compare("aaa"));
+  EXPECT_EQ(-1, StringRef("aab").compare("aabb"));
+  EXPECT_EQ( 1, StringRef("aab").compare("aa"));
+  EXPECT_EQ( 1, StringRef("\xFF").compare("\1"));
+
+  EXPECT_EQ(-1, StringRef("AaB").compare_lower("aAd"));
+  EXPECT_EQ( 0, StringRef("AaB").compare_lower("aab"));
+  EXPECT_EQ( 1, StringRef("AaB").compare_lower("AAA"));
+  EXPECT_EQ(-1, StringRef("AaB").compare_lower("aaBb"));
+  EXPECT_EQ( 1, StringRef("AaB").compare_lower("aA"));
+  EXPECT_EQ( 1, StringRef("\xFF").compare_lower("\1"));
+
+  EXPECT_EQ(-1, StringRef("aab").compare_numeric("aad"));
+  EXPECT_EQ( 0, StringRef("aab").compare_numeric("aab"));
+  EXPECT_EQ( 1, StringRef("aab").compare_numeric("aaa"));
+  EXPECT_EQ(-1, StringRef("aab").compare_numeric("aabb"));
+  EXPECT_EQ( 1, StringRef("aab").compare_numeric("aa"));
+  EXPECT_EQ(-1, StringRef("1").compare_numeric("10"));
+  EXPECT_EQ( 0, StringRef("10").compare_numeric("10"));
+  EXPECT_EQ( 0, StringRef("10a").compare_numeric("10a"));
+  EXPECT_EQ( 1, StringRef("2").compare_numeric("1"));
+  EXPECT_EQ( 0, StringRef("llvm_v1i64_ty").compare_numeric("llvm_v1i64_ty"));
+  EXPECT_EQ( 1, StringRef("\xFF").compare_numeric("\1"));
+  EXPECT_EQ( 1, StringRef("V16").compare_numeric("V1_q0"));
+  EXPECT_EQ(-1, StringRef("V1_q0").compare_numeric("V16"));
+  EXPECT_EQ(-1, StringRef("V8_q0").compare_numeric("V16"));
+  EXPECT_EQ( 1, StringRef("V16").compare_numeric("V8_q0"));
+  EXPECT_EQ(-1, StringRef("V1_q0").compare_numeric("V8_q0"));
+  EXPECT_EQ( 1, StringRef("V8_q0").compare_numeric("V1_q0"));
+}
+
+TEST(StringRefTest, Operators) {
+  EXPECT_EQ("", StringRef());
+  EXPECT_TRUE(StringRef("aab") < StringRef("aad"));
+  EXPECT_FALSE(StringRef("aab") < StringRef("aab"));
+  EXPECT_TRUE(StringRef("aab") <= StringRef("aab"));
+  EXPECT_FALSE(StringRef("aab") <= StringRef("aaa"));
+  EXPECT_TRUE(StringRef("aad") > StringRef("aab"));
+  EXPECT_FALSE(StringRef("aab") > StringRef("aab"));
+  EXPECT_TRUE(StringRef("aab") >= StringRef("aab"));
+  EXPECT_FALSE(StringRef("aaa") >= StringRef("aab"));
+  EXPECT_EQ(StringRef("aab"), StringRef("aab"));
+  EXPECT_FALSE(StringRef("aab") == StringRef("aac"));
+  EXPECT_FALSE(StringRef("aab") != StringRef("aab"));
+  EXPECT_TRUE(StringRef("aab") != StringRef("aac"));
+  EXPECT_EQ('a', StringRef("aab")[1]);
+}
+
+TEST(StringRefTest, Substr) {
+  StringRef Str("hello");
+  EXPECT_EQ("lo", Str.substr(3));
+  EXPECT_EQ("", Str.substr(100));
+  EXPECT_EQ("hello", Str.substr(0, 100));
+  EXPECT_EQ("o", Str.substr(4, 10));
+}
+
+TEST(StringRefTest, Slice) {
+  StringRef Str("hello");
+  EXPECT_EQ("l", Str.slice(2, 3));
+  EXPECT_EQ("ell", Str.slice(1, 4));
+  EXPECT_EQ("llo", Str.slice(2, 100));
+  EXPECT_EQ("", Str.slice(2, 1));
+  EXPECT_EQ("", Str.slice(10, 20));
+}
+
+TEST(StringRefTest, Split) {
+  StringRef Str("hello");
+  EXPECT_EQ(std::make_pair(StringRef("hello"), StringRef("")),
+            Str.split('X'));
+  EXPECT_EQ(std::make_pair(StringRef("h"), StringRef("llo")),
+            Str.split('e'));
+  EXPECT_EQ(std::make_pair(StringRef(""), StringRef("ello")),
+            Str.split('h'));
+  EXPECT_EQ(std::make_pair(StringRef("he"), StringRef("lo")),
+            Str.split('l'));
+  EXPECT_EQ(std::make_pair(StringRef("hell"), StringRef("")),
+            Str.split('o'));
+
+  EXPECT_EQ(std::make_pair(StringRef("hello"), StringRef("")),
+            Str.rsplit('X'));
+  EXPECT_EQ(std::make_pair(StringRef("h"), StringRef("llo")),
+            Str.rsplit('e'));
+  EXPECT_EQ(std::make_pair(StringRef(""), StringRef("ello")),
+            Str.rsplit('h'));
+  EXPECT_EQ(std::make_pair(StringRef("hel"), StringRef("o")),
+            Str.rsplit('l'));
+  EXPECT_EQ(std::make_pair(StringRef("hell"), StringRef("")),
+            Str.rsplit('o'));
+}
+
+TEST(StringRefTest, Split2) {
+  SmallVector<StringRef, 5> parts;
+  SmallVector<StringRef, 5> expected;
+
+  expected.push_back("ab"); expected.push_back("c");
+  StringRef(",ab,,c,").split(parts, ",", -1, false);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back(""); expected.push_back("ab"); expected.push_back("");
+  expected.push_back("c"); expected.push_back("");
+  StringRef(",ab,,c,").split(parts, ",", -1, true);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("");
+  StringRef("").split(parts, ",", -1, true);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  StringRef("").split(parts, ",", -1, false);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  StringRef(",").split(parts, ",", -1, false);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back(""); expected.push_back("");
+  StringRef(",").split(parts, ",", -1, true);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back("b");
+  StringRef("a,b").split(parts, ",", -1, true);
+  EXPECT_TRUE(parts == expected);
+
+  // Test MaxSplit
+  expected.clear(); parts.clear();
+  expected.push_back("a,,b,c");
+  StringRef("a,,b,c").split(parts, ",", 0, true);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a,,b,c");
+  StringRef("a,,b,c").split(parts, ",", 0, false);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back(",b,c");
+  StringRef("a,,b,c").split(parts, ",", 1, true);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back(",b,c");
+  StringRef("a,,b,c").split(parts, ",", 1, false);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back(""); expected.push_back("b,c");
+  StringRef("a,,b,c").split(parts, ",", 2, true);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back("b,c");
+  StringRef("a,,b,c").split(parts, ",", 2, false);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back(""); expected.push_back("b");
+  expected.push_back("c");
+  StringRef("a,,b,c").split(parts, ",", 3, true);
+  EXPECT_TRUE(parts == expected);
+
+  expected.clear(); parts.clear();
+  expected.push_back("a"); expected.push_back("b"); expected.push_back("c");
+  StringRef("a,,b,c").split(parts, ",", 3, false);
+  EXPECT_TRUE(parts == expected);
+}
+
+TEST(StringRefTest, StartsWith) {
+  StringRef Str("hello");
+  EXPECT_TRUE(Str.startswith("he"));
+  EXPECT_FALSE(Str.startswith("helloworld"));
+  EXPECT_FALSE(Str.startswith("hi"));
+}
+
+TEST(StringRefTest, EndsWith) {
+  StringRef Str("hello");
+  EXPECT_TRUE(Str.endswith("lo"));
+  EXPECT_FALSE(Str.endswith("helloworld"));
+  EXPECT_FALSE(Str.endswith("worldhello"));
+  EXPECT_FALSE(Str.endswith("so"));
+}
+
+TEST(StringRefTest, Find) {
+  StringRef Str("hello");
+  EXPECT_EQ(2U, Str.find('l'));
+  EXPECT_EQ(StringRef::npos, Str.find('z'));
+  EXPECT_EQ(StringRef::npos, Str.find("helloworld"));
+  EXPECT_EQ(0U, Str.find("hello"));
+  EXPECT_EQ(1U, Str.find("ello"));
+  EXPECT_EQ(StringRef::npos, Str.find("zz"));
+  EXPECT_EQ(2U, Str.find("ll", 2));
+  EXPECT_EQ(StringRef::npos, Str.find("ll", 3));
+
+  EXPECT_EQ(3U, Str.rfind('l'));
+  EXPECT_EQ(StringRef::npos, Str.rfind('z'));
+  EXPECT_EQ(StringRef::npos, Str.rfind("helloworld"));
+  EXPECT_EQ(0U, Str.rfind("hello"));
+  EXPECT_EQ(1U, Str.rfind("ello"));
+  EXPECT_EQ(StringRef::npos, Str.rfind("zz"));
+
+  EXPECT_EQ(2U, Str.find_first_of('l'));
+  EXPECT_EQ(1U, Str.find_first_of("el"));
+  EXPECT_EQ(StringRef::npos, Str.find_first_of("xyz"));
+
+  EXPECT_EQ(1U, Str.find_first_not_of('h'));
+  EXPECT_EQ(4U, Str.find_first_not_of("hel"));
+  EXPECT_EQ(StringRef::npos, Str.find_first_not_of("hello"));
+}
+
+TEST(StringRefTest, Count) {
+  StringRef Str("hello");
+  EXPECT_EQ(2U, Str.count('l'));
+  EXPECT_EQ(1U, Str.count('o'));
+  EXPECT_EQ(0U, Str.count('z'));
+  EXPECT_EQ(0U, Str.count("helloworld"));
+  EXPECT_EQ(1U, Str.count("hello"));
+  EXPECT_EQ(1U, Str.count("ello"));
+  EXPECT_EQ(0U, Str.count("zz"));
+}
+
+TEST(StringRefTest, EditDistance) {
+  StringRef Str("hello");
+  EXPECT_EQ(2U, Str.edit_distance("hill"));
+}
+
+TEST(StringRefTest, Misc) {
+  std::string Storage;
+  raw_string_ostream OS(Storage);
+  OS << StringRef("hello");
+  EXPECT_EQ("hello", OS.str());
+}
+
+} // end anonymous namespace
diff --git a/src/LLVM/unittests/ADT/TripleTest.cpp b/src/LLVM/unittests/ADT/TripleTest.cpp
new file mode 100644
index 0000000..160b692
--- /dev/null
+++ b/src/LLVM/unittests/ADT/TripleTest.cpp
@@ -0,0 +1,270 @@
+//===----------- Triple.cpp - Triple unit tests ---------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/Triple.h"
+
+using namespace llvm;
+
+namespace {
+
+TEST(TripleTest, BasicParsing) {
+  Triple T;
+
+  T = Triple("");
+  EXPECT_EQ("", T.getArchName().str());
+  EXPECT_EQ("", T.getVendorName().str());
+  EXPECT_EQ("", T.getOSName().str());
+  EXPECT_EQ("", T.getEnvironmentName().str());
+
+  T = Triple("-");
+  EXPECT_EQ("", T.getArchName().str());
+  EXPECT_EQ("", T.getVendorName().str());
+  EXPECT_EQ("", T.getOSName().str());
+  EXPECT_EQ("", T.getEnvironmentName().str());
+
+  T = Triple("--");
+  EXPECT_EQ("", T.getArchName().str());
+  EXPECT_EQ("", T.getVendorName().str());
+  EXPECT_EQ("", T.getOSName().str());
+  EXPECT_EQ("", T.getEnvironmentName().str());
+
+  T = Triple("---");
+  EXPECT_EQ("", T.getArchName().str());
+  EXPECT_EQ("", T.getVendorName().str());
+  EXPECT_EQ("", T.getOSName().str());
+  EXPECT_EQ("", T.getEnvironmentName().str());
+
+  T = Triple("----");
+  EXPECT_EQ("", T.getArchName().str());
+  EXPECT_EQ("", T.getVendorName().str());
+  EXPECT_EQ("", T.getOSName().str());
+  EXPECT_EQ("-", T.getEnvironmentName().str());
+
+  T = Triple("a");
+  EXPECT_EQ("a", T.getArchName().str());
+  EXPECT_EQ("", T.getVendorName().str());
+  EXPECT_EQ("", T.getOSName().str());
+  EXPECT_EQ("", T.getEnvironmentName().str());
+
+  T = Triple("a-b");
+  EXPECT_EQ("a", T.getArchName().str());
+  EXPECT_EQ("b", T.getVendorName().str());
+  EXPECT_EQ("", T.getOSName().str());
+  EXPECT_EQ("", T.getEnvironmentName().str());
+
+  T = Triple("a-b-c");
+  EXPECT_EQ("a", T.getArchName().str());
+  EXPECT_EQ("b", T.getVendorName().str());
+  EXPECT_EQ("c", T.getOSName().str());
+  EXPECT_EQ("", T.getEnvironmentName().str());
+
+  T = Triple("a-b-c-d");
+  EXPECT_EQ("a", T.getArchName().str());
+  EXPECT_EQ("b", T.getVendorName().str());
+  EXPECT_EQ("c", T.getOSName().str());
+  EXPECT_EQ("d", T.getEnvironmentName().str());
+}
+
+TEST(TripleTest, ParsedIDs) {
+  Triple T;
+
+  T = Triple("i386-apple-darwin");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::Apple, T.getVendor());
+  EXPECT_EQ(Triple::Darwin, T.getOS());
+  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+
+  T = Triple("x86_64-pc-linux-gnu");
+  EXPECT_EQ(Triple::x86_64, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ(Triple::GNU, T.getEnvironment());
+
+  T = Triple("powerpc-dunno-notsure");
+  EXPECT_EQ(Triple::ppc, T.getArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::UnknownOS, T.getOS());
+  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+
+  T = Triple("arm-none-none-eabi");
+  EXPECT_EQ(Triple::arm, T.getArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::UnknownOS, T.getOS());
+  EXPECT_EQ(Triple::EABI, T.getEnvironment());
+
+  T = Triple("huh");
+  EXPECT_EQ(Triple::UnknownArch, T.getArch());
+}
+
+static std::string Join(StringRef A, StringRef B, StringRef C) {
+  std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C;
+  return Str;
+}
+
+static std::string Join(StringRef A, StringRef B, StringRef C, StringRef D) {
+  std::string Str = A; Str += '-'; Str += B; Str += '-'; Str += C; Str += '-';
+  Str += D; return Str;
+}
+
+TEST(TripleTest, Normalization) {
+
+  EXPECT_EQ("", Triple::normalize(""));
+  EXPECT_EQ("-", Triple::normalize("-"));
+  EXPECT_EQ("--", Triple::normalize("--"));
+  EXPECT_EQ("---", Triple::normalize("---"));
+  EXPECT_EQ("----", Triple::normalize("----"));
+
+  EXPECT_EQ("a", Triple::normalize("a"));
+  EXPECT_EQ("a-b", Triple::normalize("a-b"));
+  EXPECT_EQ("a-b-c", Triple::normalize("a-b-c"));
+  EXPECT_EQ("a-b-c-d", Triple::normalize("a-b-c-d"));
+
+  EXPECT_EQ("i386-b-c", Triple::normalize("i386-b-c"));
+  EXPECT_EQ("i386-a-c", Triple::normalize("a-i386-c"));
+  EXPECT_EQ("i386-a-b", Triple::normalize("a-b-i386"));
+  EXPECT_EQ("i386-a-b-c", Triple::normalize("a-b-c-i386"));
+
+  EXPECT_EQ("a-pc-c", Triple::normalize("a-pc-c"));
+  EXPECT_EQ("-pc-b-c", Triple::normalize("pc-b-c"));
+  EXPECT_EQ("a-pc-b", Triple::normalize("a-b-pc"));
+  EXPECT_EQ("a-pc-b-c", Triple::normalize("a-b-c-pc"));
+
+  EXPECT_EQ("a-b-linux", Triple::normalize("a-b-linux"));
+  EXPECT_EQ("--linux-b-c", Triple::normalize("linux-b-c"));
+  EXPECT_EQ("a--linux-c", Triple::normalize("a-linux-c"));
+
+  EXPECT_EQ("i386-pc-a", Triple::normalize("a-pc-i386"));
+  EXPECT_EQ("i386-pc-", Triple::normalize("-pc-i386"));
+  EXPECT_EQ("-pc-linux-c", Triple::normalize("linux-pc-c"));
+  EXPECT_EQ("-pc-linux", Triple::normalize("linux-pc-"));
+
+  EXPECT_EQ("i386", Triple::normalize("i386"));
+  EXPECT_EQ("-pc", Triple::normalize("pc"));
+  EXPECT_EQ("--linux", Triple::normalize("linux"));
+
+  EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-gnu-linux"));
+
+  // Check that normalizing a permutated set of valid components returns a
+  // triple with the unpermuted components.
+  StringRef C[4];
+  for (int Arch = 1+Triple::UnknownArch; Arch < Triple::InvalidArch; ++Arch) {
+    C[0] = Triple::getArchTypeName(Triple::ArchType(Arch));
+    for (int Vendor = 1+Triple::UnknownVendor; Vendor <= Triple::PC;
+         ++Vendor) {
+      C[1] = Triple::getVendorTypeName(Triple::VendorType(Vendor));
+      for (int OS = 1+Triple::UnknownOS; OS <= Triple::Minix; ++OS) {
+        C[2] = Triple::getOSTypeName(Triple::OSType(OS));
+
+        // If a value has multiple interpretations, then the permutation
+        // test will inevitably fail.  Currently this is only the case for
+        // "psp" which parses as both an architecture and an O/S.
+        if (OS == Triple::Psp)
+          continue;
+
+        std::string E = Join(C[0], C[1], C[2]);
+        EXPECT_EQ(E, Triple::normalize(Join(C[0], C[1], C[2])));
+
+        EXPECT_EQ(E, Triple::normalize(Join(C[0], C[2], C[1])));
+        EXPECT_EQ(E, Triple::normalize(Join(C[1], C[2], C[0])));
+        EXPECT_EQ(E, Triple::normalize(Join(C[1], C[0], C[2])));
+        EXPECT_EQ(E, Triple::normalize(Join(C[2], C[0], C[1])));
+        EXPECT_EQ(E, Triple::normalize(Join(C[2], C[1], C[0])));
+
+        for (int Env = 1+Triple::UnknownEnvironment; Env <= Triple::MachO;
+             ++Env) {
+          C[3] = Triple::getEnvironmentTypeName(Triple::EnvironmentType(Env));
+
+          std::string F = Join(C[0], C[1], C[2], C[3]);
+          EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[2], C[3])));
+
+          EXPECT_EQ(F, Triple::normalize(Join(C[0], C[1], C[3], C[2])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[3], C[1])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[0], C[2], C[1], C[3])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[1], C[2])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[0], C[3], C[2], C[1])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[3], C[0])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[1], C[2], C[0], C[3])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[0], C[2])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[1], C[3], C[2], C[0])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[2], C[3])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[1], C[0], C[3], C[2])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[0], C[1])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[2], C[3], C[1], C[0])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[1], C[3])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[2], C[0], C[3], C[1])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[3], C[0])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[2], C[1], C[0], C[3])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[1], C[2])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[3], C[0], C[2], C[1])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[2], C[0])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[3], C[1], C[0], C[2])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[0], C[1])));
+          EXPECT_EQ(F, Triple::normalize(Join(C[3], C[2], C[1], C[0])));
+        }
+      }
+    }
+  }
+
+  EXPECT_EQ("a-b-psp", Triple::normalize("a-b-psp"));
+  EXPECT_EQ("psp-b-c", Triple::normalize("psp-b-c"));
+
+  // Various real-world funky triples.  The value returned by GCC's config.sub
+  // is given in the comment.
+  EXPECT_EQ("i386--mingw32", Triple::normalize("i386-mingw32")); // i386-pc-mingw32
+  EXPECT_EQ("x86_64--linux-gnu", Triple::normalize("x86_64-linux-gnu")); // x86_64-pc-linux-gnu
+  EXPECT_EQ("i486--linux-gnu", Triple::normalize("i486-linux-gnu")); // i486-pc-linux-gnu
+  EXPECT_EQ("i386-redhat-linux", Triple::normalize("i386-redhat-linux")); // i386-redhat-linux-gnu
+  EXPECT_EQ("i686--linux", Triple::normalize("i686-linux")); // i686-pc-linux-gnu
+  EXPECT_EQ("arm-none--eabi", Triple::normalize("arm-none-eabi")); // arm-none-eabi
+}
+
+TEST(TripleTest, MutateName) {
+  Triple T;
+  EXPECT_EQ(Triple::UnknownArch, T.getArch());
+  EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
+  EXPECT_EQ(Triple::UnknownOS, T.getOS());
+  EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());
+
+  T.setArchName("i386");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ("i386--", T.getTriple());
+
+  T.setVendorName("pc");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ("i386-pc-", T.getTriple());
+
+  T.setOSName("linux");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ("i386-pc-linux", T.getTriple());
+
+  T.setEnvironmentName("gnu");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Linux, T.getOS());
+  EXPECT_EQ("i386-pc-linux-gnu", T.getTriple());
+
+  T.setOSName("freebsd");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::FreeBSD, T.getOS());
+  EXPECT_EQ("i386-pc-freebsd-gnu", T.getTriple());
+
+  T.setOSAndEnvironmentName("darwin");
+  EXPECT_EQ(Triple::x86, T.getArch());
+  EXPECT_EQ(Triple::PC, T.getVendor());
+  EXPECT_EQ(Triple::Darwin, T.getOS());
+  EXPECT_EQ("i386-pc-darwin", T.getTriple());
+
+}
+
+}
diff --git a/src/LLVM/unittests/ADT/TwineTest.cpp b/src/LLVM/unittests/ADT/TwineTest.cpp
new file mode 100644
index 0000000..e9cc41d
--- /dev/null
+++ b/src/LLVM/unittests/ADT/TwineTest.cpp
@@ -0,0 +1,87 @@
+//===- TwineTest.cpp - Twine unit tests -----------------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+using namespace llvm;
+
+namespace {
+
+std::string repr(const Twine &Value) {
+  std::string res;
+  llvm::raw_string_ostream OS(res);
+  Value.printRepr(OS);
+  return OS.str();
+}
+
+TEST(TwineTest, Construction) {
+  EXPECT_EQ("", Twine().str());
+  EXPECT_EQ("hi", Twine("hi").str());
+  EXPECT_EQ("hi", Twine(std::string("hi")).str());
+  EXPECT_EQ("hi", Twine(StringRef("hi")).str());
+  EXPECT_EQ("hi", Twine(StringRef(std::string("hi"))).str());
+  EXPECT_EQ("hi", Twine(StringRef("hithere", 2)).str());
+}
+
+TEST(TwineTest, Numbers) {
+  EXPECT_EQ("123", Twine(123U).str());
+  EXPECT_EQ("123", Twine(123).str());
+  EXPECT_EQ("-123", Twine(-123).str());
+  EXPECT_EQ("123", Twine(123).str());
+  EXPECT_EQ("-123", Twine(-123).str());
+
+  EXPECT_EQ("7b", Twine::utohexstr(123).str());
+}
+
+TEST(TwineTest, Characters) {
+  EXPECT_EQ("x", Twine('x').str());
+  EXPECT_EQ("x", Twine(static_cast<unsigned char>('x')).str());
+  EXPECT_EQ("x", Twine(static_cast<signed char>('x')).str());
+}
+
+TEST(TwineTest, Concat) {
+  // Check verse repr, since we care about the actual representation not just
+  // the result.
+
+  // Concat with null.
+  EXPECT_EQ("(Twine null empty)", 
+            repr(Twine("hi").concat(Twine::createNull())));
+  EXPECT_EQ("(Twine null empty)", 
+            repr(Twine::createNull().concat(Twine("hi"))));
+  
+  // Concat with empty.
+  EXPECT_EQ("(Twine cstring:\"hi\" empty)", 
+            repr(Twine("hi").concat(Twine())));
+  EXPECT_EQ("(Twine cstring:\"hi\" empty)", 
+            repr(Twine().concat(Twine("hi"))));
+
+  // Concatenation of unary ropes.
+  EXPECT_EQ("(Twine cstring:\"a\" cstring:\"b\")", 
+            repr(Twine("a").concat(Twine("b"))));
+
+  // Concatenation of other ropes.
+  EXPECT_EQ("(Twine rope:(Twine cstring:\"a\" cstring:\"b\") cstring:\"c\")", 
+            repr(Twine("a").concat(Twine("b")).concat(Twine("c"))));
+  EXPECT_EQ("(Twine cstring:\"a\" rope:(Twine cstring:\"b\" cstring:\"c\"))",
+            repr(Twine("a").concat(Twine("b").concat(Twine("c")))));
+}
+
+TEST(TwineTest, toNullTerminatedStringRef) {
+  SmallString<8> storage;
+  EXPECT_EQ(0, *Twine("hello").toNullTerminatedStringRef(storage).end());
+  EXPECT_EQ(0,
+           *Twine(StringRef("hello")).toNullTerminatedStringRef(storage).end());
+}
+
+  // I suppose linking in the entire code generator to add a unit test to check
+  // the code size of the concat operation is overkill... :)
+
+} // end anonymous namespace
diff --git a/src/LLVM/unittests/ADT/ilistTest.cpp b/src/LLVM/unittests/ADT/ilistTest.cpp
new file mode 100644
index 0000000..09a699a
--- /dev/null
+++ b/src/LLVM/unittests/ADT/ilistTest.cpp
@@ -0,0 +1,44 @@
+//===- llvm/unittest/ADT/APInt.cpp - APInt unit tests ---------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include <ostream>
+#include "gtest/gtest.h"
+#include "llvm/ADT/ilist.h"
+#include "llvm/ADT/ilist_node.h"
+
+using namespace llvm;
+
+namespace {
+
+struct Node : ilist_node<Node> {
+  int Value;
+
+  Node() {}
+  Node(int _Value) : Value(_Value) {}
+};
+
+TEST(ilistTest, Basic) {
+  ilist<Node> List;
+  List.push_back(Node(1));
+  EXPECT_EQ(1, List.back().Value);
+  EXPECT_EQ(0, List.back().getPrevNode());
+  EXPECT_EQ(0, List.back().getNextNode());
+
+  List.push_back(Node(2));
+  EXPECT_EQ(2, List.back().Value);
+  EXPECT_EQ(2, List.front().getNextNode()->Value);
+  EXPECT_EQ(1, List.back().getPrevNode()->Value);
+
+  const ilist<Node> &ConstList = List;
+  EXPECT_EQ(2, ConstList.back().Value);
+  EXPECT_EQ(2, ConstList.front().getNextNode()->Value);
+  EXPECT_EQ(1, ConstList.back().getPrevNode()->Value);
+}
+
+}