LLVM  6.0.0svn
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/StringExtras.h"
16 #include "llvm/ADT/Twine.h"
24 #include "llvm/IR/DataLayout.h"
25 #include "llvm/IR/Mangler.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/MC/MCAsmInfo.h"
28 #include "llvm/MC/MCContext.h"
29 #include "llvm/MC/MCExpr.h"
30 #include "llvm/MC/MCSection.h"
31 #include "llvm/MC/MCStreamer.h"
32 #include "llvm/MC/MCSymbol.h"
35 using namespace llvm;
36 
38 
40 
41 ARMTargetStreamer &ARMException::getTargetStreamer() {
42  MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
43  return static_cast<ARMTargetStreamer &>(TS);
44 }
45 
48  getTargetStreamer().emitFnStart();
49  // See if we need call frame info.
51  assert(MoveType != AsmPrinter::CFI_M_EH &&
52  "non-EH CFI not yet supported in prologue with EHABI lowering");
53 
54  if (MoveType == AsmPrinter::CFI_M_Debug) {
55  if (!hasEmittedCFISections) {
57  Asm->OutStreamer->EmitCFISections(false, true);
58  hasEmittedCFISections = true;
59  }
60 
61  shouldEmitCFI = true;
62  Asm->OutStreamer->EmitCFIStartProc(false);
63  }
64 }
65 
66 /// endFunction - Gather and emit post-function exception information.
67 ///
69  ARMTargetStreamer &ATS = getTargetStreamer();
70  const Function *F = MF->getFunction();
71  const Function *Per = nullptr;
72  if (F->hasPersonalityFn())
73  Per = dyn_cast<Function>(F->getPersonalityFn()->stripPointerCasts());
74  bool forceEmitPersonality =
77  bool shouldEmitPersonality = forceEmitPersonality ||
78  !MF->getLandingPads().empty();
80  !shouldEmitPersonality)
81  ATS.emitCantUnwind();
82  else if (shouldEmitPersonality) {
83  // Emit references to personality.
84  if (Per) {
85  MCSymbol *PerSym = Asm->getSymbol(Per);
86  Asm->OutStreamer->EmitSymbolAttribute(PerSym, MCSA_Global);
87  ATS.emitPersonality(PerSym);
88  }
89 
90  // Emit .handlerdata directive.
91  ATS.emitHandlerData();
92 
93  // Emit actual exception table
95  }
96 
98  ATS.emitFnEnd();
99 }
100 
101 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
102  const MachineFunction *MF = Asm->MF;
103  const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
104  const std::vector<unsigned> &FilterIds = MF->getFilterIds();
105 
106  bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
107 
108  int Entry = 0;
109  // Emit the Catch TypeInfos.
110  if (VerboseAsm && !TypeInfos.empty()) {
111  Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
112  Asm->OutStreamer->AddBlankLine();
113  Entry = TypeInfos.size();
114  }
115 
116  for (const GlobalValue *GV : reverse(TypeInfos)) {
117  if (VerboseAsm)
118  Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
119  Asm->EmitTTypeReference(GV, TTypeEncoding);
120  }
121 
122  // Emit the Exception Specifications.
123  if (VerboseAsm && !FilterIds.empty()) {
124  Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
125  Asm->OutStreamer->AddBlankLine();
126  Entry = 0;
127  }
128  for (std::vector<unsigned>::const_iterator
129  I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
130  unsigned TypeID = *I;
131  if (VerboseAsm) {
132  --Entry;
133  if (TypeID != 0)
134  Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
135  }
136 
137  Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
138  TTypeEncoding);
139  }
140 }
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:92
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
bool needsOnlyDebugCFIMoves() const
Returns false if needsCFIMoves() == CFI_M_EH for any function in the module.
Definition: AsmPrinter.h:303
CFIMoveType needsCFIMoves() const
Definition: AsmPrinter.cpp:917
Target specific streamer interface.
Definition: MCStreamer.h:80
const MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:95
bool shouldEmitCFI
Per-function flag to indicate if frame CFI info should be emitted.
F(f)
setjmp/longjmp based exceptions
virtual void emitPersonality(const MCSymbol *Personality)
const std::vector< unsigned > & getFilterIds() const
Return a reference to the typeids encoding filters used in 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:55
auto reverse(ContainerTy &&C, typename std::enable_if< has_rbegin< ContainerTy >::value >::type *=nullptr) -> decltype(make_range(C.rbegin(), C.rend()))
Definition: STLExtras.h:186
void emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:349
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:634
void endFunction(const MachineFunction *) override
Gather and emit post-function exception information.
void beginFunction(const MachineFunction *MF) override
Gather pre-function exception information.
const MCAsmInfo * MAI
Target Asm Printer information.
Definition: AsmPrinter.h:83
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:77
EHPersonality classifyEHPersonality(const Value *Pers)
See if the given exception handling personality function is one that we understand.
const Constant * stripPointerCasts() const
Definition: Constant.h:153
AsmPrinter * Asm
Target of directive emission.
Definition: EHStreamer.h:34
bool hasEmittedCFISections
Per-module flag to indicate if .cfi_section has beeen emitted.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
MCSymbol * getSymbol(const GlobalValue *GV) const
Definition: AsmPrinter.cpp:433
Module.h This file contains the declarations for the Module class.
void EmitTTypeReference(const GlobalValue *GV, unsigned Encoding) const
Emit reference to a ttype global with a specified encoding.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:505
This file contains constants used for implementing Dwarf debug support.
.type _foo,
Definition: MCDirectives.h:30
#define I(x, y, z)
Definition: MD5.cpp:58
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1260
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:554
const std::vector< const GlobalValue * > & getTypeInfos() const
Return a reference to the C++ typeinfo for the current function.
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