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