Distinguish .const and .const_data on Darwin, when needed. This is somehow crazy :)
[oota-llvm.git] / lib / Target / X86 / X86TargetAsmInfo.cpp
1 //===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
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"
23 #include "llvm/Support/Dwarf.h"
24
25 using namespace llvm;
26 using namespace llvm::dwarf;
27
28 static const char *const x86_asm_table[] = {
29                                       "{si}", "S",
30                                       "{di}", "D",
31                                       "{ax}", "a",
32                                       "{cx}", "c",
33                                       "{memory}", "memory",
34                                       "{flags}", "",
35                                       "{dirflag}", "",
36                                       "{fpsr}", "",
37                                       "{cc}", "cc",
38                                       0,0};
39
40 X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
41   const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
42   X86TM = &TM;
43
44   AsmTransCBE = x86_asm_table;
45
46   AssemblerDialect = Subtarget->getAsmFlavor();
47 }
48
49 bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
50   // FIXME: this should verify that we are targetting a 486 or better.  If not,
51   // we will turn this bswap into something that will be lowered to logical ops
52   // instead of emitting the bswap asm.  For now, we don't support 486 or lower
53   // so don't worry about this.
54
55   // Verify this is a simple bswap.
56   if (CI->getNumOperands() != 2 ||
57       CI->getType() != CI->getOperand(1)->getType() ||
58       !CI->getType()->isInteger())
59     return false;
60
61   const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
62   if (!Ty || Ty->getBitWidth() % 16 != 0)
63     return false;
64
65   // Okay, we can do this xform, do so now.
66   const Type *Tys[] = { Ty };
67   Module *M = CI->getParent()->getParent()->getParent();
68   Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
69
70   Value *Op = CI->getOperand(1);
71   Op = CallInst::Create(Int, Op, CI->getName(), CI);
72
73   CI->replaceAllUsesWith(Op);
74   CI->eraseFromParent();
75   return true;
76 }
77
78
79 bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const {
80   InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
81   std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
82
83   std::string AsmStr = IA->getAsmString();
84
85   // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
86   std::vector<std::string> AsmPieces;
87   SplitString(AsmStr, AsmPieces, "\n");  // ; as separator?
88
89   switch (AsmPieces.size()) {
90   default: return false;
91   case 1:
92     AsmStr = AsmPieces[0];
93     AsmPieces.clear();
94     SplitString(AsmStr, AsmPieces, " \t");  // Split with whitespace.
95
96     // bswap $0
97     if (AsmPieces.size() == 2 &&
98         AsmPieces[0] == "bswap" && AsmPieces[1] == "$0") {
99       // No need to check constraints, nothing other than the equivalent of
100       // "=r,0" would be valid here.
101       return LowerToBSwap(CI);
102     }
103     break;
104   case 3:
105     if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
106         Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
107         Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
108       // bswap %eax / bswap %edx / xchgl %eax, %edx  -> llvm.bswap.i64
109       std::vector<std::string> Words;
110       SplitString(AsmPieces[0], Words, " \t");
111       if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {
112         Words.clear();
113         SplitString(AsmPieces[1], Words, " \t");
114         if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") {
115           Words.clear();
116           SplitString(AsmPieces[2], Words, " \t,");
117           if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" &&
118               Words[2] == "%edx") {
119             return LowerToBSwap(CI);
120           }
121         }
122       }
123     }
124     break;
125   }
126   return false;
127 }
128
129 X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM):
130   X86TargetAsmInfo(TM) {
131   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
132
133   AlignmentIsInBytes = false;
134   TextAlignFillValue = 0x90;
135   GlobalPrefix = "_";
136   if (!is64Bit)
137     Data64bitsDirective = 0;       // we can't emit a 64-bit unit
138   ZeroDirective = "\t.space\t";  // ".space N" emits N zeros.
139   PrivateGlobalPrefix = "L";     // Marker for constant pool idxs
140   BSSSection = 0;                       // no BSS section.
141   ZeroFillDirective = "\t.zerofill\t";  // Uses .zerofill
142   ConstantPoolSection = "\t.const\n";
143   JumpTableDataSection = "\t.const\n";
144   CStringSection = "\t.cstring";
145   CStringSection_ = getUnnamedSection("\t.cstring",
146                                SectionFlags::Mergeable | SectionFlags::Strings);
147   FourByteConstantSection = "\t.literal4\n";
148   FourByteConstantSection_ = getUnnamedSection("\t.literal4\n",
149                                                SectionFlags::Mergeable);
150   EightByteConstantSection_ = getUnnamedSection("\t.literal8\n",
151                                                 SectionFlags::Mergeable);
152   // FIXME: Why don't always use this section?
153   if (is64Bit) {
154     SixteenByteConstantSection = "\t.literal16\n";
155     SixteenByteConstantSection_ = getUnnamedSection("\t.literal16\n",
156                                                     SectionFlags::Mergeable);
157   }
158   ReadOnlySection = "\t.const\n";
159   ReadOnlySection_ = getUnnamedSection("\t.const\n", SectionFlags::None);
160   // FIXME: These should be named sections, really.
161   TextCoalSection =
162   getUnnamedSection(".section __TEXT,__textcoal_nt,coalesced,pure_instructions",
163                     SectionFlags::Code);
164   ConstDataCoalSection =
165     getUnnamedSection(".section __DATA,__const_coal,coalesced",
166                       SectionFlags::None);
167   ConstDataSection = getUnnamedSection(".const_data", SectionFlags::None);
168   DataCoalSection = getUnnamedSection(".section __DATA,__datacoal_nt,coalesced",
169                                       SectionFlags::Writeable);
170
171   LCOMMDirective = "\t.lcomm\t";
172   SwitchToSectionDirective = "\t.section ";
173   StringConstantPrefix = "\1LC";
174   COMMDirectiveTakesAlignment = false;
175   HasDotTypeDotSizeDirective = false;
176   if (TM.getRelocationModel() == Reloc::Static) {
177     StaticCtorsSection = ".constructor";
178     StaticDtorsSection = ".destructor";
179   } else {
180     StaticCtorsSection = ".mod_init_func";
181     StaticDtorsSection = ".mod_term_func";
182   }
183   if (is64Bit) {
184     PersonalityPrefix = "";
185     PersonalitySuffix = "+4@GOTPCREL";
186   } else {
187     PersonalityPrefix = "L";
188     PersonalitySuffix = "$non_lazy_ptr";
189   }
190   NeedsIndirectEncoding = true;
191   InlineAsmStart = "## InlineAsm Start";
192   InlineAsmEnd = "## InlineAsm End";
193   CommentString = "##";
194   SetDirective = "\t.set";
195   PCSymbol = ".";
196   UsedDirective = "\t.no_dead_strip\t";
197   WeakDefDirective = "\t.weak_definition ";
198   WeakRefDirective = "\t.weak_reference ";
199   HiddenDirective = "\t.private_extern ";
200   ProtectedDirective = "\t.globl\t";
201
202   // In non-PIC modes, emit a special label before jump tables so that the
203   // linker can perform more accurate dead code stripping.
204   if (TM.getRelocationModel() != Reloc::PIC_) {
205     // Emit a local label that is preserved until the linker runs.
206     JumpTableSpecialLabelPrefix = "l";
207   }
208
209   SupportsDebugInformation = true;
210   NeedsSet = true;
211   DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
212   DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
213   DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
214   DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
215   DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
216   DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
217   DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
218   DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
219   DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
220   DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
221   DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
222
223   // Exceptions handling
224   SupportsExceptionHandling = true;
225   GlobalEHDirective = "\t.globl\t";
226   SupportsWeakOmittedEHFrame = false;
227   AbsoluteEHSectionOffsets = false;
228   DwarfEHFrameSection =
229   ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
230   DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
231 }
232
233 unsigned
234 X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
235                                               bool Global) const {
236   if (Reason == DwarfEncoding::Functions && Global)
237     return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
238   else if (Reason == DwarfEncoding::CodeLabels || !Global)
239     return DW_EH_PE_pcrel;
240   else
241     return DW_EH_PE_absptr;
242 }
243
244 const Section*
245 X86DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
246   SectionKind::Kind Kind = SectionKindForGlobal(GV);
247   bool isWeak = GV->isWeakForLinker();
248   bool isNonStatic = (X86TM->getRelocationModel() != Reloc::Static);
249
250   switch (Kind) {
251    case SectionKind::Text:
252     if (isWeak)
253       return TextCoalSection;
254     else
255       return getTextSection_();
256    case SectionKind::Data:
257    case SectionKind::ThreadData:
258    case SectionKind::BSS:
259    case SectionKind::ThreadBSS:
260     if (cast<GlobalVariable>(GV)->isConstant())
261       return (isWeak ? ConstDataCoalSection : ConstDataSection);
262     else
263       return (isWeak ? DataCoalSection : getDataSection_());
264    case SectionKind::ROData:
265     return (isWeak ? ConstDataCoalSection :
266             (isNonStatic ? ConstDataSection : getReadOnlySection_()));
267    case SectionKind::RODataMergeStr:
268     return (isWeak ?
269             ConstDataCoalSection :
270             MergeableStringSection(cast<GlobalVariable>(GV)));
271    case SectionKind::RODataMergeConst:
272     return (isWeak ?
273             ConstDataCoalSection:
274             MergeableConstSection(cast<GlobalVariable>(GV)));
275    default:
276     assert(0 && "Unsuported section kind for global");
277   }
278
279   // FIXME: Do we have any extra special weird cases?
280 }
281
282 const Section*
283 X86DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
284   const TargetData *TD = X86TM->getTargetData();
285   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
286   const Type *Type = cast<ConstantArray>(C)->getType()->getElementType();
287
288   unsigned Size = TD->getABITypeSize(Type);
289   if (Size) {
290     const TargetData *TD = X86TM->getTargetData();
291     unsigned Align = TD->getPreferredAlignment(GV);
292     if (Align <= 32)
293       return getCStringSection_();
294   }
295
296   return getReadOnlySection_();
297 }
298
299 const Section*
300 X86DarwinTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
301   const TargetData *TD = X86TM->getTargetData();
302   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
303
304   unsigned Size = TD->getABITypeSize(C->getType());
305   if (Size == 4)
306     return FourByteConstantSection_;
307   else if (Size == 8)
308     return EightByteConstantSection_;
309   else if (Size == 16 && X86TM->getSubtarget<X86Subtarget>().is64Bit())
310     return SixteenByteConstantSection_;
311
312   return getReadOnlySection_();
313 }
314
315 std::string
316 X86DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
317                                                SectionKind::Kind kind) const {
318   assert(0 && "Darwin does not use unique sections");
319   return "";
320 }
321
322 X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
323   X86TargetAsmInfo(TM) {
324   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
325
326   TextSection_ = getUnnamedSection("\t.text", SectionFlags::Code);
327   DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable);
328   BSSSection_  = getUnnamedSection("\t.bss",
329                                    SectionFlags::Writeable | SectionFlags::BSS);
330   ReadOnlySection_ = getNamedSection("\t.rodata", SectionFlags::None);
331   TLSDataSection_ = getNamedSection("\t.tdata",
332                                     SectionFlags::Writeable | SectionFlags::TLS);
333   TLSBSSSection_ = getNamedSection("\t.tbss",
334                 SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS);
335
336   ReadOnlySection = ".rodata";
337   FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
338   EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
339   SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
340   CStringSection = ".rodata.str";
341   PrivateGlobalPrefix = ".L";
342   WeakRefDirective = "\t.weak\t";
343   SetDirective = "\t.set\t";
344   PCSymbol = ".";
345
346   // Set up DWARF directives
347   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
348
349   // Debug Information
350   AbsoluteDebugSectionOffsets = true;
351   SupportsDebugInformation = true;
352   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
353   DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";
354   DwarfLineSection =    "\t.section\t.debug_line,\"\",@progbits";
355   DwarfFrameSection =   "\t.section\t.debug_frame,\"\",@progbits";
356   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
357   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
358   DwarfStrSection =     "\t.section\t.debug_str,\"\",@progbits";
359   DwarfLocSection =     "\t.section\t.debug_loc,\"\",@progbits";
360   DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
361   DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",@progbits";
362   DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
363
364   // Exceptions handling
365   if (!is64Bit)
366     SupportsExceptionHandling = true;
367   AbsoluteEHSectionOffsets = false;
368   DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
369   DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
370
371   // On Linux we must declare when we can use a non-executable stack.
372   if (X86TM->getSubtarget<X86Subtarget>().isLinux())
373     NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
374 }
375
376 unsigned
377 X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
378                                            bool Global) const {
379   CodeModel::Model CM = X86TM->getCodeModel();
380   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
381
382   if (X86TM->getRelocationModel() == Reloc::PIC_) {
383     unsigned Format = 0;
384
385     if (!is64Bit)
386       // 32 bit targets always encode pointers as 4 bytes
387       Format = DW_EH_PE_sdata4;
388     else {
389       // 64 bit targets encode pointers in 4 bytes iff:
390       // - code model is small OR
391       // - code model is medium and we're emitting externally visible symbols
392       //   or any code symbols
393       if (CM == CodeModel::Small ||
394           (CM == CodeModel::Medium && (Global ||
395                                        Reason != DwarfEncoding::Data)))
396         Format = DW_EH_PE_sdata4;
397       else
398         Format = DW_EH_PE_sdata8;
399     }
400
401     if (Global)
402       Format |= DW_EH_PE_indirect;
403
404     return (Format | DW_EH_PE_pcrel);
405   } else {
406     if (is64Bit &&
407         (CM == CodeModel::Small ||
408          (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
409       return DW_EH_PE_udata4;
410     else
411       return DW_EH_PE_absptr;
412   }
413 }
414
415 const Section*
416 X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
417   SectionKind::Kind Kind = SectionKindForGlobal(GV);
418
419   if (const Function *F = dyn_cast<Function>(GV)) {
420     switch (F->getLinkage()) {
421      default: assert(0 && "Unknown linkage type!");
422      case Function::InternalLinkage:
423      case Function::DLLExportLinkage:
424      case Function::ExternalLinkage:
425       return getTextSection_();
426      case Function::WeakLinkage:
427      case Function::LinkOnceLinkage:
428       std::string Name = UniqueSectionForGlobal(GV, Kind);
429       unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
430       return getNamedSection(Name.c_str(), Flags);
431     }
432   } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
433     if (GVar->isWeakForLinker()) {
434       std::string Name = UniqueSectionForGlobal(GVar, Kind);
435       unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str());
436       return getNamedSection(Name.c_str(), Flags);
437     } else {
438       switch (Kind) {
439        case SectionKind::Data:
440         return getDataSection_();
441        case SectionKind::BSS:
442         // ELF targets usually have BSS sections
443         return getBSSSection_();
444        case SectionKind::ROData:
445         return getReadOnlySection_();
446        case SectionKind::RODataMergeStr:
447         return MergeableStringSection(GVar);
448        case SectionKind::RODataMergeConst:
449         return MergeableConstSection(GVar);
450        case SectionKind::ThreadData:
451         // ELF targets usually support TLS stuff
452         return getTLSDataSection_();
453        case SectionKind::ThreadBSS:
454         return getTLSBSSSection_();
455        default:
456         assert(0 && "Unsuported section kind for global");
457       }
458     }
459   } else
460     assert(0 && "Unsupported global");
461 }
462
463 const Section*
464 X86ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
465   const TargetData *TD = X86TM->getTargetData();
466   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
467   const Type *Type = C->getType();
468
469   // FIXME: string here is temporary, until stuff will fully land in.
470   // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's
471   // currently directly used by asmprinter.
472   unsigned Size = TD->getABITypeSize(Type);
473   if (Size == 4 || Size == 8 || Size == 16) {
474     std::string Name =  ".rodata.cst" + utostr(Size);
475
476     return getNamedSection(Name.c_str(),
477                            SectionFlags::setEntitySize(SectionFlags::Mergeable,
478                                                        Size));
479   }
480
481   return getReadOnlySection_();
482 }
483
484 const Section*
485 X86ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
486   const TargetData *TD = X86TM->getTargetData();
487   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
488   const ConstantArray *CVA = cast<ConstantArray>(C);
489   const Type *Type = CVA->getType()->getElementType();
490
491   unsigned Size = TD->getABITypeSize(Type);
492   if (Size <= 16) {
493     // We also need alignment here
494     const TargetData *TD = X86TM->getTargetData();
495     unsigned Align = TD->getPreferredAlignment(GV);
496     if (Align < Size)
497       Align = Size;
498
499     std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align);
500     unsigned Flags = SectionFlags::setEntitySize(SectionFlags::Mergeable |
501                                                  SectionFlags::Strings,
502                                                  Size);
503     return getNamedSection(Name.c_str(), Flags);
504   }
505
506   return getReadOnlySection_();
507 }
508
509 std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
510   std::string Flags = ",\"";
511
512   if (!(flags & SectionFlags::Debug))
513     Flags += 'a';
514   if (flags & SectionFlags::Code)
515     Flags += 'x';
516   if (flags & SectionFlags::Writeable)
517     Flags += 'w';
518   if (flags & SectionFlags::Mergeable)
519     Flags += 'M';
520   if (flags & SectionFlags::Strings)
521     Flags += 'S';
522   if (flags & SectionFlags::TLS)
523     Flags += 'T';
524
525   Flags += "\"";
526
527   // FIXME: There can be exceptions here
528   if (flags & SectionFlags::BSS)
529     Flags += ",@nobits";
530   else
531     Flags += ",@progbits";
532
533   if (unsigned entitySize = SectionFlags::getEntitySize(flags))
534     Flags += "," + utostr(entitySize);
535
536   return Flags;
537 }
538
539 X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
540   X86TargetAsmInfo(TM) {
541   GlobalPrefix = "_";
542   LCOMMDirective = "\t.lcomm\t";
543   COMMDirectiveTakesAlignment = false;
544   HasDotTypeDotSizeDirective = false;
545   StaticCtorsSection = "\t.section .ctors,\"aw\"";
546   StaticDtorsSection = "\t.section .dtors,\"aw\"";
547   HiddenDirective = NULL;
548   PrivateGlobalPrefix = "L";  // Prefix for private global symbols
549   WeakRefDirective = "\t.weak\t";
550   SetDirective = "\t.set\t";
551
552   // Set up DWARF directives
553   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
554   AbsoluteDebugSectionOffsets = true;
555   AbsoluteEHSectionOffsets = false;
556   SupportsDebugInformation = true;
557   DwarfSectionOffsetDirective = "\t.secrel32\t";
558   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"dr\"";
559   DwarfInfoSection =    "\t.section\t.debug_info,\"dr\"";
560   DwarfLineSection =    "\t.section\t.debug_line,\"dr\"";
561   DwarfFrameSection =   "\t.section\t.debug_frame,\"dr\"";
562   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
563   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
564   DwarfStrSection =     "\t.section\t.debug_str,\"dr\"";
565   DwarfLocSection =     "\t.section\t.debug_loc,\"dr\"";
566   DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
567   DwarfRangesSection =  "\t.section\t.debug_ranges,\"dr\"";
568   DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
569 }
570
571 unsigned
572 X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
573                                             bool Global) const {
574   CodeModel::Model CM = X86TM->getCodeModel();
575   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
576
577   if (X86TM->getRelocationModel() == Reloc::PIC_) {
578     unsigned Format = 0;
579
580     if (!is64Bit)
581       // 32 bit targets always encode pointers as 4 bytes
582       Format = DW_EH_PE_sdata4;
583     else {
584       // 64 bit targets encode pointers in 4 bytes iff:
585       // - code model is small OR
586       // - code model is medium and we're emitting externally visible symbols
587       //   or any code symbols
588       if (CM == CodeModel::Small ||
589           (CM == CodeModel::Medium && (Global ||
590                                        Reason != DwarfEncoding::Data)))
591         Format = DW_EH_PE_sdata4;
592       else
593         Format = DW_EH_PE_sdata8;
594     }
595
596     if (Global)
597       Format |= DW_EH_PE_indirect;
598
599     return (Format | DW_EH_PE_pcrel);
600   } else {
601     if (is64Bit &&
602         (CM == CodeModel::Small ||
603          (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
604       return DW_EH_PE_udata4;
605     else
606       return DW_EH_PE_absptr;
607   }
608 }
609
610 std::string
611 X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
612                                              SectionKind::Kind kind) const {
613   switch (kind) {
614    case SectionKind::Text:
615     return ".text$linkonce" + GV->getName();
616    case SectionKind::Data:
617    case SectionKind::BSS:
618    case SectionKind::ThreadData:
619    case SectionKind::ThreadBSS:
620     return ".data$linkonce" + GV->getName();
621    case SectionKind::ROData:
622    case SectionKind::RODataMergeConst:
623    case SectionKind::RODataMergeStr:
624     return ".rdata$linkonce" + GV->getName();
625    default:
626     assert(0 && "Unknown section kind");
627   }
628 }
629
630 std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
631   std::string Flags = ",\"";
632
633   if (flags & SectionFlags::Code)
634     Flags += 'x';
635   if (flags & SectionFlags::Writeable)
636     Flags += 'w';
637
638   Flags += "\"";
639
640   return Flags;
641 }
642
643 X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
644   X86TargetAsmInfo(TM) {
645   GlobalPrefix = "_";
646   CommentString = ";";
647
648   PrivateGlobalPrefix = "$";
649   AlignDirective = "\talign\t";
650   ZeroDirective = "\tdb\t";
651   ZeroDirectiveSuffix = " dup(0)";
652   AsciiDirective = "\tdb\t";
653   AscizDirective = 0;
654   Data8bitsDirective = "\tdb\t";
655   Data16bitsDirective = "\tdw\t";
656   Data32bitsDirective = "\tdd\t";
657   Data64bitsDirective = "\tdq\t";
658   HasDotTypeDotSizeDirective = false;
659
660   TextSection = "_text";
661   DataSection = "_data";
662   JumpTableDataSection = NULL;
663   SwitchToSectionDirective = "";
664   TextSectionStartSuffix = "\tsegment 'CODE'";
665   DataSectionStartSuffix = "\tsegment 'DATA'";
666   SectionEndDirectiveSuffix = "\tends\n";
667 }