[compiler-rt] [llvm] [Transforms][IPO] Add func suffix in ArgumentPromotion and DeadArgumentElimination (PR #109899)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 5 18:38:12 PDT 2024


yonghong-song wrote:

> This is going to cause SamplePGO tooling (both in the compiler and out of it) to need updating. Here's a place in the compiler that needs updating, e.g.:
> 
> https://github.com/llvm/llvm-project/blob/808c498f52c8ff7724f762dab351600864023098/llvm/include/llvm/ProfileData/SampleProf.h#L1107
> 
> To avoid affecting profile handling, and avoid a lot of test churn, can you put this under an option (ideally defaulted off)?

I tried an example with bpftool (https://github.com/torvalds/linux/tree/master/tools/bpf/bpftool). I build the libbpf/bpftool with additional flags  -gline-tables-only -fdebug-info-for-profiling -funique-internal-linkage-names. I also intentionally modified one of static function 'btf_new' so 'btf_new' function eventually will have .argelim suffix.

I then used the following command to generate the training data.
```
  sudo perf record -e BR_INST_RETIRED.NEAR_TAKEN:uppp -b -o perf.data -c 10059 --buildid-mmap ./bpftool prog
  sudo perf script -F ip,brstack -i perf.data --show-mmap-events &> perfscript.out 
  llvm-profgen --binary ./bpftool --perfscript=perfscript.out --output=sample.perfscript.bin
  llvm-profdata merge --sample --text sample.perfscript.bin --output=sample.perfscript.txt
```

I checked sample.perfscript.txt, the 'btf_new' symbol indeed in the training data:
```
$ llvm-readelf -s bpftool | grep btf_new 
   420: 000000000004a780  2396 FUNC    LOCAL  DEFAULT    13 _ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074.argelim
$ grep btf_new sample.perfscript.txt
_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074:324779:0
```

Another example
```
$ llvm-readelf -s bpftool | grep print_boot_time
   265: 0000000000026580   262 FUNC    LOCAL  DEFAULT    13 _ZL15print_boot_timeyPcj.__uniq.209043448395238328353871160106749095556.argelim
$ grep print_boot_time sample.perfscript.txt
_ZL15print_boot_timeyPcj.__uniq.209043448395238328353871160106749095556:95:0
```

I did some code inspection and find that llvm-profgen uses symbol table to find the code and do disassemble. But eventual write to the training data is based on dwarf (address range -> func name in dwarf). In dwarf, the func name is
```
$ llvm-dwarfdump bpftool | grep _ZL7btf_newPKvjP3btfi
                  DW_AT_call_origin     (0x00014d02 "_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074")
                DW_AT_linkage_name      ("_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074")
                  DW_AT_call_origin     (0x00014d02 "_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074")
                  DW_AT_call_origin     (0x00014d02 "_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074")
                  DW_AT_call_origin     (0x00014d02 "_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074")
                  DW_AT_call_origin     (0x00014d02 "_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074")
                  DW_AT_call_origin     (0x00014d02 "_ZL7btf_newPKvjP3btfi.__uniq.13970676711478106820152951367420834074")
```
You can see the above linkage name which is the one in the training data.

So I think the .argelim suffix should not impact sampling based profile.

The same for .argprom suffix:
```
$ llvm-readelf -s bpftool | grep btf_invalidate_raw_data_1
   414: 0000000000055210    60 FUNC    LOCAL  DEFAULT    13 _ZL25btf_invalidate_raw_data_1P3btfPKc.__uniq.13970676711478106820152951367420834074.argprom
[yhs at devbig309.ftw3 ~/work/bpf-next/tools/bpf/bpftool (schedext-v1-3-debug)]$ llvm-dwarfdump bpftool | grep btf_invalidate_raw_data_1
                  DW_AT_call_origin     (0x00015e44 "_ZL25btf_invalidate_raw_data_1P3btfPKc.__uniq.13970676711478106820152951367420834074")
                DW_AT_linkage_name      ("_ZL25btf_invalidate_raw_data_1P3btfPKc.__uniq.13970676711478106820152951367420834074")
                DW_AT_name      ("btf_invalidate_raw_data_1")
```


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


More information about the llvm-commits mailing list