Take advantage of C++'s thread-safe static local initialization to simplify thread-safe pass initialization.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@116426 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Owen Anderson 2010-10-13 20:24:34 +00:00
parent 72731a6c19
commit 972beb5431

View File

@ -24,6 +24,7 @@
#include "Pass.h"
#include "llvm/PassRegistry.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/Compiler.h"
#include <vector>
namespace llvm {
@ -129,21 +130,20 @@ private:
};
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
static bool initialized = false; \
if (initialized) return; \
initialized = true; \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis); \
Registry.registerPass(*PI); \
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);
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis) \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
static bool initialized = false; \
if (initialized) return; \
initialized = true;
static void* initialize##passName##PassOnce(PassRegistry &Registry) {
#define INITIALIZE_PASS_DEPENDENCY(depName) \
initialize##depName##Pass(Registry);
@ -154,6 +154,11 @@ private:
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis); \
Registry.registerPass(*PI); \
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);
@ -232,14 +237,19 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
};
#define INITIALIZE_ANALYSIS_GROUP(agName, name) \
void llvm::initialize##agName##AnalysisGroup(PassRegistry &Registry) { \
static void* initialize##agName##AnalysisGroupOnce(PassRegistry &Registry) { \
PassInfo *AI = new PassInfo(name, & agName :: ID); \
Registry.registerAnalysisGroup(& agName ::ID, 0, *AI, false); \
return AI; \
} \
void llvm::initialize##agName##AnalysisGroup(PassRegistry &Registry) { \
ATTRIBUTE_USED static void* initialized = \
initialize##agName##AnalysisGroupOnce(Registry); \
} \
static RegisterAnalysisGroup<agName> agName##_info (name);
#define INITIALIZE_AG_PASS(passName, agName, arg, name, cfg, analysis, def) \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
initialize##agName##AnalysisGroup(Registry); \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis); \
@ -247,12 +257,17 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
\
PassInfo *AI = new PassInfo(name, & agName :: ID); \
Registry.registerAnalysisGroup(& agName ::ID, & passName ::ID, *AI, def); \
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);
#define INITIALIZE_AG_PASS_BEGIN(passName, agName, arg, n, cfg, analysis, def) \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
initialize##agName##AnalysisGroup(Registry);
#define INITIALIZE_AG_PASS_END(passName, agName, arg, n, cfg, analysis, def) \
@ -262,6 +277,11 @@ struct RegisterAnalysisGroup : public RegisterAGBase {
\
PassInfo *AI = new PassInfo(n, & agName :: ID); \
Registry.registerAnalysisGroup(& agName ::ID, & passName ::ID, *AI, def); \
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);