This patch adds a StatsFile option to LTO/Config.h and updates both
LLVMGold and llvm-lto2 to set it.
Details
Diff Detail
Event Timeline
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).
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.
tools/gold/gold-plugin.cpp | ||
---|---|---|
206 | document | |
1057 | 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... |
document