Page MenuHomePhabricator

[mlir] Add support for DebugCounters using the new DebugAction infrastructure
ClosedPublic

Authored by rriddle on Feb 9 2021, 8:41 PM.

Details

Summary

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.

Depends On D84986

Diff Detail

Event Timeline

rriddle created this revision.Feb 9 2021, 8:41 PM
rriddle requested review of this revision.Feb 9 2021, 8:41 PM
jpienaar accepted this revision.Feb 18 2021, 3:44 PM

Nice, thanks

mlir/docs/DebugActions.md
188

Can these be chained? E.g., skip 47, execute 2, skip 10 again, execute 17?

205

Seems like we alternate between `shell and `sh , but `shell is mostly used.

mlir/lib/Support/DebugCounter.cpp
25

Should these still be registered in opt builds? (I'm assuming they'd have no effect there)

126

Why not fail here? Given this is only used in debug builds

This revision is now accepted and ready to land.Feb 18 2021, 3:44 PM
rriddle updated this revision to Diff 325127.Feb 19 2021, 6:31 PM
rriddle marked 3 inline comments as done.

update

mlir/docs/DebugActions.md
188

No, each counter currently only has one skip and one count, so chaining isn't possible. Added a note.

205

We should align around one, do you have a preference?

mlir/lib/Support/DebugCounter.cpp
25

Good point, wrapped registration with NDEBUG.

mehdi_amini accepted this revision.Feb 19 2021, 8:00 PM
mehdi_amini added inline comments.
mlir/docs/DebugActions.md
214

Please document the -mlir-print-debug-counter aspect, that seems fairly important in the workflow. I'd expect someone to start from this to get initial values for bisecting for example.

rriddle marked an inline comment as done.Feb 22 2021, 6:42 PM
mehdi_amini accepted this revision.Feb 22 2021, 8:19 PM
This revision was landed with ongoing or failed builds.Feb 23 2021, 1:02 AM
This revision was automatically updated to reflect the committed changes.