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