This is an archive of the discontinued LLVM Phabricator instance.

Refactor bitcode writer into classes (NFC)
ClosedPublic

Authored by tejohnson on Apr 22 2016, 4:41 PM.

Details

Summary

As discussed in on the mailing list yesterday, I have refactored
BitcodeWriter.cpp to use classes to manage the bitcode writing process,
instead of passing around long lists of parameters between static
functions. See:

http://lists.llvm.org/pipermail/llvm-dev/2016-April/098610.html

I created a parent BitcodeWriter class to own the BitstreamWriter,
write the header, and contain the main entry point into the writing
process. There are two derived classes, one for writing a module and one
for writing a combined index file (for ThinLTO), which manage the
writing process specific to those bitcode file types.

I also changed the functions to conform to LLVM coding standards
(lowercase function name first letter). The only two routines that still
start with an uppercase letter are the two external interfaces, which
can be fixed as a follow-on (I wanted to keep this round just within
BitcodeWriter.cpp).

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson updated this revision to Diff 54750.Apr 22 2016, 4:41 PM
tejohnson retitled this revision from to Refactor bitcode writer into classes (NFC).
tejohnson updated this object.
tejohnson added reviewers: dexonsmith, mehdi_amini.
tejohnson added a subscriber: llvm-commits.
mehdi_amini accepted this revision.Apr 22 2016, 5:02 PM
mehdi_amini edited edge metadata.

Look quite straightforward to me (with some inline comments that don't require another round of review)

Makes me think that this file is quite big, should we split it in two and have the summary handling in a separate file?

lib/Bitcode/Writer/BitcodeWriter.cpp
66 ↗(On Diff #54750)

I'd say "Abstract classto manage the bitcode writing, subclassed for each bitcode file type."

71 ↗(On Diff #54750)

Use a reference is it non-optional and does not need to be rebound.

100 ↗(On Diff #54750)

May as well provide protected access to the Buffer member directly.
(if you prefer the method, use a verb i.e. getBuffer())

101 ↗(On Diff #54750)

Same.

109 ↗(On Diff #54750)

Same as before: reference is so much nicer when applicable :)

248 ↗(On Diff #54750)

it displays weirdly, but I assume you clang-formatted right?

266 ↗(On Diff #54750)

const ref?

3373 ↗(On Diff #54750)

Should we call writeIdentificationBlock() here as well? (not as part of this patch, just while I'm looking at it)

This revision is now accepted and ready to land.Apr 22 2016, 5:02 PM
In D19447#409790, @joker.eph wrote:

Look quite straightforward to me (with some inline comments that don't require another round of review)

Makes me think that this file is quite big, should we split it in two and have the summary handling in a separate file?

Yes, it does seem large. Unfortunately, the summary handling is relatively quite a bit smaller, so it would still leave a large file. Let me think about what would make sense.

lib/Bitcode/Writer/BitcodeWriter.cpp
66 ↗(On Diff #54750)

Will update.

71 ↗(On Diff #54750)

In other contexts I have seen the advice that const references should be avoided as class members because of dangers due to lifetime issues if a temporary were to be passed in to the constructor. It looks like this is fairly common practice in LLVM though. I will go ahead and change it since that seems to be the convention here.

100 ↗(On Diff #54750)

Yeah, this is what I had done originally, then I switched it to access via a method but it introduces a lot more change (especially for stream()). I will go ahead and change it back.

101 ↗(On Diff #54750)

Will do

109 ↗(On Diff #54750)

Ok

248 ↗(On Diff #54750)

Looks weird to me too. I did clang format, and in fact just tried putting the void writeFunction on the same line and clang-format put it back. It's because the DenseMap is so long.

266 ↗(On Diff #54750)

ok

3373 ↗(On Diff #54750)

Yes, I think that would be a good idea. Will add that in a follow-on.

mehdi_amini added inline comments.Apr 22 2016, 8:37 PM
lib/Bitcode/Writer/BitcodeWriter.cpp
71 ↗(On Diff #54750)

Interesting, nobody ever pointed me to this "con" of using a ref before.

tejohnson updated this revision to Diff 54764.Apr 22 2016, 9:05 PM
tejohnson edited edge metadata.
  • Address comments.
This revision was automatically updated to reflect the committed changes.