LLVM API Documentation
00001 //===-- llvm/ADT/Statistic.h - Easy way to expose stats ---------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file defines the 'Statistic' class, which is designed to be an easy way 00011 // to expose various metrics from passes. These statistics are printed at the 00012 // end of a run (from llvm_shutdown), when the -stats command line option is 00013 // passed on the command line. 00014 // 00015 // This is useful for reporting information like the number of instructions 00016 // simplified, optimized or removed by various transformations, like this: 00017 // 00018 // static Statistic NumInstsKilled("gcse", "Number of instructions killed"); 00019 // 00020 // Later, in the code: ++NumInstsKilled; 00021 // 00022 // NOTE: Statistics *must* be declared as global variables. 00023 // 00024 //===----------------------------------------------------------------------===// 00025 00026 #ifndef LLVM_ADT_STATISTIC_H 00027 #define LLVM_ADT_STATISTIC_H 00028 00029 namespace llvm { 00030 00031 class Statistic { 00032 public: 00033 const char *Name; 00034 const char *Desc; 00035 unsigned Value : 31; 00036 bool Initialized : 1; 00037 00038 unsigned getValue() const { return Value; } 00039 const char *getName() const { return Name; } 00040 const char *getDesc() const { return Desc; } 00041 00042 /// construct - This should only be called for non-global statistics. 00043 void construct(const char *name, const char *desc) { 00044 Name = name; Desc = desc; 00045 Value = 0; Initialized = 0; 00046 } 00047 00048 // Allow use of this class as the value itself. 00049 operator unsigned() const { return Value; } 00050 const Statistic &operator=(unsigned Val) { Value = Val; return init(); } 00051 const Statistic &operator++() { ++Value; return init(); } 00052 unsigned operator++(int) { init(); return Value++; } 00053 const Statistic &operator--() { --Value; return init(); } 00054 unsigned operator--(int) { init(); return Value--; } 00055 const Statistic &operator+=(const unsigned &V) { Value += V; return init(); } 00056 const Statistic &operator-=(const unsigned &V) { Value -= V; return init(); } 00057 const Statistic &operator*=(const unsigned &V) { Value *= V; return init(); } 00058 const Statistic &operator/=(const unsigned &V) { Value /= V; return init(); } 00059 00060 protected: 00061 Statistic &init() { 00062 if (!Initialized) RegisterStatistic(); 00063 return *this; 00064 } 00065 void RegisterStatistic(); 00066 }; 00067 00068 // STATISTIC - A macro to make definition of statistics really simple. This 00069 // automatically passes the DEBUG_TYPE of the file into the statistic. 00070 #define STATISTIC(VARNAME, DESC) \ 00071 static llvm::Statistic VARNAME = { DEBUG_TYPE, DESC, 0, 0 } 00072 00073 } // End llvm namespace 00074 00075 #endif