Don't lower splat vector load to relative to the esp if the
[oota-llvm.git] / lib / Support / FoldingSet.cpp
index 3a1a0cd842e050f1fc0c04122e0ac3e8d9c20e2d..954dc77dff1e954d7f7e40ee97c3453730b4c9c0 100644 (file)
@@ -15,6 +15,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/ADT/FoldingSet.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/MathExtras.h"
 #include <cassert>
 #include <cstring>
@@ -50,7 +51,7 @@ void FoldingSetNodeID::AddInteger(unsigned long I) {
   else if (sizeof(long) == sizeof(long long)) {
     AddInteger((unsigned long long)I);
   } else {
-    assert(0 && "unexpected sizeof(long)");
+    llvm_unreachable("unexpected sizeof(long)");
   }
 }
 void FoldingSetNodeID::AddInteger(long long I) {
@@ -62,14 +63,14 @@ void FoldingSetNodeID::AddInteger(unsigned long long I) {
     Bits.push_back(unsigned(I >> 32));
 }
 
-void FoldingSetNodeID::AddString(const char *String) {
-  unsigned Size = static_cast<unsigned>(strlen(String));
+void FoldingSetNodeID::AddString(StringRef String) {
+  unsigned Size =  String.size();
   Bits.push_back(Size);
   if (!Size) return;
 
   unsigned Units = Size / 4;
   unsigned Pos = 0;
-  const unsigned *Base = (const unsigned *)String;
+  const unsigned *Base = (const unsigned*) String.data();
   
   // If the string is aligned do a bulk transfer.
   if (!((intptr_t)Base & 3)) {
@@ -77,44 +78,7 @@ void FoldingSetNodeID::AddString(const char *String) {
     Pos = (Units + 1) * 4;
   } else {
     // Otherwise do it the hard way.
-    for ( Pos += 4; Pos <= Size; Pos += 4) {
-      unsigned V = ((unsigned char)String[Pos - 4] << 24) |
-                   ((unsigned char)String[Pos - 3] << 16) |
-                   ((unsigned char)String[Pos - 2] << 8) |
-                    (unsigned char)String[Pos - 1];
-      Bits.push_back(V);
-    }
-  }
-  
-  // With the leftover bits.
-  unsigned V = 0;
-  // Pos will have overshot size by 4 - #bytes left over. 
-  switch (Pos - Size) {
-  case 1: V = (V << 8) | (unsigned char)String[Size - 3]; // Fall thru.
-  case 2: V = (V << 8) | (unsigned char)String[Size - 2]; // Fall thru.
-  case 3: V = (V << 8) | (unsigned char)String[Size - 1]; break;
-  default: return; // Nothing left.
-  }
-
-  Bits.push_back(V);
-}
-
-void FoldingSetNodeID::AddString(const std::string &String) {
-  unsigned Size = static_cast<unsigned>(String.size());
-  Bits.push_back(Size);
-  if (!Size) return;
-
-  unsigned Units = Size / 4;
-  unsigned Pos = 0;
-  const unsigned *Base = (const unsigned *)String.data();
-  
-  // If the string is aligned do a bulk transfer.
-  if (!((intptr_t)Base & 3)) {
-    Bits.append(Base, Base + Units);
-    Pos = (Units + 1) * 4;
-  } else {
-    // Otherwise do it the hard way.
-    for ( Pos += 4; Pos <= Size; Pos += 4) {
+    for (Pos += 4; Pos <= Size; Pos += 4) {
       unsigned V = ((unsigned char)String[Pos - 4] << 24) |
                    ((unsigned char)String[Pos - 3] << 16) |
                    ((unsigned char)String[Pos - 2] << 8) |