Skip to content

Commit 30257dd

Browse files
committed
[NFC][SanCov] Move Module and analysis callbacks into ModuleSanitizerCoverage class
Avoid passing them around.
1 parent b0fe4d4 commit 30257dd

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

llvm/lib/Transforms/Instrumentation/SanitizerCoverage.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,19 @@ class ModuleSanitizerCoverage {
208208
using PostDomTreeCallback =
209209
function_ref<const PostDominatorTree &(Function &F)>;
210210

211-
ModuleSanitizerCoverage(const SanitizerCoverageOptions &Options,
211+
ModuleSanitizerCoverage(Module &M, DomTreeCallback DTCallback,
212+
PostDomTreeCallback PDTCallback,
213+
const SanitizerCoverageOptions &Options,
212214
const SpecialCaseList *Allowlist,
213215
const SpecialCaseList *Blocklist)
214-
: Options(Options), Allowlist(Allowlist), Blocklist(Blocklist) {}
216+
: M(M), DTCallback(DTCallback), PDTCallback(PDTCallback),
217+
Options(Options), Allowlist(Allowlist), Blocklist(Blocklist) {}
215218

216-
bool instrumentModule(Module &M, DomTreeCallback DTCallback,
217-
PostDomTreeCallback PDTCallback);
219+
bool instrumentModule();
218220

219221
private:
220222
void createFunctionControlFlow(Function &F);
221-
void instrumentFunction(Function &F, DomTreeCallback DTCallback,
222-
PostDomTreeCallback PDTCallback);
223+
void instrumentFunction(Function &F);
223224
void InjectCoverageForIndirectCalls(Function &F,
224225
ArrayRef<Instruction *> IndirCalls);
225226
void InjectTraceForCmp(Function &F, ArrayRef<Instruction *> CmpTraceTargets);
@@ -249,6 +250,11 @@ class ModuleSanitizerCoverage {
249250
std::string getSectionName(const std::string &Section) const;
250251
std::string getSectionStart(const std::string &Section) const;
251252
std::string getSectionEnd(const std::string &Section) const;
253+
254+
Module &M;
255+
DomTreeCallback DTCallback;
256+
PostDomTreeCallback PDTCallback;
257+
252258
FunctionCallee SanCovTracePCIndir;
253259
FunctionCallee SanCovTracePC, SanCovTracePCGuard;
254260
std::array<FunctionCallee, 4> SanCovTraceCmpFunction;
@@ -283,16 +289,17 @@ class ModuleSanitizerCoverage {
283289

284290
PreservedAnalyses SanitizerCoveragePass::run(Module &M,
285291
ModuleAnalysisManager &MAM) {
286-
ModuleSanitizerCoverage ModuleSancov(OverrideFromCL(Options), Allowlist.get(),
287-
Blocklist.get());
288292
auto &FAM = MAM.getResult<FunctionAnalysisManagerModuleProxy>(M).getManager();
289293
auto DTCallback = [&FAM](Function &F) -> const DominatorTree & {
290294
return FAM.getResult<DominatorTreeAnalysis>(F);
291295
};
292296
auto PDTCallback = [&FAM](Function &F) -> const PostDominatorTree & {
293297
return FAM.getResult<PostDominatorTreeAnalysis>(F);
294298
};
295-
if (!ModuleSancov.instrumentModule(M, DTCallback, PDTCallback))
299+
ModuleSanitizerCoverage ModuleSancov(M, DTCallback, PDTCallback,
300+
OverrideFromCL(Options), Allowlist.get(),
301+
Blocklist.get());
302+
if (!ModuleSancov.instrumentModule())
296303
return PreservedAnalyses::all();
297304

298305
PreservedAnalyses PA = PreservedAnalyses::none();
@@ -363,8 +370,7 @@ Function *ModuleSanitizerCoverage::CreateInitCallsForSections(
363370
return CtorFunc;
364371
}
365372

366-
bool ModuleSanitizerCoverage::instrumentModule(
367-
Module &M, DomTreeCallback DTCallback, PostDomTreeCallback PDTCallback) {
373+
bool ModuleSanitizerCoverage::instrumentModule() {
368374
if (Options.CoverageType == SanitizerCoverageOptions::SCK_None)
369375
return false;
370376
if (Allowlist &&
@@ -477,7 +483,7 @@ bool ModuleSanitizerCoverage::instrumentModule(
477483
M.getOrInsertFunction(SanCovTracePCGuardName, VoidTy, PtrTy);
478484

479485
for (auto &F : M)
480-
instrumentFunction(F, DTCallback, PDTCallback);
486+
instrumentFunction(F);
481487

482488
Function *Ctor = nullptr;
483489

@@ -596,8 +602,7 @@ static bool IsInterestingCmp(ICmpInst *CMP, const DominatorTree &DT,
596602
return true;
597603
}
598604

599-
void ModuleSanitizerCoverage::instrumentFunction(
600-
Function &F, DomTreeCallback DTCallback, PostDomTreeCallback PDTCallback) {
605+
void ModuleSanitizerCoverage::instrumentFunction(Function &F) {
601606
if (F.empty())
602607
return;
603608
if (F.getName().contains(".module_ctor"))

0 commit comments

Comments
 (0)