[llvm-commits] [llvm] r116489 - /llvm/trunk/include/llvm/PassSupport.h
Owen Anderson
resistor at mac.com
Thu Oct 14 10:26:07 PDT 2010
Author: resistor
Date: Thu Oct 14 12:26:06 2010
New Revision: 116489
URL: http://llvm.org/viewvc/llvm-project?rev=116489&view=rev
Log:
Apparently MSVC doesn't support thread-safe static local initialization. Roll our own solution instead.
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=116489&r1=116488&r2=116489&view=diff
==============================================================================
--- llvm/trunk/include/llvm/PassSupport.h (original)
+++ llvm/trunk/include/llvm/PassSupport.h Thu Oct 14 12:26:06 2010
@@ -24,7 +24,7 @@
#include "Pass.h"
#include "llvm/PassRegistry.h"
#include "llvm/InitializePasses.h"
-#include "llvm/Support/Compiler.h"
+#include "llvm/System/Atomic.h"
#include <vector>
namespace llvm {
@@ -137,10 +137,10 @@
return PI; \
} \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
- ATTRIBUTE_USED \
- static void* initialized = initialize##passName##PassOnce(Registry); \
- } \
- static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis);
+ static sys::cas_flag initialized = 0; \
+ sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
+ if (old_val == 0) initialize##passName##PassOnce(Registry); \
+ }
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) {
@@ -157,10 +157,10 @@
return PI; \
} \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
- ATTRIBUTE_USED \
- static void* initialized = initialize##passName##PassOnce(Registry); \
- } \
- static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis);
+ static sys::cas_flag initialized = 0; \
+ sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
+ if (old_val == 0) initialize##passName##PassOnce(Registry); \
+ }
template<typename PassName>
Pass *callDefaultCtor() { return new PassName(); }
@@ -244,10 +244,11 @@
return AI; \
} \
void llvm::initialize##agName##AnalysisGroup(PassRegistry &Registry) { \
- ATTRIBUTE_USED static void* initialized = \
- initialize##agName##AnalysisGroupOnce(Registry); \
- } \
- static RegisterAnalysisGroup<agName> agName##_info (name);
+ static sys::cas_flag initialized = 0; \
+ sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
+ if (old_val == 0) initialize##agName##AnalysisGroupOnce(Registry); \
+ }
+
#define INITIALIZE_AG_PASS(passName, agName, arg, name, cfg, analysis, def) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
@@ -260,11 +261,11 @@
return AI; \
} \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
- ATTRIBUTE_USED \
- static void* initialized = initialize##passName##PassOnce(Registry); \
- } \
- static RegisterPass<passName> passName ## _info(arg, name, cfg, analysis); \
- static RegisterAnalysisGroup<agName, def> passName ## _ag(passName ## _info);
+ static sys::cas_flag initialized = 0; \
+ sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
+ if (old_val == 0) initialize##passName##PassOnce(Registry); \
+ }
+
#define INITIALIZE_AG_PASS_BEGIN(passName, agName, arg, n, cfg, analysis, def) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) {
@@ -279,11 +280,10 @@
return AI; \
} \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
- ATTRIBUTE_USED \
- static void* initialized = initialize##passName##PassOnce(Registry); \
- } \
- static RegisterPass<passName> passName ## _info(arg, n, cfg, analysis); \
- static RegisterAnalysisGroup<agName, def> passName ## _ag(passName ## _info);
+ static sys::cas_flag initialized = 0; \
+ sys::cas_flag old_val = sys::CompareAndSwap(&initialized, 1, 0); \
+ if (old_val == 0) initialize##passName##PassOnce(Registry); \
+ }
//===---------------------------------------------------------------------------
/// PassRegistrationListener class - This class is meant to be derived from by
More information about the llvm-commits
mailing list