blob: d687e2f44cfd7787a2b541d66fe0ade02550f762 [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 Korobeynikov28a2b542008-06-28 13:45:57 +000022#include "llvm/Target/TargetOptions.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000023#include "llvm/Support/Dwarf.h"
Dale Johannesen3bb62832007-04-23 20:00:17 +000024#include <cctype>
25#include <cstring>
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000026
27using namespace llvm;
28
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000029void TargetAsmInfo::fillDefaultValues() {
30 BSSSection = "\t.bss";
31 BSSSection_ = 0;
32 ReadOnlySection = 0;
33 SmallDataSection = 0;
34 SmallBSSSection = 0;
35 SmallRODataSection = 0;
36 TLSDataSection = 0;
37 TLSBSSSection = 0;
38 ZeroFillDirective = 0;
39 NonexecutableStackDirective = 0;
40 NeedsSet = false;
41 MaxInstLength = 4;
42 PCSymbol = "$";
43 SeparatorChar = ';';
44 CommentString = "#";
45 GlobalPrefix = "";
46 PrivateGlobalPrefix = ".";
47 LessPrivateGlobalPrefix = "";
48 JumpTableSpecialLabelPrefix = 0;
49 GlobalVarAddrPrefix = "";
50 GlobalVarAddrSuffix = "";
51 FunctionAddrPrefix = "";
52 FunctionAddrSuffix = "";
53 PersonalityPrefix = "";
54 PersonalitySuffix = "";
55 NeedsIndirectEncoding = false;
56 InlineAsmStart = "#APP";
57 InlineAsmEnd = "#NO_APP";
58 AssemblerDialect = 0;
59 StringConstantPrefix = ".str";
60 ZeroDirective = "\t.zero\t";
61 ZeroDirectiveSuffix = 0;
62 AsciiDirective = "\t.ascii\t";
63 AscizDirective = "\t.asciz\t";
64 Data8bitsDirective = "\t.byte\t";
65 Data16bitsDirective = "\t.short\t";
66 Data32bitsDirective = "\t.long\t";
67 Data64bitsDirective = "\t.quad\t";
68 AlignDirective = "\t.align\t";
69 AlignmentIsInBytes = true;
70 TextAlignFillValue = 0;
71 SwitchToSectionDirective = "\t.section\t";
72 TextSectionStartSuffix = "";
73 DataSectionStartSuffix = "";
74 SectionEndDirectiveSuffix = 0;
75 ConstantPoolSection = "\t.section .rodata";
76 JumpTableDataSection = "\t.section .rodata";
77 JumpTableDirective = 0;
78 CStringSection = 0;
79 CStringSection_ = 0;
80 // FIXME: Flags are ELFish - replace with normal section stuff.
81 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
82 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
83 GlobalDirective = "\t.globl\t";
84 SetDirective = 0;
85 LCOMMDirective = 0;
86 COMMDirective = "\t.comm\t";
87 COMMDirectiveTakesAlignment = true;
88 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000089 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000090 UsedDirective = 0;
91 WeakRefDirective = 0;
92 WeakDefDirective = 0;
93 // FIXME: These are ELFish - move to ELFTAI.
94 HiddenDirective = "\t.hidden\t";
95 ProtectedDirective = "\t.protected\t";
96 AbsoluteDebugSectionOffsets = false;
97 AbsoluteEHSectionOffsets = false;
98 HasLEB128 = false;
99 HasDotLocAndDotFile = false;
100 SupportsDebugInformation = false;
101 SupportsExceptionHandling = false;
102 DwarfRequiresFrameSection = true;
Scott Michel210de722009-01-26 22:32:51 +0000103 SupportsMacInfoSection = true;
Bill Wendling722f5f12008-12-24 08:05:17 +0000104 NonLocalEHFrameLabel = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000105 GlobalEHDirective = 0;
106 SupportsWeakOmittedEHFrame = true;
107 DwarfSectionOffsetDirective = 0;
108 DwarfAbbrevSection = ".debug_abbrev";
109 DwarfInfoSection = ".debug_info";
110 DwarfLineSection = ".debug_line";
111 DwarfFrameSection = ".debug_frame";
112 DwarfPubNamesSection = ".debug_pubnames";
113 DwarfPubTypesSection = ".debug_pubtypes";
114 DwarfStrSection = ".debug_str";
115 DwarfLocSection = ".debug_loc";
116 DwarfARangesSection = ".debug_aranges";
117 DwarfRangesSection = ".debug_ranges";
118 DwarfMacInfoSection = ".debug_macinfo";
119 DwarfEHFrameSection = ".eh_frame";
120 DwarfExceptionSection = ".gcc_except_table";
121 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000122 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000123 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000124}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000125
Dan Gohman8f092252008-11-03 18:22:42 +0000126TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
127 : TM(tm) {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000128 fillDefaultValues();
129}
130
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000131TargetAsmInfo::~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
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000174static bool isConstantString(const Constant *C) {
175 // 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
178 if (CVA && CVA->isCString())
179 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
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.
205 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
206 } else if (GVar->isConstant() && !isThreadLocal) {
207 // Now we know, that varible has initializer and it is constant. We need to
208 // 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();
211 if (C->ContainsRelocations())
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000212 return SectionKind::ROData;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000213 else {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000214 // Check, if initializer is a null-terminated string
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000215 if (isConstantString(C))
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000216 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000217 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000218 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000219 }
220 }
221
222 // Variable is not constant or thread-local - emit to generic data section.
223 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
224}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000225
226unsigned
227TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000228 const char* Name) const {
229 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000230
231 // Decode flags from global itself.
232 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000233 SectionKind::Kind Kind = SectionKindForGlobal(GV);
234 switch (Kind) {
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000235 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000236 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000237 break;
238 case SectionKind::ThreadData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000239 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000240 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000241 // FALLS THROUGH
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000242 case SectionKind::Data:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000243 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000244 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000245 break;
246 case SectionKind::ROData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000247 case SectionKind::RODataMergeStr:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000248 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000249 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000250 break;
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000251 case SectionKind::SmallData:
252 case SectionKind::SmallBSS:
253 Flags |= SectionFlags::Writeable;
254 // FALLS THROUGH
255 case SectionKind::SmallROData:
256 Flags |= SectionFlags::Small;
257 break;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000258 default:
259 assert(0 && "Unexpected section kind!");
260 }
261
Duncan Sands5df31862008-09-29 11:25:42 +0000262 if (GV->mayBeOverridden())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000263 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000264 }
265
266 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000267 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000268 Flags |= SectionFlags::Named;
269
270 // Some lame default implementation based on some magic section names.
271 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000272 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
273 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
274 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000275 Flags |= SectionFlags::BSS;
276 else if (strcmp(Name, ".tdata") == 0 ||
277 strncmp(Name, ".tdata.", 7) == 0 ||
278 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
279 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
280 Flags |= SectionFlags::TLS;
281 else if (strcmp(Name, ".tbss") == 0 ||
282 strncmp(Name, ".tbss.", 6) == 0 ||
283 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
284 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
285 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000286 }
287
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000288 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000289}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000290
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000291const Section*
Evan Cheng42ccc212008-08-08 17:56:50 +0000292TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000293 const Section* S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000294 // Select section name
295 if (GV->hasSection()) {
296 // Honour section already set, if any
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000297 unsigned Flags = SectionFlagsForGlobal(GV,
298 GV->getSection().c_str());
299 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000300 } else {
301 // Use default section depending on the 'type' of global
Evan Cheng42ccc212008-08-08 17:56:50 +0000302 S = SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000303 }
304
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000305 return S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000306}
307
308// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000309const Section*
310TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000311 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000312
Duncan Sands5df31862008-09-29 11:25:42 +0000313 if (GV->mayBeOverridden()) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000314 std::string Name = UniqueSectionForGlobal(GV, Kind);
315 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
316 return getNamedSection(Name.c_str(), Flags);
317 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000318 if (Kind == SectionKind::Text)
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000319 return getTextSection();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000320 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000321 return getBSSSection_();
Anton Korobeynikov00181a32008-09-24 22:20:27 +0000322 else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
323 return getReadOnlySection();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000324 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000325
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000326 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000327}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000328
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000329// Lame default implementation. Calculate the section name for machine const.
330const Section*
331TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
332 // FIXME: Support data.rel stuff someday
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000333 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000334}
335
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000336std::string
337TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000338 SectionKind::Kind Kind) const {
339 switch (Kind) {
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000340 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000341 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000342 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000343 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000344 case SectionKind::SmallData:
345 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000346 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000347 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000348 case SectionKind::SmallBSS:
349 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000350 case SectionKind::ROData:
351 case SectionKind::RODataMergeConst:
352 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000353 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000354 case SectionKind::SmallROData:
355 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000356 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000357 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000358 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000359 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000360 default:
361 assert(0 && "Unknown section kind");
362 }
Devang Patel8a84e442009-01-05 17:31:22 +0000363 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000364}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000365
366const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000367TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
368 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000369 Section& S = Sections[Name];
370
371 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000372 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000373 S.Flags = Flags | SectionFlags::Named;
374 S.Name = Name;
375 }
376
377 return &S;
378}
379
380const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000381TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
382 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000383 Section& S = Sections[Directive];
384
385 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000386 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000387 S.Flags = Flags & ~SectionFlags::Named;
388 S.Name = Directive;
389 }
390
391 return &S;
392}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000393
394const std::string&
395TargetAsmInfo::getSectionFlags(unsigned Flags) const {
396 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
397
398 // We didn't print these flags yet, print and save them to map. This reduces
399 // amount of heap trashing due to std::string construction / concatenation.
400 if (I == FlagsStrings.end())
401 I = FlagsStrings.insert(std::make_pair(Flags,
402 printSectionFlags(Flags))).first;
403
404 return I->second;
405}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000406
407unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
408 unsigned Size = 0;
409 do {
410 Value >>= 7;
411 Size += sizeof(int8_t);
412 } while (Value);
413 return Size;
414}
415
416unsigned TargetAsmInfo::getSLEB128Size(int Value) {
417 unsigned Size = 0;
418 int Sign = Value >> (8 * sizeof(Value) - 1);
419 bool IsMore;
420
421 do {
422 unsigned Byte = Value & 0x7f;
423 Value >>= 7;
424 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
425 Size += sizeof(int8_t);
426 } while (IsMore);
427 return Size;
428}