This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add $_op hook to RewriterGen.
AbandonedPublic

Authored by lucyrfox on Jan 31 2020, 4:20 PM.

Details

Summary

The $_op hook makes it possible to access information about the current operation in a TableGen pattern. This is already implemented in OpDefinitionsGen; this change adds it to RewriterGen as well.

This is needed for a lowering in the TF dialect.

Diff Detail

Event Timeline

lucyrfox created this revision.Jan 31 2020, 4:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 31 2020, 4:20 PM

Unit tests: unknown.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

rriddle retitled this revision from Add $_op hook to RewriterGen. to [mlir] Add $_op hook to RewriterGen..Jan 31 2020, 5:02 PM

Can you expand on the commit description of what is this about / why are you doing this?

(also is this something that a test can be written for?)

lucyrfox updated this revision to Diff 242192.EditedFeb 3 2020, 2:26 PM

Added tests.

lucyrfox edited the summary of this revision. (Show Details)Feb 3 2020, 2:27 PM

Unit tests: pass. 62430 tests passed, 0 failed and 845 were skipped.

clang-tidy: pass.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

Pre-merge checks is in beta. Report issue. Please join beta or enable it for your project.

antiagainst added inline comments.Feb 4 2020, 7:26 AM
mlir/test/lib/TestDialect/TestOps.td
608

I think this is misleading at least, if not problematic. The current way to support this is that we capture both the op's result and its operands and then pass them in as positional parameters so CheckResultCount can be written as

def CheckResultCount : Constraint<CPred<"$0.getOperation()->getNumResults() == $1.getInt()">>;

and used as

[(CheckResultCount $op, $result_count)]

One thing to note that we can have multiple source ops matched (as the source pattern can match a DAG of ops) so it's unclear which matchec op $_op will point to, so it's misleading at least. I think the above explicitly capturing is a better way to handle this case.

lucyrfox abandoned this revision.Feb 4 2020, 11:30 AM
lucyrfox marked an inline comment as done.
lucyrfox added inline comments.
mlir/test/lib/TestDialect/TestOps.td
608

Thanks for the reply, Lei.

$0.getOperation() doesn't compile -- $0, or $op, is an OpResult -- but CheckResultCount can be written as:

def CheckResultCount : Constraint<CPred<"$0.getOwner()->getNumResults() == $1.getInt()">>;

This works for the use case I have in the TF dialect as well. --> I'll abandon this change as the $_op hook is not necessary.

lucyrfox marked an inline comment as done.Feb 19 2020, 11:16 AM