Skip to content

[HWASAN][UBSAN] Don't use default profile-summary-cutoff-hot #87691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,8 @@ static cl::opt<bool>
cl::desc("Use selective instrumentation"),
cl::Hidden, cl::init(false));

static cl::opt<int> ClHotPercentileCutoff(
"hwasan-percentile-cutoff-hot", cl::init(0),
cl::desc("Alternative hot percentile cuttoff."
"By default `-profile-summary-cutoff-hot` is used."));
static cl::opt<int> ClHotPercentileCutoff("hwasan-percentile-cutoff-hot",
cl::desc("Hot percentile cuttoff."));

static cl::opt<float>
ClRandomSkipRate("hwasan-random-skip-rate", cl::init(0),
Expand Down Expand Up @@ -1512,12 +1510,8 @@ bool HWAddressSanitizer::selectiveInstrumentationShouldSkip(
++NumNoProfileSummaryFuncs;
return false;
}
auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(F);
return (
(ClHotPercentileCutoff.getNumOccurrences() && ClHotPercentileCutoff >= 0)
? PSI->isFunctionHotInCallGraphNthPercentile(ClHotPercentileCutoff,
&F, BFI)
: PSI->isFunctionHotInCallGraph(&F, BFI));
return PSI->isFunctionHotInCallGraphNthPercentile(
ClHotPercentileCutoff, &F, FAM.getResult<BlockFrequencyAnalysis>(F));
}

void HWAddressSanitizer::sanitizeFunction(Function &F,
Expand Down
13 changes: 3 additions & 10 deletions llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ using namespace llvm;

#define DEBUG_TYPE "remove-traps"

static cl::opt<int> HotPercentileCutoff(
"remove-traps-percentile-cutoff-hot", cl::init(0),
cl::desc("Alternative hot percentile cuttoff. By default "
"`-profile-summary-cutoff-hot` is used."));
static cl::opt<int> HotPercentileCutoff("remove-traps-percentile-cutoff-hot",
cl::desc("Hot percentile cuttoff."));

static cl::opt<float>
RandomRate("remove-traps-random-rate", cl::init(0.0),
Expand Down Expand Up @@ -64,12 +62,7 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI,
uint64_t Count = 0;
for (const auto *PR : predecessors(&BB))
Count += BFI.getBlockProfileCount(PR).value_or(0);

IsHot =
HotPercentileCutoff.getNumOccurrences()
? (HotPercentileCutoff > 0 &&
PSI->isHotCountNthPercentile(HotPercentileCutoff, Count))
: PSI->isHotCount(Count);
IsHot = PSI->isHotCountNthPercentile(HotPercentileCutoff, Count);
}

if (ShouldRemove(IsHot)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
; RUN: -hwasan-percentile-cutoff-hot=700000 | FileCheck %s --check-prefix=HOT70
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
; RUN: | FileCheck %s --check-prefix=HOT99
; RUN: -hwasan-percentile-cutoff-hot=990000 | FileCheck %s --check-prefix=HOT99
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
; RUN: -hwasan-random-skip-rate=0.0 | FileCheck %s --check-prefix=RANDOM0
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/RemoveTraps/remove-traps.ll
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes='function(remove-traps)' -S | FileCheck %s --check-prefixes=NOPROFILE
; RUN: opt < %s -passes='function(remove-traps)' -remove-traps-random-rate=1 -S | FileCheck %s --check-prefixes=ALL
; RUN: opt < %s -passes='require<profile-summary>,function(remove-traps)' -S | FileCheck %s --check-prefixes=HOT99
; RUN: opt < %s -passes='require<profile-summary>,function(remove-traps)' -remove-traps-percentile-cutoff-hot=990000 -S | FileCheck %s --check-prefixes=HOT99
; RUN: opt < %s -passes='require<profile-summary>,function(remove-traps)' -remove-traps-percentile-cutoff-hot=700000 -S | FileCheck %s --check-prefixes=HOT70

target triple = "x86_64-pc-linux-gnu"
Expand Down