Support unwinding from inline assembly
authorcynecx <me@cynecx.net>
Thu, 13 May 2021 18:05:11 +0000 (19:05 +0100)
committerAmanieu d'Antras <amanieu@gmail.com>
Thu, 13 May 2021 18:13:03 +0000 (19:13 +0100)
commit8ec9fd483949ca3b23053effcac226dcc56e7a95
treec85cb91a5668b9af25f8e87a1679cf9bb451bef4
parent9d3eb7885d916b22bc673334f71a10e3b2835174
Support unwinding from inline assembly

I've taken the following steps to add unwinding support from inline assembly:

1) Add a new `unwind` "attribute" (like `sideeffect`) to the asm syntax:

```
invoke void asm sideeffect unwind "call thrower", "~{dirflag},~{fpsr},~{flags}"()
    to label %exit unwind label %uexit
```

2.) Add Bitcode writing/reading support + LLVM-IR parsing.

3.) Emit EHLabels around inline assembly lowering (SelectionDAGBuilder + GlobalISel) when `InlineAsm::canThrow` is enabled.

4.) Tweak InstCombineCalls/InlineFunction pass to not mark inline assembly "calls" as nounwind.

5.) Add clang support by introducing a new clobber: "unwind", which lower to the `canThrow` being enabled.

6.) Don't allow unwinding callbr.

Reviewed By: Amanieu

Differential Revision: https://reviews.llvm.org/D95745
35 files changed:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Basic/TargetInfo.cpp
clang/lib/CodeGen/CGStmt.cpp
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/CodeGenCXX/unwind-inline-asm.cpp [new file with mode: 0644]
llvm/bindings/go/llvm/ir.go
llvm/include/llvm-c/Core.h
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/InlineAsm.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
llvm/lib/IR/AsmWriter.cpp
llvm/lib/IR/ConstantsContext.h
llvm/lib/IR/Core.cpp
llvm/lib/IR/InlineAsm.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/lib/Transforms/Utils/ValueMapper.cpp
llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-unwind-inline-asm.ll [new file with mode: 0644]
llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unwind-inline-asm.ll [new file with mode: 0644]
llvm/test/CodeGen/AArch64/GlobalISel/unwind-inline-asm.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/no-seh-unwind-inline-asm-codegen.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/no-unwind-inline-asm-codegen.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/seh-unwind-inline-asm-codegen.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/sjlj-unwind-inline-asm-codegen.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/unwind-inline-asm-codegen.ll [new file with mode: 0644]
llvm/test/Transforms/Inline/no-unwind-inline-asm.ll [new file with mode: 0644]
llvm/test/Transforms/Inline/unwind-inline-asm.ll [new file with mode: 0644]
llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll [new file with mode: 0644]
llvm/test/Transforms/InstCombine/unwind-inline-asm.ll [new file with mode: 0644]