Revert "Introduce a string_ostream string builder facilty"

Temporarily back out commits r211749, r211752 and r211754.

llvm-svn: 211814
diff --git a/llvm/lib/Transforms/Instrumentation/DebugIR.cpp b/llvm/lib/Transforms/Instrumentation/DebugIR.cpp
index 56e60e6..f2f1738 100644
--- a/llvm/lib/Transforms/Instrumentation/DebugIR.cpp
+++ b/llvm/lib/Transforms/Instrumentation/DebugIR.cpp
@@ -352,12 +352,14 @@
   }
 
   std::string getTypeName(Type *T) {
-    string_ostream OS;
+    std::string TypeName;
+    raw_string_ostream TypeStream(TypeName);
     if (T)
-      T->print(OS);
+      T->print(TypeStream);
     else
-      OS << "Printing <null> Type";
-    return OS.str();
+      TypeStream << "Printing <null> Type";
+    TypeStream.flush();
+    return TypeName;
   }
 
   /// Returns the MDNode that represents type T if it is already created, or 0
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
index 5af938b..cfeb62e 100644
--- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -316,9 +316,11 @@
       }
       ReturnBlock = new GCOVBlock(i++, os);
 
-      string_ostream FnNameLine;
-      FnNameLine << getFunctionName(SP) << SP.getLineNumber();
-      FuncChecksum = hash_value(FnNameLine.str());
+      std::string FunctionNameAndLine;
+      raw_string_ostream FNLOS(FunctionNameAndLine);
+      FNLOS << getFunctionName(SP) << SP.getLineNumber();
+      FNLOS.flush();
+      FuncChecksum = hash_value(FunctionNameAndLine);
     }
 
     ~GCOVFunction() {
@@ -335,14 +337,15 @@
     }
 
     std::string getEdgeDestinations() {
-      string_ostream EdgeDestinations;
+      std::string EdgeDestinations;
+      raw_string_ostream EDOS(EdgeDestinations);
       Function *F = Blocks.begin()->first->getParent();
       for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
         GCOVBlock &Block = *Blocks[I];
         for (int i = 0, e = Block.OutEdges.size(); i != e; ++i)
-          EdgeDestinations << Block.OutEdges[i]->Number;
+          EDOS << Block.OutEdges[i]->Number;
       }
-      return EdgeDestinations.str();
+      return EdgeDestinations;
     }
 
     uint32_t getFuncChecksum() {
diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
index bb88bc0..4ca0323 100644
--- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp
@@ -2424,7 +2424,8 @@
 
     if (PoisonStack && MS.TrackOrigins) {
       setOrigin(&I, getCleanOrigin());
-      small_string_ostream<2048> StackDescription;
+      SmallString<2048> StackDescriptionStorage;
+      raw_svector_ostream StackDescription(StackDescriptionStorage);
       // We create a string with a description of the stack allocation and
       // pass it into __msan_set_alloca_origin.
       // It will be printed by the run-time if stack-originated UMR is found.
diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
index 744fb24..dd4dd50 100644
--- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
+++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
@@ -835,7 +835,8 @@
       // of line at the module level and to provide a very simple format
       // encoding the information herein. Both of these makes it simpler to
       // parse the annotations by a simple external program.
-      string_ostream os;
+      std::string Str;
+      raw_string_ostream os(Str);
       os << "(" << Inst->getParent()->getParent()->getName() << ",%"
          << Inst->getName() << ")";
 
@@ -848,7 +849,8 @@
       Hash = cast<MDString>(Node->getOperand(0));
     }
   } else if (Argument *Arg = dyn_cast<Argument>(Ptr)) {
-    string_ostream os;
+    std::string str;
+    raw_string_ostream os(str);
     os << "(" << Arg->getParent()->getName() << ",%" << Arg->getName()
        << ")";
     Hash = MDString::get(Arg->getContext(), os.str());
@@ -858,7 +860,8 @@
 }
 
 static std::string SequenceToString(Sequence A) {
-  string_ostream os;
+  std::string str;
+  raw_string_ostream os(str);
   os << A;
   return os.str();
 }
diff --git a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
index 42fd398..cce016a 100644
--- a/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
+++ b/llvm/lib/Transforms/Utils/ASanStackFrameLayout.cpp
@@ -65,7 +65,8 @@
     Vars[i].Alignment = std::max(Vars[i].Alignment, kMinAlignment);
 
   std::stable_sort(Vars.begin(), Vars.end(), CompareVars);
-  small_string_ostream<2048> StackDescription;
+  SmallString<2048> StackDescriptionStorage;
+  raw_svector_ostream StackDescription(StackDescriptionStorage);
   StackDescription << NumVars;
   Layout->FrameAlignment = std::max(Granularity, Vars[0].Alignment);
   SmallVector<uint8_t, 64> &SB(Layout->ShadowBytes);
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 2338d29..cb8a41d 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -212,23 +212,24 @@
 /// Optimization analysis message produced during vectorization. Messages inform
 /// the user why vectorization did not occur.
 class Report {
-  string_ostream Message;
+  std::string Message;
+  raw_string_ostream Out;
   Instruction *Instr;
 
 public:
-  Report(Instruction *I = nullptr) : Instr(I) {
-    Message << "loop not vectorized: ";
+  Report(Instruction *I = nullptr) : Out(Message), Instr(I) {
+    Out << "loop not vectorized: ";
   }
 
   template <typename A> Report &operator<<(const A &Value) {
-    Message << Value;
+    Out << Value;
     return *this;
   }
 
   Instruction *getInstr() { return Instr; }
 
-  StringRef str() { return Message.str(); }
-  operator Twine() { return Message.str(); }
+  std::string &str() { return Out.str(); }
+  operator Twine() { return Out.str(); }
 };
 
 /// InnerLoopVectorizer vectorizes loops which contain only one basic
@@ -502,17 +503,18 @@
 #ifndef NDEBUG
 /// \return string containing a file name and a line # for the given loop.
 static std::string getDebugLocString(const Loop *L) {
-  if (!L)
-    return std::string();
-
-  string_ostream OS;
-  const DebugLoc LoopDbgLoc = L->getStartLoc();
-  if (!LoopDbgLoc.isUnknown())
-    LoopDbgLoc.print(L->getHeader()->getContext(), OS);
-  else
-    // Just print the module name.
-    OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
-  return OS.str();
+  std::string Result;
+  if (L) {
+    raw_string_ostream OS(Result);
+    const DebugLoc LoopDbgLoc = L->getStartLoc();
+    if (!LoopDbgLoc.isUnknown())
+      LoopDbgLoc.print(L->getHeader()->getContext(), OS);
+    else
+      // Just print the module name.
+      OS << L->getHeader()->getParent()->getParent()->getModuleIdentifier();
+    OS.flush();
+  }
+  return Result;
 }
 #endif