[llvm] 5a3cc7b - [PassBuilder] Expose parametrized passes related functions (#85357)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 21:14:34 PDT 2024
Author: paperchalice
Date: 2024-03-16T12:14:30+08:00
New Revision: 5a3cc7ba24c564a19a7812efd79ecd224b8193f5
URL: https://github.com/llvm/llvm-project/commit/5a3cc7ba24c564a19a7812efd79ecd224b8193f5
DIFF: https://github.com/llvm/llvm-project/commit/5a3cc7ba24c564a19a7812efd79ecd224b8193f5.diff
LOG: [PassBuilder] Expose parametrized passes related functions (#85357)
Some targets have passes with parameters, e.g. ARM, AMDGPU and MIPS.
For example, AMDGPU has a pass `AMDGPUAtomicOptimizerPass`
which need a `ScanOption`, this commit enables the syntax
like `-passes=amdgpu-atomic-optimizer<strategy=dpp>` for backend passes.
Added:
Modified:
llvm/include/llvm/Passes/PassBuilder.h
llvm/lib/Passes/PassBuilder.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h
index 6822cfdb4957b6..8817a2585646ca 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -626,6 +626,52 @@ class PassBuilder {
void invokePipelineEarlySimplificationEPCallbacks(ModulePassManager &MPM,
OptimizationLevel Level);
+ static bool checkParametrizedPassName(StringRef Name, StringRef PassName) {
+ if (!Name.consume_front(PassName))
+ return false;
+ // normal pass name w/o parameters == default parameters
+ if (Name.empty())
+ return true;
+ return Name.starts_with("<") && Name.ends_with(">");
+ }
+
+ /// This performs customized parsing of pass name with parameters.
+ ///
+ /// We do not need parametrization of passes in textual pipeline very often,
+ /// yet on a rare occasion ability to specify parameters right there can be
+ /// useful.
+ ///
+ /// \p Name - parameterized specification of a pass from a textual pipeline
+ /// is a string in a form of :
+ /// PassName '<' parameter-list '>'
+ ///
+ /// Parameter list is being parsed by the parser callable argument, \p Parser,
+ /// It takes a string-ref of parameters and returns either StringError or a
+ /// parameter list in a form of a custom parameters type, all wrapped into
+ /// Expected<> template class.
+ ///
+ template <typename ParametersParseCallableT>
+ static auto parsePassParameters(ParametersParseCallableT &&Parser,
+ StringRef Name, StringRef PassName)
+ -> decltype(Parser(StringRef{})) {
+ using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
+
+ StringRef Params = Name;
+ if (!Params.consume_front(PassName)) {
+ llvm_unreachable(
+ "unable to strip pass name from parametrized pass specification");
+ }
+ if (!Params.empty() &&
+ (!Params.consume_front("<") || !Params.consume_back(">"))) {
+ llvm_unreachable("invalid format for parametrized pass name");
+ }
+
+ Expected<ParametersT> Result = Parser(Params);
+ assert((Result || Result.template errorIsA<StringError>()) &&
+ "Pass parameter parser can only return StringErrors.");
+ return Result;
+ }
+
private:
// O1 pass pipeline
FunctionPassManager
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 4d1eb10d2d41c6..0204730f750a1c 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -503,15 +503,6 @@ static std::optional<int> parseDevirtPassName(StringRef Name) {
return Count;
}
-static bool checkParametrizedPassName(StringRef Name, StringRef PassName) {
- if (!Name.consume_front(PassName))
- return false;
- // normal pass name w/o parameters == default parameters
- if (Name.empty())
- return true;
- return Name.starts_with("<") && Name.ends_with(">");
-}
-
static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
return StringSwitch<std::optional<OptimizationLevel>>(S)
.Case("O0", OptimizationLevel::O0)
@@ -525,42 +516,6 @@ static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
namespace {
-/// This performs customized parsing of pass name with parameters.
-///
-/// We do not need parametrization of passes in textual pipeline very often,
-/// yet on a rare occasion ability to specify parameters right there can be
-/// useful.
-///
-/// \p Name - parameterized specification of a pass from a textual pipeline
-/// is a string in a form of :
-/// PassName '<' parameter-list '>'
-///
-/// Parameter list is being parsed by the parser callable argument, \p Parser,
-/// It takes a string-ref of parameters and returns either StringError or a
-/// parameter list in a form of a custom parameters type, all wrapped into
-/// Expected<> template class.
-///
-template <typename ParametersParseCallableT>
-auto parsePassParameters(ParametersParseCallableT &&Parser, StringRef Name,
- StringRef PassName) -> decltype(Parser(StringRef{})) {
- using ParametersT = typename decltype(Parser(StringRef{}))::value_type;
-
- StringRef Params = Name;
- if (!Params.consume_front(PassName)) {
- assert(false &&
- "unable to strip pass name from parametrized pass specification");
- }
- if (!Params.empty() &&
- (!Params.consume_front("<") || !Params.consume_back(">"))) {
- assert(false && "invalid format for parametrized pass name");
- }
-
- Expected<ParametersT> Result = Parser(Params);
- assert((Result || Result.template errorIsA<StringError>()) &&
- "Pass parameter parser can only return StringErrors.");
- return Result;
-}
-
/// Parser of parameters for HardwareLoops pass.
Expected<HardwareLoopOptions> parseHardwareLoopOptions(StringRef Params) {
HardwareLoopOptions HardwareLoopOpts;
@@ -1196,7 +1151,7 @@ static bool isModulePassName(StringRef Name, CallbacksT &Callbacks) {
if (Name == NAME) \
return true;
#define MODULE_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- if (checkParametrizedPassName(Name, NAME)) \
+ if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
return true;
#define MODULE_ANALYSIS(NAME, CREATE_PASS) \
if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
@@ -1225,7 +1180,7 @@ static bool isCGSCCPassName(StringRef Name, CallbacksT &Callbacks) {
if (Name == NAME) \
return true;
#define CGSCC_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- if (checkParametrizedPassName(Name, NAME)) \
+ if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
return true;
#define CGSCC_ANALYSIS(NAME, CREATE_PASS) \
if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
@@ -1252,7 +1207,7 @@ static bool isFunctionPassName(StringRef Name, CallbacksT &Callbacks) {
if (Name == NAME) \
return true;
#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- if (checkParametrizedPassName(Name, NAME)) \
+ if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
return true;
#define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \
if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
@@ -1293,7 +1248,7 @@ static bool isLoopNestPassName(StringRef Name, CallbacksT &Callbacks,
if (parseRepeatPassName(Name))
return true;
- if (checkParametrizedPassName(Name, "lnicm")) {
+ if (PassBuilder::checkParametrizedPassName(Name, "lnicm")) {
UseMemorySSA = true;
return true;
}
@@ -1315,7 +1270,7 @@ static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
if (parseRepeatPassName(Name))
return true;
- if (checkParametrizedPassName(Name, "licm")) {
+ if (PassBuilder::checkParametrizedPassName(Name, "licm")) {
UseMemorySSA = true;
return true;
}
@@ -1324,7 +1279,7 @@ static bool isLoopPassName(StringRef Name, CallbacksT &Callbacks,
if (Name == NAME) \
return true;
#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \
- if (checkParametrizedPassName(Name, NAME)) \
+ if (PassBuilder::checkParametrizedPassName(Name, NAME)) \
return true;
#define LOOP_ANALYSIS(NAME, CREATE_PASS) \
if (Name == "require<" NAME ">" || Name == "invalidate<" NAME ">") \
More information about the llvm-commits
mailing list