This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Operation] Simplify Operation casting, NFC
ClosedPublic

Authored by bzcheeseman on May 4 2022, 2:00 PM.

Details

Summary

We can simplify the code needed to implement dyn_cast/cast/isa support for MLIR operations with documented interfaces via the CastInfo structures. This will also provide an example of how to use CastInfo.

Depends on D123901

Diff Detail

Event Timeline

bzcheeseman created this revision.May 4 2022, 2:00 PM
Herald added a project: Restricted Project. · View Herald Transcript
bzcheeseman requested review of this revision.May 4 2022, 2:00 PM
bzcheeseman edited the summary of this revision. (Show Details)May 4 2022, 2:01 PM
bzcheeseman retitled this revision from [MLIR][Operations] Simplify Operation casting to [MLIR][Operation] Simplify Operation casting, NFC.May 4 2022, 2:16 PM
bzcheeseman edited the summary of this revision. (Show Details)
rriddle accepted this revision.May 11 2022, 9:19 AM
rriddle added inline comments.
mlir/include/mlir/IR/Operation.h
827–833

I wonder if we should have a trait for forwarding the reference variant to the pointer variant of a ToValueCast. Though maybe this is rare enough where it doesn't matter.

This revision is now accepted and ready to land.May 11 2022, 9:19 AM
This revision was automatically updated to reflect the committed changes.
bzcheeseman added inline comments.May 11 2022, 9:40 PM
mlir/include/mlir/IR/Operation.h
827–833

Yeah I don't think it happens that often, not many systems have fallible reference-to-reference casting. But luckily, if it does, we can add a trait for it :)

rriddle added inline comments.May 11 2022, 9:42 PM
mlir/include/mlir/IR/Operation.h
827–833

Well this is reference-to-value, which for anything that crosses the reference-value boundary would be common.

bzcheeseman added inline comments.May 11 2022, 10:09 PM
mlir/include/mlir/IR/Operation.h
827–833

Fair enough - though we're just adding a convenience specialization on top so that we don't have to use dyn_cast<T>(&operation). If more MLIR structures want this it should be easy to add a forwarding trait, I just haven't seen the demand yet.