#include "llvm/ADT/Statistic.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/ManagedStatic.h"
#include <cstring>
using namespace llvm;
-// CreateInfoOutputFile - Return a file stream to print our output on.
-namespace llvm { extern raw_ostream *CreateInfoOutputFile(); }
-
/// -stats - Command line option to cause transformations to emit stats about
/// what they did.
///
}
}
-namespace {
-
-struct NameCompare {
- bool operator()(const Statistic *LHS, const Statistic *RHS) const {
- int Cmp = std::strcmp(LHS->getName(), RHS->getName());
- if (Cmp != 0) return Cmp < 0;
-
- // Secondary key is the description.
- return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0;
- }
-};
-
-}
-
// Print information when destroyed, iff command line option is specified.
StatisticInfo::~StatisticInfo() {
llvm::PrintStatistics();
}
// Sort the fields by name.
- std::stable_sort(Stats.Stats.begin(), Stats.Stats.end(), NameCompare());
+ std::stable_sort(Stats.Stats.begin(), Stats.Stats.end(),
+ [](const Statistic *LHS, const Statistic *RHS) {
+ if (int Cmp = std::strcmp(LHS->getName(), RHS->getName()))
+ return Cmp < 0;
+
+ // Secondary key is the description.
+ return std::strcmp(LHS->getDesc(), RHS->getDesc()) < 0;
+ });
// Print out the statistics header...
OS << "===" << std::string(73, '-') << "===\n"
if (Stats.Stats.empty()) return;
// Get the stream to write to.
- raw_ostream &OutStream = *CreateInfoOutputFile();
- PrintStatistics(OutStream);
- delete &OutStream; // Close the file.
+ std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
+ PrintStatistics(*OutStream);
+
#else
// Check if the -stats option is set instead of checking
// !Stats.Stats.empty(). In release builds, Statistics operators
// do nothing, so stats are never Registered.
if (Enabled) {
// Get the stream to write to.
- raw_ostream &OutStream = *CreateInfoOutputFile();
- OutStream << "Statistics are disabled. "
- << "Build with asserts or with -DLLVM_ENABLE_STATS\n";
- OutStream.flush();
- delete &OutStream; // Close the file.
+ std::unique_ptr<raw_ostream> OutStream = CreateInfoOutputFile();
+ (*OutStream) << "Statistics are disabled. "
+ << "Build with asserts or with -DLLVM_ENABLE_STATS\n";
}
#endif
}