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;
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 {