blob: 0f770bd30002ebaa52be896f0cb3d42bf3923846 [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"
Anton Korobeynikov72bb4022009-01-27 22:29:24 +000016#include "llvm/DerivedTypes.h"
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000017#include "llvm/GlobalVariable.h"
18#include "llvm/Function.h"
19#include "llvm/Module.h"
20#include "llvm/Type.h"
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000021#include "llvm/Target/TargetAsmInfo.h"
Anton Korobeynikovdb232312009-03-29 17:13:49 +000022#include "llvm/Target/TargetMachine.h"
Anton Korobeynikov28a2b542008-06-28 13:45:57 +000023#include "llvm/Target/TargetOptions.h"
Anton Korobeynikovcee750f2008-02-27 23:33:50 +000024#include "llvm/Support/Dwarf.h"
Torok Edwinc25e7582009-07-11 20:10:48 +000025#include "llvm/Support/ErrorHandling.h"
Dale Johannesen3bb62832007-04-23 20:00:17 +000026#include <cctype>
27#include <cstring>
Jim Laskeyec0d9fe2006-09-06 18:35:33 +000028using namespace llvm;
29
Chris Lattner4e0f25b2009-06-19 00:08:39 +000030TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm)
Daniel Dunbar7384e1b2009-07-22 20:26:37 +000031 : TM(tm)
32{
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000033 BSSSection = "\t.bss";
34 BSSSection_ = 0;
35 ReadOnlySection = 0;
36 SmallDataSection = 0;
37 SmallBSSSection = 0;
38 SmallRODataSection = 0;
39 TLSDataSection = 0;
40 TLSBSSSection = 0;
41 ZeroFillDirective = 0;
42 NonexecutableStackDirective = 0;
43 NeedsSet = false;
44 MaxInstLength = 4;
45 PCSymbol = "$";
46 SeparatorChar = ';';
David Greene014700c2009-07-13 20:25:48 +000047 CommentColumn = 60;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000048 CommentString = "#";
David Greene76081c42009-07-20 22:02:59 +000049 FirstOperandColumn = 0;
50 MaxOperandLength = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000051 GlobalPrefix = "";
52 PrivateGlobalPrefix = ".";
Chris Lattner90f8b702009-07-21 17:30:51 +000053 LinkerPrivateGlobalPrefix = "";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000054 JumpTableSpecialLabelPrefix = 0;
55 GlobalVarAddrPrefix = "";
56 GlobalVarAddrSuffix = "";
57 FunctionAddrPrefix = "";
58 FunctionAddrSuffix = "";
59 PersonalityPrefix = "";
60 PersonalitySuffix = "";
61 NeedsIndirectEncoding = false;
62 InlineAsmStart = "#APP";
63 InlineAsmEnd = "#NO_APP";
64 AssemblerDialect = 0;
Chris Lattnera93ca922009-06-18 23:41:35 +000065 AllowQuotesInName = false;
Anton Korobeynikov32b952a2008-09-25 21:00: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;
76 TextAlignFillValue = 0;
77 SwitchToSectionDirective = "\t.section\t";
78 TextSectionStartSuffix = "";
79 DataSectionStartSuffix = "";
80 SectionEndDirectiveSuffix = 0;
81 ConstantPoolSection = "\t.section .rodata";
82 JumpTableDataSection = "\t.section .rodata";
83 JumpTableDirective = 0;
84 CStringSection = 0;
85 CStringSection_ = 0;
86 // FIXME: Flags are ELFish - replace with normal section stuff.
87 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
88 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
89 GlobalDirective = "\t.globl\t";
90 SetDirective = 0;
91 LCOMMDirective = 0;
92 COMMDirective = "\t.comm\t";
93 COMMDirectiveTakesAlignment = true;
94 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000095 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000096 UsedDirective = 0;
97 WeakRefDirective = 0;
98 WeakDefDirective = 0;
99 // FIXME: These are ELFish - move to ELFTAI.
100 HiddenDirective = "\t.hidden\t";
101 ProtectedDirective = "\t.protected\t";
102 AbsoluteDebugSectionOffsets = false;
103 AbsoluteEHSectionOffsets = false;
104 HasLEB128 = false;
105 HasDotLocAndDotFile = false;
106 SupportsDebugInformation = false;
107 SupportsExceptionHandling = false;
108 DwarfRequiresFrameSection = true;
Devang Patel0f7fef32009-04-13 17:02:03 +0000109 DwarfUsesInlineInfoSection = false;
Chris Lattnere2cf37b2009-07-17 20:46:40 +0000110 Is_EHSymbolPrivate = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000111 GlobalEHDirective = 0;
112 SupportsWeakOmittedEHFrame = true;
113 DwarfSectionOffsetDirective = 0;
114 DwarfAbbrevSection = ".debug_abbrev";
115 DwarfInfoSection = ".debug_info";
116 DwarfLineSection = ".debug_line";
117 DwarfFrameSection = ".debug_frame";
118 DwarfPubNamesSection = ".debug_pubnames";
119 DwarfPubTypesSection = ".debug_pubtypes";
Devang Patel0f7fef32009-04-13 17:02:03 +0000120 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000121 DwarfStrSection = ".debug_str";
122 DwarfLocSection = ".debug_loc";
123 DwarfARangesSection = ".debug_aranges";
124 DwarfRangesSection = ".debug_ranges";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000125 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000126 DwarfEHFrameSection = ".eh_frame";
127 DwarfExceptionSection = ".gcc_except_table";
128 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000129 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000130 DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable);
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
Owen Anderson1ca29d32009-07-13 21:27:19 +0000176static bool isConstantString(const Constant *C) {
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000177 // First check: is we have constant array of i8 terminated with zero
178 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
179 // Check, if initializer is a null-terminated string
Owen Anderson1ca29d32009-07-13 21:27:19 +0000180 if (CVA && CVA->isCString())
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000181 return true;
182
183 // Another possibility: [1 x i8] zeroinitializer
184 if (isa<ConstantAggregateZero>(C)) {
185 if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType())) {
186 return (Ty->getElementType() == Type::Int8Ty &&
187 Ty->getNumElements() == 1);
188 }
189 }
190
191 return false;
192}
193
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000194SectionKind::Kind
195TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
196 // Early exit - functions should be always in text sections.
197 if (isa<Function>(GV))
198 return SectionKind::Text;
199
200 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
201 bool isThreadLocal = GVar->isThreadLocal();
202 assert(GVar && "Invalid global value for section selection");
203
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000204 if (isSuitableForBSS(GVar)) {
205 // Variable can be easily put to BSS section.
Chris Lattner7cf12c72009-07-22 00:05:44 +0000206 return isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000207 } else if (GVar->isConstant() && !isThreadLocal) {
Chris Lattner97d2cae2009-07-21 23:47:11 +0000208 // Now we know, that variable has initializer and it is constant. We need to
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000209 // check its initializer to decide, which section to output it into. Also
210 // note, there is no thread-local r/o section.
211 Constant *C = GVar->getInitializer();
Chris Lattner7cf12c72009-07-22 00:05:44 +0000212 if (C->getRelocationInfo() != 0) {
Chris Lattnerb2fb9cc2009-07-21 23:49:55 +0000213 // Decide whether it is still possible to put symbol into r/o section.
214 if (TM.getRelocationModel() != Reloc::Static)
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000215 return SectionKind::Data;
Chris Lattnerb2fb9cc2009-07-21 23:49:55 +0000216 else
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000217 return SectionKind::ROData;
Anton Korobeynikovdb232312009-03-29 17:13:49 +0000218 } else {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000219 // Check, if initializer is a null-terminated string
Owen Anderson1ca29d32009-07-13 21:27:19 +0000220 if (isConstantString(C))
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000221 return SectionKind::RODataMergeStr;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000222 else
Anton Korobeynikov0e48a0c2008-07-09 13:24:38 +0000223 return SectionKind::RODataMergeConst;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000224 }
225 }
226
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000227 // Variable either is not constant or thread-local - output to data section.
Anton Korobeynikovfca82de2009-03-30 15:27:43 +0000228 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000229}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000230
231unsigned
232TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000233 const char* Name) const {
234 unsigned Flags = SectionFlags::None;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000235
236 // Decode flags from global itself.
237 if (GV) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000238 SectionKind::Kind Kind = SectionKindForGlobal(GV);
239 switch (Kind) {
Chris Lattner1010c212009-07-21 17:25:13 +0000240 case SectionKind::Text:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000241 Flags |= SectionFlags::Code;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000242 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000243 case SectionKind::ThreadData:
244 case SectionKind::ThreadBSS:
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000245 Flags |= SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000246 // FALLS THROUGH
Chris Lattner1010c212009-07-21 17:25:13 +0000247 case SectionKind::Data:
248 case SectionKind::DataRel:
249 case SectionKind::DataRelLocal:
250 case SectionKind::DataRelRO:
251 case SectionKind::DataRelROLocal:
252 case SectionKind::BSS:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000253 Flags |= SectionFlags::Writeable;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000254 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000255 case SectionKind::ROData:
256 case SectionKind::RODataMergeStr:
257 case SectionKind::RODataMergeConst:
Anton Korobeynikov7d51edf2008-07-09 13:29:44 +0000258 // No additional flags here
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000259 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000260 case SectionKind::SmallData:
261 case SectionKind::SmallBSS:
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000262 Flags |= SectionFlags::Writeable;
263 // FALLS THROUGH
Chris Lattner1010c212009-07-21 17:25:13 +0000264 case SectionKind::SmallROData:
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000265 Flags |= SectionFlags::Small;
266 break;
Chris Lattner1010c212009-07-21 17:25:13 +0000267 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000268 llvm_unreachable("Unexpected section kind!");
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000269 }
270
Duncan Sands667d4b82009-03-07 15:45:40 +0000271 if (GV->isWeakForLinker())
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000272 Flags |= SectionFlags::Linkonce;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000273 }
274
275 // Add flags from sections, if any.
Anton Korobeynikov2a889172008-07-09 13:25:46 +0000276 if (Name && *Name) {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000277 Flags |= SectionFlags::Named;
278
279 // Some lame default implementation based on some magic section names.
280 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000281 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
282 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
283 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000284 Flags |= SectionFlags::BSS;
285 else if (strcmp(Name, ".tdata") == 0 ||
286 strncmp(Name, ".tdata.", 7) == 0 ||
287 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
288 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
289 Flags |= SectionFlags::TLS;
290 else if (strcmp(Name, ".tbss") == 0 ||
291 strncmp(Name, ".tbss.", 6) == 0 ||
292 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
293 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
294 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000295 }
296
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000297 return Flags;
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000298}
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000299
Chris Lattner7558f112009-07-21 21:09:35 +0000300const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000301 // Select section name
302 if (GV->hasSection()) {
Chris Lattner7558f112009-07-21 21:09:35 +0000303 // Honour section already set, if any.
304 unsigned Flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
305 return getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000306 }
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000307
Chris Lattner7558f112009-07-21 21:09:35 +0000308 // Use default section depending on the 'type' of global
309 return SelectSectionForGlobal(GV);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000310}
311
312// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000313const Section*
314TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000315 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000316
Duncan Sands667d4b82009-03-07 15:45:40 +0000317 if (GV->isWeakForLinker()) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000318 std::string Name = UniqueSectionForGlobal(GV, Kind);
319 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
320 return getNamedSection(Name.c_str(), Flags);
321 } else {
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000322 if (Kind == SectionKind::Text)
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000323 return getTextSection();
Anton Korobeynikov45788622008-08-07 09:51:54 +0000324 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000325 return getBSSSection_();
Anton Korobeynikov00181a32008-09-24 22:20:27 +0000326 else if (getReadOnlySection() && SectionKind::isReadOnly(Kind))
327 return getReadOnlySection();
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000328 }
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000329
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000330 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000331}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000332
Chris Lattner298414e2009-07-22 00:28:43 +0000333/// getSectionForMergableConstant - Given a mergable constant with the
334/// specified size and relocation information, return a section that it
335/// should be placed in.
336const Section *
337TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
338 unsigned ReloInfo) const {
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000339 // FIXME: Support data.rel stuff someday
Chris Lattner298414e2009-07-22 00:28:43 +0000340 // Lame default implementation. Calculate the section name for machine const.
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000341 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000342}
343
Chris Lattner298414e2009-07-22 00:28:43 +0000344
345
346
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000347std::string
348TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikovb20015b2008-07-09 13:25:26 +0000349 SectionKind::Kind Kind) const {
350 switch (Kind) {
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000351 case SectionKind::Text:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000352 return ".gnu.linkonce.t." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000353 case SectionKind::Data:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000354 return ".gnu.linkonce.d." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000355 case SectionKind::DataRel:
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000356 return ".gnu.linkonce.d.rel" + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000357 case SectionKind::DataRelLocal:
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000358 return ".gnu.linkonce.d.rel.local" + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000359 case SectionKind::DataRelRO:
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000360 return ".gnu.linkonce.d.rel.ro" + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000361 case SectionKind::DataRelROLocal:
Anton Korobeynikov71a7c6c2009-03-30 15:27:03 +0000362 return ".gnu.linkonce.d.rel.ro.local" + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000363 case SectionKind::SmallData:
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000364 return ".gnu.linkonce.s." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000365 case SectionKind::BSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000366 return ".gnu.linkonce.b." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000367 case SectionKind::SmallBSS:
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000368 return ".gnu.linkonce.sb." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000369 case SectionKind::ROData:
370 case SectionKind::RODataMergeConst:
371 case SectionKind::RODataMergeStr:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000372 return ".gnu.linkonce.r." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000373 case SectionKind::SmallROData:
Anton Korobeynikov04dda732008-07-22 17:09:59 +0000374 return ".gnu.linkonce.s2." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000375 case SectionKind::ThreadData:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000376 return ".gnu.linkonce.td." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000377 case SectionKind::ThreadBSS:
Anton Korobeynikov52486702008-07-09 13:24:55 +0000378 return ".gnu.linkonce.tb." + GV->getName();
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000379 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000380 llvm_unreachable("Unknown section kind");
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000381 }
Devang Patel8a84e442009-01-05 17:31:22 +0000382 return NULL;
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000383}
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000384
Chris Lattner7558f112009-07-21 21:09:35 +0000385const Section *TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
386 bool Override) const {
387 Section &S = Sections[Name];
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000388
389 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000390 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000391 S.Flags = Flags | SectionFlags::Named;
392 S.Name = Name;
393 }
394
395 return &S;
396}
397
398const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000399TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
400 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000401 Section& S = Sections[Directive];
402
403 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000404 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000405 S.Flags = Flags & ~SectionFlags::Named;
406 S.Name = Directive;
407 }
408
409 return &S;
410}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000411
412const std::string&
413TargetAsmInfo::getSectionFlags(unsigned Flags) const {
414 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
415
416 // We didn't print these flags yet, print and save them to map. This reduces
417 // amount of heap trashing due to std::string construction / concatenation.
418 if (I == FlagsStrings.end())
419 I = FlagsStrings.insert(std::make_pair(Flags,
420 printSectionFlags(Flags))).first;
421
422 return I->second;
423}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000424
425unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
426 unsigned Size = 0;
427 do {
428 Value >>= 7;
429 Size += sizeof(int8_t);
430 } while (Value);
431 return Size;
432}
433
434unsigned TargetAsmInfo::getSLEB128Size(int Value) {
435 unsigned Size = 0;
436 int Sign = Value >> (8 * sizeof(Value) - 1);
437 bool IsMore;
438
439 do {
440 unsigned Byte = Value & 0x7f;
441 Value >>= 7;
442 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
443 Size += sizeof(int8_t);
444 } while (IsMore);
445 return Size;
446}