LLVM 23.0.0git
BlockCoverageInference.h
Go to the documentation of this file.
1//===-- BlockCoverageInference.h - Minimal Execution Coverage ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file finds the minimum set of blocks on a CFG that must be instrumented
11/// to infer execution coverage for the whole graph.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_BLOCKCOVERAGEINFERENCE_H
16#define LLVM_TRANSFORMS_INSTRUMENTATION_BLOCKCOVERAGEINFERENCE_H
17
18#include "llvm/ADT/ArrayRef.h"
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/SetVector.h"
23
24namespace llvm {
25
26class Function;
27class BasicBlock;
28class DotFuncBCIInfo;
29
31 friend class DotFuncBCIInfo;
32
33public:
35
36 LLVM_ABI BlockCoverageInference(const Function &F, bool ForceInstrumentEntry);
37
38 /// \return true if \p BB should be instrumented for coverage.
39 LLVM_ABI bool shouldInstrumentBlock(const BasicBlock &BB) const;
40
41 /// \return the set of blocks \p Deps such that \p BB is covered iff any
42 /// blocks in \p Deps are covered.
44
45 /// \return a hash that depends on the set of instrumented blocks.
47
48 /// Dump the inference graph.
49 LLVM_ABI void dump(raw_ostream &OS) const;
50
51 /// View the inferred block coverage as a dot file.
52 /// Filled gray blocks are instrumented, red outlined blocks are found to be
53 /// covered, red edges show that a block's coverage can be inferred from its
54 /// successors, and blue edges show that a block's coverage can be inferred
55 /// from its predecessors.
57 const DenseMap<const BasicBlock *, bool> *Coverage = nullptr) const;
58
59private:
60 const Function &F;
61 bool ForceInstrumentEntry;
62
63 /// Maps blocks to a minimal list of predecessors that can be used to infer
64 /// this block's coverage.
65 DenseMap<const BasicBlock *, BlockSet> PredecessorDependencies;
66
67 /// Maps blocks to a minimal list of successors that can be used to infer
68 /// this block's coverage.
69 DenseMap<const BasicBlock *, BlockSet> SuccessorDependencies;
70
71 /// Compute \p PredecessorDependencies and \p SuccessorDependencies.
72 void findDependencies();
73
74 /// Find the set of basic blocks that are reachable from \p Start without the
75 /// basic block \p Avoid.
76 void getReachableAvoiding(const BasicBlock &Start, const BasicBlock &Avoid,
77 bool IsForward, BlockSet &Reachable) const;
78
79 LLVM_ABI static std::string getBlockNames(ArrayRef<const BasicBlock *> BBs);
80 static std::string getBlockNames(BlockSet BBs) {
81 return getBlockNames(ArrayRef<const BasicBlock *>(BBs.begin(), BBs.end()));
82 }
83};
84
85} // end namespace llvm
86
87#endif // LLVM_TRANSFORMS_INSTRUMENTATION_BLOCKCOVERAGEINFERENCE_H
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
static bool findDependencies(DependenceKind Flavor, const Value *Arg, BasicBlock *StartBB, Instruction *StartInst, SmallPtrSetImpl< Instruction * > &DependingInsts, ProvenanceAnalysis &PA)
Walk up the CFG from StartPos (which is in StartBB) and find local and non-local dependencies on Arg.
This file implements a set that has insertion order iteration characteristics.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
LLVM Basic Block Representation.
Definition BasicBlock.h:62
LLVM_ABI void dump(raw_ostream &OS) const
Dump the inference graph.
LLVM_ABI uint64_t getInstrumentedBlocksHash() const
LLVM_ABI bool shouldInstrumentBlock(const BasicBlock &BB) const
LLVM_ABI void viewBlockCoverageGraph(const DenseMap< const BasicBlock *, bool > *Coverage=nullptr) const
View the inferred block coverage as a dot file.
LLVM_ABI BlockCoverageInference(const Function &F, bool ForceInstrumentEntry)
LLVM_ABI BlockSet getDependencies(const BasicBlock &BB) const
SmallSetVector< const BasicBlock *, 4 > BlockSet
iterator end()
Get an iterator to the end of the SetVector.
Definition SetVector.h:112
iterator begin()
Get an iterator to the beginning of the SetVector.
Definition SetVector.h:106
A SetVector that performs no allocations if smaller than a certain size.
Definition SetVector.h:339
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.