This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Add a DialectAsmParser::getChecked method
ClosedPublic

Authored by rriddle on Mar 3 2021, 5:58 PM.

Details

Summary

This function simplifies calling the getChecked methods on Attributes and Types from within the parser, and removes any need to use getEncodedSourceLocation for these methods (by using an SMLoc instead). This is much more efficient than using an mlir::Location, as the encoding process to produce an mlir::Location is inefficient and undesirable for parsing (locations used during parsing should not persist afterwards unless otherwise necessary).

Diff Detail

Event Timeline

rriddle created this revision.Mar 3 2021, 5:58 PM
rriddle requested review of this revision.Mar 3 2021, 5:58 PM
jpienaar added inline comments.Mar 3 2021, 9:10 PM
mlir/include/mlir/IR/DialectImplementation.h
175

SMLoc is a very specific to textual IR format parsing (debug/test format) part of the world. Does it make as much sense in IR? Is there an alternative where Location is cheap to create from SMLoc for just these parsing cases where we know the context outlives the potential use? (Alternatively this as a helper method in utils that just makes the getChecked inside smaller to write at call site?). SMLoc just feels a bit weird here.

rriddle added inline comments.Mar 3 2021, 9:17 PM
mlir/include/mlir/IR/DialectImplementation.h
175

I'm not sure what you are getting at. This is the parser for attributes and types, this almost exclusively uses llvm::SMLoc. I don't see any other location format being useful here, this class is only used for textual IR format parsing.

jpienaar accepted this revision.Mar 4 2021, 5:24 AM

Nice improvement, thanks

mlir/include/mlir/IR/DialectImplementation.h
175

Yeah I was in wrong file "in my mind" switching tabs and I just looked at the snippets.

This revision is now accepted and ready to land.Mar 4 2021, 5:24 AM
This revision was landed with ongoing or failed builds.Mar 4 2021, 12:00 PM
This revision was automatically updated to reflect the committed changes.