[PATCH] D36847: [Support] Add "reference-counted" Timer

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 17 13:58:31 PDT 2017


modocache created this revision.

In Clang's `lib/CodeGen/CodeGenAction.cpp`, a timer is used to measure
the amount of time spent generating LLVM IR. The timer is started and
stopped in a method, `BackendConsumer::HandleTopLevelDecl`, that is called
recursively. `llvm::Timer` does not allow starting a timer twice, so to
prevent a runtime assertion that would occur if the timer is started
a second time as the method recurses, it's guarded by a "reference
count" variable: if the reference count is incremented from 0 to 1, the
timer is started. Subsequent calls to start the timer increment the
reference count, but do not call `startTimer()`. `stopTimer()` is called when
the reference count goes from 1 to 0.

This pattern is useful when timing any recursive method, such as in
https://reviews.llvm.org/D36492.

Add a `RefCntTimer` that can be used for situations such as these.
Unlike the base `Timer` class, multiple calls to `startTimer()` are
fine, as long as `stopTimer()` is called an equal number of times.


https://reviews.llvm.org/D36847

Files:
  include/llvm/Support/Timer.h
  lib/Support/Timer.cpp
  unittests/Support/TimerTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36847.111562.patch
Type: text/x-patch
Size: 3124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170817/253744e4/attachment.bin>


More information about the llvm-commits mailing list