This is an archive of the discontinued LLVM Phabricator instance.

[mlir][IR] Refactor the `getChecked` and `verifyConstructionInvariants` methods on Attributes/Types
ClosedPublic

Authored by rriddle on Feb 19 2021, 4:39 PM.

Details

Summary

verifyConstructionInvariants is intended to allow for verifying the invariants of an attribute/type on construction, and getChecked is intended to enable more graceful error handling aside from an assert. There are a few problems with the current implementation of these methods:

  • verifyConstructionInvariants requires an mlir::Location for emitting errors, which is prohibitively costly in the situations that would most likely use them, e.g. the parser.

This creates an unfortunate code duplication between the verifier code and the parser code, given that the parser operates on llvm::SMLoc and it is an undesirable overhead to pre-emptively convert from that to an mlir::Location.

  • getChecked effectively requires duplicating the definition of the get method, creating a quite clunky workflow due to the subtle different in its signature.

This revision aims to talk the above problems by refactoring the implementation to use a callback for error emission. Using a callback allows for deferring the costly part of error emission until it is actually necessary.

Due to the necessary signature change in each instance of these methods, this revision also takes this opportunity to cleanup the definition of these methods by:

  • restructuring the signature of getChecked such that it can be generated from the same code block as the get method.
  • renaming verifyConstructionInvariants to verify to match the naming scheme of the rest of the compiler.

Diff Detail

Event Timeline

rriddle created this revision.Feb 19 2021, 4:39 PM
rriddle requested review of this revision.Feb 19 2021, 4:39 PM
mehdi_amini accepted this revision.Feb 19 2021, 4:49 PM

No change needed in flang?

This revision is now accepted and ready to land.Feb 19 2021, 4:49 PM
This revision was landed with ongoing or failed builds.Feb 22 2021, 5:38 PM
This revision was automatically updated to reflect the committed changes.

No change needed in flang?

Thanks, added flang change on commit.