[llvm-dev] Proposal: virtual constant propagation

Hans Wennborg via llvm-dev llvm-dev at lists.llvm.org
Thu Jan 28 08:47:52 PST 2016


On Wed, Jan 27, 2016 at 7:57 PM, Peter Collingbourne <peter at pcc.me.uk> wrote:
> The pass that applies this transformation will be placed early in the LTO
> pipeline, before most of the regular optimization passes. The pass could later
> be extended to do general devirtualization based on the bitset information:
>
>  - The pass can implement single-deriver (i.e. only one derived class with a
>    non-pure virtual function definition) and single-implementation
>    (i.e. multiple derived classes all sharing a virtual function definition
>    from a base class) devirtualization by checking that each of the possible
>    values loaded from the vtables in the bitset are either identical or
>    __cxa_pure_virtual (calls to pure virtuals are UB, so we’d be fine
>    disregarding them), and propagating the identical address into the
>    function callee.

In addition to the constant value propagation, which looks fantastic,
I'm also very interested in this aspect.

For example, Blink/WebKit public interface is full of classes like
[0], which have a single implementation (sometimes there's also a mock
implementation used in tests). In many classes (like [1]), the methods
are not pure-virtual but have dummy implementations, but we should be
able to figure out that the base class constructor is never called
except when constructing the single implementation class.

Most of this interface might not be very hot, but optimizing the
virtual barrier away seems looks like a juicy opportunity for binary
size and inlining (and start-up time if we can drop the vtables and
void the dynamic relocations).

Cheers,
Hans

[0]. https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/public/platform/WebScrollbar.h
[1]. https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/public/platform/WebScrollbarBehavior.h


More information about the llvm-dev mailing list