summaryrefslogtreecommitdiff
path: root/include/llvm/ADT/Statistic.h
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-12-08 20:00:42 +0000
committerChris Lattner <sabre@nondot.org>2006-12-08 20:00:42 +0000
commit975f05852d15c98540b50de7df704d67e5a794cd (patch)
tree0fd0c62d8a08823565c49a2bd4667d71574c2644 /include/llvm/ADT/Statistic.h
parent4d9a186b10dacf1d702ef32c2638e9016d8f483b (diff)
downloadllvm-975f05852d15c98540b50de7df704d67e5a794cd.tar.gz
llvm-975f05852d15c98540b50de7df704d67e5a794cd.tar.bz2
llvm-975f05852d15c98540b50de7df704d67e5a794cd.tar.xz
Change the implementation of statistic to not need destructors at all.
Instead, the stat info is printed when llvm_shutdown() is called. These also don't need static ctors, but getting rid of them is uglier: still investigating. This reduces the number of static dtors in llvm from ~1400 to ~750. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32372 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/Statistic.h')
-rw-r--r--include/llvm/ADT/Statistic.h41
1 files changed, 24 insertions, 17 deletions
diff --git a/include/llvm/ADT/Statistic.h b/include/llvm/ADT/Statistic.h
index dd44f2709b..74abe6442b 100644
--- a/include/llvm/ADT/Statistic.h
+++ b/include/llvm/ADT/Statistic.h
@@ -31,29 +31,36 @@ namespace llvm {
class Statistic {
const char *Name;
const char *Desc;
- unsigned Value;
- static unsigned NumStats;
+ unsigned Value : 31;
+ bool Initialized : 1;
public:
// Normal constructor, default initialize data item...
Statistic(const char *name, const char *desc)
- : Name(name), Desc(desc), Value(0) {
- ++NumStats; // Keep track of how many stats are created...
+ : Name(name), Desc(desc), Value(0), Initialized(0) {
}
- // Print information when destroyed, iff command line option is specified
- ~Statistic();
-
- // Allow use of this class as the value itself...
+ unsigned getValue() const { return Value; }
+ const char *getName() const { return Name; }
+ const char *getDesc() const { return Desc; }
+
+ // Allow use of this class as the value itself.
operator unsigned() const { return Value; }
- const Statistic &operator=(unsigned Val) { Value = Val; return *this; }
- const Statistic &operator++() { ++Value; return *this; }
- unsigned operator++(int) { return Value++; }
- const Statistic &operator--() { --Value; return *this; }
- unsigned operator--(int) { return Value--; }
- const Statistic &operator+=(const unsigned &V) { Value += V; return *this; }
- const Statistic &operator-=(const unsigned &V) { Value -= V; return *this; }
- const Statistic &operator*=(const unsigned &V) { Value *= V; return *this; }
- const Statistic &operator/=(const unsigned &V) { Value /= V; return *this; }
+ const Statistic &operator=(unsigned Val) { Value = Val; return init(); }
+ const Statistic &operator++() { ++Value; return init(); }
+ unsigned operator++(int) { init(); return Value++; }
+ const Statistic &operator--() { --Value; return init(); }
+ unsigned operator--(int) { init(); return Value--; }
+ 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(); }
+
+private:
+ Statistic &init() {
+ if (!Initialized) RegisterStatistic();
+ return *this;
+ }
+ void RegisterStatistic();
};
} // End llvm namespace