2004-09-02 00:55:40 +02:00
|
|
|
//===-- llvm/ADT/Statistic.h - Easy way to expose stats ---------*- C++ -*-===//
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 21:46:57 +02:00
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2005-04-21 22:19:05 +02:00
|
|
|
//
|
2003-10-20 21:46:57 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
2002-05-10 17:36:56 +02:00
|
|
|
//
|
|
|
|
// This file defines the 'Statistic' class, which is designed to be an easy way
|
2006-12-06 18:46:33 +01: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 17:36:56 +02:00
|
|
|
//
|
|
|
|
// This is useful for reporting information like the number of instructions
|
|
|
|
// simplified, optimized or removed by various transformations, like this:
|
|
|
|
//
|
2006-12-06 18:46:33 +01:00
|
|
|
// static Statistic NumInstsKilled("gcse", "Number of instructions killed");
|
2002-05-10 17:36:56 +02:00
|
|
|
//
|
2004-02-13 05:49:04 +01:00
|
|
|
// Later, in the code: ++NumInstsKilled;
|
2002-05-10 17:36:56 +02:00
|
|
|
//
|
2006-12-06 18:46:33 +01:00
|
|
|
// NOTE: Statistics *must* be declared as global variables.
|
|
|
|
//
|
2002-05-10 17:36:56 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2004-09-02 00:55:40 +02:00
|
|
|
#ifndef LLVM_ADT_STATISTIC_H
|
|
|
|
#define LLVM_ADT_STATISTIC_H
|
2002-05-10 17:36:56 +02:00
|
|
|
|
2010-11-29 19:16:10 +01:00
|
|
|
#include "llvm/Support/Atomic.h"
|
2009-06-23 23:19:38 +02:00
|
|
|
|
2003-11-11 23:41:34 +01:00
|
|
|
namespace llvm {
|
2010-03-30 19:32:08 +02:00
|
|
|
class raw_ostream;
|
2003-11-11 23:41:34 +01:00
|
|
|
|
2006-12-20 00:17:40 +01:00
|
|
|
class Statistic {
|
2006-12-19 22:27:47 +01:00
|
|
|
public:
|
2002-05-10 17:36:56 +02:00
|
|
|
const char *Name;
|
2002-10-02 00:35:45 +02:00
|
|
|
const char *Desc;
|
2009-06-30 07:33:46 +02:00
|
|
|
volatile llvm::sys::cas_flag Value;
|
2009-06-23 23:19:38 +02:00
|
|
|
bool Initialized;
|
2002-05-10 17:36:56 +02:00
|
|
|
|
2009-06-30 07:33:46 +02:00
|
|
|
llvm::sys::cas_flag getValue() const { return Value; }
|
2006-12-08 21:00:42 +01:00
|
|
|
const char *getName() const { return Name; }
|
|
|
|
const char *getDesc() const { return Desc; }
|
2006-12-20 00:17:40 +01: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 21:00:42 +01:00
|
|
|
// Allow use of this class as the value itself.
|
2006-12-06 18:46:33 +01:00
|
|
|
operator unsigned() const { return Value; }
|
2009-06-23 23:19:38 +02:00
|
|
|
const Statistic &operator=(unsigned Val) {
|
|
|
|
Value = Val;
|
|
|
|
return init();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Statistic &operator++() {
|
2010-06-24 18:31:32 +02:00
|
|
|
// FIXME: This function and all those that follow carefully use an
|
|
|
|
// atomic operation to update the value safely in the presence of
|
|
|
|
// concurrent accesses, but not to read the return value, so the
|
|
|
|
// return value is not thread safe.
|
2009-06-23 23:19:38 +02:00
|
|
|
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 20:25:42 +01:00
|
|
|
|
2006-12-19 23:55:57 +01:00
|
|
|
protected:
|
2006-12-20 00:17:40 +01:00
|
|
|
Statistic &init() {
|
2009-06-23 23:19:38 +02:00
|
|
|
bool tmp = Initialized;
|
|
|
|
sys::MemoryFence();
|
|
|
|
if (!tmp) RegisterStatistic();
|
2006-12-08 21:00:42 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
void RegisterStatistic();
|
2002-05-10 17:36:56 +02:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2006-12-19 22:27:47 +01: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 14:41:24 +02:00
|
|
|
static llvm::Statistic VARNAME = { DEBUG_TYPE, DESC, 0, 0 }
|
2002-05-10 17:36:56 +02:00
|
|
|
|
2010-03-30 19:32:08 +02: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 23:41:34 +01:00
|
|
|
} // End llvm namespace
|
|
|
|
|
2002-05-10 17:36:56 +02:00
|
|
|
#endif
|