blob: 51042dac9588a4214537f7a7ea4ec63a15833150 [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 Lattner0d4960c32009-07-24 20:14:10 +000030TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) : TM(tm) {
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000031 BSSSection = "\t.bss";
32 BSSSection_ = 0;
33 ReadOnlySection = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000034 TLSDataSection = 0;
35 TLSBSSSection = 0;
36 ZeroFillDirective = 0;
37 NonexecutableStackDirective = 0;
38 NeedsSet = false;
39 MaxInstLength = 4;
40 PCSymbol = "$";
41 SeparatorChar = ';';
David Greene014700c2009-07-13 20:25:48 +000042 CommentColumn = 60;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000043 CommentString = "#";
David Greene76081c42009-07-20 22:02:59 +000044 FirstOperandColumn = 0;
45 MaxOperandLength = 0;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000046 GlobalPrefix = "";
47 PrivateGlobalPrefix = ".";
Chris Lattner90f8b702009-07-21 17:30:51 +000048 LinkerPrivateGlobalPrefix = "";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000049 JumpTableSpecialLabelPrefix = 0;
50 GlobalVarAddrPrefix = "";
51 GlobalVarAddrSuffix = "";
52 FunctionAddrPrefix = "";
53 FunctionAddrSuffix = "";
54 PersonalityPrefix = "";
55 PersonalitySuffix = "";
56 NeedsIndirectEncoding = false;
57 InlineAsmStart = "#APP";
58 InlineAsmEnd = "#NO_APP";
59 AssemblerDialect = 0;
Chris Lattnera93ca922009-06-18 23:41:35 +000060 AllowQuotesInName = false;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000061 ZeroDirective = "\t.zero\t";
62 ZeroDirectiveSuffix = 0;
63 AsciiDirective = "\t.ascii\t";
64 AscizDirective = "\t.asciz\t";
65 Data8bitsDirective = "\t.byte\t";
66 Data16bitsDirective = "\t.short\t";
67 Data32bitsDirective = "\t.long\t";
68 Data64bitsDirective = "\t.quad\t";
69 AlignDirective = "\t.align\t";
70 AlignmentIsInBytes = true;
71 TextAlignFillValue = 0;
72 SwitchToSectionDirective = "\t.section\t";
73 TextSectionStartSuffix = "";
74 DataSectionStartSuffix = "";
75 SectionEndDirectiveSuffix = 0;
76 ConstantPoolSection = "\t.section .rodata";
77 JumpTableDataSection = "\t.section .rodata";
78 JumpTableDirective = 0;
79 CStringSection = 0;
80 CStringSection_ = 0;
81 // FIXME: Flags are ELFish - replace with normal section stuff.
82 StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits";
83 StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits";
84 GlobalDirective = "\t.globl\t";
85 SetDirective = 0;
86 LCOMMDirective = 0;
87 COMMDirective = "\t.comm\t";
88 COMMDirectiveTakesAlignment = true;
89 HasDotTypeDotSizeDirective = true;
Rafael Espindola952b8392008-12-03 11:01:37 +000090 HasSingleParameterDotFile = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +000091 UsedDirective = 0;
92 WeakRefDirective = 0;
93 WeakDefDirective = 0;
94 // FIXME: These are ELFish - move to ELFTAI.
95 HiddenDirective = "\t.hidden\t";
96 ProtectedDirective = "\t.protected\t";
97 AbsoluteDebugSectionOffsets = false;
98 AbsoluteEHSectionOffsets = false;
99 HasLEB128 = false;
100 HasDotLocAndDotFile = false;
101 SupportsDebugInformation = false;
102 SupportsExceptionHandling = false;
103 DwarfRequiresFrameSection = true;
Devang Patel0f7fef32009-04-13 17:02:03 +0000104 DwarfUsesInlineInfoSection = false;
Chris Lattnere2cf37b2009-07-17 20:46:40 +0000105 Is_EHSymbolPrivate = true;
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000106 GlobalEHDirective = 0;
107 SupportsWeakOmittedEHFrame = true;
108 DwarfSectionOffsetDirective = 0;
109 DwarfAbbrevSection = ".debug_abbrev";
110 DwarfInfoSection = ".debug_info";
111 DwarfLineSection = ".debug_line";
112 DwarfFrameSection = ".debug_frame";
113 DwarfPubNamesSection = ".debug_pubnames";
114 DwarfPubTypesSection = ".debug_pubtypes";
Devang Patel0f7fef32009-04-13 17:02:03 +0000115 DwarfDebugInlineSection = ".debug_inlined";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000116 DwarfStrSection = ".debug_str";
117 DwarfLocSection = ".debug_loc";
118 DwarfARangesSection = ".debug_aranges";
119 DwarfRangesSection = ".debug_ranges";
Chris Lattnerb839c3f2009-06-18 23:31:37 +0000120 DwarfMacroInfoSection = ".debug_macinfo";
Anton Korobeynikov32b952a2008-09-25 21:00:33 +0000121 DwarfEHFrameSection = ".eh_frame";
122 DwarfExceptionSection = ".gcc_except_table";
123 AsmTransCBE = 0;
Anton Korobeynikovd7ca4162008-09-24 22:15:21 +0000124 TextSection = getUnnamedSection("\t.text", SectionFlags::Code);
Chris Lattnerb4fc4192009-07-25 18:57:34 +0000125 DataSection = getUnnamedSection("\t.data", SectionFlags::Writable);
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000126}
Chris Lattnerf5b10ec2006-10-05 00:35:16 +0000127
128TargetAsmInfo::~TargetAsmInfo() {
129}
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000130
131/// Measure the specified inline asm to determine an approximation of its
132/// length.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000133/// Comments (which run till the next SeparatorChar or newline) do not
134/// count as an instruction.
135/// Any other non-whitespace text is considered an instruction, with
136/// multiple instructions separated by SeparatorChar or newlines.
137/// Variable-length instructions are not handled here; this function
138/// may be overloaded in the target code to do that.
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000139unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
140 // Count the number of instructions in the asm.
Dale Johannesen3bb62832007-04-23 20:00:17 +0000141 bool atInsnStart = true;
142 unsigned Length = 0;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000143 for (; *Str; ++Str) {
144 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen3bb62832007-04-23 20:00:17 +0000145 atInsnStart = true;
146 if (atInsnStart && !isspace(*Str)) {
147 Length += MaxInstLength;
148 atInsnStart = false;
149 }
150 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
151 atInsnStart = false;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000152 }
153
Dale Johannesen3bb62832007-04-23 20:00:17 +0000154 return Length;
Chris Lattner4c7b07a2006-10-13 17:50:07 +0000155}
Anton Korobeynikova6199c82007-03-07 02:47:57 +0000156
Anton Korobeynikov8213f9c2008-02-29 22:09:08 +0000157unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovcee750f2008-02-27 23:33:50 +0000158 bool Global) const {
159 return dwarf::DW_EH_PE_absptr;
160}
161
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000162static bool isSuitableForBSS(const GlobalVariable *GV) {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000163 Constant *C = GV->getInitializer();
Chris Lattnerb4fc4192009-07-25 18:57:34 +0000164
165 // Must have zero initializer.
166 if (!C->isNullValue())
167 return false;
168
169 // Leave constant zeros in readonly constant sections, so they can be shared.
170 if (GV->isConstant())
171 return false;
172
173 // If the global has an explicit section specified, don't put it in BSS.
174 if (!GV->getSection().empty())
175 return false;
176
Chris Lattner460d51e2009-07-25 23:21:55 +0000177 // If -nozero-initialized-in-bss is specified, don't ever use BSS.
178 if (NoZerosInBSS)
179 return false;
180
181 // Otherwise, put it in BSS!
182 return true;
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000183}
184
Owen Anderson1ca29d32009-07-13 21:27:19 +0000185static bool isConstantString(const Constant *C) {
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000186 // First check: is we have constant array of i8 terminated with zero
187 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
188 // Check, if initializer is a null-terminated string
Owen Anderson1ca29d32009-07-13 21:27:19 +0000189 if (CVA && CVA->isCString())
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000190 return true;
191
192 // Another possibility: [1 x i8] zeroinitializer
Chris Lattner0d4960c32009-07-24 20:14:10 +0000193 if (isa<ConstantAggregateZero>(C))
194 if (const ArrayType *Ty = dyn_cast<ArrayType>(C->getType()))
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000195 return (Ty->getElementType() == Type::Int8Ty &&
196 Ty->getNumElements() == 1);
Anton Korobeynikov72bb4022009-01-27 22:29:24 +0000197
198 return false;
199}
200
Chris Lattner8adc5472009-07-24 16:46:50 +0000201static unsigned SectionFlagsForGlobal(const GlobalValue *GV,
Chris Lattner460d51e2009-07-25 23:21:55 +0000202 SectionKind Kind) {
Chris Lattnerb4fc4192009-07-25 18:57:34 +0000203 // Decode flags from global and section kind.
Chris Lattner104bbd12009-07-24 16:44:01 +0000204 unsigned Flags = SectionFlags::None;
Chris Lattner104bbd12009-07-24 16:44:01 +0000205 if (GV->isWeakForLinker())
206 Flags |= SectionFlags::Linkonce;
Chris Lattnere346e182009-07-26 05:44:20 +0000207 if (Kind.isBSS() || Kind.isThreadBSS())
Chris Lattnerb4fc4192009-07-25 18:57:34 +0000208 Flags |= SectionFlags::BSS;
Chris Lattnere346e182009-07-26 05:44:20 +0000209 if (Kind.isThreadLocal())
Chris Lattnerb4fc4192009-07-25 18:57:34 +0000210 Flags |= SectionFlags::TLS;
Chris Lattnere346e182009-07-26 05:44:20 +0000211 if (Kind.isText())
Chris Lattnerb4fc4192009-07-25 18:57:34 +0000212 Flags |= SectionFlags::Code;
Chris Lattner460d51e2009-07-25 23:21:55 +0000213 if (Kind.isWritable())
Chris Lattnerb4fc4192009-07-25 18:57:34 +0000214 Flags |= SectionFlags::Writable;
Chris Lattner104bbd12009-07-24 16:44:01 +0000215
Chris Lattner27f30652009-07-24 16:50:24 +0000216 return Flags;
217}
Chris Lattner104bbd12009-07-24 16:44:01 +0000218
Chris Lattner460d51e2009-07-25 23:21:55 +0000219static SectionKind SectionKindForGlobal(const GlobalValue *GV,
220 Reloc::Model ReloModel) {
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000221 // Early exit - functions should be always in text sections.
Chris Lattnere5ca0ac2009-07-24 16:53:52 +0000222 const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
223 if (GVar == 0)
Chris Lattner460d51e2009-07-25 23:21:55 +0000224 return SectionKind::getText();
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000225
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000226 bool isThreadLocal = GVar->isThreadLocal();
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000227
Chris Lattnerb3035042009-07-24 19:15:47 +0000228 // Variable can be easily put to BSS section.
229 if (isSuitableForBSS(GVar))
Chris Lattner460d51e2009-07-25 23:21:55 +0000230 return isThreadLocal ? SectionKind::getThreadBSS() : SectionKind::getBSS();
Chris Lattnerb3035042009-07-24 19:15:47 +0000231
232 // If this is thread-local, put it in the general "thread_data" section.
233 if (isThreadLocal)
Chris Lattner460d51e2009-07-25 23:21:55 +0000234 return SectionKind::getThreadData();
Chris Lattnerb3035042009-07-24 19:15:47 +0000235
236 Constant *C = GVar->getInitializer();
237
238 // If the global is marked constant, we can put it into a mergable section,
239 // a mergable string section, or general .data if it contains relocations.
240 if (GVar->isConstant()) {
241 // If the initializer for the global contains something that requires a
242 // relocation, then we may have to drop this into a wriable data section
243 // even though it is marked const.
244 switch (C->getRelocationInfo()) {
245 default: llvm_unreachable("unknown relocation info kind");
246 case Constant::NoRelocation:
247 // If initializer is a null-terminated string, put it in a "cstring"
248 // section if the target has it.
Owen Anderson1ca29d32009-07-13 21:27:19 +0000249 if (isConstantString(C))
Chris Lattnere346e182009-07-26 05:44:20 +0000250 return SectionKind::getMergableCString();
Chris Lattnerb3035042009-07-24 19:15:47 +0000251
252 // Otherwise, just drop it into a mergable constant section.
Chris Lattnere346e182009-07-26 05:44:20 +0000253 return SectionKind::getMergableConst();
Chris Lattnerb3035042009-07-24 19:15:47 +0000254
255 case Constant::LocalRelocation:
256 // In static relocation model, the linker will resolve all addresses, so
257 // the relocation entries will actually be constants by the time the app
258 // starts up.
Chris Lattner0d4960c32009-07-24 20:14:10 +0000259 if (ReloModel == Reloc::Static)
Chris Lattnere346e182009-07-26 05:44:20 +0000260 return SectionKind::getReadOnly();
Chris Lattnerb3035042009-07-24 19:15:47 +0000261
262 // Otherwise, the dynamic linker needs to fix it up, put it in the
263 // writable data.rel.local section.
Chris Lattnere346e182009-07-26 05:44:20 +0000264 return SectionKind::getReadOnlyWithRelLocal();
Chris Lattnerb3035042009-07-24 19:15:47 +0000265
266 case Constant::GlobalRelocations:
267 // In static relocation model, the linker will resolve all addresses, so
268 // the relocation entries will actually be constants by the time the app
269 // starts up.
Chris Lattner0d4960c32009-07-24 20:14:10 +0000270 if (ReloModel == Reloc::Static)
Chris Lattnere346e182009-07-26 05:44:20 +0000271 return SectionKind::getReadOnly();
Chris Lattnerb3035042009-07-24 19:15:47 +0000272
273 // Otherwise, the dynamic linker needs to fix it up, put it in the
274 // writable data.rel section.
Chris Lattnere346e182009-07-26 05:44:20 +0000275 return SectionKind::getReadOnlyWithRel();
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000276 }
277 }
278
Chris Lattnerb3035042009-07-24 19:15:47 +0000279 // Okay, this isn't a constant. If the initializer for the global is going
280 // to require a runtime relocation by the dynamic linker, put it into a more
281 // specific section to improve startup time of the app. This coalesces these
282 // globals together onto fewer pages, improving the locality of the dynamic
283 // linker.
Chris Lattner0d4960c32009-07-24 20:14:10 +0000284 if (ReloModel == Reloc::Static)
Chris Lattnere346e182009-07-26 05:44:20 +0000285 return SectionKind::getDataNoRel();
Chris Lattnerb3035042009-07-24 19:15:47 +0000286
287 switch (C->getRelocationInfo()) {
288 default: llvm_unreachable("unknown relocation info kind");
Chris Lattnere346e182009-07-26 05:44:20 +0000289 case Constant::NoRelocation: return SectionKind::getDataNoRel();
Chris Lattner460d51e2009-07-25 23:21:55 +0000290 case Constant::LocalRelocation: return SectionKind::getDataRelLocal();
291 case Constant::GlobalRelocations: return SectionKind::getDataRel();
Chris Lattnerb3035042009-07-24 19:15:47 +0000292 }
Anton Korobeynikov28a2b542008-06-28 13:45:57 +0000293}
Anton Korobeynikovbeb9d402008-07-09 13:16:59 +0000294
Chris Lattner4f055912009-07-25 18:11:58 +0000295/// SectionForGlobal - This method computes the appropriate section to emit
296/// the specified global variable or function definition. This should not
297/// be passed external (or available externally) globals.
Chris Lattner7558f112009-07-21 21:09:35 +0000298const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Chris Lattner4f055912009-07-25 18:11:58 +0000299 assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
300 "Can only be used for global definitions");
301
Chris Lattner460d51e2009-07-25 23:21:55 +0000302 SectionKind Kind = SectionKindForGlobal(GV, TM.getRelocationModel());
Chris Lattner7420ab22009-07-24 18:34:27 +0000303
304 // Select section name.
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000305 if (GV->hasSection()) {
Chris Lattner7420ab22009-07-24 18:34:27 +0000306 // If the target has special section hacks for specifically named globals,
307 // return them now.
308 if (const Section *TS = getSpecialCasedSectionGlobals(GV, Kind))
309 return TS;
310
Chris Lattner7558f112009-07-21 21:09:35 +0000311 // Honour section already set, if any.
Chris Lattner7420ab22009-07-24 18:34:27 +0000312 unsigned Flags = SectionFlagsForGlobal(GV, Kind);
Chris Lattner27f30652009-07-24 16:50:24 +0000313
314 // This is an explicitly named section.
315 Flags |= SectionFlags::Named;
316
317 // If the target has magic semantics for certain section names, make sure to
318 // pick up the flags. This allows the user to write things with attribute
319 // section and still get the appropriate section flags printed.
Chris Lattner2dcafe42009-07-24 17:02:17 +0000320 Flags |= getFlagsForNamedSection(GV->getSection().c_str());
Chris Lattner27f30652009-07-24 16:50:24 +0000321
Chris Lattner7558f112009-07-21 21:09:35 +0000322 return getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000323 }
Daniel Dunbar7384e1b2009-07-22 20:26:37 +0000324
Chris Lattnereed05b82009-07-24 05:10:25 +0000325 // If this global is linkonce/weak and the target handles this by emitting it
326 // into a 'uniqued' section name, create and return the section now.
327 if (GV->isWeakForLinker()) {
Chris Lattner7420ab22009-07-24 18:34:27 +0000328 if (const char *Prefix = getSectionPrefixForUniqueGlobal(Kind)) {
329 unsigned Flags = SectionFlagsForGlobal(GV, Kind);
Chris Lattnere5ca0ac2009-07-24 16:53:52 +0000330
Chris Lattnereed05b82009-07-24 05:10:25 +0000331 // FIXME: Use mangler interface (PR4584).
Daniel Dunbar895c9ed2009-07-24 12:21:08 +0000332 std::string Name = Prefix+GV->getNameStr();
Chris Lattnereed05b82009-07-24 05:10:25 +0000333 return getNamedSection(Name.c_str(), Flags);
334 }
335 }
336
Chris Lattner7558f112009-07-21 21:09:35 +0000337 // Use default section depending on the 'type' of global
Chris Lattnerf20f2502009-07-24 18:42:53 +0000338 return SelectSectionForGlobal(GV, Kind);
Anton Korobeynikov265c5252008-07-09 13:22:46 +0000339}
340
341// Lame default implementation. Calculate the section name for global.
Evan Cheng42ccc212008-08-08 17:56:50 +0000342const Section*
Chris Lattnerf20f2502009-07-24 18:42:53 +0000343TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
Chris Lattner460d51e2009-07-25 23:21:55 +0000344 SectionKind Kind) const {
Chris Lattnere346e182009-07-26 05:44:20 +0000345 assert(!Kind.isThreadLocal() && "Doesn't support TLS");
346
347 if (Kind.isText())
Chris Lattnereed05b82009-07-24 05:10:25 +0000348 return getTextSection();
349
Chris Lattner460d51e2009-07-25 23:21:55 +0000350 if (Kind.isBSS())
Chris Lattnereed05b82009-07-24 05:10:25 +0000351 if (const Section *S = getBSSSection_())
352 return S;
353
Chris Lattner460d51e2009-07-25 23:21:55 +0000354 if (Kind.isReadOnly())
Chris Lattnereed05b82009-07-24 05:10:25 +0000355 if (const Section *S = getReadOnlySection())
356 return S;
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000357
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000358 return getDataSection();
Anton Korobeynikov0c602462008-07-09 13:18:02 +0000359}
Anton Korobeynikov29b03f72008-07-09 13:19:38 +0000360
Chris Lattner298414e2009-07-22 00:28:43 +0000361/// getSectionForMergableConstant - Given a mergable constant with the
362/// specified size and relocation information, return a section that it
363/// should be placed in.
364const Section *
365TargetAsmInfo::getSectionForMergableConstant(uint64_t Size,
366 unsigned ReloInfo) const {
Chris Lattner7f88a202009-07-26 05:57:07 +0000367 if (ReloInfo == 0)
368 if (const Section *S = getReadOnlySection())
369 return S;
370
Anton Korobeynikov315690e2008-09-24 22:16:16 +0000371 return getDataSection();
Anton Korobeynikov93cacf12008-08-07 09:50:34 +0000372}
373
Chris Lattner298414e2009-07-22 00:28:43 +0000374
Chris Lattner7558f112009-07-21 21:09:35 +0000375const Section *TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
376 bool Override) const {
377 Section &S = Sections[Name];
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000378
379 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000380 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000381 S.Flags = Flags | SectionFlags::Named;
382 S.Name = Name;
383 }
384
385 return &S;
386}
387
388const Section*
Anton Korobeynikov328da652008-08-16 12:58:12 +0000389TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
390 bool Override) const {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000391 Section& S = Sections[Directive];
392
393 // This is newly-created section, set it up properly.
Anton Korobeynikov328da652008-08-16 12:58:12 +0000394 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikov0d44ba82008-07-09 13:28:49 +0000395 S.Flags = Flags & ~SectionFlags::Named;
396 S.Name = Directive;
397 }
398
399 return &S;
400}
Anton Korobeynikovd0c1e292008-08-16 12:57:07 +0000401
402const std::string&
403TargetAsmInfo::getSectionFlags(unsigned Flags) const {
404 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
405
406 // We didn't print these flags yet, print and save them to map. This reduces
407 // amount of heap trashing due to std::string construction / concatenation.
408 if (I == FlagsStrings.end())
409 I = FlagsStrings.insert(std::make_pair(Flags,
410 printSectionFlags(Flags))).first;
411
412 return I->second;
413}
Anton Korobeynikovffe31d72008-08-16 12:57:46 +0000414
415unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
416 unsigned Size = 0;
417 do {
418 Value >>= 7;
419 Size += sizeof(int8_t);
420 } while (Value);
421 return Size;
422}
423
424unsigned TargetAsmInfo::getSLEB128Size(int Value) {
425 unsigned Size = 0;
426 int Sign = Value >> (8 * sizeof(Value) - 1);
427 bool IsMore;
428
429 do {
430 unsigned Byte = Value & 0x7f;
431 Value >>= 7;
432 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
433 Size += sizeof(int8_t);
434 } while (IsMore);
435 return Size;
436}