[llvm-commits] [llvm] r104873 - in /llvm/trunk/tools: llc/llc.cpp llvm-mc/llvm-mc.cpp opt/opt.cpp

Dan Gohman gohman at apple.com
Thu May 27 12:47:36 PDT 2010


Author: djg
Date: Thu May 27 14:47:36 2010
New Revision: 104873

URL: http://llvm.org/viewvc/llvm-project?rev=104873&view=rev
Log:
Avoid calling outs() and fouts() when the stream isn't really needed.

Modified:
    llvm/trunk/tools/llc/llc.cpp
    llvm/trunk/tools/llvm-mc/llvm-mc.cpp
    llvm/trunk/tools/opt/opt.cpp

Modified: llvm/trunk/tools/llc/llc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llc/llc.cpp?rev=104873&r1=104872&r2=104873&view=diff
==============================================================================
--- llvm/trunk/tools/llc/llc.cpp (original)
+++ llvm/trunk/tools/llc/llc.cpp Thu May 27 14:47:36 2010
@@ -124,7 +124,8 @@
                                               const char *ProgName) {
   if (OutputFilename != "") {
     if (OutputFilename == "-")
-      return &fouts();
+      return new formatted_raw_ostream(outs(),
+                                       formatted_raw_ostream::PRESERVE_STREAM);
 
     // Make sure that the Out file gets unlinked from the disk if we get a
     // SIGINT
@@ -147,7 +148,8 @@
 
   if (InputFilename == "-") {
     OutputFilename = "-";
-    return &fouts();
+    return new formatted_raw_ostream(outs(),
+                                     formatted_raw_ostream::PRESERVE_STREAM);
   }
 
   OutputFilename = GetFileNameRoot(InputFilename);
@@ -332,7 +334,7 @@
                                  DisableVerify)) {
     errs() << argv[0] << ": target does not support generation of this"
            << " file type!\n";
-    if (Out != &fouts()) delete Out;
+    delete Out;
     // And the Out file is empty and useless, so remove it now.
     sys::Path(OutputFilename).eraseFromDisk();
     return 1;
@@ -340,8 +342,8 @@
 
   PM.run(mod);
 
-  // Delete the ostream if it's not a stdout stream
-  if (Out != &fouts()) delete Out;
+  // Delete the ostream.
+  delete Out;
 
   return 0;
 }

Modified: llvm/trunk/tools/llvm-mc/llvm-mc.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mc/llvm-mc.cpp?rev=104873&r1=104872&r2=104873&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mc/llvm-mc.cpp (original)
+++ llvm/trunk/tools/llvm-mc/llvm-mc.cpp Thu May 27 14:47:36 2010
@@ -323,8 +323,7 @@
   Parser.setTargetParser(*TAP.get());
 
   int Res = Parser.Run(NoInitialTextSection);
-  if (Out != &fouts())
-    delete Out;
+  delete Out;
 
   // Delete output on errors.
   if (Res && OutputFilename != "-")

Modified: llvm/trunk/tools/opt/opt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=104873&r1=104872&r2=104873&view=diff
==============================================================================
--- llvm/trunk/tools/opt/opt.cpp (original)
+++ llvm/trunk/tools/opt/opt.cpp Thu May 27 14:47:36 2010
@@ -378,8 +378,12 @@
 
   // Figure out what stream we are supposed to write to...
   // FIXME: outs() is not binary!
-  raw_ostream *Out = &outs();  // Default to printing to stdout...
-  if (OutputFilename != "-") {
+  raw_ostream *Out = 0;
+  bool DeleteStream = true;
+  if (OutputFilename == "-") {
+    Out = &outs();  // Default to printing to stdout...
+    DeleteStream = false;
+  } else {
     if (NoOutput || AnalyzeOnly) {
       errs() << "WARNING: The -o (output filename) option is ignored when\n"
                 "the --disable-output or --analyze options are used.\n";
@@ -540,7 +544,7 @@
   Passes.run(*M.get());
 
   // Delete the raw_fd_ostream.
-  if (Out != &outs())
+  if (DeleteStream)
     delete Out;
   return 0;
 }





More information about the llvm-commits mailing list