#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 {
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, \
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);
+ CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
+ }
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) {
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);
+ CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
+ }
template<typename PassName>
Pass *callDefaultCtor() { return new PassName(); }
return AI; \
} \
void llvm::initialize##agName##AnalysisGroup(PassRegistry &Registry) { \
- ATTRIBUTE_USED static void* initialized = \
- initialize##agName##AnalysisGroupOnce(Registry); \
- } \
- static RegisterAnalysisGroup<agName> agName##_info (name);
+ CALL_ONCE_INITIALIZATION(initialize##agName##AnalysisGroupOnce) \
+ }
+
#define INITIALIZE_AG_PASS(passName, agName, arg, name, cfg, analysis, def) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
- initialize##agName##AnalysisGroup(Registry); \
+ if (!def) initialize##agName##AnalysisGroup(Registry); \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis); \
Registry.registerPass(*PI); \
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);
+ CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
+ }
+
#define INITIALIZE_AG_PASS_BEGIN(passName, agName, arg, n, cfg, analysis, def) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
- initialize##agName##AnalysisGroup(Registry);
+ if (!def) initialize##agName##AnalysisGroup(Registry);
#define INITIALIZE_AG_PASS_END(passName, agName, arg, n, cfg, analysis, def) \
PassInfo *PI = new PassInfo(n, arg, & passName ::ID, \
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);
+ CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
+ }
//===---------------------------------------------------------------------------
/// PassRegistrationListener class - This class is meant to be derived from by