blob: 04de225a4007929785b42b115aa68f7b5dd1d40b [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";
Chris Lattner4e0f25b2009-06-19 00:08:39 +000058 // FIXME: Why don't we always use this section?
59 if (is64Bit)
Anton Korobeynikov64818732008-09-24 22:18:54 +000060 SixteenByteConstantSection = getUnnamedSection("\t.literal16\n",
Chris Lattner5fe575f2009-07-27 05:32:16 +000061 SectionKind::MergeableConst16);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000062 LCOMMDirective = "\t.lcomm\t";
Bill Wendlingb6be1392009-07-13 18:48:39 +000063
Anton Korobeynikov16b7f512008-08-08 18:25:52 +000064 // Leopard and above support aligned common symbols.
65 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000066 HasDotTypeDotSizeDirective = false;
Daniel Dunbarf6ccee52009-07-24 08:24:36 +000067
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000068 if (is64Bit) {
69 PersonalityPrefix = "";
70 PersonalitySuffix = "+4@GOTPCREL";
71 } else {
72 PersonalityPrefix = "L";
73 PersonalitySuffix = "$non_lazy_ptr";
74 }
Bill Wendlingb6be1392009-07-13 18:48:39 +000075
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000076 InlineAsmStart = "## InlineAsm Start";
77 InlineAsmEnd = "## InlineAsm End";
78 CommentString = "##";
79 SetDirective = "\t.set";
80 PCSymbol = ".";
81 UsedDirective = "\t.no_dead_strip\t";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000082 ProtectedDirective = "\t.globl\t";
83
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000084 SupportsDebugInformation = true;
Devang Patel0f7fef32009-04-13 17:02:03 +000085 DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
86 DwarfUsesInlineInfoSection = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000087
88 // Exceptions handling
89 SupportsExceptionHandling = true;
90 GlobalEHDirective = "\t.globl\t";
91 SupportsWeakOmittedEHFrame = false;
92 AbsoluteEHSectionOffsets = false;
93 DwarfEHFrameSection =
94 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
Bill Wendlingdb425492009-07-13 20:27:41 +000095 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +000096}
97
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +000098unsigned
99X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
100 bool Global) const {
101 if (Reason == DwarfEncoding::Functions && Global)
102 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
103 else if (Reason == DwarfEncoding::CodeLabels || !Global)
104 return DW_EH_PE_pcrel;
105 else
106 return DW_EH_PE_absptr;
107}
108
Rafael Espindola2f6fea92008-12-19 10:55:56 +0000109const char *
110X86DarwinTargetAsmInfo::getEHGlobalPrefix() const
111{
112 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
113 if (Subtarget->getDarwinVers() > 9)
114 return PrivateGlobalPrefix;
115 else
116 return "";
117}
118
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000119X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000120 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000121
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000122 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000123 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
Chris Lattner5fe575f2009-07-27 05:32:16 +0000131 BSSSection_ = getUnnamedSection("\t.bss", SectionKind::BSS);
Chris Lattner0fcf4dc2009-07-26 19:23:28 +0000132
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000133 // Debug Information
134 AbsoluteDebugSectionOffsets = true;
135 SupportsDebugInformation = true;
136 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
137 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
138 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
139 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
140 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
141 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
142 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
143 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
144 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
145 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000146 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000147
148 // Exceptions handling
Anton Korobeynikovc4da15a2008-09-08 21:13:08 +0000149 SupportsExceptionHandling = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000150 AbsoluteEHSectionOffsets = false;
151 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
152 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
153
154 // On Linux we must declare when we can use a non-executable stack.
Dan Gohman8f092252008-11-03 18:22:42 +0000155 if (TM.getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000156 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
157}
158
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000159unsigned
160X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
161 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000162 CodeModel::Model CM = TM.getCodeModel();
163 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000164
Dan Gohman8f092252008-11-03 18:22:42 +0000165 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000166 unsigned Format = 0;
167
168 if (!is64Bit)
169 // 32 bit targets always encode pointers as 4 bytes
170 Format = DW_EH_PE_sdata4;
171 else {
172 // 64 bit targets encode pointers in 4 bytes iff:
173 // - code model is small OR
174 // - code model is medium and we're emitting externally visible symbols
175 // or any code symbols
176 if (CM == CodeModel::Small ||
177 (CM == CodeModel::Medium && (Global ||
178 Reason != DwarfEncoding::Data)))
179 Format = DW_EH_PE_sdata4;
180 else
181 Format = DW_EH_PE_sdata8;
182 }
183
184 if (Global)
185 Format |= DW_EH_PE_indirect;
186
187 return (Format | DW_EH_PE_pcrel);
188 } else {
189 if (is64Bit &&
190 (CM == CodeModel::Small ||
191 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
192 return DW_EH_PE_udata4;
193 else
194 return DW_EH_PE_absptr;
195 }
196}
197
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000198X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000199 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000200
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000201 GlobalPrefix = "_";
202 LCOMMDirective = "\t.lcomm\t";
203 COMMDirectiveTakesAlignment = false;
204 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000205 HasSingleParameterDotFile = false;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000206 StaticCtorsSection = "\t.section .ctors,\"aw\"";
207 StaticDtorsSection = "\t.section .dtors,\"aw\"";
208 HiddenDirective = NULL;
209 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
210 WeakRefDirective = "\t.weak\t";
211 SetDirective = "\t.set\t";
212
213 // Set up DWARF directives
214 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
215 AbsoluteDebugSectionOffsets = true;
216 AbsoluteEHSectionOffsets = false;
217 SupportsDebugInformation = true;
218 DwarfSectionOffsetDirective = "\t.secrel32\t";
219 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
220 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
221 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
222 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
223 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
224 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
225 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
226 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
227 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
228 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000229 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000230}
231
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000232unsigned
233X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
234 bool Global) const {
Dan Gohman8f092252008-11-03 18:22:42 +0000235 CodeModel::Model CM = TM.getCodeModel();
236 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000237
Dan Gohman8f092252008-11-03 18:22:42 +0000238 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000239 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000240
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000241 if (!is64Bit)
242 // 32 bit targets always encode pointers as 4 bytes
243 Format = DW_EH_PE_sdata4;
244 else {
245 // 64 bit targets encode pointers in 4 bytes iff:
246 // - code model is small OR
247 // - code model is medium and we're emitting externally visible symbols
248 // or any code symbols
249 if (CM == CodeModel::Small ||
250 (CM == CodeModel::Medium && (Global ||
251 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000252 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000253 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000254 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000255 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000256
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000257 if (Global)
258 Format |= DW_EH_PE_indirect;
259
260 return (Format | DW_EH_PE_pcrel);
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000261 }
Chris Lattner55acc682009-07-24 04:49:34 +0000262
263 if (is64Bit &&
264 (CM == CodeModel::Small ||
265 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
266 return DW_EH_PE_udata4;
267 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000268}
269
Chris Lattner55acc682009-07-24 04:49:34 +0000270const char *X86COFFTargetAsmInfo::
Chris Lattner460d51e2009-07-25 23:21:55 +0000271getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
Chris Lattnere346e182009-07-26 05:44:20 +0000272 if (Kind.isText())
Chris Lattner460d51e2009-07-25 23:21:55 +0000273 return ".text$linkonce";
Chris Lattner2ceb60a2009-07-26 06:48:26 +0000274 if (Kind.isWriteable())
Chris Lattner460d51e2009-07-25 23:21:55 +0000275 return ".data$linkonce";
276 return ".rdata$linkonce";
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000277}
278
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000279
Chris Lattner5fe575f2009-07-27 05:32:16 +0000280
281void X86COFFTargetAsmInfo::getSectionFlagsAsString(SectionKind Kind,
282 SmallVectorImpl<char> &Str) const {
Chris Lattnerf40761d2009-07-26 07:33:58 +0000283 // FIXME: Inefficient.
284 std::string Res = ",\"";
Chris Lattner5fe575f2009-07-27 05:32:16 +0000285 if (Kind.isText())
Chris Lattnerf40761d2009-07-26 07:33:58 +0000286 Res += 'x';
Chris Lattner5fe575f2009-07-27 05:32:16 +0000287 if (Kind.isWriteable())
Chris Lattnerf40761d2009-07-26 07:33:58 +0000288 Res += 'w';
289 Res += "\"";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000290
Chris Lattnerf40761d2009-07-26 07:33:58 +0000291 Str.append(Res.begin(), Res.end());
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000292}
293
294X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000295 X86GenericTargetAsmInfo(TM) {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000296 GlobalPrefix = "_";
297 CommentString = ";";
298
Eli Friedmanaace4b12009-06-19 04:48:38 +0000299 InlineAsmStart = "; InlineAsm Start";
300 InlineAsmEnd = "; InlineAsm End";
301
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000302 PrivateGlobalPrefix = "$";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000303 AlignDirective = "\tALIGN\t";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000304 ZeroDirective = "\tdb\t";
305 ZeroDirectiveSuffix = " dup(0)";
306 AsciiDirective = "\tdb\t";
307 AscizDirective = 0;
308 Data8bitsDirective = "\tdb\t";
309 Data16bitsDirective = "\tdw\t";
310 Data32bitsDirective = "\tdd\t";
311 Data64bitsDirective = "\tdq\t";
312 HasDotTypeDotSizeDirective = false;
Rafael Espindola952b8392008-12-03 11:01:37 +0000313 HasSingleParameterDotFile = false;
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000314
Eli Friedmanaace4b12009-06-19 04:48:38 +0000315 AlignmentIsInBytes = true;
316
Chris Lattner5fe575f2009-07-27 05:32:16 +0000317 TextSection = getUnnamedSection("_text", SectionKind::Text);
318 DataSection = getUnnamedSection("_data", SectionKind::DataRel);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000319
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000320 JumpTableDataSection = NULL;
321 SwitchToSectionDirective = "";
Eli Friedmanaace4b12009-06-19 04:48:38 +0000322 TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
323 DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000324 SectionEndDirectiveSuffix = "\tends\n";
325}
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000326
Anton Korobeynikov6381a132008-10-05 08:53:29 +0000327// Instantiate default implementation.
328TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);