[llvm] 4d7f28a - [Passes] Expose parseSinglePassOption (#86226)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 21 19:56:02 PDT 2024
Author: paperchalice
Date: 2024-03-22T10:55:58+08:00
New Revision: 4d7f28a2c4b187f0bef3877081100786156defc7
URL: https://github.com/llvm/llvm-project/commit/4d7f28a2c4b187f0bef3877081100786156defc7
DIFF: https://github.com/llvm/llvm-project/commit/4d7f28a2c4b187f0bef3877081100786156defc7.diff
LOG: [Passes] Expose parseSinglePassOption (#86226)
Reland #86225, adjust the name space.
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 8817a2585646ca..d1232124d5d819 100644
--- a/llvm/include/llvm/Passes/PassBuilder.h
+++ b/llvm/include/llvm/Passes/PassBuilder.h
@@ -672,6 +672,13 @@ class PassBuilder {
return Result;
}
+ /// Handle passes only accept one bool-valued parameter.
+ ///
+ /// \return false when Params is empty.
+ static Expected<bool> parseSinglePassOption(StringRef Params,
+ StringRef OptionName,
+ StringRef PassName);
+
private:
// O1 pass pipeline
FunctionPassManager
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 9d98ae7dde520f..f60f4eb3f0ef8c 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -514,6 +514,26 @@ static std::optional<OptimizationLevel> parseOptLevel(StringRef S) {
.Default(std::nullopt);
}
+Expected<bool> PassBuilder::parseSinglePassOption(StringRef Params,
+ StringRef OptionName,
+ StringRef PassName) {
+ bool Result = false;
+ while (!Params.empty()) {
+ StringRef ParamName;
+ std::tie(ParamName, Params) = Params.split(';');
+
+ if (ParamName == OptionName) {
+ Result = true;
+ } else {
+ return make_error<StringError>(
+ formatv("invalid {1} pass parameter '{0}' ", ParamName, PassName)
+ .str(),
+ inconvertibleErrorCode());
+ }
+ }
+ return Result;
+}
+
namespace {
/// Parser of parameters for HardwareLoops pass.
@@ -600,44 +620,29 @@ Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
return UnrollOpts;
}
-Expected<bool> parseSinglePassOption(StringRef Params, StringRef OptionName,
- StringRef PassName) {
- bool Result = false;
- while (!Params.empty()) {
- StringRef ParamName;
- std::tie(ParamName, Params) = Params.split(';');
-
- if (ParamName == OptionName) {
- Result = true;
- } else {
- return make_error<StringError>(
- formatv("invalid {1} pass parameter '{0}' ", ParamName, PassName)
- .str(),
- inconvertibleErrorCode());
- }
- }
- return Result;
-}
-
Expected<bool> parseGlobalDCEPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "vfe-linkage-unit-visibility", "GlobalDCE");
+ return PassBuilder::parseSinglePassOption(
+ Params, "vfe-linkage-unit-visibility", "GlobalDCE");
}
Expected<bool> parseCGProfilePassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "in-lto-post-link", "CGProfile");
+ return PassBuilder::parseSinglePassOption(Params, "in-lto-post-link",
+ "CGProfile");
}
Expected<bool> parseInlinerPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "only-mandatory", "InlinerPass");
+ return PassBuilder::parseSinglePassOption(Params, "only-mandatory",
+ "InlinerPass");
}
Expected<bool> parseCoroSplitPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "reuse-storage", "CoroSplitPass");
+ return PassBuilder::parseSinglePassOption(Params, "reuse-storage",
+ "CoroSplitPass");
}
Expected<bool> parsePostOrderFunctionAttrsPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "skip-non-recursive-function-attrs",
- "PostOrderFunctionAttrs");
+ return PassBuilder::parseSinglePassOption(
+ Params, "skip-non-recursive-function-attrs", "PostOrderFunctionAttrs");
}
Expected<CFGuardPass::Mechanism> parseCFGuardPassOptions(StringRef Params) {
@@ -661,19 +666,21 @@ Expected<CFGuardPass::Mechanism> parseCFGuardPassOptions(StringRef Params) {
}
Expected<bool> parseEarlyCSEPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "memssa", "EarlyCSE");
+ return PassBuilder::parseSinglePassOption(Params, "memssa", "EarlyCSE");
}
Expected<bool> parseEntryExitInstrumenterPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "post-inline", "EntryExitInstrumenter");
+ return PassBuilder::parseSinglePassOption(Params, "post-inline",
+ "EntryExitInstrumenter");
}
Expected<bool> parseLoopExtractorPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "single", "LoopExtractor");
+ return PassBuilder::parseSinglePassOption(Params, "single", "LoopExtractor");
}
Expected<bool> parseLowerMatrixIntrinsicsPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "minimal", "LowerMatrixIntrinsics");
+ return PassBuilder::parseSinglePassOption(Params, "minimal",
+ "LowerMatrixIntrinsics");
}
Expected<AddressSanitizerOptions> parseASanPassOptions(StringRef Params) {
@@ -1013,13 +1020,13 @@ parseStackLifetimeOptions(StringRef Params) {
}
Expected<bool> parseDependenceAnalysisPrinterOptions(StringRef Params) {
- return parseSinglePassOption(Params, "normalized-results",
- "DependenceAnalysisPrinter");
+ return PassBuilder::parseSinglePassOption(Params, "normalized-results",
+ "DependenceAnalysisPrinter");
}
Expected<bool> parseSeparateConstOffsetFromGEPPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "lower-gep",
- "SeparateConstOffsetFromGEP");
+ return PassBuilder::parseSinglePassOption(Params, "lower-gep",
+ "SeparateConstOffsetFromGEP");
}
Expected<OptimizationLevel>
@@ -1035,13 +1042,13 @@ parseFunctionSimplificationPipelineOptions(StringRef Params) {
}
Expected<bool> parseMemorySSAPrinterPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "no-ensure-optimized-uses",
- "MemorySSAPrinterPass");
+ return PassBuilder::parseSinglePassOption(Params, "no-ensure-optimized-uses",
+ "MemorySSAPrinterPass");
}
Expected<bool> parseSpeculativeExecutionPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "only-if-divergent-target",
- "SpeculativeExecutionPass");
+ return PassBuilder::parseSinglePassOption(Params, "only-if-divergent-target",
+ "SpeculativeExecutionPass");
}
Expected<std::string> parseMemProfUsePassOptions(StringRef Params) {
@@ -1062,13 +1069,13 @@ Expected<std::string> parseMemProfUsePassOptions(StringRef Params) {
}
Expected<bool> parseStructuralHashPrinterPassOptions(StringRef Params) {
- return parseSinglePassOption(Params, "detailed",
- "StructuralHashPrinterPass");
+ return PassBuilder::parseSinglePassOption(Params, "detailed",
+ "StructuralHashPrinterPass");
}
Expected<bool> parseWinEHPrepareOptions(StringRef Params) {
- return parseSinglePassOption(Params, "demote-catchswitch-only",
- "WinEHPreparePass");
+ return PassBuilder::parseSinglePassOption(Params, "demote-catchswitch-only",
+ "WinEHPreparePass");
}
Expected<GlobalMergeOptions> parseGlobalMergeOptions(StringRef Params) {
More information about the llvm-commits
mailing list