llvm.org GIT mirror llvm / ecb2768
Refactor statistic a big and introduce a horrible-but-necessary macro (STATISTIC), which allows us to define statistics that don't introduce static ctors into the .o files. I'm migrating code over to use this incrementally. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32687 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
2 changed file(s) with 26 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
2727
2828 namespace llvm {
2929
30 class Statistic {
30 class StatisticBase {
31 public:
3132 const char *Name;
3233 const char *Desc;
3334 unsigned Value : 31;
3435 bool Initialized : 1;
35 public:
36 // Normal constructor, default initialize data item...
37 Statistic(const char *name, const char *desc)
38 : Name(name), Desc(desc), Value(0), Initialized(0) {
39 }
4036
4137 unsigned getValue() const { return Value; }
4238 const char *getName() const { return Name; }
4440
4541 // Allow use of this class as the value itself.
4642 operator unsigned() const { return Value; }
47 const Statistic &operator=(unsigned Val) { Value = Val; return init(); }
48 const Statistic &operator++() { ++Value; return init(); }
43 const StatisticBase &operator=(unsigned Val) { Value = Val; return init(); }
44 const StatisticBase &operator++() { ++Value; return init(); }
4945 unsigned operator++(int) { init(); return Value++; }
50 const Statistic &operator--() { --Value; return init(); }
46 const StatisticBase &operator--() { --Value; return init(); }
5147 unsigned operator--(int) { init(); return Value--; }
52 const Statistic &operator+=(const unsigned &V) { Value += V; return init(); }
53 const Statistic &operator-=(const unsigned &V) { Value -= V; return init(); }
54 const Statistic &operator*=(const unsigned &V) { Value *= V; return init(); }
55 const Statistic &operator/=(const unsigned &V) { Value /= V; return init(); }
48 const StatisticBase &operator+=(const unsigned &V) {Value += V;return init();}
49 const StatisticBase &operator-=(const unsigned &V) {Value -= V;return init();}
50 const StatisticBase &operator*=(const unsigned &V) {Value *= V;return init();}
51 const StatisticBase &operator/=(const unsigned &V) {Value /= V;return init();}
5652
5753 private:
58 Statistic &init() {
54 StatisticBase &init() {
5955 if (!Initialized) RegisterStatistic();
6056 return *this;
6157 }
6258 void RegisterStatistic();
6359 };
60
61 struct Statistic : public StatisticBase {
62 Statistic(const char *name, const char *desc) {
63 Name = name; Desc = desc; Value = 0; Initialized = 0;
64 }
65 };
66
67
68 // STATISTIC - A macro to make definition of statistics really simple. This
69 // automatically passes the DEBUG_TYPE of the file into the statistic.
70 #define STATISTIC(VARNAME, DESC) \
71 static StatisticBase VARNAME = { DEBUG_TYPE, DESC, 0, 0 }
6472
6573 } // End llvm namespace
6674
4444 /// on demand (when the first statistic is bumped) and destroyed only when
4545 /// llvm_shutdown is called. We print statistics from the destructor.
4646 class StatisticInfo {
47 std::vector*> Stats;
47 std::vectorBase*> Stats;
4848 public:
4949 ~StatisticInfo();
5050
51 void addStatistic(const Statistic *S) {
51 void addStatistic(const StatisticBase *S) {
5252 Stats.push_back(S);
5353 }
5454 };
5959
6060 /// RegisterStatistic - The first time a statistic is bumped, this method is
6161 /// called.
62 void Statistic::RegisterStatistic() {
62 void StatisticBase::RegisterStatistic() {
6363 // If stats are enabled, inform StatInfo that this statistic should be
6464 // printed.
6565 if (Enabled)
6969 }
7070
7171 struct NameCompare {
72 bool operator()(const Statistic *LHS, const Statistic *RHS) const {
72 bool operator()(const StatisticBase *LHS, const StatisticBase *RHS) const {
7373 int Cmp = std::strcmp(LHS->getName(), RHS->getName());
7474 if (Cmp != 0) return Cmp < 0;
7575