blob: f112120c1abc75f99922643a6e31ea1a10d26a5d [file] [log] [blame]
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +00001//===-- CodeGen/AsmPrinter/EHStreamer.cpp - Exception Directive Streamer --===//
Bill Wendlingd64cd2b2009-05-15 01:12:28 +00002//
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//
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000010// This file contains support for writing exception info into assembly files.
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000011//
12//===----------------------------------------------------------------------===//
13
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000014#include "EHStreamer.h"
Chris Lattnerda790ea2010-04-05 05:28:23 +000015#include "llvm/CodeGen/AsmPrinter.h"
David Greenea5be1b12009-08-19 21:55:33 +000016#include "llvm/CodeGen/MachineFunction.h"
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000017#include "llvm/CodeGen/MachineInstr.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000018#include "llvm/CodeGen/MachineModuleInfo.h"
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000019#include "llvm/IR/Function.h"
Chris Lattnerb8666022009-09-16 01:46:41 +000020#include "llvm/MC/MCAsmInfo.h"
Chris Lattner4b7dadb2009-08-19 05:49:37 +000021#include "llvm/MC/MCStreamer.h"
Chris Lattner555ceabe2010-01-16 18:37:32 +000022#include "llvm/MC/MCSymbol.h"
Logan Chien5b776b72014-02-22 14:00:39 +000023#include "llvm/Support/LEB128.h"
Chris Lattnerc16c75e2009-08-02 01:34:32 +000024#include "llvm/Target/TargetLoweringObjectFile.h"
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000025
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000026using namespace llvm;
27
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000028EHStreamer::EHStreamer(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {}
Bill Wendlingdd20b982009-05-15 01:18:50 +000029
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000030EHStreamer::~EHStreamer() {}
Bill Wendlingdd20b982009-05-15 01:18:50 +000031
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000032/// How many leading type ids two landing pads have in common.
33unsigned EHStreamer::sharedTypeIDs(const LandingPadInfo *L,
34 const LandingPadInfo *R) {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000035 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
36 unsigned LSize = LIds.size(), RSize = RIds.size();
37 unsigned MinSize = LSize < RSize ? LSize : RSize;
38 unsigned Count = 0;
39
40 for (; Count != MinSize; ++Count)
41 if (LIds[Count] != RIds[Count])
42 return Count;
43
44 return Count;
45}
46
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000047/// Compute the actions table and gather the first action index for each landing
48/// pad site.
49unsigned EHStreamer::
50computeActionsTable(const SmallVectorImpl<const LandingPadInfo*> &LandingPads,
Bill Wendlingb67440e2009-07-29 00:31:35 +000051 SmallVectorImpl<ActionEntry> &Actions,
52 SmallVectorImpl<unsigned> &FirstActions) {
Bill Wendling0e749fe2009-08-20 22:02:24 +000053
54 // The action table follows the call-site table in the LSDA. The individual
55 // records are of two types:
56 //
57 // * Catch clause
58 // * Exception specification
59 //
60 // The two record kinds have the same format, with only small differences.
61 // They are distinguished by the "switch value" field: Catch clauses
62 // (TypeInfos) have strictly positive switch values, and exception
63 // specifications (FilterIds) have strictly negative switch values. Value 0
64 // indicates a catch-all clause.
65 //
Bill Wendling1fddd872009-07-28 23:22:13 +000066 // Negative type IDs index into FilterIds. Positive type IDs index into
67 // TypeInfos. The value written for a positive type ID is just the type ID
68 // itself. For a negative type ID, however, the value written is the
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000069 // (negative) byte offset of the corresponding FilterIds entry. The byte
Bill Wendling1fddd872009-07-28 23:22:13 +000070 // offset is usually equal to the type ID (because the FilterIds entries are
71 // written using a variable width encoding, which outputs one byte per entry
72 // as long as the value written is not too large) but can differ. This kind
73 // of complication does not occur for positive type IDs because type infos are
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000074 // output using a fixed width encoding. FilterOffsets[i] holds the byte
75 // offset corresponding to FilterIds[i].
Bill Wendling45057342009-07-29 21:19:44 +000076
77 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000078 SmallVector<int, 16> FilterOffsets;
79 FilterOffsets.reserve(FilterIds.size());
80 int Offset = -1;
Bill Wendling45057342009-07-29 21:19:44 +000081
82 for (std::vector<unsigned>::const_iterator
83 I = FilterIds.begin(), E = FilterIds.end(); I != E; ++I) {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000084 FilterOffsets.push_back(Offset);
Logan Chien5b776b72014-02-22 14:00:39 +000085 Offset -= getULEB128Size(*I);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000086 }
87
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000088 FirstActions.reserve(LandingPads.size());
89
90 int FirstAction = 0;
91 unsigned SizeActions = 0;
Craig Topper353eda42014-04-24 06:44:33 +000092 const LandingPadInfo *PrevLPI = nullptr;
Bill Wendling45057342009-07-29 21:19:44 +000093
Bill Wendling23b177e2009-07-28 23:44:43 +000094 for (SmallVectorImpl<const LandingPadInfo *>::const_iterator
Bill Wendling1fddd872009-07-28 23:22:13 +000095 I = LandingPads.begin(), E = LandingPads.end(); I != E; ++I) {
96 const LandingPadInfo *LPI = *I;
97 const std::vector<int> &TypeIds = LPI->TypeIds;
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +000098 unsigned NumShared = PrevLPI ? sharedTypeIDs(LPI, PrevLPI) : 0;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +000099 unsigned SizeSiteActions = 0;
100
101 if (NumShared < TypeIds.size()) {
102 unsigned SizeAction = 0;
Bill Wendling7742b642010-02-10 21:41:57 +0000103 unsigned PrevAction = (unsigned)-1;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000104
105 if (NumShared) {
Chris Lattner07c1b942010-04-04 20:10:41 +0000106 unsigned SizePrevIds = PrevLPI->TypeIds.size();
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000107 assert(Actions.size());
Bill Wendling7742b642010-02-10 21:41:57 +0000108 PrevAction = Actions.size() - 1;
Logan Chien5b776b72014-02-22 14:00:39 +0000109 SizeAction = getSLEB128Size(Actions[PrevAction].NextAction) +
110 getSLEB128Size(Actions[PrevAction].ValueForTypeID);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000111
112 for (unsigned j = NumShared; j != SizePrevIds; ++j) {
Bill Wendling7742b642010-02-10 21:41:57 +0000113 assert(PrevAction != (unsigned)-1 && "PrevAction is invalid!");
Logan Chien5b776b72014-02-22 14:00:39 +0000114 SizeAction -= getSLEB128Size(Actions[PrevAction].ValueForTypeID);
Bill Wendling7742b642010-02-10 21:41:57 +0000115 SizeAction += -Actions[PrevAction].NextAction;
116 PrevAction = Actions[PrevAction].Previous;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000117 }
118 }
119
120 // Compute the actions.
Bill Wendling1fddd872009-07-28 23:22:13 +0000121 for (unsigned J = NumShared, M = TypeIds.size(); J != M; ++J) {
122 int TypeID = TypeIds[J];
123 assert(-1 - TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000124 int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
Logan Chien5b776b72014-02-22 14:00:39 +0000125 unsigned SizeTypeID = getSLEB128Size(ValueForTypeID);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000126
127 int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
Logan Chien5b776b72014-02-22 14:00:39 +0000128 SizeAction = SizeTypeID + getSLEB128Size(NextAction);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000129 SizeSiteActions += SizeAction;
130
Bill Wendling0e749fe2009-08-20 22:02:24 +0000131 ActionEntry Action = { ValueForTypeID, NextAction, PrevAction };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000132 Actions.push_back(Action);
Bill Wendling7742b642010-02-10 21:41:57 +0000133 PrevAction = Actions.size() - 1;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000134 }
135
136 // Record the first action of the landing pad site.
137 FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
138 } // else identical - re-use previous FirstAction
139
Bill Wendling0e749fe2009-08-20 22:02:24 +0000140 // Information used when created the call-site table. The action record
141 // field of the call site record is the offset of the first associated
142 // action record, relative to the start of the actions table. This value is
Bill Wendling7742b642010-02-10 21:41:57 +0000143 // biased by 1 (1 indicating the start of the actions table), and 0
Bill Wendling0e749fe2009-08-20 22:02:24 +0000144 // indicates that there are no actions.
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000145 FirstActions.push_back(FirstAction);
146
147 // Compute this sites contribution to size.
148 SizeActions += SizeSiteActions;
Bill Wendling1fddd872009-07-28 23:22:13 +0000149
150 PrevLPI = LPI;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000151 }
152
Bill Wendling1fddd872009-07-28 23:22:13 +0000153 return SizeActions;
154}
155
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000156/// Return `true' if this is a call to a function marked `nounwind'. Return
157/// `false' otherwise.
158bool EHStreamer::callToNoUnwindFunction(const MachineInstr *MI) {
Evan Cheng7f8e5632011-12-07 07:15:52 +0000159 assert(MI->isCall() && "This should be a call instruction!");
Bill Wendlinge4120642009-11-12 21:59:20 +0000160
161 bool MarkedNoUnwind = false;
162 bool SawFunc = false;
163
164 for (unsigned I = 0, E = MI->getNumOperands(); I != E; ++I) {
165 const MachineOperand &MO = MI->getOperand(I);
166
Chris Lattner17d38592010-03-31 06:09:04 +0000167 if (!MO.isGlobal()) continue;
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000168
Dan Gohmanbcaf6812010-04-15 01:51:59 +0000169 const Function *F = dyn_cast<Function>(MO.getGlobal());
Craig Topper353eda42014-04-24 06:44:33 +0000170 if (!F) continue;
Bill Wendlingc781d7a2009-11-12 23:13:08 +0000171
Chris Lattner17d38592010-03-31 06:09:04 +0000172 if (SawFunc) {
173 // Be conservative. If we have more than one function operand for this
174 // call, then we can't make the assumption that it's the callee and
175 // not a parameter to the call.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000176 //
Chris Lattner17d38592010-03-31 06:09:04 +0000177 // FIXME: Determine if there's a way to say that `F' is the callee or
178 // parameter.
179 MarkedNoUnwind = false;
180 break;
Bill Wendlinge4120642009-11-12 21:59:20 +0000181 }
Chris Lattner17d38592010-03-31 06:09:04 +0000182
183 MarkedNoUnwind = F->doesNotThrow();
184 SawFunc = true;
Bill Wendlinge4120642009-11-12 21:59:20 +0000185 }
186
187 return MarkedNoUnwind;
188}
189
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000190/// Compute the call-site table. The entry for an invoke has a try-range
191/// containing the call, a non-zero landing pad, and an appropriate action. The
192/// entry for an ordinary call has a try-range containing the call and zero for
193/// the landing pad and the action. Calls marked 'nounwind' have no entry and
194/// must not be contained in the try-range of any entry - they form gaps in the
195/// table. Entries must be ordered by try-range address.
196void EHStreamer::
197computeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites,
Bill Wendlingb67440e2009-07-29 00:31:35 +0000198 const SmallVectorImpl<const LandingPadInfo *> &LandingPads,
199 const SmallVectorImpl<unsigned> &FirstActions) {
Reid Klecknerf2acbba2014-12-19 22:30:08 +0000200 // Invokes and nounwind calls have entries in PadMap (due to being bracketed
201 // by try-range labels when lowered). Ordinary calls do not, so appropriate
202 // try-ranges for them need be deduced so we can put them in the LSDA.
203 RangeMapType PadMap;
204 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
205 const LandingPadInfo *LandingPad = LandingPads[i];
206 for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
207 MCSymbol *BeginLabel = LandingPad->BeginLabels[j];
208 assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
209 PadRange P = { i, j };
210 PadMap[BeginLabel] = P;
211 }
212 }
213
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000214 // The end label of the previous invoke or nounwind try-range.
Craig Topper353eda42014-04-24 06:44:33 +0000215 MCSymbol *LastLabel = nullptr;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000216
217 // Whether there is a potentially throwing instruction (currently this means
218 // an ordinary call) between the end of the previous try-range and now.
219 bool SawPotentiallyThrowing = false;
220
Bill Wendling23b177e2009-07-28 23:44:43 +0000221 // Whether the last CallSite entry was for an invoke.
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000222 bool PreviousIsInvoke = false;
223
Reid Kleckner93acac62014-12-19 22:19:48 +0000224 bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
225
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000226 // Visit all instructions in order of address.
Alexey Samsonov41b977d2014-04-30 18:29:51 +0000227 for (const auto &MBB : *Asm->MF) {
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000228 for (const auto &MI : MBB) {
229 if (!MI.isEHLabel()) {
230 if (MI.isCall())
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000231 SawPotentiallyThrowing |= !callToNoUnwindFunction(&MI);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000232 continue;
233 }
234
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000235 // End of the previous try-range?
Alexey Samsonovf74bde62014-04-30 22:17:38 +0000236 MCSymbol *BeginLabel = MI.getOperand(0).getMCSymbol();
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000237 if (BeginLabel == LastLabel)
238 SawPotentiallyThrowing = false;
239
240 // Beginning of a new try-range?
Jeffrey Yasskinb40d3f72009-11-10 01:02:17 +0000241 RangeMapType::const_iterator L = PadMap.find(BeginLabel);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000242 if (L == PadMap.end())
243 // Nope, it was just some random label.
244 continue;
245
Bill Wendling0e749fe2009-08-20 22:02:24 +0000246 const PadRange &P = L->second;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000247 const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000248 assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
249 "Inconsistent landing pad map!");
250
Bill Wendling0e749fe2009-08-20 22:02:24 +0000251 // For Dwarf exception handling (SjLj handling doesn't use this). If some
252 // instruction between the previous try-range and this one may throw,
253 // create a call-site entry with no landing pad for the region between the
254 // try-ranges.
Reid Kleckner93acac62014-12-19 22:19:48 +0000255 if (SawPotentiallyThrowing && !IsSJLJ) {
Craig Topper353eda42014-04-24 06:44:33 +0000256 CallSiteEntry Site = { LastLabel, BeginLabel, nullptr, 0 };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000257 CallSites.push_back(Site);
258 PreviousIsInvoke = false;
259 }
260
261 LastLabel = LandingPad->EndLabels[P.RangeIndex];
262 assert(BeginLabel && LastLabel && "Invalid landing pad!");
263
Chris Lattner17d38592010-03-31 06:09:04 +0000264 if (!LandingPad->LandingPadLabel) {
265 // Create a gap.
266 PreviousIsInvoke = false;
267 } else {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000268 // This try-range is for an invoke.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000269 CallSiteEntry Site = {
270 BeginLabel,
271 LastLabel,
272 LandingPad->LandingPadLabel,
273 FirstActions[P.PadIndex]
274 };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000275
Jim Grosbach5afbf2b2009-09-01 17:19:13 +0000276 // Try to merge with the previous call-site. SJLJ doesn't do this
Reid Kleckner93acac62014-12-19 22:19:48 +0000277 if (PreviousIsInvoke && !IsSJLJ) {
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000278 CallSiteEntry &Prev = CallSites.back();
279 if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
280 // Extend the range of the previous entry.
281 Prev.EndLabel = Site.EndLabel;
282 continue;
283 }
284 }
285
286 // Otherwise, create a new call-site.
Reid Kleckner93acac62014-12-19 22:19:48 +0000287 if (!IsSJLJ)
Jim Grosbach54c05302010-01-28 01:45:32 +0000288 CallSites.push_back(Site);
289 else {
290 // SjLj EH must maintain the call sites in the order assigned
291 // to them by the SjLjPrepare pass.
292 unsigned SiteNo = MMI->getCallSiteBeginLabel(BeginLabel);
293 if (CallSites.size() < SiteNo)
294 CallSites.resize(SiteNo);
295 CallSites[SiteNo - 1] = Site;
296 }
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000297 PreviousIsInvoke = true;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000298 }
299 }
300 }
301
302 // If some instruction between the previous try-range and the end of the
303 // function may throw, create a call-site entry with no landing pad for the
304 // region following the try-range.
Reid Kleckner93acac62014-12-19 22:19:48 +0000305 if (SawPotentiallyThrowing && !IsSJLJ) {
Craig Topper353eda42014-04-24 06:44:33 +0000306 CallSiteEntry Site = { LastLabel, nullptr, nullptr, 0 };
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000307 CallSites.push_back(Site);
308 }
Bill Wendlingb67440e2009-07-29 00:31:35 +0000309}
310
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000311/// Emit landing pads and actions.
Bill Wendling2cf00142009-07-29 00:50:05 +0000312///
313/// The general organization of the table is complex, but the basic concepts are
314/// easy. First there is a header which describes the location and organization
315/// of the three components that follow.
Eric Christopherd517ac02009-08-28 22:33:43 +0000316///
Bill Wendling2cf00142009-07-29 00:50:05 +0000317/// 1. The landing pad site information describes the range of code covered by
318/// the try. In our case it's an accumulation of the ranges covered by the
319/// invokes in the try. There is also a reference to the landing pad that
320/// handles the exception once processed. Finally an index into the actions
321/// table.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000322/// 2. The action table, in our case, is composed of pairs of type IDs and next
Bill Wendling2cf00142009-07-29 00:50:05 +0000323/// action offset. Starting with the action index from the landing pad
Bill Wendling0e749fe2009-08-20 22:02:24 +0000324/// site, each type ID is checked for a match to the current exception. If
Bill Wendling2cf00142009-07-29 00:50:05 +0000325/// it matches then the exception and type id are passed on to the landing
326/// pad. Otherwise the next action is looked up. This chain is terminated
Bill Wendling023ed642009-09-10 06:50:01 +0000327/// with a next action of zero. If no type id is found then the frame is
Bill Wendling2cf00142009-07-29 00:50:05 +0000328/// unwound and handling continues.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000329/// 3. Type ID table contains references to all the C++ typeinfo for all
Bill Wendling023ed642009-09-10 06:50:01 +0000330/// catches in the function. This tables is reverse indexed base 1.
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000331void EHStreamer::emitExceptionTable() {
Reid Kleckner283bc2e2014-11-14 00:35:50 +0000332 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
Bill Wendlingb67440e2009-07-29 00:31:35 +0000333 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
334 const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
Bill Wendlingb67440e2009-07-29 00:31:35 +0000335
336 // Sort the landing pads in order of their type ids. This is used to fold
337 // duplicate actions.
338 SmallVector<const LandingPadInfo *, 64> LandingPads;
339 LandingPads.reserve(PadInfos.size());
340
341 for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
342 LandingPads.push_back(&PadInfos[i]);
343
Benjamin Kramerb0f74b22014-03-07 21:35:39 +0000344 // Order landing pads lexicographically by type id.
345 std::sort(LandingPads.begin(), LandingPads.end(),
346 [](const LandingPadInfo *L,
347 const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; });
Bill Wendlingb67440e2009-07-29 00:31:35 +0000348
349 // Compute the actions table and gather the first action index for each
350 // landing pad site.
351 SmallVector<ActionEntry, 32> Actions;
352 SmallVector<unsigned, 64> FirstActions;
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000353 unsigned SizeActions =
354 computeActionsTable(LandingPads, Actions, FirstActions);
Bill Wendlingb67440e2009-07-29 00:31:35 +0000355
Bill Wendlingb67440e2009-07-29 00:31:35 +0000356 // Compute the call-site table.
357 SmallVector<CallSiteEntry, 64> CallSites;
Reid Klecknerf2acbba2014-12-19 22:30:08 +0000358 computeCallSiteTable(CallSites, LandingPads, FirstActions);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000359
360 // Final tallies.
361
362 // Call sites.
Chris Lattnerfd795022010-04-05 00:26:50 +0000363 bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj;
Bill Wendlinga482ec82009-09-10 00:17:04 +0000364 bool HaveTTData = IsSJLJ ? (!TypeInfos.empty() || !FilterIds.empty()) : true;
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000365
Bill Wendling88fdcd32010-02-24 23:34:35 +0000366 unsigned CallSiteTableLength;
Bill Wendlinga482ec82009-09-10 00:17:04 +0000367 if (IsSJLJ)
Bill Wendling88fdcd32010-02-24 23:34:35 +0000368 CallSiteTableLength = 0;
Chris Lattner07c1b942010-04-04 20:10:41 +0000369 else {
370 unsigned SiteStartSize = 4; // dwarf::DW_EH_PE_udata4
371 unsigned SiteLengthSize = 4; // dwarf::DW_EH_PE_udata4
372 unsigned LandingPadSize = 4; // dwarf::DW_EH_PE_udata4
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000373 CallSiteTableLength =
Chris Lattner07c1b942010-04-04 20:10:41 +0000374 CallSites.size() * (SiteStartSize + SiteLengthSize + LandingPadSize);
375 }
Bill Wendlinga482ec82009-09-10 00:17:04 +0000376
Jim Grosbach693e36a2009-08-11 00:09:57 +0000377 for (unsigned i = 0, e = CallSites.size(); i < e; ++i) {
Logan Chien5b776b72014-02-22 14:00:39 +0000378 CallSiteTableLength += getULEB128Size(CallSites[i].Action);
Bill Wendlinga482ec82009-09-10 00:17:04 +0000379 if (IsSJLJ)
Logan Chien5b776b72014-02-22 14:00:39 +0000380 CallSiteTableLength += getULEB128Size(i);
Jim Grosbach693e36a2009-08-11 00:09:57 +0000381 }
Bill Wendlinga482ec82009-09-10 00:17:04 +0000382
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000383 // Type infos.
Chris Lattnerc16c75e2009-08-02 01:34:32 +0000384 const MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection();
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000385 unsigned TTypeEncoding;
Bill Wendling9e5c2062009-09-10 06:27:16 +0000386 unsigned TypeFormatSize;
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000387
Bill Wendlingbf562682009-09-10 01:12:47 +0000388 if (!HaveTTData) {
Bill Wendling023ed642009-09-10 06:50:01 +0000389 // For SjLj exceptions, if there is no TypeInfo, then we just explicitly say
390 // that we're omitting that bit.
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000391 TTypeEncoding = dwarf::DW_EH_PE_omit;
Chris Lattnerfd795022010-04-05 00:26:50 +0000392 // dwarf::DW_EH_PE_absptr
Chandler Carruth5da3f052012-11-01 09:14:31 +0000393 TypeFormatSize = Asm->getDataLayout().getPointerSize();
Chris Lattner47fc2352009-07-31 22:03:47 +0000394 } else {
Chris Lattner7005cd32009-08-02 03:59:56 +0000395 // Okay, we have actual filters or typeinfos to emit. As such, we need to
396 // pick a type encoding for them. We're about to emit a list of pointers to
397 // typeinfo objects at the end of the LSDA. However, unless we're in static
398 // mode, this reference will require a relocation by the dynamic linker.
Chris Lattnerf4b92a82009-07-31 22:18:14 +0000399 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000400 // Because of this, we have a couple of options:
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000401 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000402 // 1) If we are in -static mode, we can always use an absolute reference
403 // from the LSDA, because the static linker will resolve it.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000404 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000405 // 2) Otherwise, if the LSDA section is writable, we can output the direct
406 // reference to the typeinfo and allow the dynamic linker to relocate
407 // it. Since it is in a writable section, the dynamic linker won't
408 // have a problem.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000409 //
Chris Lattner7005cd32009-08-02 03:59:56 +0000410 // 3) Finally, if we're in PIC mode and the LDSA section isn't writable,
411 // we need to use some form of indirection. For example, on Darwin,
412 // we can output a statically-relocatable reference to a dyld stub. The
413 // offset to the stub is constant, but the contents are in a section
414 // that is updated by the dynamic linker. This is easy enough, but we
415 // need to tell the personality function of the unwinder to indirect
416 // through the dyld stub.
417 //
Bill Wendlingbf562682009-09-10 01:12:47 +0000418 // FIXME: When (3) is actually implemented, we'll have to emit the stubs
Chris Lattner7005cd32009-08-02 03:59:56 +0000419 // somewhere. This predicate should be moved to a shared location that is
420 // in target-independent code.
421 //
Anton Korobeynikovae4ccc12010-02-15 22:35:59 +0000422 TTypeEncoding = Asm->getObjFileLowering().getTTypeEncoding();
Chris Lattnere619c0d2010-04-04 20:20:50 +0000423 TypeFormatSize = Asm->GetSizeOfEncodedValue(TTypeEncoding);
Bill Wendling243ac562009-09-10 02:07:37 +0000424 }
Bill Wendlingbf562682009-09-10 01:12:47 +0000425
Bill Wendling243ac562009-09-10 02:07:37 +0000426 // Begin the exception table.
Anton Korobeynikovfe3a6e02011-01-30 22:07:31 +0000427 // Sometimes we want not to emit the data into separate section (e.g. ARM
428 // EHABI). In this case LSDASection will be NULL.
Anton Korobeynikovb15beb22011-01-24 22:38:40 +0000429 if (LSDASection)
430 Asm->OutStreamer.SwitchSection(LSDASection);
Chris Lattner9e06e532010-04-28 01:05:45 +0000431 Asm->EmitAlignment(2);
Bill Wendlingbf562682009-09-10 01:12:47 +0000432
Bill Wendling88fdcd32010-02-24 23:34:35 +0000433 // Emit the LSDA.
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000434 MCSymbol *GCCETSym =
Chris Lattnereec9bf12010-03-10 02:48:06 +0000435 Asm->OutContext.GetOrCreateSymbol(Twine("GCC_except_table")+
Chris Lattnerfd795022010-04-05 00:26:50 +0000436 Twine(Asm->getFunctionNumber()));
Chris Lattnereec9bf12010-03-10 02:48:06 +0000437 Asm->OutStreamer.EmitLabel(GCCETSym);
Chris Lattnerfd795022010-04-05 00:26:50 +0000438 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("exception",
439 Asm->getFunctionNumber()));
Bill Wendling243ac562009-09-10 02:07:37 +0000440
Chris Lattnereec9bf12010-03-10 02:48:06 +0000441 if (IsSJLJ)
Chris Lattnera179b522010-04-04 19:25:43 +0000442 Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("_LSDA_",
443 Asm->getFunctionNumber()));
Bill Wendling243ac562009-09-10 02:07:37 +0000444
Bill Wendling88fdcd32010-02-24 23:34:35 +0000445 // Emit the LSDA header.
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000446 Asm->EmitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart");
447 Asm->EmitEncodingByte(TTypeEncoding, "@TType");
Bill Wendling243ac562009-09-10 02:07:37 +0000448
Bill Wendling88fdcd32010-02-24 23:34:35 +0000449 // The type infos need to be aligned. GCC does this by inserting padding just
450 // before the type infos. However, this changes the size of the exception
451 // table, so you need to take this into account when you output the exception
452 // table size. However, the size is output using a variable length encoding.
453 // So by increasing the size by inserting padding, you may increase the number
454 // of bytes used for writing the size. If it increases, say by one byte, then
455 // you now need to output one less byte of padding to get the type infos
456 // aligned. However this decreases the size of the exception table. This
457 // changes the value you have to output for the exception table size. Due to
458 // the variable length encoding, the number of bytes used for writing the
459 // length may decrease. If so, you then have to increase the amount of
460 // padding. And so on. If you look carefully at the GCC code you will see that
461 // it indeed does this in a loop, going on and on until the values stabilize.
462 // We chose another solution: don't output padding inside the table like GCC
463 // does, instead output it before the table.
464 unsigned SizeTypes = TypeInfos.size() * TypeFormatSize;
Logan Chien5b776b72014-02-22 14:00:39 +0000465 unsigned CallSiteTableLengthSize = getULEB128Size(CallSiteTableLength);
Bill Wendling88fdcd32010-02-24 23:34:35 +0000466 unsigned TTypeBaseOffset =
467 sizeof(int8_t) + // Call site format
468 CallSiteTableLengthSize + // Call site table length size
469 CallSiteTableLength + // Call site table length
470 SizeActions + // Actions size
471 SizeTypes;
Logan Chien5b776b72014-02-22 14:00:39 +0000472 unsigned TTypeBaseOffsetSize = getULEB128Size(TTypeBaseOffset);
Bill Wendling88fdcd32010-02-24 23:34:35 +0000473 unsigned TotalSize =
474 sizeof(int8_t) + // LPStart format
475 sizeof(int8_t) + // TType format
476 (HaveTTData ? TTypeBaseOffsetSize : 0) + // TType base offset size
477 TTypeBaseOffset; // TType base offset
478 unsigned SizeAlign = (4 - TotalSize) & 3;
479
Bill Wendling24c74f12010-02-25 23:52:44 +0000480 if (HaveTTData) {
Bill Wendlingfea6c4e2010-02-26 21:31:01 +0000481 // Account for any extra padding that will be added to the call site table
Bill Wendling60aa4df2010-02-25 21:19:47 +0000482 // length.
Chris Lattner9efd1182010-04-04 19:09:29 +0000483 Asm->EmitULEB128(TTypeBaseOffset, "@TType base offset", SizeAlign);
Bill Wendlingc3a93762010-02-26 22:17:52 +0000484 SizeAlign = 0;
Bill Wendling24c74f12010-02-25 23:52:44 +0000485 }
Bill Wendling15349f82009-07-28 22:23:45 +0000486
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000487 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
488
Bill Wendling023ed642009-09-10 06:50:01 +0000489 // SjLj Exception handling
Bill Wendlinga482ec82009-09-10 00:17:04 +0000490 if (IsSJLJ) {
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000491 Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site");
Bill Wendlingc3a93762010-02-26 22:17:52 +0000492
493 // Add extra padding if it wasn't added to the TType base offset.
Chris Lattner9efd1182010-04-04 19:09:29 +0000494 Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000495
Jim Grosbach693e36a2009-08-11 00:09:57 +0000496 // Emit the landing pad site information.
Jim Grosbach486be662009-08-17 16:41:22 +0000497 unsigned idx = 0;
498 for (SmallVectorImpl<CallSiteEntry>::const_iterator
499 I = CallSites.begin(), E = CallSites.end(); I != E; ++I, ++idx) {
500 const CallSiteEntry &S = *I;
Bill Wendling0e749fe2009-08-20 22:02:24 +0000501
Renato Golinc8d40652011-08-18 23:43:14 +0000502 // Offset of the landing pad, counted in 16-byte bundles relative to the
503 // @LPStart address.
Bill Wendlingddec6832011-06-21 22:40:24 +0000504 if (VerboseAsm) {
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000505 Asm->OutStreamer.AddComment(">> Call Site " + Twine(idx) + " <<");
506 Asm->OutStreamer.AddComment(" On exception at call site "+Twine(idx));
Bill Wendlingddec6832011-06-21 22:40:24 +0000507 }
Bill Wendlingddec6832011-06-21 22:40:24 +0000508 Asm->EmitULEB128(idx);
Bill Wendling0e749fe2009-08-20 22:02:24 +0000509
510 // Offset of the first associated action record, relative to the start of
511 // the action table. This value is biased by 1 (1 indicates the start of
512 // the action table), and 0 indicates that there are no actions.
Renato Golinc8d40652011-08-18 23:43:14 +0000513 if (VerboseAsm) {
514 if (S.Action == 0)
515 Asm->OutStreamer.AddComment(" Action: cleanup");
516 else
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000517 Asm->OutStreamer.AddComment(" Action: " +
518 Twine((S.Action - 1) / 2 + 1));
Renato Golinc8d40652011-08-18 23:43:14 +0000519 }
Bill Wendlingddec6832011-06-21 22:40:24 +0000520 Asm->EmitULEB128(S.Action);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000521 }
Jim Grosbach693e36a2009-08-11 00:09:57 +0000522 } else {
Reid Kleckner93acac62014-12-19 22:19:48 +0000523 // Itanium LSDA exception handling
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000524
Bill Wendling0e749fe2009-08-20 22:02:24 +0000525 // The call-site table is a list of all call sites that may throw an
526 // exception (including C++ 'throw' statements) in the procedure
527 // fragment. It immediately follows the LSDA header. Each entry indicates,
528 // for a given call, the first corresponding action record and corresponding
529 // landing pad.
530 //
531 // The table begins with the number of bytes, stored as an LEB128
532 // compressed, unsigned integer. The records immediately follow the record
533 // count. They are sorted in increasing call-site address. Each record
534 // indicates:
535 //
536 // * The position of the call-site.
537 // * The position of the landing pad.
538 // * The first action record for that call site.
539 //
540 // A missing entry in the call-site table indicates that a call is not
Bill Wendling023ed642009-09-10 06:50:01 +0000541 // supposed to throw.
Bill Wendling0e749fe2009-08-20 22:02:24 +0000542
543 // Emit the landing pad call site table.
Chris Lattnerb75af3c2010-04-04 20:04:21 +0000544 Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site");
Bill Wendlingc3a93762010-02-26 22:17:52 +0000545
546 // Add extra padding if it wasn't added to the TType base offset.
Chris Lattner9efd1182010-04-04 19:09:29 +0000547 Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000548
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000549 unsigned Entry = 0;
Jim Grosbach693e36a2009-08-11 00:09:57 +0000550 for (SmallVectorImpl<CallSiteEntry>::const_iterator
551 I = CallSites.begin(), E = CallSites.end(); I != E; ++I) {
552 const CallSiteEntry &S = *I;
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000553
Chris Lattnera179b522010-04-04 19:25:43 +0000554 MCSymbol *EHFuncBeginSym =
Chris Lattnerfd795022010-04-05 00:26:50 +0000555 Asm->GetTempSymbol("eh_func_begin", Asm->getFunctionNumber());
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000556
Chris Lattner34adc8d2010-03-14 01:41:15 +0000557 MCSymbol *BeginLabel = S.BeginLabel;
Craig Topper353eda42014-04-24 06:44:33 +0000558 if (!BeginLabel)
Chris Lattner34adc8d2010-03-14 01:41:15 +0000559 BeginLabel = EHFuncBeginSym;
560 MCSymbol *EndLabel = S.EndLabel;
Craig Topper353eda42014-04-24 06:44:33 +0000561 if (!EndLabel)
Chris Lattnerfd795022010-04-05 00:26:50 +0000562 EndLabel = Asm->GetTempSymbol("eh_func_end", Asm->getFunctionNumber());
Anton Korobeynikov61d167e2011-01-14 21:57:45 +0000563
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000564
Bill Wendling0e749fe2009-08-20 22:02:24 +0000565 // Offset of the call site relative to the previous call site, counted in
566 // number of 16-byte bundles. The first call site is counted relative to
567 // the start of the procedure fragment.
Renato Golinc8d40652011-08-18 23:43:14 +0000568 if (VerboseAsm)
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000569 Asm->OutStreamer.AddComment(">> Call Site " + Twine(++Entry) + " <<");
Chris Lattnerc7cc8152010-04-04 21:31:54 +0000570 Asm->EmitLabelDifference(BeginLabel, EHFuncBeginSym, 4);
Renato Golinc8d40652011-08-18 23:43:14 +0000571 if (VerboseAsm)
572 Asm->OutStreamer.AddComment(Twine(" Call between ") +
573 BeginLabel->getName() + " and " +
574 EndLabel->getName());
Chris Lattnerf1429f12010-04-04 19:58:12 +0000575 Asm->EmitLabelDifference(EndLabel, BeginLabel, 4);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000576
Bill Wendling0e749fe2009-08-20 22:02:24 +0000577 // Offset of the landing pad, counted in 16-byte bundles relative to the
578 // @LPStart address.
Renato Golinc8d40652011-08-18 23:43:14 +0000579 if (!S.PadLabel) {
580 if (VerboseAsm)
581 Asm->OutStreamer.AddComment(" has no landing pad");
Eric Christopherce0cfce2013-01-09 01:35:34 +0000582 Asm->OutStreamer.EmitIntValue(0, 4/*size*/);
Renato Golinc8d40652011-08-18 23:43:14 +0000583 } else {
584 if (VerboseAsm)
585 Asm->OutStreamer.AddComment(Twine(" jumps to ") +
586 S.PadLabel->getName());
Chris Lattnerc7cc8152010-04-04 21:31:54 +0000587 Asm->EmitLabelDifference(S.PadLabel, EHFuncBeginSym, 4);
Renato Golinc8d40652011-08-18 23:43:14 +0000588 }
Jim Grosbach693e36a2009-08-11 00:09:57 +0000589
Bill Wendling0e749fe2009-08-20 22:02:24 +0000590 // Offset of the first associated action record, relative to the start of
591 // the action table. This value is biased by 1 (1 indicates the start of
592 // the action table), and 0 indicates that there are no actions.
Renato Golinc8d40652011-08-18 23:43:14 +0000593 if (VerboseAsm) {
594 if (S.Action == 0)
595 Asm->OutStreamer.AddComment(" On action: cleanup");
596 else
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000597 Asm->OutStreamer.AddComment(" On action: " +
598 Twine((S.Action - 1) / 2 + 1));
Renato Golinc8d40652011-08-18 23:43:14 +0000599 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000600 Asm->EmitULEB128(S.Action);
Jim Grosbach693e36a2009-08-11 00:09:57 +0000601 }
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000602 }
603
Bill Wendling0e749fe2009-08-20 22:02:24 +0000604 // Emit the Action Table.
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000605 int Entry = 0;
Bill Wendling23b177e2009-07-28 23:44:43 +0000606 for (SmallVectorImpl<ActionEntry>::const_iterator
607 I = Actions.begin(), E = Actions.end(); I != E; ++I) {
608 const ActionEntry &Action = *I;
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000609
610 if (VerboseAsm) {
611 // Emit comments that decode the action table.
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000612 Asm->OutStreamer.AddComment(">> Action Record " + Twine(++Entry) + " <<");
Renato Golinc8d40652011-08-18 23:43:14 +0000613 }
614
615 // Type Filter
616 //
617 // Used by the runtime to match the type of the thrown exception to the
618 // type of the catch clauses or the types in the exception specification.
619 if (VerboseAsm) {
Duncan Sands2e679372011-09-28 09:13:02 +0000620 if (Action.ValueForTypeID > 0)
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000621 Asm->OutStreamer.AddComment(" Catch TypeInfo " +
622 Twine(Action.ValueForTypeID));
Duncan Sands2e679372011-09-28 09:13:02 +0000623 else if (Action.ValueForTypeID < 0)
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000624 Asm->OutStreamer.AddComment(" Filter TypeInfo " +
625 Twine(Action.ValueForTypeID));
Duncan Sands2e679372011-09-28 09:13:02 +0000626 else
627 Asm->OutStreamer.AddComment(" Cleanup");
Renato Golinc8d40652011-08-18 23:43:14 +0000628 }
629 Asm->EmitSLEB128(Action.ValueForTypeID);
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000630
Renato Golinc8d40652011-08-18 23:43:14 +0000631 // Action Record
632 //
633 // Self-relative signed displacement in bytes of the next action record,
634 // or 0 if there is no next action record.
635 if (VerboseAsm) {
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000636 if (Action.NextAction == 0) {
637 Asm->OutStreamer.AddComment(" No further actions");
638 } else {
639 unsigned NextAction = Entry + (Action.NextAction + 1) / 2;
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000640 Asm->OutStreamer.AddComment(" Continue to action "+Twine(NextAction));
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000641 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000642 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000643 Asm->EmitSLEB128(Action.NextAction);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000644 }
645
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000646 emitTypeInfos(TTypeEncoding);
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000647
648 Asm->EmitAlignment(2);
649}
650
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000651void EHStreamer::emitTypeInfos(unsigned TTypeEncoding) {
Reid Kleckner283bc2e2014-11-14 00:35:50 +0000652 const std::vector<const GlobalValue *> &TypeInfos = MMI->getTypeInfos();
Anton Korobeynikovf65a6382012-11-19 21:06:26 +0000653 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
654
655 bool VerboseAsm = Asm->OutStreamer.isVerboseAsm();
656
657 int Entry = 0;
Bill Wendling4f0b8d72009-10-22 20:48:59 +0000658 // Emit the Catch TypeInfos.
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000659 if (VerboseAsm && !TypeInfos.empty()) {
660 Asm->OutStreamer.AddComment(">> Catch TypeInfos <<");
Chris Lattner566cae92010-03-09 23:52:58 +0000661 Asm->OutStreamer.AddBlankLine();
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000662 Entry = TypeInfos.size();
Chris Lattner566cae92010-03-09 23:52:58 +0000663 }
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000664
Reid Kleckner283bc2e2014-11-14 00:35:50 +0000665 for (std::vector<const GlobalValue *>::const_reverse_iterator
Bill Wendling4b384b02009-11-19 00:09:14 +0000666 I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) {
Reid Kleckner283bc2e2014-11-14 00:35:50 +0000667 const GlobalValue *GV = *I;
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000668 if (VerboseAsm)
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000669 Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--));
Anton Korobeynikov097b0e92012-11-19 21:17:20 +0000670 Asm->EmitTTypeReference(GV, TTypeEncoding);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000671 }
672
Bill Wendling4f0b8d72009-10-22 20:48:59 +0000673 // Emit the Exception Specifications.
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000674 if (VerboseAsm && !FilterIds.empty()) {
675 Asm->OutStreamer.AddComment(">> Filter TypeInfos <<");
Chris Lattner566cae92010-03-09 23:52:58 +0000676 Asm->OutStreamer.AddBlankLine();
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000677 Entry = 0;
Chris Lattner566cae92010-03-09 23:52:58 +0000678 }
Bill Wendling23b177e2009-07-28 23:44:43 +0000679 for (std::vector<unsigned>::const_iterator
680 I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) {
681 unsigned TypeID = *I;
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000682 if (VerboseAsm) {
683 --Entry;
684 if (TypeID != 0)
Benjamin Kramercb6b02a2011-10-16 15:46:29 +0000685 Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry));
Bill Wendlinga8339eb2011-06-21 22:30:20 +0000686 }
687
688 Asm->EmitULEB128(TypeID);
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000689 }
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000690}
691
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000692/// Emit all exception information that should come after the content.
693void EHStreamer::endModule() {
Craig Topperee4dab52012-02-05 08:31:47 +0000694 llvm_unreachable("Should be implemented");
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000695}
696
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000697/// Gather pre-function exception information. Assumes it's being emitted
698/// immediately after the function entry point.
699void EHStreamer::beginFunction(const MachineFunction *MF) {
Craig Topperee4dab52012-02-05 08:31:47 +0000700 llvm_unreachable("Should be implemented");
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000701}
702
Saleem Abdulrasool8076cab2014-06-11 01:19:03 +0000703/// Gather and emit post-function exception information.
704void EHStreamer::endFunction(const MachineFunction *) {
Craig Topperee4dab52012-02-05 08:31:47 +0000705 llvm_unreachable("Should be implemented");
Bill Wendlingd64cd2b2009-05-15 01:12:28 +0000706}