blob: c9a525a506edecc76bc010fe110e7238213c85ea [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"
16#include "llvm/GlobalVariable.h"
17#include "llvm/Function.h"
18#include "llvm/Module.h"
19#include "llvm/Type.h"
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000020#include "llvm/Target/TargetAsmInfo.h"
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000021#include "llvm/Target/TargetOptions.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000022#include "llvm/Support/Dwarf.h"
Dale Johannesen3bb62832007-04-23 20:00:17 +000023#include <cctype>
24#include <cstring>
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000025
26using namespace llvm;
27
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000028void TargetAsmInfo::fillDefaultValues() {
29 BSSSection = "\t.bss";
30 BSSSection_ = 0;
31 ReadOnlySection = 0;
32 SmallDataSection = 0;
33 SmallBSSSection = 0;
34 SmallRODataSection = 0;
35 TLSDataSection = 0;
36 TLSBSSSection = 0;
37 ZeroFillDirective = 0;
38 NonexecutableStackDirective = 0;
39 NeedsSet = false;
40 MaxInstLength = 4;
41 PCSymbol = "$";
42 SeparatorChar = ';';
43 CommentString = "#";
44 GlobalPrefix = "";
45 PrivateGlobalPrefix = ".";
46 LessPrivateGlobalPrefix = "";
47 JumpTableSpecialLabelPrefix = 0;
48 GlobalVarAddrPrefix = "";
49 GlobalVarAddrSuffix = "";
50 FunctionAddrPrefix = "";
51 FunctionAddrSuffix = "";
52 PersonalityPrefix = "";
53 PersonalitySuffix = "";
54 NeedsIndirectEncoding = false;
55 InlineAsmStart = "#APP";
56 InlineAsmEnd = "#NO_APP";
57 AssemblerDialect = 0;
58 StringConstantPrefix = ".str";
59 ZeroDirective = "\t.zero\t";
60 ZeroDirectiveSuffix = 0;
61 AsciiDirective = "\t.ascii\t";
62 AscizDirective = "\t.asciz\t";
63 Data8bitsDirective = "\t.byte\t";
64 Data16bitsDirective = "\t.short\t";
65 Data32bitsDirective = "\t.long\t";
66 Data64bitsDirective = "\t.quad\t";
67 AlignDirective = "\t.align\t";
68 AlignmentIsInBytes = true;
69 TextAlignFillValue = 0;
70 SwitchToSectionDirective = "\t.section\t";
71 TextSectionStartSuffix = "";
72 DataSectionStartSuffix = "";
73 SectionEndDirectiveSuffix = 0;
74 ConstantPoolSection = "\t.section .rodata";
75 JumpTableDataSection = "\t.section .rodata";
76 JumpTableDirective = 0;
77 CStringSection = 0;
78 CStringSection_ = 0;
79 // FIXME: Flags are ELFish - replace with normal section stuff.
80 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
81 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
82 GlobalDirective = "\t.globl\t";
83 SetDirective = 0;
84 LCOMMDirective = 0;
85 COMMDirective = "\t.comm\t";
86 COMMDirectiveTakesAlignment = true;
87 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000088 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000089 UsedDirective = 0;
90 WeakRefDirective = 0;
91 WeakDefDirective = 0;
92 // FIXME: These are ELFish - move to ELFTAI.
93 HiddenDirective = "\t.hidden\t";
94 ProtectedDirective = "\t.protected\t";
95 AbsoluteDebugSectionOffsets = false;
96 AbsoluteEHSectionOffsets = false;
97 HasLEB128 = false;
98 HasDotLocAndDotFile = false;
99 SupportsDebugInformation = false;
100 SupportsExceptionHandling = false;
101 DwarfRequiresFrameSection = true;
Bill Wendlingd4121be2008-12-24 05:25:49 +0000102 FDEEncodingRequiresSData4 = true;
Bill Wendling722f5f12008-12-24 08:05:17 +0000103 NonLocalEHFrameLabel = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000104 GlobalEHDirective = 0;
105 SupportsWeakOmittedEHFrame = true;
106 DwarfSectionOffsetDirective = 0;
107 DwarfAbbrevSection = ".debug_abbrev";
108 DwarfInfoSection = ".debug_info";
109 DwarfLineSection = ".debug_line";
110 DwarfFrameSection = ".debug_frame";
111 DwarfPubNamesSection = ".debug_pubnames";
112 DwarfPubTypesSection = ".debug_pubtypes";
113 DwarfStrSection = ".debug_str";
114 DwarfLocSection = ".debug_loc";
115 DwarfARangesSection = ".debug_aranges";
116 DwarfRangesSection = ".debug_ranges";
117 DwarfMacInfoSection = ".debug_macinfo";
118 DwarfEHFrameSection = ".eh_frame";
119 DwarfExceptionSection = ".gcc_except_table";
120 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000121 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000122 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000123}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000124
Dan Gohman8f092252008-11-03 18:22:42 +0000125TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
126 : TM(tm) {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000127 fillDefaultValues();
128}
129
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000130TargetAsmInfo::~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
173SectionKind::Kind
174TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
175 // Early exit - functions should be always in text sections.
176 if (isa<Function>(GV))
177 return SectionKind::Text;
178
179 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
180 bool isThreadLocal = GVar->isThreadLocal();
181 assert(GVar && "Invalid global value for section selection");
182
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000183 if (isSuitableForBSS(GVar)) {
184 // Variable can be easily put to BSS section.
185 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
186 } else if (GVar->isConstant() && !isThreadLocal) {
187 // Now we know, that varible has initializer and it is constant. We need to
188 // check its initializer to decide, which section to output it into. Also
189 // note, there is no thread-local r/o section.
190 Constant *C = GVar->getInitializer();
191 if (C->ContainsRelocations())
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000192 return SectionKind::ROData;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000193 else {
194 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
195 // Check, if initializer is a null-terminated string
196 if (CVA && CVA->isCString())
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000197 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000198 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000199 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000200 }
201 }
202
203 // Variable is not constant or thread-local - emit to generic data section.
204 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
205}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000206
207unsigned
208TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000209 const char* Name) const {
210 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000211
212 // Decode flags from global itself.
213 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000214 SectionKind::Kind Kind = SectionKindForGlobal(GV);
215 switch (Kind) {
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000216 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000217 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000218 break;
219 case SectionKind::ThreadData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000220 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000221 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000222 // FALLS THROUGH
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000223 case SectionKind::Data:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000224 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000225 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000226 break;
227 case SectionKind::ROData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000228 case SectionKind::RODataMergeStr:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000229 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000230 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000231 break;
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000232 case SectionKind::SmallData:
233 case SectionKind::SmallBSS:
234 Flags |= SectionFlags::Writeable;
235 // FALLS THROUGH
236 case SectionKind::SmallROData:
237 Flags |= SectionFlags::Small;
238 break;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000239 default:
240 assert(0 && "Unexpected section kind!");
241 }
242
Duncan Sands5df31862008-09-29 11:25:42 +0000243 if (GV->mayBeOverridden())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000244 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000245 }
246
247 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000248 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000249 Flags |= SectionFlags::Named;
250
251 // Some lame default implementation based on some magic section names.
252 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000253 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
254 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
255 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000256 Flags |= SectionFlags::BSS;
257 else if (strcmp(Name, ".tdata") == 0 ||
258 strncmp(Name, ".tdata.", 7) == 0 ||
259 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
260 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
261 Flags |= SectionFlags::TLS;
262 else if (strcmp(Name, ".tbss") == 0 ||
263 strncmp(Name, ".tbss.", 6) == 0 ||
264 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
265 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
266 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000267 }
268
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000269 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000270}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000271
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000272const Section*
Evan Cheng42ccc212008-08-08 17:56:50 +0000273TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000274 const Section* S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000275 // Select section name
276 if (GV->hasSection()) {
277 // Honour section already set, if any
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000278 unsigned Flags = SectionFlagsForGlobal(GV,
279 GV->getSection().c_str());
280 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000281 } else {
282 // Use default section depending on the 'type' of global
Evan Cheng42ccc212008-08-08 17:56:50 +0000283 S = SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000284 }
285
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000286 return S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000287}
288
289// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000290const Section*
291TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000292 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000293
Duncan Sands5df31862008-09-29 11:25:42 +0000294 if (GV->mayBeOverridden()) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000295 std::string Name = UniqueSectionForGlobal(GV, Kind);
296 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
297 return getNamedSection(Name.c_str(), Flags);
298 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000299 if (Kind == SectionKind::Text)
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000300 return getTextSection();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000301 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000302 return getBSSSection_();
Anton Korobeynikov00181a32008-09-24 22:20:27 +0000303 else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
304 return getReadOnlySection();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000305 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000306
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000307 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000308}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000309
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000310// Lame default implementation. Calculate the section name for machine const.
311const Section*
312TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
313 // FIXME: Support data.rel stuff someday
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000314 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000315}
316
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000317std::string
318TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000319 SectionKind::Kind Kind) const {
320 switch (Kind) {
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000321 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000322 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000323 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000324 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000325 case SectionKind::SmallData:
326 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000327 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000328 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000329 case SectionKind::SmallBSS:
330 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000331 case SectionKind::ROData:
332 case SectionKind::RODataMergeConst:
333 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000334 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000335 case SectionKind::SmallROData:
336 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000337 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000338 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000339 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000340 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000341 default:
342 assert(0 && "Unknown section kind");
343 }
344}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000345
346const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000347TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
348 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000349 Section& S = Sections[Name];
350
351 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000352 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000353 S.Flags = Flags | SectionFlags::Named;
354 S.Name = Name;
355 }
356
357 return &S;
358}
359
360const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000361TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
362 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000363 Section& S = Sections[Directive];
364
365 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000366 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000367 S.Flags = Flags & ~SectionFlags::Named;
368 S.Name = Directive;
369 }
370
371 return &S;
372}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000373
374const std::string&
375TargetAsmInfo::getSectionFlags(unsigned Flags) const {
376 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
377
378 // We didn't print these flags yet, print and save them to map. This reduces
379 // amount of heap trashing due to std::string construction / concatenation.
380 if (I == FlagsStrings.end())
381 I = FlagsStrings.insert(std::make_pair(Flags,
382 printSectionFlags(Flags))).first;
383
384 return I->second;
385}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000386
387unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
388 unsigned Size = 0;
389 do {
390 Value >>= 7;
391 Size += sizeof(int8_t);
392 } while (Value);
393 return Size;
394}
395
396unsigned TargetAsmInfo::getSLEB128Size(int Value) {
397 unsigned Size = 0;
398 int Sign = Value >> (8 * sizeof(Value) - 1);
399 bool IsMore;
400
401 do {
402 unsigned Byte = Value & 0x7f;
403 Value >>= 7;
404 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
405 Size += sizeof(int8_t);
406 } while (IsMore);
407 return Size;
408}