This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Support for specifying function index from pass manager
ClosedPublic

Authored by tejohnson on Nov 26 2015, 7:15 AM.

Details

Summary

Add a field on the PassManagerBuilder that clang or gold can use to pass
down the function index file to use for importing when the ThinLTO
backend is triggered. Add support to supply this to the function import
pass.

Also add support to the Linker::LinkModules interface used by clang
for passing down the index so that exported local values can be
promoted and renamed early.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson updated this revision to Diff 41250.Nov 26 2015, 7:15 AM
tejohnson retitled this revision from to [ThinLTO] Support for specifying function index from pass manager.
tejohnson updated this object.
tejohnson added reviewers: mehdi_amini, dexonsmith.
tejohnson added subscribers: llvm-commits, davidxl.
mehdi_amini added inline comments.Nov 26 2015, 9:58 AM
include/llvm/Transforms/IPO.h
88 ↗(On Diff #41250)

Document.

include/llvm/Transforms/IPO/PassManagerBuilder.h
120 ↗(On Diff #41250)

Could we pass and store here directly the FunctionIndex in memory instead of a path to the file?
I can imagine some use cases where we have it in memory and want to construct the pass pipeline (ld64 plugin for instance), and the interface shouldn't force to dump to disk.

lib/Transforms/IPO/FunctionImport.cpp
243 ↗(On Diff #41250)

Storing a string ref is error prone: the client needs to keep it alive. I'd rather store a std::string (and have all the prototype createFunctionImportPass(std::string))

258 ↗(On Diff #41250)

This test+error is redundant with the one 3 lines below I think.

292 ↗(On Diff #41250)

It would be nice to keep the ability to create the pass without the IndexFile, so overload instead of replace here?

Thanks for the review, responses below.

include/llvm/Transforms/IPO/PassManagerBuilder.h
120 ↗(On Diff #41250)

Yes and this is related to a TODO I added to the companion clang patch D15025. Since we have to create a function index there (or from the gold-plugin or whatever linker is being used in the single machine version), I think we should stash the FunctionIndex on the dest Module. In that case we could use the existing index off the module if it is non-null, or the -summary-file if not. I will make that change.

lib/Transforms/IPO/FunctionImport.cpp
243 ↗(On Diff #41250)

Ok agreed. But will be moot with the above change to stash index on module.

258 ↗(On Diff #41250)

No, this is testing for when the user has supplied an index twice (via front-end and via -summary-file). The below error is for when the user has supplied neither. I.e. together they ensure the index must be specified exactly once.

292 ↗(On Diff #41250)

Or just make the parameter have a default of "" as in the FunctionImportPass constructor change I made. But this will be moot with my change to stash the index on the module.

tejohnson updated this revision to Diff 41540.Dec 1 2015, 11:25 AM
tejohnson marked an inline comment as done.
  • Address Mehdi's comments.
mehdi_amini added inline comments.Dec 1 2015, 6:08 PM
include/llvm/IR/Module.h
177 ↗(On Diff #41540)

It does not make sense to me conceptually: the FunctionIndex is not owned by a Module. It is a common data-structure for all Modules that we're dealing with.

lib/Transforms/IPO/FunctionImport.cpp
254 ↗(On Diff #41540)

This does not seem right to me: I don't understand how you don't do a double-free when deleting the Index.

tejohnson added inline comments.Dec 2 2015, 10:04 AM
include/llvm/IR/Module.h
177 ↗(On Diff #41540)

Ok, I had been thinking that this would be owned by the module we are importing into. But agree after thinking about the case you mentioned where there is one copy in memory in the linker, shared by all the backend threads.

Probably I should just pass the in-memory index directly in PassManagerBuilder. But the question is how to set this from clang (in D15025). The CodeGenOptions where I save the index file name doesn't seem like the right place, but perhaps I can save it on the CompilerInvocation object, and set it on the PassManagerBuilder from there. WDYT?

lib/Transforms/IPO/FunctionImport.cpp
254 ↗(On Diff #41540)

You're right, this should just be a pointer not a unique_ptr.

tejohnson added inline comments.Dec 3 2015, 12:11 PM
include/llvm/IR/Module.h
177 ↗(On Diff #41540)

In the new patch I will upload it is passed on the PassManagerBuilder. The FE doesn't need to stash it anywhere it turns out, it is straightforward to pass it down to where I needed it.

tejohnson updated this revision to Diff 41786.Dec 3 2015, 12:12 PM
  • Address more comments.
tejohnson updated this revision to Diff 41925.Dec 4 2015, 12:26 PM
  • Add new renameModuleForThinLTO helper, remove now unneeded LinkModules
  • Add new renameModuleForThinLTO helper, remove now unneeded LinkModules

arc truncated this - it should have said "remove now unneeded LinkModules change" (LinkModules is still there and needed in other contexts).

  • Add new renameModuleForThinLTO helper, remove now unneeded LinkModules

arc truncated this - it should have said "remove now unneeded LinkModules change" (LinkModules is still there and needed in other contexts).

mehdi_amini accepted this revision.Dec 4 2015, 12:33 PM
mehdi_amini edited edge metadata.

The renameModuleForThinLTO change seems to be separate from the rest of the patch? Commit separately.

lib/Transforms/IPO/FunctionImport.cpp
242 ↗(On Diff #41925)

Nit: /// *Optional* Function summary

This revision is now accepted and ready to land.Dec 4 2015, 12:33 PM
mehdi_amini requested changes to this revision.Dec 4 2015, 12:35 PM
mehdi_amini edited edge metadata.

The function index is owned by the PassManagerBuilder in this patch, which is not good: there is not guarantee it will outlive the PassManager. The PassManagerBuild should take a pointer and not own the FunctionIndex I think.

This revision now requires changes to proceed.Dec 4 2015, 12:35 PM
tejohnson updated this revision to Diff 41934.Dec 4 2015, 1:41 PM
tejohnson edited edge metadata.
  • Move ownership of FunctionInfoIndex out of PassManagerBuilder.
mehdi_amini accepted this revision.Dec 4 2015, 1:59 PM
mehdi_amini edited edge metadata.

LGTM, but commit the renameModuleForThinLTO() change separately.

This revision is now accepted and ready to land.Dec 4 2015, 1:59 PM
This revision was automatically updated to reflect the committed changes.