24for (
auto E : Chunks) {
37auto ConsumeInt = [&]() -> int64_t {
39 Remaining.
take_until([](
char c) {
return c <
'0' || c >
'9'; });
41if (
Number.getAsInteger(10, Res)) {
42errs() <<
"Failed to parse int at : " << Remaining <<
"\n";
50 int64_t Num = ConsumeInt();
53if (!Chunks.
empty() && Num <= Chunks[Chunks.
size() - 1].End) {
54errs() <<
"Expected Chunks to be in increasing order " << Num
55 <<
" <= " << Chunks[Chunks.
size() - 1].End <<
"\n";
60 int64_t Num2 = ConsumeInt();
64errs() <<
"Expected " << Num <<
" < " << Num2 <<
" in " << Num <<
"-" 79errs() <<
"Failed to parse at : " << Remaining;
88// This class overrides the default list implementation of printing so we 89// can pretty print the list of debug counter options. This type of 90// dynamic option is pretty rare (basically this and pass lists). 91classDebugCounterList :
publiccl::list<std::string, DebugCounter> {
96template <
class... Mods>
97explicit DebugCounterList(Mods &&... Ms) :
Base(
std::forward<Mods>(Ms)...) {}
100void printOptionInfo(
size_t GlobalWidth)
const override{
101// This is a variant of from generic_parser_base::printOptionInfo. Sadly, 102// it's not easy to make it more usable. We could get it to print these as 103// options if we were a cl::opt and registered them, but lists don't have 104// options, nor does the parser for std::string. The other mechanisms for 105// options are global and would pollute the global namespace with our 106// counters. Rather than go that route, we have just overridden the 107// printing, which only a few things call anyway. 108outs() <<
" -" << ArgStr;
109// All of the other options in CommandLine.cpp use ArgStr.size() + 6 for 110// width, so we do the same. 111 Option::printHelpStr(HelpStr, GlobalWidth, ArgStr.size() + 6);
113for (
constauto &
Name : CounterInstance) {
115 CounterInstance.getCounterInfo(CounterInstance.getCounterId(
Name));
116size_t NumSpaces = GlobalWidth -
Info.first.size() - 8;
123// All global objects associated to the DebugCounter, including the DebugCounter 124// itself, are owned by a single global instance of the DebugCounterOwner 125// struct. This makes it easier to control the order in which constructors and 126// destructors are run. 128 DebugCounterList DebugCounterOption{
130cl::desc(
"Comma separated list of debug counter skip and count"),
133"print-debug-counter",
138cl::desc(
"Print out debug counter info after all counters accumulated")};
140"debug-counter-break-on-last",
145cl::desc(
"Insert a break point on the last enabled count of a " 148 DebugCounterOwner() {
149// Our destructor uses the debug stream. By referencing it here, we 150// ensure that its destructor runs after our destructor. 154// Print information when destroyed, iff command line option is specified. 155 ~DebugCounterOwner() {
156if (ShouldPrintCounter)
161}
// anonymous namespace 166static DebugCounterOwner O;
170// This is called by the command line parser when it sees a value for the 171// debug-counter option defined above. 176// The strings should come in as counter=chunk_list 178if (CounterPair.second.empty()) {
179errs() <<
"DebugCounter Error: " << Val <<
" does not have an = in it\n";
182StringRef CounterName = CounterPair.first;
189unsigned CounterID =
getCounterId(std::string(CounterName));
191errs() <<
"DebugCounter Error: " << CounterName
192 <<
" is not a registered counter\n";
199 Counter.
Chunks = std::move(Chunks);
208OS <<
"Counters and values:\n";
209for (
auto &CounterName : CounterNames) {
210unsigned CounterID =
getCounterId(std::string(CounterName));
212 << Us.Counters[CounterID].Count <<
",";
220auto Result = Us.Counters.find(CounterName);
221if (Result != Us.Counters.end()) {
239 /// Handle consecutive blocks. 246// Didn't find the counter, should we warn? static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
Analysis containing CSE Info
#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.
This file provides an implementation of debug counters.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
empty - Check if the array is empty.
static void printChunks(raw_ostream &OS, ArrayRef< Chunk >)
DenseMap< unsigned, CounterInfo > Counters
CounterVector RegisteredCounters
void push_back(const std::string &)
unsigned getCounterId(const std::string &Name) const
static bool shouldExecuteImpl(unsigned CounterName)
static void enableAllCounters()
static bool parseChunks(StringRef Str, SmallVector< Chunk > &Res)
Return true on parsing error and print the error message on the llvm::errs()
static DebugCounter & instance()
Returns a reference to the singleton instance.
void print(raw_ostream &OS) const
LLVM_DUMP_METHOD void dump() const
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
StringRef drop_front(size_t N=1) const
Return a StringRef equal to 'this' but with the first N elements dropped.
StringRef take_until(function_ref< bool(char)> F) const
Return the longest prefix of 'this' such that no character in the prefix satisfies the given predicat...
iterator end()
Return an iterator to the end of the vector.
iterator begin()
Return an iterator to the start of the vector.
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.
initializer< Ty > init(const Ty &Val)
LocationClass< Ty > location(Ty &L)
This is an optimization pass for GlobalISel generic memory operations.
raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
void initDebugCounterOptions()
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
void print(llvm::raw_ostream &OS)
SmallVector< Chunk > Chunks