aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorFlorian Mayer <fmayer@google.com>2025-06-27 13:46:54 -0700
committerGitHub <noreply@github.com>2025-06-27 13:46:54 -0700
commit8d2034cf68b51041a40069b0d868dfcdbf719685 (patch)
tree1239d166a421bc77f2df42c4c77691d866eacaff /clang/lib
parent23be14b22200905b42bcea9add95f1f9233c728a (diff)
downloadllvm-8d2034cf68b51041a40069b0d868dfcdbf719685.zip
llvm-8d2034cf68b51041a40069b0d868dfcdbf719685.tar.gz
llvm-8d2034cf68b51041a40069b0d868dfcdbf719685.tar.bz2
[clang] Add flag fallow-runtime-check-skip-hot-cutoff (#145999)
Co-authored-by: Kazu Hirata <kazu@google.com>
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/CodeGen/BackendUtil.cpp12
-rw-r--r--clang/lib/Driver/ToolChains/Clang.cpp3
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp17
3 files changed, 27 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 97bc063..1c92ea4 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -805,17 +805,21 @@ static void addSanitizers(const Triple &TargetTriple,
// SanitizeSkipHotCutoffs: doubles with range [0, 1]
// Opts.cutoffs: unsigned ints with range [0, 1000000]
auto ScaledCutoffs = CodeGenOpts.SanitizeSkipHotCutoffs.getAllScaled(1000000);
-
+ uint64_t AllowRuntimeCheckSkipHotCutoff =
+ CodeGenOpts.AllowRuntimeCheckSkipHotCutoff.value_or(0.0) * 1000000;
// TODO: remove IsRequested()
- if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value()) {
+ if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value() ||
+ CodeGenOpts.AllowRuntimeCheckSkipHotCutoff.has_value()) {
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
PB.registerOptimizerEarlyEPCallback(
- [ScaledCutoffs](ModulePassManager &MPM, OptimizationLevel Level,
- ThinOrFullLTOPhase Phase) {
+ [ScaledCutoffs, AllowRuntimeCheckSkipHotCutoff](
+ ModulePassManager &MPM, OptimizationLevel Level,
+ ThinOrFullLTOPhase Phase) {
LowerAllowCheckPass::Options Opts;
// TODO: after removing IsRequested(), make this unconditional
if (ScaledCutoffs.has_value())
Opts.cutoffs = ScaledCutoffs.value();
+ Opts.runtime_check = AllowRuntimeCheckSkipHotCutoff;
MPM.addPass(
createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
});
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 8a18865..ceb592d 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6028,7 +6028,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more
// complicated ways.
auto SanitizeArgs = TC.getSanitizerArgs(Args);
-
+ Args.AddLastArg(CmdArgs,
+ options::OPT_fallow_runtime_check_skip_hot_cutoff_EQ);
bool IsAsyncUnwindTablesDefault =
TC.getDefaultUnwindTableLevel(Args) == ToolChain::UnwindTableLevel::Asynchronous;
bool IsSyncUnwindTablesDefault =
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 9e269ab..f366e90 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1820,6 +1820,11 @@ void CompilerInvocationBase::GenerateCodeGenArgs(const CodeGenOptions &Opts,
for (std::string Sanitizer : Values)
GenerateArg(Consumer, OPT_fsanitize_skip_hot_cutoff_EQ, Sanitizer);
+ if (Opts.AllowRuntimeCheckSkipHotCutoff) {
+ GenerateArg(Consumer, OPT_fallow_runtime_check_skip_hot_cutoff_EQ,
+ std::to_string(*Opts.AllowRuntimeCheckSkipHotCutoff));
+ }
+
for (StringRef Sanitizer :
serializeSanitizerKinds(Opts.SanitizeAnnotateDebugInfo))
GenerateArg(Consumer, OPT_fsanitize_annotate_debug_info_EQ, Sanitizer);
@@ -2322,6 +2327,18 @@ bool CompilerInvocation::ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args,
Args.getAllArgValues(OPT_fsanitize_annotate_debug_info_EQ), Diags,
Opts.SanitizeAnnotateDebugInfo);
+ if (StringRef V =
+ Args.getLastArgValue(OPT_fallow_runtime_check_skip_hot_cutoff_EQ);
+ !V.empty()) {
+ double A;
+ if (V.getAsDouble(A) || A < 0.0 || A > 1.0) {
+ Diags.Report(diag::err_drv_invalid_value)
+ << "-fallow-runtime-check-skip-hot-cutoff=" << V;
+ } else {
+ Opts.AllowRuntimeCheckSkipHotCutoff = A;
+ }
+ }
+
Opts.EmitVersionIdentMetadata = Args.hasFlag(OPT_Qy, OPT_Qn, true);
if (!LangOpts->CUDAIsDevice)