[PATCH] D45531: [GoldPlugin] Add support for -save-stats=obj.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 11 10:43:51 PDT 2018
fhahn created this revision.
fhahn added reviewers: MatzeB, tejohnson, espindola.
Herald added a subscriber: mehdi_amini.
This patch adds a -save-stats=obj plugin option, that writes
the collected stats to a output_name.stats file. The corresponding
Clang option is implemented in Clang's driver, so there is nothing we
can re-use unfortunately.
I am not sure what the best option is here. I basically want to get an
option to dump the stats collected during LTO to a file, so they are
included when collecting stats from the test-suite compiled with LTO.
This will also require a change to the test-suite to add this option to
the LDFLAGS.
This is a very naive approach, please let me know if you think there is
a better way to collect the stats for LTO.
https://reviews.llvm.org/D45531
Files:
tools/gold/gold-plugin.cpp
Index: tools/gold/gold-plugin.cpp
===================================================================
--- tools/gold/gold-plugin.cpp
+++ tools/gold/gold-plugin.cpp
@@ -199,6 +199,7 @@
static bool new_pass_manager = false;
// Debug new pass manager
static bool debug_pass_manager = false;
+ static bool save_stats_obj = false;
static void process_plugin_option(const char *opt_)
{
@@ -262,6 +263,8 @@
new_pass_manager = true;
} else if (opt == "debug-pass-manager") {
debug_pass_manager = true;
+ } else if (opt == "-save-stats=obj") {
+ save_stats_obj = true;
} else {
// Save this option to pass to the code generator.
// ParseCommandLineOptions() expects argv[0] to be program name. Lazily
@@ -1030,6 +1033,9 @@
if (unsigned NumOpts = options::extra.size())
cl::ParseCommandLineOptions(NumOpts, &options::extra[0]);
+ if (options::save_stats_obj)
+ llvm::EnableStatistics(false);
+
std::vector<std::pair<SmallString<128>, bool>> Files = runLTO();
if (options::TheOutputType == options::OT_DISABLE ||
@@ -1051,6 +1057,14 @@
set_extra_library_path(options::extra_library_path.c_str()) != LDPS_OK)
message(LDPL_FATAL, "Unable to set the extra library path.");
+ if (options::save_stats_obj) {
+ std::error_code EC;
+ raw_fd_ostream OS(output_name+".stats", EC, sys::fs::OpenFlags::F_None);
+ if (EC)
+ message(LDPL_FATAL, "Failed to write the stats file.");
+ else
+ llvm::PrintStatisticsJSON(OS);
+ }
return LDPS_OK;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45531.142045.patch
Type: text/x-patch
Size: 1549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180411/b3812808/attachment.bin>
More information about the llvm-commits
mailing list