This is an archive of the discontinued LLVM Phabricator instance.

[llvm][StringExtras] Add a fail-able version of `fromHex`
ClosedPublic

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

Details

Summary

This revision adds a fail-able/checked version of fromHex that fails when the input string contains a non-hex character. This removes the need for users to have a separate check for if the string contains all hex digits. This becomes very costly for large hex strings given that checking if a string contains only hex digits is effectively the same as just converting it in the first place.

Context: In MLIR we use hex strings to represent very large constants in the textual format of the IR. These changes lead to a large decrease in compile time when parsing these constants (2 seconds -> ~1 second).

Diff Detail

Event Timeline

rriddle created this revision.Oct 27 2020, 2:17 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 27 2020, 2:17 PM
rriddle requested review of this revision.Oct 27 2020, 2:17 PM

This LGTM, added some other reviewers for "added entropy" purpose if possible.

llvm/include/llvm/ADT/StringExtras.h
168–172

Can you document the API?

phosek accepted this revision.Oct 27 2020, 9:48 PM
phosek added inline comments.
llvm/include/llvm/ADT/StringExtras.h
180–182

Nit: Can you leave an empty line between functions?

This revision is now accepted and ready to land.Oct 27 2020, 9:48 PM
dexonsmith accepted this revision.Oct 28 2020, 8:49 AM
dexonsmith added inline comments.
llvm/include/llvm/ADT/StringExtras.h
73–104

Can this change be separated out and committed first? It doesn't seem tightly entangled to me...

dblaikie added inline comments.Oct 28 2020, 10:43 AM
llvm/include/llvm/ADT/StringExtras.h
73–104

+1 for this being a separate NFC/perf-only change (would be good to have some perf measurements to support the change too)

rriddle updated this revision to Diff 301333.Oct 28 2020, 10:49 AM
rriddle marked 2 inline comments as done.

Resolve comments

rriddle marked 2 inline comments as done.Oct 28 2020, 10:51 AM
rriddle added inline comments.
llvm/include/llvm/ADT/StringExtras.h
73–104

Done, thanks! Split out to https://reviews.llvm.org/D90320.

rriddle retitled this revision from [llvm][StringExtras] Add a fail-able version of `fromHex` and optimize hex digit lookup to [llvm][StringExtras] Add a fail-able version of `fromHex`.Oct 28 2020, 10:51 AM
rriddle edited the summary of this revision. (Show Details)
rriddle marked an inline comment as done.Oct 28 2020, 4:57 PM
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.