Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 1 | //===----- JITDwarfEmitter.cpp - Write dwarf tables into memory -----------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines a JITDwarfEmitter object that is used by the JIT to |
| 11 | // write dwarf tables to memory. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "JIT.h" |
| 16 | #include "JITDwarfEmitter.h" |
| 17 | #include "llvm/Function.h" |
| 18 | #include "llvm/ADT/DenseMap.h" |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/JITCodeEmitter.h" |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/MachineFunction.h" |
| 21 | #include "llvm/CodeGen/MachineLocation.h" |
| 22 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| 23 | #include "llvm/ExecutionEngine/JITMemoryManager.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 25 | #include "llvm/MC/MCAsmInfo.h" |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 26 | #include "llvm/MC/MCSymbol.h" |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetData.h" |
| 28 | #include "llvm/Target/TargetInstrInfo.h" |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame^] | 29 | #include "llvm/Target/TargetFrameLowering.h" |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 30 | #include "llvm/Target/TargetMachine.h" |
| 31 | #include "llvm/Target/TargetRegisterInfo.h" |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 32 | using namespace llvm; |
| 33 | |
Daniel Dunbar | 003de66 | 2009-09-21 05:58:35 +0000 | [diff] [blame] | 34 | JITDwarfEmitter::JITDwarfEmitter(JIT& theJit) : MMI(0), Jit(theJit) {} |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 35 | |
| 36 | |
| 37 | unsigned char* JITDwarfEmitter::EmitDwarfTable(MachineFunction& F, |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 38 | JITCodeEmitter& jce, |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 39 | unsigned char* StartFunction, |
Reid Kleckner | 2763217 | 2009-09-20 23:52:43 +0000 | [diff] [blame] | 40 | unsigned char* EndFunction, |
| 41 | unsigned char* &EHFramePtr) { |
Daniel Dunbar | 003de66 | 2009-09-21 05:58:35 +0000 | [diff] [blame] | 42 | assert(MMI && "MachineModuleInfo not registered!"); |
| 43 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 44 | const TargetMachine& TM = F.getTarget(); |
| 45 | TD = TM.getTargetData(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame^] | 46 | stackGrowthDirection = TM.getFrameLowering()->getStackGrowthDirection(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 47 | RI = TM.getRegisterInfo(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame^] | 48 | TFI = TM.getFrameLowering(); |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 49 | JCE = &jce; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 50 | |
| 51 | unsigned char* ExceptionTable = EmitExceptionTable(&F, StartFunction, |
| 52 | EndFunction); |
| 53 | |
| 54 | unsigned char* Result = 0; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 55 | |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 56 | const std::vector<const Function *> Personalities = MMI->getPersonalities(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 57 | EHFramePtr = EmitCommonEHFrame(Personalities[MMI->getPersonalityIndex()]); |
| 58 | |
| 59 | Result = EmitEHFrame(Personalities[MMI->getPersonalityIndex()], EHFramePtr, |
| 60 | StartFunction, EndFunction, ExceptionTable); |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 61 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 62 | return Result; |
| 63 | } |
| 64 | |
| 65 | |
Nicolas Geoffray | 5913e6c | 2008-04-20 17:44:19 +0000 | [diff] [blame] | 66 | void |
| 67 | JITDwarfEmitter::EmitFrameMoves(intptr_t BaseLabelPtr, |
| 68 | const std::vector<MachineMove> &Moves) const { |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 69 | unsigned PointerSize = TD->getPointerSize(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame^] | 70 | int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ? |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 71 | PointerSize : -PointerSize; |
Chris Lattner | 2e9919a | 2010-03-14 08:12:40 +0000 | [diff] [blame] | 72 | MCSymbol *BaseLabel = 0; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 73 | |
| 74 | for (unsigned i = 0, N = Moves.size(); i < N; ++i) { |
| 75 | const MachineMove &Move = Moves[i]; |
Chris Lattner | 2e9919a | 2010-03-14 08:12:40 +0000 | [diff] [blame] | 76 | MCSymbol *Label = Move.getLabel(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 77 | |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 78 | // Throw out move if the label is invalid. |
Bill Wendling | 091fc4b | 2010-04-18 00:56:05 +0000 | [diff] [blame] | 79 | if (Label && (*JCE->getLabelLocations())[Label] == 0) |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 80 | continue; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 81 | |
| 82 | intptr_t LabelPtr = 0; |
Chris Lattner | 2e9919a | 2010-03-14 08:12:40 +0000 | [diff] [blame] | 83 | if (Label) LabelPtr = JCE->getLabelAddress(Label); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 84 | |
| 85 | const MachineLocation &Dst = Move.getDestination(); |
| 86 | const MachineLocation &Src = Move.getSource(); |
| 87 | |
| 88 | // Advance row if new location. |
Chris Lattner | 2e9919a | 2010-03-14 08:12:40 +0000 | [diff] [blame] | 89 | if (BaseLabelPtr && Label && BaseLabel != Label) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 90 | JCE->emitByte(dwarf::DW_CFA_advance_loc4); |
| 91 | JCE->emitInt32(LabelPtr - BaseLabelPtr); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 92 | |
Chris Lattner | 2e9919a | 2010-03-14 08:12:40 +0000 | [diff] [blame] | 93 | BaseLabel = Label; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 94 | BaseLabelPtr = LabelPtr; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | // If advancing cfa. |
Daniel Dunbar | 489032a | 2008-10-03 17:11:57 +0000 | [diff] [blame] | 98 | if (Dst.isReg() && Dst.getReg() == MachineLocation::VirtualFP) { |
| 99 | if (!Src.isReg()) { |
| 100 | if (Src.getReg() == MachineLocation::VirtualFP) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 101 | JCE->emitByte(dwarf::DW_CFA_def_cfa_offset); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 102 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 103 | JCE->emitByte(dwarf::DW_CFA_def_cfa); |
| 104 | JCE->emitULEB128Bytes(RI->getDwarfRegNum(Src.getReg(), true)); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 107 | JCE->emitULEB128Bytes(-Src.getOffset()); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 108 | } else { |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 109 | llvm_unreachable("Machine move not supported yet."); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 110 | } |
Daniel Dunbar | 489032a | 2008-10-03 17:11:57 +0000 | [diff] [blame] | 111 | } else if (Src.isReg() && |
| 112 | Src.getReg() == MachineLocation::VirtualFP) { |
| 113 | if (Dst.isReg()) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 114 | JCE->emitByte(dwarf::DW_CFA_def_cfa_register); |
| 115 | JCE->emitULEB128Bytes(RI->getDwarfRegNum(Dst.getReg(), true)); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 116 | } else { |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 117 | llvm_unreachable("Machine move not supported yet."); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 118 | } |
| 119 | } else { |
Daniel Dunbar | 489032a | 2008-10-03 17:11:57 +0000 | [diff] [blame] | 120 | unsigned Reg = RI->getDwarfRegNum(Src.getReg(), true); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 121 | int Offset = Dst.getOffset() / stackGrowth; |
| 122 | |
| 123 | if (Offset < 0) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 124 | JCE->emitByte(dwarf::DW_CFA_offset_extended_sf); |
| 125 | JCE->emitULEB128Bytes(Reg); |
| 126 | JCE->emitSLEB128Bytes(Offset); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 127 | } else if (Reg < 64) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 128 | JCE->emitByte(dwarf::DW_CFA_offset + Reg); |
| 129 | JCE->emitULEB128Bytes(Offset); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 130 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 131 | JCE->emitByte(dwarf::DW_CFA_offset_extended); |
| 132 | JCE->emitULEB128Bytes(Reg); |
| 133 | JCE->emitULEB128Bytes(Offset); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /// SharedTypeIds - How many leading type ids two landing pads have in common. |
| 140 | static unsigned SharedTypeIds(const LandingPadInfo *L, |
| 141 | const LandingPadInfo *R) { |
| 142 | const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds; |
| 143 | unsigned LSize = LIds.size(), RSize = RIds.size(); |
| 144 | unsigned MinSize = LSize < RSize ? LSize : RSize; |
| 145 | unsigned Count = 0; |
| 146 | |
| 147 | for (; Count != MinSize; ++Count) |
| 148 | if (LIds[Count] != RIds[Count]) |
| 149 | return Count; |
| 150 | |
| 151 | return Count; |
| 152 | } |
| 153 | |
| 154 | |
| 155 | /// PadLT - Order landing pads lexicographically by type id. |
| 156 | static bool PadLT(const LandingPadInfo *L, const LandingPadInfo *R) { |
| 157 | const std::vector<int> &LIds = L->TypeIds, &RIds = R->TypeIds; |
| 158 | unsigned LSize = LIds.size(), RSize = RIds.size(); |
| 159 | unsigned MinSize = LSize < RSize ? LSize : RSize; |
| 160 | |
| 161 | for (unsigned i = 0; i != MinSize; ++i) |
| 162 | if (LIds[i] != RIds[i]) |
| 163 | return LIds[i] < RIds[i]; |
| 164 | |
| 165 | return LSize < RSize; |
| 166 | } |
| 167 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 168 | namespace { |
| 169 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 170 | /// ActionEntry - Structure describing an entry in the actions table. |
| 171 | struct ActionEntry { |
| 172 | int ValueForTypeID; // The value to write - may not be equal to the type id. |
| 173 | int NextAction; |
| 174 | struct ActionEntry *Previous; |
| 175 | }; |
| 176 | |
| 177 | /// PadRange - Structure holding a try-range and the associated landing pad. |
| 178 | struct PadRange { |
| 179 | // The index of the landing pad. |
| 180 | unsigned PadIndex; |
| 181 | // The index of the begin and end labels in the landing pad's label lists. |
| 182 | unsigned RangeIndex; |
| 183 | }; |
| 184 | |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 185 | typedef DenseMap<MCSymbol*, PadRange> RangeMapType; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 186 | |
| 187 | /// CallSiteEntry - Structure describing an entry in the call-site table. |
| 188 | struct CallSiteEntry { |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 189 | MCSymbol *BeginLabel; // zero indicates the start of the function. |
| 190 | MCSymbol *EndLabel; // zero indicates the end of the function. |
| 191 | MCSymbol *PadLabel; // zero indicates that there is no landing pad. |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 192 | unsigned Action; |
| 193 | }; |
| 194 | |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 197 | unsigned char* JITDwarfEmitter::EmitExceptionTable(MachineFunction* MF, |
| 198 | unsigned char* StartFunction, |
Nicolas Geoffray | 5913e6c | 2008-04-20 17:44:19 +0000 | [diff] [blame] | 199 | unsigned char* EndFunction) const { |
Daniel Dunbar | 003de66 | 2009-09-21 05:58:35 +0000 | [diff] [blame] | 200 | assert(MMI && "MachineModuleInfo not registered!"); |
| 201 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 202 | // Map all labels and get rid of any dead landing pads. |
Bill Wendling | 47639fc | 2010-04-16 08:46:10 +0000 | [diff] [blame] | 203 | MMI->TidyLandingPads(JCE->getLabelLocations()); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 204 | |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 205 | const std::vector<const GlobalVariable *> &TypeInfos = MMI->getTypeInfos(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 206 | const std::vector<unsigned> &FilterIds = MMI->getFilterIds(); |
| 207 | const std::vector<LandingPadInfo> &PadInfos = MMI->getLandingPads(); |
| 208 | if (PadInfos.empty()) return 0; |
| 209 | |
| 210 | // Sort the landing pads in order of their type ids. This is used to fold |
| 211 | // duplicate actions. |
| 212 | SmallVector<const LandingPadInfo *, 64> LandingPads; |
| 213 | LandingPads.reserve(PadInfos.size()); |
| 214 | for (unsigned i = 0, N = PadInfos.size(); i != N; ++i) |
| 215 | LandingPads.push_back(&PadInfos[i]); |
| 216 | std::sort(LandingPads.begin(), LandingPads.end(), PadLT); |
| 217 | |
| 218 | // Negative type ids index into FilterIds, positive type ids index into |
| 219 | // TypeInfos. The value written for a positive type id is just the type |
| 220 | // id itself. For a negative type id, however, the value written is the |
| 221 | // (negative) byte offset of the corresponding FilterIds entry. The byte |
| 222 | // offset is usually equal to the type id, because the FilterIds entries |
| 223 | // are written using a variable width encoding which outputs one byte per |
| 224 | // entry as long as the value written is not too large, but can differ. |
| 225 | // This kind of complication does not occur for positive type ids because |
| 226 | // type infos are output using a fixed width encoding. |
| 227 | // FilterOffsets[i] holds the byte offset corresponding to FilterIds[i]. |
| 228 | SmallVector<int, 16> FilterOffsets; |
| 229 | FilterOffsets.reserve(FilterIds.size()); |
| 230 | int Offset = -1; |
| 231 | for(std::vector<unsigned>::const_iterator I = FilterIds.begin(), |
| 232 | E = FilterIds.end(); I != E; ++I) { |
| 233 | FilterOffsets.push_back(Offset); |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 234 | Offset -= MCAsmInfo::getULEB128Size(*I); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | // Compute the actions table and gather the first action index for each |
| 238 | // landing pad site. |
| 239 | SmallVector<ActionEntry, 32> Actions; |
| 240 | SmallVector<unsigned, 64> FirstActions; |
| 241 | FirstActions.reserve(LandingPads.size()); |
| 242 | |
| 243 | int FirstAction = 0; |
| 244 | unsigned SizeActions = 0; |
| 245 | for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { |
| 246 | const LandingPadInfo *LP = LandingPads[i]; |
| 247 | const std::vector<int> &TypeIds = LP->TypeIds; |
| 248 | const unsigned NumShared = i ? SharedTypeIds(LP, LandingPads[i-1]) : 0; |
| 249 | unsigned SizeSiteActions = 0; |
| 250 | |
| 251 | if (NumShared < TypeIds.size()) { |
| 252 | unsigned SizeAction = 0; |
| 253 | ActionEntry *PrevAction = 0; |
| 254 | |
| 255 | if (NumShared) { |
| 256 | const unsigned SizePrevIds = LandingPads[i-1]->TypeIds.size(); |
| 257 | assert(Actions.size()); |
| 258 | PrevAction = &Actions.back(); |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 259 | SizeAction = MCAsmInfo::getSLEB128Size(PrevAction->NextAction) + |
| 260 | MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 261 | for (unsigned j = NumShared; j != SizePrevIds; ++j) { |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 262 | SizeAction -= MCAsmInfo::getSLEB128Size(PrevAction->ValueForTypeID); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 263 | SizeAction += -PrevAction->NextAction; |
| 264 | PrevAction = PrevAction->Previous; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | // Compute the actions. |
| 269 | for (unsigned I = NumShared, M = TypeIds.size(); I != M; ++I) { |
| 270 | int TypeID = TypeIds[I]; |
| 271 | assert(-1-TypeID < (int)FilterOffsets.size() && "Unknown filter id!"); |
| 272 | int ValueForTypeID = TypeID < 0 ? FilterOffsets[-1 - TypeID] : TypeID; |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 273 | unsigned SizeTypeID = MCAsmInfo::getSLEB128Size(ValueForTypeID); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 274 | |
| 275 | int NextAction = SizeAction ? -(SizeAction + SizeTypeID) : 0; |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 276 | SizeAction = SizeTypeID + MCAsmInfo::getSLEB128Size(NextAction); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 277 | SizeSiteActions += SizeAction; |
| 278 | |
| 279 | ActionEntry Action = {ValueForTypeID, NextAction, PrevAction}; |
| 280 | Actions.push_back(Action); |
| 281 | |
| 282 | PrevAction = &Actions.back(); |
| 283 | } |
| 284 | |
| 285 | // Record the first action of the landing pad site. |
| 286 | FirstAction = SizeActions + SizeSiteActions - SizeAction + 1; |
| 287 | } // else identical - re-use previous FirstAction |
| 288 | |
| 289 | FirstActions.push_back(FirstAction); |
| 290 | |
| 291 | // Compute this sites contribution to size. |
| 292 | SizeActions += SizeSiteActions; |
| 293 | } |
| 294 | |
| 295 | // Compute the call-site table. Entries must be ordered by address. |
| 296 | SmallVector<CallSiteEntry, 64> CallSites; |
| 297 | |
| 298 | RangeMapType PadMap; |
| 299 | for (unsigned i = 0, N = LandingPads.size(); i != N; ++i) { |
| 300 | const LandingPadInfo *LandingPad = LandingPads[i]; |
| 301 | for (unsigned j=0, E = LandingPad->BeginLabels.size(); j != E; ++j) { |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 302 | MCSymbol *BeginLabel = LandingPad->BeginLabels[j]; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 303 | assert(!PadMap.count(BeginLabel) && "Duplicate landing pad labels!"); |
| 304 | PadRange P = { i, j }; |
| 305 | PadMap[BeginLabel] = P; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | bool MayThrow = false; |
Chris Lattner | 1611273 | 2010-03-14 01:41:15 +0000 | [diff] [blame] | 310 | MCSymbol *LastLabel = 0; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 311 | for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); |
| 312 | I != E; ++I) { |
| 313 | for (MachineBasicBlock::const_iterator MI = I->begin(), E = I->end(); |
| 314 | MI != E; ++MI) { |
Dan Gohman | 4406604 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 315 | if (!MI->isLabel()) { |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 316 | MayThrow |= MI->getDesc().isCall(); |
| 317 | continue; |
| 318 | } |
| 319 | |
Chris Lattner | 6b4205a | 2010-03-14 08:28:48 +0000 | [diff] [blame] | 320 | MCSymbol *BeginLabel = MI->getOperand(0).getMCSymbol(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 321 | assert(BeginLabel && "Invalid label!"); |
| 322 | |
| 323 | if (BeginLabel == LastLabel) |
| 324 | MayThrow = false; |
| 325 | |
| 326 | RangeMapType::iterator L = PadMap.find(BeginLabel); |
| 327 | |
| 328 | if (L == PadMap.end()) |
| 329 | continue; |
| 330 | |
| 331 | PadRange P = L->second; |
| 332 | const LandingPadInfo *LandingPad = LandingPads[P.PadIndex]; |
| 333 | |
| 334 | assert(BeginLabel == LandingPad->BeginLabels[P.RangeIndex] && |
| 335 | "Inconsistent landing pad map!"); |
| 336 | |
| 337 | // If some instruction between the previous try-range and this one may |
| 338 | // throw, create a call-site entry with no landing pad for the region |
| 339 | // between the try-ranges. |
| 340 | if (MayThrow) { |
| 341 | CallSiteEntry Site = {LastLabel, BeginLabel, 0, 0}; |
| 342 | CallSites.push_back(Site); |
| 343 | } |
| 344 | |
| 345 | LastLabel = LandingPad->EndLabels[P.RangeIndex]; |
| 346 | CallSiteEntry Site = {BeginLabel, LastLabel, |
| 347 | LandingPad->LandingPadLabel, FirstActions[P.PadIndex]}; |
| 348 | |
| 349 | assert(Site.BeginLabel && Site.EndLabel && Site.PadLabel && |
| 350 | "Invalid landing pad!"); |
| 351 | |
| 352 | // Try to merge with the previous call-site. |
| 353 | if (CallSites.size()) { |
Dan Gohman | 719de53 | 2008-06-21 22:00:54 +0000 | [diff] [blame] | 354 | CallSiteEntry &Prev = CallSites.back(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 355 | if (Site.PadLabel == Prev.PadLabel && Site.Action == Prev.Action) { |
| 356 | // Extend the range of the previous entry. |
| 357 | Prev.EndLabel = Site.EndLabel; |
| 358 | continue; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | // Otherwise, create a new call-site. |
| 363 | CallSites.push_back(Site); |
| 364 | } |
| 365 | } |
| 366 | // If some instruction between the previous try-range and the end of the |
| 367 | // function may throw, create a call-site entry with no landing pad for the |
| 368 | // region following the try-range. |
| 369 | if (MayThrow) { |
| 370 | CallSiteEntry Site = {LastLabel, 0, 0, 0}; |
| 371 | CallSites.push_back(Site); |
| 372 | } |
| 373 | |
| 374 | // Final tallies. |
| 375 | unsigned SizeSites = CallSites.size() * (sizeof(int32_t) + // Site start. |
| 376 | sizeof(int32_t) + // Site length. |
| 377 | sizeof(int32_t)); // Landing pad. |
| 378 | for (unsigned i = 0, e = CallSites.size(); i < e; ++i) |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 379 | SizeSites += MCAsmInfo::getULEB128Size(CallSites[i].Action); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 380 | |
| 381 | unsigned SizeTypes = TypeInfos.size() * TD->getPointerSize(); |
| 382 | |
| 383 | unsigned TypeOffset = sizeof(int8_t) + // Call site format |
| 384 | // Call-site table length |
Chris Lattner | af76e59 | 2009-08-22 20:48:53 +0000 | [diff] [blame] | 385 | MCAsmInfo::getULEB128Size(SizeSites) + |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 386 | SizeSites + SizeActions + SizeTypes; |
| 387 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 388 | // Begin the exception table. |
Reid Kleckner | 01248e6 | 2009-08-21 21:03:57 +0000 | [diff] [blame] | 389 | JCE->emitAlignmentWithFill(4, 0); |
| 390 | // Asm->EOL("Padding"); |
| 391 | |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 392 | unsigned char* DwarfExceptionTable = (unsigned char*)JCE->getCurrentPCValue(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 393 | |
| 394 | // Emit the header. |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 395 | JCE->emitByte(dwarf::DW_EH_PE_omit); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 396 | // Asm->EOL("LPStart format (DW_EH_PE_omit)"); |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 397 | JCE->emitByte(dwarf::DW_EH_PE_absptr); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 398 | // Asm->EOL("TType format (DW_EH_PE_absptr)"); |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 399 | JCE->emitULEB128Bytes(TypeOffset); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 400 | // Asm->EOL("TType base offset"); |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 401 | JCE->emitByte(dwarf::DW_EH_PE_udata4); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 402 | // Asm->EOL("Call site format (DW_EH_PE_udata4)"); |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 403 | JCE->emitULEB128Bytes(SizeSites); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 404 | // Asm->EOL("Call-site table length"); |
| 405 | |
| 406 | // Emit the landing pad site information. |
| 407 | for (unsigned i = 0; i < CallSites.size(); ++i) { |
| 408 | CallSiteEntry &S = CallSites[i]; |
| 409 | intptr_t BeginLabelPtr = 0; |
| 410 | intptr_t EndLabelPtr = 0; |
| 411 | |
| 412 | if (!S.BeginLabel) { |
| 413 | BeginLabelPtr = (intptr_t)StartFunction; |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 414 | JCE->emitInt32(0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 415 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 416 | BeginLabelPtr = JCE->getLabelAddress(S.BeginLabel); |
| 417 | JCE->emitInt32(BeginLabelPtr - (intptr_t)StartFunction); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | // Asm->EOL("Region start"); |
| 421 | |
Bill Wendling | abeca44 | 2009-12-28 01:53:00 +0000 | [diff] [blame] | 422 | if (!S.EndLabel) |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 423 | EndLabelPtr = (intptr_t)EndFunction; |
Bill Wendling | abeca44 | 2009-12-28 01:53:00 +0000 | [diff] [blame] | 424 | else |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 425 | EndLabelPtr = JCE->getLabelAddress(S.EndLabel); |
Bill Wendling | abeca44 | 2009-12-28 01:53:00 +0000 | [diff] [blame] | 426 | |
| 427 | JCE->emitInt32(EndLabelPtr - BeginLabelPtr); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 428 | //Asm->EOL("Region length"); |
| 429 | |
| 430 | if (!S.PadLabel) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 431 | JCE->emitInt32(0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 432 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 433 | unsigned PadLabelPtr = JCE->getLabelAddress(S.PadLabel); |
| 434 | JCE->emitInt32(PadLabelPtr - (intptr_t)StartFunction); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 435 | } |
| 436 | // Asm->EOL("Landing pad"); |
| 437 | |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 438 | JCE->emitULEB128Bytes(S.Action); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 439 | // Asm->EOL("Action"); |
| 440 | } |
| 441 | |
| 442 | // Emit the actions. |
| 443 | for (unsigned I = 0, N = Actions.size(); I != N; ++I) { |
| 444 | ActionEntry &Action = Actions[I]; |
| 445 | |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 446 | JCE->emitSLEB128Bytes(Action.ValueForTypeID); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 447 | //Asm->EOL("TypeInfo index"); |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 448 | JCE->emitSLEB128Bytes(Action.NextAction); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 449 | //Asm->EOL("Next action"); |
| 450 | } |
| 451 | |
| 452 | // Emit the type ids. |
| 453 | for (unsigned M = TypeInfos.size(); M; --M) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 454 | const GlobalVariable *GV = TypeInfos[M - 1]; |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 455 | |
| 456 | if (GV) { |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 457 | if (TD->getPointerSize() == sizeof(int32_t)) |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 458 | JCE->emitInt32((intptr_t)Jit.getOrEmitGlobalVariable(GV)); |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 459 | else |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 460 | JCE->emitInt64((intptr_t)Jit.getOrEmitGlobalVariable(GV)); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 461 | } else { |
| 462 | if (TD->getPointerSize() == sizeof(int32_t)) |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 463 | JCE->emitInt32(0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 464 | else |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 465 | JCE->emitInt64(0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 466 | } |
| 467 | // Asm->EOL("TypeInfo"); |
| 468 | } |
| 469 | |
| 470 | // Emit the filter typeids. |
| 471 | for (unsigned j = 0, M = FilterIds.size(); j < M; ++j) { |
| 472 | unsigned TypeID = FilterIds[j]; |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 473 | JCE->emitULEB128Bytes(TypeID); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 474 | //Asm->EOL("Filter TypeInfo index"); |
| 475 | } |
Reid Kleckner | 01248e6 | 2009-08-21 21:03:57 +0000 | [diff] [blame] | 476 | |
| 477 | JCE->emitAlignmentWithFill(4, 0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 478 | |
| 479 | return DwarfExceptionTable; |
| 480 | } |
| 481 | |
Nicolas Geoffray | 5913e6c | 2008-04-20 17:44:19 +0000 | [diff] [blame] | 482 | unsigned char* |
| 483 | JITDwarfEmitter::EmitCommonEHFrame(const Function* Personality) const { |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 484 | unsigned PointerSize = TD->getPointerSize(); |
Anton Korobeynikov | 16c29b5 | 2011-01-10 12:39:04 +0000 | [diff] [blame^] | 485 | int stackGrowth = stackGrowthDirection == TargetFrameLowering::StackGrowsUp ? |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 486 | PointerSize : -PointerSize; |
| 487 | |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 488 | unsigned char* StartCommonPtr = (unsigned char*)JCE->getCurrentPCValue(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 489 | // EH Common Frame header |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 490 | JCE->allocateSpace(4, 0); |
| 491 | unsigned char* FrameCommonBeginPtr = (unsigned char*)JCE->getCurrentPCValue(); |
| 492 | JCE->emitInt32((int)0); |
| 493 | JCE->emitByte(dwarf::DW_CIE_VERSION); |
| 494 | JCE->emitString(Personality ? "zPLR" : "zR"); |
| 495 | JCE->emitULEB128Bytes(1); |
| 496 | JCE->emitSLEB128Bytes(stackGrowth); |
| 497 | JCE->emitByte(RI->getDwarfRegNum(RI->getRARegister(), true)); |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 498 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 499 | if (Personality) { |
Nicolas Geoffray | 42cc8f1 | 2009-02-15 20:49:23 +0000 | [diff] [blame] | 500 | // Augmentation Size: 3 small ULEBs of one byte each, and the personality |
| 501 | // function which size is PointerSize. |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 502 | JCE->emitULEB128Bytes(3 + PointerSize); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 503 | |
Nicolas Geoffray | 42cc8f1 | 2009-02-15 20:49:23 +0000 | [diff] [blame] | 504 | // We set the encoding of the personality as direct encoding because we use |
| 505 | // the function pointer. The encoding is not relative because the current |
| 506 | // PC value may be bigger than the personality function pointer. |
| 507 | if (PointerSize == 4) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 508 | JCE->emitByte(dwarf::DW_EH_PE_sdata4); |
| 509 | JCE->emitInt32(((intptr_t)Jit.getPointerToGlobal(Personality))); |
Nicolas Geoffray | 42cc8f1 | 2009-02-15 20:49:23 +0000 | [diff] [blame] | 510 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 511 | JCE->emitByte(dwarf::DW_EH_PE_sdata8); |
| 512 | JCE->emitInt64(((intptr_t)Jit.getPointerToGlobal(Personality))); |
Nicolas Geoffray | 42cc8f1 | 2009-02-15 20:49:23 +0000 | [diff] [blame] | 513 | } |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 514 | |
Bill Wendling | 89ee706 | 2010-02-16 00:58:02 +0000 | [diff] [blame] | 515 | // LSDA encoding: This must match the encoding used in EmitEHFrame () |
| 516 | if (PointerSize == 4) |
| 517 | JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4); |
| 518 | else |
| 519 | JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8); |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 520 | JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 521 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 522 | JCE->emitULEB128Bytes(1); |
| 523 | JCE->emitULEB128Bytes(dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | std::vector<MachineMove> Moves; |
Anton Korobeynikov | d9e3385 | 2010-11-18 23:25:52 +0000 | [diff] [blame] | 527 | TFI->getInitialFrameState(Moves); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 528 | EmitFrameMoves(0, Moves); |
Reid Kleckner | 01248e6 | 2009-08-21 21:03:57 +0000 | [diff] [blame] | 529 | |
| 530 | JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop); |
| 531 | |
| 532 | JCE->emitInt32At((uintptr_t*)StartCommonPtr, |
| 533 | (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() - |
| 534 | FrameCommonBeginPtr)); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 535 | |
| 536 | return StartCommonPtr; |
| 537 | } |
| 538 | |
| 539 | |
Nicolas Geoffray | 5913e6c | 2008-04-20 17:44:19 +0000 | [diff] [blame] | 540 | unsigned char* |
| 541 | JITDwarfEmitter::EmitEHFrame(const Function* Personality, |
| 542 | unsigned char* StartCommonPtr, |
| 543 | unsigned char* StartFunction, |
| 544 | unsigned char* EndFunction, |
| 545 | unsigned char* ExceptionTable) const { |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 546 | unsigned PointerSize = TD->getPointerSize(); |
| 547 | |
| 548 | // EH frame header. |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 549 | unsigned char* StartEHPtr = (unsigned char*)JCE->getCurrentPCValue(); |
| 550 | JCE->allocateSpace(4, 0); |
| 551 | unsigned char* FrameBeginPtr = (unsigned char*)JCE->getCurrentPCValue(); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 552 | // FDE CIE Offset |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 553 | JCE->emitInt32(FrameBeginPtr - StartCommonPtr); |
| 554 | JCE->emitInt32(StartFunction - (unsigned char*)JCE->getCurrentPCValue()); |
| 555 | JCE->emitInt32(EndFunction - StartFunction); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 556 | |
| 557 | // If there is a personality and landing pads then point to the language |
| 558 | // specific data area in the exception table. |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 559 | if (Personality) { |
| 560 | JCE->emitULEB128Bytes(PointerSize == 4 ? 4 : 8); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 561 | |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 562 | if (PointerSize == 4) { |
| 563 | if (!MMI->getLandingPads().empty()) |
| 564 | JCE->emitInt32(ExceptionTable-(unsigned char*)JCE->getCurrentPCValue()); |
| 565 | else |
| 566 | JCE->emitInt32((int)0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 567 | } else { |
Bill Wendling | 9d48b55 | 2009-09-09 00:11:02 +0000 | [diff] [blame] | 568 | if (!MMI->getLandingPads().empty()) |
| 569 | JCE->emitInt64(ExceptionTable-(unsigned char*)JCE->getCurrentPCValue()); |
| 570 | else |
| 571 | JCE->emitInt64((int)0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 572 | } |
| 573 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 574 | JCE->emitULEB128Bytes(0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | // Indicate locations of function specific callee saved registers in |
| 578 | // frame. |
| 579 | EmitFrameMoves((intptr_t)StartFunction, MMI->getFrameMoves()); |
Reid Kleckner | 01248e6 | 2009-08-21 21:03:57 +0000 | [diff] [blame] | 580 | |
| 581 | JCE->emitAlignmentWithFill(PointerSize, dwarf::DW_CFA_nop); |
| 582 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 583 | // Indicate the size of the table |
Reid Kleckner | 01248e6 | 2009-08-21 21:03:57 +0000 | [diff] [blame] | 584 | JCE->emitInt32At((uintptr_t*)StartEHPtr, |
| 585 | (uintptr_t)((unsigned char*)JCE->getCurrentPCValue() - |
| 586 | StartEHPtr)); |
| 587 | |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 588 | // Double zeroes for the unwind runtime |
| 589 | if (PointerSize == 8) { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 590 | JCE->emitInt64(0); |
| 591 | JCE->emitInt64(0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 592 | } else { |
Bruno Cardoso Lopes | a3f99f9 | 2009-05-30 20:51:52 +0000 | [diff] [blame] | 593 | JCE->emitInt32(0); |
| 594 | JCE->emitInt32(0); |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 595 | } |
Nicolas Geoffray | afe6c2b | 2008-02-13 18:39:37 +0000 | [diff] [blame] | 596 | |
| 597 | return StartEHPtr; |
| 598 | } |