[all-commits] [llvm/llvm-project] b4ad28: [CodeGen] Async unwind - add a pass to fix CFI inf...

Momchil Velikov via All-commits all-commits at lists.llvm.org
Mon Apr 11 05:36:52 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b4ad28da196d3c2b1bc064b4dc46c3e00e93438f
      https://github.com/llvm/llvm-project/commit/b4ad28da196d3c2b1bc064b4dc46c3e00e93438f
  Author: Momchil Velikov <momchil.velikov at arm.com>
  Date:   2022-04-11 (Mon, 11 Apr 2022)

  Changed paths:
    A llvm/include/llvm/CodeGen/CFIFixup.h
    M llvm/include/llvm/CodeGen/Passes.h
    M llvm/include/llvm/CodeGen/TargetFrameLowering.h
    M llvm/include/llvm/InitializePasses.h
    M llvm/include/llvm/Target/TargetMachine.h
    M llvm/include/llvm/Target/TargetOptions.h
    M llvm/lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
    A llvm/lib/CodeGen/CFIFixup.cpp
    M llvm/lib/CodeGen/CMakeLists.txt
    M llvm/lib/CodeGen/CodeGen.cpp
    M llvm/lib/CodeGen/TailDuplicator.cpp
    M llvm/lib/CodeGen/TargetFrameLoweringImpl.cpp
    M llvm/lib/CodeGen/TargetPassConfig.cpp
    M llvm/lib/Target/AArch64/AArch64.h
    M llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
    M llvm/lib/Target/AArch64/AArch64FrameLowering.h
    M llvm/lib/Target/AArch64/AArch64TargetMachine.cpp
    M llvm/test/CodeGen/AArch64/O0-pipeline.ll
    M llvm/test/CodeGen/AArch64/O3-pipeline.ll
    M llvm/test/CodeGen/AArch64/arm64-fp128.ll
    M llvm/test/CodeGen/AArch64/arm64-opt-remarks-lazy-bfi.ll
    M llvm/test/CodeGen/AArch64/arm64-shrink-wrapping.ll
    A llvm/test/CodeGen/AArch64/cfi-fixup.mir
    M llvm/test/CodeGen/AArch64/fast-isel-branch-cond-split.ll
    M llvm/test/CodeGen/AArch64/nomerge.ll
    M llvm/test/CodeGen/AArch64/optimize-cond-branch.ll
    M llvm/test/CodeGen/AArch64/sve-alloca.ll

  Log Message:
  -----------
  [CodeGen] Async unwind - add a pass to fix CFI information

This pass inserts the necessary CFI instructions to compensate for the
inconsistency of the call-frame information caused by linear (non-CGA
aware) nature of the unwind tables.

Unlike the `CFIInstrInserer` pass, this one almost always emits only
`.cfi_remember_state`/`.cfi_restore_state`, which results in smaller
unwind tables and also transparently handles custom unwind info
extensions like CFA offset adjustement and save locations of SVE
registers.

This pass takes advantage of the constraints taht LLVM imposes on the
placement of save/restore points (cf. `ShrinkWrap.cpp`):

  * there is a single basic block, containing the function prologue

  * possibly multiple epilogue blocks, where each epilogue block is
    complete and self-contained, i.e. CSR restore instructions (and the
    corresponding CFI instructions are not split across two or more
    blocks.

  * prologue and epilogue blocks are outside of any loops

Thus, during execution, at the beginning and at the end of each basic
block the function can be in one of two states:

  - "has a call frame", if the function has executed the prologue, or
     has not executed any epilogue

  - "does not have a call frame", if the function has not executed the
    prologue, or has executed an epilogue

These properties can be computed for each basic block by a single RPO
traversal.

>From the point of view of the unwind tables, the "has/does not have
call frame" state at beginning of each block is determined by the
state at the end of the previous block, in layout order.

Where these states differ, we insert compensating CFI instructions,
which come in two flavours:

- CFI instructions, which reset the unwind table state to the
    initial one.  This is done by a target specific hook and is
    expected to be trivial to implement, for example it could be:
```
     .cfi_def_cfa <sp>, 0
     .cfi_same_value <rN>
     .cfi_same_value <rN-1>
     ...
```
where `<rN>` are the callee-saved registers.

- CFI instructions, which reset the unwind table state to the one
    created by the function prologue. These are the sequence:
```
       .cfi_restore_state
       .cfi_remember_state
```
In this case we also insert a `.cfi_remember_state` after the
last CFI instruction in the function prologue.

Reviewed By: MaskRay, danielkiss, chill

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




More information about the All-commits mailing list