Skip to content

Commit

Permalink
Create macro INITIALIZE_TM_PASS.
Browse files Browse the repository at this point in the history
Pass initialization requires to initialize TargetMachine for back-end
specific passes. This commit creates a new macro INITIALIZE_TM_PASS to
simplify this kind of initialization.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210641 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Jiangning Liu committed Jun 11, 2014
1 parent f847ccb commit e65c403
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 42 deletions.
12 changes: 12 additions & 0 deletions include/llvm/PassSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,18 @@ class PassInfo {
} \
TsanHappensAfter(&initialized);

#define INITIALIZE_TM_PASS(passName, arg, name, cfg, analysis) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
PassInfo::NormalCtor_t(callDefaultCtor< passName >), cfg, analysis, \
PassInfo::TargetMachineCtor_t(callTargetMachineCtor< passName >)); \
Registry.registerPass(*PI, true); \
return PI; \
} \
void llvm::initialize##passName##Pass(PassRegistry &Registry) { \
CALL_ONCE_INITIALIZATION(initialize##passName##PassOnce) \
}

#define INITIALIZE_PASS(passName, arg, name, cfg, analysis) \
static void* initialize##passName##PassOnce(PassRegistry &Registry) { \
PassInfo *PI = new PassInfo(name, arg, & passName ::ID, \
Expand Down
19 changes: 3 additions & 16 deletions lib/CodeGen/AtomicExpandLoadLinkedPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,9 @@ namespace {

char AtomicExpandLoadLinked::ID = 0;
char &llvm::AtomicExpandLoadLinkedID = AtomicExpandLoadLinked::ID;

static void *initializeAtomicExpandLoadLinkedPassOnce(PassRegistry &Registry) {
PassInfo *PI = new PassInfo(
"Expand Atomic calls in terms of load-linked & store-conditional",
"atomic-ll-sc", &AtomicExpandLoadLinked::ID,
PassInfo::NormalCtor_t(callDefaultCtor<AtomicExpandLoadLinked>), false,
false, PassInfo::TargetMachineCtor_t(
callTargetMachineCtor<AtomicExpandLoadLinked>));
Registry.registerPass(*PI, true);
return PI;
}

void llvm::initializeAtomicExpandLoadLinkedPass(PassRegistry &Registry) {
CALL_ONCE_INITIALIZATION(initializeAtomicExpandLoadLinkedPassOnce)
}

INITIALIZE_TM_PASS(AtomicExpandLoadLinked, "atomic-ll-sc",
"Expand Atomic calls in terms of load-linked & store-conditional",
false, false)

FunctionPass *llvm::createAtomicExpandLoadLinkedPass(const TargetMachine *TM) {
return new AtomicExpandLoadLinked(TM);
Expand Down
15 changes: 2 additions & 13 deletions lib/CodeGen/CodeGenPrepare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,8 @@ typedef DenseMap<Instruction *, Type *> InstrToOrigTy;
}

char CodeGenPrepare::ID = 0;
static void *initializeCodeGenPreparePassOnce(PassRegistry &Registry) {
initializeTargetLibraryInfoPass(Registry);
PassInfo *PI = new PassInfo(
"Optimize for code generation", "codegenprepare", &CodeGenPrepare::ID,
PassInfo::NormalCtor_t(callDefaultCtor<CodeGenPrepare>), false, false,
PassInfo::TargetMachineCtor_t(callTargetMachineCtor<CodeGenPrepare>));
Registry.registerPass(*PI, true);
return PI;
}

void llvm::initializeCodeGenPreparePass(PassRegistry &Registry) {
CALL_ONCE_INITIALIZATION(initializeCodeGenPreparePassOnce)
}
INITIALIZE_TM_PASS(CodeGenPrepare, "codegenprepare",
"Optimize for code generation", false, false)

FunctionPass *llvm::createCodeGenPreparePass(const TargetMachine *TM) {
return new CodeGenPrepare(TM);
Expand Down
15 changes: 2 additions & 13 deletions lib/Transforms/Scalar/GlobalMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,8 @@ namespace {
} // end anonymous namespace

char GlobalMerge::ID = 0;

static void *initializeGlobalMergePassOnce(PassRegistry &Registry) {
PassInfo *PI = new PassInfo(
"Merge global variables", "global-merge", &GlobalMerge::ID,
PassInfo::NormalCtor_t(callDefaultCtor<GlobalMerge>), false, false,
PassInfo::TargetMachineCtor_t(callTargetMachineCtor<GlobalMerge>));
Registry.registerPass(*PI, true);
return PI;
}

void llvm::initializeGlobalMergePass(PassRegistry &Registry) {
CALL_ONCE_INITIALIZATION(initializeGlobalMergePassOnce)
}
INITIALIZE_TM_PASS(GlobalMerge, "global-merge", "Merge global variables",
false, false)

bool GlobalMerge::doMerge(SmallVectorImpl<GlobalVariable*> &Globals,
Module &M, bool isConst, unsigned AddrSpace) const {
Expand Down

0 comments on commit e65c403

Please sign in to comment.