LLVM 23.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;
27 uint16_t Register2; // For 2-register ops (e.g. PUSH2)
29
30 Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
31 : Label(L), Offset(Off), Register(Reg), Register2(0), Operation(Op) {}
32
33 Instruction(unsigned Op, MCSymbol *L, unsigned Reg1, unsigned Reg2,
34 unsigned Off)
35 : Label(L), Offset(Off), Register(Reg1), Register2(Reg2), Operation(Op) {}
36
37 bool operator==(const Instruction &I) const {
38 // Check whether two instructions refer to the same operation
39 // applied at a different spot (i.e. pointing at a different label).
40 return Offset == I.Offset && Register == I.Register &&
41 Register2 == I.Register2 && Operation == I.Operation;
42 }
43 bool operator!=(const Instruction &I) const { return !(*this == I); }
44};
45
46struct FrameInfo {
47 const MCSymbol *Begin = nullptr;
48 const MCSymbol *End = nullptr;
49 const MCSymbol *FuncletOrFuncEnd = nullptr;
50 const MCSymbol *ExceptionHandler = nullptr;
51 const MCSymbol *Function = nullptr;
53 const MCSymbol *PrologEnd = nullptr;
54 const MCSymbol *Symbol = nullptr;
58
59 bool HandlesUnwind = false;
60 bool HandlesExceptions = false;
61 bool EmitAttempted = false;
62 bool Fragment = false;
63 constexpr static uint8_t DefaultVersion = 1;
65
66 int LastFrameInst = -1;
68 std::vector<Instruction> Instructions;
69 struct Epilog {
70 std::vector<Instruction> Instructions;
71 unsigned Condition;
72 const MCSymbol *Start = nullptr;
73 const MCSymbol *End = nullptr;
74 const MCSymbol *UnwindV2Start = nullptr;
76 };
78
79 // For splitting unwind info of large functions
80 struct Segment {
81 int64_t Offset;
82 int64_t Length;
84 MCSymbol *Symbol = nullptr;
85 // Map an Epilog's symbol to its offset within the function.
87
88 Segment(int64_t Offset, int64_t Length, bool HasProlog = false)
90 };
91
92 std::vector<Segment> Segments;
93
94 FrameInfo() = default;
95 FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
96 : Begin(BeginFuncEHLabel), Function(Function) {}
97 FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
99 : Begin(BeginFuncEHLabel), Function(Function),
101
102 bool empty() const {
103 if (!Instructions.empty())
104 return false;
105 for (const auto &E : EpilogMap)
106 if (!E.second.Instructions.empty())
107 return false;
108 return true;
109 }
110};
111
113public:
114 virtual ~UnwindEmitter();
115
116 /// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
117 virtual void Emit(MCStreamer &Streamer) const = 0;
118 virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI,
119 bool HandlerData) const = 0;
120};
121} // namespace WinEH
122} // namespace llvm
123
124#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:57
Register Reg
This file implements a map that provides insertion order iteration.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:573
Streaming machine code generation interface.
Definition MCStreamer.h:222
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:38
Represents a location in source code.
Definition SMLoc.h:22
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.
DWARFExpression::Operation Op
std::vector< Instruction > Instructions
Definition MCWinEH.h:70
const MCSymbol * Start
Definition MCWinEH.h:72
const MCSymbol * UnwindV2Start
Definition MCWinEH.h:74
Segment(int64_t Offset, int64_t Length, bool HasProlog=false)
Definition MCWinEH.h:88
MapVector< MCSymbol *, int64_t > Epilogs
Definition MCWinEH.h:86
bool empty() const
Definition MCWinEH.h:102
std::vector< Instruction > Instructions
Definition MCWinEH.h:68
std::vector< Segment > Segments
Definition MCWinEH.h:92
const MCSymbol * Function
Definition MCWinEH.h:51
MCSection * TextSection
Definition MCWinEH.h:55
FrameInfo * ChainedParent
Definition MCWinEH.h:67
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel, FrameInfo *ChainedParent)
Definition MCWinEH.h:97
const MCSymbol * Symbol
Definition MCWinEH.h:54
const MCSymbol * PrologEnd
Definition MCWinEH.h:53
MapVector< MCSymbol *, Epilog > EpilogMap
Definition MCWinEH.h:77
uint32_t PrologCodeBytes
Definition MCWinEH.h:57
const MCSymbol * FuncletOrFuncEnd
Definition MCWinEH.h:49
const MCSymbol * End
Definition MCWinEH.h:48
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
Definition MCWinEH.h:95
const MCSymbol * Begin
Definition MCWinEH.h:47
static constexpr uint8_t DefaultVersion
Definition MCWinEH.h:63
const MCSymbol * ExceptionHandler
Definition MCWinEH.h:50
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
Definition MCWinEH.h:30
const MCSymbol * Label
Definition MCWinEH.h:24
bool operator==(const Instruction &I) const
Definition MCWinEH.h:37
Instruction(unsigned Op, MCSymbol *L, unsigned Reg1, unsigned Reg2, unsigned Off)
Definition MCWinEH.h:33
bool operator!=(const Instruction &I) const
Definition MCWinEH.h:43