Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 1 | //===-- AsmPrinterDwarf.cpp - AsmPrinter Dwarf Support --------------------===// |
| 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 implements the Dwarf emissions parts of AsmPrinter. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #define DEBUG_TYPE "asm-printer" |
| 15 | #include "llvm/CodeGen/AsmPrinter.h" |
Eric Christopher | 698a8ab | 2014-03-07 01:44:14 +0000 | [diff] [blame^] | 16 | #include "llvm/ADT/SmallBitVector.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Twine.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DataLayout.h" |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCAsmInfo.h" |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSection.h" |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCStreamer.h" |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbol.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MachineLocation.h" |
| 24 | #include "llvm/Support/Dwarf.h" |
| 25 | #include "llvm/Support/ErrorHandling.h" |
Anton Korobeynikov | 2f93128 | 2011-01-10 12:39:04 +0000 | [diff] [blame] | 26 | #include "llvm/Target/TargetFrameLowering.h" |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 27 | #include "llvm/Target/TargetLoweringObjectFile.h" |
| 28 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | aabc604 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 29 | #include "llvm/Target/TargetRegisterInfo.h" |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 30 | using namespace llvm; |
| 31 | |
Chris Lattner | aabc604 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 32 | //===----------------------------------------------------------------------===// |
| 33 | // Dwarf Emission Helper Routines |
| 34 | //===----------------------------------------------------------------------===// |
| 35 | |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 36 | /// EmitSLEB128 - emit the specified signed leb128 value. |
David Blaikie | 5acff7e | 2013-06-23 18:31:11 +0000 | [diff] [blame] | 37 | void AsmPrinter::EmitSLEB128(int64_t Value, const char *Desc) const { |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 38 | if (isVerbose() && Desc) |
| 39 | OutStreamer.AddComment(Desc); |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 40 | |
Benjamin Kramer | c74798d | 2011-11-05 11:52:44 +0000 | [diff] [blame] | 41 | OutStreamer.EmitSLEB128IntValue(Value); |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /// EmitULEB128 - emit the specified signed leb128 value. |
David Blaikie | 5acff7e | 2013-06-23 18:31:11 +0000 | [diff] [blame] | 45 | void AsmPrinter::EmitULEB128(uint64_t Value, const char *Desc, |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 46 | unsigned PadTo) const { |
| 47 | if (isVerbose() && Desc) |
| 48 | OutStreamer.AddComment(Desc); |
Rafael Espindola | 38d0756 | 2010-11-04 18:17:08 +0000 | [diff] [blame] | 49 | |
Eric Christopher | bf7bc49 | 2013-01-09 03:52:05 +0000 | [diff] [blame] | 50 | OutStreamer.EmitULEB128IntValue(Value, PadTo); |
Chris Lattner | 9efd118 | 2010-04-04 19:09:29 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Chris Lattner | baf2be0 | 2010-04-04 20:01:25 +0000 | [diff] [blame] | 53 | /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value. |
| 54 | void AsmPrinter::EmitCFAByte(unsigned Val) const { |
| 55 | if (isVerbose()) { |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 56 | if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset + 64) |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 57 | OutStreamer.AddComment("DW_CFA_offset + Reg (" + |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 58 | Twine(Val - dwarf::DW_CFA_offset) + ")"); |
Chris Lattner | baf2be0 | 2010-04-04 20:01:25 +0000 | [diff] [blame] | 59 | else |
| 60 | OutStreamer.AddComment(dwarf::CallFrameString(Val)); |
| 61 | } |
Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 62 | OutStreamer.EmitIntValue(Val, 1); |
Chris Lattner | baf2be0 | 2010-04-04 20:01:25 +0000 | [diff] [blame] | 63 | } |
| 64 | |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 65 | static const char *DecodeDWARFEncoding(unsigned Encoding) { |
| 66 | switch (Encoding) { |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 67 | case dwarf::DW_EH_PE_absptr: |
| 68 | return "absptr"; |
| 69 | case dwarf::DW_EH_PE_omit: |
| 70 | return "omit"; |
| 71 | case dwarf::DW_EH_PE_pcrel: |
| 72 | return "pcrel"; |
| 73 | case dwarf::DW_EH_PE_udata4: |
| 74 | return "udata4"; |
| 75 | case dwarf::DW_EH_PE_udata8: |
| 76 | return "udata8"; |
| 77 | case dwarf::DW_EH_PE_sdata4: |
| 78 | return "sdata4"; |
| 79 | case dwarf::DW_EH_PE_sdata8: |
| 80 | return "sdata8"; |
| 81 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4: |
| 82 | return "pcrel udata4"; |
| 83 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4: |
| 84 | return "pcrel sdata4"; |
| 85 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8: |
| 86 | return "pcrel udata8"; |
| 87 | case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8: |
| 88 | return "pcrel sdata8"; |
| 89 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4 |
| 90 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 91 | return "indirect pcrel udata4"; |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 92 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4 |
| 93 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 94 | return "indirect pcrel sdata4"; |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 95 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8 |
| 96 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 97 | return "indirect pcrel udata8"; |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 98 | case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8 |
| 99 | : |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 100 | return "indirect pcrel sdata8"; |
| 101 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 102 | |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 103 | return "<unknown encoding>"; |
| 104 | } |
| 105 | |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 106 | /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an |
| 107 | /// encoding. If verbose assembly output is enabled, we output comments |
| 108 | /// describing the encoding. Desc is an optional string saying what the |
| 109 | /// encoding is specifying (e.g. "LSDA"). |
Chris Lattner | aabc604 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 110 | void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) const { |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 111 | if (isVerbose()) { |
Eric Christopher | cb7119e | 2013-12-04 22:29:02 +0000 | [diff] [blame] | 112 | if (Desc) |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 113 | OutStreamer.AddComment(Twine(Desc) + " Encoding = " + |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 114 | Twine(DecodeDWARFEncoding(Val))); |
| 115 | else |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 116 | OutStreamer.AddComment(Twine("Encoding = ") + DecodeDWARFEncoding(Val)); |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 117 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 118 | |
Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 119 | OutStreamer.EmitIntValue(Val, 1); |
Chris Lattner | b75af3c | 2010-04-04 20:04:21 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 122 | /// GetSizeOfEncodedValue - Return the size of the encoding in bytes. |
| 123 | unsigned AsmPrinter::GetSizeOfEncodedValue(unsigned Encoding) const { |
| 124 | if (Encoding == dwarf::DW_EH_PE_omit) |
| 125 | return 0; |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 126 | |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 127 | switch (Encoding & 0x07) { |
Eric Christopher | 596077b | 2013-12-04 22:26:43 +0000 | [diff] [blame] | 128 | default: |
| 129 | llvm_unreachable("Invalid encoded value."); |
| 130 | case dwarf::DW_EH_PE_absptr: |
| 131 | return TM.getDataLayout()->getPointerSize(); |
| 132 | case dwarf::DW_EH_PE_udata2: |
| 133 | return 2; |
| 134 | case dwarf::DW_EH_PE_udata4: |
| 135 | return 4; |
| 136 | case dwarf::DW_EH_PE_udata8: |
| 137 | return 8; |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 138 | } |
| 139 | } |
| 140 | |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 141 | void AsmPrinter::EmitTTypeReference(const GlobalValue *GV, |
| 142 | unsigned Encoding) const { |
Anton Korobeynikov | 097b0e9 | 2012-11-19 21:17:20 +0000 | [diff] [blame] | 143 | if (GV) { |
| 144 | const TargetLoweringObjectFile &TLOF = getObjFileLowering(); |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 145 | |
Anton Korobeynikov | 097b0e9 | 2012-11-19 21:17:20 +0000 | [diff] [blame] | 146 | const MCExpr *Exp = |
Rafael Espindola | daeafb4 | 2014-02-19 17:23:20 +0000 | [diff] [blame] | 147 | TLOF.getTTypeGlobalReference(GV, Encoding, *Mang, TM, MMI, OutStreamer); |
Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 148 | OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding)); |
Anton Korobeynikov | 097b0e9 | 2012-11-19 21:17:20 +0000 | [diff] [blame] | 149 | } else |
Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 150 | OutStreamer.EmitIntValue(0, GetSizeOfEncodedValue(Encoding)); |
Chris Lattner | e619c0d | 2010-04-04 20:20:50 +0000 | [diff] [blame] | 151 | } |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 152 | |
| 153 | /// EmitSectionOffset - Emit the 4-byte offset of Label from the start of its |
| 154 | /// section. This can be done with a special directive if the target supports |
| 155 | /// it (e.g. cygwin) or by emitting it as an offset from a label at the start |
| 156 | /// of the section. |
| 157 | /// |
| 158 | /// SectionLabel is a temporary label emitted at the start of the section that |
| 159 | /// Label lives in. |
| 160 | void AsmPrinter::EmitSectionOffset(const MCSymbol *Label, |
| 161 | const MCSymbol *SectionLabel) const { |
| 162 | // On COFF targets, we have to emit the special .secrel32 directive. |
Matt Arsenault | 034ca0f | 2013-04-22 22:49:11 +0000 | [diff] [blame] | 163 | if (MAI->needsDwarfSectionOffsetDirective()) { |
Rafael Espindola | d3df3d3 | 2011-12-17 01:14:52 +0000 | [diff] [blame] | 164 | OutStreamer.EmitCOFFSecRel32(Label); |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 165 | return; |
| 166 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 167 | |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 168 | // Get the section that we're referring to, based on SectionLabel. |
| 169 | const MCSection &Section = SectionLabel->getSection(); |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 170 | |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 171 | // If Label has already been emitted, verify that it is in the same section as |
| 172 | // section label for sanity. |
| 173 | assert((!Label->isInSection() || &Label->getSection() == &Section) && |
| 174 | "Section offset using wrong section base for label"); |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 175 | |
Duncan Sands | b847bf5 | 2011-03-12 13:07:37 +0000 | [diff] [blame] | 176 | // If the section in question will end up with an address of 0 anyway, we can |
| 177 | // just emit an absolute reference to save a relocation. |
| 178 | if (Section.isBaseAddressKnownZero()) { |
Eric Christopher | ce0cfce | 2013-01-09 01:35:34 +0000 | [diff] [blame] | 179 | OutStreamer.EmitSymbolValue(Label, 4); |
Duncan Sands | b847bf5 | 2011-03-12 13:07:37 +0000 | [diff] [blame] | 180 | return; |
| 181 | } |
Eric Christopher | 1d6bd41 | 2012-11-20 20:34:47 +0000 | [diff] [blame] | 182 | |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 183 | // Otherwise, emit it as a label difference from the start of the section. |
| 184 | EmitLabelDifference(Label, SectionLabel, 4); |
| 185 | } |
| 186 | |
Eric Christopher | 698a8ab | 2014-03-07 01:44:14 +0000 | [diff] [blame^] | 187 | |
| 188 | /// Emit a dwarf register operation. |
| 189 | static void emitDwarfRegOp(const AsmPrinter &AP, int Reg) { |
| 190 | assert(Reg >= 0); |
| 191 | if (Reg < 32) { |
| 192 | AP.OutStreamer.AddComment( |
| 193 | dwarf::OperationEncodingString(dwarf::DW_OP_reg0 + Reg)); |
| 194 | AP.EmitInt8(dwarf::DW_OP_reg0 + Reg); |
| 195 | } else { |
| 196 | AP.OutStreamer.AddComment("DW_OP_regx"); |
| 197 | AP.EmitInt8(dwarf::DW_OP_regx); |
| 198 | AP.OutStreamer.AddComment(Twine(Reg)); |
| 199 | AP.EmitULEB128(Reg); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /// Emit an (double-)indirect dwarf register operation. |
| 204 | static void emitDwarfRegOpIndirect(const AsmPrinter &AP, |
| 205 | int Reg, int Offset, bool Deref) { |
| 206 | assert(Reg >= 0); |
| 207 | if (Reg < 32) { |
| 208 | AP.OutStreamer.AddComment( |
| 209 | dwarf::OperationEncodingString(dwarf::DW_OP_breg0 + Reg)); |
| 210 | AP.EmitInt8(dwarf::DW_OP_breg0 + Reg); |
| 211 | } else { |
| 212 | AP.OutStreamer.AddComment("DW_OP_bregx"); |
| 213 | AP.EmitInt8(dwarf::DW_OP_bregx); |
| 214 | AP.OutStreamer.AddComment(Twine(Reg)); |
| 215 | AP.EmitULEB128(Reg); |
| 216 | } |
| 217 | AP.EmitSLEB128(Offset); |
| 218 | if (Deref) |
| 219 | AP.EmitInt8(dwarf::DW_OP_deref); |
| 220 | } |
| 221 | |
| 222 | /// Emit a dwarf register operation for describing |
| 223 | /// - a small value occupying only part of a register or |
| 224 | /// - a small register representing only part of a value. |
| 225 | static void emitDwarfOpPiece(const AsmPrinter &AP, |
| 226 | unsigned Size, unsigned Offset) { |
| 227 | assert(Size > 0); |
| 228 | if (Offset > 0) { |
| 229 | AP.OutStreamer.AddComment("DW_OP_bit_piece"); |
| 230 | AP.EmitInt8(dwarf::DW_OP_bit_piece); |
| 231 | AP.OutStreamer.AddComment(Twine(Size)); |
| 232 | AP.EmitULEB128(Size); |
| 233 | AP.OutStreamer.AddComment(Twine(Offset)); |
| 234 | AP.EmitULEB128(Offset); |
| 235 | } else { |
| 236 | AP.OutStreamer.AddComment("DW_OP_piece"); |
| 237 | AP.EmitInt8(dwarf::DW_OP_piece); |
| 238 | unsigned ByteSize = Size / 8; // Assuming 8 bits per byte. |
| 239 | AP.OutStreamer.AddComment(Twine(ByteSize)); |
| 240 | AP.EmitULEB128(ByteSize); |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /// Some targets do not provide a DWARF register number for every |
| 245 | /// register. This function attempts to emit a dwarf register by |
| 246 | /// emitting a piece of a super-register or by piecing together |
| 247 | /// multiple subregisters that alias the register. |
| 248 | static void EmitDwarfRegOpPiece(const AsmPrinter &AP, |
| 249 | const MachineLocation &MLoc) { |
| 250 | assert(!MLoc.isIndirect()); |
| 251 | const TargetRegisterInfo *TRI = AP.TM.getRegisterInfo(); |
| 252 | int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false); |
| 253 | |
| 254 | // Walk up the super-register chain until we find a valid number. |
| 255 | // For example, EAX on x86_64 is a 32-bit piece of RAX with offset 0. |
| 256 | for (MCSuperRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) { |
| 257 | Reg = TRI->getDwarfRegNum(*SR, false); |
| 258 | if (Reg >= 0) { |
| 259 | unsigned Idx = TRI->getSubRegIndex(*SR, MLoc.getReg()); |
| 260 | unsigned Size = TRI->getSubRegIdxSize(Idx); |
| 261 | unsigned Offset = TRI->getSubRegIdxOffset(Idx); |
| 262 | AP.OutStreamer.AddComment("super-register"); |
| 263 | emitDwarfRegOp(AP, Reg); |
| 264 | emitDwarfOpPiece(AP, Size, Offset); |
| 265 | return; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | // Otherwise, attempt to find a covering set of sub-register numbers. |
| 270 | // For example, Q0 on ARM is a composition of D0+D1. |
| 271 | // |
| 272 | // Keep track of the current position so we can emit the more |
| 273 | // efficient DW_OP_piece. |
| 274 | unsigned CurPos = 0; |
| 275 | // The size of the register in bits, assuming 8 bits per byte. |
| 276 | unsigned RegSize = TRI->getMinimalPhysRegClass(MLoc.getReg())->getSize()*8; |
| 277 | // Keep track of the bits in the register we already emitted, so we |
| 278 | // can avoid emitting redundant aliasing subregs. |
| 279 | SmallBitVector Coverage(RegSize, false); |
| 280 | for (MCSubRegIterator SR(MLoc.getReg(), TRI); SR.isValid(); ++SR) { |
| 281 | unsigned Idx = TRI->getSubRegIndex(MLoc.getReg(), *SR); |
| 282 | unsigned Size = TRI->getSubRegIdxSize(Idx); |
| 283 | unsigned Offset = TRI->getSubRegIdxOffset(Idx); |
| 284 | Reg = TRI->getDwarfRegNum(*SR, false); |
| 285 | |
| 286 | // Intersection between the bits we already emitted and the bits |
| 287 | // covered by this subregister. |
| 288 | SmallBitVector Intersection(RegSize, false); |
| 289 | Intersection.set(Offset, Offset+Size); |
| 290 | Intersection ^= Coverage; |
| 291 | |
| 292 | // If this sub-register has a DWARF number and we haven't covered |
| 293 | // its range, emit a DWARF piece for it. |
| 294 | if (Reg >= 0 && Intersection.any()) { |
| 295 | AP.OutStreamer.AddComment("sub-register"); |
| 296 | emitDwarfRegOp(AP, Reg); |
| 297 | emitDwarfOpPiece(AP, Size, Offset == CurPos ? 0 : Offset); |
| 298 | CurPos = Offset+Size; |
| 299 | |
| 300 | // Mark it as emitted. |
| 301 | Coverage.set(Offset, Offset+Size); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | if (CurPos == 0) { |
| 306 | // FIXME: We have no reasonable way of handling errors in here. |
| 307 | AP.OutStreamer.AddComment("nop (could not find a dwarf register number)"); |
| 308 | AP.EmitInt8(dwarf::DW_OP_nop); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /// EmitDwarfRegOp - Emit dwarf register operation. |
| 313 | void AsmPrinter::EmitDwarfRegOp(const MachineLocation &MLoc, |
| 314 | bool Indirect) const { |
| 315 | const TargetRegisterInfo *TRI = TM.getRegisterInfo(); |
| 316 | int Reg = TRI->getDwarfRegNum(MLoc.getReg(), false); |
| 317 | if (Reg < 0) { |
| 318 | // We assume that pointers are always in an addressable register. |
| 319 | if (Indirect || MLoc.isIndirect()) { |
| 320 | // FIXME: We have no reasonable way of handling errors in here. The |
| 321 | // caller might be in the middle of a dwarf expression. We should |
| 322 | // probably assert that Reg >= 0 once debug info generation is more |
| 323 | // mature. |
| 324 | OutStreamer.AddComment( |
| 325 | "nop (invalid dwarf register number for indirect loc)"); |
| 326 | EmitInt8(dwarf::DW_OP_nop); |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | // Attempt to find a valid super- or sub-register. |
| 331 | if (!Indirect && !MLoc.isIndirect()) |
| 332 | return EmitDwarfRegOpPiece(*this, MLoc); |
| 333 | } |
| 334 | |
| 335 | if (MLoc.isIndirect()) |
| 336 | emitDwarfRegOpIndirect(*this, Reg, MLoc.getOffset(), Indirect); |
| 337 | else if (Indirect) |
| 338 | emitDwarfRegOpIndirect(*this, Reg, 0, false); |
| 339 | else |
| 340 | emitDwarfRegOp(*this, Reg); |
| 341 | } |
| 342 | |
Chris Lattner | aabc604 | 2010-04-04 23:41:46 +0000 | [diff] [blame] | 343 | //===----------------------------------------------------------------------===// |
| 344 | // Dwarf Lowering Routines |
| 345 | //===----------------------------------------------------------------------===// |
Chris Lattner | 70a4fce | 2010-04-04 23:25:33 +0000 | [diff] [blame] | 346 | |
Rafael Espindola | 227144c | 2013-05-13 01:16:13 +0000 | [diff] [blame] | 347 | void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const { |
| 348 | switch (Inst.getOperation()) { |
| 349 | default: |
| 350 | llvm_unreachable("Unexpected instruction"); |
| 351 | case MCCFIInstruction::OpDefCfaOffset: |
| 352 | OutStreamer.EmitCFIDefCfaOffset(Inst.getOffset()); |
| 353 | break; |
| 354 | case MCCFIInstruction::OpDefCfa: |
| 355 | OutStreamer.EmitCFIDefCfa(Inst.getRegister(), Inst.getOffset()); |
| 356 | break; |
| 357 | case MCCFIInstruction::OpDefCfaRegister: |
| 358 | OutStreamer.EmitCFIDefCfaRegister(Inst.getRegister()); |
| 359 | break; |
| 360 | case MCCFIInstruction::OpOffset: |
| 361 | OutStreamer.EmitCFIOffset(Inst.getRegister(), Inst.getOffset()); |
| 362 | break; |
Venkatraman Govindaraju | 4c0cdd7 | 2013-09-26 15:11:00 +0000 | [diff] [blame] | 363 | case MCCFIInstruction::OpRegister: |
| 364 | OutStreamer.EmitCFIRegister(Inst.getRegister(), Inst.getRegister2()); |
| 365 | break; |
Venkatraman Govindaraju | 3816d43 | 2013-09-26 14:49:40 +0000 | [diff] [blame] | 366 | case MCCFIInstruction::OpWindowSave: |
| 367 | OutStreamer.EmitCFIWindowSave(); |
| 368 | break; |
Rafael Espindola | beb74c3 | 2011-04-15 20:32:03 +0000 | [diff] [blame] | 369 | } |
| 370 | } |