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 | X86TM = &TM; |
| 43 | |
Andrew Lenharth | 6c0695f | 2006-11-28 19:52:49 +0000 | [diff] [blame] | 44 | AsmTransCBE = x86_asm_table; |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 45 | |
Bill Wendling | cb90099 | 2007-01-16 09:29:17 +0000 | [diff] [blame] | 46 | AssemblerDialect = Subtarget->getAsmFlavor(); |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 47 | } |
Chris Lattner | afbfded | 2006-10-05 02:43:52 +0000 | [diff] [blame] | 48 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 49 | bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const { |
| 50 | // FIXME: this should verify that we are targetting a 486 or better. If not, |
| 51 | // we will turn this bswap into something that will be lowered to logical ops |
| 52 | // instead of emitting the bswap asm. For now, we don't support 486 or lower |
| 53 | // so don't worry about this. |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 54 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 55 | // Verify this is a simple bswap. |
| 56 | if (CI->getNumOperands() != 2 || |
| 57 | CI->getType() != CI->getOperand(1)->getType() || |
Chris Lattner | 42a7551 | 2007-01-15 02:27:26 +0000 | [diff] [blame] | 58 | !CI->getType()->isInteger()) |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 59 | return false; |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 60 | |
Chris Lattner | 3e9f1d0 | 2007-04-01 20:49:36 +0000 | [diff] [blame] | 61 | const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| 62 | if (!Ty || Ty->getBitWidth() % 16 != 0) |
Reid Spencer | a54b7cb | 2007-01-12 07:05:14 +0000 | [diff] [blame] | 63 | return false; |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 64 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 65 | // Okay, we can do this xform, do so now. |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 66 | const Type *Tys[] = { Ty }; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 67 | Module *M = CI->getParent()->getParent()->getParent(); |
Chandler Carruth | 6994040 | 2007-08-04 01:51:18 +0000 | [diff] [blame] | 68 | Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1); |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 69 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 70 | Value *Op = CI->getOperand(1); |
Gabor Greif | 051a950 | 2008-04-06 20:25:17 +0000 | [diff] [blame] | 71 | Op = CallInst::Create(Int, Op, CI->getName(), CI); |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 73 | CI->replaceAllUsesWith(Op); |
| 74 | CI->eraseFromParent(); |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const { |
| 80 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 81 | std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints(); |
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 | std::string AsmStr = IA->getAsmString(); |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 84 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 85 | // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a" |
| 86 | std::vector<std::string> AsmPieces; |
| 87 | SplitString(AsmStr, AsmPieces, "\n"); // ; as separator? |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 88 | |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 89 | switch (AsmPieces.size()) { |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 90 | default: return false; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 91 | case 1: |
| 92 | AsmStr = AsmPieces[0]; |
| 93 | AsmPieces.clear(); |
| 94 | SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace. |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 95 | |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 96 | // bswap $0 |
Anton Korobeynikov | 8210045 | 2008-07-09 13:20:27 +0000 | [diff] [blame] | 97 | if (AsmPieces.size() == 2 && |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 98 | AsmPieces[0] == "bswap" && AsmPieces[1] == "$0") { |
| 99 | // No need to check constraints, nothing other than the equivalent of |
| 100 | // "=r,0" would be valid here. |
| 101 | return LowerToBSwap(CI); |
| 102 | } |
| 103 | break; |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 104 | case 3: |
Reid Spencer | 4785781 | 2006-12-31 05:55:36 +0000 | [diff] [blame] | 105 | if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 && |
Chris Lattner | 5d52135 | 2006-11-29 01:48:01 +0000 | [diff] [blame] | 106 | Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" && |
| 107 | Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") { |
| 108 | // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64 |
| 109 | std::vector<std::string> Words; |
| 110 | SplitString(AsmPieces[0], Words, " \t"); |
| 111 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") { |
| 112 | Words.clear(); |
| 113 | SplitString(AsmPieces[1], Words, " \t"); |
| 114 | if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") { |
| 115 | Words.clear(); |
| 116 | SplitString(AsmPieces[2], Words, " \t,"); |
| 117 | if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" && |
| 118 | Words[2] == "%edx") { |
| 119 | return LowerToBSwap(CI); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | break; |
Chris Lattner | 625bd05 | 2006-11-29 01:14:06 +0000 | [diff] [blame] | 125 | } |
| 126 | return false; |
| 127 | } |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 128 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 129 | X86DarwinTargetAsmInfo::X86DarwinTargetAsmInfo(const X86TargetMachine &TM): |
| 130 | X86TargetAsmInfo(TM) { |
| 131 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 132 | |
| 133 | AlignmentIsInBytes = false; |
| 134 | TextAlignFillValue = 0x90; |
| 135 | GlobalPrefix = "_"; |
| 136 | if (!is64Bit) |
| 137 | Data64bitsDirective = 0; // we can't emit a 64-bit unit |
| 138 | ZeroDirective = "\t.space\t"; // ".space N" emits N zeros. |
| 139 | PrivateGlobalPrefix = "L"; // Marker for constant pool idxs |
| 140 | BSSSection = 0; // no BSS section. |
| 141 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
| 142 | ConstantPoolSection = "\t.const\n"; |
| 143 | JumpTableDataSection = "\t.const\n"; |
| 144 | CStringSection = "\t.cstring"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 145 | CStringSection_ = getUnnamedSection("\t.cstring", |
| 146 | SectionFlags::Mergeable | SectionFlags::Strings); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 147 | FourByteConstantSection = "\t.literal4\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 148 | FourByteConstantSection_ = getUnnamedSection("\t.literal4\n", |
| 149 | SectionFlags::Mergeable); |
| 150 | EightByteConstantSection_ = getUnnamedSection("\t.literal8\n", |
| 151 | SectionFlags::Mergeable); |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 152 | // FIXME: Why don't always use this section? |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 153 | if (is64Bit) { |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 154 | SixteenByteConstantSection = "\t.literal16\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 155 | SixteenByteConstantSection_ = getUnnamedSection("\t.literal16\n", |
| 156 | SectionFlags::Mergeable); |
| 157 | } |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 158 | ReadOnlySection = "\t.const\n"; |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 159 | ReadOnlySection_ = getUnnamedSection("\t.const\n", SectionFlags::None); |
| 160 | TextCoalSection = |
| 161 | getUnnamedSection(".section __TEXT,__textcoal_nt,coalesced,pure_instructions", |
| 162 | SectionFlags::Code); |
| 163 | ConstDataCoalSection = |
| 164 | getUnnamedSection(".section __DATA,__const_coal,coalesced", |
| 165 | SectionFlags::None); |
| 166 | ConstDataSection = getUnnamedSection(".const_data", SectionFlags::None); |
| 167 | DataCoalSection = getUnnamedSection(".section __DATA,__datacoal_nt,coalesced", |
| 168 | SectionFlags::Writeable); |
| 169 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 170 | LCOMMDirective = "\t.lcomm\t"; |
| 171 | SwitchToSectionDirective = "\t.section "; |
| 172 | StringConstantPrefix = "\1LC"; |
| 173 | COMMDirectiveTakesAlignment = false; |
| 174 | HasDotTypeDotSizeDirective = false; |
| 175 | if (TM.getRelocationModel() == Reloc::Static) { |
| 176 | StaticCtorsSection = ".constructor"; |
| 177 | StaticDtorsSection = ".destructor"; |
| 178 | } else { |
| 179 | StaticCtorsSection = ".mod_init_func"; |
| 180 | StaticDtorsSection = ".mod_term_func"; |
| 181 | } |
| 182 | if (is64Bit) { |
| 183 | PersonalityPrefix = ""; |
| 184 | PersonalitySuffix = "+4@GOTPCREL"; |
| 185 | } else { |
| 186 | PersonalityPrefix = "L"; |
| 187 | PersonalitySuffix = "$non_lazy_ptr"; |
| 188 | } |
| 189 | NeedsIndirectEncoding = true; |
| 190 | InlineAsmStart = "## InlineAsm Start"; |
| 191 | InlineAsmEnd = "## InlineAsm End"; |
| 192 | CommentString = "##"; |
| 193 | SetDirective = "\t.set"; |
| 194 | PCSymbol = "."; |
| 195 | UsedDirective = "\t.no_dead_strip\t"; |
| 196 | WeakDefDirective = "\t.weak_definition "; |
| 197 | WeakRefDirective = "\t.weak_reference "; |
| 198 | HiddenDirective = "\t.private_extern "; |
| 199 | ProtectedDirective = "\t.globl\t"; |
| 200 | |
| 201 | // In non-PIC modes, emit a special label before jump tables so that the |
| 202 | // linker can perform more accurate dead code stripping. |
| 203 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 204 | // Emit a local label that is preserved until the linker runs. |
| 205 | JumpTableSpecialLabelPrefix = "l"; |
| 206 | } |
| 207 | |
| 208 | SupportsDebugInformation = true; |
| 209 | NeedsSet = true; |
| 210 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 211 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 212 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 213 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 214 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 215 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 216 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 217 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 218 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 219 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 220 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
| 221 | |
| 222 | // Exceptions handling |
| 223 | SupportsExceptionHandling = true; |
| 224 | GlobalEHDirective = "\t.globl\t"; |
| 225 | SupportsWeakOmittedEHFrame = false; |
| 226 | AbsoluteEHSectionOffsets = false; |
| 227 | DwarfEHFrameSection = |
| 228 | ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support"; |
| 229 | DwarfExceptionSection = ".section __DATA,__gcc_except_tab"; |
| 230 | } |
| 231 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 232 | unsigned |
| 233 | X86DarwinTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 234 | bool Global) const { |
| 235 | if (Reason == DwarfEncoding::Functions && Global) |
| 236 | return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4); |
| 237 | else if (Reason == DwarfEncoding::CodeLabels || !Global) |
| 238 | return DW_EH_PE_pcrel; |
| 239 | else |
| 240 | return DW_EH_PE_absptr; |
| 241 | } |
| 242 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 243 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 244 | X86DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
| 245 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
Anton Korobeynikov | c33a744 | 2008-07-09 13:27:59 +0000 | [diff] [blame] | 246 | bool isWeak = GV->isWeakForLinker(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 247 | |
| 248 | switch (Kind) { |
| 249 | case SectionKind::Text: |
| 250 | if (isWeak) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 251 | return TextCoalSection; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 252 | else |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 253 | return getTextSection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 254 | case SectionKind::Data: |
| 255 | case SectionKind::ThreadData: |
| 256 | case SectionKind::BSS: |
| 257 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 258 | if (cast<GlobalVariable>(GV)->isConstant()) |
| 259 | return (isWeak ? ConstDataCoalSection : ConstDataSection); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 260 | else |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 261 | return (isWeak ? DataCoalSection : getDataSection_()); |
| 262 | case SectionKind::ROData: |
| 263 | return (isWeak ? ConstDataCoalSection : getReadOnlySection_()); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 264 | case SectionKind::RODataMergeStr: |
| 265 | return MergeableStringSection(cast<GlobalVariable>(GV)); |
| 266 | case SectionKind::RODataMergeConst: |
| 267 | return MergeableConstSection(cast<GlobalVariable>(GV)); |
| 268 | default: |
| 269 | assert(0 && "Unsuported section kind for global"); |
| 270 | } |
| 271 | |
| 272 | // FIXME: Do we have any extra special weird cases? |
| 273 | } |
| 274 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 275 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 276 | X86DarwinTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 277 | const TargetData *TD = X86TM->getTargetData(); |
| 278 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 279 | const Type *Type = cast<ConstantArray>(C)->getType()->getElementType(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 280 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 281 | unsigned Size = TD->getABITypeSize(Type); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 282 | if (Size) { |
| 283 | const TargetData *TD = X86TM->getTargetData(); |
| 284 | unsigned Align = TD->getPreferredAlignment(GV); |
| 285 | if (Align <= 32) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 286 | return getCStringSection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 289 | return getReadOnlySection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 292 | const Section* |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 293 | X86DarwinTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 294 | const TargetData *TD = X86TM->getTargetData(); |
| 295 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 296 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 297 | unsigned Size = TD->getABITypeSize(C->getType()); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 298 | if (Size == 4) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 299 | return FourByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 300 | else if (Size == 8) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 301 | return EightByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 302 | else if (Size == 16 && X86TM->getSubtarget<X86Subtarget>().is64Bit()) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 303 | return SixteenByteConstantSection_; |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 304 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 305 | return getReadOnlySection_(); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | std::string |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 309 | X86DarwinTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 310 | SectionKind::Kind kind) const { |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 311 | assert(0 && "Darwin does not use unique sections"); |
| 312 | return ""; |
| 313 | } |
| 314 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 315 | X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM): |
| 316 | X86TargetAsmInfo(TM) { |
| 317 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 318 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 319 | TextSection_ = getUnnamedSection("\t.text", SectionFlags::Code); |
| 320 | DataSection_ = getUnnamedSection("\t.data", SectionFlags::Writeable); |
| 321 | BSSSection_ = getUnnamedSection("\t.bss", |
| 322 | SectionFlags::Writeable | SectionFlags::BSS); |
| 323 | ReadOnlySection_ = getUnnamedSection("\t.rodata", SectionFlags::None); |
| 324 | TLSDataSection_ = getNamedSection("\t.tdata", |
| 325 | SectionFlags::Writeable | SectionFlags::TLS); |
| 326 | TLSBSSSection_ = getNamedSection("\t.tbss", |
| 327 | SectionFlags::Writeable | SectionFlags::TLS | SectionFlags::BSS); |
| 328 | |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 329 | ReadOnlySection = ".rodata"; |
Anton Korobeynikov | 2a88917 | 2008-07-09 13:25:46 +0000 | [diff] [blame] | 330 | FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4"; |
| 331 | EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8"; |
| 332 | SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16"; |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 333 | CStringSection = ".rodata.str"; |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 334 | PrivateGlobalPrefix = ".L"; |
| 335 | WeakRefDirective = "\t.weak\t"; |
| 336 | SetDirective = "\t.set\t"; |
| 337 | PCSymbol = "."; |
| 338 | |
| 339 | // Set up DWARF directives |
| 340 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 341 | |
| 342 | // Debug Information |
| 343 | AbsoluteDebugSectionOffsets = true; |
| 344 | SupportsDebugInformation = true; |
| 345 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits"; |
| 346 | DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits"; |
| 347 | DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits"; |
| 348 | DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits"; |
| 349 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits"; |
| 350 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits"; |
| 351 | DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits"; |
| 352 | DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits"; |
| 353 | DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits"; |
| 354 | DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits"; |
| 355 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits"; |
| 356 | |
| 357 | // Exceptions handling |
| 358 | if (!is64Bit) |
| 359 | SupportsExceptionHandling = true; |
| 360 | AbsoluteEHSectionOffsets = false; |
| 361 | DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits"; |
| 362 | DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits"; |
| 363 | |
| 364 | // On Linux we must declare when we can use a non-executable stack. |
| 365 | if (X86TM->getSubtarget<X86Subtarget>().isLinux()) |
| 366 | NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits"; |
| 367 | } |
| 368 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 369 | unsigned |
| 370 | X86ELFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 371 | bool Global) const { |
| 372 | CodeModel::Model CM = X86TM->getCodeModel(); |
| 373 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
| 374 | |
| 375 | if (X86TM->getRelocationModel() == Reloc::PIC_) { |
| 376 | unsigned Format = 0; |
| 377 | |
| 378 | if (!is64Bit) |
| 379 | // 32 bit targets always encode pointers as 4 bytes |
| 380 | Format = DW_EH_PE_sdata4; |
| 381 | else { |
| 382 | // 64 bit targets encode pointers in 4 bytes iff: |
| 383 | // - code model is small OR |
| 384 | // - code model is medium and we're emitting externally visible symbols |
| 385 | // or any code symbols |
| 386 | if (CM == CodeModel::Small || |
| 387 | (CM == CodeModel::Medium && (Global || |
| 388 | Reason != DwarfEncoding::Data))) |
| 389 | Format = DW_EH_PE_sdata4; |
| 390 | else |
| 391 | Format = DW_EH_PE_sdata8; |
| 392 | } |
| 393 | |
| 394 | if (Global) |
| 395 | Format |= DW_EH_PE_indirect; |
| 396 | |
| 397 | return (Format | DW_EH_PE_pcrel); |
| 398 | } else { |
| 399 | if (is64Bit && |
| 400 | (CM == CodeModel::Small || |
| 401 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 402 | return DW_EH_PE_udata4; |
| 403 | else |
| 404 | return DW_EH_PE_absptr; |
| 405 | } |
| 406 | } |
| 407 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 408 | const Section* |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 409 | X86ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 410 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 411 | |
| 412 | if (const Function *F = dyn_cast<Function>(GV)) { |
| 413 | switch (F->getLinkage()) { |
| 414 | default: assert(0 && "Unknown linkage type!"); |
| 415 | case Function::InternalLinkage: |
| 416 | case Function::DLLExportLinkage: |
| 417 | case Function::ExternalLinkage: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 418 | return getTextSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 419 | case Function::WeakLinkage: |
| 420 | case Function::LinkOnceLinkage: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 421 | std::string Name = UniqueSectionForGlobal(GV, Kind); |
| 422 | unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); |
| 423 | return getNamedSection(Name.c_str(), Flags); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 424 | } |
| 425 | } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 426 | if (GVar->isWeakForLinker()) { |
| 427 | std::string Name = UniqueSectionForGlobal(GVar, Kind); |
| 428 | unsigned Flags = SectionFlagsForGlobal(GVar, Name.c_str()); |
| 429 | return getNamedSection(Name.c_str(), Flags); |
| 430 | } else { |
| 431 | switch (Kind) { |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 432 | case SectionKind::Data: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 433 | return getDataSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 434 | case SectionKind::BSS: |
| 435 | // ELF targets usually have BSS sections |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 436 | return getBSSSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 437 | case SectionKind::ROData: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 438 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 439 | case SectionKind::RODataMergeStr: |
| 440 | return MergeableStringSection(GVar); |
| 441 | case SectionKind::RODataMergeConst: |
| 442 | return MergeableConstSection(GVar); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 443 | case SectionKind::ThreadData: |
| 444 | // ELF targets usually support TLS stuff |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 445 | return getTLSDataSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 446 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 447 | return getTLSBSSSection_(); |
Anton Korobeynikov | 4260ad3 | 2008-07-09 13:23:08 +0000 | [diff] [blame] | 448 | default: |
| 449 | assert(0 && "Unsuported section kind for global"); |
| 450 | } |
| 451 | } |
| 452 | } else |
| 453 | assert(0 && "Unsupported global"); |
| 454 | } |
| 455 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 456 | const Section* |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 457 | X86ELFTargetAsmInfo::MergeableConstSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 458 | const TargetData *TD = X86TM->getTargetData(); |
| 459 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 460 | const Type *Type = C->getType(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 461 | |
| 462 | // FIXME: string here is temporary, until stuff will fully land in. |
Anton Korobeynikov | 2a88917 | 2008-07-09 13:25:46 +0000 | [diff] [blame] | 463 | // We cannot use {Four,Eight,Sixteen}ByteConstantSection here, since it's |
| 464 | // currently directly used by asmprinter. |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 465 | unsigned Size = TD->getABITypeSize(Type); |
| 466 | if (Size == 4 || Size == 8 || Size == 16) { |
| 467 | std::string Name = ".rodata.cst" + utostr(Size); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 468 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 469 | return getNamedSection(Name.c_str(), |
| 470 | SectionFlags::setEntitySize(SectionFlags::Mergeable, |
| 471 | Size)); |
| 472 | } |
| 473 | |
| 474 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 477 | const Section* |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 478 | X86ELFTargetAsmInfo::MergeableStringSection(const GlobalVariable *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 479 | const TargetData *TD = X86TM->getTargetData(); |
| 480 | Constant *C = cast<GlobalVariable>(GV)->getInitializer(); |
| 481 | const ConstantArray *CVA = cast<ConstantArray>(C); |
| 482 | const Type *Type = CVA->getType()->getElementType(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 483 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 484 | unsigned Size = TD->getABITypeSize(Type); |
| 485 | if (Size <= 16) { |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 486 | // We also need alignment here |
| 487 | const TargetData *TD = X86TM->getTargetData(); |
| 488 | unsigned Align = TD->getPreferredAlignment(GV); |
| 489 | if (Align < Size) |
| 490 | Align = Size; |
| 491 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 492 | std::string Name = getCStringSection() + utostr(Size) + '.' + utostr(Align); |
| 493 | unsigned Flags = SectionFlags::setEntitySize(SectionFlags::Mergeable | |
| 494 | SectionFlags::Strings, |
| 495 | Size); |
| 496 | return getNamedSection(Name.c_str(), Flags); |
Anton Korobeynikov | 4039e68 | 2008-07-09 13:23:57 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame^] | 499 | return getReadOnlySection_(); |
Anton Korobeynikov | 01b0e24 | 2008-07-09 13:23:37 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 502 | std::string X86ELFTargetAsmInfo::PrintSectionFlags(unsigned flags) const { |
| 503 | std::string Flags = ",\""; |
| 504 | |
| 505 | if (!(flags & SectionFlags::Debug)) |
| 506 | Flags += 'a'; |
| 507 | if (flags & SectionFlags::Code) |
| 508 | Flags += 'x'; |
| 509 | if (flags & SectionFlags::Writeable) |
| 510 | Flags += 'w'; |
| 511 | if (flags & SectionFlags::Mergeable) |
| 512 | Flags += 'M'; |
| 513 | if (flags & SectionFlags::Strings) |
| 514 | Flags += 'S'; |
| 515 | if (flags & SectionFlags::TLS) |
| 516 | Flags += 'T'; |
| 517 | |
| 518 | Flags += "\""; |
| 519 | |
| 520 | // FIXME: There can be exceptions here |
| 521 | if (flags & SectionFlags::BSS) |
| 522 | Flags += ",@nobits"; |
| 523 | else |
| 524 | Flags += ",@progbits"; |
| 525 | |
Anton Korobeynikov | 6d82942 | 2008-07-09 13:22:17 +0000 | [diff] [blame] | 526 | if (unsigned entitySize = SectionFlags::getEntitySize(flags)) |
| 527 | Flags += "," + utostr(entitySize); |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 528 | |
| 529 | return Flags; |
| 530 | } |
| 531 | |
Anton Korobeynikov | 4468b7a | 2008-07-09 13:20:48 +0000 | [diff] [blame] | 532 | X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM): |
| 533 | X86TargetAsmInfo(TM) { |
| 534 | GlobalPrefix = "_"; |
| 535 | LCOMMDirective = "\t.lcomm\t"; |
| 536 | COMMDirectiveTakesAlignment = false; |
| 537 | HasDotTypeDotSizeDirective = false; |
| 538 | StaticCtorsSection = "\t.section .ctors,\"aw\""; |
| 539 | StaticDtorsSection = "\t.section .dtors,\"aw\""; |
| 540 | HiddenDirective = NULL; |
| 541 | PrivateGlobalPrefix = "L"; // Prefix for private global symbols |
| 542 | WeakRefDirective = "\t.weak\t"; |
| 543 | SetDirective = "\t.set\t"; |
| 544 | |
| 545 | // Set up DWARF directives |
| 546 | HasLEB128 = true; // Target asm supports leb128 directives (little-endian) |
| 547 | AbsoluteDebugSectionOffsets = true; |
| 548 | AbsoluteEHSectionOffsets = false; |
| 549 | SupportsDebugInformation = true; |
| 550 | DwarfSectionOffsetDirective = "\t.secrel32\t"; |
| 551 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\""; |
| 552 | DwarfInfoSection = "\t.section\t.debug_info,\"dr\""; |
| 553 | DwarfLineSection = "\t.section\t.debug_line,\"dr\""; |
| 554 | DwarfFrameSection = "\t.section\t.debug_frame,\"dr\""; |
| 555 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\""; |
| 556 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\""; |
| 557 | DwarfStrSection = "\t.section\t.debug_str,\"dr\""; |
| 558 | DwarfLocSection = "\t.section\t.debug_loc,\"dr\""; |
| 559 | DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\""; |
| 560 | DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\""; |
| 561 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\""; |
| 562 | } |
| 563 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 564 | unsigned |
| 565 | X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
| 566 | bool Global) const { |
| 567 | CodeModel::Model CM = X86TM->getCodeModel(); |
| 568 | bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit(); |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 569 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 570 | if (X86TM->getRelocationModel() == Reloc::PIC_) { |
| 571 | unsigned Format = 0; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 572 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 573 | if (!is64Bit) |
| 574 | // 32 bit targets always encode pointers as 4 bytes |
| 575 | Format = DW_EH_PE_sdata4; |
| 576 | else { |
| 577 | // 64 bit targets encode pointers in 4 bytes iff: |
| 578 | // - code model is small OR |
| 579 | // - code model is medium and we're emitting externally visible symbols |
| 580 | // or any code symbols |
| 581 | if (CM == CodeModel::Small || |
| 582 | (CM == CodeModel::Medium && (Global || |
| 583 | Reason != DwarfEncoding::Data))) |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 584 | Format = DW_EH_PE_sdata4; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 585 | else |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 586 | Format = DW_EH_PE_sdata8; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 587 | } |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 588 | |
Anton Korobeynikov | b9e58ef | 2008-07-09 13:21:08 +0000 | [diff] [blame] | 589 | if (Global) |
| 590 | Format |= DW_EH_PE_indirect; |
| 591 | |
| 592 | return (Format | DW_EH_PE_pcrel); |
| 593 | } else { |
| 594 | if (is64Bit && |
| 595 | (CM == CodeModel::Small || |
| 596 | (CM == CodeModel::Medium && Reason != DwarfEncoding::Data))) |
| 597 | return DW_EH_PE_udata4; |
| 598 | else |
| 599 | return DW_EH_PE_absptr; |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 603 | std::string |
| 604 | X86COFFTargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
| 605 | SectionKind::Kind kind) const { |
| 606 | switch (kind) { |
| 607 | case SectionKind::Text: |
| 608 | return ".text$linkonce" + GV->getName(); |
| 609 | case SectionKind::Data: |
| 610 | case SectionKind::BSS: |
| 611 | case SectionKind::ThreadData: |
| 612 | case SectionKind::ThreadBSS: |
| 613 | return ".data$linkonce" + GV->getName(); |
| 614 | case SectionKind::ROData: |
| 615 | case SectionKind::RODataMergeConst: |
| 616 | case SectionKind::RODataMergeStr: |
| 617 | return ".rdata$linkonce" + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 618 | default: |
Anton Korobeynikov | b9a02fc | 2008-07-09 13:21:29 +0000 | [diff] [blame] | 619 | assert(0 && "Unknown section kind"); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 620 | } |
| 621 | } |
| 622 | |
Anton Korobeynikov | f447e3d | 2008-07-09 13:21:49 +0000 | [diff] [blame] | 623 | std::string X86COFFTargetAsmInfo::PrintSectionFlags(unsigned flags) const { |
| 624 | std::string Flags = ",\""; |
| 625 | |
| 626 | if (flags & SectionFlags::Code) |
| 627 | Flags += 'x'; |
| 628 | if (flags & SectionFlags::Writeable) |
| 629 | Flags += 'w'; |
| 630 | |
| 631 | Flags += "\""; |
| 632 | |
| 633 | return Flags; |
| 634 | } |
| 635 | |
| 636 | X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM): |
| 637 | X86TargetAsmInfo(TM) { |
| 638 | GlobalPrefix = "_"; |
| 639 | CommentString = ";"; |
| 640 | |
| 641 | PrivateGlobalPrefix = "$"; |
| 642 | AlignDirective = "\talign\t"; |
| 643 | ZeroDirective = "\tdb\t"; |
| 644 | ZeroDirectiveSuffix = " dup(0)"; |
| 645 | AsciiDirective = "\tdb\t"; |
| 646 | AscizDirective = 0; |
| 647 | Data8bitsDirective = "\tdb\t"; |
| 648 | Data16bitsDirective = "\tdw\t"; |
| 649 | Data32bitsDirective = "\tdd\t"; |
| 650 | Data64bitsDirective = "\tdq\t"; |
| 651 | HasDotTypeDotSizeDirective = false; |
| 652 | |
| 653 | TextSection = "_text"; |
| 654 | DataSection = "_data"; |
| 655 | JumpTableDataSection = NULL; |
| 656 | SwitchToSectionDirective = ""; |
| 657 | TextSectionStartSuffix = "\tsegment 'CODE'"; |
| 658 | DataSectionStartSuffix = "\tsegment 'DATA'"; |
| 659 | SectionEndDirectiveSuffix = "\tends\n"; |
| 660 | } |