blob: e963d7116ae8dfabc84b6eb212dee6178bcb8d9a [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),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000038 TLSDataSection("\t.section .tdata,\"awT\",@progbits"),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000039 TLSDataSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040 TLSBSSSection("\t.section .tbss,\"awT\",@nobits"),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000041 TLSBSSSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000042 ZeroFillDirective(0),
Dan Gohmana65530a2008-05-05 00:28:39 +000043 NonexecutableStackDirective(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000044 NeedsSet(false),
45 MaxInstLength(4),
46 PCSymbol("$"),
47 SeparatorChar(';'),
48 CommentString("#"),
49 GlobalPrefix(""),
50 PrivateGlobalPrefix("."),
Dale Johannesen2d34f9f2008-09-09 01:21:22 +000051 LessPrivateGlobalPrefix(""),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000052 JumpTableSpecialLabelPrefix(0),
53 GlobalVarAddrPrefix(""),
54 GlobalVarAddrSuffix(""),
55 FunctionAddrPrefix(""),
56 FunctionAddrSuffix(""),
Bill Wendlingd1bda4f2007-09-11 08:27:17 +000057 PersonalityPrefix(""),
58 PersonalitySuffix(""),
Bill Wendling2d369922007-09-11 17:20:55 +000059 NeedsIndirectEncoding(false),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000060 InlineAsmStart("#APP"),
61 InlineAsmEnd("#NO_APP"),
62 AssemblerDialect(0),
Dale Johannesen8f03a202008-06-03 18:09:06 +000063 StringConstantPrefix(".str"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +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),
Lauro Ramos Venancio9190bc42008-02-28 22:14:09 +000074 TextAlignFillValue(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000075 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),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000083 CStringSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000084 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
85 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
86 FourByteConstantSection(0),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000087 FourByteConstantSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000088 EightByteConstantSection(0),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000089 EightByteConstantSection_(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000090 SixteenByteConstantSection(0),
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +000091 SixteenByteConstantSection_(0),
Gordon Henriksene383f2a2007-12-23 20:58:16 +000092 GlobalDirective("\t.globl\t"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +000093 SetDirective(0),
94 LCOMMDirective(0),
95 COMMDirective("\t.comm\t"),
96 COMMDirectiveTakesAlignment(true),
97 HasDotTypeDotSizeDirective(true),
98 UsedDirective(0),
99 WeakRefDirective(0),
Dale Johannesenfb3ac732007-11-20 23:24:42 +0000100 WeakDefDirective(0),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000101 HiddenDirective("\t.hidden\t"),
102 ProtectedDirective("\t.protected\t"),
103 AbsoluteDebugSectionOffsets(false),
104 AbsoluteEHSectionOffsets(false),
105 HasLEB128(false),
Dan Gohman307ad202007-09-24 21:09:53 +0000106 HasDotLocAndDotFile(false),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000107 SupportsDebugInformation(false),
108 SupportsExceptionHandling(false),
109 DwarfRequiresFrameSection(true),
Dale Johannesen23b89a62007-11-21 00:45:00 +0000110 GlobalEHDirective(0),
Dale Johannesenf09b5992008-01-10 02:03:30 +0000111 SupportsWeakOmittedEHFrame(true),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112 DwarfSectionOffsetDirective(0),
113 DwarfAbbrevSection(".debug_abbrev"),
114 DwarfInfoSection(".debug_info"),
115 DwarfLineSection(".debug_line"),
116 DwarfFrameSection(".debug_frame"),
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000117 DwarfPubNamesSection(".debug_pubnames"),
118 DwarfPubTypesSection(".debug_pubtypes"),
119 DwarfStrSection(".debug_str"),
120 DwarfLocSection(".debug_loc"),
121 DwarfARangesSection(".debug_aranges"),
122 DwarfRangesSection(".debug_ranges"),
123 DwarfMacInfoSection(".debug_macinfo"),
124 DwarfEHFrameSection(".eh_frame"),
125 DwarfExceptionSection(".gcc_except_table"),
126 AsmTransCBE(0) {
Anton Korobeynikov55b94962008-09-24 22:15:21 +0000127 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikovcca60fa2008-09-24 22:16:16 +0000128 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000129}
130
131TargetAsmInfo::~TargetAsmInfo() {
132}
133
134/// Measure the specified inline asm to determine an approximation of its
135/// length.
136/// 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.
142unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
143 // Count the number of instructions in the asm.
144 bool atInsnStart = true;
145 unsigned Length = 0;
146 for (; *Str; ++Str) {
147 if (*Str == '\n' || *Str == SeparatorChar)
148 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;
155 }
156
157 return Length;
158}
159
Anton Korobeynikov8750d7c2008-02-29 22:09:08 +0000160unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikov65c0d872008-02-27 23:33:50 +0000161 bool Global) const {
162 return dwarf::DW_EH_PE_absptr;
163}
164
Anton Korobeynikovb4f658c2008-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
174SectionKind::Kind
175TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
176 // Early exit - functions should be always in text sections.
177 if (isa<Function>(GV))
178 return SectionKind::Text;
179
180 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
181 bool isThreadLocal = GVar->isThreadLocal();
182 assert(GVar && "Invalid global value for section selection");
183
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000184 if (isSuitableForBSS(GVar)) {
185 // Variable can be easily put to BSS section.
186 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
187 } else if (GVar->isConstant() && !isThreadLocal) {
188 // Now we know, that varible has initializer and it is constant. We need to
189 // check its initializer to decide, which section to output it into. Also
190 // note, there is no thread-local r/o section.
191 Constant *C = GVar->getInitializer();
192 if (C->ContainsRelocations())
Anton Korobeynikovb81503c2008-07-09 13:24:38 +0000193 return SectionKind::ROData;
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000194 else {
195 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
196 // Check, if initializer is a null-terminated string
197 if (CVA && CVA->isCString())
Anton Korobeynikovb81503c2008-07-09 13:24:38 +0000198 return SectionKind::RODataMergeStr;
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000199 else
Anton Korobeynikovb81503c2008-07-09 13:24:38 +0000200 return SectionKind::RODataMergeConst;
Anton Korobeynikovb4f658c2008-06-28 13:45:57 +0000201 }
202 }
203
204 // Variable is not constant or thread-local - emit to generic data section.
205 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
206}
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000207
208unsigned
209TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000210 const char* Name) const {
211 unsigned Flags = SectionFlags::None;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000212
213 // Decode flags from global itself.
214 if (GV) {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000215 SectionKind::Kind Kind = SectionKindForGlobal(GV);
216 switch (Kind) {
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000217 case SectionKind::Text:
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000218 Flags |= SectionFlags::Code;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000219 break;
220 case SectionKind::ThreadData:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000221 case SectionKind::ThreadBSS:
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000222 Flags |= SectionFlags::TLS;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000223 // FALLS THROUGH
Anton Korobeynikov16061032008-07-09 13:29:44 +0000224 case SectionKind::Data:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000225 case SectionKind::BSS:
Anton Korobeynikov16061032008-07-09 13:29:44 +0000226 Flags |= SectionFlags::Writeable;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000227 break;
228 case SectionKind::ROData:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000229 case SectionKind::RODataMergeStr:
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000230 case SectionKind::RODataMergeConst:
Anton Korobeynikov16061032008-07-09 13:29:44 +0000231 // No additional flags here
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000232 break;
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000233 case SectionKind::SmallData:
234 case SectionKind::SmallBSS:
235 Flags |= SectionFlags::Writeable;
236 // FALLS THROUGH
237 case SectionKind::SmallROData:
238 Flags |= SectionFlags::Small;
239 break;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000240 default:
241 assert(0 && "Unexpected section kind!");
242 }
243
Anton Korobeynikovf6816542008-07-09 13:27:59 +0000244 if (GV->isWeakForLinker())
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000245 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000246 }
247
248 // Add flags from sections, if any.
Anton Korobeynikovf7a82942008-07-09 13:25:46 +0000249 if (Name && *Name) {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000250 Flags |= SectionFlags::Named;
251
252 // Some lame default implementation based on some magic section names.
253 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000254 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
255 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
256 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000257 Flags |= SectionFlags::BSS;
258 else if (strcmp(Name, ".tdata") == 0 ||
259 strncmp(Name, ".tdata.", 7) == 0 ||
260 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
261 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
262 Flags |= SectionFlags::TLS;
263 else if (strcmp(Name, ".tbss") == 0 ||
264 strncmp(Name, ".tbss.", 6) == 0 ||
265 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
266 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
267 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000268 }
269
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000270 return Flags;
Anton Korobeynikovb3593bf2008-07-09 13:16:59 +0000271}
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000272
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000273const Section*
Evan Chengeb774e12008-08-08 17:56:50 +0000274TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000275 const Section* S;
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000276 // Select section name
277 if (GV->hasSection()) {
278 // Honour section already set, if any
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000279 unsigned Flags = SectionFlagsForGlobal(GV,
280 GV->getSection().c_str());
281 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000282 } else {
283 // Use default section depending on the 'type' of global
Evan Chengeb774e12008-08-08 17:56:50 +0000284 S = SelectSectionForGlobal(GV);
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000285 }
286
Anton Korobeynikov1a9edae2008-09-24 22:14:23 +0000287 return S;
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000288}
289
290// Lame default implementation. Calculate the section name for global.
Evan Chengeb774e12008-08-08 17:56:50 +0000291const Section*
292TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000293 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000294
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000295 if (GV->isWeakForLinker()) {
296 std::string Name = UniqueSectionForGlobal(GV, Kind);
297 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
298 return getNamedSection(Name.c_str(), Flags);
299 } else {
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000300 if (Kind == SectionKind::Text)
Anton Korobeynikov55b94962008-09-24 22:15:21 +0000301 return getTextSection();
Anton Korobeynikov80475a52008-08-07 09:51:54 +0000302 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000303 return getBSSSection_();
Anton Korobeynikov80475a52008-08-07 09:51:54 +0000304 else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind))
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000305 return getReadOnlySection_();
Anton Korobeynikov676a6252008-07-09 13:22:46 +0000306 }
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000307
Anton Korobeynikovcca60fa2008-09-24 22:16:16 +0000308 return getDataSection();
Anton Korobeynikov562c3f22008-07-09 13:18:02 +0000309}
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000310
Anton Korobeynikovfc54db12008-08-07 09:50:34 +0000311// Lame default implementation. Calculate the section name for machine const.
312const Section*
313TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
314 // FIXME: Support data.rel stuff someday
Anton Korobeynikovcca60fa2008-09-24 22:16:16 +0000315 return getDataSection();
Anton Korobeynikovfc54db12008-08-07 09:50:34 +0000316}
317
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000318std::string
319TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikov03db6772008-07-09 13:25:26 +0000320 SectionKind::Kind Kind) const {
321 switch (Kind) {
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000322 case SectionKind::Text:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000323 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000324 case SectionKind::Data:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000325 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000326 case SectionKind::SmallData:
327 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000328 case SectionKind::BSS:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000329 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000330 case SectionKind::SmallBSS:
331 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000332 case SectionKind::ROData:
333 case SectionKind::RODataMergeConst:
334 case SectionKind::RODataMergeStr:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000335 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikovd1f2de72008-07-22 17:09:59 +0000336 case SectionKind::SmallROData:
337 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000338 case SectionKind::ThreadData:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000339 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000340 case SectionKind::ThreadBSS:
Anton Korobeynikova3d07de2008-07-09 13:24:55 +0000341 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov3819e2d2008-07-09 13:19:38 +0000342 default:
343 assert(0 && "Unknown section kind");
344 }
345}
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000346
347const Section*
asla1c96962008-08-16 12:58:12 +0000348TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
349 bool Override) const {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000350 Section& S = Sections[Name];
351
352 // This is newly-created section, set it up properly.
asla1c96962008-08-16 12:58:12 +0000353 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000354 S.Flags = Flags | SectionFlags::Named;
355 S.Name = Name;
356 }
357
358 return &S;
359}
360
361const Section*
asla1c96962008-08-16 12:58:12 +0000362TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
363 bool Override) const {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000364 Section& S = Sections[Directive];
365
366 // This is newly-created section, set it up properly.
asla1c96962008-08-16 12:58:12 +0000367 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikovc33a1ff2008-07-09 13:28:49 +0000368 S.Flags = Flags & ~SectionFlags::Named;
369 S.Name = Directive;
370 }
371
372 return &S;
373}
asl27ffd262008-08-16 12:57:07 +0000374
375const std::string&
376TargetAsmInfo::getSectionFlags(unsigned Flags) const {
377 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
378
379 // We didn't print these flags yet, print and save them to map. This reduces
380 // amount of heap trashing due to std::string construction / concatenation.
381 if (I == FlagsStrings.end())
382 I = FlagsStrings.insert(std::make_pair(Flags,
383 printSectionFlags(Flags))).first;
384
385 return I->second;
386}
aslc200b112008-08-16 12:57:46 +0000387
388unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
389 unsigned Size = 0;
390 do {
391 Value >>= 7;
392 Size += sizeof(int8_t);
393 } while (Value);
394 return Size;
395}
396
397unsigned TargetAsmInfo::getSLEB128Size(int Value) {
398 unsigned Size = 0;
399 int Sign = Value >> (8 * sizeof(Value) - 1);
400 bool IsMore;
401
402 do {
403 unsigned Byte = Value & 0x7f;
404 Value >>= 7;
405 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
406 Size += sizeof(int8_t);
407 } while (IsMore);
408 return Size;
409}