This is an archive of the discontinued LLVM Phabricator instance.

[mlir][OpDefGen] Add support for generating local functions for shared utilities
ClosedPublic

Authored by rriddle on Nov 12 2020, 12:39 PM.

Details

Summary

This revision adds a new StaticVerifierFunctionEmitter class that emits local static functions in the .cpp file for shared operation verification. This class deduplicates shared operation verification code by emitting static functions alongside the op definitions. These methods are local to the definition file, and are invoked within the operation verify methods. The first bit of shared verification is for the type constraints used when verifying operands and results. An example is shown below:

static LogicalResult localVerify(...) {
  ...
}

LogicalResult OpA::verify(...) {
  if (failed(localVerify(...)))
    return failure();
  ...
}

LogicalResult OpB::verify(...) {
  if (failed(localVerify(...)))
    return failure();
  ...
}

This allowed for saving >400kb of code size from a downstream TensorFlow project (~15% of MLIR code size).

Diff Detail

Event Timeline

rriddle created this revision.Nov 12 2020, 12:39 PM
rriddle requested review of this revision.Nov 12 2020, 12:39 PM

Nice

mlir/include/mlir/TableGen/Constraint.h
56

Is this only needed to be able to unique? Would exposing a compare function suffice to not need this? (To avoid exposing TableGen types from these types)

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

I don't follow the name. It doesn't really capture what this is doing - meaning, you have to read the comment and a bit of the code.

What about StaticVerifierFunctionEmitter ? local & ODS specific don't carry a much for me

216

Is .str() needed given the assignment to string?

rriddle updated this revision to Diff 305883.Nov 17 2020, 12:41 PM
rriddle marked 3 inline comments as done.

Resolve comments

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

I originally considered emitting other things aside from verification, but it's good to leave that to when we actually need it. Changed to your suggestion.

216

Yep.

mehdi_amini accepted this revision.Nov 30 2020, 12:30 PM

I'd beef up the description to explain a bit more what this is doing.

This revision is now accepted and ready to land.Nov 30 2020, 12:30 PM
mehdi_amini added inline comments.Nov 30 2020, 12:31 PM
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
126

I think the description isn't super clear here either.

jpienaar accepted this revision.Dec 4 2020, 8:18 AM

LG post Mehdi's suggestions

rriddle edited the summary of this revision. (Show Details)Dec 14 2020, 1:49 PM
rriddle edited the summary of this revision. (Show Details)
rriddle updated this revision to Diff 311699.Dec 14 2020, 1:55 PM
rriddle edited the summary of this revision. (Show Details)

Update

rriddle marked an inline comment as done.Dec 14 2020, 1:55 PM
rriddle added inline comments.
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
126

Added an example, which should make things a bit more clear.

This revision was landed with ongoing or failed builds.Dec 14 2020, 2:22 PM
This revision was automatically updated to reflect the committed changes.
rriddle marked an inline comment as done.