blob: 513e8f0e6ce717fa3d57c31f74e6986ba29871b0 [file] [log] [blame]
Jim Laskey8e8de8f2006-09-07 22:05:02 +00001//===-- X86TargetAsmInfo.cpp - X86 asm properties ---------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Jim Laskey8e8de8f2006-09-07 22:05:02 +00007//
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 Spencer7aa8a452007-01-12 23:22:14 +000017#include "llvm/DerivedTypes.h"
Chris Lattner625bd052006-11-29 01:14:06 +000018#include "llvm/InlineAsm.h"
19#include "llvm/Instructions.h"
Chris Lattner3e9f1d02007-04-01 20:49:36 +000020#include "llvm/Intrinsics.h"
Chris Lattner625bd052006-11-29 01:14:06 +000021#include "llvm/Module.h"
22#include "llvm/ADT/StringExtras.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000023#include "llvm/Support/Dwarf.h"
24
Jim Laskey8e8de8f2006-09-07 22:05:02 +000025using namespace llvm;
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000026using namespace llvm::dwarf;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000027
Dan Gohmancfbb2f02008-03-25 21:45:14 +000028static const char *const x86_asm_table[] = {
29 "{si}", "S",
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000030 "{di}", "D",
31 "{ax}", "a",
32 "{cx}", "c",
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000033 "{memory}", "memory",
34 "{flags}", "",
35 "{dirflag}", "",
36 "{fpsr}", "",
37 "{cc}", "cc",
38 0,0};
39
Jim Laskey8e8de8f2006-09-07 22:05:02 +000040X86TargetAsmInfo::X86TargetAsmInfo(const X86TargetMachine &TM) {
41 const X86Subtarget *Subtarget = &TM.getSubtarget<X86Subtarget>();
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000042 X86TM = &TM;
43
Chris Lattnerafbfded2006-10-05 02:43:52 +000044 // FIXME - Should be simplified.
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000045
46 AsmTransCBE = x86_asm_table;
47
Jim Laskey8e8de8f2006-09-07 22:05:02 +000048 switch (Subtarget->TargetType) {
49 case X86Subtarget::isDarwin:
50 AlignmentIsInBytes = false;
Evan Chengfb8075d2008-02-28 00:43:03 +000051 TextAlignFillValue = 0x90;
Jim Laskey8e8de8f2006-09-07 22:05:02 +000052 GlobalPrefix = "_";
Evan Cheng25ab6902006-09-08 06:48:29 +000053 if (!Subtarget->is64Bit())
54 Data64bitsDirective = 0; // we can't emit a 64-bit unit
Jim Laskey8e8de8f2006-09-07 22:05:02 +000055 ZeroDirective = "\t.space\t"; // ".space N" emits N zeros.
56 PrivateGlobalPrefix = "L"; // Marker for constant pool idxs
Chris Lattner42ca4502007-01-17 17:43:33 +000057 BSSSection = 0; // no BSS section.
58 ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill
Jim Laskey8e8de8f2006-09-07 22:05:02 +000059 ConstantPoolSection = "\t.const\n";
Chris Lattnerafbfded2006-10-05 02:43:52 +000060 JumpTableDataSection = "\t.const\n";
Evan Cheng8910c1c2006-10-26 19:18:18 +000061 CStringSection = "\t.cstring";
Jim Laskey8e8de8f2006-09-07 22:05:02 +000062 FourByteConstantSection = "\t.literal4\n";
63 EightByteConstantSection = "\t.literal8\n";
Evan Cheng25ab6902006-09-08 06:48:29 +000064 if (Subtarget->is64Bit())
65 SixteenByteConstantSection = "\t.literal16\n";
Evan Chengf0b5d562007-03-08 01:07:07 +000066 ReadOnlySection = "\t.const\n";
Jim Laskey8e8de8f2006-09-07 22:05:02 +000067 LCOMMDirective = "\t.lcomm\t";
Dale Johannesen4af34942008-01-15 23:24:56 +000068 SwitchToSectionDirective = "\t.section ";
Jim Laskey8e8de8f2006-09-07 22:05:02 +000069 COMMDirectiveTakesAlignment = false;
70 HasDotTypeDotSizeDirective = false;
Evan Chengb267ca12007-01-30 08:04:53 +000071 if (TM.getRelocationModel() == Reloc::Static) {
72 StaticCtorsSection = ".constructor";
73 StaticDtorsSection = ".destructor";
74 } else {
75 StaticCtorsSection = ".mod_init_func";
76 StaticDtorsSection = ".mod_term_func";
77 }
Dale Johannesen4af34942008-01-15 23:24:56 +000078 if (Subtarget->is64Bit()) {
79 PersonalityPrefix = "";
80 PersonalitySuffix = "+4@GOTPCREL";
81 } else {
82 PersonalityPrefix = "L";
83 PersonalitySuffix = "$non_lazy_ptr";
84 }
Bill Wendlingef4a6612007-09-11 17:20:55 +000085 NeedsIndirectEncoding = true;
Dale Johannesen27c31052008-03-25 23:29:30 +000086 InlineAsmStart = "## InlineAsm Start";
87 InlineAsmEnd = "## InlineAsm End";
88 CommentString = "##";
Jim Laskey8e8de8f2006-09-07 22:05:02 +000089 SetDirective = "\t.set";
Bill Wendlingadbda022007-08-22 18:44:05 +000090 PCSymbol = ".";
Chris Lattnera53115b2006-09-26 03:39:53 +000091 UsedDirective = "\t.no_dead_strip\t";
Dale Johannesen038129d2008-01-10 02:03:30 +000092 WeakDefDirective = "\t.weak_definition ";
93 WeakRefDirective = "\t.weak_reference ";
Dale Johannesenc7406ae2008-01-11 00:54:37 +000094 HiddenDirective = "\t.private_extern ";
Bill Wendlingbebc3642008-03-18 23:38:12 +000095 ProtectedDirective = "\t.globl\t";
Jim Laskey8e8de8f2006-09-07 22:05:02 +000096
Chris Lattnerb266ccd2007-01-18 01:15:58 +000097 // In non-PIC modes, emit a special label before jump tables so that the
98 // linker can perform more accurate dead code stripping.
99 if (TM.getRelocationModel() != Reloc::PIC_) {
100 // Emit a local label that is preserved until the linker runs.
101 JumpTableSpecialLabelPrefix = "l";
102 }
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000103
104 SupportsDebugInformation = true;
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000105 NeedsSet = true;
106 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
107 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
108 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
109 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
110 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
111 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
112 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
113 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
114 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
115 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
116 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
Anton Korobeynikov095546c2007-08-21 00:31:30 +0000117
118 // Exceptions handling
Dale Johannesen4af34942008-01-15 23:24:56 +0000119 SupportsExceptionHandling = true;
Dale Johannesen038129d2008-01-10 02:03:30 +0000120 GlobalEHDirective = "\t.globl\t";
121 SupportsWeakOmittedEHFrame = false;
Anton Korobeynikov095546c2007-08-21 00:31:30 +0000122 AbsoluteEHSectionOffsets = false;
Dale Johannesen4af34942008-01-15 23:24:56 +0000123 if (Subtarget->is64Bit())
124 ShortenEHDataOn64Bit = true;
Anton Korobeynikov095546c2007-08-21 00:31:30 +0000125 DwarfEHFrameSection =
126 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
127 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000128 break;
Reid Spencer02b85112006-10-30 22:32:30 +0000129
130 case X86Subtarget::isELF:
Dan Gohman6445f612007-06-27 15:09:47 +0000131 ReadOnlySection = "\t.section\t.rodata";
Dan Gohman6f858e22007-05-03 16:38:57 +0000132 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
133 EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000134 SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
Dan Gohman6f858e22007-05-03 16:38:57 +0000135 CStringSection = "\t.section\t.rodata.str1.1,\"aMS\",@progbits,1";
Chris Lattnera3bfdd42007-01-03 18:16:48 +0000136 PrivateGlobalPrefix = ".L";
Evan Cheng8752ce62006-12-01 20:47:11 +0000137 WeakRefDirective = "\t.weak\t";
Anton Korobeynikov8b0a8c82007-04-25 14:27:10 +0000138 SetDirective = "\t.set\t";
Anton Korobeynikovedb4a6b2007-05-01 10:19:31 +0000139 PCSymbol = ".";
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000140
141 // Set up DWARF directives
142 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
Anton Korobeynikov59db3ec2007-07-25 00:06:28 +0000143
144 // Debug Information
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000145 AbsoluteDebugSectionOffsets = true;
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000146 SupportsDebugInformation = true;
Reid Spencer02b85112006-10-30 22:32:30 +0000147 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
148 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
149 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
150 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
151 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
152 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
153 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
154 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
155 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
156 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
157 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
Anton Korobeynikov2365f512007-07-14 14:06:15 +0000158
Anton Korobeynikov59db3ec2007-07-25 00:06:28 +0000159 // Exceptions handling
Anton Korobeynikov2365f512007-07-14 14:06:15 +0000160 if (!Subtarget->is64Bit())
161 SupportsExceptionHandling = true;
Anton Korobeynikov59db3ec2007-07-25 00:06:28 +0000162 AbsoluteEHSectionOffsets = false;
Anton Korobeynikov71144d82007-05-01 10:16:06 +0000163 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
164 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
Reid Spencer02b85112006-10-30 22:32:30 +0000165 break;
166
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000167 case X86Subtarget::isCygwin:
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000168 case X86Subtarget::isMingw:
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000169 GlobalPrefix = "_";
Anton Korobeynikov317848f2007-01-03 11:43:14 +0000170 LCOMMDirective = "\t.lcomm\t";
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000171 COMMDirectiveTakesAlignment = false;
172 HasDotTypeDotSizeDirective = false;
173 StaticCtorsSection = "\t.section .ctors,\"aw\"";
174 StaticDtorsSection = "\t.section .dtors,\"aw\"";
Anton Korobeynikov1a856452007-01-14 11:49:39 +0000175 HiddenDirective = NULL;
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000176 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
177 WeakRefDirective = "\t.weak\t";
178 SetDirective = "\t.set\t";
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000179
180 // Set up DWARF directives
181 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
Anton Korobeynikov79dda2b2007-05-01 22:23:12 +0000182 AbsoluteDebugSectionOffsets = true;
183 AbsoluteEHSectionOffsets = false;
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000184 SupportsDebugInformation = true;
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000185 DwarfSectionOffsetDirective = "\t.secrel32\t";
Anton Korobeynikovab4022f2006-10-31 08:31:24 +0000186 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
187 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
188 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
189 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
190 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
191 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
192 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
193 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
194 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
195 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
196 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
197 break;
Bill Wendling11502862007-01-16 04:13:03 +0000198
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000199 case X86Subtarget::isWindows:
200 GlobalPrefix = "_";
201 HasDotTypeDotSizeDirective = false;
202 break;
Bill Wendling11502862007-01-16 04:13:03 +0000203
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000204 default: break;
205 }
206
207 if (Subtarget->isFlavorIntel()) {
208 GlobalPrefix = "_";
209 CommentString = ";";
210
211 PrivateGlobalPrefix = "$";
212 AlignDirective = "\talign\t";
213 ZeroDirective = "\tdb\t";
214 ZeroDirectiveSuffix = " dup(0)";
215 AsciiDirective = "\tdb\t";
216 AscizDirective = 0;
217 Data8bitsDirective = "\tdb\t";
218 Data16bitsDirective = "\tdw\t";
219 Data32bitsDirective = "\tdd\t";
220 Data64bitsDirective = "\tdq\t";
221 HasDotTypeDotSizeDirective = false;
222
223 TextSection = "_text";
224 DataSection = "_data";
Anton Korobeynikov24287dd2006-12-19 21:04:20 +0000225 JumpTableDataSection = NULL;
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000226 SwitchToSectionDirective = "";
227 TextSectionStartSuffix = "\tsegment 'CODE'";
228 DataSectionStartSuffix = "\tsegment 'DATA'";
229 SectionEndDirectiveSuffix = "\tends\n";
230 }
Bill Wendlingcb900992007-01-16 09:29:17 +0000231
Dan Gohmana779a982008-05-05 00:28:39 +0000232 // On Linux we must declare when we can use a non-executable stack.
Dan Gohman600bf162008-05-05 16:11:31 +0000233 if (Subtarget->isLinux())
Dan Gohmana779a982008-05-05 00:28:39 +0000234 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
235
Bill Wendlingcb900992007-01-16 09:29:17 +0000236 AssemblerDialect = Subtarget->getAsmFlavor();
Jim Laskey8e8de8f2006-09-07 22:05:02 +0000237}
Chris Lattnerafbfded2006-10-05 02:43:52 +0000238
Chris Lattner625bd052006-11-29 01:14:06 +0000239bool X86TargetAsmInfo::LowerToBSwap(CallInst *CI) const {
240 // FIXME: this should verify that we are targetting a 486 or better. If not,
241 // we will turn this bswap into something that will be lowered to logical ops
242 // instead of emitting the bswap asm. For now, we don't support 486 or lower
243 // so don't worry about this.
244
245 // Verify this is a simple bswap.
246 if (CI->getNumOperands() != 2 ||
247 CI->getType() != CI->getOperand(1)->getType() ||
Chris Lattner42a75512007-01-15 02:27:26 +0000248 !CI->getType()->isInteger())
Chris Lattner625bd052006-11-29 01:14:06 +0000249 return false;
250
Chris Lattner3e9f1d02007-04-01 20:49:36 +0000251 const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
252 if (!Ty || Ty->getBitWidth() % 16 != 0)
Reid Spencera54b7cb2007-01-12 07:05:14 +0000253 return false;
Chris Lattner3e9f1d02007-04-01 20:49:36 +0000254
Chris Lattner625bd052006-11-29 01:14:06 +0000255 // Okay, we can do this xform, do so now.
Chandler Carruth69940402007-08-04 01:51:18 +0000256 const Type *Tys[] = { Ty };
Chris Lattner625bd052006-11-29 01:14:06 +0000257 Module *M = CI->getParent()->getParent()->getParent();
Chandler Carruth69940402007-08-04 01:51:18 +0000258 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
Chris Lattner625bd052006-11-29 01:14:06 +0000259
260 Value *Op = CI->getOperand(1);
Gabor Greif051a9502008-04-06 20:25:17 +0000261 Op = CallInst::Create(Int, Op, CI->getName(), CI);
Chris Lattner625bd052006-11-29 01:14:06 +0000262
Chris Lattner625bd052006-11-29 01:14:06 +0000263 CI->replaceAllUsesWith(Op);
264 CI->eraseFromParent();
265 return true;
266}
267
268
269bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const {
270 InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
Chris Lattner5d521352006-11-29 01:48:01 +0000271 std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
Chris Lattner625bd052006-11-29 01:14:06 +0000272
273 std::string AsmStr = IA->getAsmString();
274
275 // TODO: should remove alternatives from the asmstring: "foo {a|b}" -> "foo a"
276 std::vector<std::string> AsmPieces;
277 SplitString(AsmStr, AsmPieces, "\n"); // ; as separator?
278
279 switch (AsmPieces.size()) {
280 default: return false;
281 case 1:
282 AsmStr = AsmPieces[0];
283 AsmPieces.clear();
284 SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace.
285
Chris Lattner5d521352006-11-29 01:48:01 +0000286 // bswap $0
Chris Lattner625bd052006-11-29 01:14:06 +0000287 if (AsmPieces.size() == 2 &&
288 AsmPieces[0] == "bswap" && AsmPieces[1] == "$0") {
289 // No need to check constraints, nothing other than the equivalent of
290 // "=r,0" would be valid here.
291 return LowerToBSwap(CI);
292 }
293 break;
Chris Lattner5d521352006-11-29 01:48:01 +0000294 case 3:
Reid Spencer47857812006-12-31 05:55:36 +0000295 if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
Chris Lattner5d521352006-11-29 01:48:01 +0000296 Constraints[0].Codes.size() == 1 && Constraints[0].Codes[0] == "A" &&
297 Constraints[1].Codes.size() == 1 && Constraints[1].Codes[0] == "0") {
298 // bswap %eax / bswap %edx / xchgl %eax, %edx -> llvm.bswap.i64
299 std::vector<std::string> Words;
300 SplitString(AsmPieces[0], Words, " \t");
301 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%eax") {
302 Words.clear();
303 SplitString(AsmPieces[1], Words, " \t");
304 if (Words.size() == 2 && Words[0] == "bswap" && Words[1] == "%edx") {
305 Words.clear();
306 SplitString(AsmPieces[2], Words, " \t,");
307 if (Words.size() == 3 && Words[0] == "xchgl" && Words[1] == "%eax" &&
308 Words[2] == "%edx") {
309 return LowerToBSwap(CI);
310 }
311 }
312 }
313 }
314 break;
Chris Lattner625bd052006-11-29 01:14:06 +0000315 }
316 return false;
317}
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000318
319/// PreferredEHDataFormat - This hook allows the target to select data
320/// format used for encoding pointers in exception handling data. Reason is
321/// 0 for data, 1 for code labels, 2 for function pointers. Global is true
322/// if the symbol can be relocated.
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000323unsigned X86TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000324 bool Global) const {
325 const X86Subtarget *Subtarget = &X86TM->getSubtarget<X86Subtarget>();
326
327 switch (Subtarget->TargetType) {
328 case X86Subtarget::isDarwin:
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000329 if (Reason == DwarfEncoding::Functions && Global)
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000330 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000331 else if (Reason == DwarfEncoding::CodeLabels || !Global)
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000332 return DW_EH_PE_pcrel;
333 else
334 return DW_EH_PE_absptr;
335
336 case X86Subtarget::isELF:
337 case X86Subtarget::isCygwin:
338 case X86Subtarget::isMingw: {
339 CodeModel::Model CM = X86TM->getCodeModel();
340
341 if (X86TM->getRelocationModel() == Reloc::PIC_) {
342 unsigned Format = 0;
343
344 if (!Subtarget->is64Bit())
345 // 32 bit targets always encode pointers as 4 bytes
346 Format = DW_EH_PE_sdata4;
347 else {
348 // 64 bit targets encode pointers in 4 bytes iff:
349 // - code model is small OR
350 // - code model is medium and we're emitting externally visible symbols or
351 // any code symbols
352 if (CM == CodeModel::Small ||
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000353 (CM == CodeModel::Medium && (Global ||
354 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000355 Format = DW_EH_PE_sdata4;
356 else
357 Format = DW_EH_PE_sdata8;
358 }
359
360 if (Global)
361 Format |= DW_EH_PE_indirect;
362
363 return (Format | DW_EH_PE_pcrel);
364 } else {
365 if (Subtarget->is64Bit() &&
366 (CM == CodeModel::Small ||
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000367 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000368 return DW_EH_PE_udata4;
369 else
370 return DW_EH_PE_absptr;
371 }
372 }
373
374 default:
375 return TargetAsmInfo::PreferredEHDataFormat(Reason, Global);
376 }
377}
378