]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - opencl/llvm.git/blob - lib/CodeGen/AsmPrinter/AsmPrinterDwarf.cpp
Pass the Mangler by reference.
[opencl/llvm.git] / lib / CodeGen / AsmPrinter / AsmPrinterDwarf.cpp
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 //===----------------------------------------------------------------------===//
14 #define DEBUG_TYPE "asm-printer"
15 #include "llvm/CodeGen/AsmPrinter.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCSection.h"
20 #include "llvm/MC/MCStreamer.h"
21 #include "llvm/MC/MCSymbol.h"
22 #include "llvm/MC/MachineLocation.h"
23 #include "llvm/Support/Dwarf.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Target/TargetFrameLowering.h"
26 #include "llvm/Target/TargetLoweringObjectFile.h"
27 #include "llvm/Target/TargetMachine.h"
28 #include "llvm/Target/TargetRegisterInfo.h"
29 using namespace llvm;
31 //===----------------------------------------------------------------------===//
32 // Dwarf Emission Helper Routines
33 //===----------------------------------------------------------------------===//
35 /// EmitSLEB128 - emit the specified signed leb128 value.
36 void AsmPrinter::EmitSLEB128(int64_t Value, const char *Desc) const {
37   if (isVerbose() && Desc)
38     OutStreamer.AddComment(Desc);
40   OutStreamer.EmitSLEB128IntValue(Value);
41 }
43 /// EmitULEB128 - emit the specified signed leb128 value.
44 void AsmPrinter::EmitULEB128(uint64_t Value, const char *Desc,
45                              unsigned PadTo) const {
46   if (isVerbose() && Desc)
47     OutStreamer.AddComment(Desc);
49   OutStreamer.EmitULEB128IntValue(Value, PadTo);
50 }
52 /// EmitCFAByte - Emit a .byte 42 directive for a DW_CFA_xxx value.
53 void AsmPrinter::EmitCFAByte(unsigned Val) const {
54   if (isVerbose()) {
55     if (Val >= dwarf::DW_CFA_offset && Val < dwarf::DW_CFA_offset + 64)
56       OutStreamer.AddComment("DW_CFA_offset + Reg (" +
57                              Twine(Val - dwarf::DW_CFA_offset) + ")");
58     else
59       OutStreamer.AddComment(dwarf::CallFrameString(Val));
60   }
61   OutStreamer.EmitIntValue(Val, 1);
62 }
64 static const char *DecodeDWARFEncoding(unsigned Encoding) {
65   switch (Encoding) {
66   case dwarf::DW_EH_PE_absptr:
67     return "absptr";
68   case dwarf::DW_EH_PE_omit:
69     return "omit";
70   case dwarf::DW_EH_PE_pcrel:
71     return "pcrel";
72   case dwarf::DW_EH_PE_udata4:
73     return "udata4";
74   case dwarf::DW_EH_PE_udata8:
75     return "udata8";
76   case dwarf::DW_EH_PE_sdata4:
77     return "sdata4";
78   case dwarf::DW_EH_PE_sdata8:
79     return "sdata8";
80   case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4:
81     return "pcrel udata4";
82   case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4:
83     return "pcrel sdata4";
84   case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8:
85     return "pcrel udata8";
86   case dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8:
87     return "pcrel sdata8";
88   case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata4
89       :
90     return "indirect pcrel udata4";
91   case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4
92       :
93     return "indirect pcrel sdata4";
94   case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8
95       :
96     return "indirect pcrel udata8";
97   case dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata8
98       :
99     return "indirect pcrel sdata8";
100   }
102   return "<unknown encoding>";
105 /// EmitEncodingByte - Emit a .byte 42 directive that corresponds to an
106 /// encoding.  If verbose assembly output is enabled, we output comments
107 /// describing the encoding.  Desc is an optional string saying what the
108 /// encoding is specifying (e.g. "LSDA").
109 void AsmPrinter::EmitEncodingByte(unsigned Val, const char *Desc) const {
110   if (isVerbose()) {
111     if (Desc)
112       OutStreamer.AddComment(Twine(Desc) + " Encoding = " +
113                              Twine(DecodeDWARFEncoding(Val)));
114     else
115       OutStreamer.AddComment(Twine("Encoding = ") + DecodeDWARFEncoding(Val));
116   }
118   OutStreamer.EmitIntValue(Val, 1);
121 /// GetSizeOfEncodedValue - Return the size of the encoding in bytes.
122 unsigned AsmPrinter::GetSizeOfEncodedValue(unsigned Encoding) const {
123   if (Encoding == dwarf::DW_EH_PE_omit)
124     return 0;
126   switch (Encoding & 0x07) {
127   default:
128     llvm_unreachable("Invalid encoded value.");
129   case dwarf::DW_EH_PE_absptr:
130     return TM.getDataLayout()->getPointerSize();
131   case dwarf::DW_EH_PE_udata2:
132     return 2;
133   case dwarf::DW_EH_PE_udata4:
134     return 4;
135   case dwarf::DW_EH_PE_udata8:
136     return 8;
137   }
140 void AsmPrinter::EmitTTypeReference(const GlobalValue *GV,
141                                     unsigned Encoding) const {
142   if (GV) {
143     const TargetLoweringObjectFile &TLOF = getObjFileLowering();
145     const MCExpr *Exp =
146         TLOF.getTTypeGlobalReference(GV, *Mang, MMI, Encoding, OutStreamer);
147     OutStreamer.EmitValue(Exp, GetSizeOfEncodedValue(Encoding));
148   } else
149     OutStreamer.EmitIntValue(0, GetSizeOfEncodedValue(Encoding));
152 /// EmitSectionOffset - Emit the 4-byte offset of Label from the start of its
153 /// section.  This can be done with a special directive if the target supports
154 /// it (e.g. cygwin) or by emitting it as an offset from a label at the start
155 /// of the section.
156 ///
157 /// SectionLabel is a temporary label emitted at the start of the section that
158 /// Label lives in.
159 void AsmPrinter::EmitSectionOffset(const MCSymbol *Label,
160                                    const MCSymbol *SectionLabel) const {
161   // On COFF targets, we have to emit the special .secrel32 directive.
162   if (MAI->needsDwarfSectionOffsetDirective()) {
163     OutStreamer.EmitCOFFSecRel32(Label);
164     return;
165   }
167   // Get the section that we're referring to, based on SectionLabel.
168   const MCSection &Section = SectionLabel->getSection();
170   // If Label has already been emitted, verify that it is in the same section as
171   // section label for sanity.
172   assert((!Label->isInSection() || &Label->getSection() == &Section) &&
173          "Section offset using wrong section base for label");
175   // If the section in question will end up with an address of 0 anyway, we can
176   // just emit an absolute reference to save a relocation.
177   if (Section.isBaseAddressKnownZero()) {
178     OutStreamer.EmitSymbolValue(Label, 4);
179     return;
180   }
182   // Otherwise, emit it as a label difference from the start of the section.
183   EmitLabelDifference(Label, SectionLabel, 4);
186 //===----------------------------------------------------------------------===//
187 // Dwarf Lowering Routines
188 //===----------------------------------------------------------------------===//
190 void AsmPrinter::emitCFIInstruction(const MCCFIInstruction &Inst) const {
191   switch (Inst.getOperation()) {
192   default:
193     llvm_unreachable("Unexpected instruction");
194   case MCCFIInstruction::OpDefCfaOffset:
195     OutStreamer.EmitCFIDefCfaOffset(Inst.getOffset());
196     break;
197   case MCCFIInstruction::OpDefCfa:
198     OutStreamer.EmitCFIDefCfa(Inst.getRegister(), Inst.getOffset());
199     break;
200   case MCCFIInstruction::OpDefCfaRegister:
201     OutStreamer.EmitCFIDefCfaRegister(Inst.getRegister());
202     break;
203   case MCCFIInstruction::OpOffset:
204     OutStreamer.EmitCFIOffset(Inst.getRegister(), Inst.getOffset());
205     break;
206   case MCCFIInstruction::OpRegister:
207     OutStreamer.EmitCFIRegister(Inst.getRegister(), Inst.getRegister2());
208     break;
209   case MCCFIInstruction::OpWindowSave:
210     OutStreamer.EmitCFIWindowSave();
211     break;
212   }