1 //===-- CodeGen/AsmPrinter/DwarfException.cpp - Dwarf Exception Impl ------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains support for writing dwarf exception info into asm files.
12 //===----------------------------------------------------------------------===//
14 #include "DwarfException.h"
15 #include "llvm/Module.h"
16 #include "llvm/CodeGen/MachineModuleInfo.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
18 #include "llvm/CodeGen/MachineLocation.h"
19 #include "llvm/Support/Dwarf.h"
20 #include "llvm/Support/Timer.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/Target/TargetAsmInfo.h"
23 #include "llvm/Target/TargetRegisterInfo.h"
24 #include "llvm/Target/TargetData.h"
25 #include "llvm/Target/TargetFrameInfo.h"
26 #include "llvm/Target/TargetOptions.h"
27 #include "llvm/ADT/StringExtras.h"
30 static TimerGroup &getDwarfTimerGroup() {
31 static TimerGroup DwarfTimerGroup("Dwarf Exception");
32 return DwarfTimerGroup;
35 DwarfException::DwarfException(raw_ostream &OS, AsmPrinter *A,
36 const TargetAsmInfo *T)
37 : Dwarf(OS, A, T, "eh"), shouldEmitTable(false), shouldEmitMoves(false),
38 shouldEmitTableModule(false), shouldEmitMovesModule(false),
40 if (TimePassesIsEnabled)
41 ExceptionTimer = new Timer("Dwarf Exception Writer",
42 getDwarfTimerGroup());
45 DwarfException::~DwarfException() {
46 delete ExceptionTimer;
49 void DwarfException::EmitCommonEHFrame(const Function *Personality,
51 // Size and sign of stack growth.
53 Asm->TM.getFrameInfo()->getStackGrowthDirection() ==
54 TargetFrameInfo::StackGrowsUp ?
55 TD->getPointerSize() : -TD->getPointerSize();
57 // Begin eh frame section.
58 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
60 if (TAI->is_EHSymbolPrivate())
61 O << TAI->getPrivateGlobalPrefix();
63 O << "EH_frame" << Index << ":\n";
64 EmitLabel("section_eh_frame", Index);
66 // Define base labels.
67 EmitLabel("eh_frame_common", Index);
69 // Define the eh frame length.
70 EmitDifference("eh_frame_common_end", Index,
71 "eh_frame_common_begin", Index, true);
72 Asm->EOL("Length of Common Information Entry");
75 EmitLabel("eh_frame_common_begin", Index);
76 Asm->EmitInt32((int)0);
77 Asm->EOL("CIE Identifier Tag");
78 Asm->EmitInt8(dwarf::DW_CIE_VERSION);
79 Asm->EOL("CIE Version");
81 // The personality presence indicates that language specific information will
82 // show up in the eh frame.
83 Asm->EmitString(Personality ? "zPLR" : "zR");
84 Asm->EOL("CIE Augmentation");
87 Asm->EmitULEB128Bytes(1);
88 Asm->EOL("CIE Code Alignment Factor");
89 Asm->EmitSLEB128Bytes(stackGrowth);
90 Asm->EOL("CIE Data Alignment Factor");
91 Asm->EmitInt8(RI->getDwarfRegNum(RI->getRARegister(), true));
92 Asm->EOL("CIE Return Address Column");
94 // If there is a personality, we need to indicate the functions location.
96 Asm->EmitULEB128Bytes(7);
97 Asm->EOL("Augmentation Size");
99 if (TAI->getNeedsIndirectEncoding()) {
100 Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 |
101 dwarf::DW_EH_PE_indirect);
102 Asm->EOL("Personality (pcrel sdata4 indirect)");
104 Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
105 Asm->EOL("Personality (pcrel sdata4)");
108 PrintRelDirective(true);
109 O << TAI->getPersonalityPrefix();
110 Asm->EmitExternalGlobal((const GlobalVariable *)(Personality));
111 O << TAI->getPersonalitySuffix();
112 if (strcmp(TAI->getPersonalitySuffix(), "+4@GOTPCREL"))
113 O << "-" << TAI->getPCSymbol();
114 Asm->EOL("Personality");
116 Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
117 Asm->EOL("LSDA Encoding (pcrel sdata4)");
119 Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
120 Asm->EOL("FDE Encoding (pcrel sdata4)");
122 Asm->EmitULEB128Bytes(1);
123 Asm->EOL("Augmentation Size");
125 Asm->EmitInt8(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4);
126 Asm->EOL("FDE Encoding (pcrel sdata4)");
129 // Indicate locations of general callee saved registers in frame.
130 std::vector<MachineMove> Moves;
131 RI->getInitialFrameState(Moves);
132 EmitFrameMoves(NULL, 0, Moves, true);
134 // On Darwin the linker honors the alignment of eh_frame, which means it must
135 // be 8-byte on 64-bit targets to match what gcc does. Otherwise you get
136 // holes which confuse readers of eh_frame.
137 Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3,
139 EmitLabel("eh_frame_common_end", Index);
144 /// EmitEHFrame - Emit function exception frame information.
146 void DwarfException::EmitEHFrame(const FunctionEHFrameInfo &EHFrameInfo) {
147 assert(!EHFrameInfo.function->hasAvailableExternallyLinkage() &&
148 "Should not emit 'available externally' functions at all");
150 const Function *TheFunc = EHFrameInfo.function;
152 Asm->SwitchToTextSection(TAI->getDwarfEHFrameSection());
154 // Externally visible entry into the functions eh frame info. If the
155 // corresponding function is static, this should not be externally visible.
156 if (!TheFunc->hasLocalLinkage())
157 if (const char *GlobalEHDirective = TAI->getGlobalEHDirective())
158 O << GlobalEHDirective << EHFrameInfo.FnName << "\n";
160 // If corresponding function is weak definition, this should be too.
161 if (TheFunc->isWeakForLinker() && TAI->getWeakDefDirective())
162 O << TAI->getWeakDefDirective() << EHFrameInfo.FnName << "\n";
164 // If there are no calls then you can't unwind. This may mean we can omit the
165 // EH Frame, but some environments do not handle weak absolute symbols. If
166 // UnwindTablesMandatory is set we cannot do this optimization; the unwind
167 // info is to be available for non-EH uses.
168 if (!EHFrameInfo.hasCalls && !UnwindTablesMandatory &&
169 (!TheFunc->isWeakForLinker() ||
170 !TAI->getWeakDefDirective() ||
171 TAI->getSupportsWeakOmittedEHFrame())) {
172 O << EHFrameInfo.FnName << " = 0\n";
173 // This name has no connection to the function, so it might get
174 // dead-stripped when the function is not, erroneously. Prohibit
175 // dead-stripping unconditionally.
176 if (const char *UsedDirective = TAI->getUsedDirective())
177 O << UsedDirective << EHFrameInfo.FnName << "\n\n";
179 O << EHFrameInfo.FnName << ":\n";
182 EmitDifference("eh_frame_end", EHFrameInfo.Number,
183 "eh_frame_begin", EHFrameInfo.Number, true);
184 Asm->EOL("Length of Frame Information Entry");
186 EmitLabel("eh_frame_begin", EHFrameInfo.Number);
188 EmitSectionOffset("eh_frame_begin", "eh_frame_common",
189 EHFrameInfo.Number, EHFrameInfo.PersonalityIndex,
192 Asm->EOL("FDE CIE offset");
194 EmitReference("eh_func_begin", EHFrameInfo.Number, true, true);
195 Asm->EOL("FDE initial location");
196 EmitDifference("eh_func_end", EHFrameInfo.Number,
197 "eh_func_begin", EHFrameInfo.Number, true);
198 Asm->EOL("FDE address range");
200 // If there is a personality and landing pads then point to the language
201 // specific data area in the exception table.
202 if (EHFrameInfo.PersonalityIndex) {
203 Asm->EmitULEB128Bytes(4);
204 Asm->EOL("Augmentation size");
206 if (EHFrameInfo.hasLandingPads)
207 EmitReference("exception", EHFrameInfo.Number, true, true);
209 Asm->EmitInt32((int)0);
210 Asm->EOL("Language Specific Data Area");
212 Asm->EmitULEB128Bytes(0);
213 Asm->EOL("Augmentation size");
216 // Indicate locations of function specific callee saved registers in frame.
217 EmitFrameMoves("eh_func_begin", EHFrameInfo.Number, EHFrameInfo.Moves,
220 // On Darwin the linker honors the alignment of eh_frame, which means it
221 // must be 8-byte on 64-bit targets to match what gcc does. Otherwise you
222 // get holes which confuse readers of eh_frame.
223 Asm->EmitAlignment(TD->getPointerSize() == sizeof(int32_t) ? 2 : 3,
225 EmitLabel("eh_frame_end", EHFrameInfo.Number);
227 // If the function is marked used, this table should be also. We cannot
228 // make the mark unconditional in this case, since retaining the table also
229 // retains the function in this case, and there is code around that depends
230 // on unused functions (calling undefined externals) being dead-stripped to
231 // link correctly. Yes, there really is.
232 if (MMI->isUsedFunction(EHFrameInfo.function))
233 if (const char *UsedDirective = TAI->getUsedDirective())
234 O << UsedDirective << EHFrameInfo.FnName << "\n\n";
238 /// EmitExceptionTable - Emit landing pads and actions.
240 /// The general organization of the table is complex, but the basic concepts are
241 /// easy. First there is a header which describes the location and organization
242 /// of the three components that follow.
244 /// 1. The landing pad site information describes the range of code covered by
245 /// the try. In our case it's an accumulation of the ranges covered by the
246 /// invokes in the try. There is also a reference to the landing pad that
247 /// handles the exception once processed. Finally an index into the actions
249 /// 2. The action table, in our case, is composed of pairs of type ids and next
250 /// action offset. Starting with the action index from the landing pad
251 /// site, each type Id is checked for a match to the current exception. If
252 /// it matches then the exception and type id are passed on to the landing
253 /// pad. Otherwise the next action is looked up. This chain is terminated
254 /// with a next action of zero. If no type id is found the the frame is
255 /// unwound and handling continues.
256 /// 3. Type id table contains references to all the C++ typeinfo for all
257 /// catches in the function. This tables is reversed indexed base 1.
259 /// SharedTypeIds - How many leading type ids two landing pads have in common.
260 unsigned DwarfException::SharedTypeIds(const LandingPadInfo *L,
261 const LandingPadInfo *R) {
262 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
263 unsigned LSize = LIds.size(), RSize = RIds.size();
264 unsigned MinSize = LSize < RSize ? LSize : RSize;
267 for (; Count != MinSize; ++Count)
268 if (LIds[Count] != RIds[Count])
274 /// PadLT - Order landing pads lexicographically by type id.
275 bool DwarfException::PadLT(const LandingPadInfo *L, const LandingPadInfo *R) {
276 const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds;
277 unsigned LSize = LIds.size(), RSize = RIds.size();
278 unsigned MinSize = LSize < RSize ? LSize : RSize;
280 for (unsigned i = 0; i != MinSize; ++i)
281 if (LIds[i] != RIds[i])
282 return LIds[i] < RIds[i];
284 return LSize < RSize;
287 void DwarfException::EmitExceptionTable() {
288 const std::vector<GlobalVariable *> &TypeInfos = MMI->getTypeInfos();
289 const std::vector<unsigned> &FilterIds = MMI->getFilterIds();
290 const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads();
291 if (PadInfos.empty()) return;
293 // Sort the landing pads in order of their type ids. This is used to fold
294 // duplicate actions.
295 SmallVector<const LandingPadInfo *, 64> LandingPads;
296 LandingPads.reserve(PadInfos.size());
297 for (unsigned i = 0, N = PadInfos.size(); i != N; ++i)
298 LandingPads.push_back(&PadInfos[i]);
299 std::sort(LandingPads.begin(), LandingPads.end(), PadLT);
301 // Negative type ids index into FilterIds, positive type ids index into
302 // TypeInfos. The value written for a positive type id is just the type id
303 // itself. For a negative type id, however, the value written is the
304 // (negative) byte offset of the corresponding FilterIds entry. The byte
305 // offset is usually equal to the type id, because the FilterIds entries are
306 // written using a variable width encoding which outputs one byte per entry as
307 // long as the value written is not too large, but can differ. This kind of
308 // complication does not occur for positive type ids because type infos are
309 // output using a fixed width encoding. FilterOffsets[i] holds the byte
310 // offset corresponding to FilterIds[i].
311 SmallVector<int, 16> FilterOffsets;
312 FilterOffsets.reserve(FilterIds.size());
314 for(std::vector<unsigned>::const_iterator I = FilterIds.begin(),
315 E = FilterIds.end(); I != E; ++I) {
316 FilterOffsets.push_back(Offset);
317 Offset -= TargetAsmInfo::getULEB128Size(*I);
320 // Compute the actions table and gather the first action index for each
322 SmallVector<ActionEntry, 32> Actions;
323 SmallVector<unsigned, 64> FirstActions;
324 FirstActions.reserve(LandingPads.size());
327 unsigned SizeActions = 0;
328 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
329 const LandingPadInfo *LP = LandingPads[i];
330 const std::vector<int> &TypeIds = LP->TypeIds;
331 const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0;
332 unsigned SizeSiteActions = 0;
334 if (NumShared < TypeIds.size()) {
335 unsigned SizeAction = 0;
336 ActionEntry *PrevAction = 0;
339 const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size();
340 assert(Actions.size());
341 PrevAction = &Actions.back();
342 SizeAction = TargetAsmInfo::getSLEB128Size(PrevAction->NextAction) +
343 TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
345 for (unsigned j = NumShared; j != SizePrevIds; ++j) {
347 TargetAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID);
348 SizeAction += -PrevAction->NextAction;
349 PrevAction = PrevAction->Previous;
353 // Compute the actions.
354 for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) {
355 int TypeID = TypeIds[I];
356 assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!");
357 int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID;
358 unsigned SizeTypeID = TargetAsmInfo::getSLEB128Size(ValueForTypeID);
360 int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0;
361 SizeAction = SizeTypeID + TargetAsmInfo::getSLEB128Size(NextAction);
362 SizeSiteActions += SizeAction;
364 ActionEntry Action = {ValueForTypeID, NextAction, PrevAction};
365 Actions.push_back(Action);
367 PrevAction = &Actions.back();
370 // Record the first action of the landing pad site.
371 FirstAction = SizeActions + SizeSiteActions - SizeAction + 1;
372 } // else identical - re-use previous FirstAction
374 FirstActions.push_back(FirstAction);
376 // Compute this sites contribution to size.
377 SizeActions += SizeSiteActions;
380 // Compute the call-site table. The entry for an invoke has a try-range
381 // containing the call, a non-zero landing pad and an appropriate action. The
382 // entry for an ordinary call has a try-range containing the call and zero for
383 // the landing pad and the action. Calls marked 'nounwind' have no entry and
384 // must not be contained in the try-range of any entry - they form gaps in the
385 // table. Entries must be ordered by try-range address.
386 SmallVector<CallSiteEntry, 64> CallSites;
390 // Invokes and nounwind calls have entries in PadMap (due to being bracketed
391 // by try-range labels when lowered). Ordinary calls do not, so appropriate
392 // try-ranges for them need be deduced.
393 for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) {
394 const LandingPadInfo *LandingPad = LandingPads[i];
395 for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) {
396 unsigned BeginLabel = LandingPad->BeginLabels[j];
397 assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!");
398 PadRange P = { i, j };
399 PadMap[BeginLabel] = P;
403 // The end label of the previous invoke or nounwind try-range.
404 unsigned LastLabel = 0;
406 // Whether there is a potentially throwing instruction (currently this means
407 // an ordinary call) between the end of the previous try-range and now.
408 bool SawPotentiallyThrowing = false;
410 // Whether the last callsite entry was for an invoke.
411 bool PreviousIsInvoke = false;
413 // Visit all instructions in order of address.
414 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
416 for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end();
418 if (!MI->isLabel()) {
419 SawPotentiallyThrowing |= MI->getDesc().isCall();
423 unsigned BeginLabel = MI->getOperand(0).getImm();
424 assert(BeginLabel && "Invalid label!");
426 // End of the previous try-range?
427 if (BeginLabel == LastLabel)
428 SawPotentiallyThrowing = false;
430 // Beginning of a new try-range?
431 RangeMapType::iterator L = PadMap.find(BeginLabel);
432 if (L == PadMap.end())
433 // Nope, it was just some random label.
436 PadRange P = L->second;
437 const LandingPadInfo *LandingPad = LandingPads[P.PadIndex];
439 assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] &&
440 "Inconsistent landing pad map!");
442 // If some instruction between the previous try-range and this one may
443 // throw, create a call-site entry with no landing pad for the region
444 // between the try-ranges.
445 if (SawPotentiallyThrowing) {
446 CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0};
447 CallSites.push_back(Site);
448 PreviousIsInvoke = false;
451 LastLabel = LandingPad->EndLabels[P.RangeIndex];
452 assert(BeginLabel && LastLabel && "Invalid landing pad!");
454 if (LandingPad->LandingPadLabel) {
455 // This try-range is for an invoke.
456 CallSiteEntry Site = {BeginLabel, LastLabel,
457 LandingPad->LandingPadLabel,
458 FirstActions[P.PadIndex]};
460 // Try to merge with the previous call-site.
461 if (PreviousIsInvoke) {
462 CallSiteEntry &Prev = CallSites.back();
463 if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) {
464 // Extend the range of the previous entry.
465 Prev.EndLabel = Site.EndLabel;
470 // Otherwise, create a new call-site.
471 CallSites.push_back(Site);
472 PreviousIsInvoke = true;
475 PreviousIsInvoke = false;
480 // If some instruction between the previous try-range and the end of the
481 // function may throw, create a call-site entry with no landing pad for the
482 // region following the try-range.
483 if (SawPotentiallyThrowing) {
484 CallSiteEntry Site = {LastLabel, 0, 0, 0};
485 CallSites.push_back(Site);
491 const unsigned SiteStartSize = sizeof(int32_t); // DW_EH_PE_udata4
492 const unsigned SiteLengthSize = sizeof(int32_t); // DW_EH_PE_udata4
493 const unsigned LandingPadSize = sizeof(int32_t); // DW_EH_PE_udata4
494 unsigned SizeSites = CallSites.size() * (SiteStartSize +
497 for (unsigned i = 0, e = CallSites.size(); i < e; ++i)
498 SizeSites += TargetAsmInfo::getULEB128Size(CallSites[i].Action);
501 const unsigned TypeInfoSize = TD->getPointerSize(); // DW_EH_PE_absptr
502 unsigned SizeTypes = TypeInfos.size() * TypeInfoSize;
504 unsigned TypeOffset = sizeof(int8_t) + // Call site format
505 TargetAsmInfo::getULEB128Size(SizeSites) + // Call-site table length
506 SizeSites + SizeActions + SizeTypes;
508 unsigned TotalSize = sizeof(int8_t) + // LPStart format
509 sizeof(int8_t) + // TType format
510 TargetAsmInfo::getULEB128Size(TypeOffset) + // TType base offset
513 unsigned SizeAlign = (4 - TotalSize) & 3;
515 // Begin the exception table.
516 Asm->SwitchToDataSection(TAI->getDwarfExceptionSection());
517 Asm->EmitAlignment(2, 0, 0, false);
518 O << "GCC_except_table" << SubprogramCount << ":\n";
520 for (unsigned i = 0; i != SizeAlign; ++i) {
525 EmitLabel("exception", SubprogramCount);
528 Asm->EmitInt8(dwarf::DW_EH_PE_omit);
529 Asm->EOL("LPStart format (DW_EH_PE_omit)");
530 Asm->EmitInt8(dwarf::DW_EH_PE_absptr);
531 Asm->EOL("TType format (DW_EH_PE_absptr)");
532 Asm->EmitULEB128Bytes(TypeOffset);
533 Asm->EOL("TType base offset");
534 Asm->EmitInt8(dwarf::DW_EH_PE_udata4);
535 Asm->EOL("Call site format (DW_EH_PE_udata4)");
536 Asm->EmitULEB128Bytes(SizeSites);
537 Asm->EOL("Call-site table length");
539 // Emit the landing pad site information.
540 for (unsigned i = 0; i < CallSites.size(); ++i) {
541 CallSiteEntry &S = CallSites[i];
542 const char *BeginTag;
543 unsigned BeginNumber;
546 BeginTag = "eh_func_begin";
547 BeginNumber = SubprogramCount;
550 BeginNumber = S.BeginLabel;
553 EmitSectionOffset(BeginTag, "eh_func_begin", BeginNumber, SubprogramCount,
555 Asm->EOL("Region start");
558 EmitDifference("eh_func_end", SubprogramCount, BeginTag, BeginNumber,
561 EmitDifference("label", S.EndLabel, BeginTag, BeginNumber, true);
563 Asm->EOL("Region length");
568 EmitSectionOffset("label", "eh_func_begin", S.PadLabel, SubprogramCount,
571 Asm->EOL("Landing pad");
573 Asm->EmitULEB128Bytes(S.Action);
578 for (unsigned I = 0, N = Actions.size(); I != N; ++I) {
579 ActionEntry &Action = Actions[I];
581 Asm->EmitSLEB128Bytes(Action.ValueForTypeID);
582 Asm->EOL("TypeInfo index");
583 Asm->EmitSLEB128Bytes(Action.NextAction);
584 Asm->EOL("Next action");
587 // Emit the type ids.
588 for (unsigned M = TypeInfos.size(); M; --M) {
589 GlobalVariable *GV = TypeInfos[M - 1];
594 O << Asm->getGlobalLinkName(GV, GLN);
599 Asm->EOL("TypeInfo");
602 // Emit the filter typeids.
603 for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) {
604 unsigned TypeID = FilterIds[j];
605 Asm->EmitULEB128Bytes(TypeID);
606 Asm->EOL("Filter TypeInfo index");
609 Asm->EmitAlignment(2, 0, 0, false);
612 /// EndModule - Emit all exception information that should come after the
614 void DwarfException::EndModule() {
615 if (TimePassesIsEnabled)
616 ExceptionTimer->startTimer();
618 if (shouldEmitMovesModule || shouldEmitTableModule) {
619 const std::vector<Function *> Personalities = MMI->getPersonalities();
620 for (unsigned i = 0; i < Personalities.size(); ++i)
621 EmitCommonEHFrame(Personalities[i], i);
623 for (std::vector<FunctionEHFrameInfo>::iterator I = EHFrames.begin(),
624 E = EHFrames.end(); I != E; ++I)
628 if (TimePassesIsEnabled)
629 ExceptionTimer->stopTimer();
632 /// BeginFunction - Gather pre-function exception information. Assumes being
633 /// emitted immediately after the function entry point.
634 void DwarfException::BeginFunction(MachineFunction *MF) {
635 if (TimePassesIsEnabled)
636 ExceptionTimer->startTimer();
639 shouldEmitTable = shouldEmitMoves = false;
641 if (MMI && TAI->doesSupportExceptionHandling()) {
642 // Map all labels and get rid of any dead landing pads.
643 MMI->TidyLandingPads();
645 // If any landing pads survive, we need an EH table.
646 if (MMI->getLandingPads().size())
647 shouldEmitTable = true;
649 // See if we need frame move info.
650 if (!MF->getFunction()->doesNotThrow() || UnwindTablesMandatory)
651 shouldEmitMoves = true;
653 if (shouldEmitMoves || shouldEmitTable)
654 // Assumes in correct section after the entry point.
655 EmitLabel("eh_func_begin", ++SubprogramCount);
658 shouldEmitTableModule |= shouldEmitTable;
659 shouldEmitMovesModule |= shouldEmitMoves;
661 if (TimePassesIsEnabled)
662 ExceptionTimer->stopTimer();
665 /// EndFunction - Gather and emit post-function exception information.
667 void DwarfException::EndFunction() {
668 if (TimePassesIsEnabled)
669 ExceptionTimer->startTimer();
671 if (shouldEmitMoves || shouldEmitTable) {
672 EmitLabel("eh_func_end", SubprogramCount);
673 EmitExceptionTable();
675 // Save EH frame information
677 FunctionEHFrameInfo(getAsm()->getCurrentFunctionEHName(MF),
679 MMI->getPersonalityIndex(),
680 MF->getFrameInfo()->hasCalls(),
681 !MMI->getLandingPads().empty(),
682 MMI->getFrameMoves(),
686 if (TimePassesIsEnabled)
687 ExceptionTimer->stopTimer();