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

Chris Lattner sabre at nondot.org
Wed Dec 6 09:47:27 PST 2006



Changes in directory llvm/include/llvm/ADT:

Statistic.h updated: 1.17 -> 1.18
---
Log message:

Detemplatize the Statistic class.  The only type it is instantiated with
is 'unsigned'.



---
Diffs of the changes:  (+19 -20)

 Statistic.h |   39 +++++++++++++++++++--------------------
 1 files changed, 19 insertions(+), 20 deletions(-)


Index: llvm/include/llvm/ADT/Statistic.h
diff -u llvm/include/llvm/ADT/Statistic.h:1.17 llvm/include/llvm/ADT/Statistic.h:1.18
--- llvm/include/llvm/ADT/Statistic.h:1.17	Tue Aug 29 23:17:00 2006
+++ llvm/include/llvm/ADT/Statistic.h	Wed Dec  6 11:46:31 2006
@@ -8,17 +8,19 @@
 //===----------------------------------------------------------------------===//
 //
 // This file defines the 'Statistic' class, which is designed to be an easy way
-// to expose various success metrics from passes.  These statistics are printed
-// at the end of a run, when the -stats command line option is enabled on the
-// command line.
+// to expose various metrics from passes.  These statistics are printed at the
+// end of a run (from llvm_shutdown), when the -stats command line option is
+// passed on the command line.
 //
 // This is useful for reporting information like the number of instructions
 // simplified, optimized or removed by various transformations, like this:
 //
-// static Statistic<> NumInstsKilled("gcse", "Number of instructions killed");
+// static Statistic NumInstsKilled("gcse", "Number of instructions killed");
 //
 // Later, in the code: ++NumInstsKilled;
 //
+// NOTE: Statistics *must* be declared as global variables.
+//
 //===----------------------------------------------------------------------===//
 
 #ifndef LLVM_ADT_STATISTIC_H
@@ -29,7 +31,7 @@
 
 namespace llvm {
 
-// StatisticBase - Nontemplated base class for Statistic<> class...
+// StatisticBase - Nontemplated base class for Statistic class...
 class StatisticBase {
   const char *Name;
   const char *Desc;
@@ -55,39 +57,36 @@
 };
 
 // Statistic Class - templated on the data type we are monitoring...
-template <typename DataType=unsigned>
 class Statistic : private StatisticBase {
-  DataType Value;
+  unsigned Value;
 
   virtual void printValue(std::ostream &o) const { o << Value; }
-  virtual bool hasSomeData() const { return Value != DataType(); }
+  virtual bool hasSomeData() const { return Value != 0; }
 public:
   // Normal constructor, default initialize data item...
   Statistic(const char *name, const char *desc)
-    : StatisticBase(name, desc), Value(DataType()) {}
+    : StatisticBase(name, desc), Value(0) {}
 
   // Constructor to provide an initial value...
-  Statistic(const DataType &Val, const char *name, const char *desc)
+  Statistic(const unsigned &Val, const char *name, const char *desc)
     : StatisticBase(name, desc), Value(Val) {}
 
   // Print information when destroyed, iff command line option is specified
   ~Statistic() { destroy(); }
 
   // Allow use of this class as the value itself...
-  operator DataType() const { return Value; }
-  const Statistic &operator=(DataType Val) { Value = Val; return *this; }
+  operator unsigned() const { return Value; }
+  const Statistic &operator=(unsigned Val) { Value = Val; return *this; }
   const Statistic &operator++() { ++Value; return *this; }
-  DataType operator++(int) { return Value++; }
+  unsigned operator++(int) { return Value++; }
   const Statistic &operator--() { --Value; return *this; }
-  DataType operator--(int) { return Value--; }
-  const Statistic &operator+=(const DataType &V) { Value += V; return *this; }
-  const Statistic &operator-=(const DataType &V) { Value -= V; return *this; }
-  const Statistic &operator*=(const DataType &V) { Value *= V; return *this; }
-  const Statistic &operator/=(const DataType &V) { Value /= V; 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; }
 };
 
-EXTERN_TEMPLATE_INSTANTIATION(class Statistic<unsigned>);
-
 } // End llvm namespace
 
 #endif






More information about the llvm-commits mailing list