blob: 3df09bc60a5db984787770bdd08938ff682c80c3 [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 = "#";
48 GlobalPrefix = "";
49 PrivateGlobalPrefix = ".";
50 LessPrivateGlobalPrefix = "";
51 JumpTableSpecialLabelPrefix = 0;
52 GlobalVarAddrPrefix = "";
53 GlobalVarAddrSuffix = "";
54 FunctionAddrPrefix = "";
55 FunctionAddrSuffix = "";
56 PersonalityPrefix = "";
57 PersonalitySuffix = "";
58 NeedsIndirectEncoding = false;
59 InlineAsmStart = "#APP";
60 InlineAsmEnd = "#NO_APP";
61 AssemblerDialect = 0;
62 StringConstantPrefix = ".str";
Chris Lattnera93ca922009-06-18 23:41:35 +000063 AllowQuotesInName = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000064 ZeroDirective = "\t.zero\t";
65 ZeroDirectiveSuffix = 0;
66 AsciiDirective = "\t.ascii\t";
67 AscizDirective = "\t.asciz\t";
68 Data8bitsDirective = "\t.byte\t";
69 Data16bitsDirective = "\t.short\t";
70 Data32bitsDirective = "\t.long\t";
71 Data64bitsDirective = "\t.quad\t";
72 AlignDirective = "\t.align\t";
73 AlignmentIsInBytes = true;
74 TextAlignFillValue = 0;
75 SwitchToSectionDirective = "\t.section\t";
76 TextSectionStartSuffix = "";
77 DataSectionStartSuffix = "";
78 SectionEndDirectiveSuffix = 0;
79 ConstantPoolSection = "\t.section .rodata";
80 JumpTableDataSection = "\t.section .rodata";
81 JumpTableDirective = 0;
82 CStringSection = 0;
83 CStringSection_ = 0;
84 // FIXME: Flags are ELFish - replace with normal section stuff.
85 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
86 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
87 GlobalDirective = "\t.globl\t";
88 SetDirective = 0;
89 LCOMMDirective = 0;
90 COMMDirective = "\t.comm\t";
91 COMMDirectiveTakesAlignment = true;
92 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000093 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000094 UsedDirective = 0;
95 WeakRefDirective = 0;
96 WeakDefDirective = 0;
97 // FIXME: These are ELFish - move to ELFTAI.
98 HiddenDirective = "\t.hidden\t";
99 ProtectedDirective = "\t.protected\t";
100 AbsoluteDebugSectionOffsets = false;
101 AbsoluteEHSectionOffsets = false;
102 HasLEB128 = false;
103 HasDotLocAndDotFile = false;
104 SupportsDebugInformation = false;
105 SupportsExceptionHandling = false;
106 DwarfRequiresFrameSection = true;
Devang Patel0f7fef32009-04-13 17:02:03 +0000107 DwarfUsesInlineInfoSection = false;
Bill Wendling722f5f12008-12-24 08:05:17 +0000108 NonLocalEHFrameLabel = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000109 GlobalEHDirective = 0;
110 SupportsWeakOmittedEHFrame = true;
111 DwarfSectionOffsetDirective = 0;
112 DwarfAbbrevSection = ".debug_abbrev";
113 DwarfInfoSection = ".debug_info";
114 DwarfLineSection = ".debug_line";
115 DwarfFrameSection = ".debug_frame";
116 DwarfPubNamesSection = ".debug_pubnames";
117 DwarfPubTypesSection = ".debug_pubtypes";
Devang Patel0f7fef32009-04-13 17:02:03 +0000118 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000119 DwarfStrSection = ".debug_str";
120 DwarfLocSection = ".debug_loc";
121 DwarfARangesSection = ".debug_aranges";
122 DwarfRangesSection = ".debug_ranges";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000123 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000124 DwarfEHFrameSection = ".eh_frame";
125 DwarfExceptionSection = ".gcc_except_table";
126 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000127 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000128 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000129}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000130
131TargetAsmInfo::~TargetAsmInfo() {
132}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000133
134/// Measure the specified inline asm to determine an approximation of its
135/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000136/// Comments (which run till the next SeparatorChar or newline) do not
137/// count as an instruction.
138/// Any other non-whitespace text is considered an instruction, with
139/// multiple instructions separated by SeparatorChar or newlines.
140/// Variable-length instructions are not handled here; this function
141/// may be overloaded in the target code to do that.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000142unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
143 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000144 bool atInsnStart = true;
145 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000146 for (; *Str; ++Str) {
147 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000148 atInsnStart = true;
149 if (atInsnStart && !isspace(*Str)) {
150 Length += MaxInstLength;
151 atInsnStart = false;
152 }
153 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
154 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000155 }
156
Dale Johannesen3bb62832007-04-23 20:00:17 +0000157 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000158}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000159
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000160unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000161 bool Global) const {
162 return dwarf::DW_EH_PE_absptr;
163}
164
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000165static bool isSuitableForBSS(const GlobalVariable *GV) {
166 if (!GV->hasInitializer())
167 return true;
168
169 // Leave constant zeros in readonly constant sections, so they can be shared
170 Constant *C = GV->getInitializer();
171 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
172}
173
Owen Anderson0a5372e2009-07-13 04:09:18 +0000174static bool isConstantString(LLVMContext &Context, const Constant *C) {
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000175 // First check: is we have constant array of i8 terminated with zero
176 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
177 // Check, if initializer is a null-terminated string
Owen Anderson0a5372e2009-07-13 04:09:18 +0000178 if (CVA && CVA->isCString(Context))
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000179 return true;
180
181 // Another possibility: [1 x i8] zeroinitializer
182 if (isa<ConstantAggregateZero>(C)) {
183 if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
184 return (Ty->getElementType() == Type::Int8Ty &&
185 Ty->getNumElements() == 1);
186 }
187 }
188
189 return false;
190}
191
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000192unsigned TargetAsmInfo::RelocBehaviour() const {
193 // By default - all relocations in PIC mode would force symbol to be
194 // placed in r/w section.
195 return (TM.getRelocationModel() != Reloc::Static ?
196 Reloc::LocalOrGlobal : Reloc::None);
197}
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000198
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000199SectionKind::Kind
200TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
201 // Early exit - functions should be always in text sections.
202 if (isa<Function>(GV))
203 return SectionKind::Text;
204
205 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
206 bool isThreadLocal = GVar->isThreadLocal();
207 assert(GVar && "Invalid global value for section selection");
208
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000209 if (isSuitableForBSS(GVar)) {
210 // Variable can be easily put to BSS section.
211 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
212 } else if (GVar->isConstant() && !isThreadLocal) {
213 // Now we know, that varible has initializer and it is constant. We need to
214 // check its initializer to decide, which section to output it into. Also
215 // note, there is no thread-local r/o section.
216 Constant *C = GVar->getInitializer();
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000217 if (C->ContainsRelocations(Reloc::LocalOrGlobal)) {
218 // Decide, whether it is still possible to put symbol into r/o section.
219 unsigned Reloc = RelocBehaviour();
220
221 // We already did a query for 'all' relocs, thus - early exits.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000222 if (Reloc == Reloc::LocalOrGlobal)
223 return SectionKind::Data;
224 else if (Reloc == Reloc::None)
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000225 return SectionKind::ROData;
226 else {
227 // Ok, target wants something funny. Honour it.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000228 return (C->ContainsRelocations(Reloc) ?
229 SectionKind::Data : SectionKind::ROData);
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000230 }
231 } else {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000232 // Check, if initializer is a null-terminated string
Owen Anderson0a5372e2009-07-13 04:09:18 +0000233 if (isConstantString(GV->getParent()->getContext(), C))
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000234 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000235 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000236 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000237 }
238 }
239
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000240 // Variable either is not constant or thread-local - output to data section.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000241 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000242}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000243
244unsigned
245TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000246 const char* Name) const {
247 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000248
249 // Decode flags from global itself.
250 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000251 SectionKind::Kind Kind = SectionKindForGlobal(GV);
252 switch (Kind) {
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000253 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000254 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000255 break;
256 case SectionKind::ThreadData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000257 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000258 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000259 // FALLS THROUGH
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000260 case SectionKind::Data:
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000261 case SectionKind::DataRel:
262 case SectionKind::DataRelLocal:
263 case SectionKind::DataRelRO:
264 case SectionKind::DataRelROLocal:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000265 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000266 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000267 break;
268 case SectionKind::ROData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000269 case SectionKind::RODataMergeStr:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000270 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000271 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000272 break;
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000273 case SectionKind::SmallData:
274 case SectionKind::SmallBSS:
275 Flags |= SectionFlags::Writeable;
276 // FALLS THROUGH
277 case SectionKind::SmallROData:
278 Flags |= SectionFlags::Small;
279 break;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000280 default:
Torok Edwinc25e7582009-07-11 20:10:48 +0000281 LLVM_UNREACHABLE("Unexpected section kind!");
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000282 }
283
Duncan Sands667d4b82009-03-07 15:45:40 +0000284 if (GV->isWeakForLinker())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000285 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000286 }
287
288 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000289 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000290 Flags |= SectionFlags::Named;
291
292 // Some lame default implementation based on some magic section names.
293 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000294 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
295 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
296 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000297 Flags |= SectionFlags::BSS;
298 else if (strcmp(Name, ".tdata") == 0 ||
299 strncmp(Name, ".tdata.", 7) == 0 ||
300 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
301 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
302 Flags |= SectionFlags::TLS;
303 else if (strcmp(Name, ".tbss") == 0 ||
304 strncmp(Name, ".tbss.", 6) == 0 ||
305 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
306 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
307 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000308 }
309
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000310 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000311}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000312
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000313const Section*
Evan Cheng42ccc212008-08-08 17:56:50 +0000314TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000315 const Section* S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000316 // Select section name
317 if (GV->hasSection()) {
318 // Honour section already set, if any
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000319 unsigned Flags = SectionFlagsForGlobal(GV,
320 GV->getSection().c_str());
321 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000322 } else {
323 // Use default section depending on the 'type' of global
Evan Cheng42ccc212008-08-08 17:56:50 +0000324 S = SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000325 }
326
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000327 return S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000328}
329
330// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000331const Section*
332TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000333 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000334
Duncan Sands667d4b82009-03-07 15:45:40 +0000335 if (GV->isWeakForLinker()) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000336 std::string Name = UniqueSectionForGlobal(GV, Kind);
337 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
338 return getNamedSection(Name.c_str(), Flags);
339 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000340 if (Kind == SectionKind::Text)
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000341 return getTextSection();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000342 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000343 return getBSSSection_();
Anton Korobeynikov00181a32008-09-24 22:20:27 +0000344 else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
345 return getReadOnlySection();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000346 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000347
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000348 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000349}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000350
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000351// Lame default implementation. Calculate the section name for machine const.
352const Section*
353TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
354 // FIXME: Support data.rel stuff someday
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000355 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000356}
357
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000358std::string
359TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000360 SectionKind::Kind Kind) const {
361 switch (Kind) {
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000362 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000363 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000364 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000365 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000366 case SectionKind::DataRel:
367 return ".gnu.linkonce.d.rel" + GV->getName();
368 case SectionKind::DataRelLocal:
369 return ".gnu.linkonce.d.rel.local" + GV->getName();
370 case SectionKind::DataRelRO:
371 return ".gnu.linkonce.d.rel.ro" + GV->getName();
372 case SectionKind::DataRelROLocal:
373 return ".gnu.linkonce.d.rel.ro.local" + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000374 case SectionKind::SmallData:
375 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000376 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000377 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000378 case SectionKind::SmallBSS:
379 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000380 case SectionKind::ROData:
381 case SectionKind::RODataMergeConst:
382 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000383 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000384 case SectionKind::SmallROData:
385 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000386 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000387 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000388 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000389 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000390 default:
Torok Edwinc25e7582009-07-11 20:10:48 +0000391 LLVM_UNREACHABLE("Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000392 }
Devang Patel8a84e442009-01-05 17:31:22 +0000393 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000394}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000395
396const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000397TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
398 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000399 Section& S = Sections[Name];
400
401 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000402 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000403 S.Flags = Flags | SectionFlags::Named;
404 S.Name = Name;
405 }
406
407 return &S;
408}
409
410const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000411TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
412 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000413 Section& S = Sections[Directive];
414
415 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000416 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000417 S.Flags = Flags & ~SectionFlags::Named;
418 S.Name = Directive;
419 }
420
421 return &S;
422}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000423
424const std::string&
425TargetAsmInfo::getSectionFlags(unsigned Flags) const {
426 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
427
428 // We didn't print these flags yet, print and save them to map. This reduces
429 // amount of heap trashing due to std::string construction / concatenation.
430 if (I == FlagsStrings.end())
431 I = FlagsStrings.insert(std::make_pair(Flags,
432 printSectionFlags(Flags))).first;
433
434 return I->second;
435}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000436
437unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
438 unsigned Size = 0;
439 do {
440 Value >>= 7;
441 Size += sizeof(int8_t);
442 } while (Value);
443 return Size;
444}
445
446unsigned TargetAsmInfo::getSLEB128Size(int Value) {
447 unsigned Size = 0;
448 int Sign = Value >> (8 * sizeof(Value) - 1);
449 bool IsMore;
450
451 do {
452 unsigned Byte = Value & 0x7f;
453 Value >>= 7;
454 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
455 Size += sizeof(int8_t);
456 } while (IsMore);
457 return Size;
458}