[all-commits] [llvm/llvm-project] 901a81: [clang] Optimize castToDeclContext for 2% improvem...

Pol M via All-commits all-commits at lists.llvm.org
Thu Jan 4 06:42:49 PST 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 901a8160a8cb3bda3558fffb8e109485c42affe5
      https://github.com/llvm/llvm-project/commit/901a8160a8cb3bda3558fffb8e109485c42affe5
  Author: Pol M <polmarcetsarda at gmail.com>
  Date:   2024-01-04 (Thu, 04 Jan 2024)

  Changed paths:
    M clang/include/clang/AST/DeclCXX.h
    M clang/lib/AST/DeclBase.cpp
    M clang/utils/TableGen/ClangASTNodesEmitter.cpp
    M clang/utils/TableGen/TableGen.cpp
    M clang/utils/TableGen/TableGenBackends.h

  Log Message:
  -----------
  [clang] Optimize castToDeclContext for 2% improvement in build times (#76825)

Optimize castToDeclContext for 2% improvement in build times
castToDeclContext is a heavily used function, and as such, it needs to
be kept as slim as feasible to preserve as much performance as possible.
To this end, it was observed that the function was generating suboptimal
assembly code, and putting the most common execution path in the longest
sequence of instructions. This patch addresses this by guiding the
compiler towards generating a lookup table of offsets, which can be used
to perform an addition on the pointer. This results in a 1-2%
improvement on debug builds (and a negligible improvement on release).

To achieve this, the switch was simplified to flatten the if statements
in the default branch. In order to make the values of the switch more
compact, encouraging LLVM to generate a look-up table instead of a jump
table, the AST TableGen generator was modified so it can take order
priority based on class inheritance. This combination allowed for a more
optimal generation of the function. Of note, 2 other functions with an
equivalent structure also needed to be modified.

Fixes #76824




More information about the All-commits mailing list