X86 floating-point passes don't modify the CFG.
[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 X86DarwinTargetAsmInfo::PreferredEHDataFormat() const {
95   const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
96   if (Subtarget->getDarwinVers() > 9)
97     return DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4;
98
99   return DW_EH_PE_absptr;
100 }
101
102 const char *
103 X86DarwinTargetAsmInfo::getEHGlobalPrefix() const {
104   const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
105   if (Subtarget->getDarwinVers() > 9)
106     return PrivateGlobalPrefix;
107   return "";
108 }
109
110 X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM) :
111   X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
112
113   CStringSection = ".rodata.str";
114   PrivateGlobalPrefix = ".L";
115   WeakRefDirective = "\t.weak\t";
116   SetDirective = "\t.set\t";
117   PCSymbol = ".";
118
119   // Set up DWARF directives
120   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
121
122   // Debug Information
123   AbsoluteDebugSectionOffsets = true;
124   SupportsDebugInformation = true;
125   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
126   DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";
127   DwarfLineSection =    "\t.section\t.debug_line,\"\",@progbits";
128   DwarfFrameSection =   "\t.section\t.debug_frame,\"\",@progbits";
129   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
130   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
131   DwarfStrSection =     "\t.section\t.debug_str,\"\",@progbits";
132   DwarfLocSection =     "\t.section\t.debug_loc,\"\",@progbits";
133   DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
134   DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",@progbits";
135   DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
136
137   // Exceptions handling
138   SupportsExceptionHandling = true;
139   AbsoluteEHSectionOffsets = false;
140   DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
141   DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
142
143   // On Linux we must declare when we can use a non-executable stack.
144   if (TM.getSubtarget<X86Subtarget>().isLinux())
145     NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
146 }
147
148 unsigned
149 X86ELFTargetAsmInfo::PreferredEHDataFormat() const {
150   CodeModel::Model CM = TM.getCodeModel();
151   bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
152
153   if (TM.getRelocationModel() == Reloc::PIC_) {
154     unsigned Format = 0;
155
156     if (!is64Bit)
157       // 32 bit targets always encode pointers as 4 bytes
158       Format = DW_EH_PE_sdata4;
159     else {
160       // 64 bit targets encode pointers in 4 bytes iff:
161       // - code model is small OR
162       // - code model is medium and we're emitting externally visible symbols
163       //   or any code symbols
164       if (CM == CodeModel::Small || CM == CodeModel::Medium)
165         Format = DW_EH_PE_sdata4;
166       else
167         Format = DW_EH_PE_sdata8;
168     }
169
170     Format |= DW_EH_PE_indirect;
171     return (Format | DW_EH_PE_pcrel);
172   }
173   
174   if (is64Bit && CM == CodeModel::Small)
175     return DW_EH_PE_udata4;
176   return DW_EH_PE_absptr;
177 }
178
179
180 unsigned
181 X86COFFTargetAsmInfo::PreferredEHDataFormat() const {
182   CodeModel::Model CM = TM.getCodeModel();
183   bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
184
185   if (TM.getRelocationModel() == Reloc::PIC_) {
186     unsigned Format = 0;
187
188     if (!is64Bit)
189       // 32 bit targets always encode pointers as 4 bytes
190       Format = DW_EH_PE_sdata4;
191     else {
192       // 64 bit targets encode pointers in 4 bytes iff:
193       // - code model is small OR
194       // - code model is medium and we're emitting externally visible symbols
195       //   or any code symbols
196       if (CM == CodeModel::Small || CM == CodeModel::Medium)
197         Format = DW_EH_PE_sdata4;
198       else
199         Format = DW_EH_PE_sdata8;
200     }
201
202     Format |= DW_EH_PE_indirect;
203     return (Format | DW_EH_PE_pcrel);
204   }
205   
206   if (is64Bit && CM == CodeModel::Small)
207     return DW_EH_PE_udata4;
208   return DW_EH_PE_absptr;
209 }
210
211
212
213 X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
214   X86TargetAsmInfo<TargetAsmInfo>(TM) {
215   GlobalPrefix = "_";
216   CommentString = ";";
217
218   InlineAsmStart = "; InlineAsm Start";
219   InlineAsmEnd   = "; InlineAsm End";
220
221   PrivateGlobalPrefix = "$";
222   AlignDirective = "\tALIGN\t";
223   ZeroDirective = "\tdb\t";
224   ZeroDirectiveSuffix = " dup(0)";
225   AsciiDirective = "\tdb\t";
226   AscizDirective = 0;
227   Data8bitsDirective = "\tdb\t";
228   Data16bitsDirective = "\tdw\t";
229   Data32bitsDirective = "\tdd\t";
230   Data64bitsDirective = "\tdq\t";
231   HasDotTypeDotSizeDirective = false;
232   HasSingleParameterDotFile = false;
233
234   AlignmentIsInBytes = true;
235
236   JumpTableDataSection = NULL;
237   SwitchToSectionDirective = "";
238   TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
239   DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
240   SectionEndDirectiveSuffix = "\tends\n";
241 }
242
243 // Instantiate default implementation.
244 TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);