blob: 7aac8cc34938ae6f95c4bb6de9786acdb28a1e20 [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"
Dale Johannesen3bb62832007-04-23 20:00:17 +000025#include <cctype>
26#include <cstring>
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000027
28using namespace llvm;
29
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000030void TargetAsmInfo::fillDefaultValues() {
31 BSSSection = "\t.bss";
32 BSSSection_ = 0;
33 ReadOnlySection = 0;
34 SmallDataSection = 0;
35 SmallBSSSection = 0;
36 SmallRODataSection = 0;
37 TLSDataSection = 0;
38 TLSBSSSection = 0;
39 ZeroFillDirective = 0;
40 NonexecutableStackDirective = 0;
41 NeedsSet = false;
42 MaxInstLength = 4;
43 PCSymbol = "$";
44 SeparatorChar = ';';
45 CommentString = "#";
46 GlobalPrefix = "";
47 PrivateGlobalPrefix = ".";
48 LessPrivateGlobalPrefix = "";
49 JumpTableSpecialLabelPrefix = 0;
50 GlobalVarAddrPrefix = "";
51 GlobalVarAddrSuffix = "";
52 FunctionAddrPrefix = "";
53 FunctionAddrSuffix = "";
54 PersonalityPrefix = "";
55 PersonalitySuffix = "";
56 NeedsIndirectEncoding = false;
57 InlineAsmStart = "#APP";
58 InlineAsmEnd = "#NO_APP";
59 AssemblerDialect = 0;
60 StringConstantPrefix = ".str";
61 ZeroDirective = "\t.zero\t";
62 ZeroDirectiveSuffix = 0;
63 AsciiDirective = "\t.ascii\t";
64 AscizDirective = "\t.asciz\t";
65 Data8bitsDirective = "\t.byte\t";
66 Data16bitsDirective = "\t.short\t";
67 Data32bitsDirective = "\t.long\t";
68 Data64bitsDirective = "\t.quad\t";
69 AlignDirective = "\t.align\t";
70 AlignmentIsInBytes = true;
71 TextAlignFillValue = 0;
72 SwitchToSectionDirective = "\t.section\t";
73 TextSectionStartSuffix = "";
74 DataSectionStartSuffix = "";
75 SectionEndDirectiveSuffix = 0;
76 ConstantPoolSection = "\t.section .rodata";
77 JumpTableDataSection = "\t.section .rodata";
78 JumpTableDirective = 0;
79 CStringSection = 0;
80 CStringSection_ = 0;
81 // FIXME: Flags are ELFish - replace with normal section stuff.
82 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
83 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
84 GlobalDirective = "\t.globl\t";
85 SetDirective = 0;
86 LCOMMDirective = 0;
87 COMMDirective = "\t.comm\t";
88 COMMDirectiveTakesAlignment = true;
89 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000090 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000091 UsedDirective = 0;
92 WeakRefDirective = 0;
93 WeakDefDirective = 0;
94 // FIXME: These are ELFish - move to ELFTAI.
95 HiddenDirective = "\t.hidden\t";
96 ProtectedDirective = "\t.protected\t";
97 AbsoluteDebugSectionOffsets = false;
98 AbsoluteEHSectionOffsets = false;
99 HasLEB128 = false;
100 HasDotLocAndDotFile = false;
101 SupportsDebugInformation = false;
102 SupportsExceptionHandling = false;
103 DwarfRequiresFrameSection = true;
Devang Patel0f7fef32009-04-13 17:02:03 +0000104 DwarfUsesInlineInfoSection = false;
Bill Wendling722f5f12008-12-24 08:05:17 +0000105 NonLocalEHFrameLabel = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000106 GlobalEHDirective = 0;
107 SupportsWeakOmittedEHFrame = true;
108 DwarfSectionOffsetDirective = 0;
109 DwarfAbbrevSection = ".debug_abbrev";
110 DwarfInfoSection = ".debug_info";
111 DwarfLineSection = ".debug_line";
112 DwarfFrameSection = ".debug_frame";
113 DwarfPubNamesSection = ".debug_pubnames";
114 DwarfPubTypesSection = ".debug_pubtypes";
Devang Patel0f7fef32009-04-13 17:02:03 +0000115 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000116 DwarfStrSection = ".debug_str";
117 DwarfLocSection = ".debug_loc";
118 DwarfARangesSection = ".debug_aranges";
119 DwarfRangesSection = ".debug_ranges";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000120 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000121 DwarfEHFrameSection = ".eh_frame";
122 DwarfExceptionSection = ".gcc_except_table";
123 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000124 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000125 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000126}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000127
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000128TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
Dan Gohman8f092252008-11-03 18:22:42 +0000129 : TM(tm) {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000130 fillDefaultValues();
131}
132
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000133TargetAsmInfo::~TargetAsmInfo() {
134}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000135
136/// Measure the specified inline asm to determine an approximation of its
137/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000138/// Comments (which run till the next SeparatorChar or newline) do not
139/// count as an instruction.
140/// Any other non-whitespace text is considered an instruction, with
141/// multiple instructions separated by SeparatorChar or newlines.
142/// Variable-length instructions are not handled here; this function
143/// may be overloaded in the target code to do that.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000144unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
145 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000146 bool atInsnStart = true;
147 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000148 for (; *Str; ++Str) {
149 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000150 atInsnStart = true;
151 if (atInsnStart && !isspace(*Str)) {
152 Length += MaxInstLength;
153 atInsnStart = false;
154 }
155 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
156 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000157 }
158
Dale Johannesen3bb62832007-04-23 20:00:17 +0000159 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000160}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000161
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000162unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000163 bool Global) const {
164 return dwarf::DW_EH_PE_absptr;
165}
166
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000167static bool isSuitableForBSS(const GlobalVariable *GV) {
168 if (!GV->hasInitializer())
169 return true;
170
171 // Leave constant zeros in readonly constant sections, so they can be shared
172 Constant *C = GV->getInitializer();
173 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
174}
175
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000176static bool isConstantString(const Constant *C) {
177 // First check: is we have constant array of i8 terminated with zero
178 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
179 // Check, if initializer is a null-terminated string
180 if (CVA && CVA->isCString())
181 return true;
182
183 // Another possibility: [1 x i8] zeroinitializer
184 if (isa<ConstantAggregateZero>(C)) {
185 if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
186 return (Ty->getElementType() == Type::Int8Ty &&
187 Ty->getNumElements() == 1);
188 }
189 }
190
191 return false;
192}
193
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000194unsigned TargetAsmInfo::RelocBehaviour() const {
195 // By default - all relocations in PIC mode would force symbol to be
196 // placed in r/w section.
197 return (TM.getRelocationModel() != Reloc::Static ?
198 Reloc::LocalOrGlobal : Reloc::None);
199}
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000200
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000201SectionKind::Kind
202TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
203 // Early exit - functions should be always in text sections.
204 if (isa<Function>(GV))
205 return SectionKind::Text;
206
207 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
208 bool isThreadLocal = GVar->isThreadLocal();
209 assert(GVar && "Invalid global value for section selection");
210
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000211 if (isSuitableForBSS(GVar)) {
212 // Variable can be easily put to BSS section.
213 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
214 } else if (GVar->isConstant() && !isThreadLocal) {
215 // Now we know, that varible has initializer and it is constant. We need to
216 // check its initializer to decide, which section to output it into. Also
217 // note, there is no thread-local r/o section.
218 Constant *C = GVar->getInitializer();
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000219 if (C->ContainsRelocations(Reloc::LocalOrGlobal)) {
220 // Decide, whether it is still possible to put symbol into r/o section.
221 unsigned Reloc = RelocBehaviour();
222
223 // We already did a query for 'all' relocs, thus - early exits.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000224 if (Reloc == Reloc::LocalOrGlobal)
225 return SectionKind::Data;
226 else if (Reloc == Reloc::None)
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000227 return SectionKind::ROData;
228 else {
229 // Ok, target wants something funny. Honour it.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000230 return (C->ContainsRelocations(Reloc) ?
231 SectionKind::Data : SectionKind::ROData);
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000232 }
233 } else {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000234 // Check, if initializer is a null-terminated string
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000235 if (isConstantString(C))
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000236 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000237 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000238 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000239 }
240 }
241
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000242 // Variable either is not constant or thread-local - output to data section.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000243 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000244}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000245
246unsigned
247TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000248 const char* Name) const {
249 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000250
251 // Decode flags from global itself.
252 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000253 SectionKind::Kind Kind = SectionKindForGlobal(GV);
254 switch (Kind) {
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000255 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000256 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000257 break;
258 case SectionKind::ThreadData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000259 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000260 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000261 // FALLS THROUGH
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000262 case SectionKind::Data:
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000263 case SectionKind::DataRel:
264 case SectionKind::DataRelLocal:
265 case SectionKind::DataRelRO:
266 case SectionKind::DataRelROLocal:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000267 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000268 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000269 break;
270 case SectionKind::ROData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000271 case SectionKind::RODataMergeStr:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000272 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000273 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000274 break;
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000275 case SectionKind::SmallData:
276 case SectionKind::SmallBSS:
277 Flags |= SectionFlags::Writeable;
278 // FALLS THROUGH
279 case SectionKind::SmallROData:
280 Flags |= SectionFlags::Small;
281 break;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000282 default:
283 assert(0 && "Unexpected section kind!");
284 }
285
Duncan Sands667d4b82009-03-07 15:45:40 +0000286 if (GV->isWeakForLinker())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000287 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000288 }
289
290 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000291 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000292 Flags |= SectionFlags::Named;
293
294 // Some lame default implementation based on some magic section names.
295 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000296 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
297 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
298 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000299 Flags |= SectionFlags::BSS;
300 else if (strcmp(Name, ".tdata") == 0 ||
301 strncmp(Name, ".tdata.", 7) == 0 ||
302 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
303 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
304 Flags |= SectionFlags::TLS;
305 else if (strcmp(Name, ".tbss") == 0 ||
306 strncmp(Name, ".tbss.", 6) == 0 ||
307 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
308 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
309 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000310 }
311
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000312 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000313}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000314
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000315const Section*
Evan Cheng42ccc212008-08-08 17:56:50 +0000316TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000317 const Section* S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000318 // Select section name
319 if (GV->hasSection()) {
320 // Honour section already set, if any
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000321 unsigned Flags = SectionFlagsForGlobal(GV,
322 GV->getSection().c_str());
323 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000324 } else {
325 // Use default section depending on the 'type' of global
Evan Cheng42ccc212008-08-08 17:56:50 +0000326 S = SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000327 }
328
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000329 return S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000330}
331
332// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000333const Section*
334TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000335 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000336
Duncan Sands667d4b82009-03-07 15:45:40 +0000337 if (GV->isWeakForLinker()) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000338 std::string Name = UniqueSectionForGlobal(GV, Kind);
339 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
340 return getNamedSection(Name.c_str(), Flags);
341 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000342 if (Kind == SectionKind::Text)
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000343 return getTextSection();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000344 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000345 return getBSSSection_();
Anton Korobeynikov00181a32008-09-24 22:20:27 +0000346 else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
347 return getReadOnlySection();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000348 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000349
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000350 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000351}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000352
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000353// Lame default implementation. Calculate the section name for machine const.
354const Section*
355TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
356 // FIXME: Support data.rel stuff someday
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000357 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000358}
359
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000360std::string
361TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000362 SectionKind::Kind Kind) const {
363 switch (Kind) {
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000364 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000365 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000366 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000367 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000368 case SectionKind::DataRel:
369 return ".gnu.linkonce.d.rel" + GV->getName();
370 case SectionKind::DataRelLocal:
371 return ".gnu.linkonce.d.rel.local" + GV->getName();
372 case SectionKind::DataRelRO:
373 return ".gnu.linkonce.d.rel.ro" + GV->getName();
374 case SectionKind::DataRelROLocal:
375 return ".gnu.linkonce.d.rel.ro.local" + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000376 case SectionKind::SmallData:
377 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000378 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000379 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000380 case SectionKind::SmallBSS:
381 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000382 case SectionKind::ROData:
383 case SectionKind::RODataMergeConst:
384 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000385 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000386 case SectionKind::SmallROData:
387 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000388 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000389 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000390 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000391 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000392 default:
393 assert(0 && "Unknown section kind");
394 }
Devang Patel8a84e442009-01-05 17:31:22 +0000395 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000396}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000397
398const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000399TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
400 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000401 Section& S = Sections[Name];
402
403 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000404 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000405 S.Flags = Flags | SectionFlags::Named;
406 S.Name = Name;
407 }
408
409 return &S;
410}
411
412const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000413TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
414 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000415 Section& S = Sections[Directive];
416
417 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000418 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000419 S.Flags = Flags & ~SectionFlags::Named;
420 S.Name = Directive;
421 }
422
423 return &S;
424}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000425
426const std::string&
427TargetAsmInfo::getSectionFlags(unsigned Flags) const {
428 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
429
430 // We didn't print these flags yet, print and save them to map. This reduces
431 // amount of heap trashing due to std::string construction / concatenation.
432 if (I == FlagsStrings.end())
433 I = FlagsStrings.insert(std::make_pair(Flags,
434 printSectionFlags(Flags))).first;
435
436 return I->second;
437}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000438
439unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
440 unsigned Size = 0;
441 do {
442 Value >>= 7;
443 Size += sizeof(int8_t);
444 } while (Value);
445 return Size;
446}
447
448unsigned TargetAsmInfo::getSLEB128Size(int Value) {
449 unsigned Size = 0;
450 int Sign = Value >> (8 * sizeof(Value) - 1);
451 bool IsMore;
452
453 do {
454 unsigned Byte = Value & 0x7f;
455 Value >>= 7;
456 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
457 Size += sizeof(int8_t);
458 } while (IsMore);
459 return Size;
460}