This is an archive of the discontinued LLVM Phabricator instance.

[mlir:Bytecode][NFC] Refactor string section writing and reading
ClosedPublic

Authored by rriddle on Aug 23 2022, 1:34 PM.

Details

Summary

This extracts the string section writer and reader into dedicated
classes, which better separates the logic and will also simplify future
patches that want to interact with the string section.

Diff Detail

Event Timeline

rriddle created this revision.Aug 23 2022, 1:34 PM
rriddle requested review of this revision.Aug 23 2022, 1:34 PM
mehdi_amini added inline comments.Aug 23 2022, 1:57 PM
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
295

Shall we check on load that there is no null char in the middle of the string?

302

Do you need totalStringDataSize? Isn't the same check if stringDataEndOffset == 0?

mlir/lib/Bytecode/Writer/BytecodeWriter.cpp
232

Still an opportunity to sort the string based on frequency, right? :)

mehdi_amini accepted this revision.Aug 23 2022, 1:57 PM
This revision is now accepted and ready to land.Aug 23 2022, 1:57 PM
rriddle marked 2 inline comments as done.Aug 23 2022, 3:27 PM
rriddle added inline comments.
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
295

StringAttr supports strings with null characters, so I've just been allowing null holding strings in the string section (to simplify things). It doesn't affect loading at all given we don't use the null character for size computation. Do you think we should disallow that here?

mlir/lib/Bytecode/Writer/BytecodeWriter.cpp
232

Yeah. I've got a TODO for that in the followup Attr/Type patch as well, it should just require a bit of preprocessing (with no format changes). It wasn't clear in the beginning how annoying it would be to support, but after attr/type support I don't think it'll be too bad.

rriddle updated this revision to Diff 455009.Aug 23 2022, 4:30 PM
rriddle marked an inline comment as done.
This revision was landed with ongoing or failed builds.Aug 23 2022, 4:56 PM
This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.Aug 24 2022, 1:45 AM
mlir/lib/Bytecode/Reader/BytecodeReader.cpp
295

Not necessarily, but I remember some doc on the bytecode that was explicit about null-terminated string which excluded null char?