blob: d85e5987570527b5b9a1fad50a0e10903005c0cf [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines target asm properties related what form asm statements
11// should take.
12//
13//===----------------------------------------------------------------------===//
14
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +000015#include "llvm/Constants.h"
16#include "llvm/GlobalVariable.h"
17#include "llvm/Function.h"
18#include "llvm/Module.h"
19#include "llvm/Type.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020#include "llvm/Target/TargetAsmInfo.h"
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +000021#include "llvm/Target/TargetOptions.h"
Anton Korobeynikov65c0d872008-02-27 23:33:50 +000022#include "llvm/Support/Dwarf.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000023#include <cctype>
24#include <cstring>
25
26using namespace llvm;
27
28TargetAsmInfo::TargetAsmInfo() :
Anton Korobeynikov55b94962008-09-24 22:15:21 +000029 TextSection(0),
Anton Korobeynikovcca60fa2008-09-24 22:16:16 +000030 DataSection(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000031 BSSSection("\t.bss"),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000032 BSSSection_(0),
33 ReadOnlySection(0),
34 ReadOnlySection_(0),
Bruno Cardoso Lopes8eef5122008-07-22 15:26:53 +000035 SmallDataSection(0),
36 SmallBSSSection(0),
37 SmallRODataSection(0),
Anton Korobeynikov9a213e42008-09-24 22:17:06 +000038 TLSDataSection(0),
39 TLSBSSSection(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040 ZeroFillDirective(0),
Dan Gohmana65530a2008-05-05 00:28:39 +000041 NonexecutableStackDirective(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042 NeedsSet(false),
43 MaxInstLength(4),
44 PCSymbol("$"),
45 SeparatorChar(';'),
46 CommentString("#"),
47 GlobalPrefix(""),
48 PrivateGlobalPrefix("."),
Dale Johannesen2d34f9f2008-09-09 01:21:22 +000049 LessPrivateGlobalPrefix(""),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050 JumpTableSpecialLabelPrefix(0),
51 GlobalVarAddrPrefix(""),
52 GlobalVarAddrSuffix(""),
53 FunctionAddrPrefix(""),
54 FunctionAddrSuffix(""),
Bill Wendlingd1bda4f2007-09-11 08:27:17 +000055 PersonalityPrefix(""),
56 PersonalitySuffix(""),
Bill Wendling2d369922007-09-11 17:20:55 +000057 NeedsIndirectEncoding(false),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058 InlineAsmStart("#APP"),
59 InlineAsmEnd("#NO_APP"),
60 AssemblerDialect(0),
Dale Johannesen8f03a202008-06-03 18:09:06 +000061 StringConstantPrefix(".str"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062 ZeroDirective("\t.zero\t"),
63 ZeroDirectiveSuffix(0),
64 AsciiDirective("\t.ascii\t"),
65 AscizDirective("\t.asciz\t"),
66 Data8bitsDirective("\t.byte\t"),
67 Data16bitsDirective("\t.short\t"),
68 Data32bitsDirective("\t.long\t"),
69 Data64bitsDirective("\t.quad\t"),
70 AlignDirective("\t.align\t"),
71 AlignmentIsInBytes(true),
Lauro Ramos Venancio9190bc42008-02-28 22:14:09 +000072 TextAlignFillValue(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073 SwitchToSectionDirective("\t.section\t"),
74 TextSectionStartSuffix(""),
75 DataSectionStartSuffix(""),
76 SectionEndDirectiveSuffix(0),
77 ConstantPoolSection("\t.section .rodata"),
78 JumpTableDataSection("\t.section .rodata"),
79 JumpTableDirective(0),
80 CStringSection(0),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000081 CStringSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000082 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
83 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
84 FourByteConstantSection(0),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000085 FourByteConstantSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000086 EightByteConstantSection(0),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000087 EightByteConstantSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 SixteenByteConstantSection(0),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000089 SixteenByteConstantSection_(0),
Gordon Henriksene383f2a2007-12-23 20:58:16 +000090 GlobalDirective("\t.globl\t"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000091 SetDirective(0),
92 LCOMMDirective(0),
93 COMMDirective("\t.comm\t"),
94 COMMDirectiveTakesAlignment(true),
95 HasDotTypeDotSizeDirective(true),
96 UsedDirective(0),
97 WeakRefDirective(0),
Dale Johannesenfb3ac732007-11-20 23:24:42 +000098 WeakDefDirective(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099 HiddenDirective("\t.hidden\t"),
100 ProtectedDirective("\t.protected\t"),
101 AbsoluteDebugSectionOffsets(false),
102 AbsoluteEHSectionOffsets(false),
103 HasLEB128(false),
Dan Gohman307ad202007-09-24 21:09:53 +0000104 HasDotLocAndDotFile(false),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000105 SupportsDebugInformation(false),
106 SupportsExceptionHandling(false),
107 DwarfRequiresFrameSection(true),
Dale Johannesen23b89a62007-11-21 00:45:00 +0000108 GlobalEHDirective(0),
Dale Johannesenf09b5992008-01-10 02:03:30 +0000109 SupportsWeakOmittedEHFrame(true),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110 DwarfSectionOffsetDirective(0),
111 DwarfAbbrevSection(".debug_abbrev"),
112 DwarfInfoSection(".debug_info"),
113 DwarfLineSection(".debug_line"),
114 DwarfFrameSection(".debug_frame"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000115 DwarfPubNamesSection(".debug_pubnames"),
116 DwarfPubTypesSection(".debug_pubtypes"),
117 DwarfStrSection(".debug_str"),
118 DwarfLocSection(".debug_loc"),
119 DwarfARangesSection(".debug_aranges"),
120 DwarfRangesSection(".debug_ranges"),
121 DwarfMacInfoSection(".debug_macinfo"),
122 DwarfEHFrameSection(".eh_frame"),
123 DwarfExceptionSection(".gcc_except_table"),
124 AsmTransCBE(0) {
Anton Korobeynikov55b94962008-09-24 22:15:21 +0000125 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikovcca60fa2008-09-24 22:16:16 +0000126 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127}
128
129TargetAsmInfo::~TargetAsmInfo() {
130}
131
132/// Measure the specified inline asm to determine an approximation of its
133/// length.
134/// Comments (which run till the next SeparatorChar or newline) do not
135/// count as an instruction.
136/// Any other non-whitespace text is considered an instruction, with
137/// multiple instructions separated by SeparatorChar or newlines.
138/// Variable-length instructions are not handled here; this function
139/// may be overloaded in the target code to do that.
140unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
141 // Count the number of instructions in the asm.
142 bool atInsnStart = true;
143 unsigned Length = 0;
144 for (; *Str; ++Str) {
145 if (*Str == '\n' || *Str == SeparatorChar)
146 atInsnStart = true;
147 if (atInsnStart && !isspace(*Str)) {
148 Length += MaxInstLength;
149 atInsnStart = false;
150 }
151 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
152 atInsnStart = false;
153 }
154
155 return Length;
156}
157
Anton Korobeynikov8750d7c2008-02-29 22:09:08 +0000158unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000159 bool Global) const {
160 return dwarf::DW_EH_PE_absptr;
161}
162
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000163static bool isSuitableForBSS(const GlobalVariable *GV) {
164 if (!GV->hasInitializer())
165 return true;
166
167 // Leave constant zeros in readonly constant sections, so they can be shared
168 Constant *C = GV->getInitializer();
169 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
170}
171
172SectionKind::Kind
173TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
174 // Early exit - functions should be always in text sections.
175 if (isa<Function>(GV))
176 return SectionKind::Text;
177
178 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
179 bool isThreadLocal = GVar->isThreadLocal();
180 assert(GVar && "Invalid global value for section selection");
181
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000182 if (isSuitableForBSS(GVar)) {
183 // Variable can be easily put to BSS section.
184 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
185 } else if (GVar->isConstant() && !isThreadLocal) {
186 // Now we know, that varible has initializer and it is constant. We need to
187 // check its initializer to decide, which section to output it into. Also
188 // note, there is no thread-local r/o section.
189 Constant *C = GVar->getInitializer();
190 if (C->ContainsRelocations())
Anton Korobeynikovb81503c2008-07-09 13:24:38 +0000191 return SectionKind::ROData;
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000192 else {
193 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
194 // Check, if initializer is a null-terminated string
195 if (CVA && CVA->isCString())
Anton Korobeynikovb81503c2008-07-09 13:24:38 +0000196 return SectionKind::RODataMergeStr;
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000197 else
Anton Korobeynikovb81503c2008-07-09 13:24:38 +0000198 return SectionKind::RODataMergeConst;
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000199 }
200 }
201
202 // Variable is not constant or thread-local - emit to generic data section.
203 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
204}
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000205
206unsigned
207TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000208 const char* Name) const {
209 unsigned Flags = SectionFlags::None;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000210
211 // Decode flags from global itself.
212 if (GV) {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000213 SectionKind::Kind Kind = SectionKindForGlobal(GV);
214 switch (Kind) {
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000215 case SectionKind::Text:
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000216 Flags |= SectionFlags::Code;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000217 break;
218 case SectionKind::ThreadData:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000219 case SectionKind::ThreadBSS:
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000220 Flags |= SectionFlags::TLS;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000221 // FALLS THROUGH
Anton Korobeynikov16061032008-07-09 13:29:44 +0000222 case SectionKind::Data:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000223 case SectionKind::BSS:
Anton Korobeynikov16061032008-07-09 13:29:44 +0000224 Flags |= SectionFlags::Writeable;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000225 break;
226 case SectionKind::ROData:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000227 case SectionKind::RODataMergeStr:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000228 case SectionKind::RODataMergeConst:
Anton Korobeynikov16061032008-07-09 13:29:44 +0000229 // No additional flags here
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000230 break;
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000231 case SectionKind::SmallData:
232 case SectionKind::SmallBSS:
233 Flags |= SectionFlags::Writeable;
234 // FALLS THROUGH
235 case SectionKind::SmallROData:
236 Flags |= SectionFlags::Small;
237 break;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000238 default:
239 assert(0 && "Unexpected section kind!");
240 }
241
Anton Korobeynikovf6816542008-07-09 13:27:59 +0000242 if (GV->isWeakForLinker())
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000243 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000244 }
245
246 // Add flags from sections, if any.
Anton Korobeynikovf7a82942008-07-09 13:25:46 +0000247 if (Name && *Name) {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000248 Flags |= SectionFlags::Named;
249
250 // Some lame default implementation based on some magic section names.
251 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000252 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
253 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
254 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000255 Flags |= SectionFlags::BSS;
256 else if (strcmp(Name, ".tdata") == 0 ||
257 strncmp(Name, ".tdata.", 7) == 0 ||
258 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
259 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
260 Flags |= SectionFlags::TLS;
261 else if (strcmp(Name, ".tbss") == 0 ||
262 strncmp(Name, ".tbss.", 6) == 0 ||
263 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
264 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
265 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000266 }
267
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000268 return Flags;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000269}
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000270
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000271const Section*
Evan Chengeb774e12008-08-08 17:56:50 +0000272TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000273 const Section* S;
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000274 // Select section name
275 if (GV->hasSection()) {
276 // Honour section already set, if any
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000277 unsigned Flags = SectionFlagsForGlobal(GV,
278 GV->getSection().c_str());
279 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000280 } else {
281 // Use default section depending on the 'type' of global
Evan Chengeb774e12008-08-08 17:56:50 +0000282 S = SelectSectionForGlobal(GV);
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000283 }
284
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000285 return S;
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000286}
287
288// Lame default implementation. Calculate the section name for global.
Evan Chengeb774e12008-08-08 17:56:50 +0000289const Section*
290TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000291 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000292
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000293 if (GV->isWeakForLinker()) {
294 std::string Name = UniqueSectionForGlobal(GV, Kind);
295 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
296 return getNamedSection(Name.c_str(), Flags);
297 } else {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000298 if (Kind == SectionKind::Text)
Anton Korobeynikov55b94962008-09-24 22:15:21 +0000299 return getTextSection();
Anton Korobeynikov80475a52008-08-07 09:51:54 +0000300 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000301 return getBSSSection_();
Anton Korobeynikov80475a52008-08-07 09:51:54 +0000302 else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind))
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000303 return getReadOnlySection_();
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000304 }
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000305
Anton Korobeynikovcca60fa2008-09-24 22:16:16 +0000306 return getDataSection();
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000307}
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000308
Anton Korobeynikovfc54db12008-08-07 09:50:34 +0000309// Lame default implementation. Calculate the section name for machine const.
310const Section*
311TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
312 // FIXME: Support data.rel stuff someday
Anton Korobeynikovcca60fa2008-09-24 22:16:16 +0000313 return getDataSection();
Anton Korobeynikovfc54db12008-08-07 09:50:34 +0000314}
315
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000316std::string
317TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000318 SectionKind::Kind Kind) const {
319 switch (Kind) {
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000320 case SectionKind::Text:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000321 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000322 case SectionKind::Data:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000323 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000324 case SectionKind::SmallData:
325 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000326 case SectionKind::BSS:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000327 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000328 case SectionKind::SmallBSS:
329 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000330 case SectionKind::ROData:
331 case SectionKind::RODataMergeConst:
332 case SectionKind::RODataMergeStr:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000333 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000334 case SectionKind::SmallROData:
335 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000336 case SectionKind::ThreadData:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000337 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000338 case SectionKind::ThreadBSS:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000339 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000340 default:
341 assert(0 && "Unknown section kind");
342 }
343}
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000344
345const Section*
asla1c96962008-08-16 12:58:12 +0000346TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
347 bool Override) const {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000348 Section& S = Sections[Name];
349
350 // This is newly-created section, set it up properly.
asla1c96962008-08-16 12:58:12 +0000351 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000352 S.Flags = Flags | SectionFlags::Named;
353 S.Name = Name;
354 }
355
356 return &S;
357}
358
359const Section*
asla1c96962008-08-16 12:58:12 +0000360TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
361 bool Override) const {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000362 Section& S = Sections[Directive];
363
364 // This is newly-created section, set it up properly.
asla1c96962008-08-16 12:58:12 +0000365 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000366 S.Flags = Flags & ~SectionFlags::Named;
367 S.Name = Directive;
368 }
369
370 return &S;
371}
asl27ffd262008-08-16 12:57:07 +0000372
373const std::string&
374TargetAsmInfo::getSectionFlags(unsigned Flags) const {
375 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
376
377 // We didn't print these flags yet, print and save them to map. This reduces
378 // amount of heap trashing due to std::string construction / concatenation.
379 if (I == FlagsStrings.end())
380 I = FlagsStrings.insert(std::make_pair(Flags,
381 printSectionFlags(Flags))).first;
382
383 return I->second;
384}
aslc200b112008-08-16 12:57:46 +0000385
386unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
387 unsigned Size = 0;
388 do {
389 Value >>= 7;
390 Size += sizeof(int8_t);
391 } while (Value);
392 return Size;
393}
394
395unsigned TargetAsmInfo::getSLEB128Size(int Value) {
396 unsigned Size = 0;
397 int Sign = Value >> (8 * sizeof(Value) - 1);
398 bool IsMore;
399
400 do {
401 unsigned Byte = Value & 0x7f;
402 Value >>= 7;
403 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
404 Size += sizeof(int8_t);
405 } while (IsMore);
406 return Size;
407}