Implement cast fp -> bool
[oota-llvm.git] / lib / Support / Timer.cpp
index 98001287d9a03a0cf1a5eeedf32182197900a6de..5d493b8a15e2e329b073362fea01235e384468b3 100644 (file)
@@ -1,4 +1,11 @@
 //===-- Timer.cpp - Interval Timing Support -------------------------------===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 // Interval Timing implementation.
 //
 
 #include "Support/Timer.h"
 #include "Support/CommandLine.h"
-
 #include "Config/sys/resource.h"
 #include "Config/sys/time.h"
 #include "Config/unistd.h"
 #include "Config/malloc.h"
-#include "Config/stdio.h"
 #include <iostream>
 #include <algorithm>
 #include <functional>
 #include <fstream>
+#include <map>
+using namespace llvm;
+
+// GetLibSupportInfoOutputFile - Return a file stream to print our output on...
+namespace llvm { extern std::ostream *GetLibSupportInfoOutputFile(); }
 
 // getLibSupportInfoOutputFilename - This ugly hack is brought to you courtesy
 // of constructor/destructor ordering being unspecified by C++.  Basically the
@@ -114,9 +124,9 @@ static TimeRecord getTimeRecord(bool Start) {
   gettimeofday(&T, 0);
 
   if (!Start) {
-    MemUsed = getMemUsage();
     if (getrusage(RUSAGE_SELF, &RU))
       perror("getrusage call failed: -time-passes info incorrect!");
+    MemUsed = getMemUsage();
   }
 
   TimeRecord Result;
@@ -178,6 +188,23 @@ void Timer::addPeakMemoryMeasurement() {
     (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
 }
 
+//===----------------------------------------------------------------------===//
+//   NamedRegionTimer Implementation
+//===----------------------------------------------------------------------===//
+
+static Timer &getNamedRegionTimer(const std::string &Name) {
+  static std::map<std::string, Timer> NamedTimers;
+
+  std::map<std::string, Timer>::iterator I = NamedTimers.lower_bound(Name);
+  if (I != NamedTimers.end() && I->first == Name)
+    return I->second;
+
+  return NamedTimers.insert(I, std::make_pair(Name, Timer(Name)))->second;
+}
+
+NamedRegionTimer::NamedRegionTimer(const std::string &Name)
+  : TimeRegion(getNamedRegionTimer(Name)) {}
+
 
 //===----------------------------------------------------------------------===//
 //   TimerGroup Implementation
@@ -242,7 +269,8 @@ void Timer::print(const Timer &Total, std::ostream &OS) {
 }
 
 // GetLibSupportInfoOutputFile - Return a file stream to print our output on...
-std::ostream *GetLibSupportInfoOutputFile() {
+std::ostream *
+llvm::GetLibSupportInfoOutputFile() {
   std::string &LibSupportInfoOutputFilename = getLibSupportInfoOutputFilename();
   if (LibSupportInfoOutputFilename.empty())
     return &std::cerr;
@@ -326,3 +354,4 @@ void TimerGroup::removeTimer() {
     DefaultTimerGroup = 0;
   }
 }
+