[all-commits] [llvm/llvm-project] e280e4: Add a pass to garbage-collect empty basic blocks a...

Rahman Lavaee via All-commits all-commits at lists.llvm.org
Tue Aug 22 15:42:35 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e280e406c2e34ce29e1e71da7cd3a284ea112ce8
      https://github.com/llvm/llvm-project/commit/e280e406c2e34ce29e1e71da7cd3a284ea112ce8
  Author: Rahman Lavaee <rahmanl at google.com>
  Date:   2023-08-22 (Tue, 22 Aug 2023)

  Changed paths:
    M llvm/include/llvm/CodeGen/Passes.h
    M llvm/include/llvm/InitializePasses.h
    M llvm/lib/CodeGen/CMakeLists.txt
    A llvm/lib/CodeGen/GCEmptyBasicBlocks.cpp
    M llvm/lib/CodeGen/TargetPassConfig.cpp
    A llvm/test/CodeGen/X86/basic-block-sections-labels-empty-block.ll
    A llvm/test/CodeGen/X86/gc-empty-basic-blocks.ll

  Log Message:
  -----------
  Add a pass to garbage-collect empty basic blocks after code generation.

Propeller and pseudo-probes map profiles back to Machine IR via basic block addresses that are stored in metadata sections.
Empty basic blocks (basic blocks without real code) obfuscate the profile mapping because their addresses collide with their next basic blocks.
For instance, the fallthrough block of an empty block should always be adjacent to it. Otherwise, a completely unnecessary jump would be added.
This patch adds a MachineFunction pass named `GCEmptyBasicBlocks` which attempts to garbage-collect the empty blocks before the `BasicBlockSections` and pass.
This pass removes each empty basic block after redirecting its incoming edges to its fall-through block.
The garbage-collection is not complete. We keep the empty block in 4 cases:
      1. The empty block is an exception handling pad.
      2. The empty block has its address taken.
      3. The empty block is the last block of the function and it has
         predecessors.
      4. The empty block is the only block of the function.
The first three cases are extremely rare in normal code (no cases for the clang binary). Removing the blocks under the first two cases requires modifying exception handling structures and operands of non-terminator instructions -- which is doable but not worth the additional complexity in the pass.

Reviewed By: tmsriram

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




More information about the All-commits mailing list