@@ -318,6 +318,8 @@ class HWAddressSanitizer {
318
318
};
319
319
void setSSI (const StackSafetyGlobalInfo *S) { SSI = S; }
320
320
321
+ bool selectiveInstrumentationShouldSkip (Function &F,
322
+ FunctionAnalysisManager &FAM);
321
323
void initializeModule ();
322
324
void createHwasanCtorComdat ();
323
325
@@ -1524,6 +1526,31 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
1524
1526
return true ;
1525
1527
}
1526
1528
1529
+ bool HWAddressSanitizer::selectiveInstrumentationShouldSkip (
1530
+ Function &F, FunctionAnalysisManager &FAM) {
1531
+ if (ClRandomSkipRate.getNumOccurrences ()) {
1532
+ std::bernoulli_distribution D (ClRandomSkipRate);
1533
+ if (D (*Rng))
1534
+ return true ;
1535
+ } else {
1536
+ auto &MAMProxy = FAM.getResult <ModuleAnalysisManagerFunctionProxy>(F);
1537
+ ProfileSummaryInfo *PSI =
1538
+ MAMProxy.getCachedResult <ProfileSummaryAnalysis>(*F.getParent ());
1539
+ if (PSI && PSI->hasProfileSummary ()) {
1540
+ auto &BFI = FAM.getResult <BlockFrequencyAnalysis>(F);
1541
+ if ((ClHotPercentileCutoff.getNumOccurrences () &&
1542
+ ClHotPercentileCutoff >= 0 )
1543
+ ? PSI->isFunctionHotInCallGraphNthPercentile (
1544
+ ClHotPercentileCutoff, &F, BFI)
1545
+ : PSI->isFunctionHotInCallGraph (&F, BFI))
1546
+ return true ;
1547
+ } else {
1548
+ ++NumNoProfileSummaryFuncs;
1549
+ }
1550
+ }
1551
+ return false ;
1552
+ }
1553
+
1527
1554
void HWAddressSanitizer::sanitizeFunction (Function &F,
1528
1555
FunctionAnalysisManager &FAM) {
1529
1556
if (&F == HwasanCtorFunction)
@@ -1536,28 +1563,10 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,
1536
1563
return ;
1537
1564
1538
1565
NumTotalFuncs++;
1539
- if (CSelectiveInstrumentation) {
1540
- if (ClRandomSkipRate.getNumOccurrences ()) {
1541
- std::bernoulli_distribution D (ClRandomSkipRate);
1542
- if (D (*Rng))
1543
- return ;
1544
- } else {
1545
- auto &MAMProxy = FAM.getResult <ModuleAnalysisManagerFunctionProxy>(F);
1546
- ProfileSummaryInfo *PSI =
1547
- MAMProxy.getCachedResult <ProfileSummaryAnalysis>(*F.getParent ());
1548
- if (PSI && PSI->hasProfileSummary ()) {
1549
- auto &BFI = FAM.getResult <BlockFrequencyAnalysis>(F);
1550
- if ((ClHotPercentileCutoff.getNumOccurrences () &&
1551
- ClHotPercentileCutoff >= 0 )
1552
- ? PSI->isFunctionHotInCallGraphNthPercentile (
1553
- ClHotPercentileCutoff, &F, BFI)
1554
- : PSI->isFunctionHotInCallGraph (&F, BFI))
1555
- return ;
1556
- } else {
1557
- ++NumNoProfileSummaryFuncs;
1558
- }
1559
- }
1560
- }
1566
+
1567
+ if (CSelectiveInstrumentation && selectiveInstrumentationShouldSkip (F, FAM))
1568
+ return ;
1569
+
1561
1570
NumInstrumentedFuncs++;
1562
1571
1563
1572
LLVM_DEBUG (dbgs () << " Function: " << F.getName () << " \n " );
0 commit comments