blob: 1097302ca7e36ecc4041e768eac3f1c6d2dca7f7 [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"
24
Jim Laskey8e8de8f2006-09-07 22:05:02 +000025using namespace llvm;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000026using namespace llvm::dwarf;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000027
Dan Gohmancfbb2f02008-03-25 21:45:14 +000028static const char *const x86_asm_table[] = {
29 "{si}", "S",
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000030 "{di}", "D",
31 "{ax}", "a",
32 "{cx}", "c",
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000033 "{memory}", "memory",
34 "{flags}", "",
35 "{dirflag}", "",
36 "{fpsr}", "",
37 "{cc}", "cc",
38 0,0};
39
Jim Laskey8e8de8f2006-09-07 22:05:02 +000040X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
41 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000042
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000043 AsmTransCBE = x86_asm_table;
Anton Korobeynikov82100452008-07-09 13:20:27 +000044
Bill Wendlingcb900992007-01-16 09:29:17 +000045 AssemblerDialect = Subtarget->getAsmFlavor();
Jim Laskey8e8de8f2006-09-07 22:05:02 +000046}
Chris Lattnerafbfded2006-10-05 02:43:52 +000047
Chris Lattner625bd052006-11-29 01:14:06 +000048bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
49 // FIXME: this should verify that we are targetting a 486 or better. If not,
50 // we will turn this bswap into something that will be lowered to logical ops
51 // instead of emitting the bswap asm. For now, we don't support 486 or lower
52 // so don't worry about this.
Anton Korobeynikov82100452008-07-09 13:20:27 +000053
Chris Lattner625bd052006-11-29 01:14:06 +000054 // Verify this is a simple bswap.
55 if (CI->getNumOperands() != 2 ||
56 CI->getType() != CI->getOperand(1)->getType() ||
Chris Lattner42a75512007-01-15 02:27:26 +000057 !CI->getType()->isInteger())
Chris Lattner625bd052006-11-29 01:14:06 +000058 return false;
Anton Korobeynikov82100452008-07-09 13:20:27 +000059
Chris Lattner3e9f1d02007-04-01 20:49:36 +000060 const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
61 if (!Ty || Ty->getBitWidth() % 16 != 0)
Reid Spencera54b7cb2007-01-12 07:05:14 +000062 return false;
Anton Korobeynikov82100452008-07-09 13:20:27 +000063
Chris Lattner625bd052006-11-29 01:14:06 +000064 // Okay, we can do this xform, do so now.
Chandler Carruth69940402007-08-04 01:51:18 +000065 const Type *Tys[] = { Ty };
Chris Lattner625bd052006-11-29 01:14:06 +000066 Module *M = CI->getParent()->getParent()->getParent();
Chandler Carruth69940402007-08-04 01:51:18 +000067 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
Anton Korobeynikov82100452008-07-09 13:20:27 +000068
Chris Lattner625bd052006-11-29 01:14:06 +000069 Value *Op = CI->getOperand(1);
Gabor Greif051a9502008-04-06 20:25:17 +000070 Op = CallInst::Create(Int, Op, CI->getName(), CI);
Anton Korobeynikov82100452008-07-09 13:20:27 +000071
Chris Lattner625bd052006-11-29 01:14:06 +000072 CI->replaceAllUsesWith(Op);
73 CI->eraseFromParent();
74 return true;
75}
76
Chris Lattner625bd052006-11-29 01:14:06 +000077bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const {
78 InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
Chris Lattner5d521352006-11-29 01:48:01 +000079 std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
Anton Korobeynikov82100452008-07-09 13:20:27 +000080
Chris Lattner625bd052006-11-29 01:14:06 +000081 std::string AsmStr = IA->getAsmString();
Anton Korobeynikov82100452008-07-09 13:20:27 +000082
Chris Lattner625bd052006-11-29 01:14:06 +000083 // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
84 std::vector<std::string> AsmPieces;
85 SplitString(AsmStr, AsmPieces, "\n"); // ; as separator?
Anton Korobeynikov82100452008-07-09 13:20:27 +000086
Chris Lattner625bd052006-11-29 01:14:06 +000087 switch (AsmPieces.size()) {
Anton Korobeynikov82100452008-07-09 13:20:27 +000088 default: return false;
Chris Lattner625bd052006-11-29 01:14:06 +000089 case 1:
90 AsmStr = AsmPieces[0];
91 AsmPieces.clear();
92 SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace.
Anton Korobeynikov82100452008-07-09 13:20:27 +000093
Chris Lattner5d521352006-11-29 01:48:01 +000094 // bswap $0
Anton Korobeynikov82100452008-07-09 13:20:27 +000095 if (AsmPieces.size() == 2 &&
Chris Lattner625bd052006-11-29 01:14:06 +000096 AsmPieces[0] == "bswap" && AsmPieces[1] == "$0") {
97 // No need to check constraints, nothing other than the equivalent of
98 // "=r,0" would be valid here.
99 return LowerToBSwap(CI);
100 }
101 break;
Chris Lattner5d521352006-11-29 01:48:01 +0000102 case 3:
Reid Spencer47857812006-12-31 05:55:36 +0000103 if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
Chris Lattner5d521352006-11-29 01:48:01 +0000104 Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
105 Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
106 // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64
107 std::vector<std::string> Words;
108 SplitString(AsmPieces[0], Words, " \t");
109 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {
110 Words.clear();
111 SplitString(AsmPieces[1], Words, " \t");
112 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") {
113 Words.clear();
114 SplitString(AsmPieces[2], Words, " \t,");
115 if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" &&
116 Words[2] == "%edx") {
117 return LowerToBSwap(CI);
118 }
119 }
120 }
121 }
122 break;
Chris Lattner625bd052006-11-29 01:14:06 +0000123 }
124 return false;
125}
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000126
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000127X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000128 X86TargetAsmInfo(TM), DarwinTargetAsmInfo(TM) {
Anton Korobeynikov16b7f512008-08-08 18:25:52 +0000129 const X86Subtarget* Subtarget = &DTM->getSubtarget<X86Subtarget>();
130 bool is64Bit = Subtarget->is64Bit();
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000131
132 AlignmentIsInBytes = false;
133 TextAlignFillValue = 0x90;
134 GlobalPrefix = "_";
135 if (!is64Bit)
136 Data64bitsDirective = 0; // we can't emit a 64-bit unit
137 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
138 PrivateGlobalPrefix = "L"; // Marker for constant pool idxs
Dale Johannesenb2dfb892008-09-09 01:21:22 +0000139 LessPrivateGlobalPrefix = "l"; // Marker for some ObjC metadata
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000140 BSSSection = 0; // no BSS section.
141 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000142 if (DTM->getRelocationModel() != Reloc::Static)
Anton Korobeynikov7705ea32008-07-09 21:54:26 +0000143 ConstantPoolSection = "\t.const_data";
144 else
145 ConstantPoolSection = "\t.const\n";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000146 JumpTableDataSection = "\t.const\n";
147 CStringSection = "\t.cstring";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000148 // FIXME: Why don't always use this section?
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000149 if (is64Bit) {
Anton Korobeynikov64818732008-09-24 22:18:54 +0000150 SixteenByteConstantSection = getUnnamedSection("\t.literal16\n",
151 SectionFlags::Mergeable);
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000152 }
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000153 ReadOnlySection = "\t.const\n";
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000154
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000155 LCOMMDirective = "\t.lcomm\t";
156 SwitchToSectionDirective = "\t.section ";
157 StringConstantPrefix = "\1LC";
Anton Korobeynikov16b7f512008-08-08 18:25:52 +0000158 // Leopard and above support aligned common symbols.
159 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000160 HasDotTypeDotSizeDirective = false;
161 if (TM.getRelocationModel() == Reloc::Static) {
162 StaticCtorsSection = ".constructor";
163 StaticDtorsSection = ".destructor";
164 } else {
165 StaticCtorsSection = ".mod_init_func";
166 StaticDtorsSection = ".mod_term_func";
167 }
168 if (is64Bit) {
169 PersonalityPrefix = "";
170 PersonalitySuffix = "+4@GOTPCREL";
171 } else {
172 PersonalityPrefix = "L";
173 PersonalitySuffix = "$non_lazy_ptr";
174 }
175 NeedsIndirectEncoding = true;
176 InlineAsmStart = "## InlineAsm Start";
177 InlineAsmEnd = "## InlineAsm End";
178 CommentString = "##";
179 SetDirective = "\t.set";
180 PCSymbol = ".";
181 UsedDirective = "\t.no_dead_strip\t";
182 WeakDefDirective = "\t.weak_definition ";
183 WeakRefDirective = "\t.weak_reference ";
184 HiddenDirective = "\t.private_extern ";
185 ProtectedDirective = "\t.globl\t";
186
187 // In non-PIC modes, emit a special label before jump tables so that the
188 // linker can perform more accurate dead code stripping.
189 if (TM.getRelocationModel() != Reloc::PIC_) {
190 // Emit a local label that is preserved until the linker runs.
191 JumpTableSpecialLabelPrefix = "l";
192 }
193
194 SupportsDebugInformation = true;
195 NeedsSet = true;
196 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
197 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
198 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
199 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
200 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
201 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
202 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
203 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
204 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
205 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
206 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
207
208 // Exceptions handling
209 SupportsExceptionHandling = true;
210 GlobalEHDirective = "\t.globl\t";
211 SupportsWeakOmittedEHFrame = false;
212 AbsoluteEHSectionOffsets = false;
213 DwarfEHFrameSection =
214 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
215 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
216}
217
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000218unsigned
219X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
220 bool Global) const {
221 if (Reason == DwarfEncoding::Functions && Global)
222 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
223 else if (Reason == DwarfEncoding::CodeLabels || !Global)
224 return DW_EH_PE_pcrel;
225 else
226 return DW_EH_PE_absptr;
227}
228
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000229X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000230 X86TargetAsmInfo(TM), ELFTargetAsmInfo(TM) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000231
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000232 ReadOnlySection = ".rodata";
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000233 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000234 PrivateGlobalPrefix = ".L";
235 WeakRefDirective = "\t.weak\t";
236 SetDirective = "\t.set\t";
237 PCSymbol = ".";
238
239 // Set up DWARF directives
240 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
241
242 // Debug Information
243 AbsoluteDebugSectionOffsets = true;
244 SupportsDebugInformation = true;
245 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
246 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
247 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
248 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
249 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
250 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
251 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
252 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
253 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
254 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
255 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
256
257 // Exceptions handling
Anton Korobeynikovc4da15a2008-09-08 21:13:08 +0000258 SupportsExceptionHandling = true;
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000259 AbsoluteEHSectionOffsets = false;
260 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
261 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
262
263 // On Linux we must declare when we can use a non-executable stack.
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000264 if (ETM->getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000265 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
266}
267
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000268unsigned
269X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
270 bool Global) const {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000271 CodeModel::Model CM = ETM->getCodeModel();
272 bool is64Bit = ETM->getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000273
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000274 if (ETM->getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000275 unsigned Format = 0;
276
277 if (!is64Bit)
278 // 32 bit targets always encode pointers as 4 bytes
279 Format = DW_EH_PE_sdata4;
280 else {
281 // 64 bit targets encode pointers in 4 bytes iff:
282 // - code model is small OR
283 // - code model is medium and we're emitting externally visible symbols
284 // or any code symbols
285 if (CM == CodeModel::Small ||
286 (CM == CodeModel::Medium && (Global ||
287 Reason != DwarfEncoding::Data)))
288 Format = DW_EH_PE_sdata4;
289 else
290 Format = DW_EH_PE_sdata8;
291 }
292
293 if (Global)
294 Format |= DW_EH_PE_indirect;
295
296 return (Format | DW_EH_PE_pcrel);
297 } else {
298 if (is64Bit &&
299 (CM == CodeModel::Small ||
300 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
301 return DW_EH_PE_udata4;
302 else
303 return DW_EH_PE_absptr;
304 }
305}
306
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000307X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
308 X86TargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000309 X86TM = &TM;
310
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000311 GlobalPrefix = "_";
312 LCOMMDirective = "\t.lcomm\t";
313 COMMDirectiveTakesAlignment = false;
314 HasDotTypeDotSizeDirective = false;
315 StaticCtorsSection = "\t.section .ctors,\"aw\"";
316 StaticDtorsSection = "\t.section .dtors,\"aw\"";
317 HiddenDirective = NULL;
318 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
319 WeakRefDirective = "\t.weak\t";
320 SetDirective = "\t.set\t";
321
322 // Set up DWARF directives
323 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
324 AbsoluteDebugSectionOffsets = true;
325 AbsoluteEHSectionOffsets = false;
326 SupportsDebugInformation = true;
327 DwarfSectionOffsetDirective = "\t.secrel32\t";
328 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
329 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
330 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
331 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
332 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
333 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
334 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
335 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
336 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
337 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
338 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
339}
340
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000341unsigned
342X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
343 bool Global) const {
344 CodeModel::Model CM = X86TM->getCodeModel();
345 bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000346
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000347 if (X86TM->getRelocationModel() == Reloc::PIC_) {
348 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000349
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000350 if (!is64Bit)
351 // 32 bit targets always encode pointers as 4 bytes
352 Format = DW_EH_PE_sdata4;
353 else {
354 // 64 bit targets encode pointers in 4 bytes iff:
355 // - code model is small OR
356 // - code model is medium and we're emitting externally visible symbols
357 // or any code symbols
358 if (CM == CodeModel::Small ||
359 (CM == CodeModel::Medium && (Global ||
360 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000361 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000362 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000363 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000364 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000365
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000366 if (Global)
367 Format |= DW_EH_PE_indirect;
368
369 return (Format | DW_EH_PE_pcrel);
370 } else {
371 if (is64Bit &&
372 (CM == CodeModel::Small ||
373 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
374 return DW_EH_PE_udata4;
375 else
376 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000377 }
378}
379
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000380std::string
381X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
382 SectionKind::Kind kind) const {
383 switch (kind) {
384 case SectionKind::Text:
385 return ".text$linkonce" + GV->getName();
386 case SectionKind::Data:
387 case SectionKind::BSS:
388 case SectionKind::ThreadData:
389 case SectionKind::ThreadBSS:
390 return ".data$linkonce" + GV->getName();
391 case SectionKind::ROData:
392 case SectionKind::RODataMergeConst:
393 case SectionKind::RODataMergeStr:
394 return ".rdata$linkonce" + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000395 default:
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000396 assert(0 && "Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000397 }
398}
399
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000400std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000401 std::string Flags = ",\"";
402
403 if (flags & SectionFlags::Code)
404 Flags += 'x';
405 if (flags & SectionFlags::Writeable)
406 Flags += 'w';
407
408 Flags += "\"";
409
410 return Flags;
411}
412
413X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
414 X86TargetAsmInfo(TM) {
415 GlobalPrefix = "_";
416 CommentString = ";";
417
418 PrivateGlobalPrefix = "$";
419 AlignDirective = "\talign\t";
420 ZeroDirective = "\tdb\t";
421 ZeroDirectiveSuffix = " dup(0)";
422 AsciiDirective = "\tdb\t";
423 AscizDirective = 0;
424 Data8bitsDirective = "\tdb\t";
425 Data16bitsDirective = "\tdw\t";
426 Data32bitsDirective = "\tdd\t";
427 Data64bitsDirective = "\tdq\t";
428 HasDotTypeDotSizeDirective = false;
429
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000430 TextSection = getUnnamedSection("_text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000431 DataSection = getUnnamedSection("_data", SectionFlags::Writeable);
432
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000433 JumpTableDataSection = NULL;
434 SwitchToSectionDirective = "";
435 TextSectionStartSuffix = "\tsegment 'CODE'";
436 DataSectionStartSuffix = "\tsegment 'DATA'";
437 SectionEndDirectiveSuffix = "\tends\n";
438}