blob: 6baebd0ffe767236bda39befc4bd79d02bdf90dc [file] [log] [blame]
Jim Laskeyef94ebb2006-09-06 19:21:41 +00001//===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==//
Jim Laskey681ecbb2006-09-06 18:35:33 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Laskey681ecbb2006-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 Korobeynikov2e052a82008-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 Laskey681ecbb2006-09-06 18:35:33 +000020#include "llvm/Target/TargetAsmInfo.h"
Anton Korobeynikov2e052a82008-06-28 13:45:57 +000021#include "llvm/Target/TargetOptions.h"
Anton Korobeynikovae24cca2008-02-27 23:33:50 +000022#include "llvm/Support/Dwarf.h"
Dale Johannesen0a1069d2007-04-23 20:00:17 +000023#include <cctype>
24#include <cstring>
Jim Laskey681ecbb2006-09-06 18:35:33 +000025
26using namespace llvm;
27
28TargetAsmInfo::TargetAsmInfo() :
Dan Gohman2675a652007-05-03 18:46:30 +000029 TextSection("\t.text"),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000030 TextSection_(0),
Dan Gohman2675a652007-05-03 18:46:30 +000031 DataSection("\t.data"),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000032 DataSection_(0),
Dan Gohman2675a652007-05-03 18:46:30 +000033 BSSSection("\t.bss"),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000034 BSSSection_(0),
35 ReadOnlySection(0),
36 ReadOnlySection_(0),
Bruno Cardoso Lopes9cfd2f82008-07-22 15:26:53 +000037 SmallDataSection(0),
38 SmallBSSSection(0),
39 SmallRODataSection(0),
Lauro Ramos Venancio25188892007-04-20 21:38:10 +000040 TLSDataSection("\t.section .tdata,\"awT\",@progbits"),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000041 TLSDataSection_(0),
Lauro Ramos Venancio25188892007-04-20 21:38:10 +000042 TLSBSSSection("\t.section .tbss,\"awT\",@nobits"),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000043 TLSBSSSection_(0),
Chris Lattner1ceb6432007-01-17 17:42:42 +000044 ZeroFillDirective(0),
Dan Gohmanbcde1722008-05-05 00:28:39 +000045 NonexecutableStackDirective(0),
Jim Laskey681ecbb2006-09-06 18:35:33 +000046 NeedsSet(false),
Chris Lattner95129a72006-10-13 17:50:07 +000047 MaxInstLength(4),
Jim Laskeyc3de9b42007-02-01 16:31:34 +000048 PCSymbol("$"),
Chris Lattner95129a72006-10-13 17:50:07 +000049 SeparatorChar(';'),
Jim Laskey681ecbb2006-09-06 18:35:33 +000050 CommentString("#"),
51 GlobalPrefix(""),
52 PrivateGlobalPrefix("."),
Chris Lattner0ee2d462007-01-18 01:12:56 +000053 JumpTableSpecialLabelPrefix(0),
Jim Laskey681ecbb2006-09-06 18:35:33 +000054 GlobalVarAddrPrefix(""),
55 GlobalVarAddrSuffix(""),
56 FunctionAddrPrefix(""),
57 FunctionAddrSuffix(""),
Bill Wendling2b8fc312007-09-11 08:27:17 +000058 PersonalityPrefix(""),
59 PersonalitySuffix(""),
Bill Wendling74fb0f12007-09-11 17:20:55 +000060 NeedsIndirectEncoding(false),
Jim Laskey681ecbb2006-09-06 18:35:33 +000061 InlineAsmStart("#APP"),
62 InlineAsmEnd("#NO_APP"),
Bill Wendlinge21237e2007-01-16 03:42:04 +000063 AssemblerDialect(0),
Dale Johannesen355b74a2008-06-03 18:09:06 +000064 StringConstantPrefix(".str"),
Jim Laskey681ecbb2006-09-06 18:35:33 +000065 ZeroDirective("\t.zero\t"),
66 ZeroDirectiveSuffix(0),
67 AsciiDirective("\t.ascii\t"),
68 AscizDirective("\t.asciz\t"),
69 Data8bitsDirective("\t.byte\t"),
70 Data16bitsDirective("\t.short\t"),
71 Data32bitsDirective("\t.long\t"),
72 Data64bitsDirective("\t.quad\t"),
73 AlignDirective("\t.align\t"),
74 AlignmentIsInBytes(true),
Lauro Ramos Venancio714eeb22008-02-28 22:14:09 +000075 TextAlignFillValue(0),
Jim Laskey681ecbb2006-09-06 18:35:33 +000076 SwitchToSectionDirective("\t.section\t"),
77 TextSectionStartSuffix(""),
78 DataSectionStartSuffix(""),
79 SectionEndDirectiveSuffix(0),
Dan Gohman3a8e2a82007-06-14 15:00:27 +000080 ConstantPoolSection("\t.section .rodata"),
81 JumpTableDataSection("\t.section .rodata"),
Andrew Lenharth783a4a92006-09-24 19:45:58 +000082 JumpTableDirective(0),
Reid Spencere54243f2006-10-27 16:14:06 +000083 CStringSection(0),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000084 CStringSection_(0),
Jim Laskey681ecbb2006-09-06 18:35:33 +000085 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
86 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
87 FourByteConstantSection(0),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000088 FourByteConstantSection_(0),
Jim Laskey681ecbb2006-09-06 18:35:33 +000089 EightByteConstantSection(0),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000090 EightByteConstantSection_(0),
Jim Laskey681ecbb2006-09-06 18:35:33 +000091 SixteenByteConstantSection(0),
Anton Korobeynikovdaee2812008-07-09 13:28:49 +000092 SixteenByteConstantSection_(0),
Gordon Henriksen84c73252007-12-23 20:58:16 +000093 GlobalDirective("\t.globl\t"),
Jim Laskey681ecbb2006-09-06 18:35:33 +000094 SetDirective(0),
95 LCOMMDirective(0),
96 COMMDirective("\t.comm\t"),
97 COMMDirectiveTakesAlignment(true),
98 HasDotTypeDotSizeDirective(true),
Chris Lattner66af3902006-09-26 03:38:18 +000099 UsedDirective(0),
Evan Cheng022030a2006-12-01 20:47:11 +0000100 WeakRefDirective(0),
Dale Johannesen763e1102007-11-20 23:24:42 +0000101 WeakDefDirective(0),
Chris Lattner9f6badb2007-01-14 06:27:21 +0000102 HiddenDirective("\t.hidden\t"),
Anton Korobeynikov39f3cff2007-04-29 18:35:00 +0000103 ProtectedDirective("\t.protected\t"),
Anton Korobeynikovb538f672007-05-01 22:23:12 +0000104 AbsoluteDebugSectionOffsets(false),
105 AbsoluteEHSectionOffsets(false),
Jim Laskey681ecbb2006-09-06 18:35:33 +0000106 HasLEB128(false),
Dan Gohman0cc9d1b2007-09-24 21:09:53 +0000107 HasDotLocAndDotFile(false),
Anton Korobeynikov4db00902007-05-05 09:04:50 +0000108 SupportsDebugInformation(false),
Jim Laskeyb4a2f052007-01-29 18:51:14 +0000109 SupportsExceptionHandling(false),
Reid Spencerb51b5c02006-10-30 22:32:30 +0000110 DwarfRequiresFrameSection(true),
Dale Johannesene70850c2007-11-21 00:45:00 +0000111 GlobalEHDirective(0),
Dale Johannesen7ecb3b72008-01-10 02:03:30 +0000112 SupportsWeakOmittedEHFrame(true),
Anton Korobeynikov942fda02007-03-07 02:47:57 +0000113 DwarfSectionOffsetDirective(0),
Jim Laskey681ecbb2006-09-06 18:35:33 +0000114 DwarfAbbrevSection(".debug_abbrev"),
115 DwarfInfoSection(".debug_info"),
116 DwarfLineSection(".debug_line"),
117 DwarfFrameSection(".debug_frame"),
118 DwarfPubNamesSection(".debug_pubnames"),
119 DwarfPubTypesSection(".debug_pubtypes"),
120 DwarfStrSection(".debug_str"),
121 DwarfLocSection(".debug_loc"),
122 DwarfARangesSection(".debug_aranges"),
123 DwarfRangesSection(".debug_ranges"),
Andrew Lenharthff35b442006-11-28 19:52:20 +0000124 DwarfMacInfoSection(".debug_macinfo"),
Jim Laskeyc3de9b42007-02-01 16:31:34 +0000125 DwarfEHFrameSection(".eh_frame"),
Jim Laskeyaf76e0e2007-02-21 22:43:40 +0000126 DwarfExceptionSection(".gcc_except_table"),
Andrew Lenharthff35b442006-11-28 19:52:20 +0000127 AsmTransCBE(0) {
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000128 TextSection_ = getUnnamedSection(TextSection);
129 DataSection_ = getUnnamedSection(DataSection);
Chris Lattner95129a72006-10-13 17:50:07 +0000130}
Chris Lattnerafe6d7a2006-10-05 00:35:16 +0000131
132TargetAsmInfo::~TargetAsmInfo() {
133}
Chris Lattner95129a72006-10-13 17:50:07 +0000134
135/// Measure the specified inline asm to determine an approximation of its
136/// length.
Dale Johannesen0a1069d2007-04-23 20:00:17 +0000137/// Comments (which run till the next SeparatorChar or newline) do not
138/// count as an instruction.
139/// Any other non-whitespace text is considered an instruction, with
140/// multiple instructions separated by SeparatorChar or newlines.
141/// Variable-length instructions are not handled here; this function
142/// may be overloaded in the target code to do that.
Chris Lattner95129a72006-10-13 17:50:07 +0000143unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const {
144 // Count the number of instructions in the asm.
Dale Johannesen0a1069d2007-04-23 20:00:17 +0000145 bool atInsnStart = true;
146 unsigned Length = 0;
Chris Lattner95129a72006-10-13 17:50:07 +0000147 for (; *Str; ++Str) {
148 if (*Str == '\n' || *Str == SeparatorChar)
Dale Johannesen0a1069d2007-04-23 20:00:17 +0000149 atInsnStart = true;
150 if (atInsnStart && !isspace(*Str)) {
151 Length += MaxInstLength;
152 atInsnStart = false;
153 }
154 if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0)
155 atInsnStart = false;
Chris Lattner95129a72006-10-13 17:50:07 +0000156 }
157
Dale Johannesen0a1069d2007-04-23 20:00:17 +0000158 return Length;
Chris Lattner95129a72006-10-13 17:50:07 +0000159}
Anton Korobeynikov942fda02007-03-07 02:47:57 +0000160
Anton Korobeynikov0e8b1462008-02-29 22:09:08 +0000161unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
Anton Korobeynikovae24cca2008-02-27 23:33:50 +0000162 bool Global) const {
163 return dwarf::DW_EH_PE_absptr;
164}
165
Anton Korobeynikov2e052a82008-06-28 13:45:57 +0000166static bool isSuitableForBSS(const GlobalVariable *GV) {
167 if (!GV->hasInitializer())
168 return true;
169
170 // Leave constant zeros in readonly constant sections, so they can be shared
171 Constant *C = GV->getInitializer();
172 return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS);
173}
174
175SectionKind::Kind
176TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const {
177 // Early exit - functions should be always in text sections.
178 if (isa<Function>(GV))
179 return SectionKind::Text;
180
181 const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV);
182 bool isThreadLocal = GVar->isThreadLocal();
183 assert(GVar && "Invalid global value for section selection");
184
Anton Korobeynikov2e052a82008-06-28 13:45:57 +0000185 if (isSuitableForBSS(GVar)) {
186 // Variable can be easily put to BSS section.
187 return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS);
188 } else if (GVar->isConstant() && !isThreadLocal) {
189 // Now we know, that varible has initializer and it is constant. We need to
190 // check its initializer to decide, which section to output it into. Also
191 // note, there is no thread-local r/o section.
192 Constant *C = GVar->getInitializer();
193 if (C->ContainsRelocations())
Anton Korobeynikov7504c282008-07-09 13:24:38 +0000194 return SectionKind::ROData;
Anton Korobeynikov2e052a82008-06-28 13:45:57 +0000195 else {
196 const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
197 // Check, if initializer is a null-terminated string
198 if (CVA && CVA->isCString())
Anton Korobeynikov7504c282008-07-09 13:24:38 +0000199 return SectionKind::RODataMergeStr;
Anton Korobeynikov2e052a82008-06-28 13:45:57 +0000200 else
Anton Korobeynikov7504c282008-07-09 13:24:38 +0000201 return SectionKind::RODataMergeConst;
Anton Korobeynikov2e052a82008-06-28 13:45:57 +0000202 }
203 }
204
205 // Variable is not constant or thread-local - emit to generic data section.
206 return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data);
207}
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000208
209unsigned
210TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
Anton Korobeynikov60919582008-07-09 13:25:26 +0000211 const char* Name) const {
212 unsigned Flags = SectionFlags::None;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000213
214 // Decode flags from global itself.
215 if (GV) {
Anton Korobeynikov60919582008-07-09 13:25:26 +0000216 SectionKind::Kind Kind = SectionKindForGlobal(GV);
217 switch (Kind) {
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000218 case SectionKind::Text:
Anton Korobeynikov60919582008-07-09 13:25:26 +0000219 Flags |= SectionFlags::Code;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000220 break;
221 case SectionKind::ThreadData:
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000222 case SectionKind::ThreadBSS:
Anton Korobeynikov60919582008-07-09 13:25:26 +0000223 Flags |= SectionFlags::TLS;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000224 // FALLS THROUGH
Anton Korobeynikov56827c12008-07-09 13:29:44 +0000225 case SectionKind::Data:
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000226 case SectionKind::BSS:
Anton Korobeynikov56827c12008-07-09 13:29:44 +0000227 Flags |= SectionFlags::Writeable;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000228 break;
229 case SectionKind::ROData:
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000230 case SectionKind::RODataMergeStr:
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000231 case SectionKind::RODataMergeConst:
Anton Korobeynikov56827c12008-07-09 13:29:44 +0000232 // No additional flags here
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000233 break;
Anton Korobeynikov4fdeb9b2008-07-22 17:09:59 +0000234 case SectionKind::SmallData:
235 case SectionKind::SmallBSS:
236 Flags |= SectionFlags::Writeable;
237 // FALLS THROUGH
238 case SectionKind::SmallROData:
239 Flags |= SectionFlags::Small;
240 break;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000241 default:
242 assert(0 && "Unexpected section kind!");
243 }
244
Anton Korobeynikov577c45d2008-07-09 13:27:59 +0000245 if (GV->isWeakForLinker())
Anton Korobeynikov60919582008-07-09 13:25:26 +0000246 Flags |= SectionFlags::Linkonce;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000247 }
248
249 // Add flags from sections, if any.
Anton Korobeynikov13b9a222008-07-09 13:25:46 +0000250 if (Name && *Name) {
Anton Korobeynikov60919582008-07-09 13:25:26 +0000251 Flags |= SectionFlags::Named;
252
253 // Some lame default implementation based on some magic section names.
254 if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 ||
Anton Korobeynikov4fdeb9b2008-07-22 17:09:59 +0000255 strncmp(Name, ".llvm.linkonce.b.", 17) == 0 ||
256 strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 ||
257 strncmp(Name, ".llvm.linkonce.sb.", 18) == 0)
Anton Korobeynikov60919582008-07-09 13:25:26 +0000258 Flags |= SectionFlags::BSS;
259 else if (strcmp(Name, ".tdata") == 0 ||
260 strncmp(Name, ".tdata.", 7) == 0 ||
261 strncmp(Name, ".gnu.linkonce.td.", 17) == 0 ||
262 strncmp(Name, ".llvm.linkonce.td.", 18) == 0)
263 Flags |= SectionFlags::TLS;
264 else if (strcmp(Name, ".tbss") == 0 ||
265 strncmp(Name, ".tbss.", 6) == 0 ||
266 strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 ||
267 strncmp(Name, ".llvm.linkonce.tb.", 18) == 0)
268 Flags |= SectionFlags::BSS | SectionFlags::TLS;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000269 }
270
Anton Korobeynikov60919582008-07-09 13:25:26 +0000271 return Flags;
Anton Korobeynikov9e4ab502008-07-09 13:16:59 +0000272}
Anton Korobeynikov21539c62008-07-09 13:18:02 +0000273
Anton Korobeynikov768019872008-07-09 13:19:08 +0000274std::string
Evan Chengdf8c7fa2008-08-08 17:56:50 +0000275TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000276 const Section* S;
Anton Korobeynikov9d6939b2008-07-09 13:22:46 +0000277 // Select section name
278 if (GV->hasSection()) {
279 // Honour section already set, if any
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000280 unsigned Flags = SectionFlagsForGlobal(GV,
281 GV->getSection().c_str());
282 S = getNamedSection(GV->getSection().c_str(), Flags);
Anton Korobeynikov9d6939b2008-07-09 13:22:46 +0000283 } else {
284 // Use default section depending on the 'type' of global
Evan Chengdf8c7fa2008-08-08 17:56:50 +0000285 S = SelectSectionForGlobal(GV);
Anton Korobeynikov9d6939b2008-07-09 13:22:46 +0000286 }
287
Dan Gohmanefa41602008-07-15 18:37:51 +0000288 if (!S->isNamed())
289 return S->Name;
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000290
Anton Korobeynikov60919582008-07-09 13:25:26 +0000291 // If section is named we need to switch into it via special '.section'
292 // directive and also append funky flags. Otherwise - section name is just
293 // some magic assembler directive.
Anton Korobeynikov44b4a9a2008-08-16 12:57:07 +0000294 return getSwitchToSectionDirective() + S->Name + getSectionFlags(S->Flags);
Anton Korobeynikov9d6939b2008-07-09 13:22:46 +0000295}
296
297// Lame default implementation. Calculate the section name for global.
Evan Chengdf8c7fa2008-08-08 17:56:50 +0000298const Section*
299TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
Anton Korobeynikov60919582008-07-09 13:25:26 +0000300 SectionKind::Kind Kind = SectionKindForGlobal(GV);
Anton Korobeynikov21539c62008-07-09 13:18:02 +0000301
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000302 if (GV->isWeakForLinker()) {
303 std::string Name = UniqueSectionForGlobal(GV, Kind);
304 unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str());
305 return getNamedSection(Name.c_str(), Flags);
306 } else {
Anton Korobeynikov60919582008-07-09 13:25:26 +0000307 if (Kind == SectionKind::Text)
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000308 return getTextSection_();
Anton Korobeynikov8ab2f492008-08-07 09:51:54 +0000309 else if (isBSS(Kind) && getBSSSection_())
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000310 return getBSSSection_();
Anton Korobeynikov8ab2f492008-08-07 09:51:54 +0000311 else if (getReadOnlySection_() && SectionKind::isReadOnly(Kind))
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000312 return getReadOnlySection_();
Anton Korobeynikov9d6939b2008-07-09 13:22:46 +0000313 }
Anton Korobeynikov21539c62008-07-09 13:18:02 +0000314
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000315 return getDataSection_();
Anton Korobeynikov21539c62008-07-09 13:18:02 +0000316}
Anton Korobeynikovab778022008-07-09 13:19:38 +0000317
Anton Korobeynikovef643a42008-08-07 09:50:34 +0000318// Lame default implementation. Calculate the section name for machine const.
319const Section*
320TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const {
321 // FIXME: Support data.rel stuff someday
322 return getDataSection_();
323}
324
Anton Korobeynikovab778022008-07-09 13:19:38 +0000325std::string
326TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV,
Anton Korobeynikov60919582008-07-09 13:25:26 +0000327 SectionKind::Kind Kind) const {
328 switch (Kind) {
Anton Korobeynikovab778022008-07-09 13:19:38 +0000329 case SectionKind::Text:
Anton Korobeynikovd789b7c2008-07-09 13:24:55 +0000330 return ".gnu.linkonce.t." + GV->getName();
Anton Korobeynikovab778022008-07-09 13:19:38 +0000331 case SectionKind::Data:
Anton Korobeynikovd789b7c2008-07-09 13:24:55 +0000332 return ".gnu.linkonce.d." + GV->getName();
Anton Korobeynikov4fdeb9b2008-07-22 17:09:59 +0000333 case SectionKind::SmallData:
334 return ".gnu.linkonce.s." + GV->getName();
Anton Korobeynikovab778022008-07-09 13:19:38 +0000335 case SectionKind::BSS:
Anton Korobeynikovd789b7c2008-07-09 13:24:55 +0000336 return ".gnu.linkonce.b." + GV->getName();
Anton Korobeynikov4fdeb9b2008-07-22 17:09:59 +0000337 case SectionKind::SmallBSS:
338 return ".gnu.linkonce.sb." + GV->getName();
Anton Korobeynikovab778022008-07-09 13:19:38 +0000339 case SectionKind::ROData:
340 case SectionKind::RODataMergeConst:
341 case SectionKind::RODataMergeStr:
Anton Korobeynikovd789b7c2008-07-09 13:24:55 +0000342 return ".gnu.linkonce.r." + GV->getName();
Anton Korobeynikov4fdeb9b2008-07-22 17:09:59 +0000343 case SectionKind::SmallROData:
344 return ".gnu.linkonce.s2." + GV->getName();
Anton Korobeynikovab778022008-07-09 13:19:38 +0000345 case SectionKind::ThreadData:
Anton Korobeynikovd789b7c2008-07-09 13:24:55 +0000346 return ".gnu.linkonce.td." + GV->getName();
Anton Korobeynikovab778022008-07-09 13:19:38 +0000347 case SectionKind::ThreadBSS:
Anton Korobeynikovd789b7c2008-07-09 13:24:55 +0000348 return ".gnu.linkonce.tb." + GV->getName();
Anton Korobeynikovab778022008-07-09 13:19:38 +0000349 default:
350 assert(0 && "Unknown section kind");
351 }
352}
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000353
354const Section*
Anton Korobeynikov2ae54462008-08-16 12:58:12 +0000355TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags,
356 bool Override) const {
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000357 Section& S = Sections[Name];
358
359 // This is newly-created section, set it up properly.
Anton Korobeynikov2ae54462008-08-16 12:58:12 +0000360 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000361 S.Flags = Flags | SectionFlags::Named;
362 S.Name = Name;
363 }
364
365 return &S;
366}
367
368const Section*
Anton Korobeynikov2ae54462008-08-16 12:58:12 +0000369TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags,
370 bool Override) const {
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000371 Section& S = Sections[Directive];
372
373 // This is newly-created section, set it up properly.
Anton Korobeynikov2ae54462008-08-16 12:58:12 +0000374 if (S.Flags == SectionFlags::Invalid || Override) {
Anton Korobeynikovdaee2812008-07-09 13:28:49 +0000375 S.Flags = Flags & ~SectionFlags::Named;
376 S.Name = Directive;
377 }
378
379 return &S;
380}
Anton Korobeynikov44b4a9a2008-08-16 12:57:07 +0000381
382const std::string&
383TargetAsmInfo::getSectionFlags(unsigned Flags) const {
384 SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags);
385
386 // We didn't print these flags yet, print and save them to map. This reduces
387 // amount of heap trashing due to std::string construction / concatenation.
388 if (I == FlagsStrings.end())
389 I = FlagsStrings.insert(std::make_pair(Flags,
390 printSectionFlags(Flags))).first;
391
392 return I->second;
393}
Anton Korobeynikovbd890b12008-08-16 12:57:46 +0000394
395unsigned TargetAsmInfo::getULEB128Size(unsigned Value) {
396 unsigned Size = 0;
397 do {
398 Value >>= 7;
399 Size += sizeof(int8_t);
400 } while (Value);
401 return Size;
402}
403
404unsigned TargetAsmInfo::getSLEB128Size(int Value) {
405 unsigned Size = 0;
406 int Sign = Value >> (8 * sizeof(Value) - 1);
407 bool IsMore;
408
409 do {
410 unsigned Byte = Value & 0x7f;
411 Value >>= 7;
412 IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0;
413 Size += sizeof(int8_t);
414 } while (IsMore);
415 return Size;
416}