| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 1 | //===-- CodeGen/AsmPrinter/EHStreamer.cpp - Exception Directive Streamer --===// | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 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 | // | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 10 | // This file contains support for writing exception info into assembly files. | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 11 | // | 
|  | 12 | //===----------------------------------------------------------------------===// | 
|  | 13 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 14 | #include "EHStreamer.h" | 
| Chris Lattner | da790ea | 2010-04-05 05:28:23 +0000 | [diff] [blame] | 15 | #include "llvm/CodeGen/AsmPrinter.h" | 
| David Greene | a5be1b1 | 2009-08-19 21:55:33 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/MachineFunction.h" | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineInstr.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/MachineModuleInfo.h" | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Function.h" | 
| Chris Lattner | b866602 | 2009-09-16 01:46:41 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCAsmInfo.h" | 
| Chris Lattner | 4b7dadb | 2009-08-19 05:49:37 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCStreamer.h" | 
| Chris Lattner | 555ceabe | 2010-01-16 18:37:32 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbol.h" | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 23 | #include "llvm/Support/LEB128.h" | 
| Chris Lattner | c16c75e | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 24 | #include "llvm/Target/TargetLoweringObjectFile.h" | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 25 |  | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 26 | using namespace llvm; | 
|  | 27 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 28 | EHStreamer::EHStreamer(AsmPrinter *A) : Asm(A), MMI(Asm->MMI) {} | 
| Bill Wendling | dd20b98 | 2009-05-15 01:18:50 +0000 | [diff] [blame] | 29 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 30 | EHStreamer::~EHStreamer() {} | 
| Bill Wendling | dd20b98 | 2009-05-15 01:18:50 +0000 | [diff] [blame] | 31 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 32 | /// How many leading type ids two landing pads have in common. | 
|  | 33 | unsigned EHStreamer::sharedTypeIDs(const LandingPadInfo *L, | 
|  | 34 | const LandingPadInfo *R) { | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 35 | 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 Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 47 | /// Compute the actions table and gather the first action index for each landing | 
|  | 48 | /// pad site. | 
|  | 49 | unsigned EHStreamer:: | 
|  | 50 | computeActionsTable(const SmallVectorImpl<const LandingPadInfo*> &LandingPads, | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 51 | SmallVectorImpl<ActionEntry> &Actions, | 
|  | 52 | SmallVectorImpl<unsigned> &FirstActions) { | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 53 |  | 
|  | 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 Wendling | 1fddd87 | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 66 | // 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 Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 69 | // (negative) byte offset of the corresponding FilterIds entry.  The byte | 
| Bill Wendling | 1fddd87 | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 70 | // 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 Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 74 | // output using a fixed width encoding.  FilterOffsets[i] holds the byte | 
|  | 75 | // offset corresponding to FilterIds[i]. | 
| Bill Wendling | 4505734 | 2009-07-29 21:19:44 +0000 | [diff] [blame] | 76 |  | 
|  | 77 | const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 78 | SmallVector<int, 16> FilterOffsets; | 
|  | 79 | FilterOffsets.reserve(FilterIds.size()); | 
|  | 80 | int Offset = -1; | 
| Bill Wendling | 4505734 | 2009-07-29 21:19:44 +0000 | [diff] [blame] | 81 |  | 
|  | 82 | for (std::vector<unsigned>::const_iterator | 
|  | 83 | I = FilterIds.begin(), E = FilterIds.end(); I != E; ++I) { | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 84 | FilterOffsets.push_back(Offset); | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 85 | Offset -= getULEB128Size(*I); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 86 | } | 
|  | 87 |  | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 88 | FirstActions.reserve(LandingPads.size()); | 
|  | 89 |  | 
|  | 90 | int FirstAction = 0; | 
|  | 91 | unsigned SizeActions = 0; | 
| Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 92 | const LandingPadInfo *PrevLPI = nullptr; | 
| Bill Wendling | 4505734 | 2009-07-29 21:19:44 +0000 | [diff] [blame] | 93 |  | 
| Bill Wendling | 23b177e | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 94 | for (SmallVectorImpl<const LandingPadInfo *>::const_iterator | 
| Bill Wendling | 1fddd87 | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 95 | I = LandingPads.begin(), E = LandingPads.end(); I != E; ++I) { | 
|  | 96 | const LandingPadInfo *LPI = *I; | 
|  | 97 | const std::vector<int> &TypeIds = LPI->TypeIds; | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 98 | unsigned NumShared = PrevLPI ? sharedTypeIDs(LPI, PrevLPI) : 0; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 99 | unsigned SizeSiteActions = 0; | 
|  | 100 |  | 
|  | 101 | if (NumShared < TypeIds.size()) { | 
|  | 102 | unsigned SizeAction = 0; | 
| Bill Wendling | 7742b64 | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 103 | unsigned PrevAction = (unsigned)-1; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 104 |  | 
|  | 105 | if (NumShared) { | 
| Chris Lattner | 07c1b94 | 2010-04-04 20:10:41 +0000 | [diff] [blame] | 106 | unsigned SizePrevIds = PrevLPI->TypeIds.size(); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 107 | assert(Actions.size()); | 
| Bill Wendling | 7742b64 | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 108 | PrevAction = Actions.size() - 1; | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 109 | SizeAction = getSLEB128Size(Actions[PrevAction].NextAction) + | 
|  | 110 | getSLEB128Size(Actions[PrevAction].ValueForTypeID); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 111 |  | 
|  | 112 | for (unsigned j = NumShared; j != SizePrevIds; ++j) { | 
| Bill Wendling | 7742b64 | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 113 | assert(PrevAction != (unsigned)-1 && "PrevAction is invalid!"); | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 114 | SizeAction -= getSLEB128Size(Actions[PrevAction].ValueForTypeID); | 
| Bill Wendling | 7742b64 | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 115 | SizeAction += -Actions[PrevAction].NextAction; | 
|  | 116 | PrevAction = Actions[PrevAction].Previous; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 117 | } | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | // Compute the actions. | 
| Bill Wendling | 1fddd87 | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 121 | 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 Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 124 | int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID; | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 125 | unsigned SizeTypeID = getSLEB128Size(ValueForTypeID); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 126 |  | 
|  | 127 | int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0; | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 128 | SizeAction = SizeTypeID + getSLEB128Size(NextAction); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 129 | SizeSiteActions += SizeAction; | 
|  | 130 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 131 | ActionEntry Action = { ValueForTypeID, NextAction, PrevAction }; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 132 | Actions.push_back(Action); | 
| Bill Wendling | 7742b64 | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 133 | PrevAction = Actions.size() - 1; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 134 | } | 
|  | 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 Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 140 | // 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 Wendling | 7742b64 | 2010-02-10 21:41:57 +0000 | [diff] [blame] | 143 | // biased by 1 (1 indicating the start of the actions table), and 0 | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 144 | // indicates that there are no actions. | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 145 | FirstActions.push_back(FirstAction); | 
|  | 146 |  | 
|  | 147 | // Compute this sites contribution to size. | 
|  | 148 | SizeActions += SizeSiteActions; | 
| Bill Wendling | 1fddd87 | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 149 |  | 
|  | 150 | PrevLPI = LPI; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 151 | } | 
|  | 152 |  | 
| Bill Wendling | 1fddd87 | 2009-07-28 23:22:13 +0000 | [diff] [blame] | 153 | return SizeActions; | 
|  | 154 | } | 
|  | 155 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 156 | /// Return `true' if this is a call to a function marked `nounwind'. Return | 
|  | 157 | /// `false' otherwise. | 
|  | 158 | bool EHStreamer::callToNoUnwindFunction(const MachineInstr *MI) { | 
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 159 | assert(MI->isCall() && "This should be a call instruction!"); | 
| Bill Wendling | e412064 | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 160 |  | 
|  | 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 Lattner | 17d3859 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 167 | if (!MO.isGlobal()) continue; | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 168 |  | 
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 169 | const Function *F = dyn_cast<Function>(MO.getGlobal()); | 
| Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 170 | if (!F) continue; | 
| Bill Wendling | c781d7a | 2009-11-12 23:13:08 +0000 | [diff] [blame] | 171 |  | 
| Chris Lattner | 17d3859 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 172 | 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 Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 176 | // | 
| Chris Lattner | 17d3859 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 177 | // FIXME: Determine if there's a way to say that `F' is the callee or | 
|  | 178 | // parameter. | 
|  | 179 | MarkedNoUnwind = false; | 
|  | 180 | break; | 
| Bill Wendling | e412064 | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 181 | } | 
| Chris Lattner | 17d3859 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 182 |  | 
|  | 183 | MarkedNoUnwind = F->doesNotThrow(); | 
|  | 184 | SawFunc = true; | 
| Bill Wendling | e412064 | 2009-11-12 21:59:20 +0000 | [diff] [blame] | 185 | } | 
|  | 186 |  | 
|  | 187 | return MarkedNoUnwind; | 
|  | 188 | } | 
|  | 189 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 190 | /// 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. | 
|  | 196 | void EHStreamer:: | 
|  | 197 | computeCallSiteTable(SmallVectorImpl<CallSiteEntry> &CallSites, | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 198 | const RangeMapType &PadMap, | 
|  | 199 | const SmallVectorImpl<const LandingPadInfo *> &LandingPads, | 
|  | 200 | const SmallVectorImpl<unsigned> &FirstActions) { | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 201 | // The end label of the previous invoke or nounwind try-range. | 
| Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 202 | MCSymbol *LastLabel = nullptr; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 203 |  | 
|  | 204 | // Whether there is a potentially throwing instruction (currently this means | 
|  | 205 | // an ordinary call) between the end of the previous try-range and now. | 
|  | 206 | bool SawPotentiallyThrowing = false; | 
|  | 207 |  | 
| Bill Wendling | 23b177e | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 208 | // Whether the last CallSite entry was for an invoke. | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 209 | bool PreviousIsInvoke = false; | 
|  | 210 |  | 
|  | 211 | // Visit all instructions in order of address. | 
| Alexey Samsonov | 41b977d | 2014-04-30 18:29:51 +0000 | [diff] [blame] | 212 | for (const auto &MBB : *Asm->MF) { | 
| Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 213 | for (const auto &MI : MBB) { | 
|  | 214 | if (!MI.isEHLabel()) { | 
|  | 215 | if (MI.isCall()) | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 216 | SawPotentiallyThrowing |= !callToNoUnwindFunction(&MI); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 217 | continue; | 
|  | 218 | } | 
|  | 219 |  | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 220 | // End of the previous try-range? | 
| Alexey Samsonov | f74bde6 | 2014-04-30 22:17:38 +0000 | [diff] [blame] | 221 | MCSymbol *BeginLabel = MI.getOperand(0).getMCSymbol(); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 222 | if (BeginLabel == LastLabel) | 
|  | 223 | SawPotentiallyThrowing = false; | 
|  | 224 |  | 
|  | 225 | // Beginning of a new try-range? | 
| Jeffrey Yasskin | b40d3f7 | 2009-11-10 01:02:17 +0000 | [diff] [blame] | 226 | RangeMapType::const_iterator L = PadMap.find(BeginLabel); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 227 | if (L == PadMap.end()) | 
|  | 228 | // Nope, it was just some random label. | 
|  | 229 | continue; | 
|  | 230 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 231 | const PadRange &P = L->second; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 232 | const LandingPadInfo *LandingPad = LandingPads[P.PadIndex]; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 233 | assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] && | 
|  | 234 | "Inconsistent landing pad map!"); | 
|  | 235 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 236 | // For Dwarf exception handling (SjLj handling doesn't use this). If some | 
|  | 237 | // instruction between the previous try-range and this one may throw, | 
|  | 238 | // create a call-site entry with no landing pad for the region between the | 
|  | 239 | // try-ranges. | 
| Anton Korobeynikov | 9be547c | 2011-01-14 21:58:08 +0000 | [diff] [blame] | 240 | if (SawPotentiallyThrowing && Asm->MAI->isExceptionHandlingDwarf()) { | 
| Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 241 | CallSiteEntry Site = { LastLabel, BeginLabel, nullptr, 0 }; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 242 | CallSites.push_back(Site); | 
|  | 243 | PreviousIsInvoke = false; | 
|  | 244 | } | 
|  | 245 |  | 
|  | 246 | LastLabel = LandingPad->EndLabels[P.RangeIndex]; | 
|  | 247 | assert(BeginLabel && LastLabel && "Invalid landing pad!"); | 
|  | 248 |  | 
| Chris Lattner | 17d3859 | 2010-03-31 06:09:04 +0000 | [diff] [blame] | 249 | if (!LandingPad->LandingPadLabel) { | 
|  | 250 | // Create a gap. | 
|  | 251 | PreviousIsInvoke = false; | 
|  | 252 | } else { | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 253 | // This try-range is for an invoke. | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 254 | CallSiteEntry Site = { | 
|  | 255 | BeginLabel, | 
|  | 256 | LastLabel, | 
|  | 257 | LandingPad->LandingPadLabel, | 
|  | 258 | FirstActions[P.PadIndex] | 
|  | 259 | }; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 260 |  | 
| Jim Grosbach | 5afbf2b | 2009-09-01 17:19:13 +0000 | [diff] [blame] | 261 | // Try to merge with the previous call-site. SJLJ doesn't do this | 
| Anton Korobeynikov | 9be547c | 2011-01-14 21:58:08 +0000 | [diff] [blame] | 262 | if (PreviousIsInvoke && Asm->MAI->isExceptionHandlingDwarf()) { | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 263 | CallSiteEntry &Prev = CallSites.back(); | 
|  | 264 | if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) { | 
|  | 265 | // Extend the range of the previous entry. | 
|  | 266 | Prev.EndLabel = Site.EndLabel; | 
|  | 267 | continue; | 
|  | 268 | } | 
|  | 269 | } | 
|  | 270 |  | 
|  | 271 | // Otherwise, create a new call-site. | 
| Anton Korobeynikov | 9be547c | 2011-01-14 21:58:08 +0000 | [diff] [blame] | 272 | if (Asm->MAI->isExceptionHandlingDwarf()) | 
| Jim Grosbach | 54c0530 | 2010-01-28 01:45:32 +0000 | [diff] [blame] | 273 | CallSites.push_back(Site); | 
|  | 274 | else { | 
|  | 275 | // SjLj EH must maintain the call sites in the order assigned | 
|  | 276 | // to them by the SjLjPrepare pass. | 
|  | 277 | unsigned SiteNo = MMI->getCallSiteBeginLabel(BeginLabel); | 
|  | 278 | if (CallSites.size() < SiteNo) | 
|  | 279 | CallSites.resize(SiteNo); | 
|  | 280 | CallSites[SiteNo - 1] = Site; | 
|  | 281 | } | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 282 | PreviousIsInvoke = true; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 283 | } | 
|  | 284 | } | 
|  | 285 | } | 
|  | 286 |  | 
|  | 287 | // If some instruction between the previous try-range and the end of the | 
|  | 288 | // function may throw, create a call-site entry with no landing pad for the | 
|  | 289 | // region following the try-range. | 
| Anton Korobeynikov | 9be547c | 2011-01-14 21:58:08 +0000 | [diff] [blame] | 290 | if (SawPotentiallyThrowing && Asm->MAI->isExceptionHandlingDwarf()) { | 
| Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 291 | CallSiteEntry Site = { LastLabel, nullptr, nullptr, 0 }; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 292 | CallSites.push_back(Site); | 
|  | 293 | } | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 294 | } | 
|  | 295 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 296 | /// Emit landing pads and actions. | 
| Bill Wendling | 2cf0014 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 297 | /// | 
|  | 298 | /// The general organization of the table is complex, but the basic concepts are | 
|  | 299 | /// easy.  First there is a header which describes the location and organization | 
|  | 300 | /// of the three components that follow. | 
| Eric Christopher | d517ac0 | 2009-08-28 22:33:43 +0000 | [diff] [blame] | 301 | /// | 
| Bill Wendling | 2cf0014 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 302 | ///  1. The landing pad site information describes the range of code covered by | 
|  | 303 | ///     the try.  In our case it's an accumulation of the ranges covered by the | 
|  | 304 | ///     invokes in the try.  There is also a reference to the landing pad that | 
|  | 305 | ///     handles the exception once processed.  Finally an index into the actions | 
|  | 306 | ///     table. | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 307 | ///  2. The action table, in our case, is composed of pairs of type IDs and next | 
| Bill Wendling | 2cf0014 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 308 | ///     action offset.  Starting with the action index from the landing pad | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 309 | ///     site, each type ID is checked for a match to the current exception.  If | 
| Bill Wendling | 2cf0014 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 310 | ///     it matches then the exception and type id are passed on to the landing | 
|  | 311 | ///     pad.  Otherwise the next action is looked up.  This chain is terminated | 
| Bill Wendling | 023ed64 | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 312 | ///     with a next action of zero.  If no type id is found then the frame is | 
| Bill Wendling | 2cf0014 | 2009-07-29 00:50:05 +0000 | [diff] [blame] | 313 | ///     unwound and handling continues. | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 314 | ///  3. Type ID table contains references to all the C++ typeinfo for all | 
| Bill Wendling | 023ed64 | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 315 | ///     catches in the function.  This tables is reverse indexed base 1. | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 316 | void EHStreamer::emitExceptionTable() { | 
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 317 | const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 318 | const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); | 
|  | 319 | const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 320 |  | 
|  | 321 | // Sort the landing pads in order of their type ids.  This is used to fold | 
|  | 322 | // duplicate actions. | 
|  | 323 | SmallVector<const LandingPadInfo *, 64> LandingPads; | 
|  | 324 | LandingPads.reserve(PadInfos.size()); | 
|  | 325 |  | 
|  | 326 | for (unsigned i = 0, N = PadInfos.size(); i != N; ++i) | 
|  | 327 | LandingPads.push_back(&PadInfos[i]); | 
|  | 328 |  | 
| Benjamin Kramer | b0f74b2 | 2014-03-07 21:35:39 +0000 | [diff] [blame] | 329 | // Order landing pads lexicographically by type id. | 
|  | 330 | std::sort(LandingPads.begin(), LandingPads.end(), | 
|  | 331 | [](const LandingPadInfo *L, | 
|  | 332 | const LandingPadInfo *R) { return L->TypeIds < R->TypeIds; }); | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 333 |  | 
|  | 334 | // Compute the actions table and gather the first action index for each | 
|  | 335 | // landing pad site. | 
|  | 336 | SmallVector<ActionEntry, 32> Actions; | 
|  | 337 | SmallVector<unsigned, 64> FirstActions; | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 338 | unsigned SizeActions = | 
|  | 339 | computeActionsTable(LandingPads, Actions, FirstActions); | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 340 |  | 
|  | 341 | // Invokes and nounwind calls have entries in PadMap (due to being bracketed | 
|  | 342 | // by try-range labels when lowered).  Ordinary calls do not, so appropriate | 
| Bill Wendling | 023ed64 | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 343 | // try-ranges for them need be deduced when using DWARF exception handling. | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 344 | RangeMapType PadMap; | 
|  | 345 | for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { | 
|  | 346 | const LandingPadInfo *LandingPad = LandingPads[i]; | 
|  | 347 | for (unsigned j = 0, E = LandingPad->BeginLabels.size(); j != E; ++j) { | 
| Chris Lattner | 34adc8d | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 348 | MCSymbol *BeginLabel = LandingPad->BeginLabels[j]; | 
| Bill Wendling | b67440e | 2009-07-29 00:31:35 +0000 | [diff] [blame] | 349 | assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!"); | 
|  | 350 | PadRange P = { i, j }; | 
|  | 351 | PadMap[BeginLabel] = P; | 
|  | 352 | } | 
|  | 353 | } | 
|  | 354 |  | 
|  | 355 | // Compute the call-site table. | 
|  | 356 | SmallVector<CallSiteEntry, 64> CallSites; | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 357 | computeCallSiteTable(CallSites, PadMap, LandingPads, FirstActions); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 358 |  | 
|  | 359 | // Final tallies. | 
|  | 360 |  | 
|  | 361 | // Call sites. | 
| Chris Lattner | fd79502 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 362 | bool IsSJLJ = Asm->MAI->getExceptionHandlingType() == ExceptionHandling::SjLj; | 
| Bill Wendling | a482ec8 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 363 | bool HaveTTData = IsSJLJ ? (!TypeInfos.empty() || !FilterIds.empty()) : true; | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 364 |  | 
| Bill Wendling | 88fdcd3 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 365 | unsigned CallSiteTableLength; | 
| Bill Wendling | a482ec8 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 366 | if (IsSJLJ) | 
| Bill Wendling | 88fdcd3 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 367 | CallSiteTableLength = 0; | 
| Chris Lattner | 07c1b94 | 2010-04-04 20:10:41 +0000 | [diff] [blame] | 368 | else { | 
|  | 369 | unsigned SiteStartSize  = 4; // dwarf::DW_EH_PE_udata4 | 
|  | 370 | unsigned SiteLengthSize = 4; // dwarf::DW_EH_PE_udata4 | 
|  | 371 | unsigned LandingPadSize = 4; // dwarf::DW_EH_PE_udata4 | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 372 | CallSiteTableLength = | 
| Chris Lattner | 07c1b94 | 2010-04-04 20:10:41 +0000 | [diff] [blame] | 373 | CallSites.size() * (SiteStartSize + SiteLengthSize + LandingPadSize); | 
|  | 374 | } | 
| Bill Wendling | a482ec8 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 375 |  | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 376 | for (unsigned i = 0, e = CallSites.size(); i < e; ++i) { | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 377 | CallSiteTableLength += getULEB128Size(CallSites[i].Action); | 
| Bill Wendling | a482ec8 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 378 | if (IsSJLJ) | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 379 | CallSiteTableLength += getULEB128Size(i); | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 380 | } | 
| Bill Wendling | a482ec8 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 381 |  | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 382 | // Type infos. | 
| Chris Lattner | c16c75e | 2009-08-02 01:34:32 +0000 | [diff] [blame] | 383 | const MCSection *LSDASection = Asm->getObjFileLowering().getLSDASection(); | 
| Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 384 | unsigned TTypeEncoding; | 
| Bill Wendling | 9e5c206 | 2009-09-10 06:27:16 +0000 | [diff] [blame] | 385 | unsigned TypeFormatSize; | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 386 |  | 
| Bill Wendling | bf56268 | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 387 | if (!HaveTTData) { | 
| Bill Wendling | 023ed64 | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 388 | // For SjLj exceptions, if there is no TypeInfo, then we just explicitly say | 
|  | 389 | // that we're omitting that bit. | 
| Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 390 | TTypeEncoding = dwarf::DW_EH_PE_omit; | 
| Chris Lattner | fd79502 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 391 | // dwarf::DW_EH_PE_absptr | 
| Chandler Carruth | 5da3f05 | 2012-11-01 09:14:31 +0000 | [diff] [blame] | 392 | TypeFormatSize = Asm->getDataLayout().getPointerSize(); | 
| Chris Lattner | 47fc235 | 2009-07-31 22:03:47 +0000 | [diff] [blame] | 393 | } else { | 
| Chris Lattner | 7005cd3 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 394 | // Okay, we have actual filters or typeinfos to emit.  As such, we need to | 
|  | 395 | // pick a type encoding for them.  We're about to emit a list of pointers to | 
|  | 396 | // typeinfo objects at the end of the LSDA.  However, unless we're in static | 
|  | 397 | // mode, this reference will require a relocation by the dynamic linker. | 
| Chris Lattner | f4b92a8 | 2009-07-31 22:18:14 +0000 | [diff] [blame] | 398 | // | 
| Chris Lattner | 7005cd3 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 399 | // Because of this, we have a couple of options: | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 400 | // | 
| Chris Lattner | 7005cd3 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 401 | //   1) If we are in -static mode, we can always use an absolute reference | 
|  | 402 | //      from the LSDA, because the static linker will resolve it. | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 403 | // | 
| Chris Lattner | 7005cd3 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 404 | //   2) Otherwise, if the LSDA section is writable, we can output the direct | 
|  | 405 | //      reference to the typeinfo and allow the dynamic linker to relocate | 
|  | 406 | //      it.  Since it is in a writable section, the dynamic linker won't | 
|  | 407 | //      have a problem. | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 408 | // | 
| Chris Lattner | 7005cd3 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 409 | //   3) Finally, if we're in PIC mode and the LDSA section isn't writable, | 
|  | 410 | //      we need to use some form of indirection.  For example, on Darwin, | 
|  | 411 | //      we can output a statically-relocatable reference to a dyld stub. The | 
|  | 412 | //      offset to the stub is constant, but the contents are in a section | 
|  | 413 | //      that is updated by the dynamic linker.  This is easy enough, but we | 
|  | 414 | //      need to tell the personality function of the unwinder to indirect | 
|  | 415 | //      through the dyld stub. | 
|  | 416 | // | 
| Bill Wendling | bf56268 | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 417 | // FIXME: When (3) is actually implemented, we'll have to emit the stubs | 
| Chris Lattner | 7005cd3 | 2009-08-02 03:59:56 +0000 | [diff] [blame] | 418 | // somewhere.  This predicate should be moved to a shared location that is | 
|  | 419 | // in target-independent code. | 
|  | 420 | // | 
| Anton Korobeynikov | ae4ccc1 | 2010-02-15 22:35:59 +0000 | [diff] [blame] | 421 | TTypeEncoding = Asm->getObjFileLowering().getTTypeEncoding(); | 
| Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 422 | TypeFormatSize = Asm->GetSizeOfEncodedValue(TTypeEncoding); | 
| Bill Wendling | 243ac56 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 423 | } | 
| Bill Wendling | bf56268 | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 424 |  | 
| Bill Wendling | 243ac56 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 425 | // Begin the exception table. | 
| Anton Korobeynikov | fe3a6e0 | 2011-01-30 22:07:31 +0000 | [diff] [blame] | 426 | // Sometimes we want not to emit the data into separate section (e.g. ARM | 
|  | 427 | // EHABI). In this case LSDASection will be NULL. | 
| Anton Korobeynikov | b15beb2 | 2011-01-24 22:38:40 +0000 | [diff] [blame] | 428 | if (LSDASection) | 
|  | 429 | Asm->OutStreamer.SwitchSection(LSDASection); | 
| Chris Lattner | 9e06e53 | 2010-04-28 01:05:45 +0000 | [diff] [blame] | 430 | Asm->EmitAlignment(2); | 
| Bill Wendling | bf56268 | 2009-09-10 01:12:47 +0000 | [diff] [blame] | 431 |  | 
| Bill Wendling | 88fdcd3 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 432 | // Emit the LSDA. | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 433 | MCSymbol *GCCETSym = | 
| Chris Lattner | eec9bf1 | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 434 | Asm->OutContext.GetOrCreateSymbol(Twine("GCC_except_table")+ | 
| Chris Lattner | fd79502 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 435 | Twine(Asm->getFunctionNumber())); | 
| Chris Lattner | eec9bf1 | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 436 | Asm->OutStreamer.EmitLabel(GCCETSym); | 
| Chris Lattner | fd79502 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 437 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("exception", | 
|  | 438 | Asm->getFunctionNumber())); | 
| Bill Wendling | 243ac56 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 439 |  | 
| Chris Lattner | eec9bf1 | 2010-03-10 02:48:06 +0000 | [diff] [blame] | 440 | if (IsSJLJ) | 
| Chris Lattner | a179b52 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 441 | Asm->OutStreamer.EmitLabel(Asm->GetTempSymbol("_LSDA_", | 
|  | 442 | Asm->getFunctionNumber())); | 
| Bill Wendling | 243ac56 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 443 |  | 
| Bill Wendling | 88fdcd3 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 444 | // Emit the LSDA header. | 
| Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 445 | Asm->EmitEncodingByte(dwarf::DW_EH_PE_omit, "@LPStart"); | 
|  | 446 | Asm->EmitEncodingByte(TTypeEncoding, "@TType"); | 
| Bill Wendling | 243ac56 | 2009-09-10 02:07:37 +0000 | [diff] [blame] | 447 |  | 
| Bill Wendling | 88fdcd3 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 448 | // The type infos need to be aligned. GCC does this by inserting padding just | 
|  | 449 | // before the type infos. However, this changes the size of the exception | 
|  | 450 | // table, so you need to take this into account when you output the exception | 
|  | 451 | // table size. However, the size is output using a variable length encoding. | 
|  | 452 | // So by increasing the size by inserting padding, you may increase the number | 
|  | 453 | // of bytes used for writing the size. If it increases, say by one byte, then | 
|  | 454 | // you now need to output one less byte of padding to get the type infos | 
|  | 455 | // aligned. However this decreases the size of the exception table. This | 
|  | 456 | // changes the value you have to output for the exception table size. Due to | 
|  | 457 | // the variable length encoding, the number of bytes used for writing the | 
|  | 458 | // length may decrease. If so, you then have to increase the amount of | 
|  | 459 | // padding. And so on. If you look carefully at the GCC code you will see that | 
|  | 460 | // it indeed does this in a loop, going on and on until the values stabilize. | 
|  | 461 | // We chose another solution: don't output padding inside the table like GCC | 
|  | 462 | // does, instead output it before the table. | 
|  | 463 | unsigned SizeTypes = TypeInfos.size() * TypeFormatSize; | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 464 | unsigned CallSiteTableLengthSize = getULEB128Size(CallSiteTableLength); | 
| Bill Wendling | 88fdcd3 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 465 | unsigned TTypeBaseOffset = | 
|  | 466 | sizeof(int8_t) +                            // Call site format | 
|  | 467 | CallSiteTableLengthSize +                   // Call site table length size | 
|  | 468 | CallSiteTableLength +                       // Call site table length | 
|  | 469 | SizeActions +                               // Actions size | 
|  | 470 | SizeTypes; | 
| Logan Chien | 5b776b7 | 2014-02-22 14:00:39 +0000 | [diff] [blame] | 471 | unsigned TTypeBaseOffsetSize = getULEB128Size(TTypeBaseOffset); | 
| Bill Wendling | 88fdcd3 | 2010-02-24 23:34:35 +0000 | [diff] [blame] | 472 | unsigned TotalSize = | 
|  | 473 | sizeof(int8_t) +                            // LPStart format | 
|  | 474 | sizeof(int8_t) +                            // TType format | 
|  | 475 | (HaveTTData ? TTypeBaseOffsetSize : 0) +    // TType base offset size | 
|  | 476 | TTypeBaseOffset;                            // TType base offset | 
|  | 477 | unsigned SizeAlign = (4 - TotalSize) & 3; | 
|  | 478 |  | 
| Bill Wendling | 24c74f1 | 2010-02-25 23:52:44 +0000 | [diff] [blame] | 479 | if (HaveTTData) { | 
| Bill Wendling | fea6c4e | 2010-02-26 21:31:01 +0000 | [diff] [blame] | 480 | // Account for any extra padding that will be added to the call site table | 
| Bill Wendling | 60aa4df | 2010-02-25 21:19:47 +0000 | [diff] [blame] | 481 | // length. | 
| Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 482 | Asm->EmitULEB128(TTypeBaseOffset, "@TType base offset", SizeAlign); | 
| Bill Wendling | c3a9376 | 2010-02-26 22:17:52 +0000 | [diff] [blame] | 483 | SizeAlign = 0; | 
| Bill Wendling | 24c74f1 | 2010-02-25 23:52:44 +0000 | [diff] [blame] | 484 | } | 
| Bill Wendling | 15349f8 | 2009-07-28 22:23:45 +0000 | [diff] [blame] | 485 |  | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 486 | bool VerboseAsm = Asm->OutStreamer.isVerboseAsm(); | 
|  | 487 |  | 
| Bill Wendling | 023ed64 | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 488 | // SjLj Exception handling | 
| Bill Wendling | a482ec8 | 2009-09-10 00:17:04 +0000 | [diff] [blame] | 489 | if (IsSJLJ) { | 
| Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 490 | Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); | 
| Bill Wendling | c3a9376 | 2010-02-26 22:17:52 +0000 | [diff] [blame] | 491 |  | 
|  | 492 | // Add extra padding if it wasn't added to the TType base offset. | 
| Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 493 | Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 494 |  | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 495 | // Emit the landing pad site information. | 
| Jim Grosbach | 486be66 | 2009-08-17 16:41:22 +0000 | [diff] [blame] | 496 | unsigned idx = 0; | 
|  | 497 | for (SmallVectorImpl<CallSiteEntry>::const_iterator | 
|  | 498 | I = CallSites.begin(), E = CallSites.end(); I != E; ++I, ++idx) { | 
|  | 499 | const CallSiteEntry &S = *I; | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 500 |  | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 501 | // Offset of the landing pad, counted in 16-byte bundles relative to the | 
|  | 502 | // @LPStart address. | 
| Bill Wendling | ddec683 | 2011-06-21 22:40:24 +0000 | [diff] [blame] | 503 | if (VerboseAsm) { | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 504 | Asm->OutStreamer.AddComment(">> Call Site " + Twine(idx) + " <<"); | 
|  | 505 | Asm->OutStreamer.AddComment("  On exception at call site "+Twine(idx)); | 
| Bill Wendling | ddec683 | 2011-06-21 22:40:24 +0000 | [diff] [blame] | 506 | } | 
| Bill Wendling | ddec683 | 2011-06-21 22:40:24 +0000 | [diff] [blame] | 507 | Asm->EmitULEB128(idx); | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 508 |  | 
|  | 509 | // Offset of the first associated action record, relative to the start of | 
|  | 510 | // the action table. This value is biased by 1 (1 indicates the start of | 
|  | 511 | // the action table), and 0 indicates that there are no actions. | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 512 | if (VerboseAsm) { | 
|  | 513 | if (S.Action == 0) | 
|  | 514 | Asm->OutStreamer.AddComment("  Action: cleanup"); | 
|  | 515 | else | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 516 | Asm->OutStreamer.AddComment("  Action: " + | 
|  | 517 | Twine((S.Action - 1) / 2 + 1)); | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 518 | } | 
| Bill Wendling | ddec683 | 2011-06-21 22:40:24 +0000 | [diff] [blame] | 519 | Asm->EmitULEB128(S.Action); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 520 | } | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 521 | } else { | 
|  | 522 | // DWARF Exception handling | 
| Anton Korobeynikov | 9be547c | 2011-01-14 21:58:08 +0000 | [diff] [blame] | 523 | assert(Asm->MAI->isExceptionHandlingDwarf()); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 524 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 525 | // 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 Wendling | 023ed64 | 2009-09-10 06:50:01 +0000 | [diff] [blame] | 541 | // supposed to throw. | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 542 |  | 
|  | 543 | // Emit the landing pad call site table. | 
| Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 544 | Asm->EmitEncodingByte(dwarf::DW_EH_PE_udata4, "Call site"); | 
| Bill Wendling | c3a9376 | 2010-02-26 22:17:52 +0000 | [diff] [blame] | 545 |  | 
|  | 546 | // Add extra padding if it wasn't added to the TType base offset. | 
| Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 547 | Asm->EmitULEB128(CallSiteTableLength, "Call site table length", SizeAlign); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 548 |  | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 549 | unsigned Entry = 0; | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 550 | for (SmallVectorImpl<CallSiteEntry>::const_iterator | 
|  | 551 | I = CallSites.begin(), E = CallSites.end(); I != E; ++I) { | 
|  | 552 | const CallSiteEntry &S = *I; | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 553 |  | 
| Chris Lattner | a179b52 | 2010-04-04 19:25:43 +0000 | [diff] [blame] | 554 | MCSymbol *EHFuncBeginSym = | 
| Chris Lattner | fd79502 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 555 | Asm->GetTempSymbol("eh_func_begin", Asm->getFunctionNumber()); | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 556 |  | 
| Chris Lattner | 34adc8d | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 557 | MCSymbol *BeginLabel = S.BeginLabel; | 
| Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 558 | if (!BeginLabel) | 
| Chris Lattner | 34adc8d | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 559 | BeginLabel = EHFuncBeginSym; | 
|  | 560 | MCSymbol *EndLabel = S.EndLabel; | 
| Craig Topper | 353eda4 | 2014-04-24 06:44:33 +0000 | [diff] [blame] | 561 | if (!EndLabel) | 
| Chris Lattner | fd79502 | 2010-04-05 00:26:50 +0000 | [diff] [blame] | 562 | EndLabel = Asm->GetTempSymbol("eh_func_end", Asm->getFunctionNumber()); | 
| Anton Korobeynikov | 61d167e | 2011-01-14 21:57:45 +0000 | [diff] [blame] | 563 |  | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 564 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 565 | // 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 Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 568 | if (VerboseAsm) | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 569 | Asm->OutStreamer.AddComment(">> Call Site " + Twine(++Entry) + " <<"); | 
| Chris Lattner | c7cc815 | 2010-04-04 21:31:54 +0000 | [diff] [blame] | 570 | Asm->EmitLabelDifference(BeginLabel, EHFuncBeginSym, 4); | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 571 | if (VerboseAsm) | 
|  | 572 | Asm->OutStreamer.AddComment(Twine("  Call between ") + | 
|  | 573 | BeginLabel->getName() + " and " + | 
|  | 574 | EndLabel->getName()); | 
| Chris Lattner | f1429f1 | 2010-04-04 19:58:12 +0000 | [diff] [blame] | 575 | Asm->EmitLabelDifference(EndLabel, BeginLabel, 4); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 576 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 577 | // Offset of the landing pad, counted in 16-byte bundles relative to the | 
|  | 578 | // @LPStart address. | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 579 | if (!S.PadLabel) { | 
|  | 580 | if (VerboseAsm) | 
|  | 581 | Asm->OutStreamer.AddComment("    has no landing pad"); | 
| Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 582 | Asm->OutStreamer.EmitIntValue(0, 4/*size*/); | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 583 | } else { | 
|  | 584 | if (VerboseAsm) | 
|  | 585 | Asm->OutStreamer.AddComment(Twine("    jumps to ") + | 
|  | 586 | S.PadLabel->getName()); | 
| Chris Lattner | c7cc815 | 2010-04-04 21:31:54 +0000 | [diff] [blame] | 587 | Asm->EmitLabelDifference(S.PadLabel, EHFuncBeginSym, 4); | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 588 | } | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 589 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 590 | // 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 Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 593 | if (VerboseAsm) { | 
|  | 594 | if (S.Action == 0) | 
|  | 595 | Asm->OutStreamer.AddComment("  On action: cleanup"); | 
|  | 596 | else | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 597 | Asm->OutStreamer.AddComment("  On action: " + | 
|  | 598 | Twine((S.Action - 1) / 2 + 1)); | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 599 | } | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 600 | Asm->EmitULEB128(S.Action); | 
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 601 | } | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 602 | } | 
|  | 603 |  | 
| Bill Wendling | 0e749fe | 2009-08-20 22:02:24 +0000 | [diff] [blame] | 604 | // Emit the Action Table. | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 605 | int Entry = 0; | 
| Bill Wendling | 23b177e | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 606 | for (SmallVectorImpl<ActionEntry>::const_iterator | 
|  | 607 | I = Actions.begin(), E = Actions.end(); I != E; ++I) { | 
|  | 608 | const ActionEntry &Action = *I; | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 609 |  | 
|  | 610 | if (VerboseAsm) { | 
|  | 611 | // Emit comments that decode the action table. | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 612 | Asm->OutStreamer.AddComment(">> Action Record " + Twine(++Entry) + " <<"); | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 613 | } | 
|  | 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 Sands | 2e67937 | 2011-09-28 09:13:02 +0000 | [diff] [blame] | 620 | if (Action.ValueForTypeID > 0) | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 621 | Asm->OutStreamer.AddComment("  Catch TypeInfo " + | 
|  | 622 | Twine(Action.ValueForTypeID)); | 
| Duncan Sands | 2e67937 | 2011-09-28 09:13:02 +0000 | [diff] [blame] | 623 | else if (Action.ValueForTypeID < 0) | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 624 | Asm->OutStreamer.AddComment("  Filter TypeInfo " + | 
|  | 625 | Twine(Action.ValueForTypeID)); | 
| Duncan Sands | 2e67937 | 2011-09-28 09:13:02 +0000 | [diff] [blame] | 626 | else | 
|  | 627 | Asm->OutStreamer.AddComment("  Cleanup"); | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 628 | } | 
|  | 629 | Asm->EmitSLEB128(Action.ValueForTypeID); | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 630 |  | 
| Renato Golin | c8d4065 | 2011-08-18 23:43:14 +0000 | [diff] [blame] | 631 | // 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 Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 636 | if (Action.NextAction == 0) { | 
|  | 637 | Asm->OutStreamer.AddComment("  No further actions"); | 
|  | 638 | } else { | 
|  | 639 | unsigned NextAction = Entry + (Action.NextAction + 1) / 2; | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 640 | Asm->OutStreamer.AddComment("  Continue to action "+Twine(NextAction)); | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 641 | } | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 642 | } | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 643 | Asm->EmitSLEB128(Action.NextAction); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 644 | } | 
|  | 645 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 646 | emitTypeInfos(TTypeEncoding); | 
| Anton Korobeynikov | f65a638 | 2012-11-19 21:06:26 +0000 | [diff] [blame] | 647 |  | 
|  | 648 | Asm->EmitAlignment(2); | 
|  | 649 | } | 
|  | 650 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 651 | void EHStreamer::emitTypeInfos(unsigned TTypeEncoding) { | 
| Anton Korobeynikov | f65a638 | 2012-11-19 21:06:26 +0000 | [diff] [blame] | 652 | const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); | 
|  | 653 | const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); | 
|  | 654 |  | 
|  | 655 | bool VerboseAsm = Asm->OutStreamer.isVerboseAsm(); | 
|  | 656 |  | 
|  | 657 | int Entry = 0; | 
| Bill Wendling | 4f0b8d7 | 2009-10-22 20:48:59 +0000 | [diff] [blame] | 658 | // Emit the Catch TypeInfos. | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 659 | if (VerboseAsm && !TypeInfos.empty()) { | 
|  | 660 | Asm->OutStreamer.AddComment(">> Catch TypeInfos <<"); | 
| Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 661 | Asm->OutStreamer.AddBlankLine(); | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 662 | Entry = TypeInfos.size(); | 
| Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 663 | } | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 664 |  | 
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 665 | for (std::vector<const GlobalVariable *>::const_reverse_iterator | 
| Bill Wendling | 4b384b0 | 2009-11-19 00:09:14 +0000 | [diff] [blame] | 666 | I = TypeInfos.rbegin(), E = TypeInfos.rend(); I != E; ++I) { | 
| Bill Wendling | 31c74db | 2009-11-19 19:21:09 +0000 | [diff] [blame] | 667 | const GlobalVariable *GV = *I; | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 668 | if (VerboseAsm) | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 669 | Asm->OutStreamer.AddComment("TypeInfo " + Twine(Entry--)); | 
| Anton Korobeynikov | 097b0e9 | 2012-11-19 21:17:20 +0000 | [diff] [blame] | 670 | Asm->EmitTTypeReference(GV, TTypeEncoding); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 671 | } | 
|  | 672 |  | 
| Bill Wendling | 4f0b8d7 | 2009-10-22 20:48:59 +0000 | [diff] [blame] | 673 | // Emit the Exception Specifications. | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 674 | if (VerboseAsm && !FilterIds.empty()) { | 
|  | 675 | Asm->OutStreamer.AddComment(">> Filter TypeInfos <<"); | 
| Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 676 | Asm->OutStreamer.AddBlankLine(); | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 677 | Entry = 0; | 
| Chris Lattner | 566cae9 | 2010-03-09 23:52:58 +0000 | [diff] [blame] | 678 | } | 
| Bill Wendling | 23b177e | 2009-07-28 23:44:43 +0000 | [diff] [blame] | 679 | for (std::vector<unsigned>::const_iterator | 
|  | 680 | I = FilterIds.begin(), E = FilterIds.end(); I < E; ++I) { | 
|  | 681 | unsigned TypeID = *I; | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 682 | if (VerboseAsm) { | 
|  | 683 | --Entry; | 
|  | 684 | if (TypeID != 0) | 
| Benjamin Kramer | cb6b02a | 2011-10-16 15:46:29 +0000 | [diff] [blame] | 685 | Asm->OutStreamer.AddComment("FilterInfo " + Twine(Entry)); | 
| Bill Wendling | a8339eb | 2011-06-21 22:30:20 +0000 | [diff] [blame] | 686 | } | 
|  | 687 |  | 
|  | 688 | Asm->EmitULEB128(TypeID); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 689 | } | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 690 | } | 
|  | 691 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 692 | /// Emit all exception information that should come after the content. | 
|  | 693 | void EHStreamer::endModule() { | 
| Craig Topper | ee4dab5 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 694 | llvm_unreachable("Should be implemented"); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 695 | } | 
|  | 696 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 697 | /// Gather pre-function exception information. Assumes it's being emitted | 
|  | 698 | /// immediately after the function entry point. | 
|  | 699 | void EHStreamer::beginFunction(const MachineFunction *MF) { | 
| Craig Topper | ee4dab5 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 700 | llvm_unreachable("Should be implemented"); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 701 | } | 
|  | 702 |  | 
| Saleem Abdulrasool | 8076cab | 2014-06-11 01:19:03 +0000 | [diff] [blame] | 703 | /// Gather and emit post-function exception information. | 
|  | 704 | void EHStreamer::endFunction(const MachineFunction *) { | 
| Craig Topper | ee4dab5 | 2012-02-05 08:31:47 +0000 | [diff] [blame] | 705 | llvm_unreachable("Should be implemented"); | 
| Bill Wendling | d64cd2b | 2009-05-15 01:12:28 +0000 | [diff] [blame] | 706 | } |