@@ -317,6 +317,8 @@ class HWAddressSanitizer {
317
317
Value *MemTag = nullptr ;
318
318
};
319
319
320
+ bool selectiveInstrumentationShouldSkip (Function &F,
321
+ FunctionAnalysisManager &FAM);
320
322
void initializeModule ();
321
323
void createHwasanCtorComdat ();
322
324
@@ -1523,6 +1525,31 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
1523
1525
return true ;
1524
1526
}
1525
1527
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
+
1526
1553
void HWAddressSanitizer::sanitizeFunction (Function &F,
1527
1554
FunctionAnalysisManager &FAM) {
1528
1555
if (&F == HwasanCtorFunction)
@@ -1535,28 +1562,10 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,
1535
1562
return ;
1536
1563
1537
1564
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
+
1560
1569
NumInstrumentedFuncs++;
1561
1570
1562
1571
LLVM_DEBUG (dbgs () << " Function: " << F.getName () << " \n " );
0 commit comments