This is an archive of the discontinued LLVM Phabricator instance.

[mlir][ods] Generate inferReturnTypes for ops with TypesMatchWith
ClosedPublic

Authored by Mogball on Jan 8 2023, 12:53 PM.

Details

Summary

Ops that use TypesMatchWith to constrain result types for verification
and to infer result types during parser generation should also be able
to have the inferReturnTypes method auto generated. This patch
upgrades the logic for generating inferReturnTypes to handle the
TypesMatchWith trait by building a type inference graph where each edge
corresponds to "type of A can be inferred from type of B", supporting
transformers other than "$_self".

Diff Detail

Event Timeline

Mogball created this revision.Jan 8 2023, 12:53 PM
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a reviewer: ftynse. · View Herald Transcript
Herald added a reviewer: aartbik. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Mogball requested review of this revision.Jan 8 2023, 12:53 PM

I like all the red :)

mlir/lib/TableGen/Operator.cpp
394

Comments? (esp what does each element of the vector correspond to if any). Esp. given the name o fthe struct is quite general.

405–415

This comment feels out of place here.

436

I recall there was some uncertainty with variadics, but I also seem to recall there was a proposal to address it. What does this do with variadic operands & results?

475

known type vs already inferred confuses me here. E.g., an inferred type is known. Could we use other phrases?

509

Why do we need this here in condition slot vs in increment one? (also not sure why post-incrementing here)

512

Can we add a little static helper that would be more self-documenting than checking for negative or not?

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
2525–2530

Topological order for result types feel weird :) This is in order to create valid computation structure so that inferred types can be functions of other inferred types correct?

2526

Document convention used here (I think it is just sentinel or known)

Mogball marked 3 inline comments as done.Jan 8 2023, 8:12 PM
Mogball added inline comments.
mlir/lib/TableGen/Operator.cpp
436

If the op has variadic results, type inference is not generated (this is checked at the start of the function). It's not generally valid to have TypesMatchWith or AllTypesMatch mix variadic and non-variadic types anyways, so I didn't bother checking that.

509

This is an llvm::make_early_inc_range except I still need the iterator object itself to call std::list::erase.

mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
2525–2530

Yes. I'll clarify what this means: topological wrt the type inference (directed acyclic) graph.

Mogball marked 3 inline comments as done.Jan 8 2023, 8:14 PM

This is so great Jeff, thank you for driving this forward, I love the boilerplate destruction!

rriddle added inline comments.Jan 9 2023, 8:47 AM
mlir/lib/TableGen/Operator.cpp
436

Why not? CallIndirectOp is an easy example of when this happens.

453

Missing continue; after this?

Mogball marked an inline comment as done.Jan 9 2023, 8:49 AM
Mogball added inline comments.
mlir/lib/TableGen/Operator.cpp
436

This is a pre-existing restriction. I can make another pass and see if I can add variadic result support.

Mogball updated this revision to Diff 487618.Jan 9 2023, 5:42 PM
Mogball marked 7 inline comments as done.

review comments

Mogball updated this revision to Diff 487827.Jan 10 2023, 8:58 AM

fix build

rriddle accepted this revision.Jan 12 2023, 10:47 AM
rriddle added inline comments.
mlir/include/mlir/TableGen/Operator.h
49

Can you document this? This is referring to the index we use to transform right?

This revision is now accepted and ready to land.Jan 12 2023, 10:47 AM
lattner accepted this revision.Jan 12 2023, 11:52 AM
Mogball marked an inline comment as done.Jan 12 2023, 1:18 PM
Mogball added inline comments.
mlir/include/mlir/TableGen/Operator.h
49

Yes. I'll add a doc

Mogball updated this revision to Diff 488754.Jan 12 2023, 1:26 PM
Mogball marked an inline comment as done.

rebase+review comments

This revision was landed with ongoing or failed builds.Jan 12 2023, 1:26 PM
This revision was automatically updated to reflect the committed changes.