Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 1 | //===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 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" |
Reid Spencer | 7aa8a45 | 2007-01-12 23:22:14 +0000 | [diff] [blame] | 17 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 18 | #include "llvm/InlineAsm.h" |
| 19 | #include "llvm/Instructions.h" |
Chris Lattner | 3e9f1d0 | 2007-04-01 20:49:36 +0000 | [diff] [blame] | 20 | #include "llvm/Intrinsics.h" |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 21 | #include "llvm/Module.h" |
| 22 | #include "llvm/ADT/StringExtras.h" |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Dwarf.h" |
| 24 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 25 | using namespace llvm; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 26 | using namespace llvm::dwarf; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 27 | |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 28 | const char *const llvm::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}; |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 39 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 40 | X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM): |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 41 | X86TargetAsmInfo<DarwinTargetAsmInfo>(TM) { |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 42 | const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>(); |
Anton Korobeynikov | 16b7f51 | 2008-08-08 18:25:52 +0000 | [diff] [blame] | 43 | bool is64Bit = Subtarget->is64Bit(); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 44 | |
| 45 | AlignmentIsInBytes = false; |
| 46 | TextAlignFillValue = 0x90; |
| 47 | GlobalPrefix = "_"; |
| 48 | if (!is64Bit) |
| 49 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 50 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 51 | PrivateGlobalPrefix = "L"; // Marker for constant pool idxs |
Dale Johannesen | b2dfb89 | 2008-09-09 01:21:22 +0000 | [diff] [blame] | 52 | LessPrivateGlobalPrefix = "l"; // Marker for some ObjC metadata |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 53 | BSSSection = 0; // no BSS section. |
| 54 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 55 | if (TM.getRelocationModel() != Reloc::Static) |
Anton Korobeynikov | 7705ea3 | 2008-07-09 21:54:26 +0000 | [diff] [blame] | 56 | ConstantPoolSection = "\t.const_data"; |
| 57 | else |
| 58 | ConstantPoolSection = "\t.const\n"; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 59 | JumpTableDataSection = "\t.const\n"; |
| 60 | CStringSection = "\t.cstring"; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 61 | // FIXME: Why don't always use this section? |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 62 | if (is64Bit) { |
Anton Korobeynikov | 6481873 | 2008-09-24 22:18:54 +0000 | [diff] [blame] | 63 | SixteenByteConstantSection = getUnnamedSection("\t.literal16\n", |
| 64 | SectionFlags::Mergeable); |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 65 | } |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 66 | LCOMMDirective = "\t.lcomm\t"; |
| 67 | SwitchToSectionDirective = "\t.section "; |
| 68 | StringConstantPrefix = "\1LC"; |
Anton Korobeynikov | 16b7f51 | 2008-08-08 18:25:52 +0000 | [diff] [blame] | 69 | // Leopard and above support aligned common symbols. |
| 70 | COMMDirectiveTakesAlignment = (Subtarget->getDarwinVers() >= 9); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 71 | HasDotTypeDotSizeDirective = false; |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 72 | HasSingleParameterDotFile = false; |
Bill Wendling | d4121be | 2008-12-24 05:25:49 +0000 | [diff] [blame] | 73 | FDEEncodingRequiresSData4 = false; |
Bill Wendling | 722f5f1 | 2008-12-24 08:05:17 +0000 | [diff] [blame] | 74 | NonLocalEHFrameLabel = true; |
Bill Wendling | 998dee9 | 2008-12-29 22:12:11 +0000 | [diff] [blame^] | 75 | Force32BitFDEReference = false; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 76 | if (TM.getRelocationModel() == Reloc::Static) { |
| 77 | StaticCtorsSection = ".constructor"; |
| 78 | StaticDtorsSection = ".destructor"; |
| 79 | } else { |
| 80 | StaticCtorsSection = ".mod_init_func"; |
| 81 | StaticDtorsSection = ".mod_term_func"; |
| 82 | } |
| 83 | if (is64Bit) { |
| 84 | PersonalityPrefix = ""; |
| 85 | PersonalitySuffix = "+4@GOTPCREL"; |
| 86 | } else { |
| 87 | PersonalityPrefix = "L"; |
| 88 | PersonalitySuffix = "$non_lazy_ptr"; |
| 89 | } |
| 90 | NeedsIndirectEncoding = true; |
| 91 | InlineAsmStart = "## InlineAsm Start"; |
| 92 | InlineAsmEnd = "## InlineAsm End"; |
| 93 | CommentString = "##"; |
| 94 | SetDirective = "\t.set"; |
| 95 | PCSymbol = "."; |
| 96 | UsedDirective = "\t.no_dead_strip\t"; |
| 97 | WeakDefDirective = "\t.weak_definition "; |
| 98 | WeakRefDirective = "\t.weak_reference "; |
| 99 | HiddenDirective = "\t.private_extern "; |
| 100 | ProtectedDirective = "\t.globl\t"; |
| 101 | |
| 102 | // In non-PIC modes, emit a special label before jump tables so that the |
| 103 | // linker can perform more accurate dead code stripping. |
| 104 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 105 | // Emit a local label that is preserved until the linker runs. |
| 106 | JumpTableSpecialLabelPrefix = "l"; |
| 107 | } |
| 108 | |
| 109 | SupportsDebugInformation = true; |
| 110 | NeedsSet = true; |
| 111 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 112 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 113 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 114 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 115 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 116 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 117 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 118 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 119 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 120 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 121 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
| 122 | |
| 123 | // Exceptions handling |
| 124 | SupportsExceptionHandling = true; |
| 125 | GlobalEHDirective = "\t.globl\t"; |
| 126 | SupportsWeakOmittedEHFrame = false; |
| 127 | AbsoluteEHSectionOffsets = false; |
| 128 | DwarfEHFrameSection = |
| 129 | ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support"; |
| 130 | DwarfExceptionSection = ".section __DATA,__gcc_except_tab"; |
| 131 | } |
| 132 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 133 | unsigned |
| 134 | X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 135 | bool Global) const { |
| 136 | if (Reason == DwarfEncoding::Functions && Global) |
| 137 | return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4); |
| 138 | else if (Reason == DwarfEncoding::CodeLabels || !Global) |
| 139 | return DW_EH_PE_pcrel; |
| 140 | else |
| 141 | return DW_EH_PE_absptr; |
| 142 | } |
| 143 | |
Rafael Espindola | 2f6fea9 | 2008-12-19 10:55:56 +0000 | [diff] [blame] | 144 | const char * |
| 145 | X86DarwinTargetAsmInfo::getEHGlobalPrefix() const |
| 146 | { |
| 147 | const X86Subtarget* Subtarget = &TM.getSubtarget<X86Subtarget>(); |
| 148 | if (Subtarget->getDarwinVers() > 9) |
| 149 | return PrivateGlobalPrefix; |
| 150 | else |
| 151 | return ""; |
| 152 | } |
| 153 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 154 | X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM): |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 155 | X86TargetAsmInfo<ELFTargetAsmInfo>(TM) { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 156 | |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 157 | CStringSection = ".rodata.str"; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 158 | PrivateGlobalPrefix = ".L"; |
| 159 | WeakRefDirective = "\t.weak\t"; |
| 160 | SetDirective = "\t.set\t"; |
| 161 | PCSymbol = "."; |
| 162 | |
| 163 | // Set up DWARF directives |
| 164 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 165 | |
| 166 | // Debug Information |
| 167 | AbsoluteDebugSectionOffsets = true; |
| 168 | SupportsDebugInformation = true; |
| 169 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits"; |
| 170 | DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits"; |
| 171 | DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits"; |
| 172 | DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits"; |
| 173 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits"; |
| 174 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits"; |
| 175 | DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits"; |
| 176 | DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits"; |
| 177 | DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits"; |
| 178 | DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits"; |
| 179 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits"; |
| 180 | |
| 181 | // Exceptions handling |
Anton Korobeynikov | c4da15a | 2008-09-08 21:13:08 +0000 | [diff] [blame] | 182 | SupportsExceptionHandling = true; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 183 | AbsoluteEHSectionOffsets = false; |
| 184 | DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits"; |
| 185 | DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits"; |
| 186 | |
| 187 | // On Linux we must declare when we can use a non-executable stack. |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 188 | if (TM.getSubtarget<X86Subtarget>().isLinux()) |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 189 | NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits"; |
| 190 | } |
| 191 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 192 | unsigned |
| 193 | X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 194 | bool Global) const { |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 195 | CodeModel::Model CM = TM.getCodeModel(); |
| 196 | bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit(); |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 197 | |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 198 | if (TM.getRelocationModel() == Reloc::PIC_) { |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 199 | unsigned Format = 0; |
| 200 | |
| 201 | if (!is64Bit) |
| 202 | // 32 bit targets always encode pointers as 4 bytes |
| 203 | Format = DW_EH_PE_sdata4; |
| 204 | else { |
| 205 | // 64 bit targets encode pointers in 4 bytes iff: |
| 206 | // - code model is small OR |
| 207 | // - code model is medium and we're emitting externally visible symbols |
| 208 | // or any code symbols |
| 209 | if (CM == CodeModel::Small || |
| 210 | (CM == CodeModel::Medium && (Global || |
| 211 | Reason != DwarfEncoding::Data))) |
| 212 | Format = DW_EH_PE_sdata4; |
| 213 | else |
| 214 | Format = DW_EH_PE_sdata8; |
| 215 | } |
| 216 | |
| 217 | if (Global) |
| 218 | Format |= DW_EH_PE_indirect; |
| 219 | |
| 220 | return (Format | DW_EH_PE_pcrel); |
| 221 | } else { |
| 222 | if (is64Bit && |
| 223 | (CM == CodeModel::Small || |
| 224 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 225 | return DW_EH_PE_udata4; |
| 226 | else |
| 227 | return DW_EH_PE_absptr; |
| 228 | } |
| 229 | } |
| 230 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 231 | X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM): |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 232 | X86GenericTargetAsmInfo(TM) { |
Anton Korobeynikov | 18f6ed9 | 2008-07-19 13:15:21 +0000 | [diff] [blame] | 233 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 234 | GlobalPrefix = "_"; |
| 235 | LCOMMDirective = "\t.lcomm\t"; |
| 236 | COMMDirectiveTakesAlignment = false; |
| 237 | HasDotTypeDotSizeDirective = false; |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 238 | HasSingleParameterDotFile = false; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 239 | StaticCtorsSection = "\t.section .ctors,\"aw\""; |
| 240 | StaticDtorsSection = "\t.section .dtors,\"aw\""; |
| 241 | HiddenDirective = NULL; |
| 242 | PrivateGlobalPrefix = "L"; // Prefix for private global symbols |
| 243 | WeakRefDirective = "\t.weak\t"; |
| 244 | SetDirective = "\t.set\t"; |
| 245 | |
| 246 | // Set up DWARF directives |
| 247 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 248 | AbsoluteDebugSectionOffsets = true; |
| 249 | AbsoluteEHSectionOffsets = false; |
| 250 | SupportsDebugInformation = true; |
| 251 | DwarfSectionOffsetDirective = "\t.secrel32\t"; |
| 252 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\""; |
| 253 | DwarfInfoSection = "\t.section\t.debug_info,\"dr\""; |
| 254 | DwarfLineSection = "\t.section\t.debug_line,\"dr\""; |
| 255 | DwarfFrameSection = "\t.section\t.debug_frame,\"dr\""; |
| 256 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\""; |
| 257 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\""; |
| 258 | DwarfStrSection = "\t.section\t.debug_str,\"dr\""; |
| 259 | DwarfLocSection = "\t.section\t.debug_loc,\"dr\""; |
| 260 | DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\""; |
| 261 | DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\""; |
| 262 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\""; |
| 263 | } |
| 264 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 265 | unsigned |
| 266 | X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 267 | bool Global) const { |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 268 | CodeModel::Model CM = TM.getCodeModel(); |
| 269 | bool is64Bit = TM.getSubtarget<X86Subtarget>().is64Bit(); |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 270 | |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame] | 271 | if (TM.getRelocationModel() == Reloc::PIC_) { |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 272 | unsigned Format = 0; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 273 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 274 | if (!is64Bit) |
| 275 | // 32 bit targets always encode pointers as 4 bytes |
| 276 | Format = DW_EH_PE_sdata4; |
| 277 | else { |
| 278 | // 64 bit targets encode pointers in 4 bytes iff: |
| 279 | // - code model is small OR |
| 280 | // - code model is medium and we're emitting externally visible symbols |
| 281 | // or any code symbols |
| 282 | if (CM == CodeModel::Small || |
| 283 | (CM == CodeModel::Medium && (Global || |
| 284 | Reason != DwarfEncoding::Data))) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 285 | Format = DW_EH_PE_sdata4; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 286 | else |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 287 | Format = DW_EH_PE_sdata8; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 288 | } |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 289 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 290 | if (Global) |
| 291 | Format |= DW_EH_PE_indirect; |
| 292 | |
| 293 | return (Format | DW_EH_PE_pcrel); |
| 294 | } else { |
| 295 | if (is64Bit && |
| 296 | (CM == CodeModel::Small || |
| 297 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 298 | return DW_EH_PE_udata4; |
| 299 | else |
| 300 | return DW_EH_PE_absptr; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 301 | } |
| 302 | } |
| 303 | |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 304 | std::string |
| 305 | X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 306 | SectionKind::Kind kind) const { |
| 307 | switch (kind) { |
| 308 | case SectionKind::Text: |
| 309 | return ".text$linkonce" + GV->getName(); |
| 310 | case SectionKind::Data: |
| 311 | case SectionKind::BSS: |
| 312 | case SectionKind::ThreadData: |
| 313 | case SectionKind::ThreadBSS: |
| 314 | return ".data$linkonce" + GV->getName(); |
| 315 | case SectionKind::ROData: |
| 316 | case SectionKind::RODataMergeConst: |
| 317 | case SectionKind::RODataMergeStr: |
| 318 | return ".rdata$linkonce" + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 319 | default: |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 320 | assert(0 && "Unknown section kind"); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
Anton Korobeynikov | d0c1e29 | 2008-08-16 12:57:07 +0000 | [diff] [blame] | 324 | std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const { |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 325 | std::string Flags = ",\""; |
| 326 | |
| 327 | if (flags & SectionFlags::Code) |
| 328 | Flags += 'x'; |
| 329 | if (flags & SectionFlags::Writeable) |
| 330 | Flags += 'w'; |
| 331 | |
| 332 | Flags += "\""; |
| 333 | |
| 334 | return Flags; |
| 335 | } |
| 336 | |
| 337 | X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM): |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 338 | X86GenericTargetAsmInfo(TM) { |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 339 | GlobalPrefix = "_"; |
| 340 | CommentString = ";"; |
| 341 | |
| 342 | PrivateGlobalPrefix = "$"; |
| 343 | AlignDirective = "\talign\t"; |
| 344 | ZeroDirective = "\tdb\t"; |
| 345 | ZeroDirectiveSuffix = " dup(0)"; |
| 346 | AsciiDirective = "\tdb\t"; |
| 347 | AscizDirective = 0; |
| 348 | Data8bitsDirective = "\tdb\t"; |
| 349 | Data16bitsDirective = "\tdw\t"; |
| 350 | Data32bitsDirective = "\tdd\t"; |
| 351 | Data64bitsDirective = "\tdq\t"; |
| 352 | HasDotTypeDotSizeDirective = false; |
Rafael Espindola | 952b839 | 2008-12-03 11:01:37 +0000 | [diff] [blame] | 353 | HasSingleParameterDotFile = false; |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 354 | |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 355 | TextSection = getUnnamedSection("_text", SectionFlags::Code); |
Anton Korobeynikov | 315690e | 2008-09-24 22:16:16 +0000 | [diff] [blame] | 356 | DataSection = getUnnamedSection("_data", SectionFlags::Writeable); |
| 357 | |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 358 | JumpTableDataSection = NULL; |
| 359 | SwitchToSectionDirective = ""; |
| 360 | TextSectionStartSuffix = "\tsegment 'CODE'"; |
| 361 | DataSectionStartSuffix = "\tsegment 'DATA'"; |
| 362 | SectionEndDirectiveSuffix = "\tends\n"; |
| 363 | } |
Anton Korobeynikov | 6381a13 | 2008-10-05 08:53:29 +0000 | [diff] [blame] | 364 | |
| 365 | template <class BaseTAI> |
| 366 | bool X86TargetAsmInfo<BaseTAI>::LowerToBSwap(CallInst *CI) const { |
| 367 | // FIXME: this should verify that we are targetting a 486 or better. If not, |
| 368 | // we will turn this bswap into something that will be lowered to logical ops |
| 369 | // instead of emitting the bswap asm. For now, we don't support 486 or lower |
| 370 | // so don't worry about this. |
| 371 | |
| 372 | // Verify this is a simple bswap. |
| 373 | if (CI->getNumOperands() != 2 || |
| 374 | CI->getType() != CI->getOperand(1)->getType() || |
| 375 | !CI->getType()->isInteger()) |
| 376 | return false; |
| 377 | |
| 378 | const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| 379 | if (!Ty || Ty->getBitWidth() % 16 != 0) |
| 380 | return false; |
| 381 | |
| 382 | // Okay, we can do this xform, do so now. |
| 383 | const Type *Tys[] = { Ty }; |
| 384 | Module *M = CI->getParent()->getParent()->getParent(); |
| 385 | Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); |
| 386 | |
| 387 | Value *Op = CI->getOperand(1); |
| 388 | Op = CallInst::Create(Int, Op, CI->getName(), CI); |
| 389 | |
| 390 | CI->replaceAllUsesWith(Op); |
| 391 | CI->eraseFromParent(); |
| 392 | return true; |
| 393 | } |
| 394 | |
| 395 | template <class BaseTAI> |
| 396 | bool X86TargetAsmInfo<BaseTAI>::ExpandInlineAsm(CallInst *CI) const { |
| 397 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 398 | std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints(); |
| 399 | |
| 400 | std::string AsmStr = IA->getAsmString(); |
| 401 | |
| 402 | // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a" |
| 403 | std::vector<std::string> AsmPieces; |
| 404 | SplitString(AsmStr, AsmPieces, "\n"); // ; as separator? |
| 405 | |
| 406 | switch (AsmPieces.size()) { |
| 407 | default: return false; |
| 408 | case 1: |
| 409 | AsmStr = AsmPieces[0]; |
| 410 | AsmPieces.clear(); |
| 411 | SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace. |
| 412 | |
| 413 | // bswap $0 |
| 414 | if (AsmPieces.size() == 2 && |
| 415 | AsmPieces[0] == "bswap" && AsmPieces[1] == "$0") { |
| 416 | // No need to check constraints, nothing other than the equivalent of |
| 417 | // "=r,0" would be valid here. |
| 418 | return LowerToBSwap(CI); |
| 419 | } |
| 420 | break; |
| 421 | case 3: |
| 422 | if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 && |
| 423 | Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" && |
| 424 | Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") { |
| 425 | // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64 |
| 426 | std::vector<std::string> Words; |
| 427 | SplitString(AsmPieces[0], Words, " \t"); |
| 428 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") { |
| 429 | Words.clear(); |
| 430 | SplitString(AsmPieces[1], Words, " \t"); |
| 431 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") { |
| 432 | Words.clear(); |
| 433 | SplitString(AsmPieces[2], Words, " \t,"); |
| 434 | if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" && |
| 435 | Words[2] == "%edx") { |
| 436 | return LowerToBSwap(CI); |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | break; |
| 442 | } |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | // Instantiate default implementation. |
| 447 | TEMPLATE_INSTANTIATION(class X86TargetAsmInfo<TargetAsmInfo>); |