blob: d8c331eb404c0b9dbf44704f5381b01d86759e67 [file] [log] [blame]
Jim Laskey7c95ad42006-09-06 19:21:41 +00001//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
Jim Laskeyec0d9fe2006-09-06 18:35:33 +00002//
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 Laskeyec0d9fe2006-09-06 18:35:33 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines target asm properties related what form asm statements
11// should take.
12//
13//===----------------------------------------------------------------------===//
14
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000015#include "llvm/Constants.h"
Anton Korobeynikov72bb4022009-01-27 22:29:24 +000016#include "llvm/DerivedTypes.h"
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000017#include "llvm/GlobalVariable.h"
18#include "llvm/Function.h"
19#include "llvm/Module.h"
20#include "llvm/Type.h"
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000021#include "llvm/Target/TargetAsmInfo.h"
Anton Korobeynikovdb232312009-03-29 17:13:49 +000022#include "llvm/Target/TargetMachine.h"
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000023#include "llvm/Target/TargetOptions.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000024#include "llvm/Support/Dwarf.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000025#include "llvm/Support/ErrorHandling.h"
Dale Johannesen3bb62832007-04-23 20:00:17 +000026#include <cctype>
27#include <cstring>
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000028using namespace llvm;
29
Chris Lattner4e0f25b2009-06-19 00:08:39 +000030TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
31: TM(tm) {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000032 BSSSection = "\t.bss";
33 BSSSection_ = 0;
34 ReadOnlySection = 0;
35 SmallDataSection = 0;
36 SmallBSSSection = 0;
37 SmallRODataSection = 0;
38 TLSDataSection = 0;
39 TLSBSSSection = 0;
40 ZeroFillDirective = 0;
41 NonexecutableStackDirective = 0;
42 NeedsSet = false;
43 MaxInstLength = 4;
44 PCSymbol = "$";
45 SeparatorChar = ';';
David Greene014700c2009-07-13 20:25:48 +000046 CommentColumn = 60;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000047 CommentString = "#";
David Greene76081c42009-07-20 22:02:59 +000048 FirstOperandColumn = 0;
49 MaxOperandLength = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000050 GlobalPrefix = "";
51 PrivateGlobalPrefix = ".";
Chris Lattner90f8b702009-07-21 17:30:51 +000052 LinkerPrivateGlobalPrefix = "";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000053 JumpTableSpecialLabelPrefix = 0;
54 GlobalVarAddrPrefix = "";
55 GlobalVarAddrSuffix = "";
56 FunctionAddrPrefix = "";
57 FunctionAddrSuffix = "";
58 PersonalityPrefix = "";
59 PersonalitySuffix = "";
60 NeedsIndirectEncoding = false;
61 InlineAsmStart = "#APP";
62 InlineAsmEnd = "#NO_APP";
63 AssemblerDialect = 0;
Chris Lattnera93ca922009-06-18 23:41:35 +000064 AllowQuotesInName = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000065 ZeroDirective = "\t.zero\t";
66 ZeroDirectiveSuffix = 0;
67 AsciiDirective = "\t.ascii\t";
68 AscizDirective = "\t.asciz\t";
69 Data8bitsDirective = "\t.byte\t";
70 Data16bitsDirective = "\t.short\t";
71 Data32bitsDirective = "\t.long\t";
72 Data64bitsDirective = "\t.quad\t";
73 AlignDirective = "\t.align\t";
74 AlignmentIsInBytes = true;
75 TextAlignFillValue = 0;
76 SwitchToSectionDirective = "\t.section\t";
77 TextSectionStartSuffix = "";
78 DataSectionStartSuffix = "";
79 SectionEndDirectiveSuffix = 0;
80 ConstantPoolSection = "\t.section .rodata";
81 JumpTableDataSection = "\t.section .rodata";
82 JumpTableDirective = 0;
83 CStringSection = 0;
84 CStringSection_ = 0;
85 // FIXME: Flags are ELFish - replace with normal section stuff.
86 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
87 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
88 GlobalDirective = "\t.globl\t";
89 SetDirective = 0;
90 LCOMMDirective = 0;
91 COMMDirective = "\t.comm\t";
92 COMMDirectiveTakesAlignment = true;
93 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000094 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000095 UsedDirective = 0;
96 WeakRefDirective = 0;
97 WeakDefDirective = 0;
98 // FIXME: These are ELFish - move to ELFTAI.
99 HiddenDirective = "\t.hidden\t";
100 ProtectedDirective = "\t.protected\t";
101 AbsoluteDebugSectionOffsets = false;
102 AbsoluteEHSectionOffsets = false;
103 HasLEB128 = false;
104 HasDotLocAndDotFile = false;
105 SupportsDebugInformation = false;
106 SupportsExceptionHandling = false;
107 DwarfRequiresFrameSection = true;
Devang Patel0f7fef32009-04-13 17:02:03 +0000108 DwarfUsesInlineInfoSection = false;
Chris Lattnere2cf37b2009-07-17 20:46:40 +0000109 Is_EHSymbolPrivate = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000110 GlobalEHDirective = 0;
111 SupportsWeakOmittedEHFrame = true;
112 DwarfSectionOffsetDirective = 0;
113 DwarfAbbrevSection = ".debug_abbrev";
114 DwarfInfoSection = ".debug_info";
115 DwarfLineSection = ".debug_line";
116 DwarfFrameSection = ".debug_frame";
117 DwarfPubNamesSection = ".debug_pubnames";
118 DwarfPubTypesSection = ".debug_pubtypes";
Devang Patel0f7fef32009-04-13 17:02:03 +0000119 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000120 DwarfStrSection = ".debug_str";
121 DwarfLocSection = ".debug_loc";
122 DwarfARangesSection = ".debug_aranges";
123 DwarfRangesSection = ".debug_ranges";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000124 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000125 DwarfEHFrameSection = ".eh_frame";
126 DwarfExceptionSection = ".gcc_except_table";
127 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000128 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000129 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000130}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000131
132TargetAsmInfo::~TargetAsmInfo() {
133}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000134
135/// Measure the specified inline asm to determine an approximation of its
136/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000137/// Comments (which run till the next SeparatorChar or newline) do not
138/// count as an instruction.
139/// Any other non-whitespace text is considered an instruction, with
140/// multiple instructions separated by SeparatorChar or newlines.
141/// Variable-length instructions are not handled here; this function
142/// may be overloaded in the target code to do that.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000143unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
144 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000145 bool atInsnStart = true;
146 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000147 for (; *Str; ++Str) {
148 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000149 atInsnStart = true;
150 if (atInsnStart && !isspace(*Str)) {
151 Length += MaxInstLength;
152 atInsnStart = false;
153 }
154 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
155 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000156 }
157
Dale Johannesen3bb62832007-04-23 20:00:17 +0000158 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000159}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000160
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000161unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000162 bool Global) const {
163 return dwarf::DW_EH_PE_absptr;
164}
165
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000166static bool isSuitableForBSS(const GlobalVariable *GV) {
167 if (!GV->hasInitializer())
168 return true;
169
170 // Leave constant zeros in readonly constant sections, so they can be shared
171 Constant *C = GV->getInitializer();
172 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
173}
174
Owen Anderson1ca29d32009-07-13 21:27:19 +0000175static bool isConstantString(const Constant *C) {
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000176 // First check: is we have constant array of i8 terminated with zero
177 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
178 // Check, if initializer is a null-terminated string
Owen Anderson1ca29d32009-07-13 21:27:19 +0000179 if (CVA && CVA->isCString())
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000180 return true;
181
182 // Another possibility: [1 x i8] zeroinitializer
183 if (isa<ConstantAggregateZero>(C)) {
184 if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
185 return (Ty->getElementType() == Type::Int8Ty &&
186 Ty->getNumElements() == 1);
187 }
188 }
189
190 return false;
191}
192
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000193SectionKind::Kind
194TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
195 // Early exit - functions should be always in text sections.
196 if (isa<Function>(GV))
197 return SectionKind::Text;
198
199 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
200 bool isThreadLocal = GVar->isThreadLocal();
201 assert(GVar && "Invalid global value for section selection");
202
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000203 if (isSuitableForBSS(GVar)) {
204 // Variable can be easily put to BSS section.
Chris Lattner7cf12c72009-07-22 00:05:44 +0000205 return isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000206 } else if (GVar->isConstant() && !isThreadLocal) {
Chris Lattner97d2cae2009-07-21 23:47:11 +0000207 // Now we know, that variable has initializer and it is constant. We need to
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000208 // check its initializer to decide, which section to output it into. Also
209 // note, there is no thread-local r/o section.
210 Constant *C = GVar->getInitializer();
Chris Lattner7cf12c72009-07-22 00:05:44 +0000211 if (C->getRelocationInfo() != 0) {
Chris Lattnerb2fb9cc2009-07-21 23:49:55 +0000212 // Decide whether it is still possible to put symbol into r/o section.
213 if (TM.getRelocationModel() != Reloc::Static)
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000214 return SectionKind::Data;
Chris Lattnerb2fb9cc2009-07-21 23:49:55 +0000215 else
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000216 return SectionKind::ROData;
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000217 } else {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000218 // Check, if initializer is a null-terminated string
Owen Anderson1ca29d32009-07-13 21:27:19 +0000219 if (isConstantString(C))
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000220 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000221 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000222 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000223 }
224 }
225
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000226 // Variable either is not constant or thread-local - output to data section.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000227 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000228}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000229
230unsigned
231TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000232 const char* Name) const {
233 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000234
235 // Decode flags from global itself.
236 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000237 SectionKind::Kind Kind = SectionKindForGlobal(GV);
238 switch (Kind) {
Chris Lattner1010c212009-07-21 17:25:13 +0000239 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000240 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000241 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000242 case SectionKind::ThreadData:
243 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000244 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000245 // FALLS THROUGH
Chris Lattner1010c212009-07-21 17:25:13 +0000246 case SectionKind::Data:
247 case SectionKind::DataRel:
248 case SectionKind::DataRelLocal:
249 case SectionKind::DataRelRO:
250 case SectionKind::DataRelROLocal:
251 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000252 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000253 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000254 case SectionKind::ROData:
255 case SectionKind::RODataMergeStr:
256 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000257 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000258 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000259 case SectionKind::SmallData:
260 case SectionKind::SmallBSS:
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000261 Flags |= SectionFlags::Writeable;
262 // FALLS THROUGH
Chris Lattner1010c212009-07-21 17:25:13 +0000263 case SectionKind::SmallROData:
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000264 Flags |= SectionFlags::Small;
265 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000266 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000267 llvm_unreachable("Unexpected section kind!");
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000268 }
269
Duncan Sands667d4b82009-03-07 15:45:40 +0000270 if (GV->isWeakForLinker())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000271 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000272 }
273
274 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000275 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000276 Flags |= SectionFlags::Named;
277
278 // Some lame default implementation based on some magic section names.
279 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000280 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
281 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
282 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000283 Flags |= SectionFlags::BSS;
284 else if (strcmp(Name, ".tdata") == 0 ||
285 strncmp(Name, ".tdata.", 7) == 0 ||
286 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
287 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
288 Flags |= SectionFlags::TLS;
289 else if (strcmp(Name, ".tbss") == 0 ||
290 strncmp(Name, ".tbss.", 6) == 0 ||
291 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
292 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
293 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000294 }
295
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000296 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000297}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000298
Chris Lattner7558f112009-07-21 21:09:35 +0000299const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000300 // Select section name
301 if (GV->hasSection()) {
Chris Lattner7558f112009-07-21 21:09:35 +0000302 // Honour section already set, if any.
303 unsigned Flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
304 return getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000305 }
Chris Lattner7558f112009-07-21 21:09:35 +0000306
307 // Use default section depending on the 'type' of global
308 return SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000309}
310
311// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000312const Section*
313TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000314 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000315
Duncan Sands667d4b82009-03-07 15:45:40 +0000316 if (GV->isWeakForLinker()) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000317 std::string Name = UniqueSectionForGlobal(GV, Kind);
318 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
319 return getNamedSection(Name.c_str(), Flags);
320 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000321 if (Kind == SectionKind::Text)
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000322 return getTextSection();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000323 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000324 return getBSSSection_();
Anton Korobeynikov00181a32008-09-24 22:20:27 +0000325 else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
326 return getReadOnlySection();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000327 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000328
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000329 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000330}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000331
Chris Lattner298414e2009-07-22 00:28:43 +0000332/// getSectionForMergableConstant - Given a mergable constant with the
333/// specified size and relocation information, return a section that it
334/// should be placed in.
335const Section *
336TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
337 unsigned ReloInfo) const {
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000338 // FIXME: Support data.rel stuff someday
Chris Lattner298414e2009-07-22 00:28:43 +0000339 // Lame default implementation. Calculate the section name for machine const.
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000340 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000341}
342
Chris Lattner298414e2009-07-22 00:28:43 +0000343
344
345
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000346std::string
347TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000348 SectionKind::Kind Kind) const {
349 switch (Kind) {
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000350 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000351 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000352 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000353 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000354 case SectionKind::DataRel:
355 return ".gnu.linkonce.d.rel" + GV->getName();
356 case SectionKind::DataRelLocal:
357 return ".gnu.linkonce.d.rel.local" + GV->getName();
358 case SectionKind::DataRelRO:
359 return ".gnu.linkonce.d.rel.ro" + GV->getName();
360 case SectionKind::DataRelROLocal:
361 return ".gnu.linkonce.d.rel.ro.local" + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000362 case SectionKind::SmallData:
363 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000364 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000365 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000366 case SectionKind::SmallBSS:
367 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000368 case SectionKind::ROData:
369 case SectionKind::RODataMergeConst:
370 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000371 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000372 case SectionKind::SmallROData:
373 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000374 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000375 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000376 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000377 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000378 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000379 llvm_unreachable("Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000380 }
Devang Patel8a84e442009-01-05 17:31:22 +0000381 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000382}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000383
Chris Lattner7558f112009-07-21 21:09:35 +0000384const Section *TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
385 bool Override) const {
386 Section &S = Sections[Name];
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000387
388 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000389 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000390 S.Flags = Flags | SectionFlags::Named;
391 S.Name = Name;
392 }
393
394 return &S;
395}
396
397const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000398TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
399 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000400 Section& S = Sections[Directive];
401
402 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000403 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000404 S.Flags = Flags & ~SectionFlags::Named;
405 S.Name = Directive;
406 }
407
408 return &S;
409}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000410
411const std::string&
412TargetAsmInfo::getSectionFlags(unsigned Flags) const {
413 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
414
415 // We didn't print these flags yet, print and save them to map. This reduces
416 // amount of heap trashing due to std::string construction / concatenation.
417 if (I == FlagsStrings.end())
418 I = FlagsStrings.insert(std::make_pair(Flags,
419 printSectionFlags(Flags))).first;
420
421 return I->second;
422}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000423
424unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
425 unsigned Size = 0;
426 do {
427 Value >>= 7;
428 Size += sizeof(int8_t);
429 } while (Value);
430 return Size;
431}
432
433unsigned TargetAsmInfo::getSLEB128Size(int Value) {
434 unsigned Size = 0;
435 int Sign = Value >> (8 * sizeof(Value) - 1);
436 bool IsMore;
437
438 do {
439 unsigned Byte = Value & 0x7f;
440 Value >>= 7;
441 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
442 Size += sizeof(int8_t);
443 } while (IsMore);
444 return Size;
445}