LLVM 24.0.0git
WinException.h
Go to the documentation of this file.
1//===-- WinException.h - Windows Exception Handling ----------*- 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 windows exception info into asm files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H
14#define LLVM_LIB_CODEGEN_ASMPRINTER_WIN64EXCEPTION_H
15
16#include "EHStreamer.h"
17#include <vector>
18
19namespace llvm {
20class GlobalValue;
21class MachineFunction;
22class MCExpr;
23class MCSection;
24struct WinEHFuncInfo;
25
27 /// Per-function flag to indicate if personality info should be emitted.
28 bool shouldEmitPersonality = false;
29
30 /// Per-function flag to indicate if the LSDA should be emitted.
31 bool shouldEmitLSDA = false;
32
33 /// Per-function flag to indicate if frame moves info should be emitted.
34 bool shouldEmitMoves = false;
35
36 /// True if this is a 64-bit target and we should use image relative offsets.
37 bool useImageRel32 = false;
38
39 /// True if we are generating exception handling on Windows for ARM64.
40 bool isAArch64 = false;
41
42 /// Pointer to the current funclet entry BB.
43 const MachineBasicBlock *CurrentFuncletEntry = nullptr;
44
45 /// The section of the last funclet start.
46 MCSection *CurrentFuncletTextSection = nullptr;
47
48 /// The list of symbols to add to the ehcont section
49 std::vector<const MCSymbol *> EHContTargets;
50
51 void emitCSpecificHandlerTable(const MachineFunction *MF);
52
53 void emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo,
54 const MCSymbol *BeginLabel,
55 const MCSymbol *EndLabel, int State);
56
57 /// Emit the EH table data for 32-bit and 64-bit functions using
58 /// the __CxxFrameHandler3 personality.
59 void emitCXXFrameHandler3Table(const MachineFunction *MF);
60
61 /// Emit the EH table data for _except_handler3 and _except_handler4
62 /// personality functions. These are only used on 32-bit and do not use CFI
63 /// tables.
64 void emitExceptHandlerTable(const MachineFunction *MF);
65
66 void emitCLRExceptionTable(const MachineFunction *MF);
67
68 void computeIP2StateTable(
69 const MachineFunction *MF, const WinEHFuncInfo &FuncInfo,
70 SmallVectorImpl<std::pair<const MCExpr *, int>> &IPToStateTable);
71
72 /// Emits the label used with llvm.eh.recoverfp, which is used by
73 /// outlined funclets.
74 void emitEHRegistrationOffsetLabel(const WinEHFuncInfo &FuncInfo,
75 StringRef FLinkageName);
76
77 const MCExpr *create32bitRef(const MCSymbol *Value);
78 const MCExpr *create32bitRef(const GlobalValue *GV);
79 const MCExpr *getLabel(const MCSymbol *Label);
80 const MCExpr *getOffset(const MCSymbol *OffsetOf, const MCSymbol *OffsetFrom);
81 const MCExpr *getOffsetPlusOne(const MCSymbol *OffsetOf,
82 const MCSymbol *OffsetFrom);
83
84 /// Gets the offset that we should use in a table for a stack object with the
85 /// given index. For targets using CFI (Win64, etc), this is relative to the
86 /// established SP at the end of the prologue. For targets without CFI (Win32
87 /// only), it is relative to the frame pointer.
88 int getFrameIndexOffset(int FrameIndex, const WinEHFuncInfo &FuncInfo);
89
90 void endFuncletImpl();
91public:
92 //===--------------------------------------------------------------------===//
93 // Main entry points.
94 //
96 ~WinException() override;
97
98 /// Emit all exception information that should come after the content.
99 void endModule() override;
100
101 /// Gather pre-function exception information. Assumes being emitted
102 /// immediately after the function entry point.
103 void beginFunction(const MachineFunction *MF) override;
104
105 void markFunctionEnd() override;
106
107 /// Gather and emit post-function exception information.
108 void endFunction(const MachineFunction *) override;
109
110 /// Emit target-specific EH funclet machinery.
111 void beginFunclet(const MachineBasicBlock &MBB, MCSymbol *Sym) override;
112 void endFunclet() override;
113};
114}
115
116#endif
117
MachineBasicBlock & MBB
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_LIBRARY_VISIBILITY
Definition Compiler.h:137
static std::optional< int32_t > getOffset(ArrayRef< int32_t > Offsets, size_t Idx)
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:94
EHStreamer(AsmPrinter *A)
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:580
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
LLVM Value Representation.
Definition Value.h:75
void endFunction(const MachineFunction *) override
Gather and emit post-function exception information.
void markFunctionEnd() override
void beginFunclet(const MachineBasicBlock &MBB, MCSymbol *Sym) override
Emit target-specific EH funclet machinery.
void endModule() override
Emit all exception information that should come after the content.
WinException(AsmPrinter *A)
~WinException() override
void endFunclet() override
void beginFunction(const MachineFunction *MF) override
Gather pre-function exception information.
This is an optimization pass for GlobalISel generic memory operations.