blob: 09adc433e74dd54483572d286b70defa73462e5d [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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"
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"
Anton Korobeynikov65c0d872008-02-27 23:33:50 +000023#include "llvm/Support/Dwarf.h"
Edwin Török675d5622009-07-11 20:10:48 +000024#include "llvm/Support/ErrorHandling.h"
Anton Korobeynikov65c0d872008-02-27 23:33:50 +000025
Dan Gohmanf17a25c2007-07-18 16:29:46 +000026using namespace llvm;
Anton Korobeynikov65c0d872008-02-27 23:33:50 +000027using namespace llvm::dwarf;
Dan Gohmanf17a25c2007-07-18 16:29:46 +000028
Anton Korobeynikov3829e8a2008-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};
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040
Anton Korobeynikovf700e682008-07-09 13:20:48 +000041X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +000042 X86TargetAsmInfo<DarwinTargetAsmInfo>(TM) {
Bill Wendling0ddb3862009-07-13 18:48:39 +000043 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
Anton Korobeynikov16876eb2008-08-08 18:25:52 +000044 bool is64Bit = Subtarget->is64Bit();
Anton Korobeynikovf700e682008-07-09 13:20:48 +000045
46 AlignmentIsInBytes = false;
47 TextAlignFillValue = 0x90;
Daniel Dunbar1e13b972009-07-24 08:24:36 +000048
49
Anton Korobeynikovf700e682008-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 Korobeynikovf700e682008-07-09 13:20:48 +000053 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Dan Gohmana004d7b2008-11-03 18:22:42 +000054 if (TM.getRelocationModel() != Reloc::Static)
Anton Korobeynikova7463ee2008-07-09 21:54:26 +000055 ConstantPoolSection = "\t.const_data";
56 else
57 ConstantPoolSection = "\t.const\n";
Anton Korobeynikovf700e682008-07-09 13:20:48 +000058 LCOMMDirective = "\t.lcomm\t";
Bill Wendling0ddb3862009-07-13 18:48:39 +000059
Anton Korobeynikov16876eb2008-08-08 18:25:52 +000060 // Leopard and above support aligned common symbols.
61 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikovf700e682008-07-09 13:20:48 +000062 HasDotTypeDotSizeDirective = false;
Daniel Dunbar1e13b972009-07-24 08:24:36 +000063
Anton Korobeynikovf700e682008-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 Wendling0ddb3862009-07-13 18:48:39 +000071
Anton Korobeynikovf700e682008-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 Korobeynikovf700e682008-07-09 13:20:48 +000078 ProtectedDirective = "\t.globl\t";
79
Anton Korobeynikovf700e682008-07-09 13:20:48 +000080 SupportsDebugInformation = true;
Devang Patel88bf96e2009-04-13 17:02:03 +000081 DwarfDebugInlineSection = ".section __DWARF,__debug_inlined,regular,debug";
82 DwarfUsesInlineInfoSection = true;
Anton Korobeynikovf700e682008-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 Wendling4e39d3e2009-07-13 20:27:41 +000091 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
Anton Korobeynikovf700e682008-07-09 13:20:48 +000092}
93
Chris Lattner8b0bb372009-07-31 21:39:55 +000094unsigned X86DarwinTargetAsmInfo::PreferredEHDataFormat() const {
Bill Wendling1d29c1f2009-07-29 00:59:34 +000095 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
Chris Lattner8b0bb372009-07-31 21:39:55 +000096 if (Subtarget->getDarwinVers() > 9)
97 return DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4;
Bill Wendlingcf4423b2009-07-28 21:53:17 +000098
Chris Lattner64630562009-07-27 06:17:14 +000099 return DW_EH_PE_absptr;
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000100}
101
Rafael Espindola1a931842008-12-19 10:55:56 +0000102const char *
Chris Lattner64630562009-07-27 06:17:14 +0000103X86DarwinTargetAsmInfo::getEHGlobalPrefix() const {
Rafael Espindola1a931842008-12-19 10:55:56 +0000104 const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>();
105 if (Subtarget->getDarwinVers() > 9)
106 return PrivateGlobalPrefix;
Chris Lattner64630562009-07-27 06:17:14 +0000107 return "";
Rafael Espindola1a931842008-12-19 10:55:56 +0000108}
109
Chris Lattner64630562009-07-27 06:17:14 +0000110X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM) :
Anton Korobeynikov3829e8a2008-09-25 21:00:33 +0000111 X86TargetAsmInfo<ELFTargetAsmInfo>(TM) {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000112
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000113 CStringSection = ".rodata.str";
Anton Korobeynikovf700e682008-07-09 13:20:48 +0000114 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";
Chris Lattnerecbf73b2009-06-18 23:31:37 +0000135 DwarfMacroInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
Anton Korobeynikovf700e682008-07-09 13:20:48 +0000136
137 // Exceptions handling
Anton Korobeynikov15f3a842008-09-08 21:13:08 +0000138 SupportsExceptionHandling = true;
Anton Korobeynikovf700e682008-07-09 13:20:48 +0000139 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.
Dan Gohmana004d7b2008-11-03 18:22:42 +0000144 if (TM.getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikovf700e682008-07-09 13:20:48 +0000145 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
146}
147
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000148unsigned
Chris Lattner8b0bb372009-07-31 21:39:55 +0000149X86ELFTargetAsmInfo::PreferredEHDataFormat() const {
Dan Gohmana004d7b2008-11-03 18:22:42 +0000150 CodeModel::Model CM = TM.getCodeModel();
151 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000152
Dan Gohmana004d7b2008-11-03 18:22:42 +0000153 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000154 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
Chris Lattner8b0bb372009-07-31 21:39:55 +0000164 if (CM == CodeModel::Small || CM == CodeModel::Medium)
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000165 Format = DW_EH_PE_sdata4;
166 else
167 Format = DW_EH_PE_sdata8;
168 }
169
Chris Lattner8b0bb372009-07-31 21:39:55 +0000170 Format |= DW_EH_PE_indirect;
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000171 return (Format | DW_EH_PE_pcrel);
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000172 }
Chris Lattner8b0bb372009-07-31 21:39:55 +0000173
174 if (is64Bit && CM == CodeModel::Small)
175 return DW_EH_PE_udata4;
176 return DW_EH_PE_absptr;
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000177}
178
Anton Korobeynikovf700e682008-07-09 13:20:48 +0000179
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000180unsigned
Chris Lattner8b0bb372009-07-31 21:39:55 +0000181X86COFFTargetAsmInfo::PreferredEHDataFormat() const {
Dan Gohmana004d7b2008-11-03 18:22:42 +0000182 CodeModel::Model CM = TM.getCodeModel();
183 bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000184
Dan Gohmana004d7b2008-11-03 18:22:42 +0000185 if (TM.getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000186 unsigned Format = 0;
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000187
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000188 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
Chris Lattner8b0bb372009-07-31 21:39:55 +0000196 if (CM == CodeModel::Small || CM == CodeModel::Medium)
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000197 Format = DW_EH_PE_sdata4;
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000198 else
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000199 Format = DW_EH_PE_sdata8;
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000200 }
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000201
Chris Lattner8b0bb372009-07-31 21:39:55 +0000202 Format |= DW_EH_PE_indirect;
Anton Korobeynikovcd2a4e52008-07-09 13:21:08 +0000203 return (Format | DW_EH_PE_pcrel);
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000204 }
Chris Lattnerb8245582009-07-24 04:49:34 +0000205
Chris Lattner8b0bb372009-07-31 21:39:55 +0000206 if (is64Bit && CM == CodeModel::Small)
Chris Lattnerb8245582009-07-24 04:49:34 +0000207 return DW_EH_PE_udata4;
208 return DW_EH_PE_absptr;
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000209}
210
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000211
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000212
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000213X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
Chris Lattner9418a392009-07-27 16:45:59 +0000214 X86TargetAsmInfo<TargetAsmInfo>(TM) {
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000215 GlobalPrefix = "_";
216 CommentString = ";";
217
Eli Friedman378ea832009-06-19 04:48:38 +0000218 InlineAsmStart = "; InlineAsm Start";
219 InlineAsmEnd = "; InlineAsm End";
220
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000221 PrivateGlobalPrefix = "$";
Eli Friedman378ea832009-06-19 04:48:38 +0000222 AlignDirective = "\tALIGN\t";
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000223 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;
Rafael Espindola5cf2e552008-12-03 11:01:37 +0000232 HasSingleParameterDotFile = false;
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000233
Eli Friedman378ea832009-06-19 04:48:38 +0000234 AlignmentIsInBytes = true;
235
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000236 JumpTableDataSection = NULL;
237 SwitchToSectionDirective = "";
Eli Friedman378ea832009-06-19 04:48:38 +0000238 TextSectionStartSuffix = "\tSEGMENT PARA 'CODE'";
239 DataSectionStartSuffix = "\tSEGMENT PARA 'DATA'";
Anton Korobeynikov49881c52008-07-09 13:21:49 +0000240 SectionEndDirectiveSuffix = "\tends\n";
241}
Anton Korobeynikov45d1b622008-10-05 08:53:29 +0000242
Anton Korobeynikov45d1b622008-10-05 08:53:29 +0000243// Instantiate default implementation.
244TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>);