From b8fa514b1d05ee9fa8632d2f92b3f6ee03bba384 Mon Sep 17 00:00:00 2001
From: Chris Lattner <sabre@nondot.org>
Date: Tue, 20 Aug 2002 18:47:53 +0000
Subject: [PATCH] Sort -time-passes report first by user+system, then by Wall
 clock time.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3407 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/VMCore/Pass.cpp       | 11 +++++++++++
 lib/VMCore/PassManagerT.h |  4 +---
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/lib/VMCore/Pass.cpp b/lib/VMCore/Pass.cpp
index 24f14f804bf..1c54a1b2d19 100644
--- a/lib/VMCore/Pass.cpp
+++ b/lib/VMCore/Pass.cpp
@@ -107,6 +107,17 @@ static TimeRecord getTimeRecord() {
   return Result;
 }
 
+bool TimeRecord::operator<(const TimeRecord &TR) const {
+  // Primary sort key is User+System time
+  if (UserTime+SystemTime < TR.UserTime+TR.SystemTime)
+    return true;
+  if (UserTime+SystemTime > TR.UserTime+TR.SystemTime)
+    return false;
+
+  // Secondary sort key is Wall Time
+  return Elapsed < TR.Elapsed;
+}
+
 void TimeRecord::passStart(const TimeRecord &T) {
   Elapsed    -= T.Elapsed;
   UserTime   -= T.UserTime;
diff --git a/lib/VMCore/PassManagerT.h b/lib/VMCore/PassManagerT.h
index 83061deac16..9f34f15cca5 100644
--- a/lib/VMCore/PassManagerT.h
+++ b/lib/VMCore/PassManagerT.h
@@ -85,9 +85,7 @@ struct TimeRecord {      // TimeRecord - Data we collect and print for each pass
   void passStart(const TimeRecord &T);
   void passEnd(const TimeRecord &T);
   void sum(const TimeRecord &TR);
-  bool operator<(const TimeRecord &TR) const {
-    return UserTime+SystemTime < TR.UserTime+TR.SystemTime;
-  }
+  bool operator<(const TimeRecord &TR) const;
 
   void print(const char *PassName, const TimeRecord &TotalTime) const;
 };