From: Daniel Berlin Date: Sat, 18 Mar 2017 15:41:13 +0000 (+0000) Subject: DebugCounters: Add API for setting/unsetting programatically. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1843415cb08e653e0a73370e61129772db9d8d0;p=llvm DebugCounters: Add API for setting/unsetting programatically. This is required so we can re-set the counter state for verifiers, etc. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298186 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Support/DebugCounter.h b/include/llvm/Support/DebugCounter.h index 9691b80fce8..9687cb7b9d9 100644 --- a/include/llvm/Support/DebugCounter.h +++ b/include/llvm/Support/DebugCounter.h @@ -7,12 +7,12 @@ // //===----------------------------------------------------------------------===// /// \file -/// \brief 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. +/// \brief 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 +/// 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 @@ -100,11 +100,32 @@ public: #endif // NDEBUG } + // Return true if a given counter had values set (either programatically or on + // the command line). This will return true even if those values are + // currently in a state where the counter will always execute. + static bool isCounterSet(unsigned ID) { + return instance().Counters.count(ID); + } + + // Return the skip and count for a counter. This only works for set counters. + static std::pair getCounterValue(unsigned ID) { + auto &Us = instance(); + auto Result = Us.Counters.find(ID); + assert(Result != Us.Counters.end() && "Asking about a non-set counter"); + return Result->second; + } + + // Set a registered counter to a given value. + static void setCounterValue(unsigned ID, const std::pair &Val) { + auto &Us = instance(); + Us.Counters[ID] = Val; + } + // Dump or print the current counter set. LLVM_DUMP_METHOD void dump() { print(dbgs()); } void print(raw_ostream &OS); - + // Get the counter ID for a given named counter, or return 0 if none is found. unsigned getCounterId(const std::string &Name) const { return RegisteredCounters.idFor(Name);