This is an archive of the discontinued LLVM Phabricator instance.

[Remarks] Add parser for bitstream remarks
ClosedPublic

Authored by thegameg on Sep 3 2019, 4:20 PM.

Details

Summary

The bitstream remark serializer landed in r367372.

This adds a bitstream remark parser that parser bitstream remark files to llvm::remarks::Remark objects through the llvm::remarks::RemarkParser interface.

A few interesting things to point out:

  • There are parsing helpers to parse the different types of blocks
  • The main parsing helper allows us to parse remark metadata and open an external file containing the encoded remarks
  • This adds a dependency from the Remarks library to the BitstreamReader library
  • The testing strategy is to create a remark entry through YAML, parse it, serialize it to bitstream, parse that back and compare the objects.
  • There are close to no tests for malformed bitstream remarks, due to the lack of textual format for the bitstream format.
  • This adds a new C API for parsing bitstream remarks: LLVMRemarkParserCreateBitstream.
  • This bumps the REMARKS_API_VERSION to 1.

Diff Detail

Event Timeline

thegameg created this revision.Sep 3 2019, 4:20 PM
Herald added a project: Restricted Project. · View Herald Transcript
JDevlieghere accepted this revision.Sep 4 2019, 9:47 AM

I really like your code style, useful comments, good abstractions, and great error handling. This was fun to review. A few things inline but overall this LGTM!

llvm/lib/Remarks/BitstreamRemarkParser.cpp
44

Looks like this comment needs to move down one line or Blob should be declared after the SmallVector?

91

Same as previous comment.

194

Is this actually reachable?

510

It's a little unfortunate that this pattern is repeated here but I don't have a good alternative. I considered suggesting putting it behind a macro, but given that there's only three instances that might be overkill and actually hurt readability.

llvm/lib/Remarks/BitstreamRemarkParser.h
67

I think these helpers could be private? Doing so would help convey what's part of the interface and what's not. The same applies to the other structs.

This revision is now accepted and ready to land.Sep 4 2019, 9:47 AM
thegameg updated this revision to Diff 218780.Sep 4 2019, 1:25 PM
thegameg marked 6 inline comments as done.

Address Jonas' comments. Thanks for the review!

llvm/lib/Remarks/BitstreamRemarkParser.cpp
194

I was imagining the case where we have something like a bunch of record entries followed by an end of file with no END_BLOCK. After the last successfully parsed record, we continue, then the loop condition is false, and we end up with an unterminated block because the stream is at the end, so we need to report an error.

510

I agree, I thought of a macro but I came to the same conclusion as you.

This revision was automatically updated to reflect the committed changes.