[all-commits] [llvm/llvm-project] 904b3f: [ELF] A new code layout algorithm for function reo...

spupyrev via All-commits all-commits at lists.llvm.org
Tue Sep 26 06:25:03 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 904b3f66f59e490e8b6d0c8cc8cacb7a91add544
      https://github.com/llvm/llvm-project/commit/904b3f66f59e490e8b6d0c8cc8cacb7a91add544
  Author: spupyrev <spupyrev at fb.com>
  Date:   2023-09-26 (Tue, 26 Sep 2023)

  Changed paths:
    M lld/ELF/CMakeLists.txt
    M lld/ELF/CallGraphSort.cpp
    M lld/ELF/CallGraphSort.h
    M lld/ELF/Config.h
    M lld/ELF/Driver.cpp
    M lld/ELF/Options.td
    M lld/docs/ld.lld.1
    M lld/test/ELF/cgprofile-txt.s
    M lld/test/ELF/cgprofile-txt2.s

  Log Message:
  -----------
  [ELF] A new code layout algorithm for function reordering [3a/3]

We are brining a new algorithm for function layout (reordering) based on the
call graph (extracted from a profile data). The algorithm is an improvement of
top of a known heuristic, C^3. It tries to co-locate hot and frequently executed
together functions in the resulting ordering. Unlike C^3, it explores a larger
search space and have an objective closely tied to the performance of
instruction and i-TLB caches. Hence, the name CDS = Cache-Directed Sort.
The algorithm can be used at the linking or post-linking (e.g., BOLT) stage.
Refer to https://reviews.llvm.org/D152834 for the actual implementation of the
reordering algorithm.

This diff adds a linker option to replace the existing C^3 heuristic with CDS.
The new behavior can be turned on by passing "--use-cache-directed-sort".
(the plan is to make it default in a next diff)

**Perf-impact**
clang-10 binary (built with LTO+AutoFDO/CSSPGO): wins on top of C^3 in [0.3%..0.8%]
rocksDB-8 binary (built with LTO+CSSPGO): wins on top of C^3 in [0.8%..1.5%]

Note that function layout affects the perf the most on older machines (with
smaller instruction/iTLB caches) and when huge pages are not enabled. The impact
on newer processors with huge pages enabled is likely neutral/minor.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D152840




More information about the All-commits mailing list