llvm-project/llvm
Momchil Velikov 980c3e6dd2 [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-CFG
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 that 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.

In order to accommodate backends which do not generate unwind info in
epilogues we compute an additional property "strong no call frame on
entry" which is set for the entry point of the function and for every
block reachable from the entry along a path that does not execute the
prologue. If this property holds, it takes precedence over the "has a
call frame" property.

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
2022-04-04 14:38:22 +01:00
..
benchmarks
bindings [NFC] Fix go binding build 2022-03-14 14:08:51 +08:00
cmake [cmake] Remove LLVM_USE_NEWPM option 2022-04-01 20:24:38 -07:00
docs [cmake] Remove LLVM_USE_NEWPM option 2022-04-01 20:24:38 -07:00
examples Reland "[ELF] Enable new passmanager plugin support for LTO" 2022-03-24 16:29:18 +01:00
include [CodeGen] Async unwind - add a pass to fix CFI information 2022-04-04 14:38:22 +01:00
lib [CodeGen] Async unwind - add a pass to fix CFI information 2022-04-04 14:38:22 +01:00
projects
resources
runtimes Revert "[runtimes] Create Tests.cmake if it does not exist" 2022-04-01 09:29:54 -07:00
test [CodeGen] Async unwind - add a pass to fix CFI information 2022-04-04 14:38:22 +01:00
tools Addressed post-commit comment https://reviews.llvm.org/D122746#inline-1175831 2022-04-01 14:10:22 -04:00
unittests Reland "[lit] Use sharding for GoogleTest format" 2022-04-03 22:35:45 -07:00
utils [gn build] llvm-lipo, llvm-libtool-darwin symlink targets now dep on binary 2022-04-04 09:20:49 -04:00
.clang-format
.clang-tidy
.gitattributes
.gitignore
CMakeLists.txt Add a cmake flag to turn `llvm_unreachable()` into builtin_trap() when assertions are disabled 2022-03-18 19:24:14 +00:00
CODE_OWNERS.TXT [CODE_OWNERS/CREDITS] Update my email address 2022-03-16 21:07:15 +00:00
CREDITS.TXT [CODE_OWNERS/CREDITS] Update my email address 2022-03-16 21:07:15 +00:00
LICENSE.TXT
README.txt
RELEASE_TESTERS.TXT
configure
llvm.spec.in

README.txt

The LLVM Compiler Infrastructure
================================

This directory and its subdirectories contain source code for LLVM,
a toolkit for the construction of highly optimized compilers,
optimizers, and runtime environments.

LLVM is open source software. You may freely distribute it under the terms of
the license agreement found in LICENSE.txt.

Please see the documentation provided in docs/ for further
assistance with LLVM, and in particular docs/GettingStarted.rst for getting
started with LLVM and docs/README.txt for an overview of LLVM's
documentation setup.

If you are writing a package for LLVM, see docs/Packaging.rst for our
suggestions.