[mlir] support isa/cast/dyn_cast<Operation *>(operation) again
authorAlex Zinenko <zinenko@google.com>
Fri, 13 May 2022 13:06:02 +0000 (15:06 +0200)
committerAlex Zinenko <zinenko@google.com>
Tue, 17 May 2022 09:15:17 +0000 (11:15 +0200)
commit1075c8ca49b467ec5e654a4322fbb36f63e8687f
treebd16253e1434cc15d3f26a16d546dfa1c0b5b691
parent26593e73147d5d66d87ad1a69faeaad6776b8d1d
[mlir] support isa/cast/dyn_cast<Operation *>(operation) again

The support for this has been added by 946311b8938114a37db5c9d42fb9f5a1481ccae1
but then ignored by bc22b5c9a2f729460ffdf7627b3534a8d9f3f767.

This enables one to write generic code that can be instantiated for both
specific operation classes and the common base class without
specialization. Examples include functions that take/return ops, such
as:

```mlir
template <typename FnTy>
void applyIf(FnTy &&lambda, ...) {
  for (Operation *op : ...) {
    auto specific = dyn_cast<function_traits<FnTy>::template arg_t<0>>(op);
    if (specific)
      lambda(specific);
  }
}
```

that would otherwise need to rely on template specialization to support
lambdas that take specific operations and those that take `Operation *`.

Differential Revision: https://reviews.llvm.org/D125543

Reviewed by: rriddle
mlir/include/mlir/IR/Operation.h