blob: ab4db2af3ee71b25d897f479815cf11e7b0b0d52 [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
28TargetAsmInfo::TargetAsmInfo() :
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +000029 TextSection(0),
Anton Korobeynikov315690e2008-09-24 22:16:16 +000030 DataSection(0),
Dan Gohman95701652007-05-03 18:46:30 +000031 BSSSection("\t.bss"),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000032 BSSSection_(0),
33 ReadOnlySection(0),
34 ReadOnlySection_(0),
Bruno Cardoso Lopes62d590c2008-07-22 15:26:53 +000035 SmallDataSection(0),
36 SmallBSSSection(0),
37 SmallRODataSection(0),
Anton Korobeynikov36133dd2008-09-24 22:17:06 +000038 TLSDataSection(0),
39 TLSBSSSection(0),
Chris Lattner6f198df2007-01-17 17:42:42 +000040 ZeroFillDirective(0),
Dan Gohmana779a982008-05-05 00:28:39 +000041 NonexecutableStackDirective(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000042 NeedsSet(false),
Chris Lattner4c7b07a2006-10-13 17:50:07 +000043 MaxInstLength(4),
Jim Laskeyb82313f2007-02-01 16:31:34 +000044 PCSymbol("$"),
Chris Lattner4c7b07a2006-10-13 17:50:07 +000045 SeparatorChar(';'),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000046 CommentString("#"),
47 GlobalPrefix(""),
48 PrivateGlobalPrefix("."),
Dale Johannesenb2dfb892008-09-09 01:21:22 +000049 LessPrivateGlobalPrefix(""),
Chris Lattner393a8ee2007-01-18 01:12:56 +000050 JumpTableSpecialLabelPrefix(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000051 GlobalVarAddrPrefix(""),
52 GlobalVarAddrSuffix(""),
53 FunctionAddrPrefix(""),
54 FunctionAddrSuffix(""),
Bill Wendlingd60da492007-09-11 08:27:17 +000055 PersonalityPrefix(""),
56 PersonalitySuffix(""),
Bill Wendlingef4a6612007-09-11 17:20:55 +000057 NeedsIndirectEncoding(false),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000058 InlineAsmStart("#APP"),
59 InlineAsmEnd("#NO_APP"),
Bill Wendlingeb9a42c2007-01-16 03:42:04 +000060 AssemblerDialect(0),
Dale Johannesen428ac542008-06-03 18:09:06 +000061 StringConstantPrefix(".str"),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +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 Venanciof3c630e2008-02-28 22:14:09 +000072 TextAlignFillValue(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000073 SwitchToSectionDirective("\t.section\t"),
74 TextSectionStartSuffix(""),
75 DataSectionStartSuffix(""),
76 SectionEndDirectiveSuffix(0),
Dan Gohmanaf67ea72007-06-14 15:00:27 +000077 ConstantPoolSection("\t.section .rodata"),
78 JumpTableDataSection("\t.section .rodata"),
Andrew Lenharthbeec30e2006-09-24 19:45:58 +000079 JumpTableDirective(0),
Reid Spencerc50209b2006-10-27 16:14:06 +000080 CStringSection(0),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000081 CStringSection_(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000082 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
83 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
Gordon Henriksen81361d62007-12-23 20:58:16 +000084 GlobalDirective("\t.globl\t"),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000085 SetDirective(0),
86 LCOMMDirective(0),
87 COMMDirective("\t.comm\t"),
88 COMMDirectiveTakesAlignment(true),
89 HasDotTypeDotSizeDirective(true),
Chris Lattnercb05af82006-09-26 03:38:18 +000090 UsedDirective(0),
Evan Cheng8752ce62006-12-01 20:47:11 +000091 WeakRefDirective(0),
Dale Johannesen1d4ce2a2007-11-20 23:24:42 +000092 WeakDefDirective(0),
Chris Lattner9784bc72007-01-14 06:27:21 +000093 HiddenDirective("\t.hidden\t"),
Anton Korobeynikov6f9896f2007-04-29 18:35:00 +000094 ProtectedDirective("\t.protected\t"),
Anton Korobeynikov79dda2b2007-05-01 22:23:12 +000095 AbsoluteDebugSectionOffsets(false),
96 AbsoluteEHSectionOffsets(false),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000097 HasLEB128(false),
Dan Gohman72252732007-09-24 21:09:53 +000098 HasDotLocAndDotFile(false),
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +000099 SupportsDebugInformation(false),
Jim Laskey072200c2007-01-29 18:51:14 +0000100 SupportsExceptionHandling(false),
Reid Spencer02b85112006-10-30 22:32:30 +0000101 DwarfRequiresFrameSection(true),
Dale Johannesen9305dcb2007-11-21 00:45:00 +0000102 GlobalEHDirective(0),
Dale Johannesen038129d2008-01-10 02:03:30 +0000103 SupportsWeakOmittedEHFrame(true),
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000104 DwarfSectionOffsetDirective(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +0000105 DwarfAbbrevSection(".debug_abbrev"),
106 DwarfInfoSection(".debug_info"),
107 DwarfLineSection(".debug_line"),
108 DwarfFrameSection(".debug_frame"),
109 DwarfPubNamesSection(".debug_pubnames"),
110 DwarfPubTypesSection(".debug_pubtypes"),
111 DwarfStrSection(".debug_str"),
112 DwarfLocSection(".debug_loc"),
113 DwarfARangesSection(".debug_aranges"),
114 DwarfRangesSection(".debug_ranges"),
Andrew Lenharth3655de62006-11-28 19:52:20 +0000115 DwarfMacInfoSection(".debug_macinfo"),
Jim Laskeyb82313f2007-02-01 16:31:34 +0000116 DwarfEHFrameSection(".eh_frame"),
Jim Laskeya15be8c2007-02-21 22:43:40 +0000117 DwarfExceptionSection(".gcc_except_table"),
Andrew Lenharth3655de62006-11-28 19:52:20 +0000118 AsmTransCBE(0) {
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000119 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000120 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000121}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000122
123TargetAsmInfo::~TargetAsmInfo() {
124}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000125
126/// Measure the specified inline asm to determine an approximation of its
127/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000128/// Comments (which run till the next SeparatorChar or newline) do not
129/// count as an instruction.
130/// Any other non-whitespace text is considered an instruction, with
131/// multiple instructions separated by SeparatorChar or newlines.
132/// Variable-length instructions are not handled here; this function
133/// may be overloaded in the target code to do that.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000134unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
135 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000136 bool atInsnStart = true;
137 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000138 for (; *Str; ++Str) {
139 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000140 atInsnStart = true;
141 if (atInsnStart && !isspace(*Str)) {
142 Length += MaxInstLength;
143 atInsnStart = false;
144 }
145 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
146 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000147 }
148
Dale Johannesen3bb62832007-04-23 20:00:17 +0000149 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000150}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000151
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000152unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000153 bool Global) const {
154 return dwarf::DW_EH_PE_absptr;
155}
156
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000157static bool isSuitableForBSS(const GlobalVariable *GV) {
158 if (!GV->hasInitializer())
159 return true;
160
161 // Leave constant zeros in readonly constant sections, so they can be shared
162 Constant *C = GV->getInitializer();
163 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
164}
165
166SectionKind::Kind
167TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
168 // Early exit - functions should be always in text sections.
169 if (isa<Function>(GV))
170 return SectionKind::Text;
171
172 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
173 bool isThreadLocal = GVar->isThreadLocal();
174 assert(GVar && "Invalid global value for section selection");
175
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000176 if (isSuitableForBSS(GVar)) {
177 // Variable can be easily put to BSS section.
178 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
179 } else if (GVar->isConstant() && !isThreadLocal) {
180 // Now we know, that varible has initializer and it is constant. We need to
181 // check its initializer to decide, which section to output it into. Also
182 // note, there is no thread-local r/o section.
183 Constant *C = GVar->getInitializer();
184 if (C->ContainsRelocations())
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000185 return SectionKind::ROData;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000186 else {
187 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
188 // Check, if initializer is a null-terminated string
189 if (CVA && CVA->isCString())
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000190 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000191 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000192 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000193 }
194 }
195
196 // Variable is not constant or thread-local - emit to generic data section.
197 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
198}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000199
200unsigned
201TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000202 const char* Name) const {
203 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000204
205 // Decode flags from global itself.
206 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000207 SectionKind::Kind Kind = SectionKindForGlobal(GV);
208 switch (Kind) {
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000209 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000210 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000211 break;
212 case SectionKind::ThreadData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000213 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000214 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000215 // FALLS THROUGH
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000216 case SectionKind::Data:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000217 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000218 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000219 break;
220 case SectionKind::ROData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000221 case SectionKind::RODataMergeStr:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000222 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000223 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000224 break;
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000225 case SectionKind::SmallData:
226 case SectionKind::SmallBSS:
227 Flags |= SectionFlags::Writeable;
228 // FALLS THROUGH
229 case SectionKind::SmallROData:
230 Flags |= SectionFlags::Small;
231 break;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000232 default:
233 assert(0 && "Unexpected section kind!");
234 }
235
Anton Korobeynikovc33a7442008-07-09 13:27:59 +0000236 if (GV->isWeakForLinker())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000237 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000238 }
239
240 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000241 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000242 Flags |= SectionFlags::Named;
243
244 // Some lame default implementation based on some magic section names.
245 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000246 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
247 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
248 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000249 Flags |= SectionFlags::BSS;
250 else if (strcmp(Name, ".tdata") == 0 ||
251 strncmp(Name, ".tdata.", 7) == 0 ||
252 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
253 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
254 Flags |= SectionFlags::TLS;
255 else if (strcmp(Name, ".tbss") == 0 ||
256 strncmp(Name, ".tbss.", 6) == 0 ||
257 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
258 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
259 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000260 }
261
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000262 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000263}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000264
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000265const Section*
Evan Cheng42ccc212008-08-08 17:56:50 +0000266TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000267 const Section* S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000268 // Select section name
269 if (GV->hasSection()) {
270 // Honour section already set, if any
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000271 unsigned Flags = SectionFlagsForGlobal(GV,
272 GV->getSection().c_str());
273 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000274 } else {
275 // Use default section depending on the 'type' of global
Evan Cheng42ccc212008-08-08 17:56:50 +0000276 S = SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000277 }
278
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000279 return S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000280}
281
282// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000283const Section*
284TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000285 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000286
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000287 if (GV->isWeakForLinker()) {
288 std::string Name = UniqueSectionForGlobal(GV, Kind);
289 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
290 return getNamedSection(Name.c_str(), Flags);
291 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000292 if (Kind == SectionKind::Text)
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000293 return getTextSection();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000294 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000295 return getBSSSection_();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000296 else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind))
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000297 return getReadOnlySection_();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000298 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000299
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000300 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000301}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000302
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000303// Lame default implementation. Calculate the section name for machine const.
304const Section*
305TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
306 // FIXME: Support data.rel stuff someday
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000307 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000308}
309
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000310std::string
311TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000312 SectionKind::Kind Kind) const {
313 switch (Kind) {
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000314 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000315 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000316 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000317 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000318 case SectionKind::SmallData:
319 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000320 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000321 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000322 case SectionKind::SmallBSS:
323 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000324 case SectionKind::ROData:
325 case SectionKind::RODataMergeConst:
326 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000327 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000328 case SectionKind::SmallROData:
329 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000330 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000331 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000332 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000333 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000334 default:
335 assert(0 && "Unknown section kind");
336 }
337}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000338
339const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000340TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
341 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000342 Section& S = Sections[Name];
343
344 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000345 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000346 S.Flags = Flags | SectionFlags::Named;
347 S.Name = Name;
348 }
349
350 return &S;
351}
352
353const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000354TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
355 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000356 Section& S = Sections[Directive];
357
358 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000359 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000360 S.Flags = Flags & ~SectionFlags::Named;
361 S.Name = Directive;
362 }
363
364 return &S;
365}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000366
367const std::string&
368TargetAsmInfo::getSectionFlags(unsigned Flags) const {
369 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
370
371 // We didn't print these flags yet, print and save them to map. This reduces
372 // amount of heap trashing due to std::string construction / concatenation.
373 if (I == FlagsStrings.end())
374 I = FlagsStrings.insert(std::make_pair(Flags,
375 printSectionFlags(Flags))).first;
376
377 return I->second;
378}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000379
380unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
381 unsigned Size = 0;
382 do {
383 Value >>= 7;
384 Size += sizeof(int8_t);
385 } while (Value);
386 return Size;
387}
388
389unsigned TargetAsmInfo::getSLEB128Size(int Value) {
390 unsigned Size = 0;
391 int Sign = Value >> (8 * sizeof(Value) - 1);
392 bool IsMore;
393
394 do {
395 unsigned Byte = Value & 0x7f;
396 Value >>= 7;
397 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
398 Size += sizeof(int8_t);
399 } while (IsMore);
400 return Size;
401}