[mlir] support isa/cast/dyn_cast<Operation *>(operation)
authorAlex Zinenko <zinenko@google.com>
Fri, 29 Apr 2022 15:13:24 +0000 (17:13 +0200)
committerAlex Zinenko <zinenko@google.com>
Mon, 2 May 2022 08:07:09 +0000 (10:07 +0200)
commit946311b8938114a37db5c9d42fb9f5a1481ccae1
tree44f5e31538eb04605e20dc046dc71ff1597e1f60
parent7c04454227f5c6bd3f515783950a815970c90558
[mlir] support isa/cast/dyn_cast<Operation *>(operation)

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 *`.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D124675
mlir/include/mlir/IR/Operation.h