LLVM  8.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/Twine.h"
18 #include "llvm/IR/DataLayout.h"
19 #include "llvm/IR/Mangler.h"
20 #include "llvm/IR/Module.h"
21 #include "llvm/MC/MCAsmInfo.h"
22 #include "llvm/MC/MCExpr.h"
23 #include "llvm/MC/MCSection.h"
24 #include "llvm/MC/MCStreamer.h"
25 #include "llvm/MC/MCSymbol.h"
28 using namespace llvm;
29 
31 
33 
34 ARMTargetStreamer &ARMException::getTargetStreamer() {
35  MCTargetStreamer &TS = *Asm->OutStreamer->getTargetStreamer();
36  return static_cast<ARMTargetStreamer &>(TS);
37 }
38 
41  getTargetStreamer().emitFnStart();
42  // See if we need call frame info.
44  assert(MoveType != AsmPrinter::CFI_M_EH &&
45  "non-EH CFI not yet supported in prologue with EHABI lowering");
46 
47  if (MoveType == AsmPrinter::CFI_M_Debug) {
48  if (!hasEmittedCFISections) {
50  Asm->OutStreamer->EmitCFISections(false, true);
51  hasEmittedCFISections = true;
52  }
53 
54  shouldEmitCFI = true;
55  Asm->OutStreamer->EmitCFIStartProc(false);
56  }
57 }
58 
59 /// endFunction - Gather and emit post-function exception information.
60 ///
62  ARMTargetStreamer &ATS = getTargetStreamer();
63  const Function &F = MF->getFunction();
64  const Function *Per = nullptr;
65  if (F.hasPersonalityFn())
66  Per = dyn_cast<Function>(F.getPersonalityFn()->stripPointerCasts());
67  bool forceEmitPersonality =
70  bool shouldEmitPersonality = forceEmitPersonality ||
71  !MF->getLandingPads().empty();
73  !shouldEmitPersonality)
74  ATS.emitCantUnwind();
75  else if (shouldEmitPersonality) {
76  // Emit references to personality.
77  if (Per) {
78  MCSymbol *PerSym = Asm->getSymbol(Per);
79  Asm->OutStreamer->EmitSymbolAttribute(PerSym, MCSA_Global);
80  ATS.emitPersonality(PerSym);
81  }
82 
83  // Emit .handlerdata directive.
84  ATS.emitHandlerData();
85 
86  // Emit actual exception table
88  }
89 
91  ATS.emitFnEnd();
92 }
93 
94 void ARMException::emitTypeInfos(unsigned TTypeEncoding,
95  MCSymbol *TTBaseLabel) {
96  const MachineFunction *MF = Asm->MF;
97  const std::vector<const GlobalValue *> &TypeInfos = MF->getTypeInfos();
98  const std::vector<unsigned> &FilterIds = MF->getFilterIds();
99 
100  bool VerboseAsm = Asm->OutStreamer->isVerboseAsm();
101 
102  int Entry = 0;
103  // Emit the Catch TypeInfos.
104  if (VerboseAsm && !TypeInfos.empty()) {
105  Asm->OutStreamer->AddComment(">> Catch TypeInfos <<");
106  Asm->OutStreamer->AddBlankLine();
107  Entry = TypeInfos.size();
108  }
109 
110  for (const GlobalValue *GV : reverse(TypeInfos)) {
111  if (VerboseAsm)
112  Asm->OutStreamer->AddComment("TypeInfo " + Twine(Entry--));
113  Asm->EmitTTypeReference(GV, TTypeEncoding);
114  }
115 
116  Asm->OutStreamer->EmitLabel(TTBaseLabel);
117 
118  // Emit the Exception Specifications.
119  if (VerboseAsm && !FilterIds.empty()) {
120  Asm->OutStreamer->AddComment(">> Filter TypeInfos <<");
121  Asm->OutStreamer->AddBlankLine();
122  Entry = 0;
123  }
124  for (std::vector<unsigned>::const_iterator
125  I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
126  unsigned TypeID = *I;
127  if (VerboseAsm) {
128  --Entry;
129  if (TypeID != 0)
130  Asm->OutStreamer->AddComment("FilterInfo " + Twine(Entry));
131  }
132 
133  Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
134  TTypeEncoding);
135  }
136 }
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:93
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:320
CFIMoveType needsCFIMoves() const
Definition: AsmPrinter.cpp:952
Target specific streamer interface.
Definition: MCStreamer.h:83
bool shouldEmitCFI
Per-function flag to indicate if frame CFI info should be emitted.
F(f)
MachineFunction * MF
The current machine function.
Definition: AsmPrinter.h:96
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:251
void emitExceptionTable()
Emit landing pads and actions.
Definition: EHStreamer.cpp:348
bool hasPersonalityFn() const
Check whether this function has a personality function.
Definition: Function.h:702
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:84
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:78
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:173
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:428
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.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
bool needsUnwindTableEntry() const
True if this function needs an unwind table.
Definition: Function.h:573
.type _foo,
Definition: MCDirectives.h:30
#define I(x, y, z)
Definition: MD5.cpp:58
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Constant * getPersonalityFn() const
Get the personality function associated with this function.
Definition: Function.cpp:1302
ExceptionHandling getExceptionHandlingType() const
Definition: MCAsmInfo.h:570
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