Page MenuHomePhabricator

[mlir] Add a new `ConstantLike` trait to better identify operations that represent a "constant".
ClosedPublic

Authored by rriddle on Mar 11 2020, 11:46 AM.

Details

Summary

The current mechanism for identifying is a bit hacky and extremely adhoc, i.e. we explicit check 1-result, 0-operand, no side-effect, and always foldable and then assume that this is a constant. Adding a trait adds structure to this, and makes checking for a constant much more efficient as we can guarantee that all of these things have already been verified.

Depends On D76019

Diff Detail

Event Timeline

rriddle created this revision.Mar 11 2020, 11:46 AM
jpienaar accepted this revision.Mar 12 2020, 10:54 AM
jpienaar marked an inline comment as done.

Seems reasonable :) Thanks

mlir/include/mlir/IR/Matchers.h
51

Update comment?

mlir/include/mlir/IR/OpDefinition.h
916

What would happen if this wasn't true for the op? What error/assert/failure would be triggered?

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
1551

I think we also are missing documentation on the ordering effect of traits and even discussion pending on if order should matter ...

This revision is now accepted and ready to land.Mar 12 2020, 10:54 AM
rriddle updated this revision to Diff 250006.Mar 12 2020, 11:49 AM
rriddle marked 4 inline comments as done.

Resolve comments

rriddle added inline comments.Mar 12 2020, 11:50 AM
mlir/include/mlir/IR/OpDefinition.h
916

An assert in m_Constant(i.e. all of the current users) would fire when the folding fails.

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
1551

Yes, I find the behavior surprising sometimes when my mental model conflicts with what the implementation is. I'll try to draft something in a followup for Traits.md.

This revision was automatically updated to reflect the committed changes.