This is an archive of the discontinued LLVM Phabricator instance.

[LTO][ThinLTO] Use the linker resolutions to mark global values as dso_local.
ClosedPublic

Authored by sfertile on Jul 20 2017, 2:20 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

sfertile created this revision.Jul 20 2017, 2:20 PM
mehdi_amini edited edge metadata.Jul 20 2017, 10:05 PM

Thanks, I'm glad to see this coming!

lib/LTO/LTO.cpp
729

This does not seem safe in face of hash collision.

lib/Transforms/Utils/FunctionImportUtils.cpp
213

You have a null check here, while the same iteration in LTO.cpp does not bother. I think we should be able to skip the null check by construction.

215

This loop is:

bool gv_is_dso_local = llvm::any_of(VI.getSummaryList(), [} (const std::unique_ptr<GlobalValueSummary> &Summary) { return Summary->isDSOLocal(); });
if (gv_is_dso_local) 
  GV.setDSOLocal(true);
223

I was trying to figure out if your code handles declarations as well, and it seems so.
But interestingly it means that we do the following for declarations as well, I'm not sure it is totally relevant: @tejohnson WDYT? (this is tangential to this review)

grandinj added inline comments.
include/llvm/IR/ModuleSummaryIndex.h
152

whithin -> within

inouehrs added inline comments.Jul 21 2017, 6:13 AM
lib/Bitcode/Reader/BitcodeReader.cpp
892–894

Do we need some version check (and some comments) for compatibility with old bc files?

mehdi_amini added inline comments.Jul 21 2017, 9:08 PM
lib/Bitcode/Reader/BitcodeReader.cpp
892–894

The default will be 0 for old .bc files, which translate to "not local", which should be conservatively OK I believe?

Ideally we would checking a bitcode file from the 5.0 branching point in the repo and test this behavior.

sfertile updated this revision to Diff 108159.Jul 25 2017, 5:49 PM

Fixed spelling in comment.
Updated the look-up when marking summary as local to be limited to the bitcode module being added.
Changed for loop to llvm::any_of.

sfertile marked 3 inline comments as done.Jul 25 2017, 6:36 PM
sfertile added inline comments.
lib/Bitcode/Reader/BitcodeReader.cpp
892–894

That was my reasoning for not needing a version check.
I'll add the bitcode test from the 5.0 branch next update.

lib/LTO/LTO.cpp
723

I realize that this is the same GUID as calculated above since the call to getGlobalIdentifier is being passed ExternalLinkage. I'll update this to reflect that.

729

I've limited the summary look-up to the bitcode module we are currently adding, is this what you had in mind?

sfertile updated this revision to Diff 110472.Aug 9 2017, 1:54 PM

re-based, removed accidentally added white space in one of the tests and used the existing GUID in addThinLTO summary look-up.

sfertile updated this revision to Diff 110870.Aug 13 2017, 6:26 AM

rebased to top of trunk

sfertile updated this revision to Diff 112654.Aug 24 2017, 8:29 PM

Added a bitcode compatibility test.

sfertile updated this revision to Diff 120907.Oct 30 2017, 3:48 PM
sfertile marked 6 inline comments as done.

Rebased to top of trunk. The patch this one is dependent on is now committed as well,

sfertile updated this revision to Diff 120934.Oct 30 2017, 9:17 PM

Previous diff was missing updates to one of the tests.

pcc added inline comments.Nov 2 2017, 11:21 AM
lib/Transforms/Utils/FunctionImportUtils.cpp
215

I think you need to check that all summaries are dso-local to protect against hash collisions here.

sfertile updated this revision to Diff 121430.Nov 2 2017, 7:58 PM

Changed the importing to check that every summary is local before marking a GlobalValue as local.

sfertile marked an inline comment as done.Nov 2 2017, 7:59 PM
sfertile added inline comments.
lib/Transforms/Utils/FunctionImportUtils.cpp
215

Good point. Updated.

pcc accepted this revision.Nov 3 2017, 12:53 PM

LGTM

This revision is now accepted and ready to land.Nov 3 2017, 12:53 PM
This revision was automatically updated to reflect the committed changes.
sfertile marked an inline comment as done.