This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Use module hash instead of module ID for cache key
ClosedPublic

Authored by nikic on Jul 28 2023, 5:26 AM.

Details

Summary

This is a followup to D151165. Instead of using the module ID, use the module hash for sorting the import list. The module hash is what will actually be included in the hash.

This has the advantage of being independent of the module order, which is something that Rust relies on.

A caveat here is that the test doesn't quite work for linkonce_odr functions, because the function may be imported from two different modules, and the first one on the llvm-lto2 command line gets picked (rather than, say, the prevailing copy). This doesn't really matter for Rust's purposes (because it does not use linkonce_odr linkage), but may still be worth addressing. For now I'm using a variant of the test using internal instead of linkonce_odr functions.

Diff Detail

Event Timeline

nikic created this revision.Jul 28 2023, 5:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2023, 5:26 AM
nikic requested review of this revision.Jul 28 2023, 5:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 28 2023, 5:26 AM
nikic retitled this revision from [ThinLTO} Use module hash instead of module ID for cache key to [ThinLTO] Use module hash instead of module ID for cache key.Jul 28 2023, 5:27 AM

A caveat here is that this doesn't quite work for linkonce_odr functions, because it seems like the function from the first encountered module gets picked (rather than say, the prevailing function). This doesn't really matter for Rust's purposes (because it does not use linkonce_odr linkage), but may still be worth addressing. For now I'm using a variant of the test using internal instead of linkonce_odr functions.

Can you clarify what doesn't work with linkonce_odr? This patch shouldn't affect any importing decisions, which have already been made, so the import list sorted here should only include a single copy of a linkonce_odr function.

nikic added a comment.Jul 28 2023, 6:47 AM

A caveat here is that this doesn't quite work for linkonce_odr functions, because it seems like the function from the first encountered module gets picked (rather than say, the prevailing function). This doesn't really matter for Rust's purposes (because it does not use linkonce_odr linkage), but may still be worth addressing. For now I'm using a variant of the test using internal instead of linkonce_odr functions.

Can you clarify what doesn't work with linkonce_odr? This patch shouldn't affect any importing decisions, which have already been made, so the import list sorted here should only include a single copy of a linkonce_odr function.

What I'm seeing is that the linkonce_odr function will be imported from either a.bc or b.bc, depending on the order of llvm-lto2 arguments. The patch doesn't affect importing decisions, it's just that the test case doesn't work with linkonce_odr, because it ends up still being order-dependent.

tejohnson accepted this revision.Jul 28 2023, 7:24 AM

A caveat here is that this doesn't quite work for linkonce_odr functions, because it seems like the function from the first encountered module gets picked (rather than say, the prevailing function). This doesn't really matter for Rust's purposes (because it does not use linkonce_odr linkage), but may still be worth addressing. For now I'm using a variant of the test using internal instead of linkonce_odr functions.

Can you clarify what doesn't work with linkonce_odr? This patch shouldn't affect any importing decisions, which have already been made, so the import list sorted here should only include a single copy of a linkonce_odr function.

What I'm seeing is that the linkonce_odr function will be imported from either a.bc or b.bc, depending on the order of llvm-lto2 arguments. The patch doesn't affect importing decisions, it's just that the test case doesn't work with linkonce_odr, because it ends up still being order-dependent.

Ok thanks, can you change the wording in the summary to clarify that you are talking about the test, e.g. maybe replace "this" with "the test" in "A caveat here is that this doesn't quite work for linkonce_odr functions".

lgtm otherwise

This revision is now accepted and ready to land.Jul 28 2023, 7:24 AM
nikic edited the summary of this revision. (Show Details)Jul 28 2023, 7:27 AM
akyrtzi accepted this revision.Jul 28 2023, 7:32 AM