[llvm-commits] [llvm] r73993 - in /llvm/trunk: include/llvm/Support/Timer.h include/llvm/System/Atomic.h include/llvm/Type.h lib/Support/Timer.cpp lib/System/Atomic.cpp lib/VMCore/Mangler.cpp

Owen Anderson resistor at mac.com
Tue Jun 23 13:17:23 PDT 2009


Author: resistor
Date: Tue Jun 23 15:17:22 2009
New Revision: 73993

URL: http://llvm.org/viewvc/llvm-project?rev=73993&view=rev
Log:
Revert my last series of commits related to Timer and 64-bit atomics.  Not all the targets
we care about are capable of supporting it.

Modified:
    llvm/trunk/include/llvm/Support/Timer.h
    llvm/trunk/include/llvm/System/Atomic.h
    llvm/trunk/include/llvm/Type.h
    llvm/trunk/lib/Support/Timer.cpp
    llvm/trunk/lib/System/Atomic.cpp
    llvm/trunk/lib/VMCore/Mangler.cpp

Modified: llvm/trunk/include/llvm/Support/Timer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Timer.h?rev=73993&r1=73992&r2=73993&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/Timer.h (original)
+++ llvm/trunk/include/llvm/Support/Timer.h Tue Jun 23 15:17:22 2009
@@ -34,12 +34,12 @@
 /// if they are never started.
 ///
 class Timer {
-  int64_t Elapsed;        // Wall clock time elapsed in seconds
-  int64_t UserTime;       // User time elapsed
-  int64_t SystemTime;     // System time elapsed
-  int64_t MemUsed;       // Memory allocated (in bytes)
-  int64_t PeakMem;        // Peak memory used
-  int64_t PeakMemBase;    // Temporary for peak calculation...
+  double Elapsed;        // Wall clock time elapsed in seconds
+  double UserTime;       // User time elapsed
+  double SystemTime;     // System time elapsed
+  ssize_t MemUsed;       // Memory allocated (in bytes)
+  size_t PeakMem;        // Peak memory used
+  size_t PeakMemBase;    // Temporary for peak calculation...
   std::string Name;      // The name of this time variable
   bool Started;          // Has this time variable ever been started?
   TimerGroup *TG;        // The TimerGroup this Timer is in.
@@ -49,10 +49,10 @@
   Timer(const Timer &T);
   ~Timer();
 
-  int64_t getProcessTime() const { return UserTime+SystemTime; }
-  int64_t getWallTime() const { return Elapsed; }
-  int64_t getMemUsed() const { return MemUsed; }
-  int64_t getPeakMem() const { return PeakMem; }
+  double getProcessTime() const { return UserTime+SystemTime; }
+  double getWallTime() const { return Elapsed; }
+  ssize_t getMemUsed() const { return MemUsed; }
+  size_t getPeakMem() const { return PeakMem; }
   std::string getName() const { return Name; }
 
   const Timer &operator=(const Timer &T) {

Modified: llvm/trunk/include/llvm/System/Atomic.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/System/Atomic.h?rev=73993&r1=73992&r2=73993&view=diff

==============================================================================
--- llvm/trunk/include/llvm/System/Atomic.h (original)
+++ llvm/trunk/include/llvm/System/Atomic.h Tue Jun 23 15:17:22 2009
@@ -20,14 +20,13 @@
   namespace sys {
     void MemoryFence();
 
-    uint32_t CompareAndSwap32(volatile uint32_t* ptr,
-                            uint32_t new_value,
-                            uint32_t old_value);
-    int32_t AtomicIncrement32(volatile int32_t* ptr);
-    int32_t AtomicDecrement32(volatile int32_t* ptr);
-    int32_t AtomicAdd32(volatile int32_t* ptr, int32_t val);
-    
-    int64_t AtomicAdd64(volatile int64_t* ptr, int64_t val);
+    typedef uint32_t cas_flag;
+    cas_flag CompareAndSwap(volatile cas_flag* ptr,
+                            cas_flag new_value,
+                            cas_flag old_value);
+    cas_flag AtomicIncrement(volatile cas_flag* ptr);
+    cas_flag AtomicDecrement(volatile cas_flag* ptr);
+    cas_flag AtomicAdd(volatile cas_flag* ptr, cas_flag val);
   }
 }
 

Modified: llvm/trunk/include/llvm/Type.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Type.h?rev=73993&r1=73992&r2=73993&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Type.h (original)
+++ llvm/trunk/include/llvm/Type.h Tue Jun 23 15:17:22 2009
@@ -103,7 +103,7 @@
   /// has no AbstractTypeUsers, the type is deleted.  This is only sensical for
   /// derived types.
   ///
-  mutable int32_t RefCount;
+  mutable sys::cas_flag RefCount;
 
   const Type *getForwardedTypeInternal() const;
 
@@ -338,7 +338,7 @@
 
   void addRef() const {
     assert(isAbstract() && "Cannot add a reference to a non-abstract type!");
-    sys::AtomicIncrement32(&RefCount);
+    sys::AtomicIncrement(&RefCount);
   }
 
   void dropRef() const {
@@ -347,8 +347,8 @@
 
     // If this is the last PATypeHolder using this object, and there are no
     // PATypeHandles using it, the type is dead, delete it now.
-    int32_t Count = sys::AtomicDecrement32(&RefCount);
-    if (Count == 0 && AbstractTypeUsers.empty())
+    sys::cas_flag OldCount = sys::AtomicDecrement(&RefCount);
+    if (OldCount == 0 && AbstractTypeUsers.empty())
       this->destroy();
   }
   

Modified: llvm/trunk/lib/Support/Timer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Timer.cpp?rev=73993&r1=73992&r2=73993&view=diff

==============================================================================
--- llvm/trunk/lib/Support/Timer.cpp (original)
+++ llvm/trunk/lib/Support/Timer.cpp Tue Jun 23 15:17:22 2009
@@ -112,7 +112,8 @@
 }
 
 struct TimeRecord {
-  int64_t Elapsed, UserTime, SystemTime, MemUsed;
+  double Elapsed, UserTime, SystemTime;
+  ssize_t MemUsed;
 };
 
 static TimeRecord getTimeRecord(bool Start) {
@@ -122,7 +123,7 @@
   sys::TimeValue user(0,0);
   sys::TimeValue sys(0,0);
 
-  int64_t MemUsed = 0;
+  ssize_t MemUsed = 0;
   if (Start) {
     MemUsed = getMemUsage();
     sys::Process::GetTimeUsage(now,user,sys);
@@ -131,9 +132,9 @@
     MemUsed = getMemUsage();
   }
 
-  Result.Elapsed  = now.seconds() * 1000000 + now.microseconds();
-  Result.UserTime = user.seconds() * 1000000 + user.microseconds();
-  Result.SystemTime  = sys.seconds() * 1000000 + sys.microseconds();
+  Result.Elapsed  = now.seconds()  + now.microseconds()  / 1000000.0;
+  Result.UserTime = user.seconds() + user.microseconds() / 1000000.0;
+  Result.SystemTime  = sys.seconds()  + sys.microseconds()  / 1000000.0;
   Result.MemUsed  = MemUsed;
 
   return Result;
@@ -182,11 +183,11 @@
 /// currently active timers, which will be printed when the timer group prints
 ///
 void Timer::addPeakMemoryMeasurement() {
-  int64_t MemUsed = getMemUsage();
+  size_t MemUsed = getMemUsage();
 
   for (std::vector<Timer*>::iterator I = ActiveTimers->begin(),
          E = ActiveTimers->end(); I != E; ++I)
-    (*I)->PeakMem = std::max((*I)->PeakMem, (int64_t)MemUsed-(*I)->PeakMemBase);
+    (*I)->PeakMem = std::max((*I)->PeakMem, MemUsed-(*I)->PeakMemBase);
 }
 
 //===----------------------------------------------------------------------===//
@@ -276,13 +277,12 @@
 
 void Timer::print(const Timer &Total, std::ostream &OS) {
   if (Total.UserTime)
-    printVal(UserTime / 1000000.0, Total.UserTime / 1000000.0, OS);
+    printVal(UserTime, Total.UserTime, OS);
   if (Total.SystemTime)
-    printVal(SystemTime / 1000000.0, Total.SystemTime / 1000000.0, OS);
+    printVal(SystemTime, Total.SystemTime, OS);
   if (Total.getProcessTime())
-    printVal(getProcessTime() / 1000000.0,
-             Total.getProcessTime() / 1000000.0, OS);
-  printVal(Elapsed / 1000000.0, Total.Elapsed / 1000000.0, OS);
+    printVal(getProcessTime(), Total.getProcessTime(), OS);
+  printVal(Elapsed, Total.Elapsed, OS);
 
   OS << "  ";
 
@@ -355,23 +355,23 @@
       if (this != DefaultTimerGroup) {
         *OutStream << "  Total Execution Time: ";
 
-        printAlignedFP(Total.getProcessTime() / 1000000.0, 4, 5, *OutStream);
+        printAlignedFP(Total.getProcessTime(), 4, 5, *OutStream);
         *OutStream << " seconds (";
-        printAlignedFP(Total.getWallTime() / 1000000.0, 4, 5, *OutStream);
+        printAlignedFP(Total.getWallTime(), 4, 5, *OutStream);
         *OutStream << " wall clock)\n";
       }
       *OutStream << "\n";
 
-      if (Total.UserTime / 1000000.0)
+      if (Total.UserTime)
         *OutStream << "   ---User Time---";
-      if (Total.SystemTime / 1000000.0)
+      if (Total.SystemTime)
         *OutStream << "   --System Time--";
-      if (Total.getProcessTime() / 1000000.0)
+      if (Total.getProcessTime())
         *OutStream << "   --User+System--";
       *OutStream << "   ---Wall Time---";
-      if (Total.getMemUsed() / 1000000.0)
+      if (Total.getMemUsed())
         *OutStream << "  ---Mem---";
-      if (Total.getPeakMem() / 1000000.0)
+      if (Total.getPeakMem())
         *OutStream << "  -PeakMem-";
       *OutStream << "  --- Name ---\n";
 

Modified: llvm/trunk/lib/System/Atomic.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/System/Atomic.cpp?rev=73993&r1=73992&r2=73993&view=diff

==============================================================================
--- llvm/trunk/lib/System/Atomic.cpp (original)
+++ llvm/trunk/lib/System/Atomic.cpp Tue Jun 23 15:17:22 2009
@@ -35,11 +35,11 @@
 #endif
 }
 
-uint32_t sys::CompareAndSwap32(volatile uint32_t* ptr,
-                               uint32_t new_value,
-                               uint32_t old_value) {
+sys::cas_flag sys::CompareAndSwap(volatile sys::cas_flag* ptr,
+                                  sys::cas_flag new_value,
+                                  sys::cas_flag old_value) {
 #if LLVM_MULTITHREADED==0
-  uint32_t result = *ptr;
+  sys::cas_flag result = *ptr;
   if (result == old_value)
     *ptr = new_value;
   return result;
@@ -52,7 +52,7 @@
 #endif
 }
 
-int32_t sys::AtomicIncrement32(volatile int32_t* ptr) {
+sys::cas_flag sys::AtomicIncrement(volatile sys::cas_flag* ptr) {
 #if LLVM_MULTITHREADED==0
   ++(*ptr);
   return *ptr;
@@ -65,7 +65,7 @@
 #endif
 }
 
-int32_t sys::AtomicDecrement32(volatile int32_t* ptr) {
+sys::cas_flag sys::AtomicDecrement(volatile sys::cas_flag* ptr) {
 #if LLVM_MULTITHREADED==0
   --(*ptr);
   return *ptr;
@@ -78,7 +78,7 @@
 #endif
 }
 
-int32_t sys::AtomicAdd32(volatile int32_t* ptr, int32_t val) {
+sys::cas_flag sys::AtomicAdd(volatile sys::cas_flag* ptr, sys::cas_flag val) {
 #if LLVM_MULTITHREADED==0
   *ptr += val;
   return *ptr;
@@ -91,16 +91,4 @@
 #endif
 }
 
-int64_t sys::AtomicAdd64(volatile int64_t* ptr, int64_t val) {
-#if LLVM_MULTITHREADED==0
-  *ptr += val;
-  return *ptr;
-#elif defined(__GNUC__)
-  return __sync_add_and_fetch(ptr, val);
-#elif defined(_MSC_VER)
-  return InterlockedAdd64(ptr, val);
-#else
-#  error No atomic add implementation for your platform!
-#endif
-}
 

Modified: llvm/trunk/lib/VMCore/Mangler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Mangler.cpp?rev=73993&r1=73992&r2=73993&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Mangler.cpp (original)
+++ llvm/trunk/lib/VMCore/Mangler.cpp Tue Jun 23 15:17:22 2009
@@ -165,10 +165,10 @@
   } else if (!GV->hasName()) {
     // Must mangle the global into a unique ID.
     unsigned TypeUniqueID = getTypeID(GV->getType());
-    static int32_t GlobalID = 0;
+    static uint32_t GlobalID = 0;
     
-    int32_t OldID = GlobalID;
-    sys::AtomicIncrement32(&GlobalID);
+    unsigned OldID = GlobalID;
+    sys::AtomicIncrement(&GlobalID);
     
     Name = "__unnamed_" + utostr(TypeUniqueID) + "_" + utostr(OldID);
   } else {





More information about the llvm-commits mailing list