blob: 829bb902f1e463c0777d117391d4de4a93ddc158 [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)
Daniel Dunbar7384e1b2009-07-22 20:26:37 +000031 : TM(tm)
32{
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000033 BSSSection = "\t.bss";
34 BSSSection_ = 0;
35 ReadOnlySection = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000036 TLSDataSection = 0;
37 TLSBSSSection = 0;
38 ZeroFillDirective = 0;
39 NonexecutableStackDirective = 0;
40 NeedsSet = false;
41 MaxInstLength = 4;
42 PCSymbol = "$";
43 SeparatorChar = ';';
David Greene014700c2009-07-13 20:25:48 +000044 CommentColumn = 60;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000045 CommentString = "#";
David Greene76081c42009-07-20 22:02:59 +000046 FirstOperandColumn = 0;
47 MaxOperandLength = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000048 GlobalPrefix = "";
49 PrivateGlobalPrefix = ".";
Chris Lattner90f8b702009-07-21 17:30:51 +000050 LinkerPrivateGlobalPrefix = "";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000051 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;
Chris Lattnera93ca922009-06-18 23:41:35 +000062 AllowQuotesInName = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000063 ZeroDirective = "\t.zero\t";
64 ZeroDirectiveSuffix = 0;
65 AsciiDirective = "\t.ascii\t";
66 AscizDirective = "\t.asciz\t";
67 Data8bitsDirective = "\t.byte\t";
68 Data16bitsDirective = "\t.short\t";
69 Data32bitsDirective = "\t.long\t";
70 Data64bitsDirective = "\t.quad\t";
71 AlignDirective = "\t.align\t";
72 AlignmentIsInBytes = true;
73 TextAlignFillValue = 0;
74 SwitchToSectionDirective = "\t.section\t";
75 TextSectionStartSuffix = "";
76 DataSectionStartSuffix = "";
77 SectionEndDirectiveSuffix = 0;
78 ConstantPoolSection = "\t.section .rodata";
79 JumpTableDataSection = "\t.section .rodata";
80 JumpTableDirective = 0;
81 CStringSection = 0;
82 CStringSection_ = 0;
83 // FIXME: Flags are ELFish - replace with normal section stuff.
84 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
85 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
86 GlobalDirective = "\t.globl\t";
87 SetDirective = 0;
88 LCOMMDirective = 0;
89 COMMDirective = "\t.comm\t";
90 COMMDirectiveTakesAlignment = true;
91 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000092 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000093 UsedDirective = 0;
94 WeakRefDirective = 0;
95 WeakDefDirective = 0;
96 // FIXME: These are ELFish - move to ELFTAI.
97 HiddenDirective = "\t.hidden\t";
98 ProtectedDirective = "\t.protected\t";
99 AbsoluteDebugSectionOffsets = false;
100 AbsoluteEHSectionOffsets = false;
101 HasLEB128 = false;
102 HasDotLocAndDotFile = false;
103 SupportsDebugInformation = false;
104 SupportsExceptionHandling = false;
105 DwarfRequiresFrameSection = true;
Devang Patel0f7fef32009-04-13 17:02:03 +0000106 DwarfUsesInlineInfoSection = false;
Chris Lattnere2cf37b2009-07-17 20:46:40 +0000107 Is_EHSymbolPrivate = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000108 GlobalEHDirective = 0;
109 SupportsWeakOmittedEHFrame = true;
110 DwarfSectionOffsetDirective = 0;
111 DwarfAbbrevSection = ".debug_abbrev";
112 DwarfInfoSection = ".debug_info";
113 DwarfLineSection = ".debug_line";
114 DwarfFrameSection = ".debug_frame";
115 DwarfPubNamesSection = ".debug_pubnames";
116 DwarfPubTypesSection = ".debug_pubtypes";
Devang Patel0f7fef32009-04-13 17:02:03 +0000117 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000118 DwarfStrSection = ".debug_str";
119 DwarfLocSection = ".debug_loc";
120 DwarfARangesSection = ".debug_aranges";
121 DwarfRangesSection = ".debug_ranges";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000122 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000123 DwarfEHFrameSection = ".eh_frame";
124 DwarfExceptionSection = ".gcc_except_table";
125 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000126 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000127 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000128}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000129
130TargetAsmInfo::~TargetAsmInfo() {
131}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000132
133/// Measure the specified inline asm to determine an approximation of its
134/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000135/// Comments (which run till the next SeparatorChar or newline) do not
136/// count as an instruction.
137/// Any other non-whitespace text is considered an instruction, with
138/// multiple instructions separated by SeparatorChar or newlines.
139/// Variable-length instructions are not handled here; this function
140/// may be overloaded in the target code to do that.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000141unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
142 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000143 bool atInsnStart = true;
144 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000145 for (; *Str; ++Str) {
146 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000147 atInsnStart = true;
148 if (atInsnStart && !isspace(*Str)) {
149 Length += MaxInstLength;
150 atInsnStart = false;
151 }
152 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
153 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000154 }
155
Dale Johannesen3bb62832007-04-23 20:00:17 +0000156 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000157}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000158
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000159unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000160 bool Global) const {
161 return dwarf::DW_EH_PE_absptr;
162}
163
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000164static bool isSuitableForBSS(const GlobalVariable *GV) {
165 if (!GV->hasInitializer())
166 return true;
167
168 // Leave constant zeros in readonly constant sections, so they can be shared
169 Constant *C = GV->getInitializer();
170 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
171}
172
Owen Anderson1ca29d32009-07-13 21:27:19 +0000173static bool isConstantString(const Constant *C) {
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000174 // First check: is we have constant array of i8 terminated with zero
175 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
176 // Check, if initializer is a null-terminated string
Owen Anderson1ca29d32009-07-13 21:27:19 +0000177 if (CVA && CVA->isCString())
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000178 return true;
179
180 // Another possibility: [1 x i8] zeroinitializer
181 if (isa<ConstantAggregateZero>(C)) {
182 if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
183 return (Ty->getElementType() == Type::Int8Ty &&
184 Ty->getNumElements() == 1);
185 }
186 }
187
188 return false;
189}
190
Chris Lattner8adc5472009-07-24 16:46:50 +0000191static unsigned SectionFlagsForGlobal(const GlobalValue *GV,
Chris Lattner27f30652009-07-24 16:50:24 +0000192 SectionKind::Kind Kind) {
Chris Lattner104bbd12009-07-24 16:44:01 +0000193 unsigned Flags = SectionFlags::None;
194
195 // Decode flags from global itself.
Chris Lattner104bbd12009-07-24 16:44:01 +0000196 switch (Kind) {
197 case SectionKind::Text:
198 Flags |= SectionFlags::Code;
199 break;
200 case SectionKind::ThreadData:
201 case SectionKind::ThreadBSS:
202 Flags |= SectionFlags::TLS;
203 // FALLS THROUGH
204 case SectionKind::Data:
205 case SectionKind::DataRel:
206 case SectionKind::DataRelLocal:
207 case SectionKind::DataRelRO:
208 case SectionKind::DataRelROLocal:
209 case SectionKind::BSS:
210 Flags |= SectionFlags::Writeable;
211 break;
212 case SectionKind::ROData:
213 case SectionKind::RODataMergeStr:
214 case SectionKind::RODataMergeConst:
215 // No additional flags here
216 break;
217 default:
218 llvm_unreachable("Unexpected section kind!");
219 }
220
221 if (GV->isWeakForLinker())
222 Flags |= SectionFlags::Linkonce;
223
Chris Lattner27f30652009-07-24 16:50:24 +0000224 return Flags;
225}
Chris Lattner104bbd12009-07-24 16:44:01 +0000226
Chris Lattner27f30652009-07-24 16:50:24 +0000227static unsigned GetSectionFlagsForNamedELFSection(const char *Name) {
228 unsigned Flags = 0;
229 // Some lame default implementation based on some magic section names.
230 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
231 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
232 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
233 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
234 Flags |= SectionFlags::BSS;
235 else if (strcmp(Name, ".tdata") == 0 ||
236 strncmp(Name, ".tdata.", 7) == 0 ||
237 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
238 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
239 Flags |= SectionFlags::TLS;
240 else if (strcmp(Name, ".tbss") == 0 ||
241 strncmp(Name, ".tbss.", 6) == 0 ||
242 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
243 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
244 Flags |= SectionFlags::BSS | SectionFlags::TLS;
245
Chris Lattner104bbd12009-07-24 16:44:01 +0000246 return Flags;
247}
248
249
250
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000251SectionKind::Kind
252TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
253 // Early exit - functions should be always in text sections.
254 if (isa<Function>(GV))
255 return SectionKind::Text;
256
257 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
258 bool isThreadLocal = GVar->isThreadLocal();
259 assert(GVar && "Invalid global value for section selection");
260
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000261 if (isSuitableForBSS(GVar)) {
262 // Variable can be easily put to BSS section.
Chris Lattner7cf12c72009-07-22 00:05:44 +0000263 return isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000264 } else if (GVar->isConstant() && !isThreadLocal) {
Chris Lattner97d2cae2009-07-21 23:47:11 +0000265 // Now we know, that variable has initializer and it is constant. We need to
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000266 // check its initializer to decide, which section to output it into. Also
267 // note, there is no thread-local r/o section.
268 Constant *C = GVar->getInitializer();
Chris Lattner7cf12c72009-07-22 00:05:44 +0000269 if (C->getRelocationInfo() != 0) {
Chris Lattnerb2fb9cc2009-07-21 23:49:55 +0000270 // Decide whether it is still possible to put symbol into r/o section.
271 if (TM.getRelocationModel() != Reloc::Static)
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000272 return SectionKind::Data;
Chris Lattnerb2fb9cc2009-07-21 23:49:55 +0000273 else
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000274 return SectionKind::ROData;
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000275 } else {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000276 // Check, if initializer is a null-terminated string
Owen Anderson1ca29d32009-07-13 21:27:19 +0000277 if (isConstantString(C))
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000278 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000279 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000280 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000281 }
282 }
283
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000284 // Variable either is not constant or thread-local - output to data section.
Chris Lattnerfb3431a2009-07-24 03:49:17 +0000285 return isThreadLocal ? SectionKind::ThreadData : SectionKind::Data;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000286}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000287
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000288
Chris Lattner7558f112009-07-21 21:09:35 +0000289const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000290 // Select section name
291 if (GV->hasSection()) {
Chris Lattner7558f112009-07-21 21:09:35 +0000292 // Honour section already set, if any.
Chris Lattner27f30652009-07-24 16:50:24 +0000293 unsigned Flags = SectionFlagsForGlobal(GV, SectionKindForGlobal(GV));
294
295 // This is an explicitly named section.
296 Flags |= SectionFlags::Named;
297
298 // If the target has magic semantics for certain section names, make sure to
299 // pick up the flags. This allows the user to write things with attribute
300 // section and still get the appropriate section flags printed.
301 Flags |= GetSectionFlagsForNamedELFSection(GV->getSection().c_str());
302
Chris Lattner7558f112009-07-21 21:09:35 +0000303 return getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000304 }
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000305
Chris Lattnereed05b82009-07-24 05:10:25 +0000306 // If this global is linkonce/weak and the target handles this by emitting it
307 // into a 'uniqued' section name, create and return the section now.
308 if (GV->isWeakForLinker()) {
309 if (const char *Prefix =
310 getSectionPrefixForUniqueGlobal(SectionKindForGlobal(GV))) {
311 // FIXME: Use mangler interface (PR4584).
Daniel Dunbar895c9ed2009-07-24 12:21:08 +0000312 std::string Name = Prefix+GV->getNameStr();
Chris Lattner8adc5472009-07-24 16:46:50 +0000313 unsigned Flags = SectionFlagsForGlobal(GV, SectionKindForGlobal(GV));
Chris Lattnereed05b82009-07-24 05:10:25 +0000314 return getNamedSection(Name.c_str(), Flags);
315 }
316 }
317
Chris Lattner7558f112009-07-21 21:09:35 +0000318 // Use default section depending on the 'type' of global
319 return SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000320}
321
322// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000323const Section*
324TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000325 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000326
Chris Lattnereed05b82009-07-24 05:10:25 +0000327 if (Kind == SectionKind::Text)
328 return getTextSection();
329
330 if (isBSS(Kind))
331 if (const Section *S = getBSSSection_())
332 return S;
333
334 if (SectionKind::isReadOnly(Kind))
335 if (const Section *S = getReadOnlySection())
336 return S;
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000337
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000338 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000339}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000340
Chris Lattner298414e2009-07-22 00:28:43 +0000341/// getSectionForMergableConstant - Given a mergable constant with the
342/// specified size and relocation information, return a section that it
343/// should be placed in.
344const Section *
345TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
346 unsigned ReloInfo) const {
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000347 // FIXME: Support data.rel stuff someday
Chris Lattner298414e2009-07-22 00:28:43 +0000348 // Lame default implementation. Calculate the section name for machine const.
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000349 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000350}
351
Chris Lattner298414e2009-07-22 00:28:43 +0000352
353
354
Chris Lattner55acc682009-07-24 04:49:34 +0000355const char *
356TargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000357 switch (Kind) {
Chris Lattner55acc682009-07-24 04:49:34 +0000358 default: llvm_unreachable("Unknown section kind");
359 case SectionKind::Text: return ".gnu.linkonce.t.";
360 case SectionKind::Data: return ".gnu.linkonce.d.";
361 case SectionKind::DataRel: return ".gnu.linkonce.d.rel.";
362 case SectionKind::DataRelLocal: return ".gnu.linkonce.d.rel.local.";
363 case SectionKind::DataRelRO: return ".gnu.linkonce.d.rel.ro.";
364 case SectionKind::DataRelROLocal: return ".gnu.linkonce.d.rel.ro.local.";
365 case SectionKind::BSS: return ".gnu.linkonce.b.";
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000366 case SectionKind::ROData:
367 case SectionKind::RODataMergeConst:
Chris Lattner55acc682009-07-24 04:49:34 +0000368 case SectionKind::RODataMergeStr: return ".gnu.linkonce.r.";
369 case SectionKind::ThreadData: return ".gnu.linkonce.td.";
370 case SectionKind::ThreadBSS: return ".gnu.linkonce.tb.";
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000371 }
372}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000373
Chris Lattner7558f112009-07-21 21:09:35 +0000374const Section *TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
375 bool Override) const {
376 Section &S = Sections[Name];
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000377
378 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000379 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000380 S.Flags = Flags | SectionFlags::Named;
381 S.Name = Name;
382 }
383
384 return &S;
385}
386
387const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000388TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
389 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000390 Section& S = Sections[Directive];
391
392 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000393 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000394 S.Flags = Flags & ~SectionFlags::Named;
395 S.Name = Directive;
396 }
397
398 return &S;
399}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000400
401const std::string&
402TargetAsmInfo::getSectionFlags(unsigned Flags) const {
403 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
404
405 // We didn't print these flags yet, print and save them to map. This reduces
406 // amount of heap trashing due to std::string construction / concatenation.
407 if (I == FlagsStrings.end())
408 I = FlagsStrings.insert(std::make_pair(Flags,
409 printSectionFlags(Flags))).first;
410
411 return I->second;
412}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000413
414unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
415 unsigned Size = 0;
416 do {
417 Value >>= 7;
418 Size += sizeof(int8_t);
419 } while (Value);
420 return Size;
421}
422
423unsigned TargetAsmInfo::getSLEB128Size(int Value) {
424 unsigned Size = 0;
425 int Sign = Value >> (8 * sizeof(Value) - 1);
426 bool IsMore;
427
428 do {
429 unsigned Byte = Value & 0x7f;
430 Value >>= 7;
431 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
432 Size += sizeof(int8_t);
433 } while (IsMore);
434 return Size;
435}