Skip to content

Commit 91c2e9c

Browse files
committed
[NFC][SanCov] Pass DomTrees as const references
They are not optional.
1 parent f293118 commit 91c2e9c

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,11 @@ SanitizerCoverageOptions OverrideFromCL(SanitizerCoverageOptions Options) {
204204
return Options;
205205
}
206206

207-
using DomTreeCallback = function_ref<const DominatorTree *(Function &F)>;
208-
using PostDomTreeCallback =
209-
function_ref<const PostDominatorTree *(Function &F)>;
210-
211207
class ModuleSanitizerCoverage {
212208
public:
209+
using DomTreeCallback = function_ref<const DominatorTree &(Function &F)>;
210+
using PostDomTreeCallback =
211+
function_ref<const PostDominatorTree &(Function &F)>;
213212
ModuleSanitizerCoverage(
214213
const SanitizerCoverageOptions &Options = SanitizerCoverageOptions(),
215214
const SpecialCaseList *Allowlist = nullptr,
@@ -289,11 +288,11 @@ PreservedAnalyses SanitizerCoveragePass::run(Module &M,
289288
ModuleSanitizerCoverage ModuleSancov(Options, Allowlist.get(),
290289
Blocklist.get());
291290
auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
292-
auto DTCallback = [&FAM](Function &F) -> const DominatorTree * {
293-
return &FAM.getResult<DominatorTreeAnalysis>(F);
291+
auto DTCallback = [&FAM](Function &F) -> const DominatorTree & {
292+
return FAM.getResult<DominatorTreeAnalysis>(F);
294293
};
295-
auto PDTCallback = [&FAM](Function &F) -> const PostDominatorTree * {
296-
return &FAM.getResult<PostDominatorTreeAnalysis>(F);
294+
auto PDTCallback = [&FAM](Function &F) -> const PostDominatorTree & {
295+
return FAM.getResult<PostDominatorTreeAnalysis>(F);
297296
};
298297
if (!ModuleSancov.instrumentModule(M, DTCallback, PDTCallback))
299298
return PreservedAnalyses::all();
@@ -519,29 +518,29 @@ bool ModuleSanitizerCoverage::instrumentModule(
519518
}
520519

521520
// True if block has successors and it dominates all of them.
522-
static bool isFullDominator(const BasicBlock *BB, const DominatorTree *DT) {
521+
static bool isFullDominator(const BasicBlock *BB, const DominatorTree &DT) {
523522
if (succ_empty(BB))
524523
return false;
525524

526525
return llvm::all_of(successors(BB), [&](const BasicBlock *SUCC) {
527-
return DT->dominates(BB, SUCC);
526+
return DT.dominates(BB, SUCC);
528527
});
529528
}
530529

531530
// True if block has predecessors and it postdominates all of them.
532531
static bool isFullPostDominator(const BasicBlock *BB,
533-
const PostDominatorTree *PDT) {
532+
const PostDominatorTree &PDT) {
534533
if (pred_empty(BB))
535534
return false;
536535

537536
return llvm::all_of(predecessors(BB), [&](const BasicBlock *PRED) {
538-
return PDT->dominates(BB, PRED);
537+
return PDT.dominates(BB, PRED);
539538
});
540539
}
541540

542541
static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB,
543-
const DominatorTree *DT,
544-
const PostDominatorTree *PDT,
542+
const DominatorTree &DT,
543+
const PostDominatorTree &PDT,
545544
const SanitizerCoverageOptions &Options) {
546545
// Don't insert coverage for blocks containing nothing but unreachable: we
547546
// will never call __sanitizer_cov() for them, so counting them in
@@ -569,17 +568,16 @@ static bool shouldInstrumentBlock(const Function &F, const BasicBlock *BB,
569568
&& !(isFullPostDominator(BB, PDT) && !BB->getSinglePredecessor());
570569
}
571570

572-
573571
// Returns true iff From->To is a backedge.
574572
// A twist here is that we treat From->To as a backedge if
575573
// * To dominates From or
576574
// * To->UniqueSuccessor dominates From
577575
static bool IsBackEdge(BasicBlock *From, BasicBlock *To,
578-
const DominatorTree *DT) {
579-
if (DT->dominates(To, From))
576+
const DominatorTree &DT) {
577+
if (DT.dominates(To, From))
580578
return true;
581579
if (auto Next = To->getUniqueSuccessor())
582-
if (DT->dominates(Next, From))
580+
if (DT.dominates(Next, From))
583581
return true;
584582
return false;
585583
}
@@ -589,7 +587,7 @@ static bool IsBackEdge(BasicBlock *From, BasicBlock *To,
589587
//
590588
// Note that Cmp pruning is controlled by the same flag as the
591589
// BB pruning.
592-
static bool IsInterestingCmp(ICmpInst *CMP, const DominatorTree *DT,
590+
static bool IsInterestingCmp(ICmpInst *CMP, const DominatorTree &DT,
593591
const SanitizerCoverageOptions &Options) {
594592
if (!Options.NoPrune)
595593
if (CMP->hasOneUse())
@@ -641,8 +639,8 @@ void ModuleSanitizerCoverage::instrumentFunction(
641639
SmallVector<LoadInst *, 8> Loads;
642640
SmallVector<StoreInst *, 8> Stores;
643641

644-
const DominatorTree *DT = DTCallback(F);
645-
const PostDominatorTree *PDT = PDTCallback(F);
642+
const DominatorTree &DT = DTCallback(F);
643+
const PostDominatorTree &PDT = PDTCallback(F);
646644
bool IsLeafFunc = true;
647645

648646
for (auto &BB : F) {

0 commit comments

Comments
 (0)