llvm.org GIT mirror llvm / fa10fdf
Initial checkin of Statistic class git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2599 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 18 years ago
3 changed file(s) with 207 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 //===-- Support/StatisticReporter.h - Easy way to expose stats ---*- C++ -*-==//
1 //
2 // This file defines the 'Statistic' class, which is designed to be an easy way
3 // to expose various success metrics from passes. These statistics are printed
4 // at the end of a run, when the -stats command line option is enabled on the
5 // command line.
6 //
7 // This is useful for reporting information like the number of instructions
8 // simplified, optimized or removed by various transformations, like this:
9 //
10 // static Statistic<> NumInstEliminated("GCSE - Number of instructions killed");
11 //
12 // Later, in the code: ++NumInstEliminated;
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef SUPPORT_STATISTIC_REPORTER_H
17 #define SUPPORT_STATISTIC_REPORTER_H
18
19 #include
20
21 // StatisticBase - Nontemplated base class for Statistic<> class...
22 class StatisticBase {
23 const char *Name;
24 protected:
25 StatisticBase(const char *name) : Name(name) {}
26 virtual ~StatisticBase() {}
27
28 // destroy - Called by subclass dtor so that we can still invoke virtual
29 // functions on the subclass.
30 void destroy() const;
31
32 // printValue - Overridden by template class to print out the value type...
33 virtual void printValue(ostream &o) const = 0;
34
35 // hasSomeData - Return true if some data has been aquired. Avoid printing
36 // lots of zero counts.
37 //
38 virtual bool hasSomeData() const = 0;
39 };
40
41 // Statistic Class - templated on the data type we are monitoring...
42 template
43 class Statistic : private StatisticBase {
44 DataType Value;
45
46 virtual void printValue(ostream &o) const { o << Value; }
47 virtual bool hasSomeData() const { return Value != DataType(); }
48 public:
49 // Normal constructor, default initialize data item...
50 Statistic(const char *name) : StatisticBase(name), Value(DataType()) {}
51
52 // Constructor to provide an initial value...
53 Statistic(const DataType &Val, const char *name)
54 : StatisticBase(name), Value(Val) {}
55
56 // Print information when destroyed, iff command line option is specified
57 ~Statistic() { destroy(); }
58
59 // Allow use of this class as the value itself...
60 inline operator DataType() const { return Value; }
61 inline const DataType &operator=(DataType Val) { Value = Val; return Value; }
62 inline const DataType &operator++() { return ++Value; }
63 inline DataType operator++(int) { return Value++; }
64 inline const DataType &operator+=(const DataType &V) { return Value += V; }
65 inline const DataType &operator-=(const DataType &V) { return Value -= V; }
66 };
67
68 #endif
0 //===-- Support/StatisticReporter.h - Easy way to expose stats ---*- C++ -*-==//
1 //
2 // This file defines the 'Statistic' class, which is designed to be an easy way
3 // to expose various success metrics from passes. These statistics are printed
4 // at the end of a run, when the -stats command line option is enabled on the
5 // command line.
6 //
7 // This is useful for reporting information like the number of instructions
8 // simplified, optimized or removed by various transformations, like this:
9 //
10 // static Statistic<> NumInstEliminated("GCSE - Number of instructions killed");
11 //
12 // Later, in the code: ++NumInstEliminated;
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef SUPPORT_STATISTIC_REPORTER_H
17 #define SUPPORT_STATISTIC_REPORTER_H
18
19 #include
20
21 // StatisticBase - Nontemplated base class for Statistic<> class...
22 class StatisticBase {
23 const char *Name;
24 protected:
25 StatisticBase(const char *name) : Name(name) {}
26 virtual ~StatisticBase() {}
27
28 // destroy - Called by subclass dtor so that we can still invoke virtual
29 // functions on the subclass.
30 void destroy() const;
31
32 // printValue - Overridden by template class to print out the value type...
33 virtual void printValue(ostream &o) const = 0;
34
35 // hasSomeData - Return true if some data has been aquired. Avoid printing
36 // lots of zero counts.
37 //
38 virtual bool hasSomeData() const = 0;
39 };
40
41 // Statistic Class - templated on the data type we are monitoring...
42 template
43 class Statistic : private StatisticBase {
44 DataType Value;
45
46 virtual void printValue(ostream &o) const { o << Value; }
47 virtual bool hasSomeData() const { return Value != DataType(); }
48 public:
49 // Normal constructor, default initialize data item...
50 Statistic(const char *name) : StatisticBase(name), Value(DataType()) {}
51
52 // Constructor to provide an initial value...
53 Statistic(const DataType &Val, const char *name)
54 : StatisticBase(name), Value(Val) {}
55
56 // Print information when destroyed, iff command line option is specified
57 ~Statistic() { destroy(); }
58
59 // Allow use of this class as the value itself...
60 inline operator DataType() const { return Value; }
61 inline const DataType &operator=(DataType Val) { Value = Val; return Value; }
62 inline const DataType &operator++() { return ++Value; }
63 inline DataType operator++(int) { return Value++; }
64 inline const DataType &operator+=(const DataType &V) { return Value += V; }
65 inline const DataType &operator-=(const DataType &V) { return Value -= V; }
66 };
67
68 #endif
0 //===-- Support/StatisticReporter.h - Easy way to expose stats ---*- C++ -*-==//
1 //
2 // This file defines the 'Statistic' class, which is designed to be an easy way
3 // to expose various success metrics from passes. These statistics are printed
4 // at the end of a run, when the -stats command line option is enabled on the
5 // command line.
6 //
7 // This is useful for reporting information like the number of instructions
8 // simplified, optimized or removed by various transformations, like this:
9 //
10 // static Statistic<> NumInstEliminated("GCSE - Number of instructions killed");
11 //
12 // Later, in the code: ++NumInstEliminated;
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef SUPPORT_STATISTIC_REPORTER_H
17 #define SUPPORT_STATISTIC_REPORTER_H
18
19 #include
20
21 // StatisticBase - Nontemplated base class for Statistic<> class...
22 class StatisticBase {
23 const char *Name;
24 protected:
25 StatisticBase(const char *name) : Name(name) {}
26 virtual ~StatisticBase() {}
27
28 // destroy - Called by subclass dtor so that we can still invoke virtual
29 // functions on the subclass.
30 void destroy() const;
31
32 // printValue - Overridden by template class to print out the value type...
33 virtual void printValue(ostream &o) const = 0;
34
35 // hasSomeData - Return true if some data has been aquired. Avoid printing
36 // lots of zero counts.
37 //
38 virtual bool hasSomeData() const = 0;
39 };
40
41 // Statistic Class - templated on the data type we are monitoring...
42 template
43 class Statistic : private StatisticBase {
44 DataType Value;
45
46 virtual void printValue(ostream &o) const { o << Value; }
47 virtual bool hasSomeData() const { return Value != DataType(); }
48 public:
49 // Normal constructor, default initialize data item...
50 Statistic(const char *name) : StatisticBase(name), Value(DataType()) {}
51
52 // Constructor to provide an initial value...
53 Statistic(const DataType &Val, const char *name)
54 : StatisticBase(name), Value(Val) {}
55
56 // Print information when destroyed, iff command line option is specified
57 ~Statistic() { destroy(); }
58
59 // Allow use of this class as the value itself...
60 inline operator DataType() const { return Value; }
61 inline const DataType &operator=(DataType Val) { Value = Val; return Value; }
62 inline const DataType &operator++() { return ++Value; }
63 inline DataType operator++(int) { return Value++; }
64 inline const DataType &operator+=(const DataType &V) { return Value += V; }
65 inline const DataType &operator-=(const DataType &V) { return Value -= V; }
66 };
67
68 #endif