Convert to using llvm streams instead of iostreams.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31989 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index a7269ff..26bcb43 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -745,7 +745,7 @@
     assert(Offset1<Offset2 && "There is at least one different constant here!");
 
     if ((uint64_t)(Offset2-Offset1) >= SizeMax) {
-      //std::cerr << "Determined that these two GEP's don't alias ["
+      //llvm_cerr << "Determined that these two GEP's don't alias ["
       //          << SizeMax << " bytes]: \n" << *GEP1 << *GEP2;
       return NoAlias;
     }
diff --git a/lib/Analysis/DataStructure/BottomUpClosure.cpp b/lib/Analysis/DataStructure/BottomUpClosure.cpp
index 0f48850..19b3ec1 100644
--- a/lib/Analysis/DataStructure/BottomUpClosure.cpp
+++ b/lib/Analysis/DataStructure/BottomUpClosure.cpp
@@ -13,6 +13,7 @@
 // applications like alias analysis.
 //
 //===----------------------------------------------------------------------===//
+
 #define DEBUG_TYPE "bu_dsa"
 #include "llvm/Analysis/DataStructure/DataStructure.h"
 #include "llvm/Analysis/DataStructure/DSGraph.h"
@@ -22,7 +23,6 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/Timer.h"
-#include <iostream>
 using namespace llvm;
 
 namespace {
@@ -501,7 +501,7 @@
     DSG->getNodeForValue(F->arg_begin()).mergeWith(N);
 
   } else {
-    std::cerr << "Unrecognized external function: " << F->getName() << "\n";
+    llvm_cerr << "Unrecognized external function: " << F->getName() << "\n";
     abort();
   }
 
@@ -588,21 +588,21 @@
         ++NumBUInlines;
       } else {
         if (!Printed)
-          std::cerr << "In Fns: " << Graph.getFunctionNames() << "\n";
-        std::cerr << "  calls " << CalledFuncs.size()
+          llvm_cerr << "In Fns: " << Graph.getFunctionNames() << "\n";
+        llvm_cerr << "  calls " << CalledFuncs.size()
                   << " fns from site: " << CS.getCallSite().getInstruction()
                   << "  " << *CS.getCallSite().getInstruction();
-        std::cerr << "   Fns =";
+        llvm_cerr << "   Fns =";
         unsigned NumPrinted = 0;
 
         for (std::vector<Function*>::iterator I = CalledFuncs.begin(),
                E = CalledFuncs.end(); I != E; ++I) {
-          if (NumPrinted++ < 8) std::cerr << " " << (*I)->getName();
+          if (NumPrinted++ < 8) llvm_cerr << " " << (*I)->getName();
 
           // Add the call edges to the call graph.
           ActualCallees.insert(std::make_pair(TheCall, *I));
         }
-        std::cerr << "\n";
+        llvm_cerr << "\n";
 
         // See if we already computed a graph for this set of callees.
         std::sort(CalledFuncs.begin(), CalledFuncs.end());
@@ -645,7 +645,7 @@
           // Clean up the final graph!
           GI->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
         } else {
-          std::cerr << "***\n*** RECYCLED GRAPH ***\n***\n";
+          llvm_cerr << "***\n*** RECYCLED GRAPH ***\n***\n";
         }
 
         GI = IndCallGraph.first;
@@ -685,7 +685,7 @@
          E = MainSM.global_end(); I != E; ++I)
     RC.getClonedNH(MainSM[*I]);
 
-  //Graph.writeGraphToFile(std::cerr, "bu_" + F.getName());
+  //Graph.writeGraphToFile(llvm_cerr, "bu_" + F.getName());
 }
 
 static const Function *getFnForValue(const Value *V) {
@@ -746,8 +746,8 @@
     return;
   }
 
-  std::cerr << *From;
-  std::cerr << *To;
+  llvm_cerr << *From;
+  llvm_cerr << *To;
   assert(0 && "Do not know how to copy this yet!");
   abort();
 }
diff --git a/lib/Analysis/DataStructure/CallTargets.cpp b/lib/Analysis/DataStructure/CallTargets.cpp
index 8b33cb0..5850749 100644
--- a/lib/Analysis/DataStructure/CallTargets.cpp
+++ b/lib/Analysis/DataStructure/CallTargets.cpp
@@ -23,9 +23,9 @@
 #include "llvm/Analysis/DataStructure/DSGraph.h"
 #include "llvm/Analysis/DataStructure/CallTargets.h"
 #include "llvm/ADT/Statistic.h"
-#include <iostream>
+#include "llvm/Support/Streams.h"
+#include <ostream>
 #include "llvm/Constants.h"
-
 using namespace llvm;
 
 namespace {
@@ -58,7 +58,7 @@
               } 
               if (N->isComplete() && !IndMap[cs].size()) {
                 ++CompleteEmpty;
-                std::cerr << "Call site empty: '"
+                llvm_cerr << "Call site empty: '"
                 << cs.getInstruction()->getName() 
                           << "' In '"
                 << cs.getInstruction()->getParent()->getParent()->getName()
diff --git a/lib/Analysis/DataStructure/DataStructure.cpp b/lib/Analysis/DataStructure/DataStructure.cpp
index 8b8bde0..6eee541 100644
--- a/lib/Analysis/DataStructure/DataStructure.cpp
+++ b/lib/Analysis/DataStructure/DataStructure.cpp
@@ -25,6 +25,7 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SCCIterator.h"
 #include "llvm/ADT/Statistic.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/Support/Timer.h"
 #include <iostream>
 #include <algorithm>
@@ -1262,7 +1263,7 @@
 }
 
 // dump - Allow inspection of graph in a debugger.
-void DSGraph::dump() const { print(std::cerr); }
+void DSGraph::dump() const { print(llvm_cerr); }
 
 
 /// remapLinks - Change all of the Links in the current node according to the
diff --git a/lib/Analysis/DataStructure/DataStructureStats.cpp b/lib/Analysis/DataStructure/DataStructureStats.cpp
index a73fc96..469ab2e 100644
--- a/lib/Analysis/DataStructure/DataStructureStats.cpp
+++ b/lib/Analysis/DataStructure/DataStructureStats.cpp
@@ -17,8 +17,9 @@
 #include "llvm/Instructions.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/InstVisitor.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/ADT/Statistic.h"
-#include <iostream>
+#include <ostream>
 using namespace llvm;
 
 namespace {
@@ -91,7 +92,7 @@
         totalNumCallees  += Callees.size();
         ++numIndirectCalls;
       } else
-        std::cerr << "WARNING: No callee in Function '" << F.getName()
+        llvm_cerr << "WARNING: No callee in Function '" << F.getName()
                   << "' at call: \n"
                   << *I->getCallSite().getInstruction();
     }
@@ -100,7 +101,7 @@
   NumIndirectCalls += numIndirectCalls;
 
   if (numIndirectCalls)
-    std::cout << "  In function " << F.getName() << ":  "
+    llvm_cout << "  In function " << F.getName() << ":  "
               << (totalNumCallees / (double) numIndirectCalls)
               << " average callees per indirect call\n";
 }
diff --git a/lib/Analysis/DataStructure/EquivClassGraphs.cpp b/lib/Analysis/DataStructure/EquivClassGraphs.cpp
index 4b1eaa9..38aaf0b 100644
--- a/lib/Analysis/DataStructure/EquivClassGraphs.cpp
+++ b/lib/Analysis/DataStructure/EquivClassGraphs.cpp
@@ -26,7 +26,6 @@
 #include "llvm/ADT/Statistic.h"
 #include "llvm/ADT/EquivalenceClasses.h"
 #include "llvm/ADT/STLExtras.h"
-#include <iostream>
 using namespace llvm;
 
 namespace {
@@ -91,7 +90,7 @@
   if (MainFunc && !MainFunc->isExternal()) {
     processSCC(getOrCreateGraph(*MainFunc), Stack, NextID, ValMap);
   } else {
-    std::cerr << "Fold Graphs: No 'main' function found!\n";
+    llvm_cerr << "Fold Graphs: No 'main' function found!\n";
   }
 
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
@@ -173,8 +172,8 @@
       FuncECs.insert(I->second);        // -- Make sure function has equiv class
       FirstFunc = I->second;            // -- First callee at this site
     } else {                            // Else indirect call
-      // DEBUG(std::cerr << "CALLEE: " << I->second->getName()
-      //       << " from : " << I->first);
+      // DOUT << "CALLEE: " << I->second->getName()
+      //      << " from : " << I->first;
       if (I->first != LastInst) {
         // This is the first callee from this call site.
         LastInst = I->first;
diff --git a/lib/Analysis/DataStructure/GraphChecker.cpp b/lib/Analysis/DataStructure/GraphChecker.cpp
index 50a41f2..cef3efe 100644
--- a/lib/Analysis/DataStructure/GraphChecker.cpp
+++ b/lib/Analysis/DataStructure/GraphChecker.cpp
@@ -26,10 +26,9 @@
 #include "llvm/Analysis/DataStructure/DataStructure.h"
 #include "llvm/Analysis/DataStructure/DSGraph.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/Value.h"
-#include <iostream>
 #include <set>
-
 using namespace llvm;
 
 namespace {
@@ -85,7 +84,7 @@
 DSGC::DSGC() {
   if (!AbortIfAnyCollapsed && AbortIfCollapsed.empty() &&
       CheckFlags.empty() && AbortIfMerged.empty()) {
-    std::cerr << "The -datastructure-gc is useless if you don't specify any"
+    llvm_cerr << "The -datastructure-gc is useless if you don't specify any"
                  " -dsgc-* options.  See the -help-hidden output for a list.\n";
     abort();
   }
@@ -124,8 +123,8 @@
     for (DSGraph::node_const_iterator I = G.node_begin(), E = G.node_end();
          I != E; ++I)
       if (I->isNodeCompletelyFolded()) {
-        std::cerr << "Node is collapsed: ";
-        I->print(std::cerr, &G);
+        llvm_cerr << "Node is collapsed: ";
+        I->print(llvm_cerr, &G);
         abort();
       }
   }
@@ -143,7 +142,7 @@
            E = CheckFlags.end(); I != E; ++I) {
       std::string::size_type ColonPos = I->rfind(':');
       if (ColonPos == std::string::npos) {
-        std::cerr << "Error: '" << *I
+        llvm_cerr << "Error: '" << *I
                << "' is an invalid value for the --dsgc-check-flags option!\n";
         abort();
       }
@@ -159,7 +158,7 @@
         case 'M': Flags |= DSNode::Modified;    break;
         case 'R': Flags |= DSNode::Read;        break;
         case 'A': Flags |= DSNode::Array;       break;
-        default: std::cerr << "Invalid DSNode flag!\n"; abort();
+        default: llvm_cerr << "Invalid DSNode flag!\n"; abort();
         }
       CheckFlagsM[std::string(I->begin(), I->begin()+ColonPos)] = Flags;
     }
@@ -177,25 +176,25 @@
 
         // Verify it is not collapsed if it is not supposed to be...
         if (N->isNodeCompletelyFolded() && AbortIfCollapsedS.count(Name)) {
-          std::cerr << "Node for value '%" << Name << "' is collapsed: ";
-          N->print(std::cerr, &G);
+          llvm_cerr << "Node for value '%" << Name << "' is collapsed: ";
+          N->print(llvm_cerr, &G);
           abort();
         }
 
         if (CheckFlagsM.count(Name) && CheckFlagsM[Name] != N->getNodeFlags()) {
-          std::cerr << "Node flags are not as expected for node: " << Name 
+          llvm_cerr << "Node flags are not as expected for node: " << Name 
                     << " (" << CheckFlagsM[Name] << ":" <<N->getNodeFlags()
                     << ")\n";
-          N->print(std::cerr, &G);
+          N->print(llvm_cerr, &G);
           abort();
         }
 
         // Verify that it is not merged if it is not supposed to be...
         if (AbortIfMergedS.count(Name)) {
           if (AbortIfMergedNodes.count(N)) {
-            std::cerr << "Nodes for values '%" << Name << "' and '%"
+            llvm_cerr << "Nodes for values '%" << Name << "' and '%"
                       << AbortIfMergedNodes[N] << "' is merged: ";
-            N->print(std::cerr, &G);
+            N->print(llvm_cerr, &G);
             abort();
           }
           AbortIfMergedNodes[N] = Name;
diff --git a/tools/llvm-dis/llvm-dis.cpp b/tools/llvm-dis/llvm-dis.cpp
index df0737a..8c2b3fe 100644
--- a/tools/llvm-dis/llvm-dis.cpp
+++ b/tools/llvm-dis/llvm-dis.cpp
@@ -21,10 +21,11 @@
 #include "llvm/Bytecode/Reader.h"
 #include "llvm/Assembly/PrintModulePass.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/System/Signals.h"
+#include <iostream>
 #include <fstream>
 #include <memory>
-
 using namespace llvm;
 
 static cl::opt<std::string>
@@ -47,11 +48,11 @@
 
     std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, &ErrorMessage));
     if (M.get() == 0) {
-      std::cerr << argv[0] << ": ";
+      llvm_cerr << argv[0] << ": ";
       if (ErrorMessage.size())
-        std::cerr << ErrorMessage << "\n";
+        llvm_cerr << ErrorMessage << "\n";
       else
-        std::cerr << "bytecode didn't read correctly.\n";
+        llvm_cerr << "bytecode didn't read correctly.\n";
       return 1;
     }
 
@@ -59,7 +60,7 @@
       if (OutputFilename != "-") { // Not stdout?
         if (!Force && std::ifstream(OutputFilename.c_str())) {
           // If force is not specified, make sure not to overwrite a file!
-          std::cerr << argv[0] << ": error opening '" << OutputFilename
+          llvm_cerr << argv[0] << ": error opening '" << OutputFilename
                     << "': file exists! Sending to standard output.\n";
         } else {
           Out = new std::ofstream(OutputFilename.c_str());
@@ -80,7 +81,7 @@
 
         if (!Force && std::ifstream(OutputFilename.c_str())) {
           // If force is not specified, make sure not to overwrite a file!
-          std::cerr << argv[0] << ": error opening '" << OutputFilename
+          llvm_cerr << argv[0] << ": error opening '" << OutputFilename
                     << "': file exists! Sending to standard output.\n";
         } else {
           Out = new std::ofstream(OutputFilename.c_str());
@@ -93,14 +94,15 @@
     }
 
     if (!Out->good()) {
-      std::cerr << argv[0] << ": error opening " << OutputFilename
+      llvm_cerr << argv[0] << ": error opening " << OutputFilename
                 << ": sending to stdout instead!\n";
       Out = &std::cout;
     }
 
     // All that llvm-dis does is write the assembly to a file.
     PassManager Passes;
-    Passes.add(new PrintModulePass(Out));
+    llvm_ostream L(*Out);
+    Passes.add(new PrintModulePass(&L));
     Passes.run(*M.get());
 
     if (Out != &std::cout) {
@@ -109,9 +111,9 @@
     }
     return 0;
   } catch (const std::string& msg) {
-    std::cerr << argv[0] << ": " << msg << "\n";
+    llvm_cerr << argv[0] << ": " << msg << "\n";
   } catch (...) {
-    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+    llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
   }
   return 1;
 }
diff --git a/tools/opt/opt.cpp b/tools/opt/opt.cpp
index 5a6adcd..502118e 100644
--- a/tools/opt/opt.cpp
+++ b/tools/opt/opt.cpp
@@ -23,6 +23,7 @@
 #include "llvm/Support/PassNameParser.h"
 #include "llvm/System/Signals.h"
 #include "llvm/Support/PluginLoader.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/Support/SystemUtils.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/LinkAllPasses.h"
@@ -84,9 +85,9 @@
 
   virtual bool runOnModule(Module &M) {
     if (!Quiet) {
-      std::cout << "Printing analysis '" << PassToPrint->getPassName() 
+      llvm_cout << "Printing analysis '" << PassToPrint->getPassName() 
                 << "':\n";
-      getAnalysisID<Pass>(PassToPrint).print(std::cout, &M);
+      getAnalysisID<Pass>(PassToPrint).print(llvm_cout, &M);
     }
 
     // Get and print pass...
@@ -107,11 +108,11 @@
 
   virtual bool runOnFunction(Function &F) {
     if (!Quiet) {
-      std::cout << "Printing analysis '" << PassToPrint->getPassName()
+      llvm_cout << "Printing analysis '" << PassToPrint->getPassName()
 		<< "' for function '" << F.getName() << "':\n";
     }
     // Get and print pass...
-    getAnalysisID<Pass>(PassToPrint).print(std::cout, F.getParent());
+    getAnalysisID<Pass>(PassToPrint).print(llvm_cout, F.getParent());
     return false;
   }
 
@@ -129,13 +130,13 @@
 
   virtual bool runOnBasicBlock(BasicBlock &BB) {
     if (!Quiet) {
-      std::cout << "Printing Analysis info for BasicBlock '" << BB.getName()
+      llvm_cout << "Printing Analysis info for BasicBlock '" << BB.getName()
 		<< "': Pass " << PassToPrint->getPassName() << ":\n";
     }
 
     // Get and print pass...
     getAnalysisID<Pass>(PassToPrint).print(
-      std::cout, BB.getParent()->getParent());
+      llvm_cout, BB.getParent()->getParent());
     return false;
   }
 
@@ -168,11 +169,11 @@
     // Load the input module...
     std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename, &ErrorMessage));
     if (M.get() == 0) {
-      std::cerr << argv[0] << ": ";
+      llvm_cerr << argv[0] << ": ";
       if (ErrorMessage.size())
-        std::cerr << ErrorMessage << "\n";
+        llvm_cerr << ErrorMessage << "\n";
       else
-        std::cerr << "bytecode didn't read correctly.\n";
+        llvm_cerr << "bytecode didn't read correctly.\n";
       return 1;
     }
 
@@ -182,7 +183,7 @@
     if (OutputFilename != "-") {
       if (!Force && std::ifstream(OutputFilename.c_str())) {
         // If force is not specified, make sure not to overwrite a file!
-        std::cerr << argv[0] << ": error opening '" << OutputFilename
+        llvm_cerr << argv[0] << ": error opening '" << OutputFilename
                   << "': file exists!\n"
                   << "Use -f command line argument to force output\n";
         return 1;
@@ -192,7 +193,7 @@
       Out = new std::ofstream(OutputFilename.c_str(), io_mode);
 
       if (!Out->good()) {
-        std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
+        llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
         return 1;
       }
 
@@ -226,7 +227,7 @@
         assert(target.get() && "Could not allocate target machine!");
         P = PassInf->getTargetCtor()(*target.get());
       } else
-        std::cerr << argv[0] << ": cannot create pass: "
+        llvm_cerr << argv[0] << ": cannot create pass: "
                   << PassInf->getPassName() << "\n";
       if (P) {
         Passes.add(P);
@@ -242,7 +243,7 @@
       }
       
       if (PrintEachXForm)
-        Passes.add(new PrintModulePass(&std::cerr));
+        Passes.add(new PrintModulePass(&llvm_cerr));
     }
 
     // Check that the module is well formed on completion of optimization
@@ -259,9 +260,9 @@
     return 0;
 
   } catch (const std::string& msg) {
-    std::cerr << argv[0] << ": " << msg << "\n";
+    llvm_cerr << argv[0] << ": " << msg << "\n";
   } catch (...) {
-    std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
+    llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
   }
   return 1;
 }