summaryrefslogtreecommitdiff
path: root/include/llvm/PassSupport.h
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2010-10-19 18:02:06 +0000
committerOwen Anderson <resistor@mac.com>2010-10-19 18:02:06 +0000
commit62d4ced64c43bf6c01b41bded4f5ea847afd9d3f (patch)
treed5e13d424da2c89aaa96a4db35ec46932ff096b8 /include/llvm/PassSupport.h
parent4cccb87b4d766719cd8cdf98bed1d433d245adb0 (diff)
downloadllvm-62d4ced64c43bf6c01b41bded4f5ea847afd9d3f.tar.gz
llvm-62d4ced64c43bf6c01b41bded4f5ea847afd9d3f.tar.bz2
llvm-62d4ced64c43bf6c01b41bded4f5ea847afd9d3f.tar.xz
Factor out the call-once implementation into its own macro.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116832 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/PassSupport.h')
-rw-r--r--include/llvm/PassSupport.h91
1 files changed, 21 insertions, 70 deletions
diff --git a/include/llvm/PassSupport.h b/include/llvm/PassSupport.h
index 454217970c..c79b41e587 100644
--- a/include/llvm/PassSupport.h
+++ b/include/llvm/PassSupport.h
@@ -129,6 +129,22 @@ private:
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 @@ private:
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 @@ private:
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 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
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 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
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 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
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) \
}
//===---------------------------------------------------------------------------