From 129458a7ed168f652dbaeb5c242bd0d5048ef249 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Fri, 10 Jun 2016 00:52:10 +0000 Subject: [llc] Add support for several run-pass options. Previously we could run only one machine pass with the run-pass option. With that patch, we can now specify several passes with several run-pass options (or just one option with a list of comma separated passes) and llc will build the related pipeline. This is great to test the interaction of two passes that are not necessarily next to each other in the pipeline, or play with pass ordering. Now, we should be at parity with opt for the flexibility of running passes. Note: I also moved the run pass option from CommandFlags.h to llc.cpp because, really, this is needed only there! llvm-svn: 272356 --- llvm/tools/llc/llc.cpp | 77 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 27 deletions(-) (limited to 'llvm/tools') diff --git a/llvm/tools/llc/llc.cpp b/llvm/tools/llc/llc.cpp index 981a6c34de1..51ce3c0f2bf 100644 --- a/llvm/tools/llc/llc.cpp +++ b/llvm/tools/llc/llc.cpp @@ -118,6 +118,28 @@ static cl::opt ExitOnError( cl::desc("Exit as soon as an error is encountered."), cl::init(false), cl::Hidden); +namespace { +static ManagedStatic> RunPassNames; + +struct RunPassOption { + void operator=(const std::string &Val) const { + if (Val.empty()) + return; + SmallVector PassNames; + StringRef(Val).split(PassNames, ',', -1, false); + for (auto PassName : PassNames) + RunPassNames->push_back(PassName); + } +}; +} + +static RunPassOption RunPassOpt; + +static cl::opt> RunPass( + "run-pass", + cl::desc("Run compiler only for specified passes (comma separated list)"), + cl::value_desc("pass-name"), cl::ZeroOrMore, cl::location(RunPassOpt)); + static int compileModule(char **, LLVMContext &); static std::unique_ptr @@ -379,7 +401,7 @@ static int compileModule(char **argv, LLVMContext &Context) { AnalysisID StartAfterID = nullptr; AnalysisID StopAfterID = nullptr; const PassRegistry *PR = PassRegistry::getPassRegistry(); - if (!RunPass.empty()) { + if (!RunPassNames->empty()) { if (!StartAfter.empty() || !StopAfter.empty()) { errs() << argv[0] << ": start-after and/or stop-after passes are " "redundant when run-pass is specified.\n"; @@ -389,33 +411,34 @@ static int compileModule(char **argv, LLVMContext &Context) { errs() << argv[0] << ": run-pass needs a .mir input.\n"; return 1; } - const PassInfo *PI = PR->getPassInfo(RunPass); - if (!PI) { - errs() << argv[0] << ": run-pass pass is not registered.\n"; - return 1; - } - LLVMTargetMachine &LLVMTM = static_cast(*Target); - TargetPassConfig *TPC = LLVMTM.createPassConfig(PM); - PM.add(TPC); - LLVMTM.addMachineModuleInfo(PM); - LLVMTM.addMachineFunctionAnalysis(PM, MIR.get()); - TPC->printAndVerify(""); - - 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; + for (std::string &RunPassName : *RunPassNames) { + const PassInfo *PI = PR->getPassInfo(RunPassName); + if (!PI) { + errs() << argv[0] << ": run-pass " << RunPassName << " is not registered.\n"; + return 1; + } + LLVMTargetMachine &LLVMTM = static_cast(*Target); + TargetPassConfig *TPC = LLVMTM.createPassConfig(PM); + PM.add(TPC); + LLVMTM.addMachineModuleInfo(PM); + LLVMTM.addMachineFunctionAnalysis(PM, MIR.get()); + TPC->printAndVerify(""); + + 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); } - std::string Banner - = std::string("After ") + std::string(P->getPassName()); - PM.add(P); - TPC->printAndVerify(Banner); - PM.add(createPrintMIRPass(errs())); } else { if (!StartAfter.empty()) { -- cgit v1.2.3