Page MenuHomePhabricator

[mlir] support isa/cast/dyn_cast<Operation *>(operation)
ClosedPublic

Authored by ftynse on Apr 29 2022, 8:22 AM.

Details

Summary

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

Diff Detail

Event Timeline

ftynse created this revision.Apr 29 2022, 8:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 29 2022, 8:22 AM
ftynse requested review of this revision.Apr 29 2022, 8:22 AM
rriddle accepted this revision.Apr 29 2022, 10:05 AM

It's really really sad that we would need to add casting to the same type. I suppose this is better than using SFINAE.

This revision is now accepted and ready to land.Apr 29 2022, 10:05 AM
This revision was landed with ongoing or failed builds.May 2 2022, 1:07 AM
This revision was automatically updated to reflect the committed changes.
ftynse added a comment.May 2 2022, 1:08 AM

This is indeed sad, but seemed like least worst solution compared to enable_if.