This is an archive of the discontinued LLVM Phabricator instance.

[LTO][WPD] Ignore unreachable function by analyzing IR.
ClosedPublic

Authored by mingmingl on Dec 20 2021, 2:25 PM.

Details

Summary

In regular LTO, analyze IR and discard unreachable functions when finding virtual call targets.

Diff Detail

Event Timeline

mingmingl created this revision.Dec 20 2021, 2:25 PM
mingmingl updated this revision to Diff 395525.Dec 20 2021, 2:27 PM

Combine if into &&.

mingmingl updated this revision to Diff 395526.Dec 20 2021, 2:31 PM

Resolve a compile error.

mingmingl published this revision for review.Dec 20 2021, 3:03 PM
mingmingl added a reviewer: tejohnson.
Herald added a project: Restricted Project. · View Herald TranscriptDec 20 2021, 3:04 PM
tejohnson added inline comments.Dec 20 2021, 3:28 PM
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1051–1052

Since you are adding the IR check above, thinking that to optimize for compile time this lookup should be ignored if we have the def of Fn available (avoids an extra hash table lookup and analysis).

mingmingl updated this revision to Diff 395547.Dec 20 2021, 4:55 PM

Save one index lookup if function def is present for IR analysis. Also simplify test case.

mingmingl marked an inline comment as done.Dec 20 2021, 4:57 PM

thanks for review!

I simplify the test case here, and could do the same for the previous two test cases either here or in a separate patch.

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1051–1052

Done by "first analyze function def in IR if that's present, and use export summary as a fallback".

I took the liberty to add a comment like [1]; I'm wondering what's the idiomatic way to provide pointer a line of code w/ commit for reference?

[1]

// FWIW, the writer of `ExportSummary` guarantees that function declarations
  // won't have an entry in `ExportSummary`;
  // see llvm/lib/Analysis/ModuleSummaryAnalysis.cpp#L785 at commit cf9e61a for
  // a reference.
mingmingl updated this revision to Diff 395574.Dec 20 2021, 7:14 PM
mingmingl marked an inline comment as done.

remove No newline at end of file by using a different editor

tejohnson accepted this revision.Dec 21 2021, 6:28 AM

lgtm

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1051–1052

That's a good question on code reference. Usually I see references to the file or function granularity, not this specific. However, I don't think it is really needed here. Note on that below.

2110

I don't think this comment is really relevant here. Note you are coming into this part of the handling specifically when we *do* have a function declaration in this module, so it is a little confusing to explain why we don't create a summary for them. The reason why we may have a summary for what is a function decl in this combined regular LTO module is that we have the combined summaries of all of the ThinLTO modules, and the def is in one of those. So I would just keep the first sentence of this comment block ("Learn unreachability from ...").

This revision is now accepted and ready to land.Dec 21 2021, 6:28 AM
mingmingl updated this revision to Diff 395707.Dec 21 2021, 9:35 AM
mingmingl marked 2 inline comments as done.

Remove comments on function declarations, as a combined index may contain entries for func declarations.

thanks!

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1051–1052

Got it, thanks for the inputs!

2110

The reason why we may have a summary for what is a function decl in this combined regular LTO module is that we have the combined summaries of all of the ThinLTO modules, and the def is in one of those.

I will keep this in mind, thanks for pointing it out!

Removed the comment for function declaration.

This revision was landed with ongoing or failed builds.Dec 21 2021, 10:15 AM
This revision was automatically updated to reflect the committed changes.