xref: /freebsd-src/contrib/llvm-project/llvm/include/llvm/Transforms/Instrumentation/SanitizerCoverage.h (revision bdd1243df58e60e85101c09001d9812a789b6bc4)
18bcb0991SDimitry Andric //===--------- Definition of the SanitizerCoverage class --------*- C++ -*-===//
28bcb0991SDimitry Andric //
38bcb0991SDimitry Andric //                     The LLVM Compiler Infrastructure
48bcb0991SDimitry Andric //
58bcb0991SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
68bcb0991SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
78bcb0991SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88bcb0991SDimitry Andric //
98bcb0991SDimitry Andric //===----------------------------------------------------------------------===//
108bcb0991SDimitry Andric //
11fcaf7f86SDimitry Andric // SanitizerCoverage is a simple code coverage implementation.
128bcb0991SDimitry Andric //
138bcb0991SDimitry Andric //===----------------------------------------------------------------------===//
148bcb0991SDimitry Andric 
158bcb0991SDimitry Andric #ifndef LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H
168bcb0991SDimitry Andric #define LLVM_TRANSFORMS_INSTRUMENTATION_SANITIZERCOVERAGE_H
178bcb0991SDimitry Andric 
188bcb0991SDimitry Andric #include "llvm/IR/PassManager.h"
195ffd83dbSDimitry Andric #include "llvm/Support/SpecialCaseList.h"
205ffd83dbSDimitry Andric #include "llvm/Support/VirtualFileSystem.h"
218bcb0991SDimitry Andric #include "llvm/Transforms/Instrumentation.h"
228bcb0991SDimitry Andric 
238bcb0991SDimitry Andric namespace llvm {
2481ad6265SDimitry Andric class Module;
258bcb0991SDimitry Andric 
268bcb0991SDimitry Andric /// This is the ModuleSanitizerCoverage pass used in the new pass manager. The
278bcb0991SDimitry Andric /// pass instruments functions for coverage, adds initialization calls to the
288bcb0991SDimitry Andric /// module for trace PC guards and 8bit counters if they are requested, and
298bcb0991SDimitry Andric /// appends globals to llvm.compiler.used.
30*bdd1243dSDimitry Andric class SanitizerCoveragePass : public PassInfoMixin<SanitizerCoveragePass> {
318bcb0991SDimitry Andric public:
32*bdd1243dSDimitry Andric   explicit SanitizerCoveragePass(
335ffd83dbSDimitry Andric       SanitizerCoverageOptions Options = SanitizerCoverageOptions(),
345ffd83dbSDimitry Andric       const std::vector<std::string> &AllowlistFiles =
355ffd83dbSDimitry Andric           std::vector<std::string>(),
365ffd83dbSDimitry Andric       const std::vector<std::string> &BlocklistFiles =
375ffd83dbSDimitry Andric           std::vector<std::string>())
Options(Options)385ffd83dbSDimitry Andric       : Options(Options) {
395ffd83dbSDimitry Andric     if (AllowlistFiles.size() > 0)
405ffd83dbSDimitry Andric       Allowlist = SpecialCaseList::createOrDie(AllowlistFiles,
415ffd83dbSDimitry Andric                                                *vfs::getRealFileSystem());
425ffd83dbSDimitry Andric     if (BlocklistFiles.size() > 0)
435ffd83dbSDimitry Andric       Blocklist = SpecialCaseList::createOrDie(BlocklistFiles,
445ffd83dbSDimitry Andric                                                *vfs::getRealFileSystem());
455ffd83dbSDimitry Andric   }
468bcb0991SDimitry Andric   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
isRequired()47e8d8bef9SDimitry Andric   static bool isRequired() { return true; }
488bcb0991SDimitry Andric 
498bcb0991SDimitry Andric private:
508bcb0991SDimitry Andric   SanitizerCoverageOptions Options;
515ffd83dbSDimitry Andric 
525ffd83dbSDimitry Andric   std::unique_ptr<SpecialCaseList> Allowlist;
535ffd83dbSDimitry Andric   std::unique_ptr<SpecialCaseList> Blocklist;
548bcb0991SDimitry Andric };
558bcb0991SDimitry Andric 
568bcb0991SDimitry Andric } // namespace llvm
578bcb0991SDimitry Andric 
588bcb0991SDimitry Andric #endif
59