blob: 0f5f200a7c6b5246a3d052412e0cd9f807b82955 [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
Andrew Lenharth6c0695f2006-11-28 19:52:49 +000044 AsmTransCBE = x86_asm_table;
Anton Korobeynikov82100452008-07-09 13:20:27 +000045
Bill Wendlingcb900992007-01-16 09:29:17 +000046 AssemblerDialect = Subtarget->getAsmFlavor();
Jim Laskey8e8de8f2006-09-07 22:05:02 +000047}
Chris Lattnerafbfded2006-10-05 02:43:52 +000048
Chris Lattner625bd052006-11-29 01:14:06 +000049bool 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 Korobeynikov82100452008-07-09 13:20:27 +000054
Chris Lattner625bd052006-11-29 01:14:06 +000055 // Verify this is a simple bswap.
56 if (CI->getNumOperands() != 2 ||
57 CI->getType() != CI->getOperand(1)->getType() ||
Chris Lattner42a75512007-01-15 02:27:26 +000058 !CI->getType()->isInteger())
Chris Lattner625bd052006-11-29 01:14:06 +000059 return false;
Anton Korobeynikov82100452008-07-09 13:20:27 +000060
Chris Lattner3e9f1d02007-04-01 20:49:36 +000061 const IntegerType *Ty = dyn_cast<IntegerType>(CI->getType());
62 if (!Ty || Ty->getBitWidth() % 16 != 0)
Reid Spencera54b7cb2007-01-12 07:05:14 +000063 return false;
Anton Korobeynikov82100452008-07-09 13:20:27 +000064
Chris Lattner625bd052006-11-29 01:14:06 +000065 // Okay, we can do this xform, do so now.
Chandler Carruth69940402007-08-04 01:51:18 +000066 const Type *Tys[] = { Ty };
Chris Lattner625bd052006-11-29 01:14:06 +000067 Module *M = CI->getParent()->getParent()->getParent();
Chandler Carruth69940402007-08-04 01:51:18 +000068 Constant *Int = Intrinsic::getDeclaration(M, Intrinsic::bswap, Tys, 1);
Anton Korobeynikov82100452008-07-09 13:20:27 +000069
Chris Lattner625bd052006-11-29 01:14:06 +000070 Value *Op = CI->getOperand(1);
Gabor Greif051a9502008-04-06 20:25:17 +000071 Op = CallInst::Create(Int, Op, CI->getName(), CI);
Anton Korobeynikov82100452008-07-09 13:20:27 +000072
Chris Lattner625bd052006-11-29 01:14:06 +000073 CI->replaceAllUsesWith(Op);
74 CI->eraseFromParent();
75 return true;
76}
77
78
79bool X86TargetAsmInfo::ExpandInlineAsm(CallInst *CI) const {
80 InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue());
Chris Lattner5d521352006-11-29 01:48:01 +000081 std::vector<InlineAsm::ConstraintInfo> Constraints = IA->ParseConstraints();
Anton Korobeynikov82100452008-07-09 13:20:27 +000082
Chris Lattner625bd052006-11-29 01:14:06 +000083 std::string AsmStr = IA->getAsmString();
Anton Korobeynikov82100452008-07-09 13:20:27 +000084
Chris Lattner625bd052006-11-29 01:14:06 +000085 // 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 Korobeynikov82100452008-07-09 13:20:27 +000088
Chris Lattner625bd052006-11-29 01:14:06 +000089 switch (AsmPieces.size()) {
Anton Korobeynikov82100452008-07-09 13:20:27 +000090 default: return false;
Chris Lattner625bd052006-11-29 01:14:06 +000091 case 1:
92 AsmStr = AsmPieces[0];
93 AsmPieces.clear();
94 SplitString(AsmStr, AsmPieces, " \t"); // Split with whitespace.
Anton Korobeynikov82100452008-07-09 13:20:27 +000095
Chris Lattner5d521352006-11-29 01:48:01 +000096 // bswap $0
Anton Korobeynikov82100452008-07-09 13:20:27 +000097 if (AsmPieces.size() == 2 &&
Chris Lattner625bd052006-11-29 01:14:06 +000098 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 Lattner5d521352006-11-29 01:48:01 +0000104 case 3:
Reid Spencer47857812006-12-31 05:55:36 +0000105 if (CI->getType() == Type::Int64Ty && Constraints.size() >= 2 &&
Chris Lattner5d521352006-11-29 01:48:01 +0000106 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 Lattner625bd052006-11-29 01:14:06 +0000125 }
126 return false;
127}
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000128
Anton Korobeynikov4468b7a2008-07-09 13:20:48 +0000129X86DarwinTargetAsmInfo::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";
145 FourByteConstantSection = "\t.literal4\n";
146 EightByteConstantSection = "\t.literal8\n";
147 // FIXME: Why don't always use this section?
148 if (is64Bit)
149 SixteenByteConstantSection = "\t.literal16\n";
150 ReadOnlySection = "\t.const\n";
151 LCOMMDirective = "\t.lcomm\t";
152 SwitchToSectionDirective = "\t.section ";
153 StringConstantPrefix = "\1LC";
154 COMMDirectiveTakesAlignment = false;
155 HasDotTypeDotSizeDirective = false;
156 if (TM.getRelocationModel() == Reloc::Static) {
157 StaticCtorsSection = ".constructor";
158 StaticDtorsSection = ".destructor";
159 } else {
160 StaticCtorsSection = ".mod_init_func";
161 StaticDtorsSection = ".mod_term_func";
162 }
163 if (is64Bit) {
164 PersonalityPrefix = "";
165 PersonalitySuffix = "+4@GOTPCREL";
166 } else {
167 PersonalityPrefix = "L";
168 PersonalitySuffix = "$non_lazy_ptr";
169 }
170 NeedsIndirectEncoding = true;
171 InlineAsmStart = "## InlineAsm Start";
172 InlineAsmEnd = "## InlineAsm End";
173 CommentString = "##";
174 SetDirective = "\t.set";
175 PCSymbol = ".";
176 UsedDirective = "\t.no_dead_strip\t";
177 WeakDefDirective = "\t.weak_definition ";
178 WeakRefDirective = "\t.weak_reference ";
179 HiddenDirective = "\t.private_extern ";
180 ProtectedDirective = "\t.globl\t";
181
182 // In non-PIC modes, emit a special label before jump tables so that the
183 // linker can perform more accurate dead code stripping.
184 if (TM.getRelocationModel() != Reloc::PIC_) {
185 // Emit a local label that is preserved until the linker runs.
186 JumpTableSpecialLabelPrefix = "l";
187 }
188
189 SupportsDebugInformation = true;
190 NeedsSet = true;
191 DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug";
192 DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug";
193 DwarfLineSection = ".section __DWARF,__debug_line,regular,debug";
194 DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug";
195 DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug";
196 DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug";
197 DwarfStrSection = ".section __DWARF,__debug_str,regular,debug";
198 DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug";
199 DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug";
200 DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug";
201 DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug";
202
203 // Exceptions handling
204 SupportsExceptionHandling = true;
205 GlobalEHDirective = "\t.globl\t";
206 SupportsWeakOmittedEHFrame = false;
207 AbsoluteEHSectionOffsets = false;
208 DwarfEHFrameSection =
209 ".section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support";
210 DwarfExceptionSection = ".section __DATA,__gcc_except_tab";
211}
212
213X86ELFTargetAsmInfo::X86ELFTargetAsmInfo(const X86TargetMachine &TM):
214 X86TargetAsmInfo(TM) {
215 bool is64Bit = X86TM->getSubtarget<X86Subtarget>().is64Bit();
216
217 ReadOnlySection = "\t.section\t.rodata";
218 FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4";
219 EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8";
220 SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16";
221 CStringSection = "\t.section\t.rodata.str1.1,\"aMS\",@progbits,1";
222 PrivateGlobalPrefix = ".L";
223 WeakRefDirective = "\t.weak\t";
224 SetDirective = "\t.set\t";
225 PCSymbol = ".";
226
227 // Set up DWARF directives
228 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
229
230 // Debug Information
231 AbsoluteDebugSectionOffsets = true;
232 SupportsDebugInformation = true;
233 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",@progbits";
234 DwarfInfoSection = "\t.section\t.debug_info,\"\",@progbits";
235 DwarfLineSection = "\t.section\t.debug_line,\"\",@progbits";
236 DwarfFrameSection = "\t.section\t.debug_frame,\"\",@progbits";
237 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",@progbits";
238 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",@progbits";
239 DwarfStrSection = "\t.section\t.debug_str,\"\",@progbits";
240 DwarfLocSection = "\t.section\t.debug_loc,\"\",@progbits";
241 DwarfARangesSection = "\t.section\t.debug_aranges,\"\",@progbits";
242 DwarfRangesSection = "\t.section\t.debug_ranges,\"\",@progbits";
243 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",@progbits";
244
245 // Exceptions handling
246 if (!is64Bit)
247 SupportsExceptionHandling = true;
248 AbsoluteEHSectionOffsets = false;
249 DwarfEHFrameSection = "\t.section\t.eh_frame,\"aw\",@progbits";
250 DwarfExceptionSection = "\t.section\t.gcc_except_table,\"a\",@progbits";
251
252 // On Linux we must declare when we can use a non-executable stack.
253 if (X86TM->getSubtarget<X86Subtarget>().isLinux())
254 NonexecutableStackDirective = "\t.section\t.note.GNU-stack,\"\",@progbits";
255}
256
257X86COFFTargetAsmInfo::X86COFFTargetAsmInfo(const X86TargetMachine &TM):
258 X86TargetAsmInfo(TM) {
259 GlobalPrefix = "_";
260 LCOMMDirective = "\t.lcomm\t";
261 COMMDirectiveTakesAlignment = false;
262 HasDotTypeDotSizeDirective = false;
263 StaticCtorsSection = "\t.section .ctors,\"aw\"";
264 StaticDtorsSection = "\t.section .dtors,\"aw\"";
265 HiddenDirective = NULL;
266 PrivateGlobalPrefix = "L"; // Prefix for private global symbols
267 WeakRefDirective = "\t.weak\t";
268 SetDirective = "\t.set\t";
269
270 // Set up DWARF directives
271 HasLEB128 = true; // Target asm supports leb128 directives (little-endian)
272 AbsoluteDebugSectionOffsets = true;
273 AbsoluteEHSectionOffsets = false;
274 SupportsDebugInformation = true;
275 DwarfSectionOffsetDirective = "\t.secrel32\t";
276 DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"dr\"";
277 DwarfInfoSection = "\t.section\t.debug_info,\"dr\"";
278 DwarfLineSection = "\t.section\t.debug_line,\"dr\"";
279 DwarfFrameSection = "\t.section\t.debug_frame,\"dr\"";
280 DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"dr\"";
281 DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"dr\"";
282 DwarfStrSection = "\t.section\t.debug_str,\"dr\"";
283 DwarfLocSection = "\t.section\t.debug_loc,\"dr\"";
284 DwarfARangesSection = "\t.section\t.debug_aranges,\"dr\"";
285 DwarfRangesSection = "\t.section\t.debug_ranges,\"dr\"";
286 DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"dr\"";
287}
288
289X86WinTargetAsmInfo::X86WinTargetAsmInfo(const X86TargetMachine &TM):
290 X86TargetAsmInfo(TM) {
291 GlobalPrefix = "_";
292 CommentString = ";";
293
294 PrivateGlobalPrefix = "$";
295 AlignDirective = "\talign\t";
296 ZeroDirective = "\tdb\t";
297 ZeroDirectiveSuffix = " dup(0)";
298 AsciiDirective = "\tdb\t";
299 AscizDirective = 0;
300 Data8bitsDirective = "\tdb\t";
301 Data16bitsDirective = "\tdw\t";
302 Data32bitsDirective = "\tdd\t";
303 Data64bitsDirective = "\tdq\t";
304 HasDotTypeDotSizeDirective = false;
305
306 TextSection = "_text";
307 DataSection = "_data";
308 JumpTableDataSection = NULL;
309 SwitchToSectionDirective = "";
310 TextSectionStartSuffix = "\tsegment 'CODE'";
311 DataSectionStartSuffix = "\tsegment 'DATA'";
312 SectionEndDirectiveSuffix = "\tends\n";
313}
314
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000315/// PreferredEHDataFormat - This hook allows the target to select data
316/// format used for encoding pointers in exception handling data. Reason is
317/// 0 for data, 1 for code labels, 2 for function pointers. Global is true
318/// if the symbol can be relocated.
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000319unsigned X86TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000320 bool Global) const {
321 const X86Subtarget *Subtarget = &X86TM->getSubtarget<X86Subtarget>();
322
323 switch (Subtarget->TargetType) {
324 case X86Subtarget::isDarwin:
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000325 if (Reason == DwarfEncoding::Functions && Global)
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000326 return (DW_EH_PE_pcrel | DW_EH_PE_indirect | DW_EH_PE_sdata4);
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000327 else if (Reason == DwarfEncoding::CodeLabels || !Global)
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000328 return DW_EH_PE_pcrel;
329 else
330 return DW_EH_PE_absptr;
331
332 case X86Subtarget::isELF:
333 case X86Subtarget::isCygwin:
334 case X86Subtarget::isMingw: {
335 CodeModel::Model CM = X86TM->getCodeModel();
336
337 if (X86TM->getRelocationModel() == Reloc::PIC_) {
338 unsigned Format = 0;
339
340 if (!Subtarget->is64Bit())
341 // 32 bit targets always encode pointers as 4 bytes
342 Format = DW_EH_PE_sdata4;
343 else {
344 // 64 bit targets encode pointers in 4 bytes iff:
345 // - code model is small OR
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000346 // - code model is medium and we're emitting externally visible symbols
347 // or any code symbols
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000348 if (CM == CodeModel::Small ||
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000349 (CM == CodeModel::Medium && (Global ||
350 Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000351 Format = DW_EH_PE_sdata4;
352 else
353 Format = DW_EH_PE_sdata8;
354 }
355
356 if (Global)
357 Format |= DW_EH_PE_indirect;
358
359 return (Format | DW_EH_PE_pcrel);
360 } else {
361 if (Subtarget->is64Bit() &&
362 (CM == CodeModel::Small ||
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000363 (CM == CodeModel::Medium && Reason != DwarfEncoding::Data)))
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000364 return DW_EH_PE_udata4;
365 else
366 return DW_EH_PE_absptr;
367 }
368 }
369
370 default:
371 return TargetAsmInfo::PreferredEHDataFormat(Reason, Global);
372 }
373}
374
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000375std::string X86TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
376 SectionKind::Kind kind) const {
377 const X86Subtarget *Subtarget = &X86TM->getSubtarget<X86Subtarget>();
378
379 switch (Subtarget->TargetType) {
380 case X86Subtarget::isDarwin:
381 if (kind == SectionKind::Text)
382 return "__TEXT,__textcoal_nt,coalesced,pure_instructions";
383 else
384 return "__DATA,__datacoal_nt,coalesced";
385 case X86Subtarget::isCygwin:
386 case X86Subtarget::isMingw:
387 switch (kind) {
388 case SectionKind::Text:
389 return ".text$linkonce" + GV->getName();
390 case SectionKind::Data:
391 case SectionKind::BSS:
392 case SectionKind::ThreadData:
393 case SectionKind::ThreadBSS:
394 return ".data$linkonce" + GV->getName();
395 case SectionKind::ROData:
396 case SectionKind::RODataMergeConst:
397 case SectionKind::RODataMergeStr:
398 return ".rdata$linkonce" + GV->getName();
399 default:
400 assert(0 && "Unknown section kind");
401 }
402 case X86Subtarget::isELF:
403 return TargetAsmInfo::UniqueSectionForGlobal(GV, kind);
404 default:
405 return "";
406 }
407}
408
409
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000410std::string X86TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000411 SectionKind::Kind kind = SectionKindForGlobal(GV);
412 unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
413 std::string Name;
414
415 // FIXME: Should we use some hashing based on section name and just check
416 // flags?
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000417 // FIXME: It seems, that Darwin uses much more sections.
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000418
419 // Select section name
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000420 if (GV->hasSection()) {
421 // Honour section already set, if any
422 Name = GV->getSection();
423 } else {
424 // Use default section depending on the 'type' of global
425 if (const Function *F = dyn_cast<Function>(GV)) {
426 switch (F->getLinkage()) {
427 default: assert(0 && "Unknown linkage type!");
428 case Function::InternalLinkage:
429 case Function::DLLExportLinkage:
430 case Function::ExternalLinkage:
431 Name = TextSection;
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000432 break;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000433 case Function::WeakLinkage:
434 case Function::LinkOnceLinkage:
435 Name = UniqueSectionForGlobal(F, kind);
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000436 break;
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000437 }
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000438 } else if (const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV)) {
439 if (GVar->hasCommonLinkage() ||
440 GVar->hasLinkOnceLinkage() ||
441 GVar->hasWeakLinkage())
442 Name = UniqueSectionForGlobal(GVar, kind);
443 else {
444 switch (kind) {
445 case SectionKind::Data:
446 Name = DataSection;
447 break;
448 case SectionKind::BSS:
449 Name = (BSSSection ? BSSSection : DataSection);
450 break;
451 case SectionKind::ROData:
452 case SectionKind::RODataMergeStr:
453 case SectionKind::RODataMergeConst:
454 // FIXME: Temporary
455 Name = DataSection;
456 break;
457 case SectionKind::ThreadData:
458 Name = (TLSDataSection ? TLSDataSection : DataSection);
459 break;
460 case SectionKind::ThreadBSS:
461 Name = (TLSBSSSection ? TLSBSSSection : DataSection);
462 default:
463 assert(0 && "Unsuported section kind for global");
464 }
465 }
466 } else
467 assert(0 && "Unsupported global");
468 }
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000469
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000470 Name += PrintSectionFlags(flags);
471 return Name;
472}
473
474std::string X86TargetAsmInfo::PrintSectionFlags(unsigned flags) const {
475 const X86Subtarget *Subtarget = &X86TM->getSubtarget<X86Subtarget>();
476
477 std::string Flags = "";
478
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000479 // Add all special flags, etc
480 switch (Subtarget->TargetType) {
481 case X86Subtarget::isELF:
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000482 Flags += ",\"";
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000483
484 if (!(flags & SectionFlags::Debug))
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000485 Flags += 'a';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000486 if (flags & SectionFlags::Code)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000487 Flags += 'x';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000488 if (flags & SectionFlags::Writeable)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000489 Flags += 'w';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000490 if (flags & SectionFlags::Mergeable)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000491 Flags += 'M';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000492 if (flags & SectionFlags::Strings)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000493 Flags += 'S';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000494 if (flags & SectionFlags::TLS)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000495 Flags += 'T';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000496
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000497 Flags += "\"";
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000498
499 // FIXME: There can be exceptions here
500 if (flags & SectionFlags::BSS)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000501 Flags += ",@nobits";
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000502 else
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000503 Flags += ",@progbits";
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000504
505 // FIXME: entity size for mergeable sections
506 break;
507 case X86Subtarget::isCygwin:
508 case X86Subtarget::isMingw:
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000509 Flags += ",\"";
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000510
511 if (flags & SectionFlags::Code)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000512 Flags += 'x';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000513 if (flags & SectionFlags::Writeable)
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000514 Flags += 'w';
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000515
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000516 Flags += "\"";
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000517
518 break;
519 case X86Subtarget::isDarwin:
520 // Darwin does not use any special flags
521 default:
522 break;
523 }
524
Anton Korobeynikov6e405f32008-07-09 13:20:07 +0000525 return Flags;
Anton Korobeynikovc0f41db2008-07-09 13:19:08 +0000526}