Move a few more APIs back to 2.5 forms. The only remaining ones left to change back are
[oota-llvm.git] / lib / Target / X86 / X86TargetAsmInfo.cpp
1 //===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===//
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 contains the declarations of the X86TargetAsmInfo properties.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "X86TargetAsmInfo.h"
15 #include "X86TargetMachine.h"
16 #include "X86Subtarget.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/InlineAsm.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/Intrinsics.h"
21 #include "llvm/Module.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/Support/Dwarf.h"
24 #include "llvm/Support/ErrorHandling.h"
25
26 using namespace llvm;
27 using namespace llvm::dwarf;
28
29 const char *const llvm::x86_asm_table[] = {
30   "{si}", "S",
31   "{di}", "D",
32   "{ax}", "a",
33   "{cx}", "c",
34   "{memory}", "memory",
35   "{flags}", "",
36   "{dirflag}", "",
37   "{fpsr}", "",
38   "{cc}", "cc",
39   0,0};
40
41 X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
42   X86TargetAsmInfo<DarwinTargetAsmInfo>(TM) {
43   const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
44   bool is64Bit = Subtarget->is64Bit();
45
46   AlignmentIsInBytes = false;
47   TextAlignFillValue = 0x90;
48
49
50   if (!is64Bit)
51     Data64bitsDirective = 0;       // we can't emit a 64-bit unit
52   ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
53   ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
54   if (TM.getRelocationModel() != Reloc::Static)
55     ConstantPoolSection = "\t.const_data";
56   else
57     ConstantPoolSection = "\t.const\n";
58   LCOMMDirective = "\t.lcomm\t";
59
60   // Leopard and above support aligned common symbols.
61   COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
62   HasDotTypeDotSizeDirective = false;
63
64   if (is64Bit) {
65     PersonalityPrefix = "";
66     PersonalitySuffix = "+4@GOTPCREL";
67   } else {
68     PersonalityPrefix = "L";
69     PersonalitySuffix = "$non_lazy_ptr";
70   }
71
72   InlineAsmStart = "## InlineAsm Start";
73   InlineAsmEnd = "## InlineAsm End";
74   CommentString = "##";
75   SetDirective = "\t.set";
76   PCSymbol = ".";
77   UsedDirective = "\t.no_dead_strip\t";
78   ProtectedDirective = "\t.globl\t";
79
80   SupportsDebugInformation = true;
81   DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
82   DwarfUsesInlineInfoSection = true;
83
84   // Exceptions handling
85   SupportsExceptionHandling = true;
86   GlobalEHDirective = "\t.globl\t";
87   SupportsWeakOmittedEHFrame = false;
88   AbsoluteEHSectionOffsets = false;
89   DwarfEHFrameSection =
90   ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
91   DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
92 }
93
94 unsigned
95 X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
96                                               bool Global) const {
97   const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
98
99   if (Subtarget->getDarwinVers() > 9) {
100     if ((Reason == DwarfEncoding::Data || Reason == DwarfEncoding::Functions)
101         && Global)
102       return DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4;
103
104     if (Reason == DwarfEncoding::CodeLabels || !Global)
105       return DW_EH_PE_pcrel;
106   }
107
108   return DW_EH_PE_absptr;
109 }
110
111 const char *
112 X86DarwinTargetAsmInfo::getEHGlobalPrefix() const {
113   const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
114   if (Subtarget->getDarwinVers() > 9)
115     return PrivateGlobalPrefix;
116   return "";
117 }
118
119 X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM) :
120   X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
121
122   CStringSection = ".rodata.str";
123   PrivateGlobalPrefix = ".L";
124   WeakRefDirective = "\t.weak\t";
125   SetDirective = "\t.set\t";
126   PCSymbol = ".";
127
128   // Set up DWARF directives
129   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
130
131   // Debug Information
132   AbsoluteDebugSectionOffsets = true;
133   SupportsDebugInformation = true;
134   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
135   DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";
136   DwarfLineSection =    "\t.section\t.debug_line,\"\",@progbits";
137   DwarfFrameSection =   "\t.section\t.debug_frame,\"\",@progbits";
138   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
139   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
140   DwarfStrSection =     "\t.section\t.debug_str,\"\",@progbits";
141   DwarfLocSection =     "\t.section\t.debug_loc,\"\",@progbits";
142   DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
143   DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",@progbits";
144   DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
145
146   // Exceptions handling
147   SupportsExceptionHandling = true;
148   AbsoluteEHSectionOffsets = false;
149   DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
150   DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
151
152   // On Linux we must declare when we can use a non-executable stack.
153   if (TM.getSubtarget<X86Subtarget>().isLinux())
154     NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
155 }
156
157 unsigned
158 X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
159                                            bool Global) const {
160   CodeModel::Model CM = TM.getCodeModel();
161   bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
162
163   if (TM.getRelocationModel() == Reloc::PIC_) {
164     unsigned Format = 0;
165
166     if (!is64Bit)
167       // 32 bit targets always encode pointers as 4 bytes
168       Format = DW_EH_PE_sdata4;
169     else {
170       // 64 bit targets encode pointers in 4 bytes iff:
171       // - code model is small OR
172       // - code model is medium and we're emitting externally visible symbols
173       //   or any code symbols
174       if (CM == CodeModel::Small ||
175           (CM == CodeModel::Medium && (Global ||
176                                        Reason != DwarfEncoding::Data)))
177         Format = DW_EH_PE_sdata4;
178       else
179         Format = DW_EH_PE_sdata8;
180     }
181
182     if (Global)
183       Format |= DW_EH_PE_indirect;
184
185     return (Format | DW_EH_PE_pcrel);
186   } else {
187     if (is64Bit &&
188         (CM == CodeModel::Small ||
189          (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
190       return DW_EH_PE_udata4;
191     else
192       return DW_EH_PE_absptr;
193   }
194 }
195
196
197 unsigned
198 X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
199                                             bool Global) const {
200   CodeModel::Model CM = TM.getCodeModel();
201   bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
202
203   if (TM.getRelocationModel() == Reloc::PIC_) {
204     unsigned Format = 0;
205
206     if (!is64Bit)
207       // 32 bit targets always encode pointers as 4 bytes
208       Format = DW_EH_PE_sdata4;
209     else {
210       // 64 bit targets encode pointers in 4 bytes iff:
211       // - code model is small OR
212       // - code model is medium and we're emitting externally visible symbols
213       //   or any code symbols
214       if (CM == CodeModel::Small ||
215           (CM == CodeModel::Medium && (Global ||
216                                        Reason != DwarfEncoding::Data)))
217         Format = DW_EH_PE_sdata4;
218       else
219         Format = DW_EH_PE_sdata8;
220     }
221
222     if (Global)
223       Format |= DW_EH_PE_indirect;
224
225     return (Format | DW_EH_PE_pcrel);
226   }
227   
228   if (is64Bit &&
229       (CM == CodeModel::Small ||
230        (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
231     return DW_EH_PE_udata4;
232   return DW_EH_PE_absptr;
233 }
234
235
236
237 X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
238   X86TargetAsmInfo<TargetAsmInfo>(TM) {
239   GlobalPrefix = "_";
240   CommentString = ";";
241
242   InlineAsmStart = "; InlineAsm Start";
243   InlineAsmEnd   = "; InlineAsm End";
244
245   PrivateGlobalPrefix = "$";
246   AlignDirective = "\tALIGN\t";
247   ZeroDirective = "\tdb\t";
248   ZeroDirectiveSuffix = " dup(0)";
249   AsciiDirective = "\tdb\t";
250   AscizDirective = 0;
251   Data8bitsDirective = "\tdb\t";
252   Data16bitsDirective = "\tdw\t";
253   Data32bitsDirective = "\tdd\t";
254   Data64bitsDirective = "\tdq\t";
255   HasDotTypeDotSizeDirective = false;
256   HasSingleParameterDotFile = false;
257
258   AlignmentIsInBytes = true;
259
260   JumpTableDataSection = NULL;
261   SwitchToSectionDirective = "";
262   TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
263   DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
264   SectionEndDirectiveSuffix = "\tends\n";
265 }
266
267 // Instantiate default implementation.
268 TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);