[llvm-commits] CVS: llvm/include/llvm/ADT/Statistic.h

Chris Lattner sabre at nondot.org
Fri Dec 8 12:00:59 PST 2006



Changes in directory llvm/include/llvm/ADT:

Statistic.h updated: 1.19 -> 1.20
---
Log message:

Change the implementation of statistic to not need destructors at all.
Instead, the stat info is printed when llvm_shutdown() is called.
These also don't need static ctors, but getting rid of them is uglier:
still investigating.  This reduces the number of static dtors in llvm from
~1400 to ~750.


---
Diffs of the changes:  (+24 -17)

 Statistic.h |   41 ++++++++++++++++++++++++-----------------
 1 files changed, 24 insertions(+), 17 deletions(-)


Index: llvm/include/llvm/ADT/Statistic.h
diff -u llvm/include/llvm/ADT/Statistic.h:1.19 llvm/include/llvm/ADT/Statistic.h:1.20
--- llvm/include/llvm/ADT/Statistic.h:1.19	Wed Dec  6 12:20:44 2006
+++ llvm/include/llvm/ADT/Statistic.h	Fri Dec  8 14:00:42 2006
@@ -31,29 +31,36 @@
 class Statistic {
   const char *Name;
   const char *Desc;
-  unsigned Value;
-  static unsigned NumStats;
+  unsigned Value : 31;
+  bool Initialized : 1;
 public:
   // Normal constructor, default initialize data item...
   Statistic(const char *name, const char *desc)
-    : Name(name), Desc(desc), Value(0) {
-    ++NumStats;  // Keep track of how many stats are created...
+    : Name(name), Desc(desc), Value(0), Initialized(0) {
   }
 
-  // Print information when destroyed, iff command line option is specified
-  ~Statistic();
-
-  // Allow use of this class as the value itself...
+  unsigned getValue() const { return Value; }
+  const char *getName() const { return Name; }
+  const char *getDesc() const { return Desc; }
+  
+  // Allow use of this class as the value itself.
   operator unsigned() const { return Value; }
-  const Statistic &operator=(unsigned Val) { Value = Val; return *this; }
-  const Statistic &operator++() { ++Value; return *this; }
-  unsigned operator++(int) { return Value++; }
-  const Statistic &operator--() { --Value; return *this; }
-  unsigned operator--(int) { return Value--; }
-  const Statistic &operator+=(const unsigned &V) { Value += V; return *this; }
-  const Statistic &operator-=(const unsigned &V) { Value -= V; return *this; }
-  const Statistic &operator*=(const unsigned &V) { Value *= V; return *this; }
-  const Statistic &operator/=(const unsigned &V) { Value /= V; return *this; }
+  const Statistic &operator=(unsigned Val) { Value = Val; return init(); }
+  const Statistic &operator++() { ++Value; return init(); }
+  unsigned operator++(int) { init(); return Value++; }
+  const Statistic &operator--() { --Value; return init(); }
+  unsigned operator--(int) { init(); return Value--; }
+  const Statistic &operator+=(const unsigned &V) { Value += V; return init(); }
+  const Statistic &operator-=(const unsigned &V) { Value -= V; return init(); }
+  const Statistic &operator*=(const unsigned &V) { Value *= V; return init(); }
+  const Statistic &operator/=(const unsigned &V) { Value /= V; return init(); }
+  
+private:
+  Statistic &init() {
+    if (!Initialized) RegisterStatistic();
+    return *this;
+  }
+  void RegisterStatistic();
 };
 
 } // End llvm namespace






More information about the llvm-commits mailing list