Skip to content

Commit 6be4464

Browse files
implement the fix for hybrid LTO, and update test cases
1 parent 40f913c commit 6be4464

File tree

2 files changed

+66
-22
lines changed

2 files changed

+66
-22
lines changed

llvm/lib/LTO/LTO.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,8 @@ Error LTO::runRegularLTO(AddStreamFn AddStream) {
13141314
// expected to be handled separately.
13151315
auto IsVisibleToRegularObj = [&](StringRef name) {
13161316
auto It = GlobalResolutions->find(name);
1317-
return (It == GlobalResolutions->end() || It->second.VisibleOutsideSummary);
1317+
return (It == GlobalResolutions->end() ||
1318+
It->second.VisibleOutsideSummary || It->second.ExportDynamic);
13181319
};
13191320

13201321
// If allowed, upgrade public vcall visibility metadata to linkage unit

llvm/test/ThinLTO/X86/nodevirt_exort_dynamic.ll renamed to llvm/test/ThinLTO/X86/nodevirt_export_dynamic.ll

Lines changed: 64 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
; RUN: rm -rf %t && mkdir %t && cd %t
22

3+
; Tests that devirtualization is suppressed on a class when its compatible
4+
; class could be referenced from dynamic linker that is not visible to the
5+
; linker.
6+
37
; Generate unsplit module with summary for ThinLTO index-based WPD.
48
; RUN: opt -thinlto-bc -o summary.o %s
59

6-
; RUN: llvm-dis -o - summary.o
7-
8-
;; TODO: Implement the fix for WPD in regular or hybrid LTO, and add test coverage.
9-
1010
; Index based WPD
1111
; For `_ZTI7Derived`, the 'llvm-lto2' resolution arguments specifies `VisibleOutsideSummary` as false
1212
; and `ExportDynamic` as false. The callsite inside @_ZN4Base8dispatchEv
@@ -21,15 +21,12 @@
2121
; RUN: -r=summary.o,_ZN4Base8dispatchEv,px \
2222
; RUN: -r=summary.o,_ZN7DerivedC2Ev, \
2323
; RUN: -r=summary.o,_ZN8DerivedN5printEv,px \
24-
; RUN: -r=summary.o,_ZTS4Base, \
2524
; RUN: -r=summary.o,_ZTV8DerivedN,p \
2625
; RUN: -r=summary.o,_ZTI8DerivedN,p \
27-
; RUN: -r=summary.o,_ZTI4Base, \
2826
; RUN: -r=summary.o,_ZTS8DerivedN,p \
2927
; RUN: -r=summary.o,_ZTI7Derived, \
30-
; RUN: -r=summary.o,_ZTV4Base 2>&1 | FileCheck --allow-empty %s --check-prefix=REMARK
28+
; RUN: 2>&1 | FileCheck --allow-empty %s --check-prefix=REMARK
3129

32-
; REMARK: single-impl: devirtualized a call to _ZN8DerivedN5printEv
3330

3431
; Index based WPD
3532
; For `_ZTI7Derived`, the 'llvm-lto2' resolution arguments specifies `VisibleOutsideSummary` as false
@@ -45,24 +42,70 @@
4542
; RUN: -r=summary.o,_ZN4Base8dispatchEv,px \
4643
; RUN: -r=summary.o,_ZN7DerivedC2Ev, \
4744
; RUN: -r=summary.o,_ZN8DerivedN5printEv,px \
48-
; RUN: -r=summary.o,_ZTS4Base, \
4945
; RUN: -r=summary.o,_ZTV8DerivedN,p \
5046
; RUN: -r=summary.o,_ZTI8DerivedN,p \
51-
; RUN: -r=summary.o,_ZTI4Base, \
5247
; RUN: -r=summary.o,_ZTS8DerivedN,p \
5348
; RUN: -r=summary.o,_ZTI7Derived,d \
54-
; RUN: -r=summary.o,_ZTV4Base 2>&1 | FileCheck %s --allow-empty --implicit-check-not='single-impl: devirtualized a call to'
49+
; RUN: 2>&1 | FileCheck %s --allow-empty --implicit-check-not='single-impl: devirtualized a call to'
50+
51+
52+
; Hybrid LTO WPD
53+
; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o hybrid.o %s
54+
; RUN: llvm-lto2 run hybrid.o -save-temps -pass-remarks=. \
55+
; RUN: -o hybrid \
56+
; RUN: --whole-program-visibility-enabled-in-lto=true \
57+
; RUN: --validate-all-vtables-have-type-infos=true \
58+
; RUN: --all-vtables-have-type-infos=true \
59+
; RUN: -r=hybrid.o,__cxa_pure_virtual, \
60+
; RUN: -r=hybrid.o,_ZN8DerivedNC2Ev,x \
61+
; RUN: -r=hybrid.o,_ZN4Base8dispatchEv,px \
62+
; RUN: -r=hybrid.o,_ZN7DerivedC2Ev, \
63+
; RUN: -r=hybrid.o,_ZN8DerivedN5printEv,px \
64+
; RUN: -r=hybrid.o,_ZTV8DerivedN,p \
65+
; RUN: -r=hybrid.o,_ZTI8DerivedN,p \
66+
; RUN: -r=hybrid.o,_ZTS8DerivedN,p \
67+
; RUN: -r=hybrid.o,_ZTI7Derived, \
68+
; RUN: -r=hybrid.o,_ZN8DerivedN5printEv,px \
69+
; RUN: -r=hybrid.o,_ZTV8DerivedN,p \
70+
; RUN: -r=hybrid.o,_ZTI8DerivedN,p \
71+
; RUN: 2>&1 | FileCheck --allow-empty %s --check-prefix=REMARK
72+
73+
; Hybrid LTO WPD
74+
; RUN: llvm-lto2 run hybrid.o -save-temps -pass-remarks=. \
75+
; RUN: -o hybrid \
76+
; RUN: --whole-program-visibility-enabled-in-lto=true \
77+
; RUN: --validate-all-vtables-have-type-infos=true \
78+
; RUN: --all-vtables-have-type-infos=true \
79+
; RUN: -r=hybrid.o,__cxa_pure_virtual, \
80+
; RUN: -r=hybrid.o,_ZN8DerivedNC2Ev,x \
81+
; RUN: -r=hybrid.o,_ZN4Base8dispatchEv,px \
82+
; RUN: -r=hybrid.o,_ZN7DerivedC2Ev, \
83+
; RUN: -r=hybrid.o,_ZN8DerivedN5printEv,px \
84+
; RUN: -r=hybrid.o,_ZTV8DerivedN,p \
85+
; RUN: -r=hybrid.o,_ZTI8DerivedN,p \
86+
; RUN: -r=hybrid.o,_ZTS8DerivedN,p \
87+
; RUN: -r=hybrid.o,_ZTI7Derived,d \
88+
; RUN: -r=hybrid.o,_ZN8DerivedN5printEv,px \
89+
; RUN: -r=hybrid.o,_ZTV8DerivedN,p \
90+
; RUN: -r=hybrid.o,_ZTI8DerivedN,p \
91+
; RUN: 2>&1 | FileCheck --allow-empty %s --implicit-check-not='single-impl: devirtualized a call to'
92+
93+
94+
; In regular LTO, global resolutions (as expected) show symbols are visible
95+
; outside summary (when they come from regular LTO module without summaries).
96+
; In the setting of this test case (equivalent of `-Wl,--lto-whole-program-visibility -Wl,--lto-validate-all-vtables-have-type-infos` in lld),
97+
; devirtualization will be suppressed even if the compatible class is not
98+
; referenced from shared libraries. So regular LTO test coverage is not meaningful.
99+
100+
; REMARK: single-impl: devirtualized a call to _ZN8DerivedN5printEv
55101

56102
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
57103
target triple = "x86_64-unknown-linux-gnu"
58104

59-
@_ZTV8DerivedN = linkonce_odr hidden constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI8DerivedN, ptr @_ZN8DerivedN5printEv] }, !type !0, !type !1, !type !2, !type !3, !type !4, !type !5, !vcall_visibility !6
105+
@_ZTV8DerivedN = linkonce_odr hidden constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI8DerivedN, ptr @_ZN8DerivedN5printEv] }, !type !0, !type !1, !type !2, !type !3, !vcall_visibility !6
60106
@_ZTI8DerivedN = linkonce_odr hidden constant { ptr, ptr, ptr } { ptr null, ptr @_ZTS8DerivedN, ptr @_ZTI7Derived }
61107
@_ZTS8DerivedN = linkonce_odr hidden constant [10 x i8] c"8DerivedN\00", align 1
62108
@_ZTI7Derived = external constant ptr
63-
@_ZTV4Base = linkonce_odr hidden constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI4Base, ptr @__cxa_pure_virtual] }, !type !0, !type !1, !vcall_visibility !6
64-
@_ZTI4Base = linkonce_odr hidden constant { ptr, ptr } { ptr null, ptr @_ZTS4Base }
65-
@_ZTS4Base = linkonce_odr hidden constant [6 x i8] c"4Base\00", align 1
66109

67110
@llvm.used = appending global [1 x ptr] [ptr @_ZN8DerivedNC2Ev], section "llvm.metadata"
68111

@@ -102,10 +145,10 @@ declare i1 @llvm.type.test(ptr, metadata)
102145
declare void @llvm.assume(i1)
103146
declare void @_ZN7DerivedC2Ev(ptr)
104147

105-
!0 = !{i64 16, !"_ZTS4Base"}
106-
!1 = !{i64 16, !"_ZTSM4BaseFvvE.virtual"}
107-
!2 = !{i64 16, !"_ZTS7Derived"}
108-
!3 = !{i64 16, !"_ZTSM7DerivedFvvE.virtual"}
109-
!4 = !{i64 16, !"_ZTS8DerivedN"}
110-
!5 = !{i64 16, !"_ZTSM8DerivedNFvvE.virtual"}
148+
!0 = !{i64 16, !"_ZTS7Derived"}
149+
!1 = !{i64 16, !"_ZTSM7DerivedFvvE.virtual"}
150+
!2 = !{i64 16, !"_ZTS8DerivedN"}
151+
!3 = !{i64 16, !"_ZTSM8DerivedNFvvE.virtual"}
152+
;!4 = !{i64 16, !"_ZTS8DerivedN"}
153+
;!5 = !{i64 16, !"_ZTSM8DerivedNFvvE.virtual"}
111154
!6 = !{i64 0}

0 commit comments

Comments
 (0)