LLVM 22.0.0git
MCWinEH.h
Go to the documentation of this file.
1//===- MCWinEH.h - Windows Unwinding Support --------------------*- 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#ifndef LLVM_MC_MCWINEH_H
10#define LLVM_MC_MCWINEH_H
11
12#include "llvm/ADT/MapVector.h"
14#include "llvm/Support/SMLoc.h"
15#include <vector>
16
17namespace llvm {
18class MCSection;
19class MCStreamer;
20class MCSymbol;
21
22namespace WinEH {
25 unsigned Offset;
26 unsigned Register;
27 unsigned Operation;
28
29 Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
30 : Label(L), Offset(Off), Register(Reg), Operation(Op) {}
31
32 bool operator==(const Instruction &I) const {
33 // Check whether two instructions refer to the same operation
34 // applied at a different spot (i.e. pointing at a different label).
35 return Offset == I.Offset && Register == I.Register &&
36 Operation == I.Operation;
37 }
38 bool operator!=(const Instruction &I) const { return !(*this == I); }
39};
40
41struct FrameInfo {
42 const MCSymbol *Begin = nullptr;
43 const MCSymbol *End = nullptr;
44 const MCSymbol *FuncletOrFuncEnd = nullptr;
45 const MCSymbol *ExceptionHandler = nullptr;
46 const MCSymbol *Function = nullptr;
48 const MCSymbol *PrologEnd = nullptr;
49 const MCSymbol *Symbol = nullptr;
53
54 bool HandlesUnwind = false;
55 bool HandlesExceptions = false;
56 bool EmitAttempted = false;
57 bool Fragment = false;
58 constexpr static uint8_t DefaultVersion = 1;
60
61 int LastFrameInst = -1;
62 const FrameInfo *ChainedParent = nullptr;
63 std::vector<Instruction> Instructions;
64 struct Epilog {
65 std::vector<Instruction> Instructions;
66 unsigned Condition;
67 const MCSymbol *Start = nullptr;
68 const MCSymbol *End = nullptr;
69 const MCSymbol *UnwindV2Start = nullptr;
71 };
73
74 // For splitting unwind info of large functions
75 struct Segment {
76 int64_t Offset;
77 int64_t Length;
79 MCSymbol *Symbol = nullptr;
80 // Map an Epilog's symbol to its offset within the function.
82
83 Segment(int64_t Offset, int64_t Length, bool HasProlog = false)
85 };
86
87 std::vector<Segment> Segments;
88
89 FrameInfo() = default;
90 FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
91 : Begin(BeginFuncEHLabel), Function(Function) {}
92 FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
94 : Begin(BeginFuncEHLabel), Function(Function),
96
97 bool empty() const {
98 if (!Instructions.empty())
99 return false;
100 for (const auto &E : EpilogMap)
101 if (!E.second.Instructions.empty())
102 return false;
103 return true;
104 }
105};
106
108public:
109 virtual ~UnwindEmitter();
110
111 /// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
112 virtual void Emit(MCStreamer &Streamer) const = 0;
113 virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI,
114 bool HandlerData) const = 0;
115};
116}
117}
118
119#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
#define I(x, y, z)
Definition: MD5.cpp:58
Register Reg
This file implements a map that provides insertion order iteration.
This class represents an Operation in the Expression.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
Streaming machine code generation interface.
Definition: MCStreamer.h:220
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
Represents a location in source code.
Definition: SMLoc.h:23
virtual void Emit(MCStreamer &Streamer) const =0
This emits the unwind info sections (.pdata and .xdata in PE/COFF).
virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI, bool HandlerData) const =0
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ WinEH
Windows Exception Handling.
const MCSymbol * End
Definition: MCWinEH.h:68
std::vector< Instruction > Instructions
Definition: MCWinEH.h:65
const MCSymbol * Start
Definition: MCWinEH.h:67
const MCSymbol * UnwindV2Start
Definition: MCWinEH.h:69
Segment(int64_t Offset, int64_t Length, bool HasProlog=false)
Definition: MCWinEH.h:83
MapVector< MCSymbol *, int64_t > Epilogs
Definition: MCWinEH.h:81
bool empty() const
Definition: MCWinEH.h:97
std::vector< Instruction > Instructions
Definition: MCWinEH.h:63
std::vector< Segment > Segments
Definition: MCWinEH.h:87
MCSection * TextSection
Definition: MCWinEH.h:50
const MCSymbol * Symbol
Definition: MCWinEH.h:49
const MCSymbol * PrologEnd
Definition: MCWinEH.h:48
MapVector< MCSymbol *, Epilog > EpilogMap
Definition: MCWinEH.h:72
uint32_t PrologCodeBytes
Definition: MCWinEH.h:52
const MCSymbol * FuncletOrFuncEnd
Definition: MCWinEH.h:44
const MCSymbol * End
Definition: MCWinEH.h:43
uint32_t PackedInfo
Definition: MCWinEH.h:51
const FrameInfo * ChainedParent
Definition: MCWinEH.h:62
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
Definition: MCWinEH.h:90
const MCSymbol * Begin
Definition: MCWinEH.h:42
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel, const FrameInfo *ChainedParent)
Definition: MCWinEH.h:92
static constexpr uint8_t DefaultVersion
Definition: MCWinEH.h:58
const MCSymbol * ExceptionHandler
Definition: MCWinEH.h:45
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
Definition: MCWinEH.h:29
const MCSymbol * Label
Definition: MCWinEH.h:24
bool operator==(const Instruction &I) const
Definition: MCWinEH.h:32
bool operator!=(const Instruction &I) const
Definition: MCWinEH.h:38