This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Improve BitEnumAttr, update documentation
ClosedPublic

Authored by krzysz00 on Sep 6 2022, 1:27 PM.

Details

Summary
  • Add new operators to BitEnumAttr, mainly not (which only inverts

bits that can be valid bits for the attribute) and xor

  • Add new bit enum utility functions: bitEnumClear(bits, bit) and

bitEnumSet(bits, bit, value=true) as they've come up in code I've been
writing that makes use of such enums

  • Add rudimentary tests for the enum generator
  • Update the OpDefinition documentation to make it contain a correct

example and to have it account for the changes mentioned above.

Diff Detail

Event Timeline

krzysz00 created this revision.Sep 6 2022, 1:27 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 6 2022, 1:27 PM
krzysz00 requested review of this revision.Sep 6 2022, 1:27 PM
This revision is now accepted and ready to land.Sep 6 2022, 2:10 PM
This revision was automatically updated to reflect the committed changes.
hanchung added inline comments.
mlir/docs/OpDefinitions.md
1445–1447

The behavior of bitEnumContains changed. Is it intended?

antiagainst added inline comments.Sep 8 2022, 10:09 AM
mlir/docs/OpDefinitions.md
1445–1447

Good catch about the behavior change! Sorry I missed that.

I think we should not silently changing the behavior. I also see the benefits of supporting the "and" behavior. So maybe change this into two functions, bitEnumContainsAny and bitEnumContainsAll?

hanchung added inline comments.Sep 8 2022, 10:25 AM
mlir/docs/OpDefinitions.md
1445–1447

Yes, having two methods looks good. (and the naming is more clear to me!) I'll send out a patch.