Index: include/llvm/Support/DebugCounter.h =================================================================== --- include/llvm/Support/DebugCounter.h +++ include/llvm/Support/DebugCounter.h @@ -77,22 +77,21 @@ auto &Us = instance(); auto Result = Us.Counters.find(CounterName); if (Result != Us.Counters.end()) { - auto &CounterPair = Result->second; - // We only execute while the skip (first) is zero and the count (second) - // is non-zero. + auto &CounterInfo = Result->second; + // Record how many times does shouldExecute() run for this Counter + ++CounterInfo.Count; + + // We only execute while the Skip is not smaller than Count, + // and the StopAfter + Skip is larger than Count. // Negative counters always execute. - if (CounterPair.first < 0) + if (CounterInfo.Skip < 0) return true; - if (CounterPair.first != 0) { - --CounterPair.first; + if (CounterInfo.Skip >= CounterInfo.Count) return false; - } - if (CounterPair.second < 0) + if (CounterInfo.StopAfter < 0) return true; - if (CounterPair.second != 0) { - --CounterPair.second; + if (CounterInfo.StopAfter + CounterInfo.Skip > CounterInfo.Count) return true; - } return false; } // Didn't find the counter, should we warn? @@ -107,18 +106,18 @@ 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) { + // Return the Count for a counter. This only works for set counters. + static long 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; + return Result->second.Count; } - // Set a registered counter to a given value. - static void setCounterValue(unsigned ID, const std::pair &Val) { + // Set a registered counter to a given Count value. + static void setCounterValue(unsigned ID, long Count) { auto &Us = instance(); - Us.Counters[ID] = Val; + Us.Counters[ID].Count = Count; } // Dump or print the current counter set into llvm::dbgs(). @@ -150,9 +149,17 @@ unsigned addCounter(const std::string &Name, const std::string &Desc) { unsigned Result = RegisteredCounters.insert(Name); CounterDesc[Result] = Desc; + CounterInfo CI; + Counters[Result] = CI; return Result; } - DenseMap> Counters; + // Struct to store counter info. + struct CounterInfo { + long Count = 0; + long Skip = 0; + long StopAfter = -1; + }; + DenseMap Counters; DenseMap CounterDesc; CounterVector RegisteredCounters; }; Index: lib/Support/DebugCounter.cpp =================================================================== --- lib/Support/DebugCounter.cpp +++ lib/Support/DebugCounter.cpp @@ -82,9 +82,7 @@ << " is not a registered counter\n"; return; } - - auto Res = Counters.insert({CounterID, {0, -1}}); - Res.first->second.first = CounterVal; + Counters[CounterID].Skip = CounterVal; } else if (CounterPair.first.endswith("-count")) { auto CounterName = CounterPair.first.drop_back(6); unsigned CounterID = RegisteredCounters.idFor(CounterName); @@ -93,9 +91,7 @@ << " is not a registered counter\n"; return; } - - auto Res = Counters.insert({CounterID, {0, -1}}); - Res.first->second.second = CounterVal; + Counters[CounterID].StopAfter = CounterVal; } else { errs() << "DebugCounter Error: " << CounterPair.first << " does not end with -skip or -count\n"; @@ -106,7 +102,8 @@ OS << "Counters and values:\n"; for (const auto &KV : Counters) OS << left_justify(RegisteredCounters[KV.first], 32) << ": {" - << KV.second.first << "," << KV.second.second << "}\n"; + << KV.second.Count << "," << KV.second.Skip << "," + << KV.second.StopAfter << "}\n"; } LLVM_DUMP_METHOD void DebugCounter::dump() const { Index: lib/Transforms/Scalar/NewGVN.cpp =================================================================== --- lib/Transforms/Scalar/NewGVN.cpp +++ lib/Transforms/Scalar/NewGVN.cpp @@ -861,7 +861,7 @@ // Debug counter info. When verifying, we have to reset the value numbering // debug counter to the same state it started in to get the same results. - std::pair StartingVNCounter; + long StartingVNCounter; }; } // end anonymous namespace