This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Optimize the parsing of ElementsAttr hex strings
ClosedPublic

Authored by rriddle on Oct 27 2020, 2:17 PM.

Details

Summary

This revision optimizes the parsing of hex strings by using the checked variant of llvm::fromHex, and adding a specialized method to Token for extracting hex strings. This leads a large decrease in compile time when parsing large hex constants (one example: 2.6 seconds -> 370 miliseconds)

Depends On D90265

Diff Detail

Event Timeline

rriddle created this revision.Oct 27 2020, 2:17 PM
rriddle requested review of this revision.Oct 27 2020, 2:17 PM
rdzhabarov accepted this revision.Oct 27 2020, 3:42 PM

Pretty cool improvement!

mlir/lib/Parser/AttributeParser.cpp
413

nit: can you fix typo "etring".

mlir/lib/Parser/Token.cpp
128

i see that we put comments in both .h and cpp files. It's a bit redundant, imo, but as far as i can tell it's used for all other methods.

do we stick to this convention?

This revision is now accepted and ready to land.Oct 27 2020, 3:42 PM
rdzhabarov added inline comments.Oct 27 2020, 3:54 PM
mlir/lib/Parser/Token.cpp
131

Is this to drop quotes from begin and end? (might be trivial, but i'm not too familiar with codebase).

135

nit: hex will be moved anyway, no need to make it explicit.

mehdi_amini added inline comments.Oct 27 2020, 4:04 PM
mlir/lib/Parser/Token.cpp
131

(Worth a comment I think)

135

I believe you actually need to be explicit here because the type of the returned value does not match the type of hex.

rriddle marked 2 inline comments as done.Oct 27 2020, 4:11 PM
rriddle added inline comments.
mlir/lib/Parser/Token.cpp
135

That is what I would have expected as well, but I checked with godbolt and clang/gcc seem to do the right thing with llvm::Optional.

rriddle updated this revision to Diff 301468.Oct 28 2020, 4:19 PM
rriddle marked 5 inline comments as done.

Resolve comments

mlir/lib/Parser/Token.cpp
128

i see that we put comments in both .h and cpp files. It's a bit redundant, imo, but as far as i can tell it's used for all other methods.

do we stick to this convention?

Generally, yeah. I don't do it if the declaration is already in the same file though(that is way to redundant for my taste).

This revision was landed with ongoing or failed builds.Oct 28 2020, 5:04 PM
This revision was automatically updated to reflect the committed changes.