Chris Lattner | f3f4fd5 | 2002-05-10 15:36:46 +0000 | [diff] [blame] | 1 | //===-- StatisticReporter.cpp - Easy way to expose stats information -------==// |
| 2 | // |
| 3 | // This file implements the 'Statistic' class, which is designed to be an easy |
| 4 | // way to expose various success metrics from passes. These statistics are |
| 5 | // printed at the end of a run, when the -stats command line option is enabled |
| 6 | // on the command line. |
| 7 | // |
| 8 | // This is useful for reporting information like the number of instructions |
| 9 | // simplified, optimized or removed by various transformations, like this: |
| 10 | // |
| 11 | // static Statistic<> NumInstEliminated("GCSE - Number of instructions killed"); |
| 12 | // |
| 13 | // Later, in the code: ++NumInstEliminated; |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "Support/StatisticReporter.h" |
| 18 | #include "Support/CommandLine.h" |
| 19 | #include <iostream> |
| 20 | |
Chris Lattner | 4435ac0 | 2002-05-22 17:06:20 +0000 | [diff] [blame] | 21 | bool DebugFlag; // DebugFlag - Exported boolean set by the -debug option |
| 22 | |
Chris Lattner | 5ff62e9 | 2002-07-22 02:10:13 +0000 | [diff] [blame^] | 23 | // -stats - Command line option to cause transformations to emit stats about |
| 24 | // what they did. |
| 25 | // |
| 26 | static cl::opt<bool> |
| 27 | Enabled("stats", cl::desc("Enable statistics output from program")); |
| 28 | |
| 29 | // -debug - Command line option to enable the DEBUG statements in the passes. |
| 30 | static cl::opt<bool, true> |
| 31 | Debug("debug", cl::desc("Enable debug output"), cl::Hidden, |
| 32 | cl::location(DebugFlag)); |
Chris Lattner | f3f4fd5 | 2002-05-10 15:36:46 +0000 | [diff] [blame] | 33 | |
| 34 | // Print information when destroyed, iff command line option is specified |
| 35 | void StatisticBase::destroy() const { |
| 36 | if (Enabled && hasSomeData()) { |
| 37 | std::cerr.width(7); |
| 38 | printValue(std::cerr); |
| 39 | std::cerr.width(0); |
| 40 | std::cerr << "\t" << Name << "\n"; |
| 41 | } |
| 42 | } |