From c8cb7f611fdf4d96c4d23a75aa48c93cca38646f Mon Sep 17 00:00:00 2001 From: Bjorn Pettersson Date: Thu, 16 Sep 2021 09:28:32 +0200 Subject: [PATCH] [NewPM] Make InlinerPass (aka 'inline') a parameterized pass In default pipelines the ModuleInlinerWrapperPass is adding the InlinerPass to the pipeline twice, once due to MandatoryFirst (passing true in the ctor) and then a second time with false as argument. To make it possible to bisect and reduce opt test cases for this part of the pipeline we need to be able to choose between the two different variants of the InlinerPass when running opt. This patch is changing 'inline' to a CGSCC_PASS_WITH_PARAMS in the PassRegistry, making it possible run opt with both -passes=cgscc(inline) and -passes=cgscc(inline). Reviewed By: aeubanks, mtrofin Differential Revision: https://reviews.llvm.org/D109877 --- llvm/include/llvm/Transforms/IPO/Inliner.h | 3 +++ llvm/lib/Passes/PassBuilder.cpp | 31 ++++++++++++++++++++++++++++++ llvm/lib/Passes/PassRegistry.def | 13 ++++++++++++- llvm/lib/Transforms/IPO/Inliner.cpp | 8 ++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/llvm/include/llvm/Transforms/IPO/Inliner.h b/llvm/include/llvm/Transforms/IPO/Inliner.h index 23a39d7..4b565ad 100644 --- a/llvm/include/llvm/Transforms/IPO/Inliner.h +++ b/llvm/include/llvm/Transforms/IPO/Inliner.h @@ -103,6 +103,9 @@ public: PreservedAnalyses run(LazyCallGraph::SCC &C, CGSCCAnalysisManager &AM, LazyCallGraph &CG, CGSCCUpdateResult &UR); + void printPipeline(raw_ostream &OS, + function_ref MapClassName2PassName); + private: InlineAdvisor &getAdvisor(const ModuleAnalysisManagerCGSCCProxy::Result &MAM, FunctionAnalysisManager &FAM, Module &M); diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index cda24c8..482cf58 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -386,6 +386,8 @@ PassBuilder::PassBuilder(TargetMachine *TM, PipelineTuningOptions PTO, PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); #define CGSCC_PASS(NAME, CREATE_PASS) \ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); +#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ + PIC->addClassToPassName(CLASS, NAME); #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); #include "PassRegistry.def" @@ -558,6 +560,10 @@ Expected parseSinglePassOption(StringRef Params, StringRef OptionName, return Result; } +Expected parseInlinerPassOptions(StringRef Params) { + return parseSinglePassOption(Params, "only-mandatory", "InlinerPass"); +} + Expected parseEarlyCSEPassOptions(StringRef Params) { return parseSinglePassOption(Params, "memssa", "EarlyCSE"); } @@ -863,6 +869,9 @@ static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) { #define CGSCC_PASS(NAME, CREATE_PASS) \ if (Name == NAME) \ return true; +#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ + if (checkParametrizedPassName(Name, NAME)) \ + return true; #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \ return true; @@ -1107,6 +1116,15 @@ Error PassBuilder::parseModulePass(ModulePassManager &MPM, MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS)); \ return Error::success(); \ } +#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ + if (checkParametrizedPassName(Name, NAME)) { \ + auto Params = parsePassParameters(PARSER, Name, NAME); \ + if (!Params) \ + return Params.takeError(); \ + MPM.addPass( \ + createModuleToPostOrderCGSCCPassAdaptor(CREATE_PASS(Params.get()))); \ + return Error::success(); \ + } #define FUNCTION_PASS(NAME, CREATE_PASS) \ if (Name == NAME) { \ MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \ @@ -1201,6 +1219,14 @@ Error PassBuilder::parseCGSCCPass(CGSCCPassManager &CGPM, CGPM.addPass(CREATE_PASS); \ return Error::success(); \ } +#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ + if (checkParametrizedPassName(Name, NAME)) { \ + auto Params = parsePassParameters(PARSER, Name, NAME); \ + if (!Params) \ + return Params.takeError(); \ + CGPM.addPass(CREATE_PASS(Params.get())); \ + return Error::success(); \ + } #define CGSCC_ANALYSIS(NAME, CREATE_PASS) \ if (Name == "require<" NAME ">") { \ CGPM.addPass(RequireAnalysisPass< \ @@ -1683,6 +1709,11 @@ void PassBuilder::printPassNames(raw_ostream &OS) { #define CGSCC_PASS(NAME, CREATE_PASS) printPassName(NAME, OS); #include "PassRegistry.def" + OS << "CGSCC passes with params:\n"; +#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ + printPassName(NAME, PARAMS, OS); +#include "PassRegistry.def" + OS << "CGSCC analyses:\n"; #define CGSCC_ANALYSIS(NAME, CREATE_PASS) printPassName(NAME, OS); #include "PassRegistry.def" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index bb71ebe..655c472 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -162,12 +162,23 @@ CGSCC_PASS("argpromotion", ArgumentPromotionPass()) CGSCC_PASS("invalidate", InvalidateAllAnalysesPass()) CGSCC_PASS("function-attrs", PostOrderFunctionAttrsPass()) CGSCC_PASS("attributor-cgscc", AttributorCGSCCPass()) -CGSCC_PASS("inline", InlinerPass()) CGSCC_PASS("openmp-opt-cgscc", OpenMPOptCGSCCPass()) CGSCC_PASS("coro-split", CoroSplitPass()) CGSCC_PASS("no-op-cgscc", NoOpCGSCCPass()) #undef CGSCC_PASS +#ifndef CGSCC_PASS_WITH_PARAMS +#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) +#endif +CGSCC_PASS_WITH_PARAMS("inline", + "InlinerPass", + [](bool OnlyMandatory) { + return InlinerPass(OnlyMandatory); + }, + parseInlinerPassOptions, + "only-mandatory") +#undef CGSCC_PASS_WITH_PARAMS + #ifndef FUNCTION_ANALYSIS #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) #endif diff --git a/llvm/lib/Transforms/IPO/Inliner.cpp b/llvm/lib/Transforms/IPO/Inliner.cpp index b3480bf..a11782f 100644 --- a/llvm/lib/Transforms/IPO/Inliner.cpp +++ b/llvm/lib/Transforms/IPO/Inliner.cpp @@ -1053,3 +1053,11 @@ PreservedAnalyses ModuleInlinerWrapperPass::run(Module &M, // The ModulePassManager has already taken care of invalidating analyses. return PreservedAnalyses::all(); } + +void InlinerPass::printPipeline( + raw_ostream &OS, function_ref MapClassName2PassName) { + static_cast *>(this)->printPipeline( + OS, MapClassName2PassName); + if (OnlyMandatory) + OS << ""; +} -- 2.7.4