@@ -317,6 +317,8 @@ class HWAddressSanitizer {
317317 Value *MemTag = nullptr ;
318318 };
319319
320+ bool selectiveInstrumentationShouldSkip (Function &F,
321+ FunctionAnalysisManager &FAM);
320322 void initializeModule ();
321323 void createHwasanCtorComdat ();
322324
@@ -1523,6 +1525,31 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
15231525 return true ;
15241526}
15251527
1528+ bool HWAddressSanitizer::selectiveInstrumentationShouldSkip (
1529+ Function &F, FunctionAnalysisManager &FAM) {
1530+ if (ClRandomSkipRate.getNumOccurrences ()) {
1531+ std::bernoulli_distribution D (ClRandomSkipRate);
1532+ if (D (*Rng))
1533+ return true ;
1534+ } else {
1535+ auto &MAMProxy = FAM.getResult <ModuleAnalysisManagerFunctionProxy>(F);
1536+ ProfileSummaryInfo *PSI =
1537+ MAMProxy.getCachedResult <ProfileSummaryAnalysis>(*F.getParent ());
1538+ if (PSI && PSI->hasProfileSummary ()) {
1539+ auto &BFI = FAM.getResult <BlockFrequencyAnalysis>(F);
1540+ if ((ClHotPercentileCutoff.getNumOccurrences () &&
1541+ ClHotPercentileCutoff >= 0 )
1542+ ? PSI->isFunctionHotInCallGraphNthPercentile (
1543+ ClHotPercentileCutoff, &F, BFI)
1544+ : PSI->isFunctionHotInCallGraph (&F, BFI))
1545+ return true ;
1546+ } else {
1547+ ++NumNoProfileSummaryFuncs;
1548+ }
1549+ }
1550+ return false ;
1551+ }
1552+
15261553void HWAddressSanitizer::sanitizeFunction (Function &F,
15271554 FunctionAnalysisManager &FAM) {
15281555 if (&F == HwasanCtorFunction)
@@ -1535,28 +1562,10 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,
15351562 return ;
15361563
15371564 NumTotalFuncs++;
1538- if (CSelectiveInstrumentation) {
1539- if (ClRandomSkipRate.getNumOccurrences ()) {
1540- std::bernoulli_distribution D (ClRandomSkipRate);
1541- if (D (*Rng))
1542- return ;
1543- } else {
1544- auto &MAMProxy = FAM.getResult <ModuleAnalysisManagerFunctionProxy>(F);
1545- ProfileSummaryInfo *PSI =
1546- MAMProxy.getCachedResult <ProfileSummaryAnalysis>(*F.getParent ());
1547- if (PSI && PSI->hasProfileSummary ()) {
1548- auto &BFI = FAM.getResult <BlockFrequencyAnalysis>(F);
1549- if ((ClHotPercentileCutoff.getNumOccurrences () &&
1550- ClHotPercentileCutoff >= 0 )
1551- ? PSI->isFunctionHotInCallGraphNthPercentile (
1552- ClHotPercentileCutoff, &F, BFI)
1553- : PSI->isFunctionHotInCallGraph (&F, BFI))
1554- return ;
1555- } else {
1556- ++NumNoProfileSummaryFuncs;
1557- }
1558- }
1559- }
1565+
1566+ if (CSelectiveInstrumentation && selectiveInstrumentationShouldSkip (F, FAM))
1567+ return ;
1568+
15601569 NumInstrumentedFuncs++;
15611570
15621571 LLVM_DEBUG (dbgs () << " Function: " << F.getName () << " \n " );
0 commit comments