brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.7 KiB · a61e290 Raw
100 lines · plain
1; REQUIRES: x862;; Test that symbols defined in shared libraries prevent devirtualization.3 4;; First check that we get devirtualization when the defs are in the5;; LTO unit.6 7;; Index based WPD8;; Generate unsplit module with summary for ThinLTO index-based WPD.9; RUN: opt --thinlto-bc -o %t1a.o %s10; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll11; RUN: ld.lld %t1a.o %t2a.o -o %t3a -save-temps --lto-whole-program-visibility \12; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK13; RUN: llvm-dis %t1a.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR14 15;; Hybrid WPD16;; Generate split module with summary for hybrid Thin/Regular LTO WPD.17; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s18; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll19; RUN: ld.lld %t1b.o %t2b.o -o %t3b -save-temps --lto-whole-program-visibility \20; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK21; RUN: llvm-dis %t1b.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR22 23;; Regular LTO WPD24; RUN: opt -o %t1c.o %s25; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll26; RUN: ld.lld %t1c.o %t2c.o -o %t3c -save-temps --lto-whole-program-visibility \27; RUN:   -mllvm -pass-remarks=. 2>&1 | FileCheck %s --check-prefix=REMARK28; RUN: llvm-dis %t3c.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR29 30; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi31 32;; Check that WPD fails with when linking against a shared library33;; containing the strong defs of the vtables.34; RUN: ld.lld %t2c.o -o %t.so -shared35 36;; Index based WPD37; RUN: ld.lld %t1a.o %t.so -o %t4a --lto-whole-program-visibility \38; RUN:   -mllvm -pass-remarks=. 2>&1 | count 039 40;; Hybrid WPD41; RUN: ld.lld %t1b.o %t.so -o %t4b --lto-whole-program-visibility \42; RUN:   -mllvm -pass-remarks=. 2>&1 | count 043 44;; Regular LTO WPD45; RUN: ld.lld %t1c.o %t.so -o %t4c --lto-whole-program-visibility \46; RUN:   -mllvm -pass-remarks=. 2>&1 | count 047 48target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"49target triple = "x86_64-grtev4-linux-gnu"50 51%struct.A = type { ptr }52%struct.B = type { %struct.A }53 54@_ZTV1A = available_externally unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1A1fEi, ptr @_ZN1A1nEi] }, !type !0, !vcall_visibility !255@_ZTV1B = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !256 57;; Prevent the vtables from being dead code eliminated.58@llvm.used = appending global [2 x ptr] [ ptr @_ZTV1A, ptr @_ZTV1B]59 60; CHECK-IR-LABEL: define dso_local i32 @_start61define i32 @_start(ptr %obj, i32 %a) {62entry:63  %vtable = load ptr, ptr %obj64  %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")65  call void @llvm.assume(i1 %p)66  %fptrptr = getelementptr ptr, ptr %vtable, i32 167  %fptr1 = load ptr, ptr %fptrptr, align 868 69  ;; Check that the call was devirtualized.70  ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi71  ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr172  %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)73 74  ret i32 %call75}76; CHECK-IR-LABEL: ret i3277; CHECK-IR-LABEL: }78 79declare i1 @llvm.type.test(ptr, metadata)80declare void @llvm.assume(i1)81 82define available_externally i32 @_ZN1A1fEi(ptr %this, i32 %a) #0 {83   ret i32 084}85 86define available_externally i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {87   ret i32 088}89 90define linkonce_odr i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {91   ret i32 092}93 94;; Make sure we don't inline or otherwise optimize out the direct calls.95attributes #0 = { noinline optnone }96 97!0 = !{i64 16, !"_ZTS1A"}98!1 = !{i64 16, !"_ZTS1B"}99!2 = !{i64 0}100