[clang] [llvm] [sanitizer][NFCI] Add Options parameter to LowerAllowCheckPass (PR #122765)
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 13 10:45:50 PST 2025
https://github.com/thurstond updated https://github.com/llvm/llvm-project/pull/122765
>From 6c244a083b458637f35149547270ba25675ca417 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Mon, 13 Jan 2025 18:38:14 +0000
Subject: [PATCH 1/2] [sanitizer][NFCI] Add Options to LowerAllowCheckPass
This is glue code to convert LowerAllowCheckPass from a FUNCTION_PASS to FUNCTION_PASS_WITH_PARAMS. The parameters are currently unused.
Future work will plumb `-fsanitize-skip-hot-cutoff`
(introduced in https://github.com/llvm/llvm-project/pull/121619) to
LowerAllowCheckOptions.
---
clang/lib/CodeGen/BackendUtil.cpp | 5 +++--
.../Instrumentation/LowerAllowCheckPass.h | 9 +++++++++
llvm/lib/Passes/PassBuilder.cpp | 14 ++++++++++++++
llvm/lib/Passes/PassRegistry.def | 5 ++++-
4 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 79e6bf3d24dffb..456c400c609b0d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -795,11 +795,12 @@ static void addSanitizers(const Triple &TargetTriple,
}
if (LowerAllowCheckPass::IsRequested()) {
+ LowerAllowCheckOptions Opts;
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
- PB.registerOptimizerEarlyEPCallback([](ModulePassManager &MPM,
+ PB.registerOptimizerEarlyEPCallback([&Opts](ModulePassManager &MPM,
OptimizationLevel Level,
ThinOrFullLTOPhase Phase) {
- MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass()));
+ MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
});
}
}
diff --git a/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h b/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
index af974818fec5f3..cd5204eaacc790 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
@@ -20,13 +20,22 @@
namespace llvm {
+struct LowerAllowCheckOptions {
+ std::vector<double> placeholder; // TODO: cutoffs
+};
+
// This pass is responsible for removing optional traps, like llvm.ubsantrap
// from the hot code.
class LowerAllowCheckPass : public PassInfoMixin<LowerAllowCheckPass> {
public:
+ explicit LowerAllowCheckPass(LowerAllowCheckOptions Options)
+ : Options(Options){};
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
static bool IsRequested();
+
+private:
+ LowerAllowCheckOptions Options;
};
} // namespace llvm
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index f923d5aabe0a0e..0e43112207ef97 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -821,6 +821,20 @@ Expected<EmbedBitcodeOptions> parseEmbedBitcodePassOptions(StringRef Params) {
return Result;
}
+Expected<LowerAllowCheckOptions> parseLowerAllowCheckPassOptions(StringRef Params) {
+ LowerAllowCheckOptions Result;
+ while (!Params.empty()) {
+ StringRef ParamName;
+ std::tie(ParamName, Params) = Params.split(';');
+
+ return make_error<StringError>(
+ formatv("invalid LowerAllowCheck pass parameter '{0}' ", ParamName)
+ .str(),
+ inconvertibleErrorCode());
+ }
+ return Result;
+}
+
Expected<MemorySanitizerOptions> parseMSanPassOptions(StringRef Params) {
MemorySanitizerOptions Result;
while (!Params.empty()) {
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 1021d7fcd92474..7cbea023f2129f 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -402,7 +402,6 @@ FUNCTION_PASS("loop-load-elim", LoopLoadEliminationPass())
FUNCTION_PASS("loop-simplify", LoopSimplifyPass())
FUNCTION_PASS("loop-sink", LoopSinkPass())
FUNCTION_PASS("loop-versioning", LoopVersioningPass())
-FUNCTION_PASS("lower-allow-check", LowerAllowCheckPass())
FUNCTION_PASS("lower-atomic", LowerAtomicPass())
FUNCTION_PASS("lower-constant-intrinsics", LowerConstantIntrinsicsPass())
FUNCTION_PASS("lower-expect", LowerExpectIntrinsicPass())
@@ -553,6 +552,10 @@ FUNCTION_PASS_WITH_PARAMS(
parseLoopVectorizeOptions,
"no-interleave-forced-only;interleave-forced-only;no-vectorize-forced-only;"
"vectorize-forced-only")
+FUNCTION_PASS_WITH_PARAMS(
+ "lower-allow-check", "LowerAllowCheckPass",
+ [](LowerAllowCheckOptions Opts) { return LowerAllowCheckPass(Opts); },
+ parseLowerAllowCheckPassOptions, "")
FUNCTION_PASS_WITH_PARAMS(
"lower-matrix-intrinsics", "LowerMatrixIntrinsicsPass",
[](bool Minimal) { return LowerMatrixIntrinsicsPass(Minimal); },
>From 2938d91b99e9918406d2d7c24312571d20aa3c73 Mon Sep 17 00:00:00 2001
From: Thurston Dang <thurston at google.com>
Date: Mon, 13 Jan 2025 18:43:05 +0000
Subject: [PATCH 2/2] clang-format
---
clang/lib/CodeGen/BackendUtil.cpp | 4 ++--
.../llvm/Transforms/Instrumentation/LowerAllowCheckPass.h | 4 ++--
llvm/lib/Passes/PassBuilder.cpp | 3 ++-
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 456c400c609b0d..bcdd849787dccb 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -798,8 +798,8 @@ static void addSanitizers(const Triple &TargetTriple,
LowerAllowCheckOptions Opts;
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
PB.registerOptimizerEarlyEPCallback([&Opts](ModulePassManager &MPM,
- OptimizationLevel Level,
- ThinOrFullLTOPhase Phase) {
+ OptimizationLevel Level,
+ ThinOrFullLTOPhase Phase) {
MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
});
}
diff --git a/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h b/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
index cd5204eaacc790..6fe9f2eccbc3af 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/LowerAllowCheckPass.h
@@ -21,7 +21,7 @@
namespace llvm {
struct LowerAllowCheckOptions {
- std::vector<double> placeholder; // TODO: cutoffs
+ std::vector<double> placeholder; // TODO: cutoffs
};
// This pass is responsible for removing optional traps, like llvm.ubsantrap
@@ -29,7 +29,7 @@ struct LowerAllowCheckOptions {
class LowerAllowCheckPass : public PassInfoMixin<LowerAllowCheckPass> {
public:
explicit LowerAllowCheckPass(LowerAllowCheckOptions Options)
- : Options(Options){};
+ : Options(Options) {};
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
static bool IsRequested();
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 0e43112207ef97..aeebfb75bcb5d5 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -821,7 +821,8 @@ Expected<EmbedBitcodeOptions> parseEmbedBitcodePassOptions(StringRef Params) {
return Result;
}
-Expected<LowerAllowCheckOptions> parseLowerAllowCheckPassOptions(StringRef Params) {
+Expected<LowerAllowCheckOptions>
+parseLowerAllowCheckPassOptions(StringRef Params) {
LowerAllowCheckOptions Result;
while (!Params.empty()) {
StringRef ParamName;
More information about the llvm-commits
mailing list