================
@@ -2350,6 +2343,52 @@ are listed below.
pure ThinLTO, as all split regular LTO modules are merged and LTO linked
with regular LTO.
+.. option:: -fdevirtualize-speculatively
+
+ Enable speculative devirtualization optimization where a virtual call
+ can be transformed into a direct call under the assumption that its
+ object is of a particular type. A runtime check is inserted to validate
+ the assumption before making the direct call, and if the check fails,
+ the original virtual call is made instead. This optimization can enable
+ more inlining opportunities and better optimization of the direct call.
+ This is different from other whole program devirtualization optimizations
+ that rely on global analysis and hidden visibility of the objects to prove
+ that the object is always of a particular type at a virtual call site.
+ This optimization doesn't require global analysis or hidden visibility.
+ This optimization doesn't devirtualize all virtual calls, but only
+ when there's a single implementation of the virtual function.
+ There could be a single implementaiton of the virtual function
+ either because the function is not overridden in any derived class,
+ or because there is a sinlge instantiated object that is using the funciton.
+
+ Ex of IR before the optimization:
+ .. code-block:: llvm
+ %vtable = load ptr, ptr %BV, align 8, !tbaa !6
+ %0 = tail call i1 @llvm.public.type.test(ptr %vtable, metadata
!"_ZTS4Base")
+ tail call void @llvm.assume(i1 %0)
+ %0 = load ptr, ptr %vtable, align 8
+ tail call void %0(ptr noundef nonnull align 8 dereferenceable(8) %BV)
+ ret void
+
+ IR after the optimization:
+ .. code-block:: llvm
+ %vtable = load ptr, ptr %BV, align 8, !tbaa !12
+ %0 = load ptr, ptr %vtable, align 8
+ %1 = icmp eq ptr %0, @_ZN4Base17virtual_function1Ev
+ br i1 %1, label %if.true.direct_targ, label %if.false.orig_indirect,
!prof !15
+ if.true.direct_targ: ; preds = %entry
+ tail call void @_ZN4Base17virtual_function1Ev(ptr noundef nonnull align
8 dereferenceable(8) %BV)
+ br label %if.end.icp
+ if.false.orig_indirect: ; preds = %entry
+ tail call void %0(ptr noundef nonnull align 8 dereferenceable(8) %BV)
+ br label %if.end.icp
+
+ if.end.icp: ; preds =
%if.false.orig_indirect, %if.true.direct_targ
+ ret void
+ This feature is temporarily ignored at the LLVM side when LTO is enabled.
+ TODO: Update the comment when the LLVM side supports it.
----------------
teresajohnson wrote:
Maybe "Update the comment when LLVM supports this feature for LTO." ?
https://github.com/llvm/llvm-project/pull/159685
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits