[llvm] [BOLT] Add support for safe-icf (PR #116275)

Amir Ayupov via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 25 03:45:24 PST 2024


================
@@ -0,0 +1,249 @@
+# generate profile
+# clang++ -O2 -fprofile-generate=. main.cpp   -c -o mainProf.o
+# PROF=test.profdata
+# clang++ -m64  -fprofile-use=$PROF \
+#   -mllvm -disable-icp=true -mllvm -print-after-all \
+#   -g0 -flto=thin -fwhole-program-vtables -fno-split-lto-unit -O2 \
+#   -fdebug-types-section \
+#   main.cpp -c -o mainProfLTO.bc
+# PASS='pgo-icall-prom'
+# clang++ -m64  -fprofile-use=$PROF \
+#   -O3 -Rpass=$PASS \
+#   -mllvm -print-before=$PASS \
+#   -mllvm -print-after=$PASS \
+#   -mllvm -filter-print-funcs=main \
+#   -mllvm -debug-only=$PASS \
+#   -x ir \
+#   mainProfLTO.bc -c -o mainProfFinal.o
+
+# class Base {
+# public:
+#   virtual int func(int a, int b) const = 0;
+#
+#   virtual ~Base() {};
+# };
+#
+# //namespace {
+# class Derived2 : public Base {
+#   int c = 5;
+# public:
+#   __attribute__((noinline)) int func(int a, int b)const override { return a * (a - b) + this->c; }
+#
+#   ~Derived2() {}
+# };
+#
+# class Derived3 : public Base {
+#   int c = 500;
+# public:
+#   __attribute__((noinline)) int func(int a, int b) const override { return a * (a - b) + this->c; }
+#   ~Derived3() {}
+# };
+# //} // namespace//
+#
+# __attribute__((noinline)) Base *createType(int a) {
+#     Base *base = nullptr;
+#     if (a == 4)
+#       base = new Derived2();
+#     else
+#       base = new Derived3();
+#     return base;
+# }
+#
+# extern int returnFive();
+# extern int returnFourOrFive(int val);
+# int main(int argc, char **argv) {
+#   int sum = 0;
+#   int a = returnFourOrFive(argc);
+#   int b = returnFive();
+#   Base *ptr = createType(a);
+#   Base *ptr2 = createType(b);
+#   sum += ptr->func(b, a) + ptr2->func(b, a);
+#   return 0;
+# }
+# Manually modified to remove "extra" assembly.
+  .text
+	.file	"main.cpp"
+	.section	.text.hot.,"ax", at progbits
+	.globl	_Z10createTypei                 # -- Begin function _Z10createTypei
+	.p2align	4, 0x90
+	.type	_Z10createTypei, at function
+_Z10createTypei:                        # @_Z10createTypei
+	.cfi_startproc
+	callq	_Znwm at PLT
+	leaq	_ZTV8Derived2+16(%rip), %rcx
+	leaq	_ZTV8Derived3+16(%rip), %rdx
+	cmoveq	%rcx, %rdx
+	retq
+.Lfunc_end0:
+	.size	_Z10createTypei, .Lfunc_end0-_Z10createTypei
+	.cfi_endproc
+                                        # -- End function
+	.globl	main                            # -- Begin function main
+	.p2align	4, 0x90
+	.type	main, at function
+main:                                   # @main
+	.cfi_startproc
+	callq	_Z16returnFourOrFivei at PLT
+	callq	_Z10returnFivev at PLT
+	callq	_Z10createTypei
+	callq	_Z10createTypei
+	leaq	_ZNK8Derived24funcEii(%rip), %rcx
+	jne	.LBB1_2
+	callq	_ZNK8Derived24funcEii
+.LBB1_3:                                # %if.end.icp
+	leaq	_ZNK8Derived34funcEii(%rip), %rcx
+	jne	.LBB1_5
+	callq	_ZNK8Derived34funcEii
+.LBB1_6:                                # %if.end.icp3
+	retq
+.LBB1_2:                                # %if.false.orig_indirect
+	jmp	.LBB1_3
+.LBB1_5:                                # %if.false.orig_indirect2
+	jmp	.LBB1_6
+.Lfunc_end1:
+	.size	main, .Lfunc_end1-main
+	.cfi_endproc
+                                        # -- End function
+	.section	.text.hot._ZNK8Derived24funcEii,"axG", at progbits,_ZNK8Derived24funcEii,comdat
+	.weak	_ZNK8Derived24funcEii           # -- Begin function _ZNK8Derived24funcEii
+	.p2align	4, 0x90
+	.type	_ZNK8Derived24funcEii, at function
+_ZNK8Derived24funcEii:                  # @_ZNK8Derived24funcEii
+	.cfi_startproc
+	imull	%esi, %eax
+	retq
+.Lfunc_end2:
+	.size	_ZNK8Derived24funcEii, .Lfunc_end2-_ZNK8Derived24funcEii
+	.cfi_endproc
+                                        # -- End function
+	.section	.text.unlikely._ZN8Derived2D0Ev,"axG", at progbits,_ZN8Derived2D0Ev,comdat
+	.weak	_ZN8Derived2D0Ev                # -- Begin function _ZN8Derived2D0Ev
+	.p2align	4, 0x90
+	.type	_ZN8Derived2D0Ev, at function
+_ZN8Derived2D0Ev:                       # @_ZN8Derived2D0Ev
+	.cfi_startproc
+# %bb.0:                                # %entry
+	movl	$16, %esi
+	jmp	_ZdlPvm at PLT                     # TAILCALL
+.Lfunc_end3:
+	.size	_ZN8Derived2D0Ev, .Lfunc_end3-_ZN8Derived2D0Ev
+	.cfi_endproc
+                                        # -- End function
+	.section	.text.hot._ZNK8Derived34funcEii,"axG", at progbits,_ZNK8Derived34funcEii,comdat
+	.weak	_ZNK8Derived34funcEii           # -- Begin function _ZNK8Derived34funcEii
+	.p2align	4, 0x90
+	.type	_ZNK8Derived34funcEii, at function
+_ZNK8Derived34funcEii:                  # @_ZNK8Derived34funcEii
+	.cfi_startproc
+	imull	%esi, %eax
+	retq
+.Lfunc_end4:
+	.size	_ZNK8Derived34funcEii, .Lfunc_end4-_ZNK8Derived34funcEii
+	.cfi_endproc
+                                        # -- End function
+	.section	.text.unlikely._ZN4BaseD2Ev,"axG", at progbits,_ZN4BaseD2Ev,comdat
+	.weak	_ZN4BaseD2Ev                    # -- Begin function _ZN4BaseD2Ev
+	.p2align	4, 0x90
+	.type	_ZN4BaseD2Ev, at function
+_ZN4BaseD2Ev:                           # @_ZN4BaseD2Ev
+	.cfi_startproc
+# %bb.0:                                # %entry
+	retq
+.Lfunc_end5:
+	.size	_ZN4BaseD2Ev, .Lfunc_end5-_ZN4BaseD2Ev
+	.cfi_endproc
+                                        # -- End function
+	.section	.text.unlikely._ZN8Derived3D0Ev,"axG", at progbits,_ZN8Derived3D0Ev,comdat
+	.weak	_ZN8Derived3D0Ev                # -- Begin function _ZN8Derived3D0Ev
+	.p2align	4, 0x90
+	.type	_ZN8Derived3D0Ev, at function
+_ZN8Derived3D0Ev:                       # @_ZN8Derived3D0Ev
+	.cfi_startproc
+# %bb.0:                                # %entry
+	movl	$16, %esi
+	jmp	_ZdlPvm at PLT                     # TAILCALL
+.Lfunc_end6:
+	.size	_ZN8Derived3D0Ev, .Lfunc_end6-_ZN8Derived3D0Ev
+	.cfi_endproc
+                                        # -- End function
+	.type	_ZTV8Derived2, at object           # @_ZTV8Derived2
+	.section	.data.rel.ro._ZTV8Derived2,"awG", at progbits,_ZTV8Derived2,comdat
+	.weak	_ZTV8Derived2
+	.p2align	3, 0x0
+_ZTV8Derived2:
+	.quad	0
+	.quad	_ZTI8Derived2
+	.quad	_ZNK8Derived24funcEii
+	.quad	_ZN4BaseD2Ev
+	.quad	_ZN8Derived2D0Ev
+	.size	_ZTV8Derived2, 40
+
+	.type	_ZTS8Derived2, at object           # @_ZTS8Derived2
+	.section	.rodata._ZTS8Derived2,"aG", at progbits,_ZTS8Derived2,comdat
+	.weak	_ZTS8Derived2
+_ZTS8Derived2:
+	.asciz	"8Derived2"
+	.size	_ZTS8Derived2, 10
+
+	.type	_ZTS4Base, at object               # @_ZTS4Base
+	.section	.rodata._ZTS4Base,"aG", at progbits,_ZTS4Base,comdat
+	.weak	_ZTS4Base
+_ZTS4Base:
+	.asciz	"4Base"
+	.size	_ZTS4Base, 6
+
+	.type	_ZTI4Base, at object               # @_ZTI4Base
+	.section	.data.rel.ro._ZTI4Base,"awG", at progbits,_ZTI4Base,comdat
+	.weak	_ZTI4Base
+	.p2align	3, 0x0
+_ZTI4Base:
+	.quad	_ZTVN10__cxxabiv117__class_type_infoE+16
+	.quad	_ZTS4Base
+	.size	_ZTI4Base, 16
+
+	.type	_ZTI8Derived2, at object           # @_ZTI8Derived2
+	.section	.data.rel.ro._ZTI8Derived2,"awG", at progbits,_ZTI8Derived2,comdat
+	.weak	_ZTI8Derived2
+	.p2align	3, 0x0
+_ZTI8Derived2:
+	.quad	_ZTVN10__cxxabiv120__si_class_type_infoE+16
+	.quad	_ZTS8Derived2
+	.quad	_ZTI4Base
+	.size	_ZTI8Derived2, 24
+
+	.type	_ZTV8Derived3, at object           # @_ZTV8Derived3
+	.section	.data.rel.ro._ZTV8Derived3,"awG", at progbits,_ZTV8Derived3,comdat
+	.weak	_ZTV8Derived3
+	.p2align	3, 0x0
+_ZTV8Derived3:
+	.quad	0
+	.quad	_ZTI8Derived3
+	.quad	_ZNK8Derived34funcEii
+	.quad	_ZN4BaseD2Ev
+	.quad	_ZN8Derived3D0Ev
+	.size	_ZTV8Derived3, 40
+
+	.type	_ZTS8Derived3, at object           # @_ZTS8Derived3
+	.section	.rodata._ZTS8Derived3,"aG", at progbits,_ZTS8Derived3,comdat
+	.weak	_ZTS8Derived3
+_ZTS8Derived3:
+	.asciz	"8Derived3"
+	.size	_ZTS8Derived3, 10
+
+	.type	_ZTI8Derived3, at object           # @_ZTI8Derived3
+	.section	.data.rel.ro._ZTI8Derived3,"awG", at progbits,_ZTI8Derived3,comdat
+	.weak	_ZTI8Derived3
+	.p2align	3, 0x0
+_ZTI8Derived3:
+	.quad	_ZTVN10__cxxabiv120__si_class_type_infoE+16
+	.quad	_ZTS8Derived3
+	.quad	_ZTI4Base
+	.size	_ZTI8Derived3, 24
+
+	.cg_profile _Z10createTypei, _Znwm, 2
+	.cg_profile main, _Z16returnFourOrFivei, 1
+	.cg_profile main, _Z10returnFivev, 1
+	.cg_profile main, _Z10createTypei, 2
+	.cg_profile main, _ZNK8Derived24funcEii, 1
+	.cg_profile main, _ZNK8Derived34funcEii, 1
+	.ident	"clang version 20.0.0git"
----------------
aaupov wrote:

What are these cg_profile directives needed for?

https://github.com/llvm/llvm-project/pull/116275


More information about the llvm-commits mailing list