This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Add optional import message and statistics
ClosedPublic

Authored by tejohnson on Mar 25 2016, 7:43 PM.

Details

Summary

Add a statistic to count the number of imported functions. Also, add a
new -print-imports option to emit a trace of imported functions, that
works even for an NDEBUG build.

Note that emitOptimizationRemark does not work for the above printing as
it expects a Function object and DebugLoc, neither of which we will have
particularly when we move to summary-based importing.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson updated this revision to Diff 51706.Mar 25 2016, 7:43 PM
tejohnson retitled this revision from to [ThinLTO] Add optional import message and statistics.
tejohnson updated this object.
tejohnson added a reviewer: mehdi_amini.
tejohnson added a subscriber: llvm-commits.
tejohnson updated this revision to Diff 51726.Mar 26 2016, 9:25 PM
tejohnson edited edge metadata.

Rebase on D18343/r264503.

Also, with r264503, aliases are now being added to the GlobalsToImport set even
when their aliasees can't be imported due to their linkage type. While the
importing worked correctly (the aliases imported as declarations) due to the
logic in FunctionImportGlobalProcessing::doImportAsDefinition, there is no
point to adding them to the GlobalsToImport set and it was resulting in
incorrectly printing a message indicating that the alias was imported.
To avoid this, delay adding aliases to the GlobalsToImport set until after
the linkage type of the aliasee is checked.

mehdi_amini accepted this revision.Mar 26 2016, 9:32 PM
mehdi_amini edited edge metadata.

LGTM, but please commit separately if possible: first the change about the aliases and then the changes related to the new debug.

This revision is now accepted and ready to land.Mar 26 2016, 9:32 PM
This revision was automatically updated to reflect the committed changes.
aganea added a subscriber: aganea.Mar 24 2020, 1:25 PM
aganea added inline comments.
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
359

Hello Teresa! This debug output is not thread-safe, but it is executed from ThinLTO threads. There's a test, llvm/test/Transforms/PGOProfile/Inputs/thinlto_samplepgo_icp3.ll which relies on this output. Currently that test only uses one thread (-thinlto-threads=1). However when using any other number of threads, the test randomly fails.
I wanted to test other values for -thinlto-threads in D75153, but I cannot. I'd like to land that patch, and would like your advice.

What avenue would you suggest? Add/use a mutex here? Remove the coverage for thinlto_samplepgo_icp3.ll in D75153?

tejohnson marked an inline comment as done.Mar 24 2020, 2:43 PM
tejohnson added inline comments.
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
359

I don't think it is a problem unique to this particular debugging output. Any ThinLTO test that uses a -debug or -debug-only to get messages from backend threads will hit it as well if there is more than one thread.

I'd probably either remove the changes from that test, or better, use something other than the -print-inputs flag to test that the importing happened. I.e. check the llvm-dis on the -save-temps .import.bc file.

Actually,. that test looks like it has an issue - there is a line to test with the "; ICALL-PROM:" prefix, which is not ever actually invoked. Presumably could be fixed by also checking the llvm-dis of the temp file.

aganea added inline comments.Mar 25 2020, 3:13 PM
llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
359

Just for the record, @tejohnson 's suggestion was implemented in rG934d4feab1f58ede295a3232ac47f3c01c9fc506.