]> granicus.if.org Git - llvm/commitdiff
DebugCounters: Add API for setting/unsetting programatically.
authorDaniel Berlin <dberlin@dberlin.org>
Sat, 18 Mar 2017 15:41:13 +0000 (15:41 +0000)
committerDaniel Berlin <dberlin@dberlin.org>
Sat, 18 Mar 2017 15:41:13 +0000 (15:41 +0000)
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

include/llvm/Support/DebugCounter.h

index 9691b80fce8a09fc31a2e8030244e43bee93c316..9687cb7b9d95fa835b55e7a0c9991f04e94e4695 100644 (file)
@@ -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);