LLVM  3.7.0
ARMException.cpp
Go to the documentation of this file.
1 //===-- CodeGen/AsmPrinter/ARMException.cpp - ARM EHABI Exception Impl ----===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains support for writing DWARF exception info into asm files.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "DwarfException.h"
15 #include "llvm/ADT/SmallString.h"
16 #include "llvm/ADT/StringExtras.h"
17 #include "llvm/ADT/Twine.h"
22 #include "llvm/IR/DataLayout.h"
23 #include "llvm/IR/Mangler.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/MC/MCAsmInfo.h"
26 #include "llvm/MC/MCContext.h"
27 #include "llvm/MC/MCExpr.h"
28 #include "llvm/MC/MCSection.h"
29 #include "llvm/MC/MCStreamer.h"
30 #include "llvm/MC/MCSymbol.h"
32 #include "llvm/Support/Dwarf.h"
37 using namespace llvm;
38 
40 
42 
43 ARMTargetStreamer &ARMException::getTargetStreamer() {
44  MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
45  return static_cast<ARMTargetStreamer &>(TS);
46 }
47 
48 /// endModule - Emit all exception information that should come after the
49 /// content.
51  if (shouldEmitCFI)
52  Asm->OutStreamer->EmitCFISections(false, true);
53 }
54 
57  getTargetStreamer().emitFnStart();
58  // See if we need call frame info.
60  assert(MoveType != AsmPrinter::CFI_M_EH &&
61  "non-EH CFI not yet supported in prologue with EHABI lowering");
62  if (MoveType == AsmPrinter::CFI_M_Debug) {
63  shouldEmitCFI = true;
64  Asm->OutStreamer->EmitCFIStartProc(false);
65  }
66 }
67 
68 /// endFunction - Gather and emit post-function exception information.
69 ///
71  ARMTargetStreamer &ATS = getTargetStreamer();
72  const Function *F = MF->getFunction();
73  const Function *Per = nullptr;
74  if (F->hasPersonalityFn())
75  Per = dyn_cast<Function>(F->getPersonalityFn()->stripPointerCasts());
76  assert(!MMI->getPersonality() || Per == MMI->getPersonality());
77  bool forceEmitPersonality =
80  bool shouldEmitPersonality = forceEmitPersonality ||
81  !MMI->getLandingPads().empty();
83  !shouldEmitPersonality)
84  ATS.emitCantUnwind();
85  else if (shouldEmitPersonality) {
86  // Emit references to personality.
87  if (Per) {
88  MCSymbol *PerSym = Asm->getSymbol(Per);
89  Asm->OutStreamer->EmitSymbolAttribute(PerSym, MCSA_Global);
90  ATS.emitPersonality(PerSym);
91  }
92 
93  // Emit .handlerdata directive.
94  ATS.emitHandlerData();
95 
96  // Emit actual exception table
98  }
99 
101  ATS.emitFnEnd();
102 }
103 
104 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
105  const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
106  const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
107 
108  bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
109 
110  int Entry = 0;
111  // Emit the Catch TypeInfos.
112  if (VerboseAsm && !TypeInfos.empty()) {
113  Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
114  Asm->OutStreamer->AddBlankLine();
115  Entry = TypeInfos.size();
116  }
117 
118  for (std::vector<const GlobalValue *>::const_reverse_iterator
119  I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
120  const GlobalValue *GV = *I;
121  if (VerboseAsm)
122  Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
123  Asm->EmitTTypeReference(GV, TTypeEncoding);
124  }
125 
126  // Emit the Exception Specifications.
127  if (VerboseAsm && !FilterIds.empty()) {
128  Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
129  Asm->OutStreamer->AddBlankLine();
130  Entry = 0;
131  }
132  for (std::vector<unsigned>::const_iterator
133  I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
134  unsigned TypeID = *I;
135  if (VerboseAsm) {
136  --Entry;
137  if (TypeID != 0)
138  Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
139  }
140 
141  Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
142  TTypeEncoding);
143  }
144 }
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:83
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:339
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
void endModule() override
Emit all exception information that should come after the content.
Target specific streamer interface.
Definition: MCStreamer.h:73
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:86
bool shouldEmitCFI
Per-function flag to indicate if frame CFI info should be emitted.
F(f)
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
setjmp/longjmp based exceptions
virtual void emitPersonality(const MCSymbol *Personality)
MachineModuleInfo * MMI
Collected machine module information.
Definition: EHStreamer.h:39
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:79
const std::vector< unsigned > & getFilterIds() const
getFilterIds - Return a reference to the typeids encoding filters used in the current function...
TypeID
Definitions of all of the base types for the Type system.
Definition: Type.h:54
void emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:338
const std::vector< const GlobalValue * > & getTypeInfos() const
getTypeInfos - Return a reference to the C++ typeinfo for the current function.
void endFunction(const MachineFunction *) override
Gather and emit post-function exception information.
void beginFunction(const MachineFunction *MF) override
Gather pre-function exception information.
Constant * stripPointerCasts()
Definition: Constant.h:170
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:74
bool hasPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.h:132
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:66
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:511
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:36
Module.h This file contains the declarations for the Module class.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:354
void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const
Emit reference to a ttype global with a specified encoding.
.type _foo,
Definition: MCDirectives.h:30
Constant * getPersonalityFn() const
Definition: Function.h:133
const std::vector< LandingPadInfo > & getLandingPads() const
getLandingPads - Return a reference to the landing pad info for the current function.
#define I(x, y, z)
Definition: MD5.cpp:54
CFIMoveType needsCFIMoves()
Definition: AsmPrinter.cpp:741
static TraceState * TS
bool isNoOpWithoutInvoke(EHPersonality Pers)
Return true if this personality may be safely removed if there are no invoke instructions remaining i...
ARMException(AsmPrinter *A)
~ARMException() override
const Function * getPersonality() const
getPersonality - Return a personality function if available.