brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.0 KiB · 9a302c8 Raw
148 lines · plain
1## Check that BOLT handles correctly folding functions with --icf=safe2## that can be referenced through a non control flow instruction when ICP optimization is enabled.3## This tests also checks that destructors are folded.4 5# REQUIRES: system-linux, asserts6# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t1.o7# RUN: %clang %cflags %t1.o -o %t.exe -Wl,-q8# RUN: llvm-bolt --no-threads %t.exe --icf      -debug-only=bolt-icf -o %t.bolt 2>&1 | FileCheck --check-prefix=ICFCHECK %s9# RUN: llvm-bolt --no-threads %t.exe --icf=safe -debug-only=bolt-icf -o %t.bolt 2>&1 | FileCheck --check-prefix=SAFEICFCHECK %s10 11# ICFCHECK:      ICF iteration 112# ICFCHECK-NEXT: folding Derived3Destructor into Derived2Destructor13# ICFCHECK-NEXT: folding Derived3Func into Derived2Func14 15# SAFEICFCHECK: skipping function with reference taken Derived3Func16# SAFEICFCHECK-NEXT: ICF iteration 117# SAFEICFCHECK-NEXT: folding Derived3Destructor into Derived2Destructor18 19 20## generate profile21## clang++ -O2 -fprofile-generate=. main.cpp   -c -o mainProf.o22## PROF=test.profdata23## clang++ -m64  -fprofile-use=$PROF \24##   -mllvm -disable-icp=true -mllvm -print-after-all \25##   -g0 -flto=thin -fwhole-program-vtables -fno-split-lto-unit -O2 \26##   -fdebug-types-section \27##   main.cpp -c -o mainProfLTO.bc28## PASS='pgo-icall-prom'29## clang++ -m64  -fprofile-use=$PROF \30##   -O3 -Rpass=$PASS \31##   -mllvm -print-before=$PASS \32##   -mllvm -print-after=$PASS \33##   -mllvm -filter-print-funcs=main \34##   -mllvm -debug-only=$PASS \35##   -x ir \36##   mainProfLTO.bc -c -o mainProfFinal.o37 38## class Base {39## public:40##   virtual int func(int a, int b) const = 0;41##42##   virtual ~Base() {};43## };44##45## class Derived2 : public Base {46##   int c = 5;47## public:48##   __attribute__((noinline)) int func(int a, int b)const override { return a * (a - b) + this->c; }49##50##   ~Derived2() {}51## };52##53## class Derived3 : public Base {54##   int c = 500;55## public:56##   __attribute__((noinline)) int func(int a, int b) const override { return a * (a - b) + this->c; }57##   ~Derived3() {}58## };59##60## __attribute__((noinline)) Base *createType(int a) {61##     Base *base = nullptr;62##     if (a == 4)63##       base = new Derived2();64##     else65##       base = new Derived3();66##     return base;67## }68##69## extern int returnFive();70## extern int returnFourOrFive(int val);71## int main(int argc, char **argv) {72##   int sum = 0;73##   int a = returnFourOrFive(argc);74##   int b = returnFive();75##   Base *ptr = createType(a);76##   Base *ptr2 = createType(b);77##   sum += ptr->func(b, a) + ptr2->func(b, a);78##   return 0;79## }80## clang++ -c helper.cpp -o helper.o81## int FooVar = 1;82## int BarVar = 2;83##84## int fooGlobalFuncHelper(int a, int b) {85##   return 5;86## }87## Manually modified to remove "extra" assembly.88	.globl	main89	.type	main,@function90main:91	leaq	Derived3Func(%rip), %rcx92	callq	Derived3Func93	.size	main, .-main94 95	.weak	Derived2Func96	.type	Derived2Func,@function97Derived2Func:98	imull	%esi, %eax99	retq100	.size	Derived2Func, .-Derived2Func101 102	.weak	Derived2Destructor103	.type	Derived2Destructor,@function104Derived2Destructor:105	jmp	_ZdlPvm@PLT106	.size	Derived2Destructor, .-Derived2Destructor107 108	.weak	Derived3Func109	.type	Derived3Func,@function110Derived3Func:111	imull	%esi, %eax112	retq113	.size	Derived3Func, .-Derived3Func114 115	.weak	_ZN4BaseD2Ev116	.type	_ZN4BaseD2Ev,@function117_ZN4BaseD2Ev:118	retq119	.size	_ZN4BaseD2Ev, .-_ZN4BaseD2Ev120 121	.weak	Derived3Destructor122	.type	Derived3Destructor,@function123Derived3Destructor:124	jmp	_ZdlPvm@PLT125	.size	Derived3Destructor, .-Derived3Destructor126 127	.type	_ZTV8Derived2,@object128	.section	.data.rel.ro._ZTV8Derived2,"awG",@progbits,_ZTV8Derived2,comdat129	.weak	_ZTV8Derived2130_ZTV8Derived2:131	.quad	0132	.quad	_ZTI8Derived2133	.quad	Derived2Func134	.quad	_ZN4BaseD2Ev135	.quad	Derived2Destructor136	.size	_ZTV8Derived2, 40137 138	.type	_ZTV8Derived3,@object139	.section	.data.rel.ro._ZTV8Derived3,"awG",@progbits,_ZTV8Derived3,comdat140	.weak	_ZTV8Derived3141_ZTV8Derived3:142	.quad	0143	.quad	_ZTI8Derived3144	.quad	Derived3Func145	.quad	_ZN4BaseD2Ev146	.quad	Derived3Destructor147	.size	_ZTV8Derived3, 40148