blob: 94529ea8cebacdc23bb0db7b295c07f2e3b352ce [file] [log] [blame]
Jim Laskey8e8de8f2006-09-07 22:05:02 +00001//===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey8e8de8f2006-09-07 22:05:02 +00007//
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"
Reid Spencer7aa8a452007-01-12 23:22:14 +000017#include "llvm/DerivedTypes.h"
Chris Lattner625bd052006-11-29 01:14:06 +000018#include "llvm/InlineAsm.h"
19#include "llvm/Instructions.h"
Chris Lattner3e9f1d02007-04-01 20:49:36 +000020#include "llvm/Intrinsics.h"
Chris Lattner625bd052006-11-29 01:14:06 +000021#include "llvm/Module.h"
22#include "llvm/ADT/StringExtras.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000023#include "llvm/Support/Dwarf.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000024#include "llvm/Support/ErrorHandling.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000025
Jim Laskey8e8de8f2006-09-07 22:05:02 +000026using namespace llvm;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000027using namespace llvm::dwarf;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000028
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000029const 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};
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000040
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000041X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000042 X86TargetAsmInfo<DarwinTargetAsmInfo>(TM) {
Bill Wendlingb6be1392009-07-13 18:48:39 +000043 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000044 bool is64Bit = Subtarget->is64Bit();
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000045
46 AlignmentIsInBytes = false;
47 TextAlignFillValue = 0x90;
Daniel Dunbarf6ccee52009-07-24 08:24:36 +000048
49
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000050 if (!is64Bit)
51 Data64bitsDirective = 0; // we can't emit a 64-bit unit
52 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000053 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Dan Gohman8f092252008-11-03 18:22:42 +000054 if (TM.getRelocationModel() != Reloc::Static)
Anton Korobeynikov7705ea32008-07-09 21:54:26 +000055 ConstantPoolSection = "\t.const_data";
56 else
57 ConstantPoolSection = "\t.const\n";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000058 LCOMMDirective = "\t.lcomm\t";
Bill Wendlingb6be1392009-07-13 18:48:39 +000059
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000060 // Leopard and above support aligned common symbols.
61 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000062 HasDotTypeDotSizeDirective = false;
Daniel Dunbarf6ccee52009-07-24 08:24:36 +000063
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000064 if (is64Bit) {
65 PersonalityPrefix = "";
66 PersonalitySuffix = "+4@GOTPCREL";
67 } else {
68 PersonalityPrefix = "L";
69 PersonalitySuffix = "$non_lazy_ptr";
70 }
Bill Wendlingb6be1392009-07-13 18:48:39 +000071
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000072 InlineAsmStart = "## InlineAsm Start";
73 InlineAsmEnd = "## InlineAsm End";
74 CommentString = "##";
75 SetDirective = "\t.set";
76 PCSymbol = ".";
77 UsedDirective = "\t.no_dead_strip\t";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000078 ProtectedDirective = "\t.globl\t";
79
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000080 SupportsDebugInformation = true;
Devang Patel0f7fef32009-04-13 17:02:03 +000081 DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
82 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000083
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";
Bill Wendlingdb425492009-07-13 20:27:41 +000091 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000092}
93
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +000094unsigned
95X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
96 bool Global) const {
97 if (Reason == DwarfEncoding::Functions && Global)
98 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
Chris Lattnere3466942009-07-27 06:17:14 +000099 if (Reason == DwarfEncoding::CodeLabels || !Global)
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000100 return DW_EH_PE_pcrel;
Chris Lattnere3466942009-07-27 06:17:14 +0000101 return DW_EH_PE_absptr;
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000102}
103
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000104const char *
Chris Lattnere3466942009-07-27 06:17:14 +0000105X86DarwinTargetAsmInfo::getEHGlobalPrefix() const {
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000106 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
107 if (Subtarget->getDarwinVers() > 9)
108 return PrivateGlobalPrefix;
Chris Lattnere3466942009-07-27 06:17:14 +0000109 return "";
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000110}
111
Chris Lattnere3466942009-07-27 06:17:14 +0000112X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM) :
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000113 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000114
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000115 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000116 PrivateGlobalPrefix = ".L";
117 WeakRefDirective = "\t.weak\t";
118 SetDirective = "\t.set\t";
119 PCSymbol = ".";
120
121 // Set up DWARF directives
122 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
123
Chris Lattnere3466942009-07-27 06:17:14 +0000124 BSSSection_ = getOrCreateSection("\t.bss", true, SectionKind::BSS);
Chris Lattner0fcf4dc2009-07-26 19:23:28 +0000125
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000126 // Debug Information
127 AbsoluteDebugSectionOffsets = true;
128 SupportsDebugInformation = true;
129 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
130 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
131 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
132 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
133 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
134 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
135 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
136 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
137 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
138 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000139 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000140
141 // Exceptions handling
Anton Korobeynikovc4da15a2008-09-08 21:13:08 +0000142 SupportsExceptionHandling = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000143 AbsoluteEHSectionOffsets = false;
144 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
145 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
146
147 // On Linux we must declare when we can use a non-executable stack.
Dan Gohman8f092252008-11-03 18:22:42 +0000148 if (TM.getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000149 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
150}
151
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000152unsigned
153X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
154 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000155 CodeModel::Model CM = TM.getCodeModel();
156 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000157
Dan Gohman8f092252008-11-03 18:22:42 +0000158 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000159 unsigned Format = 0;
160
161 if (!is64Bit)
162 // 32 bit targets always encode pointers as 4 bytes
163 Format = DW_EH_PE_sdata4;
164 else {
165 // 64 bit targets encode pointers in 4 bytes iff:
166 // - code model is small OR
167 // - code model is medium and we're emitting externally visible symbols
168 // or any code symbols
169 if (CM == CodeModel::Small ||
170 (CM == CodeModel::Medium && (Global ||
171 Reason != DwarfEncoding::Data)))
172 Format = DW_EH_PE_sdata4;
173 else
174 Format = DW_EH_PE_sdata8;
175 }
176
177 if (Global)
178 Format |= DW_EH_PE_indirect;
179
180 return (Format | DW_EH_PE_pcrel);
181 } else {
182 if (is64Bit &&
183 (CM == CodeModel::Small ||
184 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
185 return DW_EH_PE_udata4;
186 else
187 return DW_EH_PE_absptr;
188 }
189}
190
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000191X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000192 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000193
Chris Lattner20886cf2009-07-27 16:22:39 +0000194 TextSection = getOrCreateSection("_text", true, SectionKind::Text);
195 DataSection = getOrCreateSection("_data", true, SectionKind::DataRel);
196
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000197 GlobalPrefix = "_";
198 LCOMMDirective = "\t.lcomm\t";
199 COMMDirectiveTakesAlignment = false;
200 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000201 HasSingleParameterDotFile = false;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000202 StaticCtorsSection = "\t.section .ctors,\"aw\"";
203 StaticDtorsSection = "\t.section .dtors,\"aw\"";
204 HiddenDirective = NULL;
205 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
206 WeakRefDirective = "\t.weak\t";
207 SetDirective = "\t.set\t";
208
209 // Set up DWARF directives
210 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
211 AbsoluteDebugSectionOffsets = true;
212 AbsoluteEHSectionOffsets = false;
213 SupportsDebugInformation = true;
214 DwarfSectionOffsetDirective = "\t.secrel32\t";
215 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
216 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
217 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
218 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
219 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
220 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
221 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
222 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
223 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
224 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000225 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000226}
227
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000228unsigned
229X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
230 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000231 CodeModel::Model CM = TM.getCodeModel();
232 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000233
Dan Gohman8f092252008-11-03 18:22:42 +0000234 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000235 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000236
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000237 if (!is64Bit)
238 // 32 bit targets always encode pointers as 4 bytes
239 Format = DW_EH_PE_sdata4;
240 else {
241 // 64 bit targets encode pointers in 4 bytes iff:
242 // - code model is small OR
243 // - code model is medium and we're emitting externally visible symbols
244 // or any code symbols
245 if (CM == CodeModel::Small ||
246 (CM == CodeModel::Medium && (Global ||
247 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000248 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000249 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000250 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000251 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000252
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000253 if (Global)
254 Format |= DW_EH_PE_indirect;
255
256 return (Format | DW_EH_PE_pcrel);
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000257 }
Chris Lattner55acc682009-07-24 04:49:34 +0000258
259 if (is64Bit &&
260 (CM == CodeModel::Small ||
261 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
262 return DW_EH_PE_udata4;
263 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000264}
265
Chris Lattner55acc682009-07-24 04:49:34 +0000266const char *X86COFFTargetAsmInfo::
Chris Lattner460d51e2009-07-25 23:21:55 +0000267getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
Chris Lattnere346e182009-07-26 05:44:20 +0000268 if (Kind.isText())
Chris Lattner460d51e2009-07-25 23:21:55 +0000269 return ".text$linkonce";
Chris Lattner2ceb60a2009-07-26 06:48:26 +0000270 if (Kind.isWriteable())
Chris Lattner460d51e2009-07-25 23:21:55 +0000271 return ".data$linkonce";
272 return ".rdata$linkonce";
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000273}
274
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000275
Chris Lattner5fe575f2009-07-27 05:32:16 +0000276
277void X86COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
278 SmallVectorImpl<char> &Str) const {
Chris Lattnerf40761d2009-07-26 07:33:58 +0000279 // FIXME: Inefficient.
280 std::string Res = ",\"";
Chris Lattner5fe575f2009-07-27 05:32:16 +0000281 if (Kind.isText())
Chris Lattnerf40761d2009-07-26 07:33:58 +0000282 Res += 'x';
Chris Lattner5fe575f2009-07-27 05:32:16 +0000283 if (Kind.isWriteable())
Chris Lattnerf40761d2009-07-26 07:33:58 +0000284 Res += 'w';
285 Res += "\"";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000286
Chris Lattnerf40761d2009-07-26 07:33:58 +0000287 Str.append(Res.begin(), Res.end());
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000288}
289
290X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000291 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000292 GlobalPrefix = "_";
293 CommentString = ";";
294
Eli Friedmanaace4b12009-06-19 04:48:38 +0000295 InlineAsmStart = "; InlineAsm Start";
296 InlineAsmEnd = "; InlineAsm End";
297
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000298 PrivateGlobalPrefix = "$";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000299 AlignDirective = "\tALIGN\t";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000300 ZeroDirective = "\tdb\t";
301 ZeroDirectiveSuffix = " dup(0)";
302 AsciiDirective = "\tdb\t";
303 AscizDirective = 0;
304 Data8bitsDirective = "\tdb\t";
305 Data16bitsDirective = "\tdw\t";
306 Data32bitsDirective = "\tdd\t";
307 Data64bitsDirective = "\tdq\t";
308 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000309 HasSingleParameterDotFile = false;
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000310
Eli Friedmanaace4b12009-06-19 04:48:38 +0000311 AlignmentIsInBytes = true;
312
Chris Lattnere3466942009-07-27 06:17:14 +0000313 TextSection = getOrCreateSection("_text", true, SectionKind::Text);
314 DataSection = getOrCreateSection("_data", true, SectionKind::DataRel);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000315
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000316 JumpTableDataSection = NULL;
317 SwitchToSectionDirective = "";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000318 TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
319 DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000320 SectionEndDirectiveSuffix = "\tends\n";
321}
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000322
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000323// Instantiate default implementation.
324TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);