[PATCH] D107645: [GlobalDCE] Prepare VFE for Swift vtables (handle relative pointers and non-nfunc entries)

Kuba (Brecka) Mracek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 6 07:22:22 PDT 2021


kubamracek created this revision.
kubamracek added reviewers: yln, manmanren.
kubamracek added a project: LLVM.
Herald added subscribers: ormris, hiraditya.
kubamracek requested review of this revision.

As part of codesize optimization work for Swift, we'd like to add Virtual Function Elimination to Swift, very similarly to how GlobalDCE supports C++ VFE. There are two distinct complications on Swift vtables that GlobalDCE needs to be able to handle, and this PR adds this support:

(1) Swift vtables contain "relative pointers" instead of direct pointer references. These are in the form of:

  @symbol = ... {
    i32 trunc (i64 sub (i64 ptrtoint (<type> @target to i64), i64 ptrtoint (... @symbol to i64)) to i32)
  }

The PR extends GlobalDCE's way of looking up a vtable offset into a dependency to be able to see through this expression and find the target symbol.

(2) Swift vtables contain references that are not virtual functions.

The PR extends GlobalDCE's logic that ignores vtable->vfunc dependencies to only apply when the vtable slot offset is present in one of the !type metadata attributes on the vtable.

See the added test for an example of both of these.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D107645

Files:
  llvm/lib/Analysis/TypeMetadataUtils.cpp
  llvm/lib/Transforms/IPO/GlobalDCE.cpp
  llvm/test/Transforms/GlobalDCE/virtual-functions-swift.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D107645.364788.patch
Type: text/x-patch
Size: 5140 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210806/7f74a136/attachment.bin>


More information about the llvm-commits mailing list