@@ -136,6 +136,13 @@ struct DebugCounterOwner : DebugCounter {
136136      cl::location (this ->ShouldPrintCounter ),
137137      cl::init (false ),
138138      cl::desc (" Print out debug counter info after all counters accumulated"  )};
139+   cl::opt<bool , true > PrintDebugCounterQueries{
140+       " print-debug-counter-queries"  ,
141+       cl::Hidden,
142+       cl::Optional,
143+       cl::location (this ->ShouldPrintCounterQueries ),
144+       cl::init (false ),
145+       cl::desc (" Print out each query of an enabled debug counter"  )};
139146  cl::opt<bool , true > BreakOnLastCount{
140147      " debug-counter-break-on-last"  ,
141148      cl::Hidden,
@@ -221,31 +228,40 @@ void DebugCounter::print(raw_ostream &OS) const {
221228  }
222229}
223230
231+ bool  DebugCounter::handleCounterIncrement (CounterInfo &Info) {
232+   int64_t  CurrCount = Info.Count ++;
233+   uint64_t  CurrIdx = Info.CurrChunkIdx ;
234+ 
235+   if  (Info.Chunks .empty ())
236+     return  true ;
237+   if  (CurrIdx >= Info.Chunks .size ())
238+     return  false ;
239+ 
240+   bool  Res = Info.Chunks [CurrIdx].contains (CurrCount);
241+   if  (BreakOnLast && CurrIdx == (Info.Chunks .size () - 1 ) &&
242+       CurrCount == Info.Chunks [CurrIdx].End ) {
243+     LLVM_BUILTIN_DEBUGTRAP;
244+   }
245+   if  (CurrCount > Info.Chunks [CurrIdx].End ) {
246+     Info.CurrChunkIdx ++;
247+ 
248+     // / Handle consecutive blocks.
249+     if  (Info.CurrChunkIdx  < Info.Chunks .size () &&
250+         CurrCount == Info.Chunks [Info.CurrChunkIdx ].Begin )
251+       return  true ;
252+   }
253+   return  Res;
254+ }
255+ 
224256bool  DebugCounter::shouldExecuteImpl (unsigned  CounterName) {
225257  auto  &Us = instance ();
226258  auto  Result = Us.Counters .find (CounterName);
227259  if  (Result != Us.Counters .end ()) {
228260    auto  &CounterInfo = Result->second ;
229-     int64_t  CurrCount = CounterInfo.Count ++;
230-     uint64_t  CurrIdx = CounterInfo.CurrChunkIdx ;
231- 
232-     if  (CounterInfo.Chunks .empty ())
233-       return  true ;
234-     if  (CurrIdx >= CounterInfo.Chunks .size ())
235-       return  false ;
236- 
237-     bool  Res = CounterInfo.Chunks [CurrIdx].contains (CurrCount);
238-     if  (Us.BreakOnLast  && CurrIdx == (CounterInfo.Chunks .size () - 1 ) &&
239-         CurrCount == CounterInfo.Chunks [CurrIdx].End ) {
240-       LLVM_BUILTIN_DEBUGTRAP;
241-     }
242-     if  (CurrCount > CounterInfo.Chunks [CurrIdx].End ) {
243-       CounterInfo.CurrChunkIdx ++;
244- 
245-       // / Handle consecutive blocks.
246-       if  (CounterInfo.CurrChunkIdx  < CounterInfo.Chunks .size () &&
247-           CurrCount == CounterInfo.Chunks [CounterInfo.CurrChunkIdx ].Begin )
248-         return  true ;
261+     bool  Res = Us.handleCounterIncrement (CounterInfo);
262+     if  (Us.ShouldPrintCounterQueries  && CounterInfo.IsSet ) {
263+       dbgs () << " DebugCounter "   << Us.RegisteredCounters [CounterName] << " =" 
264+              << (CounterInfo.Count  - 1 ) << (Res ? "  execute"   : "  skip"  ) << " \n "  ;
249265    }
250266    return  Res;
251267  }
0 commit comments