LLVM  14.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 
15 namespace llvm {
16 class MCSection;
17 class MCStreamer;
18 class MCSymbol;
19 
20 namespace WinEH {
21 struct Instruction {
22  const MCSymbol *Label;
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 
39 struct 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;
47  MCSection *TextSection = nullptr;
49 
50  bool HandlesUnwind = false;
51  bool HandlesExceptions = false;
52  bool EmitAttempted = false;
53 
54  int LastFrameInst = -1;
55  const FrameInfo *ChainedParent = nullptr;
56  std::vector<Instruction> Instructions;
58 
59  FrameInfo() = default;
60  FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
61  : Begin(BeginFuncEHLabel), Function(Function) {}
62  FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel,
63  const FrameInfo *ChainedParent)
64  : Begin(BeginFuncEHLabel), Function(Function),
66 
67  bool empty() const {
68  if (!Instructions.empty())
69  return false;
70  for (const auto &E : EpilogMap)
71  if (!E.second.empty())
72  return false;
73  return true;
74  }
75 };
76 
78 public:
79  virtual ~UnwindEmitter();
80 
81  /// This emits the unwind info sections (.pdata and .xdata in PE/COFF).
82  virtual void Emit(MCStreamer &Streamer) const = 0;
83  virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI,
84  bool HandlerData) const = 0;
85 };
86 }
87 }
88 
89 #endif
llvm::WinEH::Instruction::Label
const MCSymbol * Label
Definition: MCWinEH.h:22
llvm::WinEH::Instruction::Offset
unsigned Offset
Definition: MCWinEH.h:23
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::WinEH::FrameInfo::FuncletOrFuncEnd
const MCSymbol * FuncletOrFuncEnd
Definition: MCWinEH.h:42
Reg
unsigned Reg
Definition: MachineSink.cpp:1558
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::WinEH::Instruction::Register
unsigned Register
Definition: MCWinEH.h:24
llvm::Function
Definition: Function.h:62
llvm::WinEH::FrameInfo::FrameInfo
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel, const FrameInfo *ChainedParent)
Definition: MCWinEH.h:62
MapVector.h
llvm::WinEH::FrameInfo::EpilogMap
MapVector< MCSymbol *, std::vector< Instruction > > EpilogMap
Definition: MCWinEH.h:57
llvm::WinEH::FrameInfo::TextSection
MCSection * TextSection
Definition: MCWinEH.h:47
llvm::WinEH::Instruction::operator!=
bool operator!=(const Instruction &I) const
Definition: MCWinEH.h:36
llvm::WinEH::FrameInfo::PackedInfo
uint32_t PackedInfo
Definition: MCWinEH.h:48
llvm::MapVector
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:37
llvm::WinEH::FrameInfo::ExceptionHandler
const MCSymbol * ExceptionHandler
Definition: MCWinEH.h:43
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::WinEH::FrameInfo::EmitAttempted
bool EmitAttempted
Definition: MCWinEH.h:52
llvm::WinEH::FrameInfo::LastFrameInst
int LastFrameInst
Definition: MCWinEH.h:54
llvm::WinEH::UnwindEmitter::EmitUnwindInfo
virtual void EmitUnwindInfo(MCStreamer &Streamer, FrameInfo *FI, bool HandlerData) const =0
llvm::WinEH::FrameInfo::empty
bool empty() const
Definition: MCWinEH.h:67
llvm::WinEH::FrameInfo::PrologEnd
const MCSymbol * PrologEnd
Definition: MCWinEH.h:45
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::WinEH::Instruction::Operation
unsigned Operation
Definition: MCWinEH.h:25
llvm::WinEH::Instruction::operator==
bool operator==(const Instruction &I) const
Definition: MCWinEH.h:30
llvm::WinEH::UnwindEmitter
Definition: MCWinEH.h:77
uint32_t
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
llvm::Register
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
llvm::WinEH::UnwindEmitter::~UnwindEmitter
virtual ~UnwindEmitter()
Definition: MCWinEH.cpp:21
llvm::WinEH::UnwindEmitter::Emit
virtual void Emit(MCStreamer &Streamer) const =0
This emits the unwind info sections (.pdata and .xdata in PE/COFF).
llvm::WinEH::FrameInfo::FrameInfo
FrameInfo(const MCSymbol *Function, const MCSymbol *BeginFuncEHLabel)
Definition: MCWinEH.h:60
llvm::WinEH::FrameInfo::HandlesExceptions
bool HandlesExceptions
Definition: MCWinEH.h:51
llvm::AMDGPU::SendMsg::Op
Op
Definition: SIDefines.h:325
llvm::ExceptionHandling::WinEH
@ WinEH
Windows Exception Handling.
llvm::WinEH::FrameInfo::End
const MCSymbol * End
Definition: MCWinEH.h:41
llvm::WinEH::FrameInfo::Begin
const MCSymbol * Begin
Definition: MCWinEH.h:40
llvm::WinEH::FrameInfo
Definition: MCWinEH.h:39
llvm::WinEH::FrameInfo::HandlesUnwind
bool HandlesUnwind
Definition: MCWinEH.h:50
llvm::WinEH::Instruction
Definition: MCWinEH.h:21
llvm::WinEH::Instruction::Instruction
Instruction(unsigned Op, MCSymbol *L, unsigned Reg, unsigned Off)
Definition: MCWinEH.h:27
llvm::WinEH::FrameInfo::FrameInfo
FrameInfo()=default
llvm::WinEH::FrameInfo::Instructions
std::vector< Instruction > Instructions
Definition: MCWinEH.h:56
llvm::WinEH::FrameInfo::ChainedParent
const FrameInfo * ChainedParent
Definition: MCWinEH.h:55
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::WinEH::FrameInfo::Symbol
const MCSymbol * Symbol
Definition: MCWinEH.h:46