24class DebugCounterList :
public cl::list<std::string, DebugCounter> {
29 template <
class... Mods>
30 explicit DebugCounterList(Mods &&... Ms) :
Base(
std::forward<Mods>(Ms)...) {}
33 void printOptionInfo(
size_t GlobalWidth)
const override {
41 outs() <<
" -" << ArgStr;
44 Option::printHelpStr(HelpStr, GlobalWidth, ArgStr.size() + 6);
46 for (
const auto &Entry : CounterInstance) {
47 const auto &[
Name,
Desc] = CounterInstance.getCounterDesc(
Entry.second);
48 size_t NumSpaces = GlobalWidth -
Name.size() - 8;
60 DebugCounterList DebugCounterOption{
62 cl::desc(
"Comma separated list of debug counter skip and count"),
64 cl::opt<bool, true> PrintDebugCounter{
65 "print-debug-counter",
70 cl::desc(
"Print out debug counter info after all counters accumulated"),
73 activateAllCounters();
75 cl::opt<bool, true> PrintDebugCounterQueries{
76 "print-debug-counter-queries",
81 cl::desc(
"Print out each query of an enabled debug counter")};
82 cl::opt<bool, true> BreakOnLastCount{
83 "debug-counter-break-on-last",
88 cl::desc(
"Insert a break point on the last enabled count of a "
98 ~DebugCounterOwner() {
99 if (ShouldPrintCounter)
123 if (CounterPair.second.empty()) {
124 errs() <<
"DebugCounter Error: " << Val <<
" does not have an = in it\n";
127 StringRef CounterName = CounterPair.first;
131 errs() <<
"DebugCounter Error: " << CounterName
132 <<
" is not a registered counter\n";
136 auto ExpectedChunks =
138 if (!ExpectedChunks) {
140 errs() <<
"DebugCounter Error: " << E.getMessage() <<
"\n";
144 Counter->Chunks = std::move(*ExpectedChunks);
145 Counter->Active = Counter->IsSet =
true;
152 OS <<
"Counters and values:\n";
153 for (
StringRef CounterName : CounterNames) {
162 int64_t CurrCount = Info.Count++;
163 uint64_t CurrIdx = Info.CurrChunkIdx;
165 if (Info.Chunks.empty())
167 if (CurrIdx >= Info.Chunks.size())
170 bool Res = Info.Chunks[CurrIdx].contains(CurrCount);
171 if (
BreakOnLast && CurrIdx == (Info.Chunks.size() - 1) &&
172 CurrCount == Info.Chunks[CurrIdx].getEnd()) {
175 if (CurrCount > Info.Chunks[CurrIdx].getEnd()) {
179 if (Info.CurrChunkIdx < Info.Chunks.size() &&
180 CurrCount == Info.Chunks[Info.CurrChunkIdx].getBegin())
188 bool Res = Us.handleCounterIncrement(Counter);
189 if (Us.ShouldPrintCounterQueries && Counter.IsSet) {
190 dbgs() <<
"DebugCounter " << Counter.Name <<
"=" << (Counter.Count - 1)
191 << (Res ?
" execute" :
" skip") <<
"\n";
196#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
#define LLVM_BUILTIN_DEBUGTRAP
LLVM_BUILTIN_DEBUGTRAP - On compilers which support it, expands to an expression which causes the pro...
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
static ManagedStatic< DebugCounterOwner > Owner
This file provides an implementation of debug counters.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Struct to store counter info.
CounterInfo * getCounterInfo(StringRef Name) const
static LLVM_ABI void printChunks(raw_ostream &OS, ArrayRef< IntegerInclusiveInterval > Intervals)
bool handleCounterIncrement(CounterInfo &Info)
LLVM_ABI void push_back(const std::string &)
static LLVM_ABI bool shouldExecuteImpl(CounterInfo &Counter)
static LLVM_ABI DebugCounter & instance()
Returns a reference to the singleton instance.
LLVM_ABI void print(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const
MapVector< StringRef, CounterInfo * > Counters
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class wraps a string in an Error.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
@ C
The default llvm calling convention, compatible with C.
void printIntervals(raw_ostream &OS, ArrayRef< IntegerInclusiveInterval > Intervals, char Separator=',')
Print intervals to output stream.
Expected< IntervalList > parseIntervals(StringRef IntervalStr, char Separator=',')
Parse a interval specification string like "1-10,20-30,45" or "1-10:20-30:45".
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
cb< typename detail::callback_traits< F >::result_type, typename detail::callback_traits< F >::arg_type > callback(F CB)
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
Printable print(const GCNRegPressure &RP, const GCNSubtarget *ST=nullptr, unsigned DynamicVGPRBlockSize=0)
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
void initDebugCounterOptions()
void sort(IteratorTy Start, IteratorTy End)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
FormattedString left_justify(StringRef Str, unsigned Width)
left_justify - append spaces after string so total output is Width characters.
Implement std::hash so that hash_code can be used in STL containers.