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