Add FIXME needed to be resolved later
[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
249   switch (Kind) {
250    case SectionKind::Text:
251     if (isWeak)
252       return TextCoalSection;
253     else
254       return getTextSection_();
255    case SectionKind::Data:
256    case SectionKind::ThreadData:
257    case SectionKind::BSS:
258    case SectionKind::ThreadBSS:
259     if (cast<GlobalVariable>(GV)->isConstant())
260       return (isWeak ? ConstDataCoalSection : ConstDataSection);
261     else
262       return (isWeak ? DataCoalSection : getDataSection_());
263    case SectionKind::ROData:
264     return (isWeak ? ConstDataCoalSection : getReadOnlySection_());
265    case SectionKind::RODataMergeStr:
266     return MergeableStringSection(cast<GlobalVariable>(GV));
267    case SectionKind::RODataMergeConst:
268     return MergeableConstSection(cast<GlobalVariable>(GV));
269    default:
270     assert(0 && "Unsuported section kind for global");
271   }
272
273   // FIXME: Do we have any extra special weird cases?
274 }
275
276 const Section*
277 X86DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
278   const TargetData *TD = X86TM->getTargetData();
279   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
280   const Type *Type = cast<ConstantArray>(C)->getType()->getElementType();
281
282   unsigned Size = TD->getABITypeSize(Type);
283   if (Size) {
284     const TargetData *TD = X86TM->getTargetData();
285     unsigned Align = TD->getPreferredAlignment(GV);
286     if (Align <= 32)
287       return getCStringSection_();
288   }
289
290   return getReadOnlySection_();
291 }
292
293 const Section*
294 X86DarwinTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
295   const TargetData *TD = X86TM->getTargetData();
296   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
297
298   unsigned Size = TD->getABITypeSize(C->getType());
299   if (Size == 4)
300     return FourByteConstantSection_;
301   else if (Size == 8)
302     return EightByteConstantSection_;
303   else if (Size == 16 && X86TM->getSubtarget<X86Subtarget>().is64Bit())
304     return SixteenByteConstantSection_;
305
306   return getReadOnlySection_();
307 }
308
309 std::string
310 X86DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
311                                                SectionKind::Kind kind) const {
312   assert(0 && "Darwin does not use unique sections");
313   return "";
314 }
315
316 X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
317   X86TargetAsmInfo(TM) {
318   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
319
320   TextSection_ = getUnnamedSection("\t.text", SectionFlags::Code);
321   DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable);
322   BSSSection_  = getUnnamedSection("\t.bss",
323                                    SectionFlags::Writeable | SectionFlags::BSS);
324   ReadOnlySection_ = getNamedSection("\t.rodata", SectionFlags::None);
325   TLSDataSection_ = getNamedSection("\t.tdata",
326                                     SectionFlags::Writeable | SectionFlags::TLS);
327   TLSBSSSection_ = getNamedSection("\t.tbss",
328                 SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS);
329
330   ReadOnlySection = ".rodata";
331   FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
332   EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
333   SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
334   CStringSection = ".rodata.str";
335   PrivateGlobalPrefix = ".L";
336   WeakRefDirective = "\t.weak\t";
337   SetDirective = "\t.set\t";
338   PCSymbol = ".";
339
340   // Set up DWARF directives
341   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
342
343   // Debug Information
344   AbsoluteDebugSectionOffsets = true;
345   SupportsDebugInformation = true;
346   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"\",@progbits";
347   DwarfInfoSection =    "\t.section\t.debug_info,\"\",@progbits";
348   DwarfLineSection =    "\t.section\t.debug_line,\"\",@progbits";
349   DwarfFrameSection =   "\t.section\t.debug_frame,\"\",@progbits";
350   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
351   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
352   DwarfStrSection =     "\t.section\t.debug_str,\"\",@progbits";
353   DwarfLocSection =     "\t.section\t.debug_loc,\"\",@progbits";
354   DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
355   DwarfRangesSection =  "\t.section\t.debug_ranges,\"\",@progbits";
356   DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
357
358   // Exceptions handling
359   if (!is64Bit)
360     SupportsExceptionHandling = true;
361   AbsoluteEHSectionOffsets = false;
362   DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
363   DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
364
365   // On Linux we must declare when we can use a non-executable stack.
366   if (X86TM->getSubtarget<X86Subtarget>().isLinux())
367     NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
368 }
369
370 unsigned
371 X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
372                                            bool Global) const {
373   CodeModel::Model CM = X86TM->getCodeModel();
374   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
375
376   if (X86TM->getRelocationModel() == Reloc::PIC_) {
377     unsigned Format = 0;
378
379     if (!is64Bit)
380       // 32 bit targets always encode pointers as 4 bytes
381       Format = DW_EH_PE_sdata4;
382     else {
383       // 64 bit targets encode pointers in 4 bytes iff:
384       // - code model is small OR
385       // - code model is medium and we're emitting externally visible symbols
386       //   or any code symbols
387       if (CM == CodeModel::Small ||
388           (CM == CodeModel::Medium && (Global ||
389                                        Reason != DwarfEncoding::Data)))
390         Format = DW_EH_PE_sdata4;
391       else
392         Format = DW_EH_PE_sdata8;
393     }
394
395     if (Global)
396       Format |= DW_EH_PE_indirect;
397
398     return (Format | DW_EH_PE_pcrel);
399   } else {
400     if (is64Bit &&
401         (CM == CodeModel::Small ||
402          (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
403       return DW_EH_PE_udata4;
404     else
405       return DW_EH_PE_absptr;
406   }
407 }
408
409 const Section*
410 X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
411   SectionKind::Kind Kind = SectionKindForGlobal(GV);
412
413   if (const Function *F = dyn_cast<Function>(GV)) {
414     switch (F->getLinkage()) {
415      default: assert(0 && "Unknown linkage type!");
416      case Function::InternalLinkage:
417      case Function::DLLExportLinkage:
418      case Function::ExternalLinkage:
419       return getTextSection_();
420      case Function::WeakLinkage:
421      case Function::LinkOnceLinkage:
422       std::string Name = UniqueSectionForGlobal(GV, Kind);
423       unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
424       return getNamedSection(Name.c_str(), Flags);
425     }
426   } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
427     if (GVar->isWeakForLinker()) {
428       std::string Name = UniqueSectionForGlobal(GVar, Kind);
429       unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str());
430       return getNamedSection(Name.c_str(), Flags);
431     } else {
432       switch (Kind) {
433        case SectionKind::Data:
434         return getDataSection_();
435        case SectionKind::BSS:
436         // ELF targets usually have BSS sections
437         return getBSSSection_();
438        case SectionKind::ROData:
439         return getReadOnlySection_();
440        case SectionKind::RODataMergeStr:
441         return MergeableStringSection(GVar);
442        case SectionKind::RODataMergeConst:
443         return MergeableConstSection(GVar);
444        case SectionKind::ThreadData:
445         // ELF targets usually support TLS stuff
446         return getTLSDataSection_();
447        case SectionKind::ThreadBSS:
448         return getTLSBSSSection_();
449        default:
450         assert(0 && "Unsuported section kind for global");
451       }
452     }
453   } else
454     assert(0 && "Unsupported global");
455 }
456
457 const Section*
458 X86ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const {
459   const TargetData *TD = X86TM->getTargetData();
460   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
461   const Type *Type = C->getType();
462
463   // FIXME: string here is temporary, until stuff will fully land in.
464   // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's
465   // currently directly used by asmprinter.
466   unsigned Size = TD->getABITypeSize(Type);
467   if (Size == 4 || Size == 8 || Size == 16) {
468     std::string Name =  ".rodata.cst" + utostr(Size);
469
470     return getNamedSection(Name.c_str(),
471                            SectionFlags::setEntitySize(SectionFlags::Mergeable,
472                                                        Size));
473   }
474
475   return getReadOnlySection_();
476 }
477
478 const Section*
479 X86ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const {
480   const TargetData *TD = X86TM->getTargetData();
481   Constant *C = cast<GlobalVariable>(GV)->getInitializer();
482   const ConstantArray *CVA = cast<ConstantArray>(C);
483   const Type *Type = CVA->getType()->getElementType();
484
485   unsigned Size = TD->getABITypeSize(Type);
486   if (Size <= 16) {
487     // We also need alignment here
488     const TargetData *TD = X86TM->getTargetData();
489     unsigned Align = TD->getPreferredAlignment(GV);
490     if (Align < Size)
491       Align = Size;
492
493     std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align);
494     unsigned Flags = SectionFlags::setEntitySize(SectionFlags::Mergeable |
495                                                  SectionFlags::Strings,
496                                                  Size);
497     return getNamedSection(Name.c_str(), Flags);
498   }
499
500   return getReadOnlySection_();
501 }
502
503 std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
504   std::string Flags = ",\"";
505
506   if (!(flags & SectionFlags::Debug))
507     Flags += 'a';
508   if (flags & SectionFlags::Code)
509     Flags += 'x';
510   if (flags & SectionFlags::Writeable)
511     Flags += 'w';
512   if (flags & SectionFlags::Mergeable)
513     Flags += 'M';
514   if (flags & SectionFlags::Strings)
515     Flags += 'S';
516   if (flags & SectionFlags::TLS)
517     Flags += 'T';
518
519   Flags += "\"";
520
521   // FIXME: There can be exceptions here
522   if (flags & SectionFlags::BSS)
523     Flags += ",@nobits";
524   else
525     Flags += ",@progbits";
526
527   if (unsigned entitySize = SectionFlags::getEntitySize(flags))
528     Flags += "," + utostr(entitySize);
529
530   return Flags;
531 }
532
533 X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
534   X86TargetAsmInfo(TM) {
535   GlobalPrefix = "_";
536   LCOMMDirective = "\t.lcomm\t";
537   COMMDirectiveTakesAlignment = false;
538   HasDotTypeDotSizeDirective = false;
539   StaticCtorsSection = "\t.section .ctors,\"aw\"";
540   StaticDtorsSection = "\t.section .dtors,\"aw\"";
541   HiddenDirective = NULL;
542   PrivateGlobalPrefix = "L";  // Prefix for private global symbols
543   WeakRefDirective = "\t.weak\t";
544   SetDirective = "\t.set\t";
545
546   // Set up DWARF directives
547   HasLEB128 = true;  // Target asm supports leb128 directives (little-endian)
548   AbsoluteDebugSectionOffsets = true;
549   AbsoluteEHSectionOffsets = false;
550   SupportsDebugInformation = true;
551   DwarfSectionOffsetDirective = "\t.secrel32\t";
552   DwarfAbbrevSection =  "\t.section\t.debug_abbrev,\"dr\"";
553   DwarfInfoSection =    "\t.section\t.debug_info,\"dr\"";
554   DwarfLineSection =    "\t.section\t.debug_line,\"dr\"";
555   DwarfFrameSection =   "\t.section\t.debug_frame,\"dr\"";
556   DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
557   DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
558   DwarfStrSection =     "\t.section\t.debug_str,\"dr\"";
559   DwarfLocSection =     "\t.section\t.debug_loc,\"dr\"";
560   DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
561   DwarfRangesSection =  "\t.section\t.debug_ranges,\"dr\"";
562   DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
563 }
564
565 unsigned
566 X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
567                                             bool Global) const {
568   CodeModel::Model CM = X86TM->getCodeModel();
569   bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
570
571   if (X86TM->getRelocationModel() == Reloc::PIC_) {
572     unsigned Format = 0;
573
574     if (!is64Bit)
575       // 32 bit targets always encode pointers as 4 bytes
576       Format = DW_EH_PE_sdata4;
577     else {
578       // 64 bit targets encode pointers in 4 bytes iff:
579       // - code model is small OR
580       // - code model is medium and we're emitting externally visible symbols
581       //   or any code symbols
582       if (CM == CodeModel::Small ||
583           (CM == CodeModel::Medium && (Global ||
584                                        Reason != DwarfEncoding::Data)))
585         Format = DW_EH_PE_sdata4;
586       else
587         Format = DW_EH_PE_sdata8;
588     }
589
590     if (Global)
591       Format |= DW_EH_PE_indirect;
592
593     return (Format | DW_EH_PE_pcrel);
594   } else {
595     if (is64Bit &&
596         (CM == CodeModel::Small ||
597          (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
598       return DW_EH_PE_udata4;
599     else
600       return DW_EH_PE_absptr;
601   }
602 }
603
604 std::string
605 X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
606                                              SectionKind::Kind kind) const {
607   switch (kind) {
608    case SectionKind::Text:
609     return ".text$linkonce" + GV->getName();
610    case SectionKind::Data:
611    case SectionKind::BSS:
612    case SectionKind::ThreadData:
613    case SectionKind::ThreadBSS:
614     return ".data$linkonce" + GV->getName();
615    case SectionKind::ROData:
616    case SectionKind::RODataMergeConst:
617    case SectionKind::RODataMergeStr:
618     return ".rdata$linkonce" + GV->getName();
619    default:
620     assert(0 && "Unknown section kind");
621   }
622 }
623
624 std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const {
625   std::string Flags = ",\"";
626
627   if (flags & SectionFlags::Code)
628     Flags += 'x';
629   if (flags & SectionFlags::Writeable)
630     Flags += 'w';
631
632   Flags += "\"";
633
634   return Flags;
635 }
636
637 X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
638   X86TargetAsmInfo(TM) {
639   GlobalPrefix = "_";
640   CommentString = ";";
641
642   PrivateGlobalPrefix = "$";
643   AlignDirective = "\talign\t";
644   ZeroDirective = "\tdb\t";
645   ZeroDirectiveSuffix = " dup(0)";
646   AsciiDirective = "\tdb\t";
647   AscizDirective = 0;
648   Data8bitsDirective = "\tdb\t";
649   Data16bitsDirective = "\tdw\t";
650   Data32bitsDirective = "\tdd\t";
651   Data64bitsDirective = "\tdq\t";
652   HasDotTypeDotSizeDirective = false;
653
654   TextSection = "_text";
655   DataSection = "_data";
656   JumpTableDataSection = NULL;
657   SwitchToSectionDirective = "";
658   TextSectionStartSuffix = "\tsegment 'CODE'";
659   DataSectionStartSuffix = "\tsegment 'DATA'";
660   SectionEndDirectiveSuffix = "\tends\n";
661 }