[llvm-commits] [llvm] r116832 - /llvm/trunk/include/llvm/PassSupport.h

Owen Anderson resistor at mac.com
Tue Oct 19 11:02:07 PDT 2010


Author: resistor
Date: Tue Oct 19 13:02:06 2010
New Revision: 116832

URL: http://llvm.org/viewvc/llvm-project?rev=116832&view=rev
Log:
Factor out the call-once implementation into its own macro.

Modified:
    llvm/trunk/include/llvm/PassSupport.h

Modified: llvm/trunk/include/llvm/PassSupport.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/PassSupport.h?rev=116832&r1=116831&r2=116832&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassSupport.h (original)
+++ llvm/trunk/include/llvm/PassSupport.h Tue Oct 19 13:02:06 2010
@@ -129,6 +129,22 @@
   PassInfo(const PassInfo &);       // do not implement
 };
 
+#define CALL_ONCE_INITIALIZATION(function) \
+  static volatile sys::cas_flag initialized = 0; \
+  sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
+  if (old_val == 0) { \
+    function(Registry); \
+    sys::MemoryFence(); \
+    initialized = 2; \
+  } else { \
+    sys::cas_flag tmp = initialized; \
+    sys::MemoryFence(); \
+    while (tmp != 2) { \
+      tmp = initialized; \
+      sys::MemoryFence(); \
+    } \
+  } \
+
 #define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
   static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
     PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
@@ -137,20 +153,7 @@
     return PI; \
   } \
   void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
-    static volatile sys::cas_flag initialized = 0; \
-    sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
-    if (old_val == 0) { \
-      initialize##passName##PassOnce(Registry); \
-      sys::MemoryFence(); \
-      initialized = 2; \
-    } else { \
-      sys::cas_flag tmp = initialized; \
-      sys::MemoryFence(); \
-      while (tmp != 2) { \
-        tmp = initialized; \
-        sys::MemoryFence(); \
-      } \
-    } \
+    CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
   }
 
 #define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis) \
@@ -168,20 +171,7 @@
     return PI; \
   } \
   void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
-    static volatile sys::cas_flag initialized = 0; \
-    sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
-    if (old_val == 0) { \
-      initialize##passName##PassOnce(Registry); \
-      sys::MemoryFence(); \
-      initialized = 2; \
-    } else { \
-      sys::cas_flag tmp = initialized; \
-      sys::MemoryFence(); \
-      while (tmp != 2) { \
-        tmp = initialized; \
-        sys::MemoryFence(); \
-      } \
-    } \
+    CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
   }
 
 template<typename PassName>
@@ -266,20 +256,7 @@
     return AI; \
   } \
   void llvm::initialize##agName##AnalysisGroup(PassRegistry &Registry) { \
-    static volatile sys::cas_flag initialized = 0; \
-    sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
-    if (old_val == 0) { \
-      initialize##agName##AnalysisGroupOnce(Registry); \
-      sys::MemoryFence(); \
-      initialized = 2; \
-    } else { \
-      sys::cas_flag tmp = initialized; \
-      sys::MemoryFence(); \
-      while (tmp != 2) { \
-        tmp = initialized; \
-        sys::MemoryFence(); \
-      } \
-    } \
+    CALL_ONCE_INITIALIZATION(initialize##agName##AnalysisGroupOnce) \
   }
 
 
@@ -295,20 +272,7 @@
     return AI; \
   } \
   void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
-    static volatile sys::cas_flag initialized = 0; \
-    sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
-    if (old_val == 0) { \
-      initialize##passName##PassOnce(Registry); \
-      sys::MemoryFence(); \
-      initialized = 2; \
-    } else { \
-      sys::cas_flag tmp = initialized; \
-      sys::MemoryFence(); \
-      while (tmp != 2) { \
-        tmp = initialized; \
-        sys::MemoryFence(); \
-      } \
-    } \
+    CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
   }
 
 
@@ -326,20 +290,7 @@
     return AI; \
   } \
   void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
-    static volatile sys::cas_flag initialized = 0; \
-    sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
-    if (old_val == 0) { \
-      initialize##passName##PassOnce(Registry); \
-      sys::MemoryFence(); \
-      initialized = 2; \
-    } else { \
-      sys::cas_flag tmp = initialized; \
-      sys::MemoryFence(); \
-      while (tmp != 2) { \
-        tmp = initialized; \
-        sys::MemoryFence(); \
-      } \
-    } \
+    CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
   }
 
 //===---------------------------------------------------------------------------





More information about the llvm-commits mailing list