This is an archive of the discontinued LLVM Phabricator instance.

[OpAsmParser] Refactor parseOptionalInteger to support wide integers, NFC.
ClosedPublic

Authored by lattner on May 8 2021, 6:46 PM.

Details

Summary

OpAsmParser (and DialectAsmParser) supports a pair of
parseInteger/parseOptionalInteger methods, which allow parsing a bare
integer into a C type of your choice (e.g. int8_t) using templates. It
was implemented in terms of a virtual method call that is hard coded to
int64_t because "that should be big enough".

Change the virtual method hook to return an APInt instead. This allows
asmparsers for custom ops to parse large integers if they want to, without
changing any of the clients of the fixed size C API.

Diff Detail

Event Timeline

lattner created this revision.May 8 2021, 6:46 PM
lattner requested review of this revision.May 8 2021, 6:46 PM

The usecase here is to improve the syntax of firrtl.constant in the CIRCT project. We need to parse a potentially large integer constant before knowing its MLIR type, so we can't use the existing parseAttribute hooks.

Is anyone available to take a look at this, or recommend an alternate reviewer? I don't think this is controversial in any way.

rriddle accepted this revision.May 10 2021, 10:28 PM

(currently OOO after covid shot)

mlir/include/mlir/IR/DialectImplementation.h
167

CHAR_BIT?

mlir/include/mlir/IR/OpImplementation.h
453

Same here.

This revision is now accepted and ready to land.May 10 2021, 10:28 PM
lattner updated this revision to Diff 344284.May 10 2021, 10:35 PM

Use CHAR_BIT instead of 8 as a magic number.

Great catch, fixed, thank you. Sorry for bugging you when you're recovering, I didn't know, I appreciate the review!

This revision was landed with ongoing or failed builds.May 10 2021, 10:47 PM
This revision was automatically updated to reflect the committed changes.