Statistic.h revision cf84504d7a86808117f67264ad5cfab8f5a139bc
1//===-- llvm/ADT/Statistic.h - Easy way to expose stats ---------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 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. 7// 8//===----------------------------------------------------------------------===// 9// 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. 14// 15// This is useful for reporting information like the number of instructions 16// simplified, optimized or removed by various transformations, like this: 17// 18// static Statistic NumInstsKilled("gcse", "Number of instructions killed"); 19// 20// Later, in the code: ++NumInstsKilled; 21// 22// NOTE: Statistics *must* be declared as global variables. 23// 24//===----------------------------------------------------------------------===// 25 26#ifndef LLVM_ADT_STATISTIC_H 27#define LLVM_ADT_STATISTIC_H 28 29namespace llvm { 30 31class Statistic { 32 const char *Name; 33 const char *Desc; 34 unsigned Value; 35 static unsigned NumStats; 36public: 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... 41 } 42 43 // Print information when destroyed, iff command line option is specified 44 ~Statistic(); 45 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; } 57}; 58 59} // End llvm namespace 60 61#endif 62