[llvm-commits] CVS: llvm/lib/Support/Statistic.cpp

2006-12-19 Thread Chris Lattner


Changes in directory llvm/lib/Support:

Statistic.cpp updated: 1.23 - 1.24
---
Log message:

Refactor statistic a big and introduce a horrible-but-necessary macro 
(STATISTIC), which allows us to define statistics that don't introduce
static ctors into the .o files.  I'm migrating code over to use this 
incrementally.


---
Diffs of the changes:  (+4 -4)

 Statistic.cpp |8 
 1 files changed, 4 insertions(+), 4 deletions(-)


Index: llvm/lib/Support/Statistic.cpp
diff -u llvm/lib/Support/Statistic.cpp:1.23 llvm/lib/Support/Statistic.cpp:1.24
--- llvm/lib/Support/Statistic.cpp:1.23 Fri Dec  8 14:00:42 2006
+++ llvm/lib/Support/Statistic.cpp  Tue Dec 19 15:27:47 2006
@@ -45,11 +45,11 @@
 /// on demand (when the first statistic is bumped) and destroyed only when 
 /// llvm_shutdown is called.  We print statistics from the destructor.
 class StatisticInfo {
-  std::vectorconst Statistic* Stats;
+  std::vectorconst StatisticBase* Stats;
 public:
   ~StatisticInfo();
   
-  void addStatistic(const Statistic *S) {
+  void addStatistic(const StatisticBase *S) {
 Stats.push_back(S);
   }
 };
@@ -60,7 +60,7 @@
 
 /// RegisterStatistic - The first time a statistic is bumped, this method is
 /// called.
-void Statistic::RegisterStatistic() {
+void StatisticBase::RegisterStatistic() {
   // If stats are enabled, inform StatInfo that this statistic should be
   // printed.
   if (Enabled)
@@ -70,7 +70,7 @@
 }
 
 struct NameCompare {
-  bool operator()(const Statistic *LHS, const Statistic *RHS) const {
+  bool operator()(const StatisticBase *LHS, const StatisticBase *RHS) const {
 int Cmp = std::strcmp(LHS-getName(), RHS-getName());
 if (Cmp != 0) return Cmp  0;
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/Statistic.cpp

2006-12-08 Thread Chris Lattner


Changes in directory llvm/lib/Support:

Statistic.cpp updated: 1.22 - 1.23
---
Log message:

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.


---
Diffs of the changes:  (+76 -61)

 Statistic.cpp |  137 --
 1 files changed, 76 insertions(+), 61 deletions(-)


Index: llvm/lib/Support/Statistic.cpp
diff -u llvm/lib/Support/Statistic.cpp:1.22 llvm/lib/Support/Statistic.cpp:1.23
--- llvm/lib/Support/Statistic.cpp:1.22 Thu Dec  7 17:41:45 2006
+++ llvm/lib/Support/Statistic.cpp  Fri Dec  8 14:00:42 2006
@@ -15,7 +15,7 @@
 // This is useful for reporting information like the number of instructions
 // simplified, optimized or removed by various transformations, like this:
 //
-// static Statistic NumInstEliminated(GCSE - Number of instructions killed);
+// static Statistic NumInstEliminated(GCSE, Number of instructions killed);
 //
 // Later, in the code: ++NumInstEliminated;
 //
@@ -23,84 +23,99 @@
 
 #include llvm/ADT/Statistic.h
 #include llvm/Support/CommandLine.h
+#include llvm/Support/ManagedStatic.h
 #include llvm/Support/Streams.h
 #include llvm/ADT/StringExtras.h
 #include algorithm
 #include ostream
 using namespace llvm;
 
-// GetLibSupportInfoOutputFile - Return a file stream to print our output on...
+// GetLibSupportInfoOutputFile - Return a file stream to print our output on.
 namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
 
-unsigned Statistic::NumStats = 0;
-
-// -stats - Command line option to cause transformations to emit stats about
-// what they did.
-//
+/// -stats - Command line option to cause transformations to emit stats about
+/// what they did.
+///
 static cl::optbool
 Enabled(stats, cl::desc(Enable statistics output from program));
 
-struct StatRecord {
-  std::string Value;
-  const char *Name, *Desc;
-
-  StatRecord(const std::string V, const char *N, const char *D)
-: Value(V), Name(N), Desc(D) {}
 
-  bool operator(const StatRecord SR) const {
-return std::strcmp(Name, SR.Name)  0;
-  }
-
-  void print(unsigned ValFieldSize, unsigned NameFieldSize,
- std::ostream OS) {
-OS  std::string(ValFieldSize-Value.length(), ' ')
-Value Name
-std::string(NameFieldSize-std::strlen(Name), ' ')
- -   Desc  \n;
+namespace {
+/// StatisticInfo - This class is used in a ManagedStatic so that it is created
+/// on demand (when the first statistic is bumped) and destroyed only when 
+/// llvm_shutdown is called.  We print statistics from the destructor.
+class StatisticInfo {
+  std::vectorconst Statistic* Stats;
+public:
+  ~StatisticInfo();
+  
+  void addStatistic(const Statistic *S) {
+Stats.push_back(S);
   }
 };
+}
 
-static std::vectorStatRecord *AccumStats = 0;
+static ManagedStaticStatisticInfo StatInfo;
 
-// Print information when destroyed, iff command line option is specified
-Statistic::~Statistic() {
-  if (Enabled  Value != 0) {
-if (AccumStats == 0)
-  AccumStats = new std::vectorStatRecord();
 
-AccumStats-push_back(StatRecord(utostr(Value), Name, Desc));
-  }
+/// RegisterStatistic - The first time a statistic is bumped, this method is
+/// called.
+void Statistic::RegisterStatistic() {
+  // If stats are enabled, inform StatInfo that this statistic should be
+  // printed.
+  if (Enabled)
+StatInfo-addStatistic(this);
+  // Remember we have been registered.
+  Initialized = true;
+}
 
-  if (--NumStats == 0  AccumStats) {
-std::ostream *OutStream = GetLibSupportInfoOutputFile();
+struct NameCompare {
+  bool operator()(const Statistic *LHS, const Statistic *RHS) const {
+int Cmp = std::strcmp(LHS-getName(), RHS-getName());
+if (Cmp != 0) return Cmp  0;
+
+// Secondary key is the description.
+return std::strcmp(LHS-getDesc(), RHS-getDesc())  0;
+  }
+};
 
-// Figure out how long the biggest Value and Name fields are...
-unsigned MaxNameLen = 0, MaxValLen = 0;
-for (unsigned i = 0, e = AccumStats-size(); i != e; ++i) {
-  MaxValLen = std::max(MaxValLen,
-   (unsigned)(*AccumStats)[i].Value.length());
-  MaxNameLen = std::max(MaxNameLen,
-(unsigned)std::strlen((*AccumStats)[i].Name));
-}
-
-// Sort the fields...
-std::stable_sort(AccumStats-begin(), AccumStats-end());
-
-// Print out the statistics header...
-*OutStream  ===  std::string(73, '-')  ===\n
-  ... Statistics Collected ...\n
-===  std::string(73, '-')  ===\n\n;
-
-// Print all of the statistics accumulated...
-for (unsigned i = 0, e = AccumStats-size(); i != e; ++i)
-  (*AccumStats)[i].print(MaxValLen, MaxNameLen, *OutStream);
-
-

[llvm-commits] CVS: llvm/lib/Support/Statistic.cpp SystemUtils.cpp Timer.cpp

2006-12-07 Thread Bill Wendling


Changes in directory llvm/lib/Support:

Statistic.cpp updated: 1.20 - 1.21
SystemUtils.cpp updated: 1.47 - 1.48
Timer.cpp updated: 1.47 - 1.48
---
Log message:

Removed more iostream includes


---
Diffs of the changes:  (+11 -12)

 Statistic.cpp   |5 ++---
 SystemUtils.cpp |4 ++--
 Timer.cpp   |   14 +++---
 3 files changed, 11 insertions(+), 12 deletions(-)


Index: llvm/lib/Support/Statistic.cpp
diff -u llvm/lib/Support/Statistic.cpp:1.20 llvm/lib/Support/Statistic.cpp:1.21
--- llvm/lib/Support/Statistic.cpp:1.20 Wed Dec  6 12:20:44 2006
+++ llvm/lib/Support/Statistic.cpp  Thu Dec  7 14:28:15 2006
@@ -23,9 +23,8 @@
 
 #include llvm/ADT/Statistic.h
 #include llvm/Support/CommandLine.h
+#include llvm/Support/Streams.h
 #include llvm/ADT/StringExtras.h
-#include sstream
-#include iostream
 #include algorithm
 using namespace llvm;
 
@@ -100,7 +99,7 @@
 // Free all accumulated statistics...
 delete AccumStats;
 AccumStats = 0;
-if (OutStream != std::cerr  OutStream != std::cout)
+if (OutStream != cerr.stream()  OutStream != cout.stream())
   delete OutStream;   // Close the file...
   }
 }


Index: llvm/lib/Support/SystemUtils.cpp
diff -u llvm/lib/Support/SystemUtils.cpp:1.47 
llvm/lib/Support/SystemUtils.cpp:1.48
--- llvm/lib/Support/SystemUtils.cpp:1.47   Wed Dec  6 19:30:31 2006
+++ llvm/lib/Support/SystemUtils.cppThu Dec  7 14:28:15 2006
@@ -16,12 +16,12 @@
 #include llvm/Support/SystemUtils.h
 #include llvm/System/Process.h
 #include llvm/System/Program.h
-#include iostream
 using namespace llvm;
 
 bool llvm::CheckBytecodeOutputToConsole(std::ostream* stream_to_check,
 bool print_warning) {
-  if (stream_to_check == std::cout  sys::Process::StandardOutIsDisplayed()) 
{
+  if (stream_to_check == cout.stream() 
+  sys::Process::StandardOutIsDisplayed()) {
 if (print_warning) {
   cerr  WARNING: You're attempting to print out a bytecode file.\n
 This is inadvisable as it may cause display problems. If\n


Index: llvm/lib/Support/Timer.cpp
diff -u llvm/lib/Support/Timer.cpp:1.47 llvm/lib/Support/Timer.cpp:1.48
--- llvm/lib/Support/Timer.cpp:1.47 Wed Dec  6 11:46:32 2006
+++ llvm/lib/Support/Timer.cpp  Thu Dec  7 14:28:15 2006
@@ -14,11 +14,11 @@
 #include llvm/Support/Timer.h
 #include llvm/Support/CommandLine.h
 #include llvm/Support/ManagedStatic.h
+#include llvm/Support/Streams.h
 #include llvm/System/Process.h
 #include algorithm
 #include fstream
 #include functional
-#include iostream
 #include map
 using namespace llvm;
 
@@ -263,17 +263,17 @@
 llvm::GetLibSupportInfoOutputFile() {
   std::string LibSupportInfoOutputFilename = 
getLibSupportInfoOutputFilename();
   if (LibSupportInfoOutputFilename.empty())
-return std::cerr;
+return cerr.stream();
   if (LibSupportInfoOutputFilename == -)
-return std::cout;
+return cout.stream();
 
   std::ostream *Result = new 
std::ofstream(LibSupportInfoOutputFilename.c_str(),
std::ios::app);
   if (!Result-good()) {
-std::cerr  Error opening info-output-file '
-   LibSupportInfoOutputFilename   for appending!\n;
+cerr  Error opening info-output-file '
+  LibSupportInfoOutputFilename   for appending!\n;
 delete Result;
-return std::cerr;
+return cerr.stream();
   }
   return Result;
 }
@@ -342,7 +342,7 @@
 
 TimersToPrint.clear();
 
-if (OutStream != std::cerr  OutStream != std::cout)
+if (OutStream != cerr.stream()  OutStream != cout.stream())
   delete OutStream;   // Close the file...
   }
 



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/Statistic.cpp Timer.cpp

2006-12-06 Thread Chris Lattner


Changes in directory llvm/lib/Support:

Statistic.cpp updated: 1.18 - 1.19
Timer.cpp updated: 1.46 - 1.47
---
Log message:

Detemplatize the Statistic class.  The only type it is instantiated with
is 'unsigned'.



---
Diffs of the changes:  (+2 -4)

 Statistic.cpp |4 +---
 Timer.cpp |2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)


Index: llvm/lib/Support/Statistic.cpp
diff -u llvm/lib/Support/Statistic.cpp:1.18 llvm/lib/Support/Statistic.cpp:1.19
--- llvm/lib/Support/Statistic.cpp:1.18 Tue Aug 29 23:17:00 2006
+++ llvm/lib/Support/Statistic.cpp  Wed Dec  6 11:46:32 2006
@@ -15,7 +15,7 @@
 // This is useful for reporting information like the number of instructions
 // simplified, optimized or removed by various transformations, like this:
 //
-// static Statistic NumInstEliminated(GCSE - Number of instructions 
killed);
+// static Statistic NumInstEliminated(GCSE - Number of instructions killed);
 //
 // Later, in the code: ++NumInstEliminated;
 //
@@ -33,8 +33,6 @@
 
 unsigned StatisticBase::NumStats = 0;
 
-TEMPLATE_INSTANTIATION(class Statisticunsigned);
-
 // -stats - Command line option to cause transformations to emit stats about
 // what they did.
 //


Index: llvm/lib/Support/Timer.cpp
diff -u llvm/lib/Support/Timer.cpp:1.46 llvm/lib/Support/Timer.cpp:1.47
--- llvm/lib/Support/Timer.cpp:1.46 Wed Oct  4 16:50:14 2006
+++ llvm/lib/Support/Timer.cpp  Wed Dec  6 11:46:32 2006
@@ -27,7 +27,7 @@
 
 // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
 // of constructor/destructor ordering being unspecified by C++.  Basically the
-// problem is that a Statistic object gets destroyed, which ends up calling
+// problem is that a Statistic object gets destroyed, which ends up calling
 // 'GetLibSupportInfoOutputFile()' (below), which calls this function.
 // LibSupportInfoOutputFilename used to be a global variable, but sometimes it
 // would get destroyed before the Statistic, causing havoc to ensue.  We fix



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/Statistic.cpp

2006-12-06 Thread Chris Lattner


Changes in directory llvm/lib/Support:

Statistic.cpp updated: 1.19 - 1.20
---
Log message:

merge the Statistic and StatisticBase classes, eliminating virtual methods
and eliminating #includes from the Statistic.h file.


---
Diffs of the changes:  (+5 -10)

 Statistic.cpp |   15 +--
 1 files changed, 5 insertions(+), 10 deletions(-)


Index: llvm/lib/Support/Statistic.cpp
diff -u llvm/lib/Support/Statistic.cpp:1.19 llvm/lib/Support/Statistic.cpp:1.20
--- llvm/lib/Support/Statistic.cpp:1.19 Wed Dec  6 11:46:32 2006
+++ llvm/lib/Support/Statistic.cpp  Wed Dec  6 12:20:44 2006
@@ -23,6 +23,7 @@
 
 #include llvm/ADT/Statistic.h
 #include llvm/Support/CommandLine.h
+#include llvm/ADT/StringExtras.h
 #include sstream
 #include iostream
 #include algorithm
@@ -31,7 +32,7 @@
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
 namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
 
-unsigned StatisticBase::NumStats = 0;
+unsigned Statistic::NumStats = 0;
 
 // -stats - Command line option to cause transformations to emit stats about
 // what they did.
@@ -61,19 +62,13 @@
 
 static std::vectorStatRecord *AccumStats = 0;
 
-// Out of line virtual dtor, to give the vtable etc a home.
-StatisticBase::~StatisticBase() {
-}
-
 // Print information when destroyed, iff command line option is specified
-void StatisticBase::destroy() const {
-  if (Enabled  hasSomeData()) {
+Statistic::~Statistic() {
+  if (Enabled  Value != 0) {
 if (AccumStats == 0)
   AccumStats = new std::vectorStatRecord();
 
-std::ostringstream Out;
-printValue(Out);
-AccumStats-push_back(StatRecord(Out.str(), Name, Desc));
+AccumStats-push_back(StatRecord(utostr(Value), Name, Desc));
   }
 
   if (--NumStats == 0  AccumStats) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits


[llvm-commits] CVS: llvm/lib/Support/Statistic.cpp

2006-06-21 Thread Chris Lattner


Changes in directory llvm/lib/Support:

Statistic.cpp updated: 1.16 - 1.17
---
Log message:

Add some out-of-line virtual dtors so that the class has a home, preventing
vtables for (e.g.) Instruction from being emitted into every .o file.


---
Diffs of the changes:  (+4 -0)

 Statistic.cpp |4 
 1 files changed, 4 insertions(+)


Index: llvm/lib/Support/Statistic.cpp
diff -u llvm/lib/Support/Statistic.cpp:1.16 llvm/lib/Support/Statistic.cpp:1.17
--- llvm/lib/Support/Statistic.cpp:1.16 Thu Apr 21 17:52:05 2005
+++ llvm/lib/Support/Statistic.cpp  Wed Jun 21 11:53:47 2006
@@ -61,6 +61,10 @@
 
 static std::vectorStatRecord *AccumStats = 0;
 
+// Out of line virtual dtor, to give the vtable etc a home.
+StatisticBase::~StatisticBase() {
+}
+
 // Print information when destroyed, iff command line option is specified
 void StatisticBase::destroy() const {
   if (Enabled  hasSomeData()) {



___
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits