[llvm] r298186 - DebugCounters: Add API for setting/unsetting programatically.

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 18 08:41:14 PDT 2017


Author: dannyb
Date: Sat Mar 18 10:41:13 2017
New Revision: 298186

URL: http://llvm.org/viewvc/llvm-project?rev=298186&view=rev
Log:
DebugCounters: Add API for setting/unsetting programatically.
This is required so we can re-set the counter state for verifiers,
etc.

Modified:
    llvm/trunk/include/llvm/Support/DebugCounter.h

Modified: llvm/trunk/include/llvm/Support/DebugCounter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/DebugCounter.h?rev=298186&r1=298185&r2=298186&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/DebugCounter.h (original)
+++ llvm/trunk/include/llvm/Support/DebugCounter.h Sat Mar 18 10:41:13 2017
@@ -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<int, int> 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<int, int> &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);




More information about the llvm-commits mailing list