This is an archive of the discontinued LLVM Phabricator instance.

[LTO] Add stats-file option to LTO/Config.h.
ClosedPublic

Authored by fhahn on Apr 11 2018, 10:43 AM.

Details

Summary

This patch adds a StatsFile option to LTO/Config.h and updates both
LLVMGold and llvm-lto2 to set it.

Diff Detail

Repository
rL LLVM

Event Timeline

fhahn created this revision.Apr 11 2018, 10:43 AM

A few thoughts/suggestions:

It would be better to add the calls to EnableStatistics and PrintStatisticsJSON to the LTO library, specifically inside LTO::run in LTO.cpp, so that all LTO clients can get the support with just an lto::Config change. E.g. the llvm-lto2 tool, lld.

What about -save-stats=cwd? It seems that both "obj" and "cwd" should be supported. But better than that:

  • The -save-stats clang Driver option causes the -stats-file= cc1 option to be set. Better to support a -stats-file= option in gold-plugin and corresponding Config setting LTO, which is more generic than -save-stats.
  • Once that is done, you can automatically set the gold-plugin option when -save-stats is passed to the cc1 invocation, in tools::AddGoldPlugin in clang. That simplifies the user model, and the option you need to pass in your corresponding CMake change, which can just be -save-stats=cwd.

Needs a test (assuming it is added to the LTO code, add both a gold and an llvm-lto2 based test).

fhahn updated this revision to Diff 142937.Apr 18 2018, 7:58 AM
fhahn retitled this revision from [GoldPlugin] Add support for -save-stats=obj. to [LTO] Add stats-file option to LTO/Config.h..
fhahn edited the summary of this revision. (Show Details)

Thank you very much for your suggestions Teresa! I've updated the patch to handle a new StatsFile config option in LTO::run. And added stats-file support to LLVMgold.so and llvm-lto2. I will link the patch that updated AddGoldPlugin.

tejohnson added inline comments.Apr 19 2018, 8:07 AM
tools/gold/gold-plugin.cpp
206 ↗(On Diff #142937)

document

1057 ↗(On Diff #142937)

I think there is going to be a strange interaction with this code. I added this so that we still get the stats printed to stderr under the -stats llvm internal option when we exit early because we are only doing the ThinLTO indexing step (for distrubuted ThinLTO builds), since we don't execute ~StatisticInfo() in that case. The problem is that AreStatisticsEnabled() returns "Enabled || Stats", and Enabled will be true with this patch if the new stats-file plugin option is specified. So I think what would happen for distributed builds, when we exit early here, if the new plugin option is passed we will incorrectly dump stats to stderr as well.

Hmm, looks like we should probably just call llvm_shutdown() here before we exit, which would take care of destructing StatisticInfo. Let me try that and get back...

tejohnson accepted this revision.Apr 19 2018, 8:52 AM

LGTM but please wait until after D45820 goes in.

tools/gold/gold-plugin.cpp
1057 ↗(On Diff #142937)

Just mailed you D45820 that fixes this.

This revision is now accepted and ready to land.Apr 19 2018, 8:52 AM
fhahn updated this revision to Diff 143271.Apr 20 2018, 2:47 AM

Add comment to option in gold-plugin.cpp

This revision was automatically updated to reflect the committed changes.