2004-09-01 22:55:40 +00:00
|
|
|
//===-- llvm/ADT/Statistic.h - Easy way to expose stats ---------*- C++ -*-===//
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 19:46:57 +00:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 19:59:42 +00:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 20:19:05 +00:00
|
|
|
//
|
2003-10-20 19:46:57 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-05-10 15:36:56 +00:00
|
|
|
//
|
|
|
|
// This file defines the 'Statistic' class, which is designed to be an easy way
|
2006-12-06 17:46:33 +00:00
|
|
|
// 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.
|
2002-05-10 15:36:56 +00:00
|
|
|
//
|
|
|
|
// This is useful for reporting information like the number of instructions
|
|
|
|
// simplified, optimized or removed by various transformations, like this:
|
|
|
|
//
|
2006-12-06 17:46:33 +00:00
|
|
|
// static Statistic NumInstsKilled("gcse", "Number of instructions killed");
|
2002-05-10 15:36:56 +00:00
|
|
|
//
|
2004-02-13 04:49:04 +00:00
|
|
|
// Later, in the code: ++NumInstsKilled;
|
2002-05-10 15:36:56 +00:00
|
|
|
//
|
2006-12-06 17:46:33 +00:00
|
|
|
// NOTE: Statistics *must* be declared as global variables.
|
|
|
|
//
|
2002-05-10 15:36:56 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-01 22:55:40 +00:00
|
|
|
#ifndef LLVM_ADT_STATISTIC_H
|
|
|
|
#define LLVM_ADT_STATISTIC_H
|
2002-05-10 15:36:56 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
|
|
|
|
2006-12-19 23:17:40 +00:00
|
|
|
class Statistic {
|
2006-12-19 21:27:47 +00:00
|
|
|
public:
|
2002-05-10 15:36:56 +00:00
|
|
|
const char *Name;
|
2002-10-01 22:35:45 +00:00
|
|
|
const char *Desc;
|
2006-12-08 20:00:42 +00:00
|
|
|
unsigned Value : 31;
|
|
|
|
bool Initialized : 1;
|
2002-05-10 15:36:56 +00:00
|
|
|
|
2006-12-08 20:00:42 +00:00
|
|
|
unsigned getValue() const { return Value; }
|
|
|
|
const char *getName() const { return Name; }
|
|
|
|
const char *getDesc() const { return Desc; }
|
2006-12-19 23:17:40 +00:00
|
|
|
|
|
|
|
/// construct - This should only be called for non-global statistics.
|
|
|
|
void construct(const char *name, const char *desc) {
|
|
|
|
Name = name; Desc = desc;
|
|
|
|
Value = 0; Initialized = 0;
|
|
|
|
}
|
|
|
|
|
2006-12-08 20:00:42 +00:00
|
|
|
// Allow use of this class as the value itself.
|
2006-12-06 17:46:33 +00:00
|
|
|
operator unsigned() const { return Value; }
|
2006-12-19 23:17:40 +00:00
|
|
|
const Statistic &operator=(unsigned Val) { Value = Val; return init(); }
|
|
|
|
const Statistic &operator++() { ++Value; return init(); }
|
2006-12-08 20:00:42 +00:00
|
|
|
unsigned operator++(int) { init(); return Value++; }
|
2006-12-19 23:17:40 +00:00
|
|
|
const Statistic &operator--() { --Value; return init(); }
|
2006-12-08 20:00:42 +00:00
|
|
|
unsigned operator--(int) { init(); return Value--; }
|
2006-12-19 23:17:40 +00:00
|
|
|
const Statistic &operator+=(const unsigned &V) { Value += V; return init(); }
|
|
|
|
const Statistic &operator-=(const unsigned &V) { Value -= V; return init(); }
|
|
|
|
const Statistic &operator*=(const unsigned &V) { Value *= V; return init(); }
|
|
|
|
const Statistic &operator/=(const unsigned &V) { Value /= V; return init(); }
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2006-12-19 22:55:57 +00:00
|
|
|
protected:
|
2006-12-19 23:17:40 +00:00
|
|
|
Statistic &init() {
|
2006-12-08 20:00:42 +00:00
|
|
|
if (!Initialized) RegisterStatistic();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
void RegisterStatistic();
|
2002-05-10 15:36:56 +00:00
|
|
|
};
|
2009-01-09 19:25:42 +00:00
|
|
|
|
2006-12-19 21:27:47 +00:00
|
|
|
// STATISTIC - A macro to make definition of statistics really simple. This
|
|
|
|
// automatically passes the DEBUG_TYPE of the file into the statistic.
|
|
|
|
#define STATISTIC(VARNAME, DESC) \
|
2008-05-27 12:41:24 +00:00
|
|
|
static llvm::Statistic VARNAME = { DEBUG_TYPE, DESC, 0, 0 }
|
2002-05-10 15:36:56 +00:00
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-05-10 15:36:56 +00:00
|
|
|
#endif
|