Change the DebugAction paradigm to delegate the control to the handler
authorMehdi Amini <joker.eph@gmail.com>
Tue, 18 Oct 2022 23:03:48 +0000 (23:03 +0000)
committerMehdi Amini <joker.eph@gmail.com>
Mon, 6 Mar 2023 14:58:26 +0000 (15:58 +0100)
commit7fbcf10e2e7a408dc551cab5c180ebc2fb679454
treebc1ee5b415a943b3754b3723580a40230f07a675
parent5c2716b87acd8603de5b8d280ee857524d6d81bd
Change the DebugAction paradigm to delegate the control to the handler

At the moment, we invoke `shouldExecute()` that way:

```
if (manager.shouldExecute<DebugAction>(currentOp) {
  // apply a transformation
  …
}
```

In this sequence, the manager isn’t involved in the actual execution
of the action and can’t develop rich instrumentations. Instead the API
could let the control to the handler itself:

```
// Execute the action under the control of the manager
manager.execute<DebugAction>(currentOp, [&]() {
  // apply the transformation in this callback
  …
});
```

This inversion of control (by injecting a callback) allows handlers to
implement potentially new interesting features: for example, snapshot
the IR before and after the action, or record an action execution time.
More importantly, it will allow to capture the nesting execution of
actions.

On the other side: handlers receives now a DebugAction object that wraps
generic information (tag and description especially) as well as
action-specific data.

Finally, the DebugActionManager is now enabled in release builds as
well.

Differential Revision: https://reviews.llvm.org/D144808
mlir/include/mlir/Support/DebugAction.h
mlir/include/mlir/Support/DebugCounter.h
mlir/lib/Support/DebugCounter.cpp
mlir/unittests/Support/DebugActionTest.cpp
mlir/unittests/Support/DebugCounterTest.cpp