llvm.org GIT mirror llvm / 0a36152
eliminate constructor from Statistic class. It is now impossible to get a static constructor for them :). Transition complete. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32710 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 13 years ago
2 changed file(s) with 21 addition(s) and 34 deletion(s). Raw diff Collapse all Expand all
2727
2828 namespace llvm {
2929
30 class StatisticBase {
30 class Statistic {
3131 public:
3232 const char *Name;
3333 const char *Desc;
3737 unsigned getValue() const { return Value; }
3838 const char *getName() const { return Name; }
3939 const char *getDesc() const { return Desc; }
40
40
41 /// construct - This should only be called for non-global statistics.
42 void construct(const char *name, const char *desc) {
43 Name = name; Desc = desc;
44 Value = 0; Initialized = 0;
45 }
46
4147 // Allow use of this class as the value itself.
4248 operator unsigned() const { return Value; }
43 const StatisticBase &operator=(unsigned Val) { Value = Val; return init(); }
44 const StatisticBase &operator++() { ++Value; return init(); }
49 const Statistic &operator=(unsigned Val) { Value = Val; return init(); }
50 const Statistic &operator++() { ++Value; return init(); }
4551 unsigned operator++(int) { init(); return Value++; }
46 const StatisticBase &operator--() { --Value; return init(); }
52 const Statistic &operator--() { --Value; return init(); }
4753 unsigned operator--(int) { init(); return Value--; }
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();}
54 const Statistic &operator+=(const unsigned &V) { Value += V; return init(); }
55 const Statistic &operator-=(const unsigned &V) { Value -= V; return init(); }
56 const Statistic &operator*=(const unsigned &V) { Value *= V; return init(); }
57 const Statistic &operator/=(const unsigned &V) { Value /= V; return init(); }
5258
5359 protected:
54 StatisticBase &init() {
60 Statistic &init() {
5561 if (!Initialized) RegisterStatistic();
5662 return *this;
5763 }
5864 void RegisterStatistic();
5965 };
6066
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 // Allow use of this class as the value itself.
67 operator unsigned() const { return Value; }
68 const Statistic &operator=(unsigned Val) { Value = Val; init(); return *this;}
69 const Statistic &operator++() { ++Value; init(); return *this;}
70 unsigned operator++(int) { init(); return Value++; }
71 const Statistic &operator--() { --Value; init(); return *this;}
72 unsigned operator--(int) { init(); return Value--; }
73 const Statistic &operator+=(const unsigned &V) {Value += V;init();return *this;}
74 const Statistic &operator-=(const unsigned &V) {Value -= V;init();return *this;}
75 const Statistic &operator*=(const unsigned &V) {Value *= V;init();return *this;}
76 const Statistic &operator/=(const unsigned &V) {Value /= V;init();return *this;}
77 };
78
79
8067 // STATISTIC - A macro to make definition of statistics really simple. This
8168 // automatically passes the DEBUG_TYPE of the file into the statistic.
8269 #define STATISTIC(VARNAME, DESC) \
83 static StatisticBase VARNAME = { DEBUG_TYPE, DESC, 0, 0 }
70 static Statistic VARNAME = { DEBUG_TYPE, DESC, 0, 0 }
8471
8572 } // End llvm namespace
8673
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::vectorBase*> Stats;
47 std::vector*> Stats;
4848 public:
4949 ~StatisticInfo();
5050
51 void addStatistic(const StatisticBase *S) {
51 void addStatistic(const Statistic *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 StatisticBase::RegisterStatistic() {
62 void Statistic::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 StatisticBase *LHS, const StatisticBase *RHS) const {
72 bool operator()(const Statistic *LHS, const Statistic *RHS) const {
7373 int Cmp = std::strcmp(LHS->getName(), RHS->getName());
7474 if (Cmp != 0) return Cmp < 0;
7575