LLVM 20.0.0git
Classes | Namespaces | Macros
DebugCounter.h File Reference

This file provides an implementation of debug counters. More...

#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/UniqueVector.h"
#include "llvm/Support/Debug.h"
#include <string>

Go to the source code of this file.

Classes

class  llvm::DebugCounter
 
struct  llvm::DebugCounter::Chunk
 
struct  llvm::DebugCounter::CounterState
 
struct  llvm::DebugCounter::CounterInfo
 

Namespaces

namespace  llvm
 This is an optimization pass for GlobalISel generic memory operations.
 

Macros

#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
 

Detailed Description

This file provides an implementation of debug counters.

Debug counters are a tool that let you narrow down a miscompilation to a specific thing happening.

To give a use case: Imagine you have a file, very large, and you are trying to understand the minimal transformation that breaks it. Bugpoint and bisection is often helpful here in narrowing it down to a specific pass, but it's still a very large file, and a very complicated pass to try to debug. That is where debug counting steps in. You can instrument the pass with a debug counter before it does a certain thing, and depending on the counts, it will either execute that thing or not. The debug counter itself consists of a list of chunks (inclusive numeric ranges). shouldExecute returns true iff the list is empty or the current count is in one of the chunks.

Note that a counter set to a negative number will always execute. For a concrete example, during predicateinfo creation, the renaming pass replaces each use with a renamed use.

If I use DEBUG_COUNTER to create a counter called "predicateinfo", and variable name RenameCounter, and then instrument this renaming with a debug counter, like so:

if (!DebugCounter::shouldExecute(RenameCounter) <continue or return or whatever not executing looks like>

Now I can, from the command line, make it rename or not rename certain uses by setting the chunk list. So for example bin/opt -debug-counter=predicateinfo=47 will skip renaming the first 47 uses, then rename one, then skip the rest.

Definition in file DebugCounter.h.

Macro Definition Documentation

◆ DEBUG_COUNTER

#define DEBUG_COUNTER (   VARNAME,
  COUNTERNAME,
  DESC 
)
Value:
static const unsigned VARNAME = \
DebugCounter::registerCounter(COUNTERNAME, DESC)
#define DESC

Definition at line 190 of file DebugCounter.h.