blob: dec80a43f660031fe5a480796b633960fc676758 [file] [log] [blame]
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +00001//===-- 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/Module.h"
16#include "llvm/CodeGen/AsmPrinter.h"
17#include "llvm/CodeGen/MachineModuleInfo.h"
18#include "llvm/CodeGen/MachineFrameInfo.h"
19#include "llvm/CodeGen/MachineFunction.h"
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000020#include "llvm/MC/MCAsmInfo.h"
21#include "llvm/MC/MCContext.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"
26#include "llvm/Target/Mangler.h"
Micah Villmow3574eca2012-10-08 16:38:25 +000027#include "llvm/DataLayout.h"
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000028#include "llvm/Target/TargetFrameLowering.h"
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000029#include "llvm/Target/TargetMachine.h"
30#include "llvm/Target/TargetOptions.h"
31#include "llvm/Target/TargetRegisterInfo.h"
Evgeniy Stepanov53fa1ae2012-01-24 13:05:33 +000032#include "llvm/Support/CommandLine.h"
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000033#include "llvm/Support/Dwarf.h"
34#include "llvm/Support/FormattedStream.h"
35#include "llvm/ADT/SmallString.h"
36#include "llvm/ADT/StringExtras.h"
37#include "llvm/ADT/Twine.h"
38using namespace llvm;
39
Evgeniy Stepanov53fa1ae2012-01-24 13:05:33 +000040cl::opt<bool>
41EnableARMEHABIDescriptors("arm-enable-ehabi-descriptors", cl::Hidden,
42 cl::desc("Generate ARM EHABI tables with unwinding descriptors"),
43 cl::init(false));
44
45
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000046ARMException::ARMException(AsmPrinter *A)
Benjamin Kramere288cd12012-07-20 22:05:57 +000047 : DwarfException(A) {}
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000048
49ARMException::~ARMException() {}
50
51void ARMException::EndModule() {
52}
53
54/// BeginFunction - Gather pre-function exception information. Assumes it's
55/// being emitted immediately after the function entry point.
56void ARMException::BeginFunction(const MachineFunction *MF) {
57 Asm->OutStreamer.EmitFnStart();
Rafael Espindolafc2bb8c2011-05-25 03:44:17 +000058 if (Asm->MF->getFunction()->needsUnwindTableEntry())
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000059 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_begin",
60 Asm->getFunctionNumber()));
61}
62
63/// EndFunction - Gather and emit post-function exception information.
64///
65void ARMException::EndFunction() {
Rafael Espindolafc2bb8c2011-05-25 03:44:17 +000066 if (!Asm->MF->getFunction()->needsUnwindTableEntry())
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000067 Asm->OutStreamer.EmitCantUnwind();
68 else {
69 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("eh_func_end",
70 Asm->getFunctionNumber()));
71
Evgeniy Stepanov53fa1ae2012-01-24 13:05:33 +000072 if (EnableARMEHABIDescriptors) {
73 // Map all labels and get rid of any dead landing pads.
74 MMI->TidyLandingPads();
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000075
Anton Korobeynikov062a6c82012-11-14 19:13:30 +000076 if (!MMI->getLandingPads().empty()) {
77 // Emit references to personality.
78 if (const Function * Personality =
79 MMI->getPersonalities()[MMI->getPersonalityIndex()]) {
80 MCSymbol *PerSym = Asm->Mang->getSymbol(Personality);
81 Asm->OutStreamer.EmitSymbolAttribute(PerSym, MCSA_Global);
82 Asm->OutStreamer.EmitPersonality(PerSym);
83 }
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000084
Anton Korobeynikov062a6c82012-11-14 19:13:30 +000085 // Emit .handlerdata directive.
86 Asm->OutStreamer.EmitHandlerData();
87
88 // Emit actual exception table
89 EmitExceptionTable();
90 }
Evgeniy Stepanov53fa1ae2012-01-24 13:05:33 +000091 }
Anton Korobeynikovb5e16af2011-03-05 18:43:15 +000092 }
93
94 Asm->OutStreamer.EmitFnEnd();
95}
Anton Korobeynikov2386fc82012-11-19 21:06:26 +000096
97void ARMException::EmitTypeInfos(unsigned TTypeEncoding) {
98 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
99 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
100
101 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
102
103 int Entry = 0;
104 // Emit the Catch TypeInfos.
105 if (VerboseAsm && !TypeInfos.empty()) {
106 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<");
107 Asm->OutStreamer.AddBlankLine();
108 Entry = TypeInfos.size();
109 }
110
111 for (std::vector<const GlobalVariable *>::const_reverse_iterator
112 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
113 const GlobalVariable *GV = *I;
114 if (VerboseAsm)
115 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
Anton Korobeynikov239938f2012-11-19 21:17:20 +0000116 Asm->EmitTTypeReference(GV, TTypeEncoding);
Anton Korobeynikov2386fc82012-11-19 21:06:26 +0000117 }
118
119 // Emit the Exception Specifications.
120 if (VerboseAsm && !FilterIds.empty()) {
121 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<");
122 Asm->OutStreamer.AddBlankLine();
123 Entry = 0;
124 }
125 for (std::vector<unsigned>::const_iterator
126 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
127 unsigned TypeID = *I;
128 if (VerboseAsm) {
129 --Entry;
130 if (TypeID != 0)
131 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry));
132 }
133
Anton Korobeynikov239938f2012-11-19 21:17:20 +0000134 Asm->EmitTTypeReference((TypeID == 0 ? 0 : TypeInfos[TypeID - 1]),
135 TTypeEncoding);
Anton Korobeynikov2386fc82012-11-19 21:06:26 +0000136 }
137}