llvm.org GIT mirror llvm / df71866
Simplify memory management with std::unique_ptr. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@255831 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 3 years ago
3 changed file(s) with 23 addition(s) and 27 deletion(s). Raw diff Collapse all Expand all
2727
2828 #include "llvm/Support/Atomic.h"
2929 #include "llvm/Support/Valgrind.h"
30 #include
3031
3132 namespace llvm {
3233 class raw_ostream;
34 class raw_fd_ostream;
3335
3436 class Statistic {
3537 public:
169171 /// \brief Check if statistics are enabled.
170172 bool AreStatisticsEnabled();
171173
174 /// \brief Return a file stream to print our output on.
175 std::unique_ptr CreateInfoOutputFile();
176
172177 /// \brief Print statistics to the file returned by CreateInfoOutputFile().
173178 void PrintStatistics();
174179
3232 #include
3333 #include
3434 using namespace llvm;
35
36 // CreateInfoOutputFile - Return a file stream to print our output on.
37 namespace llvm { extern raw_ostream *CreateInfoOutputFile(); }
3835
3936 /// -stats - Command line option to cause transformations to emit stats about
4037 /// what they did.
144141 if (Stats.Stats.empty()) return;
145142
146143 // Get the stream to write to.
147 raw_ostream &OutStream = *CreateInfoOutputFile();
148 PrintStatistics(OutStream);
149 delete &OutStream; // Close the file.
144 std::unique_ptr OutStream = CreateInfoOutputFile();
145 PrintStatistics(*OutStream);
146
150147 #else
151148 // Check if the -stats option is set instead of checking
152149 // !Stats.Stats.empty(). In release builds, Statistics operators
153150 // do nothing, so stats are never Registered.
154151 if (Enabled) {
155152 // Get the stream to write to.
156 raw_ostream &OutStream = *CreateInfoOutputFile();
157 OutStream << "Statistics are disabled. "
158 << "Build with asserts or with -DLLVM_ENABLE_STATS\n";
159 OutStream.flush();
160 delete &OutStream; // Close the file.
153 std::unique_ptr OutStream = CreateInfoOutputFile();
154 (*OutStream) << "Statistics are disabled. "
155 << "Build with asserts or with -DLLVM_ENABLE_STATS\n";
161156 }
162157 #endif
163158 }
1111 //===----------------------------------------------------------------------===//
1212
1313 #include "llvm/Support/Timer.h"
14 #include "llvm/ADT/Statistic.h"
1415 #include "llvm/ADT/StringMap.h"
1516 #include "llvm/Support/CommandLine.h"
1617 #include "llvm/Support/FileSystem.h"
2021 #include "llvm/Support/Process.h"
2122 #include "llvm/Support/raw_ostream.h"
2223 using namespace llvm;
23
24 // CreateInfoOutputFile - Return a file stream to print our output on.
25 namespace llvm { extern raw_ostream *CreateInfoOutputFile(); }
2624
2725 // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
2826 // of constructor/destructor ordering being unspecified by C++. Basically the
5149 cl::Hidden, cl::location(getLibSupportInfoOutputFilename()));
5250 }
5351
54 // CreateInfoOutputFile - Return a file stream to print our output on.
55 raw_ostream *llvm::CreateInfoOutputFile() {
52 // Return a file stream to print our output on.
53 std::unique_ptr llvm::CreateInfoOutputFile() {
5654 const std::string &OutputFilename = getLibSupportInfoOutputFilename();
5755 if (OutputFilename.empty())
58 return new raw_fd_ostream(2, false); // stderr.
56 return llvm::make_unique(2, false); // stderr.
5957 if (OutputFilename == "-")
60 return new raw_fd_ostream(1, false); // stdout.
61
58 return llvm::make_unique(1, false); // stdout.
59
6260 // Append mode is used because the info output file is opened and closed
6361 // each time -stats or -time-passes wants to print output to it. To
6462 // compensate for this, the test-suite Makefiles have code to delete the
6563 // info output file before running commands which write to it.
6664 std::error_code EC;
67 raw_ostream *Result = new raw_fd_ostream(OutputFilename, EC,
68 sys::fs::F_Append | sys::fs::F_Text);
65 auto Result = llvm::make_unique(
66 OutputFilename, EC, sys::fs::F_Append | sys::fs::F_Text);
6967 if (!EC)
7068 return Result;
71
69
7270 errs() << "Error opening info-output-file '"
7371 << OutputFilename << " for appending!\n";
74 delete Result;
75 return new raw_fd_ostream(2, false); // stderr.
72 return llvm::make_unique(2, false); // stderr.
7673 }
7774
7875
291288 // them were started.
292289 if (FirstTimer || TimersToPrint.empty())
293290 return;
294
295 raw_ostream *OutStream = CreateInfoOutputFile();
291
292 std::unique_ptr OutStream = CreateInfoOutputFile();
296293 PrintQueuedTimers(*OutStream);
297 delete OutStream; // Close the file.
298294 }
299295
300296 void TimerGroup::addTimer(Timer &T) {