llvm-project/llvm/lib
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
..
Analysis CallBase: fix getFnAttr so it also checks the function 2022-04-03 23:19:23 -04:00
AsmParser Revert "Revert "[OpaquePtr][LLParser] Automatically detect opaque pointers in .ll files"" 2022-03-21 17:24:56 -07:00
BinaryFormat [CUDA] Add CUDA fatbinary magic 2022-03-14 20:08:31 -04:00
Bitcode Add DXContainer 2022-03-29 14:34:23 -05:00
Bitstream [Bitstream] Remove pessimizing move 2022-02-16 08:23:02 +01:00
CodeGen [CodeGen] Async unwind - add a pass to fix CFI information 2022-04-04 14:38:22 +01:00
DWARFLinker Cleanup includes: DebugInfo & CodeGen 2022-03-12 17:26:40 +01:00
DWP Cleanup LLVMObject headers 2022-02-10 21:13:44 +01:00
DebugInfo Apply clang-tidy fixes for readability-redundant-smartptr-get in GsymReader.cpp (NFC) 2022-03-28 09:18:30 -07:00
Debuginfod Fix buildbot failures from 7917b3c6. 2022-03-21 17:58:22 +00:00
Demangle ItaniumDemangler: Update BinaryExpr::match to match the ctor 2022-03-28 21:51:27 +00:00
ExecutionEngine Remove a top-level using-directive from EPCDebugObjectRegistrar.h 2022-03-28 15:14:20 +02:00
Extensions
FileCheck
Frontend [OMPIRBuilder] Support ordered clause specified without parameter 2022-04-01 16:17:29 +08:00
FuzzMutate Revert "[FuzzMutate] Don't insert instructions after musttail call" 2022-03-16 17:29:27 +01:00
Fuzzer
IR [ConstantFold] Fold zero-index GEPs with opaque pointers 2022-04-04 13:04:27 +02:00
IRReader
InterfaceStub Cleanup includes: DebugInfo & CodeGen 2022-03-12 17:26:40 +01:00
LTO Apply clang-tidy fixes for readability-redundant-smartptr-get in SummaryBasedOptimizations.cpp (NFC) 2022-03-28 09:18:31 -07:00
LineEditor [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
Linker [PseudoProbe] Do not emit pseudo probes when module is not probed. 2022-03-25 12:59:53 -07:00
MC [MC] Make MCAsmInfo::isAcceptableChar reflect MCAsmInfo::doesAllowAtInName 2022-03-29 14:01:32 -07:00
MCA [MCA] Removed unused variable. 2022-03-13 21:55:56 -07:00
ObjCopy Apply clang-tidy fixes for modernize-use-equals-default in ELFObject.cpp (NFC) 2022-03-28 09:18:25 -07:00
Object Apply clang-tidy fixes for readability-redundant-smartptr-get in TapiUniversal.cpp (NFC) 2022-03-28 09:18:36 -07:00
ObjectYAML [WebAssembly] Rename member in WasmYAML.h to avoid compiler warning 2022-03-14 09:09:43 -07:00
Option
Passes [NewPM] Add OptimizerEarly module extension point 2022-03-31 08:22:27 -07:00
ProfileData Cleanup includes: final pass 2022-03-29 09:00:21 +02:00
Remarks Cleanup includes: DebugInfo & CodeGen 2022-03-12 17:26:40 +01:00
Support [Support/BLAKE3] CMake: Remove the workaround that checks for "CC=ccache /path/to/clang" 2022-04-03 21:02:02 -07:00
TableGen [mlir] Split out AttrDef/TypeDef and pattern constructs from OpBase.td 2022-03-15 00:18:03 -07:00
Target [CodeGen] Async unwind - add a pass to fix CFI information 2022-04-04 14:38:22 +01:00
Testing Reapply "[cmake] Prefix gtest and gtest_main with "llvm_"." 2022-03-04 13:45:43 -08:00
TextAPI
ToolDrivers
Transforms [VPlan] Update VPInterleavedAccessInfo to use getVectorLoopRegion. 2022-04-04 10:26:39 +01:00
WindowsDriver Cleanup includes: WindowsDriver & WindowsManifest 2022-03-10 17:19:06 +01:00
WindowsManifest Cleanup includes: WindowsDriver & WindowsManifest 2022-03-10 17:19:06 +01:00
XRay [llvm] Use = default (NFC) 2022-02-06 22:18:35 -08:00
CMakeLists.txt [llvm-objcopy][NFC] Move core implementation of llvm-objcopy into separate library. 2022-02-17 13:11:42 +03:00