[mlir] Add support for DebugCounters using the new DebugAction infrastructure
authorRiver Riddle <riddleriver@gmail.com>
Tue, 23 Feb 2021 08:51:57 +0000 (00:51 -0800)
committerRiver Riddle <riddleriver@gmail.com>
Tue, 23 Feb 2021 09:01:17 +0000 (01:01 -0800)
commitdc6a84fce617ab8367a84029d4ff3c698dc57dad
tree45426b698f1704a2d41867ae0dc56e7f75aad170
parent72d5afa4acc3cb7fdeb6ead90cc8f446a48c1f9d
[mlir] Add support for DebugCounters using the new DebugAction infrastructure

DebugCounters allow for selectively enabling the execution of a debug action based upon a "counter". This counter is comprised of two components that are used in the control of execution of an action, a "skip" value and a "count" value. The "skip" value is used to skip a certain number of initial executions of a debug action. The "count" value is used to prevent a debug action from executing after it has executed for a set number of times (not including any executions that have been skipped). For example, a counter for a debug action with `skip=47` and `count=2`, would skip the first 47 executions, then execute twice, and finally prevent any further executions.

This is effectively the same as the DebugCounter infrastructure in LLVM, but using the DebugAction infrastructure in MLIR. We can't simply reuse the DebugCounter support already present in LLVM due to its heavy reliance on global constructors (which are not allowed in MLIR). The DebugAction infrastructure already nicely supports the debug counter use case, and promotes the separation of policy and mechanism design philosophy.

Differential Revision: https://reviews.llvm.org/D96395
mlir/docs/DebugActions.md
mlir/include/mlir/Support/DebugCounter.h [new file with mode: 0644]
mlir/lib/Support/CMakeLists.txt
mlir/lib/Support/DebugCounter.cpp [new file with mode: 0644]
mlir/lib/Support/MlirOptMain.cpp
mlir/unittests/Support/CMakeLists.txt
mlir/unittests/Support/DebugCounterTest.cpp [new file with mode: 0644]