|
15 | 15 | #include "llvm/ADT/MapVector.h"
|
16 | 16 | #include "llvm/ADT/STLExtras.h"
|
17 | 17 | #include "llvm/ADT/SmallVector.h"
|
| 18 | +#include "llvm/ADT/Statistic.h" |
18 | 19 | #include "llvm/ADT/StringExtras.h"
|
19 | 20 | #include "llvm/ADT/StringRef.h"
|
| 21 | +#include "llvm/Analysis/BlockFrequencyInfo.h" |
20 | 22 | #include "llvm/Analysis/DomTreeUpdater.h"
|
21 | 23 | #include "llvm/Analysis/GlobalsModRef.h"
|
22 | 24 | #include "llvm/Analysis/PostDominators.h"
|
| 25 | +#include "llvm/Analysis/ProfileSummaryInfo.h" |
23 | 26 | #include "llvm/Analysis/StackSafetyAnalysis.h"
|
24 | 27 | #include "llvm/Analysis/TargetLibraryInfo.h"
|
25 | 28 | #include "llvm/Analysis/ValueTracking.h"
|
@@ -177,6 +180,18 @@ static cl::opt<bool> ClWithTls(
|
177 | 180 | "platforms that support this"),
|
178 | 181 | cl::Hidden, cl::init(true));
|
179 | 182 |
|
| 183 | +static cl::opt<bool> |
| 184 | + CSkipHotCode("hwasan-skip-hot-code", |
| 185 | + cl::desc("Do not instument hot functions based on FDO."), |
| 186 | + cl::Hidden, cl::init(false)); |
| 187 | + |
| 188 | +static cl::opt<int> HotPercentileCutoff("hwasan-percentile-cutoff-hot", |
| 189 | + cl::init(0)); |
| 190 | + |
| 191 | +STATISTIC(NumTotalFuncs, "Number of total funcs HWASAN"); |
| 192 | +STATISTIC(NumInstrumentedFuncs, "Number of HWASAN instrumented funcs"); |
| 193 | +STATISTIC(NumNoProfileSummaryFuncs, "Number of HWASAN funcs without PS"); |
| 194 | + |
180 | 195 | // Mode for selecting how to insert frame record info into the stack ring
|
181 | 196 | // buffer.
|
182 | 197 | enum RecordStackHistoryMode {
|
@@ -1507,6 +1522,27 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,
|
1507 | 1522 | if (!F.hasFnAttribute(Attribute::SanitizeHWAddress))
|
1508 | 1523 | return;
|
1509 | 1524 |
|
| 1525 | + if (F.empty()) |
| 1526 | + return; |
| 1527 | + |
| 1528 | + NumTotalFuncs++; |
| 1529 | + if (CSkipHotCode) { |
| 1530 | + auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F); |
| 1531 | + ProfileSummaryInfo *PSI = |
| 1532 | + MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent()); |
| 1533 | + if (PSI && PSI->hasProfileSummary()) { |
| 1534 | + auto &BFI = FAM.getResult<BlockFrequencyAnalysis>(F); |
| 1535 | + if ((HotPercentileCutoff.getNumOccurrences() && HotPercentileCutoff >= 0) |
| 1536 | + ? PSI->isFunctionHotInCallGraphNthPercentile(HotPercentileCutoff, |
| 1537 | + &F, BFI) |
| 1538 | + : PSI->isFunctionHotInCallGraph(&F, BFI)) |
| 1539 | + return; |
| 1540 | + } else { |
| 1541 | + ++NumNoProfileSummaryFuncs; |
| 1542 | + } |
| 1543 | + } |
| 1544 | + NumInstrumentedFuncs++; |
| 1545 | + |
1510 | 1546 | LLVM_DEBUG(dbgs() << "Function: " << F.getName() << "\n");
|
1511 | 1547 |
|
1512 | 1548 | SmallVector<InterestingMemoryOperand, 16> OperandsToInstrument;
|
|
0 commit comments