LLVM 19.0.0git
ARMException.cpp
Go to the documentation of this file.
1//===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===//
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 DWARF exception info into asm files.
10//
11//===----------------------------------------------------------------------===//
12
13#include "DwarfException.h"
14#include "llvm/ADT/Twine.h"
17#include "llvm/IR/Function.h"
18#include "llvm/MC/MCAsmInfo.h"
19#include "llvm/MC/MCStreamer.h"
20using namespace llvm;
21
23
25
26ARMTargetStreamer &ARMException::getTargetStreamer() {
27 MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
28 return static_cast<ARMTargetStreamer &>(TS);
29}
30
33 getTargetStreamer().emitFnStart();
34 // See if we need call frame info.
36 assert(CFISecType != AsmPrinter::CFISection::EH &&
37 "non-EH CFI not yet supported in prologue with EHABI lowering");
38
39 if (CFISecType == AsmPrinter::CFISection::Debug) {
40 if (!hasEmittedCFISections) {
42 Asm->OutStreamer->emitCFISections(false, true);
43 hasEmittedCFISections = true;
44 }
45
46 shouldEmitCFI = true;
47 Asm->OutStreamer->emitCFIStartProc(false);
48 }
49}
50
52 if (shouldEmitCFI)
53 Asm->OutStreamer->emitCFIEndProc();
54}
55
56/// endFunction - Gather and emit post-function exception information.
57///
59 ARMTargetStreamer &ATS = getTargetStreamer();
60 const Function &F = MF->getFunction();
61 const Function *Per = nullptr;
62 if (F.hasPersonalityFn())
63 Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
64 bool forceEmitPersonality =
65 F.hasPersonalityFn() && !isNoOpWithoutInvoke(classifyEHPersonality(Per)) &&
66 F.needsUnwindTableEntry();
67 bool shouldEmitPersonality = forceEmitPersonality ||
68 !MF->getLandingPads().empty();
70 !shouldEmitPersonality)
71 ATS.emitCantUnwind();
72 else if (shouldEmitPersonality) {
73 // Emit references to personality.
74 if (Per) {
75 MCSymbol *PerSym = Asm->getSymbol(Per);
76 ATS.emitPersonality(PerSym);
77 }
78
79 // Emit .handlerdata directive.
80 ATS.emitHandlerData();
81
82 // Emit actual exception table
84 }
85
87 ATS.emitFnEnd();
88}
89
90void ARMException::emitTypeInfos(unsigned TTypeEncoding,
91 MCSymbol *TTBaseLabel) {
92 const MachineFunction *MF = Asm->MF;
93 const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
94 const std::vector<unsigned> &FilterIds = MF->getFilterIds();
95
96 bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
97
98 int Entry = 0;
99 // Emit the Catch TypeInfos.
100 if (VerboseAsm && !TypeInfos.empty()) {
101 Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
102 Asm->OutStreamer->addBlankLine();
103 Entry = TypeInfos.size();
104 }
105
106 for (const GlobalValue *GV : reverse(TypeInfos)) {
107 if (VerboseAsm)
108 Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
109 Asm->emitTTypeReference(GV, TTypeEncoding);
110 }
111
112 Asm->OutStreamer->emitLabel(TTBaseLabel);
113
114 // Emit the Exception Specifications.
115 if (VerboseAsm && !FilterIds.empty()) {
116 Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
117 Asm->OutStreamer->addBlankLine();
118 Entry = 0;
119 }
120 for (std::vector<unsigned>::const_iterator
121 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
122 unsigned TypeID = *I;
123 if (VerboseAsm) {
124 --Entry;
125 if (TypeID != 0)
126 Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
127 }
128
129 Asm->emitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
130 TTypeEncoding);
131 }
132}
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
ARMException(AsmPrinter *A)
~ARMException() override
void endFunction(const MachineFunction *) override
Gather and emit post-function exception information.
void markFunctionEnd() override
void beginFunction(const MachineFunction *MF) override
Gather pre-function exception information.
virtual void emitPersonality(const MCSymbol *Personality)
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:85
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:704
CFISection getModuleCFISectionType() const
Get the CFISection type for the module.
Definition: AsmPrinter.h:443
virtual void emitTTypeReference(const GlobalValue *GV, unsigned Encoding)
Emit reference to a ttype global with a specified encoding.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:91
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:103
CFISection getFunctionCFISectionType(const Function &F) const
Get the CFISection type for a function.
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:100
@ Debug
Emit .debug_frame.
Emits exception handling directives.
Definition: EHStreamer.h:30
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:33
MCSymbol * emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:380
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:663
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:780
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:40
Target specific streamer interface.
Definition: MCStreamer.h:93
const std::vector< unsigned > & getFilterIds() const
Return a reference to the typeids encoding filters used in the current function.
const std::vector< const GlobalValue * > & getTypeInfos() const
Return a reference to the C++ typeinfo for the current function.
Function & getFunction()
Return the LLVM function that this machine code represents.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:54
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:419
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.