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 | |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 28 | static const char* x86_asm_table[] = {"{si}", "S", |
| 29 | "{di}", "D", |
| 30 | "{ax}", "a", |
| 31 | "{cx}", "c", |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 32 | "{memory}", "memory", |
| 33 | "{flags}", "", |
| 34 | "{dirflag}", "", |
| 35 | "{fpsr}", "", |
| 36 | "{cc}", "cc", |
| 37 | 0,0}; |
| 38 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 39 | X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) { |
| 40 | const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>(); |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 41 | X86TM = &TM; |
| 42 | |
Chris Lattner | afbfded | 2006-10-05 02:43:52 +0000 | [diff] [blame] | 43 | // FIXME - Should be simplified. |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 44 | |
| 45 | AsmTransCBE = x86_asm_table; |
| 46 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 47 | switch (Subtarget->TargetType) { |
| 48 | case X86Subtarget::isDarwin: |
| 49 | AlignmentIsInBytes = false; |
Evan Cheng | fb8075d | 2008-02-28 00:43:03 +0000 | [diff] [blame] | 50 | TextAlignFillValue = 0x90; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 51 | GlobalPrefix = "_"; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 52 | if (!Subtarget->is64Bit()) |
| 53 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 54 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 55 | PrivateGlobalPrefix = "L"; // Marker for constant pool idxs |
Chris Lattner | 42ca450 | 2007-01-17 17:43:33 +0000 | [diff] [blame] | 56 | BSSSection = 0; // no BSS section. |
| 57 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 58 | ConstantPoolSection = "\t.const\n"; |
Chris Lattner | afbfded | 2006-10-05 02:43:52 +0000 | [diff] [blame] | 59 | JumpTableDataSection = "\t.const\n"; |
Evan Cheng | 8910c1c | 2006-10-26 19:18:18 +0000 | [diff] [blame] | 60 | CStringSection = "\t.cstring"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 61 | FourByteConstantSection = "\t.literal4\n"; |
| 62 | EightByteConstantSection = "\t.literal8\n"; |
Evan Cheng | 25ab690 | 2006-09-08 06:48:29 +0000 | [diff] [blame] | 63 | if (Subtarget->is64Bit()) |
| 64 | SixteenByteConstantSection = "\t.literal16\n"; |
Evan Cheng | f0b5d56 | 2007-03-08 01:07:07 +0000 | [diff] [blame] | 65 | ReadOnlySection = "\t.const\n"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 66 | LCOMMDirective = "\t.lcomm\t"; |
Dale Johannesen | 4af3494 | 2008-01-15 23:24:56 +0000 | [diff] [blame] | 67 | SwitchToSectionDirective = "\t.section "; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 68 | COMMDirectiveTakesAlignment = false; |
| 69 | HasDotTypeDotSizeDirective = false; |
Evan Cheng | b267ca1 | 2007-01-30 08:04:53 +0000 | [diff] [blame] | 70 | if (TM.getRelocationModel() == Reloc::Static) { |
| 71 | StaticCtorsSection = ".constructor"; |
| 72 | StaticDtorsSection = ".destructor"; |
| 73 | } else { |
| 74 | StaticCtorsSection = ".mod_init_func"; |
| 75 | StaticDtorsSection = ".mod_term_func"; |
| 76 | } |
Dale Johannesen | 4af3494 | 2008-01-15 23:24:56 +0000 | [diff] [blame] | 77 | if (Subtarget->is64Bit()) { |
| 78 | PersonalityPrefix = ""; |
| 79 | PersonalitySuffix = "+4@GOTPCREL"; |
| 80 | } else { |
| 81 | PersonalityPrefix = "L"; |
| 82 | PersonalitySuffix = "$non_lazy_ptr"; |
| 83 | } |
Bill Wendling | ef4a661 | 2007-09-11 17:20:55 +0000 | [diff] [blame] | 84 | NeedsIndirectEncoding = true; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 85 | InlineAsmStart = "# InlineAsm Start"; |
| 86 | InlineAsmEnd = "# InlineAsm End"; |
| 87 | SetDirective = "\t.set"; |
Bill Wendling | adbda02 | 2007-08-22 18:44:05 +0000 | [diff] [blame] | 88 | PCSymbol = "."; |
Chris Lattner | a53115b | 2006-09-26 03:39:53 +0000 | [diff] [blame] | 89 | UsedDirective = "\t.no_dead_strip\t"; |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 90 | WeakDefDirective = "\t.weak_definition "; |
| 91 | WeakRefDirective = "\t.weak_reference "; |
Dale Johannesen | c7406ae | 2008-01-11 00:54:37 +0000 | [diff] [blame] | 92 | HiddenDirective = "\t.private_extern "; |
Bill Wendling | bebc364 | 2008-03-18 23:38:12 +0000 | [diff] [blame] | 93 | ProtectedDirective = "\t.globl\t"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 94 | |
Chris Lattner | b266ccd | 2007-01-18 01:15:58 +0000 | [diff] [blame] | 95 | // In non-PIC modes, emit a special label before jump tables so that the |
| 96 | // linker can perform more accurate dead code stripping. |
| 97 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 98 | // Emit a local label that is preserved until the linker runs. |
| 99 | JumpTableSpecialLabelPrefix = "l"; |
| 100 | } |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 101 | |
| 102 | SupportsDebugInformation = true; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 103 | NeedsSet = true; |
| 104 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 105 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 106 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 107 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 108 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 109 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 110 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 111 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 112 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 113 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 114 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
Anton Korobeynikov | 095546c | 2007-08-21 00:31:30 +0000 | [diff] [blame] | 115 | |
| 116 | // Exceptions handling |
Dale Johannesen | 4af3494 | 2008-01-15 23:24:56 +0000 | [diff] [blame] | 117 | SupportsExceptionHandling = true; |
Dale Johannesen | 038129d | 2008-01-10 02:03:30 +0000 | [diff] [blame] | 118 | GlobalEHDirective = "\t.globl\t"; |
| 119 | SupportsWeakOmittedEHFrame = false; |
Anton Korobeynikov | 095546c | 2007-08-21 00:31:30 +0000 | [diff] [blame] | 120 | AbsoluteEHSectionOffsets = false; |
Dale Johannesen | 4af3494 | 2008-01-15 23:24:56 +0000 | [diff] [blame] | 121 | if (Subtarget->is64Bit()) |
| 122 | ShortenEHDataOn64Bit = true; |
Anton Korobeynikov | 095546c | 2007-08-21 00:31:30 +0000 | [diff] [blame] | 123 | DwarfEHFrameSection = |
| 124 | ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support"; |
| 125 | DwarfExceptionSection = ".section __DATA,__gcc_except_tab"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 126 | break; |
Reid Spencer | 02b8511 | 2006-10-30 22:32:30 +0000 | [diff] [blame] | 127 | |
| 128 | case X86Subtarget::isELF: |
Dan Gohman | 6445f61 | 2007-06-27 15:09:47 +0000 | [diff] [blame] | 129 | ReadOnlySection = "\t.section\t.rodata"; |
Dan Gohman | 6f858e2 | 2007-05-03 16:38:57 +0000 | [diff] [blame] | 130 | FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4"; |
| 131 | EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8"; |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 132 | SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16"; |
Dan Gohman | 6f858e2 | 2007-05-03 16:38:57 +0000 | [diff] [blame] | 133 | CStringSection = "\t.section\t.rodata.str1.1,\"aMS\",@progbits,1"; |
Chris Lattner | a3bfdd4 | 2007-01-03 18:16:48 +0000 | [diff] [blame] | 134 | PrivateGlobalPrefix = ".L"; |
Evan Cheng | 8752ce6 | 2006-12-01 20:47:11 +0000 | [diff] [blame] | 135 | WeakRefDirective = "\t.weak\t"; |
Anton Korobeynikov | 8b0a8c8 | 2007-04-25 14:27:10 +0000 | [diff] [blame] | 136 | SetDirective = "\t.set\t"; |
Anton Korobeynikov | edb4a6b | 2007-05-01 10:19:31 +0000 | [diff] [blame] | 137 | PCSymbol = "."; |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 138 | |
| 139 | // Set up DWARF directives |
| 140 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
Anton Korobeynikov | 59db3ec | 2007-07-25 00:06:28 +0000 | [diff] [blame] | 141 | |
| 142 | // Debug Information |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 143 | AbsoluteDebugSectionOffsets = true; |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 144 | SupportsDebugInformation = true; |
Reid Spencer | 02b8511 | 2006-10-30 22:32:30 +0000 | [diff] [blame] | 145 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits"; |
| 146 | DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits"; |
| 147 | DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits"; |
| 148 | DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits"; |
| 149 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits"; |
| 150 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits"; |
| 151 | DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits"; |
| 152 | DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits"; |
| 153 | DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits"; |
| 154 | DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits"; |
| 155 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits"; |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 156 | |
Anton Korobeynikov | 59db3ec | 2007-07-25 00:06:28 +0000 | [diff] [blame] | 157 | // Exceptions handling |
Anton Korobeynikov | 2365f51 | 2007-07-14 14:06:15 +0000 | [diff] [blame] | 158 | if (!Subtarget->is64Bit()) |
| 159 | SupportsExceptionHandling = true; |
Anton Korobeynikov | 59db3ec | 2007-07-25 00:06:28 +0000 | [diff] [blame] | 160 | AbsoluteEHSectionOffsets = false; |
Anton Korobeynikov | 71144d8 | 2007-05-01 10:16:06 +0000 | [diff] [blame] | 161 | DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits"; |
| 162 | DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits"; |
Reid Spencer | 02b8511 | 2006-10-30 22:32:30 +0000 | [diff] [blame] | 163 | break; |
| 164 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 165 | case X86Subtarget::isCygwin: |
Anton Korobeynikov | 317848f | 2007-01-03 11:43:14 +0000 | [diff] [blame] | 166 | case X86Subtarget::isMingw: |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 167 | GlobalPrefix = "_"; |
Anton Korobeynikov | 317848f | 2007-01-03 11:43:14 +0000 | [diff] [blame] | 168 | LCOMMDirective = "\t.lcomm\t"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 169 | COMMDirectiveTakesAlignment = false; |
| 170 | HasDotTypeDotSizeDirective = false; |
| 171 | StaticCtorsSection = "\t.section .ctors,\"aw\""; |
| 172 | StaticDtorsSection = "\t.section .dtors,\"aw\""; |
Anton Korobeynikov | 1a85645 | 2007-01-14 11:49:39 +0000 | [diff] [blame] | 173 | HiddenDirective = NULL; |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 174 | PrivateGlobalPrefix = "L"; // Prefix for private global symbols |
| 175 | WeakRefDirective = "\t.weak\t"; |
| 176 | SetDirective = "\t.set\t"; |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 177 | |
| 178 | // Set up DWARF directives |
| 179 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
Anton Korobeynikov | 79dda2b | 2007-05-01 22:23:12 +0000 | [diff] [blame] | 180 | AbsoluteDebugSectionOffsets = true; |
| 181 | AbsoluteEHSectionOffsets = false; |
Anton Korobeynikov | 2a07e2f | 2007-05-05 09:04:50 +0000 | [diff] [blame] | 182 | SupportsDebugInformation = true; |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 183 | DwarfSectionOffsetDirective = "\t.secrel32\t"; |
Anton Korobeynikov | ab4022f | 2006-10-31 08:31:24 +0000 | [diff] [blame] | 184 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\""; |
| 185 | DwarfInfoSection = "\t.section\t.debug_info,\"dr\""; |
| 186 | DwarfLineSection = "\t.section\t.debug_line,\"dr\""; |
| 187 | DwarfFrameSection = "\t.section\t.debug_frame,\"dr\""; |
| 188 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\""; |
| 189 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\""; |
| 190 | DwarfStrSection = "\t.section\t.debug_str,\"dr\""; |
| 191 | DwarfLocSection = "\t.section\t.debug_loc,\"dr\""; |
| 192 | DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\""; |
| 193 | DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\""; |
| 194 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\""; |
| 195 | break; |
Bill Wendling | 1150286 | 2007-01-16 04:13:03 +0000 | [diff] [blame] | 196 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 197 | case X86Subtarget::isWindows: |
| 198 | GlobalPrefix = "_"; |
| 199 | HasDotTypeDotSizeDirective = false; |
| 200 | break; |
Bill Wendling | 1150286 | 2007-01-16 04:13:03 +0000 | [diff] [blame] | 201 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 202 | default: break; |
| 203 | } |
| 204 | |
| 205 | if (Subtarget->isFlavorIntel()) { |
| 206 | GlobalPrefix = "_"; |
| 207 | CommentString = ";"; |
| 208 | |
| 209 | PrivateGlobalPrefix = "$"; |
| 210 | AlignDirective = "\talign\t"; |
| 211 | ZeroDirective = "\tdb\t"; |
| 212 | ZeroDirectiveSuffix = " dup(0)"; |
| 213 | AsciiDirective = "\tdb\t"; |
| 214 | AscizDirective = 0; |
| 215 | Data8bitsDirective = "\tdb\t"; |
| 216 | Data16bitsDirective = "\tdw\t"; |
| 217 | Data32bitsDirective = "\tdd\t"; |
| 218 | Data64bitsDirective = "\tdq\t"; |
| 219 | HasDotTypeDotSizeDirective = false; |
| 220 | |
| 221 | TextSection = "_text"; |
| 222 | DataSection = "_data"; |
Anton Korobeynikov | 24287dd | 2006-12-19 21:04:20 +0000 | [diff] [blame] | 223 | JumpTableDataSection = NULL; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 224 | SwitchToSectionDirective = ""; |
| 225 | TextSectionStartSuffix = "\tsegment 'CODE'"; |
| 226 | DataSectionStartSuffix = "\tsegment 'DATA'"; |
| 227 | SectionEndDirectiveSuffix = "\tends\n"; |
| 228 | } |
Bill Wendling | cb90099 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 229 | |
| 230 | AssemblerDialect = Subtarget->getAsmFlavor(); |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 231 | } |
Chris Lattner | afbfded | 2006-10-05 02:43:52 +0000 | [diff] [blame] | 232 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 233 | bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const { |
| 234 | // FIXME: this should verify that we are targetting a 486 or better. If not, |
| 235 | // we will turn this bswap into something that will be lowered to logical ops |
| 236 | // instead of emitting the bswap asm. For now, we don't support 486 or lower |
| 237 | // so don't worry about this. |
| 238 | |
| 239 | // Verify this is a simple bswap. |
| 240 | if (CI->getNumOperands() != 2 || |
| 241 | CI->getType() != CI->getOperand(1)->getType() || |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 242 | !CI->getType()->isInteger()) |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 243 | return false; |
| 244 | |
Chris Lattner | 3e9f1d0 | 2007-04-01 20:49:36 +0000 | [diff] [blame] | 245 | const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| 246 | if (!Ty || Ty->getBitWidth() % 16 != 0) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 247 | return false; |
Chris Lattner | 3e9f1d0 | 2007-04-01 20:49:36 +0000 | [diff] [blame] | 248 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 249 | // Okay, we can do this xform, do so now. |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 250 | const Type *Tys[] = { Ty }; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 251 | Module *M = CI->getParent()->getParent()->getParent(); |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 252 | Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 253 | |
| 254 | Value *Op = CI->getOperand(1); |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 255 | Op = new CallInst(Int, Op, CI->getName(), CI); |
| 256 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 257 | CI->replaceAllUsesWith(Op); |
| 258 | CI->eraseFromParent(); |
| 259 | return true; |
| 260 | } |
| 261 | |
| 262 | |
| 263 | bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const { |
| 264 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 265 | std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints(); |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 266 | |
| 267 | std::string AsmStr = IA->getAsmString(); |
| 268 | |
| 269 | // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a" |
| 270 | std::vector<std::string> AsmPieces; |
| 271 | SplitString(AsmStr, AsmPieces, "\n"); // ; as separator? |
| 272 | |
| 273 | switch (AsmPieces.size()) { |
| 274 | default: return false; |
| 275 | case 1: |
| 276 | AsmStr = AsmPieces[0]; |
| 277 | AsmPieces.clear(); |
| 278 | SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace. |
| 279 | |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 280 | // bswap $0 |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 281 | if (AsmPieces.size() == 2 && |
| 282 | AsmPieces[0] == "bswap" && AsmPieces[1] == "$0") { |
| 283 | // No need to check constraints, nothing other than the equivalent of |
| 284 | // "=r,0" would be valid here. |
| 285 | return LowerToBSwap(CI); |
| 286 | } |
| 287 | break; |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 288 | case 3: |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 289 | if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 && |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 290 | Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" && |
| 291 | Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") { |
| 292 | // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64 |
| 293 | std::vector<std::string> Words; |
| 294 | SplitString(AsmPieces[0], Words, " \t"); |
| 295 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") { |
| 296 | Words.clear(); |
| 297 | SplitString(AsmPieces[1], Words, " \t"); |
| 298 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") { |
| 299 | Words.clear(); |
| 300 | SplitString(AsmPieces[2], Words, " \t,"); |
| 301 | if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" && |
| 302 | Words[2] == "%edx") { |
| 303 | return LowerToBSwap(CI); |
| 304 | } |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | break; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 309 | } |
| 310 | return false; |
| 311 | } |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 312 | |
| 313 | /// PreferredEHDataFormat - This hook allows the target to select data |
| 314 | /// format used for encoding pointers in exception handling data. Reason is |
| 315 | /// 0 for data, 1 for code labels, 2 for function pointers. Global is true |
| 316 | /// if the symbol can be relocated. |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 317 | unsigned X86TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 318 | bool Global) const { |
| 319 | const X86Subtarget *Subtarget = &X86TM->getSubtarget<X86Subtarget>(); |
| 320 | |
| 321 | switch (Subtarget->TargetType) { |
| 322 | case X86Subtarget::isDarwin: |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 323 | if (Reason == DwarfEncoding::Functions && Global) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 324 | return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4); |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 325 | else if (Reason == DwarfEncoding::CodeLabels || !Global) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 326 | return DW_EH_PE_pcrel; |
| 327 | else |
| 328 | return DW_EH_PE_absptr; |
| 329 | |
| 330 | case X86Subtarget::isELF: |
| 331 | case X86Subtarget::isCygwin: |
| 332 | case X86Subtarget::isMingw: { |
| 333 | CodeModel::Model CM = X86TM->getCodeModel(); |
| 334 | |
| 335 | if (X86TM->getRelocationModel() == Reloc::PIC_) { |
| 336 | unsigned Format = 0; |
| 337 | |
| 338 | if (!Subtarget->is64Bit()) |
| 339 | // 32 bit targets always encode pointers as 4 bytes |
| 340 | Format = DW_EH_PE_sdata4; |
| 341 | else { |
| 342 | // 64 bit targets encode pointers in 4 bytes iff: |
| 343 | // - code model is small OR |
| 344 | // - code model is medium and we're emitting externally visible symbols or |
| 345 | // any code symbols |
| 346 | if (CM == CodeModel::Small || |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 347 | (CM == CodeModel::Medium && (Global || |
| 348 | Reason != DwarfEncoding::Data))) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 349 | Format = DW_EH_PE_sdata4; |
| 350 | else |
| 351 | Format = DW_EH_PE_sdata8; |
| 352 | } |
| 353 | |
| 354 | if (Global) |
| 355 | Format |= DW_EH_PE_indirect; |
| 356 | |
| 357 | return (Format | DW_EH_PE_pcrel); |
| 358 | } else { |
| 359 | if (Subtarget->is64Bit() && |
| 360 | (CM == CodeModel::Small || |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 361 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 362 | return DW_EH_PE_udata4; |
| 363 | else |
| 364 | return DW_EH_PE_absptr; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | default: |
| 369 | return TargetAsmInfo::PreferredEHDataFormat(Reason, Global); |
| 370 | } |
| 371 | } |
| 372 | |