| 1 | //===-- DwarfException.h - Dwarf Exception Framework -----------*- C++ -*--===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains support for writing dwarf exception info into asm files. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H |
| 14 | #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFEXCEPTION_H |
| 15 | |
| 16 | #include "EHStreamer.h" |
| 17 | #include "llvm/CodeGen/AsmPrinter.h" |
| 18 | #include "llvm/MC/MCDwarf.h" |
| 19 | |
| 20 | namespace llvm { |
| 21 | class MachineFunction; |
| 22 | class ARMTargetStreamer; |
| 23 | |
| 24 | class LLVM_LIBRARY_VISIBILITY DwarfCFIException : public EHStreamer { |
| 25 | /// Per-function flag to indicate if .cfi_personality should be emitted. |
| 26 | bool shouldEmitPersonality = false; |
| 27 | |
| 28 | /// Per-function flag to indicate if .cfi_personality must be emitted. |
| 29 | bool forceEmitPersonality = false; |
| 30 | |
| 31 | /// Per-function flag to indicate if .cfi_lsda should be emitted. |
| 32 | bool shouldEmitLSDA = false; |
| 33 | |
| 34 | /// Per-function flag to indicate if frame CFI info should be emitted. |
| 35 | bool shouldEmitCFI = false; |
| 36 | |
| 37 | /// Per-module flag to indicate if .cfi_section has beeen emitted. |
| 38 | bool hasEmittedCFISections = false; |
| 39 | |
| 40 | /// Vector of all personality functions seen so far in the module. |
| 41 | std::vector<const GlobalValue *> Personalities; |
| 42 | |
| 43 | void addPersonality(const GlobalValue *Personality); |
| 44 | |
| 45 | public: |
| 46 | //===--------------------------------------------------------------------===// |
| 47 | // Main entry points. |
| 48 | // |
| 49 | DwarfCFIException(AsmPrinter *A); |
| 50 | ~DwarfCFIException() override; |
| 51 | |
| 52 | /// Emit all exception information that should come after the content. |
| 53 | void endModule() override; |
| 54 | |
| 55 | /// Gather pre-function exception information. Assumes being emitted |
| 56 | /// immediately after the function entry point. |
| 57 | void beginFunction(const MachineFunction *MF) override; |
| 58 | |
| 59 | /// Gather and emit post-function exception information. |
| 60 | void endFunction(const MachineFunction *) override; |
| 61 | |
| 62 | void beginBasicBlockSection(const MachineBasicBlock &MBB) override; |
| 63 | void endBasicBlockSection(const MachineBasicBlock &MBB) override; |
| 64 | }; |
| 65 | |
| 66 | class LLVM_LIBRARY_VISIBILITY ARMException : public EHStreamer { |
| 67 | /// Per-function flag to indicate if frame CFI info should be emitted. |
| 68 | bool shouldEmitCFI = false; |
| 69 | |
| 70 | /// Per-module flag to indicate if .cfi_section has beeen emitted. |
| 71 | bool hasEmittedCFISections = false; |
| 72 | |
| 73 | void emitTypeInfos(unsigned TTypeEncoding, MCSymbol *TTBaseLabel) override; |
| 74 | ARMTargetStreamer &getTargetStreamer(); |
| 75 | |
| 76 | public: |
| 77 | //===--------------------------------------------------------------------===// |
| 78 | // Main entry points. |
| 79 | // |
| 80 | ARMException(AsmPrinter *A); |
| 81 | ~ARMException() override; |
| 82 | |
| 83 | /// Emit all exception information that should come after the content. |
| 84 | void endModule() override {} |
| 85 | |
| 86 | /// Gather pre-function exception information. Assumes being emitted |
| 87 | /// immediately after the function entry point. |
| 88 | void beginFunction(const MachineFunction *MF) override; |
| 89 | |
| 90 | /// Gather and emit post-function exception information. |
| 91 | void endFunction(const MachineFunction *) override; |
| 92 | |
| 93 | void markFunctionEnd() override; |
| 94 | }; |
| 95 | |
| 96 | class LLVM_LIBRARY_VISIBILITY AIXException : public EHStreamer { |
| 97 | /// This is AIX's compat unwind section, which unwinder would use |
| 98 | /// to find the location of LSDA area and personality rountine. |
| 99 | void emitExceptionInfoTable(const MCSymbol *LSDA, const MCSymbol *PerSym); |
| 100 | |
| 101 | public: |
| 102 | AIXException(AsmPrinter *A); |
| 103 | |
| 104 | void endModule() override {} |
| 105 | void beginFunction(const MachineFunction *MF) override {} |
| 106 | void endFunction(const MachineFunction *MF) override; |
| 107 | }; |
| 108 | } // End of namespace llvm |
| 109 | |
| 110 | #endif |
| 111 | |