This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add refineReturnTypes to InferTypeOpInterface
ClosedPublic

Authored by jpienaar on Jul 16 2022, 10:18 PM.

Details

Summary

refineReturnType method shares the same parameters as inferReturnTypes but gets
passed in the return types of the op if known that can be used during
refinement passes or for more op specific error reporting. Currently the error reporting on failure is generic and doesn't allow for specializing the returned result based on failure, with this change what would previously have been a separate trait with specialized verification can just be handled as part of inferrence rather than duplicated.

refineReturnTypes behaves like inferReturnTypes if no result types are fed in,
while the current verification is recast as the default implementation for
refineReturnTypes with it calling inferReturnTypes (and so the default type
verification now goes through refine and allows for more op specific inference
mismatch errors).

Diff Detail

Event Timeline

jpienaar created this revision.Jul 16 2022, 10:18 PM
jpienaar requested review of this revision.Jul 16 2022, 10:18 PM

Can you add some context as to why?

mlir/include/mlir/Interfaces/InferTypeOpInterface.td
39

Behavior is the American spelling, so I'd say this is fine as-is.

50–51

?

We should already trim when generating the docs.

55

Can you reword this? Starting a sentence with Except feels a bit weird.

81–82

Can you add braces here? The body of the if covers quite a few lines.

mlir/test/lib/Dialect/Test/TestDialect.cpp
1131

What does this mean? Can you clarify?

jpienaar edited the summary of this revision. (Show Details)Jul 17 2022, 3:13 PM
jpienaar updated this revision to Diff 445356.Jul 17 2022, 3:27 PM
jpienaar marked 5 inline comments as done.

Clarified comments and reverted non-typo.

mlir/include/mlir/Interfaces/InferTypeOpInterface.td
50–51

The most used form in this file (all except 1) is with kwarg style comments lined up, so this is just staying consistent with the rest of the file.

Is this meant to be called in a pass?

mlir/include/mlir/Interfaces/InferTypeOpInterface.td
51

Can you provide a few more sentences on what the method is supposed to do and maybe provide an example?

jpienaar updated this revision to Diff 445536.Jul 18 2022, 9:26 AM

Expand description

Mogball accepted this revision.Jul 18 2022, 9:27 AM
This revision is now accepted and ready to land.Jul 18 2022, 9:27 AM

Is this meant to be called in a pass?

Yes I'd replace where one currently uses inferReturnTypes in TF's shape inference function with it (I'd probably actually do it in the peer shaped type components variant if I were to do it), but primary initial goal is during verification (e.g., removes need for hard coding SameOperandsAndResultType like). I considered switching the inferReturnTypes behavior, but felt weird calling in inferred still, but not out of scope :).

rriddle accepted this revision.Jul 18 2022, 1:28 PM

The failure looks real, can you check?

This revision was landed with ongoing or failed builds.Jul 18 2022, 10:19 PM
This revision was automatically updated to reflect the committed changes.