1 //===-- llvm/ADT/Statistic.h - Easy way to expose stats ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the 'Statistic' class, which is designed to be an easy way
11 // to expose various metrics from passes. These statistics are printed at the
12 // end of a run (from llvm_shutdown), when the -stats command line option is
13 // passed on the command line.
15 // This is useful for reporting information like the number of instructions
16 // simplified, optimized or removed by various transformations, like this:
18 // static Statistic NumInstsKilled("gcse", "Number of instructions killed");
20 // Later, in the code: ++NumInstsKilled;
22 // NOTE: Statistics *must* be declared as global variables.
24 //===----------------------------------------------------------------------===//
26 #ifndef LLVM_ADT_STATISTIC_H
27 #define LLVM_ADT_STATISTIC_H
35 static unsigned NumStats;
37 // Normal constructor, default initialize data item...
38 Statistic(const char *name, const char *desc)
39 : Name(name), Desc(desc), Value(0) {
40 ++NumStats; // Keep track of how many stats are created...
43 // Print information when destroyed, iff command line option is specified
46 // Allow use of this class as the value itself...
47 operator unsigned() const { return Value; }
48 const Statistic &operator=(unsigned Val) { Value = Val; return *this; }
49 const Statistic &operator++() { ++Value; return *this; }
50 unsigned operator++(int) { return Value++; }
51 const Statistic &operator--() { --Value; return *this; }
52 unsigned operator--(int) { return Value--; }
53 const Statistic &operator+=(const unsigned &V) { Value += V; return *this; }
54 const Statistic &operator-=(const unsigned &V) { Value -= V; return *this; }
55 const Statistic &operator*=(const unsigned &V) { Value *= V; return *this; }
56 const Statistic &operator/=(const unsigned &V) { Value /= V; return *this; }
59 } // End llvm namespace