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
|
|
|
|
2009-06-23 21:19:38 +00:00
|
|
|
#include "llvm/System/Atomic.h"
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
namespace llvm {
|
2010-03-30 17:32:08 +00:00
|
|
|
class raw_ostream;
|
2003-11-11 22:41:34 +00:00
|
|
|
|
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;
|
2009-06-30 05:33:46 +00:00
|
|
|
volatile llvm::sys::cas_flag Value;
|
2009-06-23 21:19:38 +00:00
|
|
|
bool Initialized;
|
2002-05-10 15:36:56 +00:00
|
|
|
|
2009-06-30 05:33:46 +00:00
|
|
|
llvm::sys::cas_flag getValue() const { return Value; }
|
2006-12-08 20:00:42 +00:00
|
|
|
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; }
|
2009-06-23 21:19:38 +00:00
|
|
|
const Statistic &operator=(unsigned Val) {
|
|
|
|
Value = Val;
|
|
|
|
return init();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Statistic &operator++() {
|
|
|
|
sys::AtomicIncrement(&Value);
|
|
|
|
return init();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned operator++(int) {
|
|
|
|
init();
|
|
|
|
unsigned OldValue = Value;
|
|
|
|
sys::AtomicIncrement(&Value);
|
|
|
|
return OldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Statistic &operator--() {
|
|
|
|
sys::AtomicDecrement(&Value);
|
|
|
|
return init();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned operator--(int) {
|
|
|
|
init();
|
|
|
|
unsigned OldValue = Value;
|
|
|
|
sys::AtomicDecrement(&Value);
|
|
|
|
return OldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Statistic &operator+=(const unsigned &V) {
|
|
|
|
sys::AtomicAdd(&Value, V);
|
|
|
|
return init();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Statistic &operator-=(const unsigned &V) {
|
|
|
|
sys::AtomicAdd(&Value, -V);
|
|
|
|
return init();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Statistic &operator*=(const unsigned &V) {
|
|
|
|
sys::AtomicMul(&Value, V);
|
|
|
|
return init();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Statistic &operator/=(const unsigned &V) {
|
|
|
|
sys::AtomicDiv(&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() {
|
2009-06-23 21:19:38 +00:00
|
|
|
bool tmp = Initialized;
|
|
|
|
sys::MemoryFence();
|
|
|
|
if (!tmp) RegisterStatistic();
|
2006-12-08 20:00:42 +00:00
|
|
|
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
|
|
|
|
2010-03-30 17:32:08 +00:00
|
|
|
/// \brief Enable the collection and printing of statistics.
|
|
|
|
void EnableStatistics();
|
|
|
|
|
|
|
|
/// \brief Print statistics to the file returned by CreateInfoOutputFile().
|
|
|
|
void PrintStatistics();
|
|
|
|
|
|
|
|
/// \brief Print statistics to the given output stream.
|
|
|
|
void PrintStatistics(raw_ostream &OS);
|
|
|
|
|
2003-11-11 22:41:34 +00:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-05-10 15:36:56 +00:00
|
|
|
#endif
|