brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · 2a3cfdc Raw
120 lines · plain
1;; Test that symbols defined in shared libraries prevent devirtualization.2 3;; First check that we get devirtualization when the defs are in the4;; LTO unit.5 6;; Index based WPD7;; Generate unsplit module with summary for ThinLTO index-based WPD.8; RUN: opt --thinlto-bc -o %t1a.o %s9; RUN: opt --thinlto-bc -o %t2a.o %S/Inputs/devirt_vcall_vis_shared_def.ll10; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \11; RUN:   --plugin-opt=whole-program-visibility \12; RUN:   --plugin-opt=save-temps \13; RUN:   --plugin-opt=-pass-remarks=. \14; RUN:   %t1a.o %t2a.o -o %t3a 2>&1 | FileCheck %s --check-prefix=REMARK15; RUN: llvm-dis %t1a.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR16 17;; Hybrid WPD18;; Generate split module with summary for hybrid Thin/Regular LTO WPD.19; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t1b.o %s20; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t2b.o %S/Inputs/devirt_vcall_vis_shared_def.ll21; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \22; RUN:   --plugin-opt=whole-program-visibility \23; RUN:   --plugin-opt=save-temps \24; RUN:   --plugin-opt=-pass-remarks=. \25; RUN:   %t1b.o %t2b.o -o %t3b 2>&1 | FileCheck %s --check-prefix=REMARK26; RUN: llvm-dis %t1b.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR27 28;; Regular LTO WPD29; RUN: opt -o %t1c.o %s30; RUN: opt -o %t2c.o %S/Inputs/devirt_vcall_vis_shared_def.ll31; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \32; RUN:   --plugin-opt=whole-program-visibility \33; RUN:   --plugin-opt=save-temps \34; RUN:   --plugin-opt=-pass-remarks=. \35; RUN:   %t1c.o %t2c.o -o %t3c 2>&1 | FileCheck %s --check-prefix=REMARK36; RUN: llvm-dis %t3c.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR37 38; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi39 40;; Check that WPD fails with when linking against a shared library41;; containing the strong defs of the vtables.42; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \43; RUN:   %t2c.o -o %t.so -shared44 45;; Index based WPD46; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \47; RUN:   --plugin-opt=whole-program-visibility \48; RUN:   --plugin-opt=-pass-remarks=. \49; RUN:   %t1a.o %t.so -o %t4a \50; RUN:   --export-dynamic 2>&1 | count 051 52;; Hybrid WPD53; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o %t4.o %s54; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \55; RUN:   --plugin-opt=whole-program-visibility \56; RUN:   --plugin-opt=-pass-remarks=. \57; RUN:   %t1b.o %t.so -o %t4b \58; RUN:   --export-dynamic 2>&1 | count 059 60;; Regular LTO WPD61; RUN: opt -o %t4.o %s62; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \63; RUN:   --plugin-opt=whole-program-visibility \64; RUN:   --plugin-opt=-pass-remarks=. \65; RUN:   %t1c.o %t.so -o %t4c \66; RUN:   --export-dynamic 2>&1 | count 067 68target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"69target triple = "x86_64-grtev4-linux-gnu"70 71%struct.A = type { ptr }72%struct.B = type { %struct.A }73 74@_ZTV1A = available_externally unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1A1fEi, ptr @_ZN1A1nEi] }, !type !0, !vcall_visibility !275@_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 !276 77;; Prevent the vtables from being dead code eliminated.78@llvm.used = appending global [2 x ptr] [ ptr @_ZTV1A, ptr @_ZTV1B]79 80; CHECK-IR-LABEL: define dso_local i32 @_start81define i32 @_start(ptr %obj, i32 %a) {82entry:83  %vtable = load ptr, ptr %obj84  %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")85  call void @llvm.assume(i1 %p)86  %fptrptr = getelementptr ptr, ptr %vtable, i32 187  %fptr1 = load ptr, ptr %fptrptr, align 888 89  ;; Check that the call was devirtualized.90  ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi91  ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr192  %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)93 94  ret i32 %call95}96; CHECK-IR-LABEL: ret i3297; CHECK-IR-LABEL: }98 99declare i1 @llvm.type.test(ptr, metadata)100declare void @llvm.assume(i1)101 102define available_externally i32 @_ZN1A1fEi(ptr %this, i32 %a) #0 {103   ret i32 0104}105 106define available_externally i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {107   ret i32 0108}109 110define linkonce_odr i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {111   ret i32 0112}113 114;; Make sure we don't inline or otherwise optimize out the direct calls.115attributes #0 = { noinline optnone }116 117!0 = !{i64 16, !"_ZTS1A"}118!1 = !{i64 16, !"_ZTS1B"}119!2 = !{i64 0}120