This is an archive of the discontinued LLVM Phabricator instance.

Generating available_externally vtables for classes without inline virtual functions
ClosedPublic

Authored by Prazek on Jul 22 2015, 5:22 PM.

Details

Summary

Generating available_externally vtables for optimizations purposes. Unfortunatelly ItaniumABI doesn't guarantee that we will be able to refer to virtual inline method by name.
But when we don't have any inline virtual methods, and key function is not defined in this TU, we can generate vtable and mark it as available_externally.

This is patch will help devirtualize better, for more info go to http://lists.cs.uiuc.edu/pipermail/cfe-dev/2015-July/044246.html

Diff Detail

Repository
rL LLVM

Event Timeline

Prazek updated this revision to Diff 30431.Jul 22 2015, 5:22 PM
Prazek retitled this revision from to Generating available_externally vtables for classes without inline virtual functions.
Prazek updated this object.
Prazek added reviewers: rsmith, nlewycky, majnemer.
Prazek added a subscriber: cfe-commits.
majnemer added inline comments.Jul 22 2015, 5:35 PM
lib/CodeGen/CGVTables.cpp
706 ↗(On Diff #30431)

I'd suggest using OptimizationLevel > 0 instead.

829 ↗(On Diff #30431)

Please clang-format this.

lib/CodeGen/ItaniumCXXABI.cpp
311–319 ↗(On Diff #30431)

Local variables should start with a capital letter.

320 ↗(On Diff #30431)

Would we want to use getCanonicalDecl instead?

rsmith added inline comments.Jul 22 2015, 5:50 PM
lib/CodeGen/ItaniumCXXABI.cpp
309 ↗(On Diff #30431)

function have -> RD has

320 ↗(On Diff #30431)

That would give the wrong answer in some cases. The isInlined flag is monotonically increasing across the redeclaration chain (at least until we reach a definition, at which point it can't change any more), so checking it on the most recent declaration at end of TU gives the correct answer. The canonical declaration may lie to you.

1510–1511 ↗(On Diff #30431)

I think the OptimizationLevel check belongs in the caller, not here. (We can emit available_externally vtables even at -O0, we just usually don't want to do so.)

Prazek marked 3 inline comments as done.Jul 22 2015, 5:58 PM
Prazek added inline comments.
lib/CodeGen/CGVTables.cpp
829 ↗(On Diff #30431)

I was formatted by clang-format (tools/clang-format/git-clang-format).
It looks ugly to me, but I thought that this is what code style is here.

Prazek added inline comments.Jul 22 2015, 6:17 PM
lib/CodeGen/ItaniumCXXABI.cpp
1510–1511 ↗(On Diff #30431)

It will make code uglier(multiple check before every function call), but You are right

Prazek marked 2 inline comments as done.Jul 22 2015, 6:25 PM
Prazek marked 2 inline comments as done.Jul 22 2015, 6:25 PM
Prazek updated this revision to Diff 30438.Jul 22 2015, 6:39 PM
rjmccall edited edge metadata.Jul 22 2015, 6:40 PM

Mostly looks fine. One suggestion, though.

lib/CodeGen/CGVTables.cpp
831 ↗(On Diff #30431)

Please do your query second; in practice, many v-tables are not external, meaning that your check will not need to be run. Your check is actually pretty expensive when optimization is enabled because of the full walk scanning for inline functions.

Prazek marked an inline comment as done.Jul 22 2015, 6:42 PM
Prazek added inline comments.
lib/CodeGen/CGVTables.cpp
838 ↗(On Diff #30438)

Good point.

Prazek updated this revision to Diff 30440.Jul 22 2015, 6:58 PM
Prazek edited edge metadata.
Prazek marked an inline comment as done.
majnemer added inline comments.Jul 23 2015, 11:19 AM
lib/CodeGen/CGVTables.cpp
835 ↗(On Diff #30440)

Odd. clang-format puts the return on its own line.

rjmccall added inline comments.Jul 23 2015, 12:39 PM
lib/CodeGen/ItaniumCXXABI.cpp
1509 ↗(On Diff #30440)

Please move this FIXME down after the other comment. It doesn't apply to the logic about apple kexts, which is unconditional.

Prazek marked an inline comment as done.Jul 23 2015, 1:24 PM
Prazek updated this revision to Diff 30520.Jul 23 2015, 1:24 PM

Thanks, LGTM.

This revision was automatically updated to reflect the committed changes.