llc: Move pass query/add code into an own function; NFC

llvm-svn: 275663
This commit is contained in:
Matthias Braun 2016-07-16 02:24:15 +00:00
parent c92a5fc9f6
commit c0d2a617f7
1 changed files with 30 additions and 23 deletions

View File

@ -267,6 +267,31 @@ int main(int argc, char **argv) {
return 0;
}
static bool addPass(PassManagerBase &PM, const char *argv0,
StringRef PassName, TargetPassConfig &TPC) {
const PassRegistry *PR = PassRegistry::getPassRegistry();
const PassInfo *PI = PR->getPassInfo(PassName);
if (!PI) {
errs() << argv0 << ": run-pass " << PassName << " is not registered.\n";
return true;
}
Pass *P;
if (PI->getTargetMachineCtor())
P = PI->getTargetMachineCtor()(&TPC.getTM<TargetMachine>());
else if (PI->getNormalCtor())
P = PI->getNormalCtor()();
else {
errs() << argv0 << ": cannot create pass: " << PI->getPassName() << "\n";
return true;
}
std::string Banner = std::string("After ") + std::string(P->getPassName());
PM.add(P);
TPC.printAndVerify(Banner);
return false;
}
static int compileModule(char **argv, LLVMContext &Context) {
// Load the module to be compiled...
SMDiagnostic Err;
@ -412,33 +437,15 @@ static int compileModule(char **argv, LLVMContext &Context) {
return 1;
}
LLVMTargetMachine &LLVMTM = static_cast<LLVMTargetMachine&>(*Target);
TargetPassConfig *TPC = LLVMTM.createPassConfig(PM);
PM.add(TPC);
TargetPassConfig &TPC = *LLVMTM.createPassConfig(PM);
PM.add(&TPC);
LLVMTM.addMachineModuleInfo(PM);
LLVMTM.addMachineFunctionAnalysis(PM, MIR.get());
TPC->printAndVerify("");
TPC.printAndVerify("");
for (std::string &RunPassName : *RunPassNames) {
const PassInfo *PI = PR->getPassInfo(RunPassName);
if (!PI) {
errs() << argv[0] << ": run-pass " << RunPassName << " is not registered.\n";
for (const std::string &RunPassName : *RunPassNames) {
if (addPass(PM, argv[0], RunPassName, TPC))
return 1;
}
Pass *P;
if (PI->getTargetMachineCtor())
P = PI->getTargetMachineCtor()(Target.get());
else if (PI->getNormalCtor())
P = PI->getNormalCtor()();
else {
errs() << argv[0] << ": cannot create pass: "
<< PI->getPassName() << "\n";
return 1;
}
std::string Banner
= std::string("After ") + std::string(P->getPassName());
PM.add(P);
TPC->printAndVerify(Banner);
}
PM.add(createPrintMIRPass(*OS));
} else {