[llvm] [Passes] Expose parseSinglePassOption (PR #86117)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 21 06:24:54 PDT 2024
https://github.com/paperchalice created https://github.com/llvm/llvm-project/pull/86117
BPF and some machine function passes need it.
>From a96291a874c9df48b22ba581ef77975e4999f65b Mon Sep 17 00:00:00 2001
From: PaperChalice <liujunchang97 at outlook.com>
Date: Thu, 21 Mar 2024 21:08:32 +0800
Subject: [PATCH] [Passes] Expose parseSinglePassOption
---
llvm/include/llvm/Passes/PassBuilder.h | 7 ++++
llvm/lib/Passes/PassBuilder.cpp | 55 +++++++++++++++-----------
2 files changed, 38 insertions(+), 24 deletions(-)
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..c5465da8b4a582 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -600,8 +600,9 @@ Expected<LoopUnrollOptions> parseLoopUnrollOptions(StringRef Params) {
return UnrollOpts;
}
-Expected<bool> parseSinglePassOption(StringRef Params, StringRef OptionName,
- StringRef PassName) {
+Expected<bool> PassBuilder::parseSinglePassOption(StringRef Params,
+ StringRef OptionName,
+ StringRef PassName) {
bool Result = false;
while (!Params.empty()) {
StringRef ParamName;
@@ -620,24 +621,28 @@ Expected<bool> parseSinglePassOption(StringRef Params, StringRef OptionName,
}
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