blob: 178aec0d57bdb45eadba121934465265e7ce4f8b [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
139 BSSSection = 0; // no BSS section.
140 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000141 if (DTM->getRelocationModel() != Reloc::Static)
Anton Korobeynikov7705ea32008-07-09 21:54:26 +0000142 ConstantPoolSection = "\t.const_data";
143 else
144 ConstantPoolSection = "\t.const\n";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000145 JumpTableDataSection = "\t.const\n";
146 CStringSection = "\t.cstring";
147 FourByteConstantSection = "\t.literal4\n";
Anton Korobeynikovb126f3b2008-07-09 20:47:55 +0000148 EightByteConstantSection = "\t.literal8\n";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000149 // FIXME: Why don't always use this section?
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000150 if (is64Bit) {
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000151 SixteenByteConstantSection = "\t.literal16\n";
Anton Korobeynikovcff2ea02008-07-19 13:15:46 +0000152 SixteenByteConstantSection_ = getUnnamedSection("\t.literal16\n",
153 SectionFlags::Mergeable);
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000154 }
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000155 ReadOnlySection = "\t.const\n";
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000156
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000157 LCOMMDirective = "\t.lcomm\t";
158 SwitchToSectionDirective = "\t.section ";
159 StringConstantPrefix = "\1LC";
Anton Korobeynikov16b7f512008-08-08 18:25:52 +0000160 // Leopard and above support aligned common symbols.
161 COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9);
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000162 HasDotTypeDotSizeDirective = false;
163 if (TM.getRelocationModel() == Reloc::Static) {
164 StaticCtorsSection = ".constructor";
165 StaticDtorsSection = ".destructor";
166 } else {
167 StaticCtorsSection = ".mod_init_func";
168 StaticDtorsSection = ".mod_term_func";
169 }
170 if (is64Bit) {
171 PersonalityPrefix = "";
172 PersonalitySuffix = "+4@GOTPCREL";
173 } else {
174 PersonalityPrefix = "L";
175 PersonalitySuffix = "$non_lazy_ptr";
176 }
177 NeedsIndirectEncoding = true;
178 InlineAsmStart = "## InlineAsm Start";
179 InlineAsmEnd = "## InlineAsm End";
180 CommentString = "##";
181 SetDirective = "\t.set";
182 PCSymbol = ".";
183 UsedDirective = "\t.no_dead_strip\t";
184 WeakDefDirective = "\t.weak_definition ";
185 WeakRefDirective = "\t.weak_reference ";
186 HiddenDirective = "\t.private_extern ";
187 ProtectedDirective = "\t.globl\t";
188
189 // In non-PIC modes, emit a special label before jump tables so that the
190 // linker can perform more accurate dead code stripping.
191 if (TM.getRelocationModel() != Reloc::PIC_) {
192 // Emit a local label that is preserved until the linker runs.
193 JumpTableSpecialLabelPrefix = "l";
194 }
195
196 SupportsDebugInformation = true;
197 NeedsSet = true;
198 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
199 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
200 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
201 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
202 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
203 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
204 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
205 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
206 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
207 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
208 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
209
210 // Exceptions handling
211 SupportsExceptionHandling = true;
212 GlobalEHDirective = "\t.globl\t";
213 SupportsWeakOmittedEHFrame = false;
214 AbsoluteEHSectionOffsets = false;
215 DwarfEHFrameSection =
216 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
217 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
218}
219
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000220unsigned
221X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
222 bool Global) const {
223 if (Reason == DwarfEncoding::Functions && Global)
224 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
225 else if (Reason == DwarfEncoding::CodeLabels || !Global)
226 return DW_EH_PE_pcrel;
227 else
228 return DW_EH_PE_absptr;
229}
230
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000231X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000232 X86TargetAsmInfo(TM), ELFTargetAsmInfo(TM) {
233 bool is64Bit = ETM->getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000234
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000235 ReadOnlySection = ".rodata";
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000236 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
237 EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
238 SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000239 CStringSection = ".rodata.str";
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000240 PrivateGlobalPrefix = ".L";
241 WeakRefDirective = "\t.weak\t";
242 SetDirective = "\t.set\t";
243 PCSymbol = ".";
244
245 // Set up DWARF directives
246 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
247
248 // Debug Information
249 AbsoluteDebugSectionOffsets = true;
250 SupportsDebugInformation = true;
251 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
252 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
253 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
254 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
255 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
256 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
257 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
258 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
259 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
260 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
261 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
262
263 // Exceptions handling
264 if (!is64Bit)
265 SupportsExceptionHandling = true;
266 AbsoluteEHSectionOffsets = false;
267 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
268 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
269
270 // On Linux we must declare when we can use a non-executable stack.
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000271 if (ETM->getSubtarget<X86Subtarget>().isLinux())
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000272 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
273}
274
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000275unsigned
276X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
277 bool Global) const {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000278 CodeModel::Model CM = ETM->getCodeModel();
279 bool is64Bit = ETM->getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000280
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000281 if (ETM->getRelocationModel() == Reloc::PIC_) {
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000282 unsigned Format = 0;
283
284 if (!is64Bit)
285 // 32 bit targets always encode pointers as 4 bytes
286 Format = DW_EH_PE_sdata4;
287 else {
288 // 64 bit targets encode pointers in 4 bytes iff:
289 // - code model is small OR
290 // - code model is medium and we're emitting externally visible symbols
291 // or any code symbols
292 if (CM == CodeModel::Small ||
293 (CM == CodeModel::Medium && (Global ||
294 Reason != DwarfEncoding::Data)))
295 Format = DW_EH_PE_sdata4;
296 else
297 Format = DW_EH_PE_sdata8;
298 }
299
300 if (Global)
301 Format |= DW_EH_PE_indirect;
302
303 return (Format | DW_EH_PE_pcrel);
304 } else {
305 if (is64Bit &&
306 (CM == CodeModel::Small ||
307 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
308 return DW_EH_PE_udata4;
309 else
310 return DW_EH_PE_absptr;
311 }
312}
313
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000314X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
315 X86TargetAsmInfo(TM) {
Anton Korobeynikov18f6ed92008-07-19 13:15:21 +0000316 X86TM = &TM;
317
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000318 GlobalPrefix = "_";
319 LCOMMDirective = "\t.lcomm\t";
320 COMMDirectiveTakesAlignment = false;
321 HasDotTypeDotSizeDirective = false;
322 StaticCtorsSection = "\t.section .ctors,\"aw\"";
323 StaticDtorsSection = "\t.section .dtors,\"aw\"";
324 HiddenDirective = NULL;
325 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
326 WeakRefDirective = "\t.weak\t";
327 SetDirective = "\t.set\t";
328
329 // Set up DWARF directives
330 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
331 AbsoluteDebugSectionOffsets = true;
332 AbsoluteEHSectionOffsets = false;
333 SupportsDebugInformation = true;
334 DwarfSectionOffsetDirective = "\t.secrel32\t";
335 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
336 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
337 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
338 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
339 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
340 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
341 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
342 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
343 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
344 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
345 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
346}
347
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000348unsigned
349X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
350 bool Global) const {
351 CodeModel::Model CM = X86TM->getCodeModel();
352 bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000353
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000354 if (X86TM->getRelocationModel() == Reloc::PIC_) {
355 unsigned Format = 0;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000356
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000357 if (!is64Bit)
358 // 32 bit targets always encode pointers as 4 bytes
359 Format = DW_EH_PE_sdata4;
360 else {
361 // 64 bit targets encode pointers in 4 bytes iff:
362 // - code model is small OR
363 // - code model is medium and we're emitting externally visible symbols
364 // or any code symbols
365 if (CM == CodeModel::Small ||
366 (CM == CodeModel::Medium && (Global ||
367 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000368 Format = DW_EH_PE_sdata4;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000369 else
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000370 Format = DW_EH_PE_sdata8;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000371 }
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000372
Anton Korobeynikovb9e58ef2008-07-09 13:21:08 +0000373 if (Global)
374 Format |= DW_EH_PE_indirect;
375
376 return (Format | DW_EH_PE_pcrel);
377 } else {
378 if (is64Bit &&
379 (CM == CodeModel::Small ||
380 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
381 return DW_EH_PE_udata4;
382 else
383 return DW_EH_PE_absptr;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000384 }
385}
386
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000387std::string
388X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
389 SectionKind::Kind kind) const {
390 switch (kind) {
391 case SectionKind::Text:
392 return ".text$linkonce" + GV->getName();
393 case SectionKind::Data:
394 case SectionKind::BSS:
395 case SectionKind::ThreadData:
396 case SectionKind::ThreadBSS:
397 return ".data$linkonce" + GV->getName();
398 case SectionKind::ROData:
399 case SectionKind::RODataMergeConst:
400 case SectionKind::RODataMergeStr:
401 return ".rdata$linkonce" + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000402 default:
Anton Korobeynikovb9a02fc2008-07-09 13:21:29 +0000403 assert(0 && "Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000404 }
405}
406
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000407std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
Anton Korobeynikovf447e3d2008-07-09 13:21:49 +0000408 std::string Flags = ",\"";
409
410 if (flags & SectionFlags::Code)
411 Flags += 'x';
412 if (flags & SectionFlags::Writeable)
413 Flags += 'w';
414
415 Flags += "\"";
416
417 return Flags;
418}
419
420X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
421 X86TargetAsmInfo(TM) {
422 GlobalPrefix = "_";
423 CommentString = ";";
424
425 PrivateGlobalPrefix = "$";
426 AlignDirective = "\talign\t";
427 ZeroDirective = "\tdb\t";
428 ZeroDirectiveSuffix = " dup(0)";
429 AsciiDirective = "\tdb\t";
430 AscizDirective = 0;
431 Data8bitsDirective = "\tdb\t";
432 Data16bitsDirective = "\tdw\t";
433 Data32bitsDirective = "\tdd\t";
434 Data64bitsDirective = "\tdq\t";
435 HasDotTypeDotSizeDirective = false;
436
437 TextSection = "_text";
438 DataSection = "_data";
439 JumpTableDataSection = NULL;
440 SwitchToSectionDirective = "";
441 TextSectionStartSuffix = "\tsegment 'CODE'";
442 DataSectionStartSuffix = "\tsegment 'DATA'";
443 SectionEndDirectiveSuffix = "\tends\n";
444}