This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add default property bytecode read and write implementation
ClosedPublic

Authored by zero9178 on Jul 14 2023, 5:04 AM.

Details

Summary

Using properties currently requires at the very least implementing four methods/code snippets:

  • convertToAttribute
  • convertFromAttribute
  • writeToMlirBytecode
  • readFromMlirBytecode

This makes replacing attributes with properties harder than it has to be: Attributes by default do not require immediately defining custom bytecode encoding.

This patch therefore adds opt-in implementations of writeToMlirBytecode and readFromMlirBytecode that work with the default implementations of convertToAttribute and convertFromAttribute. They are provided by defvars in OpBase.td and can be used by adding:

let writeToMlirBytecode = writeMlirBytecodeWithConvertToAttribute;
let readFromMlirBytecode = readMlirBytecodeUsingConvertFromAttribute;

to ones TableGen definition.

While this bytecode encoding is almost certainly not ideal for a given property, it allows more incremental use of properties and getting something sane working before optimizing the bytecode format.

Diff Detail

Event Timeline

zero9178 created this revision.Jul 14 2023, 5:04 AM
zero9178 requested review of this revision.Jul 14 2023, 5:04 AM

This makes it too easy to be "misused": that is people will think they have support for properties without knowing they don't have bytecode support: can we do something better here?
Right now the idea was that it's under control of the user by defining their ODS subclass of Property to override writeToMlirBytecode / readFromMlirBytecode, where they can call the attribute conversion if they like.

This makes it too easy to be "misused": that is people will think they have support for properties without knowing they don't have bytecode support: can we do something better here?
Right now the idea was that it's under control of the user by defining their ODS subclass of Property to override writeToMlirBytecode / readFromMlirBytecode, where they can call the attribute conversion if they like.

I see where you're coming from but I disagree with the wording. People do have support for bytecode here in the sense that it makes it possible to serialize their properties to and from bytecode. The experience is essentially the same as with attributes without a corresponding BytecodeDialectInterface implementation in that it'll just work. The "misuse" is simply that the encoding is suboptimal in size and speed.

This patch does also not take away the choice from the user, it just tries to be a more comfortable default.

I suppose an alternative to the above would be to have a defvar with the default so that users can manually say let writeToMlirBytecode = useConvertToAttribute; for example.

I suppose an alternative to the above would be to have a defvar with the default so that users can manually say let writeToMlirBytecode = useConvertToAttribute; for example.

Right, I'd rather see this I think.

zero9178 updated this revision to Diff 542658.Jul 20 2023, 1:55 PM
zero9178 edited the summary of this revision. (Show Details)

Make the new default opt-in and an almost pure TableGen implementation.
This new implementation has the only disadvantage compared to the previous one in that it only works with the default implementations of convertToAttribute and convertFromAttribute.

mehdi_amini accepted this revision.Jul 20 2023, 5:08 PM
This revision is now accepted and ready to land.Jul 20 2023, 5:08 PM