]> git.proxmox.com Git - rustc.git/blob - src/llvm/lib/CodeGen/AsmPrinter/ARMException.cpp
Imported Upstream version 1.0.0+dfsg1
[rustc.git] / src / llvm / lib / CodeGen / AsmPrinter / ARMException.cpp
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"
18 #include "llvm/CodeGen/AsmPrinter.h"
19 #include "llvm/CodeGen/MachineFrameInfo.h"
20 #include "llvm/CodeGen/MachineFunction.h"
21 #include "llvm/CodeGen/MachineModuleInfo.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"
31 #include "llvm/Support/CommandLine.h"
32 #include "llvm/Support/Dwarf.h"
33 #include "llvm/Support/FormattedStream.h"
34 #include "llvm/Target/TargetFrameLowering.h"
35 #include "llvm/Target/TargetOptions.h"
36 #include "llvm/Target/TargetRegisterInfo.h"
37 using namespace llvm;
38
39 ARMException::ARMException(AsmPrinter *A)
40 : EHStreamer(A), shouldEmitCFI(false) {}
41
42 ARMException::~ARMException() {}
43
44 ARMTargetStreamer &ARMException::getTargetStreamer() {
45 MCTargetStreamer &TS = *Asm->OutStreamer.getTargetStreamer();
46 return static_cast<ARMTargetStreamer &>(TS);
47 }
48
49 /// endModule - Emit all exception information that should come after the
50 /// content.
51 void ARMException::endModule() {
52 if (shouldEmitCFI)
53 Asm->OutStreamer.EmitCFISections(false, true);
54 }
55
56 /// beginFunction - Gather pre-function exception information. Assumes it's
57 /// being emitted immediately after the function entry point.
58 void ARMException::beginFunction(const MachineFunction *MF) {
59 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
60 getTargetStreamer().emitFnStart();
61 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
62 Asm->getFunctionNumber()));
63 // See if we need call frame info.
64 AsmPrinter::CFIMoveType MoveType = Asm->needsCFIMoves();
65 assert(MoveType != AsmPrinter::CFI_M_EH &&
66 "non-EH CFI not yet supported in prologue with EHABI lowering");
67 if (MoveType == AsmPrinter::CFI_M_Debug) {
68 shouldEmitCFI = true;
69 Asm->OutStreamer.EmitCFIStartProc(false);
70 }
71 }
72
73 /// endFunction - Gather and emit post-function exception information.
74 ///
75 void ARMException::endFunction(const MachineFunction *) {
76 if (shouldEmitCFI)
77 Asm->OutStreamer.EmitCFIEndProc();
78
79 // Map all labels and get rid of any dead landing pads.
80 MMI->TidyLandingPads();
81
82 ARMTargetStreamer &ATS = getTargetStreamer();
83 if (!Asm->MF->getFunction()->needsUnwindTableEntry() &&
84 MMI->getLandingPads().empty())
85 ATS.emitCantUnwind();
86 else {
87 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
88 Asm->getFunctionNumber()));
89 if (!MMI->getLandingPads().empty()) {
90 // Emit references to personality.
91 if (const Function * Personality =
92 MMI->getPersonalities()[MMI->getPersonalityIndex()]) {
93 MCSymbol *PerSym = Asm->getSymbol(Personality);
94 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
95 ATS.emitPersonality(PerSym);
96 }
97
98 // Emit .handlerdata directive.
99 ATS.emitHandlerData();
100
101 // Emit actual exception table
102 emitExceptionTable();
103 }
104 }
105
106 if (Asm->MAI->getExceptionHandlingType() == ExceptionHandling::ARM)
107 ATS.emitFnEnd();
108 }
109
110 void ARMException::emitTypeInfos(unsigned TTypeEncoding) {
111 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
112 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
113
114 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
115
116 int Entry = 0;
117 // Emit the Catch TypeInfos.
118 if (VerboseAsm && !TypeInfos.empty()) {
119 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<");
120 Asm->OutStreamer.AddBlankLine();
121 Entry = TypeInfos.size();
122 }
123
124 for (std::vector<const GlobalValue *>::const_reverse_iterator
125 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
126 const GlobalValue *GV = *I;
127 if (VerboseAsm)
128 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
129 Asm->EmitTTypeReference(GV, TTypeEncoding);
130 }
131
132 // Emit the Exception Specifications.
133 if (VerboseAsm && !FilterIds.empty()) {
134 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<");
135 Asm->OutStreamer.AddBlankLine();
136 Entry = 0;
137 }
138 for (std::vector<unsigned>::const_iterator
139 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
140 unsigned TypeID = *I;
141 if (VerboseAsm) {
142 --Entry;
143 if (TypeID != 0)
144 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry));
145 }
146
147 Asm->EmitTTypeReference((TypeID == 0 ? nullptr : TypeInfos[TypeID - 1]),
148 TTypeEncoding);
149 }
150 }