blob: 536f16d6578a22d6e0d62ecca9bddba3c2366763 [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() :
Dan Gohman95701652007-05-03 18:46:30 +000029 TextSection("\t.text"),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000030 TextSection_(0),
Dan Gohman95701652007-05-03 18:46:30 +000031 DataSection("\t.data"),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000032 DataSection_(0),
Dan Gohman95701652007-05-03 18:46:30 +000033 BSSSection("\t.bss"),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000034 BSSSection_(0),
35 ReadOnlySection(0),
36 ReadOnlySection_(0),
Bruno Cardoso Lopes62d590c2008-07-22 15:26:53 +000037 SmallDataSection(0),
38 SmallBSSSection(0),
39 SmallRODataSection(0),
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +000040 TLSDataSection("\t.section .tdata,\"awT\",@progbits"),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000041 TLSDataSection_(0),
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +000042 TLSBSSSection("\t.section .tbss,\"awT\",@nobits"),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000043 TLSBSSSection_(0),
Chris Lattner6f198df2007-01-17 17:42:42 +000044 ZeroFillDirective(0),
Dan Gohmana779a982008-05-05 00:28:39 +000045 NonexecutableStackDirective(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000046 NeedsSet(false),
Chris Lattner4c7b07a2006-10-13 17:50:07 +000047 MaxInstLength(4),
Jim Laskeyb82313f2007-02-01 16:31:34 +000048 PCSymbol("$"),
Chris Lattner4c7b07a2006-10-13 17:50:07 +000049 SeparatorChar(';'),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000050 CommentString("#"),
51 GlobalPrefix(""),
52 PrivateGlobalPrefix("."),
Dale Johannesenb2dfb892008-09-09 01:21:22 +000053 LessPrivateGlobalPrefix(""),
Chris Lattner393a8ee2007-01-18 01:12:56 +000054 JumpTableSpecialLabelPrefix(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000055 GlobalVarAddrPrefix(""),
56 GlobalVarAddrSuffix(""),
57 FunctionAddrPrefix(""),
58 FunctionAddrSuffix(""),
Bill Wendlingd60da492007-09-11 08:27:17 +000059 PersonalityPrefix(""),
60 PersonalitySuffix(""),
Bill Wendlingef4a6612007-09-11 17:20:55 +000061 NeedsIndirectEncoding(false),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000062 InlineAsmStart("#APP"),
63 InlineAsmEnd("#NO_APP"),
Bill Wendlingeb9a42c2007-01-16 03:42:04 +000064 AssemblerDialect(0),
Dale Johannesen428ac542008-06-03 18:09:06 +000065 StringConstantPrefix(".str"),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000066 ZeroDirective("\t.zero\t"),
67 ZeroDirectiveSuffix(0),
68 AsciiDirective("\t.ascii\t"),
69 AscizDirective("\t.asciz\t"),
70 Data8bitsDirective("\t.byte\t"),
71 Data16bitsDirective("\t.short\t"),
72 Data32bitsDirective("\t.long\t"),
73 Data64bitsDirective("\t.quad\t"),
74 AlignDirective("\t.align\t"),
75 AlignmentIsInBytes(true),
Lauro Ramos Venanciof3c630e2008-02-28 22:14:09 +000076 TextAlignFillValue(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000077 SwitchToSectionDirective("\t.section\t"),
78 TextSectionStartSuffix(""),
79 DataSectionStartSuffix(""),
80 SectionEndDirectiveSuffix(0),
Dan Gohmanaf67ea72007-06-14 15:00:27 +000081 ConstantPoolSection("\t.section .rodata"),
82 JumpTableDataSection("\t.section .rodata"),
Andrew Lenharthbeec30e2006-09-24 19:45:58 +000083 JumpTableDirective(0),
Reid Spencerc50209b2006-10-27 16:14:06 +000084 CStringSection(0),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000085 CStringSection_(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000086 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
87 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
88 FourByteConstantSection(0),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000089 FourByteConstantSection_(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000090 EightByteConstantSection(0),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000091 EightByteConstantSection_(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000092 SixteenByteConstantSection(0),
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +000093 SixteenByteConstantSection_(0),
Gordon Henriksen81361d62007-12-23 20:58:16 +000094 GlobalDirective("\t.globl\t"),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000095 SetDirective(0),
96 LCOMMDirective(0),
97 COMMDirective("\t.comm\t"),
98 COMMDirectiveTakesAlignment(true),
99 HasDotTypeDotSizeDirective(true),
Chris Lattnercb05af82006-09-26 03:38:18 +0000100 UsedDirective(0),
Evan Cheng8752ce62006-12-01 20:47:11 +0000101 WeakRefDirective(0),
Dale Johannesen1d4ce2a2007-11-20 23:24:42 +0000102 WeakDefDirective(0),
Chris Lattner9784bc72007-01-14 06:27:21 +0000103 HiddenDirective("\t.hidden\t"),
Anton Korobeynikov6f9896f2007-04-29 18:35:00 +0000104 ProtectedDirective("\t.protected\t"),
Anton Korobeynikov79dda2b2007-05-01 22:23:12 +0000105 AbsoluteDebugSectionOffsets(false),
106 AbsoluteEHSectionOffsets(false),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +0000107 HasLEB128(false),
Dan Gohman72252732007-09-24 21:09:53 +0000108 HasDotLocAndDotFile(false),
Anton Korobeynikov2a07e2f2007-05-05 09:04:50 +0000109 SupportsDebugInformation(false),
Jim Laskey072200c2007-01-29 18:51:14 +0000110 SupportsExceptionHandling(false),
Reid Spencer02b85112006-10-30 22:32:30 +0000111 DwarfRequiresFrameSection(true),
Dale Johannesen9305dcb2007-11-21 00:45:00 +0000112 GlobalEHDirective(0),
Dale Johannesen038129d2008-01-10 02:03:30 +0000113 SupportsWeakOmittedEHFrame(true),
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000114 DwarfSectionOffsetDirective(0),
Jim Laskeyec0d9fe2006-09-06 18:35:33 +0000115 DwarfAbbrevSection(".debug_abbrev"),
116 DwarfInfoSection(".debug_info"),
117 DwarfLineSection(".debug_line"),
118 DwarfFrameSection(".debug_frame"),
119 DwarfPubNamesSection(".debug_pubnames"),
120 DwarfPubTypesSection(".debug_pubtypes"),
121 DwarfStrSection(".debug_str"),
122 DwarfLocSection(".debug_loc"),
123 DwarfARangesSection(".debug_aranges"),
124 DwarfRangesSection(".debug_ranges"),
Andrew Lenharth3655de62006-11-28 19:52:20 +0000125 DwarfMacInfoSection(".debug_macinfo"),
Jim Laskeyb82313f2007-02-01 16:31:34 +0000126 DwarfEHFrameSection(".eh_frame"),
Jim Laskeya15be8c2007-02-21 22:43:40 +0000127 DwarfExceptionSection(".gcc_except_table"),
Andrew Lenharth3655de62006-11-28 19:52:20 +0000128 AsmTransCBE(0) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000129 TextSection_ = getUnnamedSection(TextSection);
130 DataSection_ = getUnnamedSection(DataSection);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000131}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000132
133TargetAsmInfo::~TargetAsmInfo() {
134}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000135
136/// Measure the specified inline asm to determine an approximation of its
137/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000138/// Comments (which run till the next SeparatorChar or newline) do not
139/// count as an instruction.
140/// Any other non-whitespace text is considered an instruction, with
141/// multiple instructions separated by SeparatorChar or newlines.
142/// Variable-length instructions are not handled here; this function
143/// may be overloaded in the target code to do that.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000144unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
145 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000146 bool atInsnStart = true;
147 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000148 for (; *Str; ++Str) {
149 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000150 atInsnStart = true;
151 if (atInsnStart && !isspace(*Str)) {
152 Length += MaxInstLength;
153 atInsnStart = false;
154 }
155 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
156 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000157 }
158
Dale Johannesen3bb62832007-04-23 20:00:17 +0000159 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000160}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000161
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000162unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000163 bool Global) const {
164 return dwarf::DW_EH_PE_absptr;
165}
166
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000167static bool isSuitableForBSS(const GlobalVariable *GV) {
168 if (!GV->hasInitializer())
169 return true;
170
171 // Leave constant zeros in readonly constant sections, so they can be shared
172 Constant *C = GV->getInitializer();
173 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
174}
175
176SectionKind::Kind
177TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
178 // Early exit - functions should be always in text sections.
179 if (isa<Function>(GV))
180 return SectionKind::Text;
181
182 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
183 bool isThreadLocal = GVar->isThreadLocal();
184 assert(GVar && "Invalid global value for section selection");
185
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000186 if (isSuitableForBSS(GVar)) {
187 // Variable can be easily put to BSS section.
188 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
189 } else if (GVar->isConstant() && !isThreadLocal) {
190 // Now we know, that varible has initializer and it is constant. We need to
191 // check its initializer to decide, which section to output it into. Also
192 // note, there is no thread-local r/o section.
193 Constant *C = GVar->getInitializer();
194 if (C->ContainsRelocations())
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000195 return SectionKind::ROData;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000196 else {
197 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
198 // Check, if initializer is a null-terminated string
199 if (CVA && CVA->isCString())
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000200 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000201 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000202 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000203 }
204 }
205
206 // Variable is not constant or thread-local - emit to generic data section.
207 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
208}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000209
210unsigned
211TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000212 const char* Name) const {
213 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000214
215 // Decode flags from global itself.
216 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000217 SectionKind::Kind Kind = SectionKindForGlobal(GV);
218 switch (Kind) {
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000219 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000220 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000221 break;
222 case SectionKind::ThreadData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000223 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000224 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000225 // FALLS THROUGH
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000226 case SectionKind::Data:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000227 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000228 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000229 break;
230 case SectionKind::ROData:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000231 case SectionKind::RODataMergeStr:
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000232 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000233 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000234 break;
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000235 case SectionKind::SmallData:
236 case SectionKind::SmallBSS:
237 Flags |= SectionFlags::Writeable;
238 // FALLS THROUGH
239 case SectionKind::SmallROData:
240 Flags |= SectionFlags::Small;
241 break;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000242 default:
243 assert(0 && "Unexpected section kind!");
244 }
245
Anton Korobeynikovc33a7442008-07-09 13:27:59 +0000246 if (GV->isWeakForLinker())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000247 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000248 }
249
250 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000251 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000252 Flags |= SectionFlags::Named;
253
254 // Some lame default implementation based on some magic section names.
255 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000256 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
257 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
258 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000259 Flags |= SectionFlags::BSS;
260 else if (strcmp(Name, ".tdata") == 0 ||
261 strncmp(Name, ".tdata.", 7) == 0 ||
262 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
263 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
264 Flags |= SectionFlags::TLS;
265 else if (strcmp(Name, ".tbss") == 0 ||
266 strncmp(Name, ".tbss.", 6) == 0 ||
267 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
268 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
269 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000270 }
271
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000272 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000273}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000274
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000275const Section*
Evan Cheng42ccc212008-08-08 17:56:50 +0000276TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000277 const Section* S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000278 // Select section name
279 if (GV->hasSection()) {
280 // Honour section already set, if any
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000281 unsigned Flags = SectionFlagsForGlobal(GV,
282 GV->getSection().c_str());
283 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000284 } else {
285 // Use default section depending on the 'type' of global
Evan Cheng42ccc212008-08-08 17:56:50 +0000286 S = SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000287 }
288
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000289 return S;
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000290}
291
292// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000293const Section*
294TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000295 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000296
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000297 if (GV->isWeakForLinker()) {
298 std::string Name = UniqueSectionForGlobal(GV, Kind);
299 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
300 return getNamedSection(Name.c_str(), Flags);
301 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000302 if (Kind == SectionKind::Text)
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000303 return getTextSection_();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000304 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000305 return getBSSSection_();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000306 else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind))
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000307 return getReadOnlySection_();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000308 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000309
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000310 return getDataSection_();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000311}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000312
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000313// Lame default implementation. Calculate the section name for machine const.
314const Section*
315TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
316 // FIXME: Support data.rel stuff someday
317 return getDataSection_();
318}
319
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000320std::string
321TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000322 SectionKind::Kind Kind) const {
323 switch (Kind) {
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000324 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000325 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000326 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000327 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000328 case SectionKind::SmallData:
329 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000330 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000331 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000332 case SectionKind::SmallBSS:
333 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000334 case SectionKind::ROData:
335 case SectionKind::RODataMergeConst:
336 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000337 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000338 case SectionKind::SmallROData:
339 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000340 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000341 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000342 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000343 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000344 default:
345 assert(0 && "Unknown section kind");
346 }
347}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000348
349const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000350TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
351 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000352 Section& S = Sections[Name];
353
354 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000355 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000356 S.Flags = Flags | SectionFlags::Named;
357 S.Name = Name;
358 }
359
360 return &S;
361}
362
363const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000364TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
365 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000366 Section& S = Sections[Directive];
367
368 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000369 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000370 S.Flags = Flags & ~SectionFlags::Named;
371 S.Name = Directive;
372 }
373
374 return &S;
375}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000376
377const std::string&
378TargetAsmInfo::getSectionFlags(unsigned Flags) const {
379 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
380
381 // We didn't print these flags yet, print and save them to map. This reduces
382 // amount of heap trashing due to std::string construction / concatenation.
383 if (I == FlagsStrings.end())
384 I = FlagsStrings.insert(std::make_pair(Flags,
385 printSectionFlags(Flags))).first;
386
387 return I->second;
388}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000389
390unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
391 unsigned Size = 0;
392 do {
393 Value >>= 7;
394 Size += sizeof(int8_t);
395 } while (Value);
396 return Size;
397}
398
399unsigned TargetAsmInfo::getSLEB128Size(int Value) {
400 unsigned Size = 0;
401 int Sign = Value >> (8 * sizeof(Value) - 1);
402 bool IsMore;
403
404 do {
405 unsigned Byte = Value & 0x7f;
406 Value >>= 7;
407 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
408 Size += sizeof(int8_t);
409 } while (IsMore);
410 return Size;
411}