LLVM 20.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"
13#include <vector>
14
15namespace llvm {
16class MCSection;
17class MCStreamer;
18class MCSymbol;
19
20namespace WinEH {
23 unsigned Offset;
24 unsigned Register;
25 unsigned Operation;
26
27 Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
28 : Label(L), Offset(Off), Register(Reg), Operation(Op) {}
29
30 bool operator==(const Instruction &I) const {
31 // Check whether two instructions refer to the same operation
32 // applied at a different spot (i.e. pointing at a different label).
33 return Offset == I.Offset && Register == I.Register &&
34 Operation == I.Operation;
35 }
36 bool operator!=(const Instruction &I) const { return !(*this == I); }
37};
38
39struct FrameInfo {
40 const MCSymbol *Begin = nullptr;
41 const MCSymbol *End = nullptr;
42 const MCSymbol *FuncletOrFuncEnd = nullptr;
43 const MCSymbol *ExceptionHandler = nullptr;
44 const MCSymbol *Function = nullptr;
45 const MCSymbol *PrologEnd = nullptr;
46 const MCSymbol *Symbol = nullptr;
50
51 bool HandlesUnwind = false;
52 bool HandlesExceptions = false;
53 bool EmitAttempted = false;
54 bool Fragment = false;
55
56 int LastFrameInst = -1;
57 const FrameInfo *ChainedParent = nullptr;
58 std::vector<Instruction> Instructions;
59 struct Epilog {
60 std::vector<Instruction> Instructions;
61 unsigned Condition;
63 };
65
66 // For splitting unwind info of large functions
67 struct Segment {
68 int64_t Offset;
69 int64_t Length;
71 MCSymbol *Symbol = nullptr;
72 // Map an Epilog's symbol to its offset within the function.
74
75 Segment(int64_t Offset, int64_t Length, bool HasProlog = false)
77 };
78
79 std::vector<Segment> Segments;
80
81 FrameInfo() = default;
82 FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
83 : Begin(BeginFuncEHLabel), Function(Function) {}
84 FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
86 : Begin(BeginFuncEHLabel), Function(Function),
88
89 bool empty() const {
90 if (!Instructions.empty())
91 return false;
92 for (const auto &E : EpilogMap)
93 if (!E.second.Instructions.empty())
94 return false;
95 return true;
96 }
97};
98
100public:
101 virtual ~UnwindEmitter();
102
103 /// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
104 virtual void Emit(MCStreamer &Streamer) const = 0;
105 virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI,
106 bool HandlerData) const = 0;
107};
108}
109}
110
111#endif
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
#define I(x, y, z)
Definition: MD5.cpp:58
unsigned 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:36
Streaming machine code generation interface.
Definition: MCStreamer.h:213
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
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
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.
std::vector< Instruction > Instructions
Definition: MCWinEH.h:60
Segment(int64_t Offset, int64_t Length, bool HasProlog=false)
Definition: MCWinEH.h:75
MapVector< MCSymbol *, int64_t > Epilogs
Definition: MCWinEH.h:73
bool empty() const
Definition: MCWinEH.h:89
std::vector< Instruction > Instructions
Definition: MCWinEH.h:58
std::vector< Segment > Segments
Definition: MCWinEH.h:79
MCSection * TextSection
Definition: MCWinEH.h:47
const MCSymbol * Symbol
Definition: MCWinEH.h:46
const MCSymbol * PrologEnd
Definition: MCWinEH.h:45
MapVector< MCSymbol *, Epilog > EpilogMap
Definition: MCWinEH.h:64
uint32_t PrologCodeBytes
Definition: MCWinEH.h:49
const MCSymbol * FuncletOrFuncEnd
Definition: MCWinEH.h:42
const MCSymbol * End
Definition: MCWinEH.h:41
uint32_t PackedInfo
Definition: MCWinEH.h:48
const FrameInfo * ChainedParent
Definition: MCWinEH.h:57
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
Definition: MCWinEH.h:82
const MCSymbol * Begin
Definition: MCWinEH.h:40
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel, const FrameInfo *ChainedParent)
Definition: MCWinEH.h:84
const MCSymbol * ExceptionHandler
Definition: MCWinEH.h:43
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
Definition: MCWinEH.h:27
const MCSymbol * Label
Definition: MCWinEH.h:22
bool operator==(const Instruction &I) const
Definition: MCWinEH.h:30
bool operator!=(const Instruction &I) const
Definition: MCWinEH.h:36