blob: bf7f7eec9fe18bb8482ee469a7a82361d86478c6 [file] [log] [blame]
Bill Wendlingeb907212009-05-15 01:12:28 +00001//===-- CodeGen/AsmPrinter/DwarfException.cpp - Dwarf 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//
Bill Wendling28275fd2009-09-10 06:50:01 +000010// This file contains support for writing DWARF exception info into asm files.
Bill Wendlingeb907212009-05-15 01:12:28 +000011//
12//===----------------------------------------------------------------------===//
13
14#include "DwarfException.h"
15#include "llvm/Module.h"
Chris Lattner6d733782010-04-05 05:28:23 +000016#include "llvm/CodeGen/AsmPrinter.h"
Bill Wendlingeb907212009-05-15 01:12:28 +000017#include "llvm/CodeGen/MachineModuleInfo.h"
18#include "llvm/CodeGen/MachineFrameInfo.h"
David Greenefc4da0c2009-08-19 21:55:33 +000019#include "llvm/CodeGen/MachineFunction.h"
Chris Lattner8c6ed052009-09-16 01:46:41 +000020#include "llvm/MC/MCAsmInfo.h"
21#include "llvm/MC/MCContext.h"
22#include "llvm/MC/MCExpr.h"
Bill Wendling43e484f2009-09-10 01:12:47 +000023#include "llvm/MC/MCSection.h"
Chris Lattner6c2f9e12009-08-19 05:49:37 +000024#include "llvm/MC/MCStreamer.h"
Chris Lattner7a2ba942010-01-16 18:37:32 +000025#include "llvm/MC/MCSymbol.h"
Chris Lattner45111d12010-01-16 21:57:06 +000026#include "llvm/Target/Mangler.h"
Bill Wendlingeb907212009-05-15 01:12:28 +000027#include "llvm/Target/TargetData.h"
Anton Korobeynikov16c29b52011-01-10 12:39:04 +000028#include "llvm/Target/TargetFrameLowering.h"
Chris Lattnerd5bbb072009-08-02 01:34:32 +000029#include "llvm/Target/TargetLoweringObjectFile.h"
Chris Lattner9d1c1ad2010-04-04 18:06:11 +000030#include "llvm/Target/TargetMachine.h"
Bill Wendlingeb907212009-05-15 01:12:28 +000031#include "llvm/Target/TargetOptions.h"
Chris Lattnerd5bbb072009-08-02 01:34:32 +000032#include "llvm/Target/TargetRegisterInfo.h"
Chris Lattner6c2f9e12009-08-19 05:49:37 +000033#include "llvm/Support/Dwarf.h"
Chris Lattner0ad9c912010-01-22 22:09:00 +000034#include "llvm/Support/FormattedStream.h"
Jim Grosbachc40d9f92009-09-01 18:49:12 +000035#include "llvm/ADT/SmallString.h"
Bill Wendlingeb907212009-05-15 01:12:28 +000036#include "llvm/ADT/StringExtras.h"
Bill Wendling1f8075d2010-02-09 22:49:16 +000037#include "llvm/ADT/Twine.h"
Bill Wendlingeb907212009-05-15 01:12:28 +000038using namespace llvm;
39
Chris Lattner75f50722010-04-04 07:48:20 +000040DwarfException::DwarfException(AsmPrinter *A)
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +000041 : Asm(A), MMI(Asm->MMI) {}
Bill Wendlingbc0d23a2009-05-15 01:18:50 +000042
Bill Wendling5f017e82010-04-07 09:28:04 +000043DwarfException::~DwarfException() {}
Bill Wendlingbc0d23a2009-05-15 01:18:50 +000044
Bill Wendlingeb907212009-05-15 01:12:28 +000045/// SharedTypeIds - How many leading type ids two landing pads have in common.
46unsigned DwarfException::SharedTypeIds(const LandingPadInfo *L,
47 const LandingPadInfo *R) {
48 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
49 unsigned LSize = LIds.size(), RSize = RIds.size();
50 unsigned MinSize = LSize < RSize ? LSize : RSize;
51 unsigned Count = 0;
52
53 for (; Count != MinSize; ++Count)
54 if (LIds[Count] != RIds[Count])
55 return Count;
56
57 return Count;
58}
59
60/// PadLT - Order landing pads lexicographically by type id.
61bool DwarfException::PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
62 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
63 unsigned LSize = LIds.size(), RSize = RIds.size();
64 unsigned MinSize = LSize < RSize ? LSize : RSize;
65
66 for (unsigned i = 0; i != MinSize; ++i)
67 if (LIds[i] != RIds[i])
68 return LIds[i] < RIds[i];
69
70 return LSize < RSize;
71}
72
Bill Wendlingd4609622009-07-28 23:23:00 +000073/// ComputeActionsTable - Compute the actions table and gather the first action
74/// index for each landing pad site.
Bill Wendlingade025c2009-07-29 00:31:35 +000075unsigned DwarfException::
76ComputeActionsTable(const SmallVectorImpl<const LandingPadInfo*> &LandingPads,
77 SmallVectorImpl<ActionEntry> &Actions,
78 SmallVectorImpl<unsigned> &FirstActions) {
Bill Wendlinga583c552009-08-20 22:02:24 +000079
80 // The action table follows the call-site table in the LSDA. The individual
81 // records are of two types:
82 //
83 // * Catch clause
84 // * Exception specification
85 //
86 // The two record kinds have the same format, with only small differences.
87 // They are distinguished by the "switch value" field: Catch clauses
88 // (TypeInfos) have strictly positive switch values, and exception
89 // specifications (FilterIds) have strictly negative switch values. Value 0
90 // indicates a catch-all clause.
91 //
Bill Wendling5e953dd2009-07-28 23:22:13 +000092 // Negative type IDs index into FilterIds. Positive type IDs index into
93 // TypeInfos. The value written for a positive type ID is just the type ID
94 // itself. For a negative type ID, however, the value written is the
Bill Wendlingeb907212009-05-15 01:12:28 +000095 // (negative) byte offset of the corresponding FilterIds entry. The byte
Bill Wendling5e953dd2009-07-28 23:22:13 +000096 // offset is usually equal to the type ID (because the FilterIds entries are
97 // written using a variable width encoding, which outputs one byte per entry
98 // as long as the value written is not too large) but can differ. This kind
99 // of complication does not occur for positive type IDs because type infos are
Bill Wendlingeb907212009-05-15 01:12:28 +0000100 // output using a fixed width encoding. FilterOffsets[i] holds the byte
101 // offset corresponding to FilterIds[i].
Bill Wendling409914b2009-07-29 21:19:44 +0000102
103 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
Bill Wendlingeb907212009-05-15 01:12:28 +0000104 SmallVector<int, 16> FilterOffsets;
105 FilterOffsets.reserve(FilterIds.size());
106 int Offset = -1;
Bill Wendling409914b2009-07-29 21:19:44 +0000107
108 for (std::vector<unsigned>::const_iterator
109 I = FilterIds.begin(), E = FilterIds.end(); I != E; ++I) {
Bill Wendlingeb907212009-05-15 01:12:28 +0000110 FilterOffsets.push_back(Offset);
Chris Lattneraf76e592009-08-22 20:48:53 +0000111 Offset -= MCAsmInfo::getULEB128Size(*I);
Bill Wendlingeb907212009-05-15 01:12:28 +0000112 }
113
Bill Wendlingeb907212009-05-15 01:12:28 +0000114 FirstActions.reserve(LandingPads.size());
115
116 int FirstAction = 0;
117 unsigned SizeActions = 0;
Bill Wendling5e953dd2009-07-28 23:22:13 +0000118 const LandingPadInfo *PrevLPI = 0;
Bill Wendling409914b2009-07-29 21:19:44 +0000119
Bill Wendling5cff4872009-07-28 23:44:43 +0000120 for (SmallVectorImpl<const LandingPadInfo *>::const_iterator
Bill Wendling5e953dd2009-07-28 23:22:13 +0000121 I = LandingPads.begin(), E = LandingPads.end(); I != E; ++I) {
122 const LandingPadInfo *LPI = *I;
123 const std::vector<int> &TypeIds = LPI->TypeIds;
Chris Lattner9be49132010-04-04 20:10:41 +0000124 unsigned NumShared = PrevLPI ? SharedTypeIds(LPI, PrevLPI) : 0;
Bill Wendlingeb907212009-05-15 01:12:28 +0000125 unsigned SizeSiteActions = 0;
126
127 if (NumShared < TypeIds.size()) {
128 unsigned SizeAction = 0;
Bill Wendling0a9abcb2010-02-10 21:41:57 +0000129 unsigned PrevAction = (unsigned)-1;
Bill Wendlingeb907212009-05-15 01:12:28 +0000130
131 if (NumShared) {
Chris Lattner9be49132010-04-04 20:10:41 +0000132 unsigned SizePrevIds = PrevLPI->TypeIds.size();
Bill Wendlingeb907212009-05-15 01:12:28 +0000133 assert(Actions.size());
Bill Wendling0a9abcb2010-02-10 21:41:57 +0000134 PrevAction = Actions.size() - 1;
135 SizeAction =
136 MCAsmInfo::getSLEB128Size(Actions[PrevAction].NextAction) +
137 MCAsmInfo::getSLEB128Size(Actions[PrevAction].ValueForTypeID);
Bill Wendlingeb907212009-05-15 01:12:28 +0000138
139 for (unsigned j = NumShared; j != SizePrevIds; ++j) {
Bill Wendling0a9abcb2010-02-10 21:41:57 +0000140 assert(PrevAction != (unsigned)-1 && "PrevAction is invalid!");
Bill Wendlingeb907212009-05-15 01:12:28 +0000141 SizeAction -=
Bill Wendling0a9abcb2010-02-10 21:41:57 +0000142 MCAsmInfo::getSLEB128Size(Actions[PrevAction].ValueForTypeID);
143 SizeAction += -Actions[PrevAction].NextAction;
144 PrevAction = Actions[PrevAction].Previous;
Bill Wendlingeb907212009-05-15 01:12:28 +0000145 }
146 }
147
148 // Compute the actions.
Bill Wendling5e953dd2009-07-28 23:22:13 +0000149 for (unsigned J = NumShared, M = TypeIds.size(); J != M; ++J) {
150 int TypeID = TypeIds[J];
151 assert(-1 - TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
Bill Wendlingeb907212009-05-15 01:12:28 +0000152 int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
Chris Lattneraf76e592009-08-22 20:48:53 +0000153 unsigned SizeTypeID = MCAsmInfo::getSLEB128Size(ValueForTypeID);
Bill Wendlingeb907212009-05-15 01:12:28 +0000154
155 int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
Chris Lattneraf76e592009-08-22 20:48:53 +0000156 SizeAction = SizeTypeID + MCAsmInfo::getSLEB128Size(NextAction);
Bill Wendlingeb907212009-05-15 01:12:28 +0000157 SizeSiteActions += SizeAction;
158
Bill Wendlinga583c552009-08-20 22:02:24 +0000159 ActionEntry Action = { ValueForTypeID, NextAction, PrevAction };
Bill Wendlingeb907212009-05-15 01:12:28 +0000160 Actions.push_back(Action);
Bill Wendling0a9abcb2010-02-10 21:41:57 +0000161 PrevAction = Actions.size() - 1;
Bill Wendlingeb907212009-05-15 01:12:28 +0000162 }
163
164 // Record the first action of the landing pad site.
165 FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
166 } // else identical - re-use previous FirstAction
167
Bill Wendlinga583c552009-08-20 22:02:24 +0000168 // Information used when created the call-site table. The action record
169 // field of the call site record is the offset of the first associated
170 // action record, relative to the start of the actions table. This value is
Bill Wendling0a9abcb2010-02-10 21:41:57 +0000171 // biased by 1 (1 indicating the start of the actions table), and 0
Bill Wendlinga583c552009-08-20 22:02:24 +0000172 // indicates that there are no actions.
Bill Wendlingeb907212009-05-15 01:12:28 +0000173 FirstActions.push_back(FirstAction);
174
175 // Compute this sites contribution to size.
176 SizeActions += SizeSiteActions;
Bill Wendling5e953dd2009-07-28 23:22:13 +0000177
178 PrevLPI = LPI;
Bill Wendlingeb907212009-05-15 01:12:28 +0000179 }
180
Bill Wendling5e953dd2009-07-28 23:22:13 +0000181 return SizeActions;
182}
183
Bill Wendlinged060dc2009-11-12 21:59:20 +0000184/// CallToNoUnwindFunction - Return `true' if this is a call to a function
185/// marked `nounwind'. Return `false' otherwise.
186bool DwarfException::CallToNoUnwindFunction(const MachineInstr *MI) {
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000187 assert(MI->isCall() && "This should be a call instruction!");
Bill Wendlinged060dc2009-11-12 21:59:20 +0000188
189 bool MarkedNoUnwind = false;
190 bool SawFunc = false;
191
192 for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
193 const MachineOperand &MO = MI->getOperand(I);
194
Chris Lattnercfd31882010-03-31 06:09:04 +0000195 if (!MO.isGlobal()) continue;
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000196
Dan Gohman46510a72010-04-15 01:51:59 +0000197 const Function *F = dyn_cast<Function>(MO.getGlobal());
Chris Lattnercfd31882010-03-31 06:09:04 +0000198 if (F == 0) continue;
Bill Wendlingecc260e2009-11-12 23:13:08 +0000199
Chris Lattnercfd31882010-03-31 06:09:04 +0000200 if (SawFunc) {
201 // Be conservative. If we have more than one function operand for this
202 // call, then we can't make the assumption that it's the callee and
203 // not a parameter to the call.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000204 //
Chris Lattnercfd31882010-03-31 06:09:04 +0000205 // FIXME: Determine if there's a way to say that `F' is the callee or
206 // parameter.
207 MarkedNoUnwind = false;
208 break;
Bill Wendlinged060dc2009-11-12 21:59:20 +0000209 }
Chris Lattnercfd31882010-03-31 06:09:04 +0000210
211 MarkedNoUnwind = F->doesNotThrow();
212 SawFunc = true;
Bill Wendlinged060dc2009-11-12 21:59:20 +0000213 }
214
215 return MarkedNoUnwind;
216}
217
Bill Wendlingade025c2009-07-29 00:31:35 +0000218/// ComputeCallSiteTable - Compute the call-site table. The entry for an invoke
Bill Wendlinga583c552009-08-20 22:02:24 +0000219/// has a try-range containing the call, a non-zero landing pad, and an
Bill Wendlingade025c2009-07-29 00:31:35 +0000220/// appropriate action. The entry for an ordinary call has a try-range
221/// containing the call and zero for the landing pad and the action. Calls
222/// marked 'nounwind' have no entry and must not be contained in the try-range
223/// of any entry - they form gaps in the table. Entries must be ordered by
224/// try-range address.
225void DwarfException::
226ComputeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
227 const RangeMapType &PadMap,
228 const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
229 const SmallVectorImpl<unsigned> &FirstActions) {
Bill Wendlingeb907212009-05-15 01:12:28 +0000230 // The end label of the previous invoke or nounwind try-range.
Chris Lattner16112732010-03-14 01:41:15 +0000231 MCSymbol *LastLabel = 0;
Bill Wendlingeb907212009-05-15 01:12:28 +0000232
233 // Whether there is a potentially throwing instruction (currently this means
234 // an ordinary call) between the end of the previous try-range and now.
235 bool SawPotentiallyThrowing = false;
236
Bill Wendling5cff4872009-07-28 23:44:43 +0000237 // Whether the last CallSite entry was for an invoke.
Bill Wendlingeb907212009-05-15 01:12:28 +0000238 bool PreviousIsInvoke = false;
239
240 // Visit all instructions in order of address.
Chris Lattner84ac8b72010-04-05 00:26:50 +0000241 for (MachineFunction::const_iterator I = Asm->MF->begin(), E = Asm->MF->end();
Bill Wendlingeb907212009-05-15 01:12:28 +0000242 I != E; ++I) {
243 for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
244 MI != E; ++MI) {
245 if (!MI->isLabel()) {
Evan Cheng5a96b3d2011-12-07 07:15:52 +0000246 if (MI->isCall())
Bill Wendlinged060dc2009-11-12 21:59:20 +0000247 SawPotentiallyThrowing |= !CallToNoUnwindFunction(MI);
Bill Wendlingeb907212009-05-15 01:12:28 +0000248 continue;
249 }
250
Bill Wendlingeb907212009-05-15 01:12:28 +0000251 // End of the previous try-range?
Chris Lattner0397ada2010-03-14 08:17:53 +0000252 MCSymbol *BeginLabel = MI->getOperand(0).getMCSymbol();
Bill Wendlingeb907212009-05-15 01:12:28 +0000253 if (BeginLabel == LastLabel)
254 SawPotentiallyThrowing = false;
255
256 // Beginning of a new try-range?
Jeffrey Yasskin81cf4322009-11-10 01:02:17 +0000257 RangeMapType::const_iterator L = PadMap.find(BeginLabel);
Bill Wendlingeb907212009-05-15 01:12:28 +0000258 if (L == PadMap.end())
259 // Nope, it was just some random label.
260 continue;
261
Bill Wendlinga583c552009-08-20 22:02:24 +0000262 const PadRange &P = L->second;
Bill Wendlingeb907212009-05-15 01:12:28 +0000263 const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
Bill Wendlingeb907212009-05-15 01:12:28 +0000264 assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
265 "Inconsistent landing pad map!");
266
Bill Wendlinga583c552009-08-20 22:02:24 +0000267 // For Dwarf exception handling (SjLj handling doesn't use this). If some
268 // instruction between the previous try-range and this one may throw,
269 // create a call-site entry with no landing pad for the region between the
270 // try-ranges.
Anton Korobeynikov3965b5e2011-01-14 21:58:08 +0000271 if (SawPotentiallyThrowing && Asm->MAI->isExceptionHandlingDwarf()) {
Bill Wendlinga583c552009-08-20 22:02:24 +0000272 CallSiteEntry Site = { LastLabel, BeginLabel, 0, 0 };
Bill Wendlingeb907212009-05-15 01:12:28 +0000273 CallSites.push_back(Site);
274 PreviousIsInvoke = false;
275 }
276
277 LastLabel = LandingPad->EndLabels[P.RangeIndex];
278 assert(BeginLabel && LastLabel && "Invalid landing pad!");
279
Chris Lattnercfd31882010-03-31 06:09:04 +0000280 if (!LandingPad->LandingPadLabel) {
281 // Create a gap.
282 PreviousIsInvoke = false;
283 } else {
Bill Wendlingeb907212009-05-15 01:12:28 +0000284 // This try-range is for an invoke.
Bill Wendlinga583c552009-08-20 22:02:24 +0000285 CallSiteEntry Site = {
286 BeginLabel,
287 LastLabel,
288 LandingPad->LandingPadLabel,
289 FirstActions[P.PadIndex]
290 };
Bill Wendlingeb907212009-05-15 01:12:28 +0000291
Jim Grosbach33668c02009-09-01 17:19:13 +0000292 // Try to merge with the previous call-site. SJLJ doesn't do this
Anton Korobeynikov3965b5e2011-01-14 21:58:08 +0000293 if (PreviousIsInvoke && Asm->MAI->isExceptionHandlingDwarf()) {
Bill Wendlingeb907212009-05-15 01:12:28 +0000294 CallSiteEntry &Prev = CallSites.back();
295 if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
296 // Extend the range of the previous entry.
297 Prev.EndLabel = Site.EndLabel;
298 continue;
299 }
300 }
301
302 // Otherwise, create a new call-site.
Anton Korobeynikov3965b5e2011-01-14 21:58:08 +0000303 if (Asm->MAI->isExceptionHandlingDwarf())
Jim Grosbachca752c92010-01-28 01:45:32 +0000304 CallSites.push_back(Site);
305 else {
306 // SjLj EH must maintain the call sites in the order assigned
307 // to them by the SjLjPrepare pass.
308 unsigned SiteNo = MMI->getCallSiteBeginLabel(BeginLabel);
309 if (CallSites.size() < SiteNo)
310 CallSites.resize(SiteNo);
311 CallSites[SiteNo - 1] = Site;
312 }
Bill Wendlingeb907212009-05-15 01:12:28 +0000313 PreviousIsInvoke = true;
Bill Wendlingeb907212009-05-15 01:12:28 +0000314 }
315 }
316 }
317
318 // If some instruction between the previous try-range and the end of the
319 // function may throw, create a call-site entry with no landing pad for the
320 // region following the try-range.
Anton Korobeynikov3965b5e2011-01-14 21:58:08 +0000321 if (SawPotentiallyThrowing && Asm->MAI->isExceptionHandlingDwarf()) {
Bill Wendlinga583c552009-08-20 22:02:24 +0000322 CallSiteEntry Site = { LastLabel, 0, 0, 0 };
Bill Wendlingeb907212009-05-15 01:12:28 +0000323 CallSites.push_back(Site);
324 }
Bill Wendlingade025c2009-07-29 00:31:35 +0000325}
326
Bill Wendling0dafca92009-07-29 00:50:05 +0000327/// EmitExceptionTable - Emit landing pads and actions.
328///
329/// The general organization of the table is complex, but the basic concepts are
330/// easy. First there is a header which describes the location and organization
331/// of the three components that follow.
Eric Christopherdbfcdb92009-08-28 22:33:43 +0000332///
Bill Wendling0dafca92009-07-29 00:50:05 +0000333/// 1. The landing pad site information describes the range of code covered by
334/// the try. In our case it's an accumulation of the ranges covered by the
335/// invokes in the try. There is also a reference to the landing pad that
336/// handles the exception once processed. Finally an index into the actions
337/// table.
Bill Wendlinga583c552009-08-20 22:02:24 +0000338/// 2. The action table, in our case, is composed of pairs of type IDs and next
Bill Wendling0dafca92009-07-29 00:50:05 +0000339/// action offset. Starting with the action index from the landing pad
Bill Wendlinga583c552009-08-20 22:02:24 +0000340/// site, each type ID is checked for a match to the current exception. If
Bill Wendling0dafca92009-07-29 00:50:05 +0000341/// it matches then the exception and type id are passed on to the landing
342/// pad. Otherwise the next action is looked up. This chain is terminated
Bill Wendling28275fd2009-09-10 06:50:01 +0000343/// with a next action of zero. If no type id is found then the frame is
Bill Wendling0dafca92009-07-29 00:50:05 +0000344/// unwound and handling continues.
Bill Wendlinga583c552009-08-20 22:02:24 +0000345/// 3. Type ID table contains references to all the C++ typeinfo for all
Bill Wendling28275fd2009-09-10 06:50:01 +0000346/// catches in the function. This tables is reverse indexed base 1.
Bill Wendlingade025c2009-07-29 00:31:35 +0000347void DwarfException::EmitExceptionTable() {
Dan Gohman46510a72010-04-15 01:51:59 +0000348 const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
Bill Wendlingade025c2009-07-29 00:31:35 +0000349 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
350 const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
Bill Wendlingade025c2009-07-29 00:31:35 +0000351
352 // Sort the landing pads in order of their type ids. This is used to fold
353 // duplicate actions.
354 SmallVector<const LandingPadInfo *, 64> LandingPads;
355 LandingPads.reserve(PadInfos.size());
356
357 for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
358 LandingPads.push_back(&PadInfos[i]);
359
360 std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
361
362 // Compute the actions table and gather the first action index for each
363 // landing pad site.
364 SmallVector<ActionEntry, 32> Actions;
365 SmallVector<unsigned, 64> FirstActions;
Bill Wendling0a9abcb2010-02-10 21:41:57 +0000366 unsigned SizeActions=ComputeActionsTable(LandingPads, Actions, FirstActions);
Bill Wendlingade025c2009-07-29 00:31:35 +0000367
368 // Invokes and nounwind calls have entries in PadMap (due to being bracketed
369 // by try-range labels when lowered). Ordinary calls do not, so appropriate
Bill Wendling28275fd2009-09-10 06:50:01 +0000370 // try-ranges for them need be deduced when using DWARF exception handling.
Bill Wendlingade025c2009-07-29 00:31:35 +0000371 RangeMapType PadMap;
372 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
373 const LandingPadInfo *LandingPad = LandingPads[i];
374 for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
Chris Lattner16112732010-03-14 01:41:15 +0000375 MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
Bill Wendlingade025c2009-07-29 00:31:35 +0000376 assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
377 PadRange P = { i, j };
378 PadMap[BeginLabel] = P;
379 }
380 }
381
382 // Compute the call-site table.
383 SmallVector<CallSiteEntry, 64> CallSites;
Jim Grosbach8b818d72009-08-17 16:41:22 +0000384 ComputeCallSiteTable(CallSites, PadMap, LandingPads, FirstActions);
Bill Wendlingeb907212009-05-15 01:12:28 +0000385
386 // Final tallies.
387
388 // Call sites.
Chris Lattner84ac8b72010-04-05 00:26:50 +0000389 bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
Bill Wendlingd1a5b372009-09-10 00:17:04 +0000390 bool HaveTTData = IsSJLJ ? (!TypeInfos.empty() || !FilterIds.empty()) : true;
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000391
Bill Wendling3dc9b482010-02-24 23:34:35 +0000392 unsigned CallSiteTableLength;
Bill Wendlingd1a5b372009-09-10 00:17:04 +0000393 if (IsSJLJ)
Bill Wendling3dc9b482010-02-24 23:34:35 +0000394 CallSiteTableLength = 0;
Chris Lattner9be49132010-04-04 20:10:41 +0000395 else {
396 unsigned SiteStartSize = 4; // dwarf::DW_EH_PE_udata4
397 unsigned SiteLengthSize = 4; // dwarf::DW_EH_PE_udata4
398 unsigned LandingPadSize = 4; // dwarf::DW_EH_PE_udata4
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000399 CallSiteTableLength =
Chris Lattner9be49132010-04-04 20:10:41 +0000400 CallSites.size() * (SiteStartSize + SiteLengthSize + LandingPadSize);
401 }
Bill Wendlingd1a5b372009-09-10 00:17:04 +0000402
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000403 for (unsigned i = 0, e = CallSites.size(); i < e; ++i) {
Bill Wendling3dc9b482010-02-24 23:34:35 +0000404 CallSiteTableLength += MCAsmInfo::getULEB128Size(CallSites[i].Action);
Bill Wendlingd1a5b372009-09-10 00:17:04 +0000405 if (IsSJLJ)
Bill Wendling3dc9b482010-02-24 23:34:35 +0000406 CallSiteTableLength += MCAsmInfo::getULEB128Size(i);
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000407 }
Bill Wendlingd1a5b372009-09-10 00:17:04 +0000408
Bill Wendlingeb907212009-05-15 01:12:28 +0000409 // Type infos.
Chris Lattnerd5bbb072009-08-02 01:34:32 +0000410 const MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection();
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000411 unsigned TTypeEncoding;
Bill Wendlinga2f64492009-09-10 06:27:16 +0000412 unsigned TypeFormatSize;
Bill Wendlingeb907212009-05-15 01:12:28 +0000413
Bill Wendling43e484f2009-09-10 01:12:47 +0000414 if (!HaveTTData) {
Bill Wendling28275fd2009-09-10 06:50:01 +0000415 // For SjLj exceptions, if there is no TypeInfo, then we just explicitly say
416 // that we're omitting that bit.
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000417 TTypeEncoding = dwarf::DW_EH_PE_omit;
Chris Lattner84ac8b72010-04-05 00:26:50 +0000418 // dwarf::DW_EH_PE_absptr
419 TypeFormatSize = Asm->getTargetData().getPointerSize();
Chris Lattner81c9a062009-07-31 22:03:47 +0000420 } else {
Chris Lattnerad88bc42009-08-02 03:59:56 +0000421 // Okay, we have actual filters or typeinfos to emit. As such, we need to
422 // pick a type encoding for them. We're about to emit a list of pointers to
423 // typeinfo objects at the end of the LSDA. However, unless we're in static
424 // mode, this reference will require a relocation by the dynamic linker.
Chris Lattner46b754c2009-07-31 22:18:14 +0000425 //
Chris Lattnerad88bc42009-08-02 03:59:56 +0000426 // Because of this, we have a couple of options:
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000427 //
Chris Lattnerad88bc42009-08-02 03:59:56 +0000428 // 1) If we are in -static mode, we can always use an absolute reference
429 // from the LSDA, because the static linker will resolve it.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000430 //
Chris Lattnerad88bc42009-08-02 03:59:56 +0000431 // 2) Otherwise, if the LSDA section is writable, we can output the direct
432 // reference to the typeinfo and allow the dynamic linker to relocate
433 // it. Since it is in a writable section, the dynamic linker won't
434 // have a problem.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000435 //
Chris Lattnerad88bc42009-08-02 03:59:56 +0000436 // 3) Finally, if we're in PIC mode and the LDSA section isn't writable,
437 // we need to use some form of indirection. For example, on Darwin,
438 // we can output a statically-relocatable reference to a dyld stub. The
439 // offset to the stub is constant, but the contents are in a section
440 // that is updated by the dynamic linker. This is easy enough, but we
441 // need to tell the personality function of the unwinder to indirect
442 // through the dyld stub.
443 //
Bill Wendling43e484f2009-09-10 01:12:47 +0000444 // FIXME: When (3) is actually implemented, we'll have to emit the stubs
Chris Lattnerad88bc42009-08-02 03:59:56 +0000445 // somewhere. This predicate should be moved to a shared location that is
446 // in target-independent code.
447 //
Anton Korobeynikov9184b252010-02-15 22:35:59 +0000448 TTypeEncoding = Asm->getObjFileLowering().getTTypeEncoding();
Chris Lattnerd2af7852010-04-04 20:20:50 +0000449 TypeFormatSize = Asm->GetSizeOfEncodedValue(TTypeEncoding);
Bill Wendlingfe220282009-09-10 02:07:37 +0000450 }
Bill Wendling43e484f2009-09-10 01:12:47 +0000451
Bill Wendlingfe220282009-09-10 02:07:37 +0000452 // Begin the exception table.
Anton Korobeynikoved299f62011-01-30 22:07:31 +0000453 // Sometimes we want not to emit the data into separate section (e.g. ARM
454 // EHABI). In this case LSDASection will be NULL.
Anton Korobeynikovd4e09782011-01-24 22:38:40 +0000455 if (LSDASection)
456 Asm->OutStreamer.SwitchSection(LSDASection);
Chris Lattner059ea132010-04-28 01:05:45 +0000457 Asm->EmitAlignment(2);
Bill Wendling43e484f2009-09-10 01:12:47 +0000458
Bill Wendling3dc9b482010-02-24 23:34:35 +0000459 // Emit the LSDA.
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000460 MCSymbol *GCCETSym =
Chris Lattner974c0fb2010-03-10 02:48:06 +0000461 Asm->OutContext.GetOrCreateSymbol(Twine("GCC_except_table")+
Chris Lattner84ac8b72010-04-05 00:26:50 +0000462 Twine(Asm->getFunctionNumber()));
Chris Lattner974c0fb2010-03-10 02:48:06 +0000463 Asm->OutStreamer.EmitLabel(GCCETSym);
Chris Lattner84ac8b72010-04-05 00:26:50 +0000464 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("exception",
465 Asm->getFunctionNumber()));
Bill Wendlingfe220282009-09-10 02:07:37 +0000466
Chris Lattner974c0fb2010-03-10 02:48:06 +0000467 if (IsSJLJ)
Chris Lattnerc0215722010-04-04 19:25:43 +0000468 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("_LSDA_",
469 Asm->getFunctionNumber()));
Bill Wendlingfe220282009-09-10 02:07:37 +0000470
Bill Wendling3dc9b482010-02-24 23:34:35 +0000471 // Emit the LSDA header.
Chris Lattnerca6190b2010-04-04 20:04:21 +0000472 Asm->EmitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
473 Asm->EmitEncodingByte(TTypeEncoding, "@TType");
Bill Wendlingfe220282009-09-10 02:07:37 +0000474
Bill Wendling3dc9b482010-02-24 23:34:35 +0000475 // The type infos need to be aligned. GCC does this by inserting padding just
476 // before the type infos. However, this changes the size of the exception
477 // table, so you need to take this into account when you output the exception
478 // table size. However, the size is output using a variable length encoding.
479 // So by increasing the size by inserting padding, you may increase the number
480 // of bytes used for writing the size. If it increases, say by one byte, then
481 // you now need to output one less byte of padding to get the type infos
482 // aligned. However this decreases the size of the exception table. This
483 // changes the value you have to output for the exception table size. Due to
484 // the variable length encoding, the number of bytes used for writing the
485 // length may decrease. If so, you then have to increase the amount of
486 // padding. And so on. If you look carefully at the GCC code you will see that
487 // it indeed does this in a loop, going on and on until the values stabilize.
488 // We chose another solution: don't output padding inside the table like GCC
489 // does, instead output it before the table.
490 unsigned SizeTypes = TypeInfos.size() * TypeFormatSize;
491 unsigned CallSiteTableLengthSize =
492 MCAsmInfo::getULEB128Size(CallSiteTableLength);
493 unsigned TTypeBaseOffset =
494 sizeof(int8_t) + // Call site format
495 CallSiteTableLengthSize + // Call site table length size
496 CallSiteTableLength + // Call site table length
497 SizeActions + // Actions size
498 SizeTypes;
499 unsigned TTypeBaseOffsetSize = MCAsmInfo::getULEB128Size(TTypeBaseOffset);
500 unsigned TotalSize =
501 sizeof(int8_t) + // LPStart format
502 sizeof(int8_t) + // TType format
503 (HaveTTData ? TTypeBaseOffsetSize : 0) + // TType base offset size
504 TTypeBaseOffset; // TType base offset
505 unsigned SizeAlign = (4 - TotalSize) & 3;
506
Bill Wendling86f0d332010-02-25 23:52:44 +0000507 if (HaveTTData) {
Bill Wendling6507eca2010-02-26 21:31:01 +0000508 // Account for any extra padding that will be added to the call site table
Bill Wendlingf7e90ae2010-02-25 21:19:47 +0000509 // length.
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000510 Asm->EmitULEB128(TTypeBaseOffset, "@TType base offset", SizeAlign);
Bill Wendling1869ac82010-02-26 22:17:52 +0000511 SizeAlign = 0;
Bill Wendling86f0d332010-02-25 23:52:44 +0000512 }
Bill Wendlingb0d9c3e2009-07-28 22:23:45 +0000513
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000514 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
515
Bill Wendling28275fd2009-09-10 06:50:01 +0000516 // SjLj Exception handling
Bill Wendlingd1a5b372009-09-10 00:17:04 +0000517 if (IsSJLJ) {
Chris Lattnerca6190b2010-04-04 20:04:21 +0000518 Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site");
Bill Wendling1869ac82010-02-26 22:17:52 +0000519
520 // Add extra padding if it wasn't added to the TType base offset.
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000521 Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign);
Bill Wendlingeb907212009-05-15 01:12:28 +0000522
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000523 // Emit the landing pad site information.
Jim Grosbach8b818d72009-08-17 16:41:22 +0000524 unsigned idx = 0;
525 for (SmallVectorImpl<CallSiteEntry>::const_iterator
526 I = CallSites.begin(), E = CallSites.end(); I != E; ++I, ++idx) {
527 const CallSiteEntry &S = *I;
Bill Wendlinga583c552009-08-20 22:02:24 +0000528
Renato Golinf1f6de12011-08-18 23:43:14 +0000529 // Offset of the landing pad, counted in 16-byte bundles relative to the
530 // @LPStart address.
Bill Wendling0c112182011-06-21 22:40:24 +0000531 if (VerboseAsm) {
Benjamin Kramer47b87982011-10-16 15:46:29 +0000532 Asm->OutStreamer.AddComment(">> Call Site " + Twine(idx) + " <<");
533 Asm->OutStreamer.AddComment(" On exception at call site "+Twine(idx));
Bill Wendling0c112182011-06-21 22:40:24 +0000534 }
Bill Wendling0c112182011-06-21 22:40:24 +0000535 Asm->EmitULEB128(idx);
Bill Wendlinga583c552009-08-20 22:02:24 +0000536
537 // Offset of the first associated action record, relative to the start of
538 // the action table. This value is biased by 1 (1 indicates the start of
539 // the action table), and 0 indicates that there are no actions.
Renato Golinf1f6de12011-08-18 23:43:14 +0000540 if (VerboseAsm) {
541 if (S.Action == 0)
542 Asm->OutStreamer.AddComment(" Action: cleanup");
543 else
Benjamin Kramer47b87982011-10-16 15:46:29 +0000544 Asm->OutStreamer.AddComment(" Action: " +
545 Twine((S.Action - 1) / 2 + 1));
Renato Golinf1f6de12011-08-18 23:43:14 +0000546 }
Bill Wendling0c112182011-06-21 22:40:24 +0000547 Asm->EmitULEB128(S.Action);
Bill Wendlingeb907212009-05-15 01:12:28 +0000548 }
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000549 } else {
550 // DWARF Exception handling
Anton Korobeynikov3965b5e2011-01-14 21:58:08 +0000551 assert(Asm->MAI->isExceptionHandlingDwarf());
Bill Wendlingeb907212009-05-15 01:12:28 +0000552
Bill Wendlinga583c552009-08-20 22:02:24 +0000553 // The call-site table is a list of all call sites that may throw an
554 // exception (including C++ 'throw' statements) in the procedure
555 // fragment. It immediately follows the LSDA header. Each entry indicates,
556 // for a given call, the first corresponding action record and corresponding
557 // landing pad.
558 //
559 // The table begins with the number of bytes, stored as an LEB128
560 // compressed, unsigned integer. The records immediately follow the record
561 // count. They are sorted in increasing call-site address. Each record
562 // indicates:
563 //
564 // * The position of the call-site.
565 // * The position of the landing pad.
566 // * The first action record for that call site.
567 //
568 // A missing entry in the call-site table indicates that a call is not
Bill Wendling28275fd2009-09-10 06:50:01 +0000569 // supposed to throw.
Bill Wendlinga583c552009-08-20 22:02:24 +0000570
571 // Emit the landing pad call site table.
Chris Lattnerca6190b2010-04-04 20:04:21 +0000572 Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site");
Bill Wendling1869ac82010-02-26 22:17:52 +0000573
574 // Add extra padding if it wasn't added to the TType base offset.
Chris Lattner7e1a8f82010-04-04 19:09:29 +0000575 Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign);
Bill Wendlingeb907212009-05-15 01:12:28 +0000576
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000577 unsigned Entry = 0;
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000578 for (SmallVectorImpl<CallSiteEntry>::const_iterator
579 I = CallSites.begin(), E = CallSites.end(); I != E; ++I) {
580 const CallSiteEntry &S = *I;
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000581
Chris Lattnerc0215722010-04-04 19:25:43 +0000582 MCSymbol *EHFuncBeginSym =
Chris Lattner84ac8b72010-04-05 00:26:50 +0000583 Asm->GetTempSymbol("eh_func_begin", Asm->getFunctionNumber());
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000584
Chris Lattner16112732010-03-14 01:41:15 +0000585 MCSymbol *BeginLabel = S.BeginLabel;
586 if (BeginLabel == 0)
587 BeginLabel = EHFuncBeginSym;
588 MCSymbol *EndLabel = S.EndLabel;
589 if (EndLabel == 0)
Chris Lattner84ac8b72010-04-05 00:26:50 +0000590 EndLabel = Asm->GetTempSymbol("eh_func_end", Asm->getFunctionNumber());
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000591
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000592
Bill Wendlinga583c552009-08-20 22:02:24 +0000593 // Offset of the call site relative to the previous call site, counted in
594 // number of 16-byte bundles. The first call site is counted relative to
595 // the start of the procedure fragment.
Renato Golinf1f6de12011-08-18 23:43:14 +0000596 if (VerboseAsm)
Benjamin Kramer47b87982011-10-16 15:46:29 +0000597 Asm->OutStreamer.AddComment(">> Call Site " + Twine(++Entry) + " <<");
Chris Lattnerf88dce12010-04-04 21:31:54 +0000598 Asm->EmitLabelDifference(BeginLabel, EHFuncBeginSym, 4);
Renato Golinf1f6de12011-08-18 23:43:14 +0000599 if (VerboseAsm)
600 Asm->OutStreamer.AddComment(Twine(" Call between ") +
601 BeginLabel->getName() + " and " +
602 EndLabel->getName());
Chris Lattnera6437182010-04-04 19:58:12 +0000603 Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
Bill Wendlingeb907212009-05-15 01:12:28 +0000604
Bill Wendlinga583c552009-08-20 22:02:24 +0000605 // Offset of the landing pad, counted in 16-byte bundles relative to the
606 // @LPStart address.
Renato Golinf1f6de12011-08-18 23:43:14 +0000607 if (!S.PadLabel) {
608 if (VerboseAsm)
609 Asm->OutStreamer.AddComment(" has no landing pad");
Chris Lattnerbcb83e52010-01-20 07:41:15 +0000610 Asm->OutStreamer.EmitIntValue(0, 4/*size*/, 0/*addrspace*/);
Renato Golinf1f6de12011-08-18 23:43:14 +0000611 } else {
612 if (VerboseAsm)
613 Asm->OutStreamer.AddComment(Twine(" jumps to ") +
614 S.PadLabel->getName());
Chris Lattnerf88dce12010-04-04 21:31:54 +0000615 Asm->EmitLabelDifference(S.PadLabel, EHFuncBeginSym, 4);
Renato Golinf1f6de12011-08-18 23:43:14 +0000616 }
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000617
Bill Wendlinga583c552009-08-20 22:02:24 +0000618 // Offset of the first associated action record, relative to the start of
619 // the action table. This value is biased by 1 (1 indicates the start of
620 // the action table), and 0 indicates that there are no actions.
Renato Golinf1f6de12011-08-18 23:43:14 +0000621 if (VerboseAsm) {
622 if (S.Action == 0)
623 Asm->OutStreamer.AddComment(" On action: cleanup");
624 else
Benjamin Kramer47b87982011-10-16 15:46:29 +0000625 Asm->OutStreamer.AddComment(" On action: " +
626 Twine((S.Action - 1) / 2 + 1));
Renato Golinf1f6de12011-08-18 23:43:14 +0000627 }
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000628 Asm->EmitULEB128(S.Action);
Jim Grosbach1b747ad2009-08-11 00:09:57 +0000629 }
Bill Wendlingeb907212009-05-15 01:12:28 +0000630 }
631
Bill Wendlinga583c552009-08-20 22:02:24 +0000632 // Emit the Action Table.
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000633 int Entry = 0;
Bill Wendling5cff4872009-07-28 23:44:43 +0000634 for (SmallVectorImpl<ActionEntry>::const_iterator
635 I = Actions.begin(), E = Actions.end(); I != E; ++I) {
636 const ActionEntry &Action = *I;
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000637
638 if (VerboseAsm) {
639 // Emit comments that decode the action table.
Benjamin Kramer47b87982011-10-16 15:46:29 +0000640 Asm->OutStreamer.AddComment(">> Action Record " + Twine(++Entry) + " <<");
Renato Golinf1f6de12011-08-18 23:43:14 +0000641 }
642
643 // Type Filter
644 //
645 // Used by the runtime to match the type of the thrown exception to the
646 // type of the catch clauses or the types in the exception specification.
647 if (VerboseAsm) {
Duncan Sands42e5c792011-09-28 09:13:02 +0000648 if (Action.ValueForTypeID > 0)
Benjamin Kramer47b87982011-10-16 15:46:29 +0000649 Asm->OutStreamer.AddComment(" Catch TypeInfo " +
650 Twine(Action.ValueForTypeID));
Duncan Sands42e5c792011-09-28 09:13:02 +0000651 else if (Action.ValueForTypeID < 0)
Benjamin Kramer47b87982011-10-16 15:46:29 +0000652 Asm->OutStreamer.AddComment(" Filter TypeInfo " +
653 Twine(Action.ValueForTypeID));
Duncan Sands42e5c792011-09-28 09:13:02 +0000654 else
655 Asm->OutStreamer.AddComment(" Cleanup");
Renato Golinf1f6de12011-08-18 23:43:14 +0000656 }
657 Asm->EmitSLEB128(Action.ValueForTypeID);
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000658
Renato Golinf1f6de12011-08-18 23:43:14 +0000659 // Action Record
660 //
661 // Self-relative signed displacement in bytes of the next action record,
662 // or 0 if there is no next action record.
663 if (VerboseAsm) {
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000664 if (Action.NextAction == 0) {
665 Asm->OutStreamer.AddComment(" No further actions");
666 } else {
667 unsigned NextAction = Entry + (Action.NextAction + 1) / 2;
Benjamin Kramer47b87982011-10-16 15:46:29 +0000668 Asm->OutStreamer.AddComment(" Continue to action "+Twine(NextAction));
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000669 }
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000670 }
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000671 Asm->EmitSLEB128(Action.NextAction);
Bill Wendlingeb907212009-05-15 01:12:28 +0000672 }
673
Bill Wendling48dc29e2009-10-22 20:48:59 +0000674 // Emit the Catch TypeInfos.
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000675 if (VerboseAsm && !TypeInfos.empty()) {
676 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<");
Chris Lattner233f52b2010-03-09 23:52:58 +0000677 Asm->OutStreamer.AddBlankLine();
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000678 Entry = TypeInfos.size();
Chris Lattner233f52b2010-03-09 23:52:58 +0000679 }
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000680
Dan Gohman46510a72010-04-15 01:51:59 +0000681 for (std::vector<const GlobalVariable *>::const_reverse_iterator
Bill Wendling01c69372009-11-19 00:09:14 +0000682 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
Bill Wendlingfb7634f2009-11-19 19:21:09 +0000683 const GlobalVariable *GV = *I;
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000684 if (VerboseAsm)
Benjamin Kramer47b87982011-10-16 15:46:29 +0000685 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
Chris Lattner90e4af72010-03-10 00:09:21 +0000686 if (GV)
Chris Lattnerd2af7852010-04-04 20:20:50 +0000687 Asm->EmitReference(GV, TTypeEncoding);
Chris Lattner90e4af72010-03-10 00:09:21 +0000688 else
Chris Lattnerd2af7852010-04-04 20:20:50 +0000689 Asm->OutStreamer.EmitIntValue(0,Asm->GetSizeOfEncodedValue(TTypeEncoding),
690 0);
Bill Wendlingeb907212009-05-15 01:12:28 +0000691 }
692
Bill Wendling48dc29e2009-10-22 20:48:59 +0000693 // Emit the Exception Specifications.
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000694 if (VerboseAsm && !FilterIds.empty()) {
695 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<");
Chris Lattner233f52b2010-03-09 23:52:58 +0000696 Asm->OutStreamer.AddBlankLine();
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000697 Entry = 0;
Chris Lattner233f52b2010-03-09 23:52:58 +0000698 }
Bill Wendling5cff4872009-07-28 23:44:43 +0000699 for (std::vector<unsigned>::const_iterator
700 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
701 unsigned TypeID = *I;
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000702 if (VerboseAsm) {
703 --Entry;
704 if (TypeID != 0)
Benjamin Kramer47b87982011-10-16 15:46:29 +0000705 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry));
Bill Wendling8fcd3e62011-06-21 22:30:20 +0000706 }
707
708 Asm->EmitULEB128(TypeID);
Bill Wendlingeb907212009-05-15 01:12:28 +0000709 }
710
Chris Lattner059ea132010-04-28 01:05:45 +0000711 Asm->EmitAlignment(2);
Bill Wendlingeb907212009-05-15 01:12:28 +0000712}
713
Bill Wendlingeb907212009-05-15 01:12:28 +0000714/// EndModule - Emit all exception information that should come after the
715/// content.
716void DwarfException::EndModule() {
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000717 assert(0 && "Should be implemented");
Bill Wendlingeb907212009-05-15 01:12:28 +0000718}
719
Bill Wendling28275fd2009-09-10 06:50:01 +0000720/// BeginFunction - Gather pre-function exception information. Assumes it's
721/// being emitted immediately after the function entry point.
Chris Lattnereec791a2010-01-26 23:18:02 +0000722void DwarfException::BeginFunction(const MachineFunction *MF) {
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000723 assert(0 && "Should be implemented");
Bill Wendlingeb907212009-05-15 01:12:28 +0000724}
725
726/// EndFunction - Gather and emit post-function exception information.
727///
728void DwarfException::EndFunction() {
Anton Korobeynikovd7e8ddc2011-01-14 21:57:45 +0000729 assert(0 && "Should be implemented");
Bill Wendlingeb907212009-05-15 01:12:28 +0000730}