================
@@ -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.
----------------
hassnaaHamdi wrote:

Maybe I'm not expressing it well.
I mean that the devirtualization would work if the virtual function is not 
overridden in the inheritance tree, or the second case when the vfunction is 
overridden but single class in the inheritance tree is instantiated. 
ex for the first case:
```
struct Base {
    __attribute__((noinline))
    virtual void virtual_function1() { asm volatile("NOP"); }
};
struct Derived : Base {
};
__attribute__((noinline))
void foo(Base *BV) {
    BV->virtual_function1();
}
void bar() {
    Base *d = new Derived();
    Base *b = new Base();
    foo(d);
    foo(b);
}
```
second case:
```
struct Base {
    __attribute__((noinline))
    virtual void virtual_function1() { asm volatile("NOP"); }
};
struct Derived : Base {
    void virtual_function1() override { asm volatile("NOP"); }
};
__attribute__((noinline))
void foo(Base *BV) {
    BV->virtual_function1();
}
void bar() {
    Base *d = new Derived();
    foo(d);
}
```

https://github.com/llvm/llvm-project/pull/159685
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to