This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Add option to generate optimization records
ClosedPublic

Authored by anemet on Nov 17 2016, 9:19 PM.

Details

Summary

It is used to drive this from the clang driver via -mllvm.

Same option name is used as in opt.

Diff Detail

Repository
rL LLVM

Event Timeline

anemet updated this revision to Diff 78463.Nov 17 2016, 9:19 PM
anemet retitled this revision from to [LTO] Add option to generate optimization records.
anemet updated this object.
anemet added reviewers: hfinkel, mehdi_amini.
anemet added a subscriber: llvm-commits.
davide added inline comments.
lib/LTO/LTOCodeGenerator.cpp
96–100 ↗(On Diff #78463)

Side note, I very much dislike adding other cl::opt in library code, but this is what we have now. If I recall correctly, @beanz has plans for moving away of them, but not sure how far away it is.
If you use the new lib/LTO interface maybe you will be able to get rid of it (but you should use llvm-lto2 to test.

521–523 ↗(On Diff #78463)

have you already diagnosed why?

570–571 ↗(On Diff #78463)

nit, typo: Optimiation

anemet marked an inline comment as done.Nov 17 2016, 9:43 PM
anemet added inline comments.
lib/LTO/LTOCodeGenerator.cpp
96–100 ↗(On Diff #78463)

Does the Darwin linker support the new interface?

521–523 ↗(On Diff #78463)

I *think* that's a known bug in our linker. Mehdi can correct me if I am wrong.

davide accepted this revision.Nov 17 2016, 10:25 PM
davide added a reviewer: davide.

LGTM with the remaining comment fixed but please wait for a second opinion.

lib/LTO/LTOCodeGenerator.cpp
96–100 ↗(On Diff #78463)

I don't know about ld64 (and I don't think you're talking about lld as it doesn't do LTO on Mach-O).
So, unfortunately, it seems that cl::opt is the only viable option.

521–523 ↗(On Diff #78463)

Fair enough.

This revision is now accepted and ready to land.Nov 17 2016, 10:25 PM
mehdi_amini added inline comments.Nov 17 2016, 10:30 PM
lib/LTO/LTOCodeGenerator.cpp
96–100 ↗(On Diff #78463)

In general it is not OK to use cl::opt for "user interface" or "api option" in library.
However I don't believe there is any other option here, and as long as it is contained in the LTOCodeGenerator that's fine: cl::opt is the way to initialize it on Darwin.
That said I think we should contain them in lto.cpp and expose APIs in LTOCodeGenerator.
We added two in LTOCodegenerator already, but that wasn't the right thing to do.

519 ↗(On Diff #78463)

s/Optimiation/Optimization/

521–523 ↗(On Diff #78463)

This is similarly to clang that does not destroy the context in production, the Darwin linker does not clear any state before exiting.

mehdi_amini accepted this revision.Nov 18 2016, 9:25 AM
mehdi_amini edited edge metadata.
This revision was automatically updated to reflect the committed changes.
mehdi_amini added inline comments.Nov 18 2016, 10:10 PM
llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
570

Actually there is an issue with this code: the backend can also emit remarks, but they may not be in the file, or the file be truncated because you flushed early but not after the backend it complete.

anemet added inline comments.Nov 21 2016, 10:34 PM
llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
570

So I guess we need to call this in compileOptimized. I'll take a look after the Thanksgiving break.

anemet added inline comments.Nov 21 2016, 10:36 PM
llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
570

(For the record, there are no remarks emitted during codegen right now but that should hopefully change soon.)

mehdi_amini added inline comments.Nov 21 2016, 10:36 PM
llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
570

Yes I think so. It seems that llvm::PrintStatistics(); is already handled here, this seems somehow the same concept.

For the record, this option was renamed to -lto-pass-remarks-output (r287627, r287628) because it broke LLVM_LINK_LLVM_DYLIB due to duplicate option name with opt.

anemet added inline comments.Nov 28 2016, 9:02 AM
llvm/trunk/lib/LTO/LTOCodeGenerator.cpp
570

Committed this in r288041.