summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-05-27 19:47:36 +0000
committerDan Gohman <gohman@apple.com>2010-05-27 19:47:36 +0000
commit174f57668feb363c63f87c392e34bac01856cd15 (patch)
treec2aaf8ca6aab35f99def3187cd7c3bf1aad94da0 /llvm
parent91ad65e8b7752755cee624ba45c186ba0146b9f5 (diff)
downloadbcm5719-llvm-174f57668feb363c63f87c392e34bac01856cd15.tar.gz
bcm5719-llvm-174f57668feb363c63f87c392e34bac01856cd15.zip
Avoid calling outs() and fouts() when the stream isn't really needed.
llvm-svn: 104873
Diffstat (limited to 'llvm')
-rw-r--r--llvm/tools/llc/llc.cpp12
-rw-r--r--llvm/tools/llvm-mc/llvm-mc.cpp3
-rw-r--r--llvm/tools/opt/opt.cpp10
3 files changed, 15 insertions, 10 deletions
diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp
index f3eed56accd..199a1a92043 100644
--- a/llvm/tools/llc/llc.cpp
+++ b/llvm/tools/llc/llc.cpp
@@ -124,7 +124,8 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
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 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
if (InputFilename == "-") {
OutputFilename = "-";
- return &fouts();
+ return new formatted_raw_ostream(outs(),
+ formatted_raw_ostream::PRESERVE_STREAM);
}
OutputFilename = GetFileNameRoot(InputFilename);
@@ -332,7 +334,7 @@ int main(int argc, char **argv) {
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 @@ int main(int argc, char **argv) {
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;
}
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index a114ab0c3f3..6de6bfb3c8a 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -323,8 +323,7 @@ static int AssembleInput(const char *ProgName) {
Parser.setTargetParser(*TAP.get());
int Res = Parser.Run(NoInitialTextSection);
- if (Out != &fouts())
- delete Out;
+ delete Out;
// Delete output on errors.
if (Res && OutputFilename != "-")
diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp
index 51b920f5331..a29555ccf95 100644
--- a/llvm/tools/opt/opt.cpp
+++ b/llvm/tools/opt/opt.cpp
@@ -378,8 +378,12 @@ int main(int argc, char **argv) {
// 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 @@ int main(int argc, char **argv) {
Passes.run(*M.get());
// Delete the raw_fd_ostream.
- if (Out != &outs())
+ if (DeleteStream)
delete Out;
return 0;
}
OpenPOWER on IntegriCloud