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