|
21 | 21 | #include "llvm/Analysis/BlockFrequencyInfo.h"
|
22 | 22 | #include "llvm/Analysis/DomTreeUpdater.h"
|
23 | 23 | #include "llvm/Analysis/GlobalsModRef.h"
|
| 24 | +#include "llvm/Analysis/OptimizationRemarkEmitter.h" |
24 | 25 | #include "llvm/Analysis/PostDominators.h"
|
25 | 26 | #include "llvm/Analysis/ProfileSummaryInfo.h"
|
26 | 27 | #include "llvm/Analysis/StackSafetyAnalysis.h"
|
@@ -1492,23 +1493,42 @@ bool HWAddressSanitizer::instrumentStack(memtag::StackInfo &SInfo,
|
1492 | 1493 | return true;
|
1493 | 1494 | }
|
1494 | 1495 |
|
| 1496 | +static void emitRemark(const Function &F, OptimizationRemarkEmitter &ORE, |
| 1497 | + bool Skip) { |
| 1498 | + if (Skip) { |
| 1499 | + ORE.emit([&]() { |
| 1500 | + return OptimizationRemark(DEBUG_TYPE, "Skip", &F) |
| 1501 | + << "Skipped: F=" << ore::NV("Function", &F); |
| 1502 | + }); |
| 1503 | + } else { |
| 1504 | + ORE.emit([&]() { |
| 1505 | + return OptimizationRemarkMissed(DEBUG_TYPE, "Sanitize", &F) |
| 1506 | + << "Sanitized: F=" << ore::NV("Function", &F); |
| 1507 | + }); |
| 1508 | + } |
| 1509 | +} |
| 1510 | + |
1495 | 1511 | bool HWAddressSanitizer::selectiveInstrumentationShouldSkip(
|
1496 | 1512 | Function &F, FunctionAnalysisManager &FAM) const {
|
1497 |
| - if (ClRandomSkipRate.getNumOccurrences()) { |
1498 |
| - std::bernoulli_distribution D(ClRandomSkipRate); |
1499 |
| - return !D(*Rng); |
1500 |
| - } |
1501 |
| - if (!ClHotPercentileCutoff.getNumOccurrences()) |
1502 |
| - return false; |
1503 |
| - auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F); |
1504 |
| - ProfileSummaryInfo *PSI = |
1505 |
| - MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent()); |
1506 |
| - if (!PSI || !PSI->hasProfileSummary()) { |
1507 |
| - ++NumNoProfileSummaryFuncs; |
1508 |
| - return false; |
1509 |
| - } |
1510 |
| - return PSI->isFunctionHotInCallGraphNthPercentile( |
1511 |
| - ClHotPercentileCutoff, &F, FAM.getResult<BlockFrequencyAnalysis>(F)); |
| 1513 | + bool Skip = [&]() { |
| 1514 | + if (ClRandomSkipRate.getNumOccurrences()) { |
| 1515 | + std::bernoulli_distribution D(ClRandomSkipRate); |
| 1516 | + return !D(*Rng); |
| 1517 | + } |
| 1518 | + if (!ClHotPercentileCutoff.getNumOccurrences()) |
| 1519 | + return false; |
| 1520 | + auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F); |
| 1521 | + ProfileSummaryInfo *PSI = |
| 1522 | + MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent()); |
| 1523 | + if (!PSI || !PSI->hasProfileSummary()) { |
| 1524 | + ++NumNoProfileSummaryFuncs; |
| 1525 | + return false; |
| 1526 | + } |
| 1527 | + return PSI->isFunctionHotInCallGraphNthPercentile( |
| 1528 | + ClHotPercentileCutoff, &F, FAM.getResult<BlockFrequencyAnalysis>(F)); |
| 1529 | + }(); |
| 1530 | + emitRemark(F, FAM.getResult<OptimizationRemarkEmitterAnalysis>(F), Skip); |
| 1531 | + return Skip; |
1512 | 1532 | }
|
1513 | 1533 |
|
1514 | 1534 | void HWAddressSanitizer::sanitizeFunction(Function &F,
|
|
0 commit comments