LLVM  16.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"
20 using namespace llvm;
21 
23 
24 ARMException::~ARMException() = default;
25 
26 ARMTargetStreamer &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();
55 }
56 
57 /// endFunction - Gather and emit post-function exception information.
58 ///
60  ARMTargetStreamer &ATS = getTargetStreamer();
61  const Function &F = MF->getFunction();
62  const Function *Per = nullptr;
63  if (F.hasPersonalityFn())
64  Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
65  bool forceEmitPersonality =
66  F.hasPersonalityFn() && !isNoOpWithoutInvoke(classifyEHPersonality(Per)) &&
67  F.needsUnwindTableEntry();
68  bool shouldEmitPersonality = forceEmitPersonality ||
69  !MF->getLandingPads().empty();
71  !shouldEmitPersonality)
72  ATS.emitCantUnwind();
73  else if (shouldEmitPersonality) {
74  // Emit references to personality.
75  if (Per) {
76  MCSymbol *PerSym = Asm->getSymbol(Per);
77  ATS.emitPersonality(PerSym);
78  }
79 
80  // Emit .handlerdata directive.
81  ATS.emitHandlerData();
82 
83  // Emit actual exception table
85  }
86 
88  ATS.emitFnEnd();
89 }
90 
91 void ARMException::emitTypeInfos(unsigned TTypeEncoding,
92  MCSymbol *TTBaseLabel) {
93  const MachineFunction *MF = Asm->MF;
94  const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
95  const std::vector<unsigned> &FilterIds = MF->getFilterIds();
96 
97  bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
98 
99  int Entry = 0;
100  // Emit the Catch TypeInfos.
101  if (VerboseAsm && !TypeInfos.empty()) {
102  Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
103  Asm->OutStreamer->addBlankLine();
104  Entry = TypeInfos.size();
105  }
106 
107  for (const GlobalValue *GV : reverse(TypeInfos)) {
108  if (VerboseAsm)
109  Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
110  Asm->emitTTypeReference(GV, TTypeEncoding);
111  }
112 
113  Asm->OutStreamer->emitLabel(TTBaseLabel);
114 
115  // Emit the Exception Specifications.
116  if (VerboseAsm && !FilterIds.empty()) {
117  Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
118  Asm->OutStreamer->addBlankLine();
119  Entry = 0;
120  }
121  for (std::vector<unsigned>::const_iterator
122  I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
123  unsigned TypeID = *I;
124  if (VerboseAsm) {
125  --Entry;
126  if (TypeID != 0)
127  Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
128  }
129 
130  Asm->emitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
131  TTypeEncoding);
132  }
133 }
llvm::ARMTargetStreamer::emitCantUnwind
virtual void emitCantUnwind()
Definition: ARMTargetStreamer.cpp:92
AsmPrinter.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::ARMTargetStreamer::emitFnEnd
virtual void emitFnEnd()
Definition: ARMTargetStreamer.cpp:91
llvm::AsmPrinter::CFISection
CFISection
Definition: AsmPrinter.h:163
llvm::DwarfCFIExceptionBase::markFunctionEnd
void markFunctionEnd() override
Definition: DwarfCFIException.cpp:28
llvm::Function
Definition: Function.h:60
llvm::ARMTargetStreamer
Definition: MCStreamer.h:135
llvm::ARMTargetStreamer::emitPersonality
virtual void emitPersonality(const MCSymbol *Personality)
Definition: ARMTargetStreamer.cpp:93
llvm::AsmPrinter::MAI
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:90
llvm::AsmPrinter::CFISection::Debug
@ Debug
Emit .debug_frame.
llvm::AsmPrinter::getFunctionCFISectionType
CFISection getFunctionCFISectionType(const Function &F) const
Get the CFISection type for a function.
Definition: AsmPrinter.cpp:1258
llvm::ExceptionHandling::ARM
@ ARM
ARM EHABI.
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::classifyEHPersonality
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
Definition: EHPersonalities.cpp:22
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MachineFunction::getFilterIds
const std::vector< unsigned > & getFilterIds() const
Return a reference to the typeids encoding filters used in the current function.
Definition: MachineFunction.h:1219
llvm::AsmPrinter::OutStreamer
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:99
Twine.h
llvm::EHStreamer::emitExceptionTable
MCSymbol * emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:375
llvm::isNoOpWithoutInvoke
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
Definition: EHPersonalities.h:95
llvm::AsmPrinter::getModuleCFISectionType
CFISection getModuleCFISectionType() const
Get the CFISection type for the module.
Definition: AsmPrinter.h:434
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:93
llvm::ARMException::ARMException
ARMException(AsmPrinter *A)
Definition: ARMException.cpp:22
llvm::DwarfCFIExceptionBase
Definition: DwarfException.h:24
llvm::GlobalValue
Definition: GlobalValue.h:44
llvm::DwarfCFIExceptionBase::hasEmittedCFISections
bool hasEmittedCFISections
Per-module flag to indicate if .cfi_section has beeen emitted.
Definition: DwarfException.h:31
llvm::ARMTargetStreamer::emitHandlerData
virtual void emitHandlerData()
Definition: ARMTargetStreamer.cpp:95
I
#define I(x, y, z)
Definition: MD5.cpp:58
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::AsmPrinter::getSymbol
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:656
llvm::AsmPrinter::MF
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:102
llvm::MachineFunction::getLandingPads
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
Definition: MachineFunction.h:1111
llvm::MachineFunction
Definition: MachineFunction.h:257
MCAsmInfo.h
llvm::EHStreamer::Asm
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:33
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
llvm::ARMException::endFunction
void endFunction(const MachineFunction *) override
Gather and emit post-function exception information.
Definition: ARMException.cpp:59
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:623
llvm::DwarfCFIExceptionBase::shouldEmitCFI
bool shouldEmitCFI
Per-function flag to indicate if frame CFI info should be emitted.
Definition: DwarfException.h:29
llvm::ARMException::~ARMException
~ARMException() override
Function.h
llvm::Function::needsUnwindTableEntry
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:620
llvm::ARMException::beginFunction
void beginFunction(const MachineFunction *MF) override
Gather pre-function exception information.
Definition: ARMException.cpp:31
llvm::AsmPrinter
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:84
llvm::ARMTargetStreamer::emitFnStart
virtual void emitFnStart()
Definition: ARMTargetStreamer.cpp:90
llvm::MCAsmInfo::getExceptionHandlingType
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:781
llvm::AsmPrinter::emitTTypeReference
virtual void emitTTypeReference(const GlobalValue *GV, unsigned Encoding)
Emit reference to a ttype global with a specified encoding.
Definition: AsmPrinterDwarf.cpp:143
MCStreamer.h
DwarfException.h
llvm::ARMException::markFunctionEnd
void markFunctionEnd() override
Definition: ARMException.cpp:51
llvm::reverse
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:485
llvm::MachineFunction::getTypeInfos
const std::vector< const GlobalValue * > & getTypeInfos() const
Return a reference to the C++ typeinfo for the current function.
Definition: MachineFunction.h:1213
llvm::Type::TypeID
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:54
MachineFunction.h
llvm::AsmPrinter::CFISection::EH
@ EH
Emit .eh_frame.