Jim Laskey | 7c95ad4 | 2006-09-06 19:21:41 +0000 | [diff] [blame] | 1 | //===-- TargetAsmInfo.cpp - Asm Info ---------------------------------------==// |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines target asm properties related what form asm statements |
| 11 | // should take. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 15 | #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 Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 20 | #include "llvm/Target/TargetAsmInfo.h" |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetOptions.h" |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 22 | #include "llvm/Support/Dwarf.h" |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 23 | #include <cctype> |
| 24 | #include <cstring> |
Jim Laskey | ec0d9fe | 2006-09-06 18:35:33 +0000 | [diff] [blame] | 25 | |
| 26 | using namespace llvm; |
| 27 | |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 28 | void TargetAsmInfo::fillDefaultValues() { |
| 29 | BSSSection = "\t.bss"; |
| 30 | BSSSection_ = 0; |
| 31 | ReadOnlySection = 0; |
| 32 | SmallDataSection = 0; |
| 33 | SmallBSSSection = 0; |
| 34 | SmallRODataSection = 0; |
| 35 | TLSDataSection = 0; |
| 36 | TLSBSSSection = 0; |
| 37 | ZeroFillDirective = 0; |
| 38 | NonexecutableStackDirective = 0; |
| 39 | NeedsSet = false; |
| 40 | MaxInstLength = 4; |
| 41 | PCSymbol = "$"; |
| 42 | SeparatorChar = ';'; |
| 43 | CommentString = "#"; |
| 44 | GlobalPrefix = ""; |
| 45 | PrivateGlobalPrefix = "."; |
| 46 | LessPrivateGlobalPrefix = ""; |
| 47 | JumpTableSpecialLabelPrefix = 0; |
| 48 | GlobalVarAddrPrefix = ""; |
| 49 | GlobalVarAddrSuffix = ""; |
| 50 | FunctionAddrPrefix = ""; |
| 51 | FunctionAddrSuffix = ""; |
| 52 | PersonalityPrefix = ""; |
| 53 | PersonalitySuffix = ""; |
| 54 | NeedsIndirectEncoding = false; |
| 55 | InlineAsmStart = "#APP"; |
| 56 | InlineAsmEnd = "#NO_APP"; |
| 57 | AssemblerDialect = 0; |
| 58 | StringConstantPrefix = ".str"; |
| 59 | ZeroDirective = "\t.zero\t"; |
| 60 | ZeroDirectiveSuffix = 0; |
| 61 | AsciiDirective = "\t.ascii\t"; |
| 62 | AscizDirective = "\t.asciz\t"; |
| 63 | Data8bitsDirective = "\t.byte\t"; |
| 64 | Data16bitsDirective = "\t.short\t"; |
| 65 | Data32bitsDirective = "\t.long\t"; |
| 66 | Data64bitsDirective = "\t.quad\t"; |
| 67 | AlignDirective = "\t.align\t"; |
| 68 | AlignmentIsInBytes = true; |
| 69 | TextAlignFillValue = 0; |
| 70 | SwitchToSectionDirective = "\t.section\t"; |
| 71 | TextSectionStartSuffix = ""; |
| 72 | DataSectionStartSuffix = ""; |
| 73 | SectionEndDirectiveSuffix = 0; |
| 74 | ConstantPoolSection = "\t.section .rodata"; |
| 75 | JumpTableDataSection = "\t.section .rodata"; |
| 76 | JumpTableDirective = 0; |
| 77 | CStringSection = 0; |
| 78 | CStringSection_ = 0; |
| 79 | // FIXME: Flags are ELFish - replace with normal section stuff. |
| 80 | StaticCtorsSection = "\t.section .ctors,\"aw\",@progbits"; |
| 81 | StaticDtorsSection = "\t.section .dtors,\"aw\",@progbits"; |
| 82 | GlobalDirective = "\t.globl\t"; |
| 83 | SetDirective = 0; |
| 84 | LCOMMDirective = 0; |
| 85 | COMMDirective = "\t.comm\t"; |
| 86 | COMMDirectiveTakesAlignment = true; |
| 87 | HasDotTypeDotSizeDirective = true; |
| 88 | UsedDirective = 0; |
| 89 | WeakRefDirective = 0; |
| 90 | WeakDefDirective = 0; |
| 91 | // FIXME: These are ELFish - move to ELFTAI. |
| 92 | HiddenDirective = "\t.hidden\t"; |
| 93 | ProtectedDirective = "\t.protected\t"; |
| 94 | AbsoluteDebugSectionOffsets = false; |
| 95 | AbsoluteEHSectionOffsets = false; |
| 96 | HasLEB128 = false; |
| 97 | HasDotLocAndDotFile = false; |
| 98 | SupportsDebugInformation = false; |
| 99 | SupportsExceptionHandling = false; |
| 100 | DwarfRequiresFrameSection = true; |
| 101 | GlobalEHDirective = 0; |
| 102 | SupportsWeakOmittedEHFrame = true; |
| 103 | DwarfSectionOffsetDirective = 0; |
| 104 | DwarfAbbrevSection = ".debug_abbrev"; |
| 105 | DwarfInfoSection = ".debug_info"; |
| 106 | DwarfLineSection = ".debug_line"; |
| 107 | DwarfFrameSection = ".debug_frame"; |
| 108 | DwarfPubNamesSection = ".debug_pubnames"; |
| 109 | DwarfPubTypesSection = ".debug_pubtypes"; |
| 110 | DwarfStrSection = ".debug_str"; |
| 111 | DwarfLocSection = ".debug_loc"; |
| 112 | DwarfARangesSection = ".debug_aranges"; |
| 113 | DwarfRangesSection = ".debug_ranges"; |
| 114 | DwarfMacInfoSection = ".debug_macinfo"; |
| 115 | DwarfEHFrameSection = ".eh_frame"; |
| 116 | DwarfExceptionSection = ".gcc_except_table"; |
| 117 | AsmTransCBE = 0; |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 118 | TextSection = getUnnamedSection("\t.text", SectionFlags::Code); |
Anton Korobeynikov | 315690e | 2008-09-24 22:16:16 +0000 | [diff] [blame] | 119 | DataSection = getUnnamedSection("\t.data", SectionFlags::Writeable); |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 120 | } |
Chris Lattner | f5b10ec | 2006-10-05 00:35:16 +0000 | [diff] [blame] | 121 | |
Dan Gohman | 8f09225 | 2008-11-03 18:22:42 +0000 | [diff] [blame^] | 122 | TargetAsmInfo::TargetAsmInfo(const TargetMachine &tm) |
| 123 | : TM(tm) { |
Anton Korobeynikov | 32b952a | 2008-09-25 21:00:33 +0000 | [diff] [blame] | 124 | fillDefaultValues(); |
| 125 | } |
| 126 | |
Chris Lattner | f5b10ec | 2006-10-05 00:35:16 +0000 | [diff] [blame] | 127 | TargetAsmInfo::~TargetAsmInfo() { |
| 128 | } |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 129 | |
| 130 | /// Measure the specified inline asm to determine an approximation of its |
| 131 | /// length. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 132 | /// Comments (which run till the next SeparatorChar or newline) do not |
| 133 | /// count as an instruction. |
| 134 | /// Any other non-whitespace text is considered an instruction, with |
| 135 | /// multiple instructions separated by SeparatorChar or newlines. |
| 136 | /// Variable-length instructions are not handled here; this function |
| 137 | /// may be overloaded in the target code to do that. |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 138 | unsigned TargetAsmInfo::getInlineAsmLength(const char *Str) const { |
| 139 | // Count the number of instructions in the asm. |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 140 | bool atInsnStart = true; |
| 141 | unsigned Length = 0; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 142 | for (; *Str; ++Str) { |
| 143 | if (*Str == '\n' || *Str == SeparatorChar) |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 144 | atInsnStart = true; |
| 145 | if (atInsnStart && !isspace(*Str)) { |
| 146 | Length += MaxInstLength; |
| 147 | atInsnStart = false; |
| 148 | } |
| 149 | if (atInsnStart && strncmp(Str, CommentString, strlen(CommentString))==0) |
| 150 | atInsnStart = false; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 151 | } |
| 152 | |
Dale Johannesen | 3bb6283 | 2007-04-23 20:00:17 +0000 | [diff] [blame] | 153 | return Length; |
Chris Lattner | 4c7b07a | 2006-10-13 17:50:07 +0000 | [diff] [blame] | 154 | } |
Anton Korobeynikov | a6199c8 | 2007-03-07 02:47:57 +0000 | [diff] [blame] | 155 | |
Anton Korobeynikov | 8213f9c | 2008-02-29 22:09:08 +0000 | [diff] [blame] | 156 | unsigned TargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason, |
Anton Korobeynikov | cee750f | 2008-02-27 23:33:50 +0000 | [diff] [blame] | 157 | bool Global) const { |
| 158 | return dwarf::DW_EH_PE_absptr; |
| 159 | } |
| 160 | |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 161 | static bool isSuitableForBSS(const GlobalVariable *GV) { |
| 162 | if (!GV->hasInitializer()) |
| 163 | return true; |
| 164 | |
| 165 | // Leave constant zeros in readonly constant sections, so they can be shared |
| 166 | Constant *C = GV->getInitializer(); |
| 167 | return (C->isNullValue() && !GV->isConstant() && !NoZerosInBSS); |
| 168 | } |
| 169 | |
| 170 | SectionKind::Kind |
| 171 | TargetAsmInfo::SectionKindForGlobal(const GlobalValue *GV) const { |
| 172 | // Early exit - functions should be always in text sections. |
| 173 | if (isa<Function>(GV)) |
| 174 | return SectionKind::Text; |
| 175 | |
| 176 | const GlobalVariable* GVar = dyn_cast<GlobalVariable>(GV); |
| 177 | bool isThreadLocal = GVar->isThreadLocal(); |
| 178 | assert(GVar && "Invalid global value for section selection"); |
| 179 | |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 180 | if (isSuitableForBSS(GVar)) { |
| 181 | // Variable can be easily put to BSS section. |
| 182 | return (isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS); |
| 183 | } else if (GVar->isConstant() && !isThreadLocal) { |
| 184 | // Now we know, that varible has initializer and it is constant. We need to |
| 185 | // check its initializer to decide, which section to output it into. Also |
| 186 | // note, there is no thread-local r/o section. |
| 187 | Constant *C = GVar->getInitializer(); |
| 188 | if (C->ContainsRelocations()) |
Anton Korobeynikov | 0e48a0c | 2008-07-09 13:24:38 +0000 | [diff] [blame] | 189 | return SectionKind::ROData; |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 190 | else { |
| 191 | const ConstantArray *CVA = dyn_cast<ConstantArray>(C); |
| 192 | // Check, if initializer is a null-terminated string |
| 193 | if (CVA && CVA->isCString()) |
Anton Korobeynikov | 0e48a0c | 2008-07-09 13:24:38 +0000 | [diff] [blame] | 194 | return SectionKind::RODataMergeStr; |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 195 | else |
Anton Korobeynikov | 0e48a0c | 2008-07-09 13:24:38 +0000 | [diff] [blame] | 196 | return SectionKind::RODataMergeConst; |
Anton Korobeynikov | 28a2b54 | 2008-06-28 13:45:57 +0000 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | |
| 200 | // Variable is not constant or thread-local - emit to generic data section. |
| 201 | return (isThreadLocal ? SectionKind::ThreadData : SectionKind::Data); |
| 202 | } |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 203 | |
| 204 | unsigned |
| 205 | TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV, |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 206 | const char* Name) const { |
| 207 | unsigned Flags = SectionFlags::None; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 208 | |
| 209 | // Decode flags from global itself. |
| 210 | if (GV) { |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 211 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
| 212 | switch (Kind) { |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 213 | case SectionKind::Text: |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 214 | Flags |= SectionFlags::Code; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 215 | break; |
| 216 | case SectionKind::ThreadData: |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 217 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 218 | Flags |= SectionFlags::TLS; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 219 | // FALLS THROUGH |
Anton Korobeynikov | 7d51edf | 2008-07-09 13:29:44 +0000 | [diff] [blame] | 220 | case SectionKind::Data: |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 221 | case SectionKind::BSS: |
Anton Korobeynikov | 7d51edf | 2008-07-09 13:29:44 +0000 | [diff] [blame] | 222 | Flags |= SectionFlags::Writeable; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 223 | break; |
| 224 | case SectionKind::ROData: |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 225 | case SectionKind::RODataMergeStr: |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 226 | case SectionKind::RODataMergeConst: |
Anton Korobeynikov | 7d51edf | 2008-07-09 13:29:44 +0000 | [diff] [blame] | 227 | // No additional flags here |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 228 | break; |
Anton Korobeynikov | 04dda73 | 2008-07-22 17:09:59 +0000 | [diff] [blame] | 229 | case SectionKind::SmallData: |
| 230 | case SectionKind::SmallBSS: |
| 231 | Flags |= SectionFlags::Writeable; |
| 232 | // FALLS THROUGH |
| 233 | case SectionKind::SmallROData: |
| 234 | Flags |= SectionFlags::Small; |
| 235 | break; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 236 | default: |
| 237 | assert(0 && "Unexpected section kind!"); |
| 238 | } |
| 239 | |
Duncan Sands | 5df3186 | 2008-09-29 11:25:42 +0000 | [diff] [blame] | 240 | if (GV->mayBeOverridden()) |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 241 | Flags |= SectionFlags::Linkonce; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | // Add flags from sections, if any. |
Anton Korobeynikov | 2a88917 | 2008-07-09 13:25:46 +0000 | [diff] [blame] | 245 | if (Name && *Name) { |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 246 | Flags |= SectionFlags::Named; |
| 247 | |
| 248 | // Some lame default implementation based on some magic section names. |
| 249 | if (strncmp(Name, ".gnu.linkonce.b.", 16) == 0 || |
Anton Korobeynikov | 04dda73 | 2008-07-22 17:09:59 +0000 | [diff] [blame] | 250 | strncmp(Name, ".llvm.linkonce.b.", 17) == 0 || |
| 251 | strncmp(Name, ".gnu.linkonce.sb.", 17) == 0 || |
| 252 | strncmp(Name, ".llvm.linkonce.sb.", 18) == 0) |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 253 | Flags |= SectionFlags::BSS; |
| 254 | else if (strcmp(Name, ".tdata") == 0 || |
| 255 | strncmp(Name, ".tdata.", 7) == 0 || |
| 256 | strncmp(Name, ".gnu.linkonce.td.", 17) == 0 || |
| 257 | strncmp(Name, ".llvm.linkonce.td.", 18) == 0) |
| 258 | Flags |= SectionFlags::TLS; |
| 259 | else if (strcmp(Name, ".tbss") == 0 || |
| 260 | strncmp(Name, ".tbss.", 6) == 0 || |
| 261 | strncmp(Name, ".gnu.linkonce.tb.", 17) == 0 || |
| 262 | strncmp(Name, ".llvm.linkonce.tb.", 18) == 0) |
| 263 | Flags |= SectionFlags::BSS | SectionFlags::TLS; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 266 | return Flags; |
Anton Korobeynikov | beb9d40 | 2008-07-09 13:16:59 +0000 | [diff] [blame] | 267 | } |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 268 | |
Anton Korobeynikov | c25e1ea | 2008-09-24 22:14:23 +0000 | [diff] [blame] | 269 | const Section* |
Evan Cheng | 42ccc21 | 2008-08-08 17:56:50 +0000 | [diff] [blame] | 270 | TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 271 | const Section* S; |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 272 | // Select section name |
| 273 | if (GV->hasSection()) { |
| 274 | // Honour section already set, if any |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 275 | unsigned Flags = SectionFlagsForGlobal(GV, |
| 276 | GV->getSection().c_str()); |
| 277 | S = getNamedSection(GV->getSection().c_str(), Flags); |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 278 | } else { |
| 279 | // Use default section depending on the 'type' of global |
Evan Cheng | 42ccc21 | 2008-08-08 17:56:50 +0000 | [diff] [blame] | 280 | S = SelectSectionForGlobal(GV); |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Anton Korobeynikov | c25e1ea | 2008-09-24 22:14:23 +0000 | [diff] [blame] | 283 | return S; |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | // Lame default implementation. Calculate the section name for global. |
Evan Cheng | 42ccc21 | 2008-08-08 17:56:50 +0000 | [diff] [blame] | 287 | const Section* |
| 288 | TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const { |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 289 | SectionKind::Kind Kind = SectionKindForGlobal(GV); |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 290 | |
Duncan Sands | 5df3186 | 2008-09-29 11:25:42 +0000 | [diff] [blame] | 291 | if (GV->mayBeOverridden()) { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 292 | std::string Name = UniqueSectionForGlobal(GV, Kind); |
| 293 | unsigned Flags = SectionFlagsForGlobal(GV, Name.c_str()); |
| 294 | return getNamedSection(Name.c_str(), Flags); |
| 295 | } else { |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 296 | if (Kind == SectionKind::Text) |
Anton Korobeynikov | d7ca416 | 2008-09-24 22:15:21 +0000 | [diff] [blame] | 297 | return getTextSection(); |
Anton Korobeynikov | 4578862 | 2008-08-07 09:51:54 +0000 | [diff] [blame] | 298 | else if (isBSS(Kind) && getBSSSection_()) |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 299 | return getBSSSection_(); |
Anton Korobeynikov | 00181a3 | 2008-09-24 22:20:27 +0000 | [diff] [blame] | 300 | else if (getReadOnlySection() && SectionKind::isReadOnly(Kind)) |
| 301 | return getReadOnlySection(); |
Anton Korobeynikov | 265c525 | 2008-07-09 13:22:46 +0000 | [diff] [blame] | 302 | } |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 303 | |
Anton Korobeynikov | 315690e | 2008-09-24 22:16:16 +0000 | [diff] [blame] | 304 | return getDataSection(); |
Anton Korobeynikov | 0c60246 | 2008-07-09 13:18:02 +0000 | [diff] [blame] | 305 | } |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 306 | |
Anton Korobeynikov | 93cacf1 | 2008-08-07 09:50:34 +0000 | [diff] [blame] | 307 | // Lame default implementation. Calculate the section name for machine const. |
| 308 | const Section* |
| 309 | TargetAsmInfo::SelectSectionForMachineConst(const Type *Ty) const { |
| 310 | // FIXME: Support data.rel stuff someday |
Anton Korobeynikov | 315690e | 2008-09-24 22:16:16 +0000 | [diff] [blame] | 311 | return getDataSection(); |
Anton Korobeynikov | 93cacf1 | 2008-08-07 09:50:34 +0000 | [diff] [blame] | 312 | } |
| 313 | |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 314 | std::string |
| 315 | TargetAsmInfo::UniqueSectionForGlobal(const GlobalValue* GV, |
Anton Korobeynikov | b20015b | 2008-07-09 13:25:26 +0000 | [diff] [blame] | 316 | SectionKind::Kind Kind) const { |
| 317 | switch (Kind) { |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 318 | case SectionKind::Text: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame] | 319 | return ".gnu.linkonce.t." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 320 | case SectionKind::Data: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame] | 321 | return ".gnu.linkonce.d." + GV->getName(); |
Anton Korobeynikov | 04dda73 | 2008-07-22 17:09:59 +0000 | [diff] [blame] | 322 | case SectionKind::SmallData: |
| 323 | return ".gnu.linkonce.s." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 324 | case SectionKind::BSS: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame] | 325 | return ".gnu.linkonce.b." + GV->getName(); |
Anton Korobeynikov | 04dda73 | 2008-07-22 17:09:59 +0000 | [diff] [blame] | 326 | case SectionKind::SmallBSS: |
| 327 | return ".gnu.linkonce.sb." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 328 | case SectionKind::ROData: |
| 329 | case SectionKind::RODataMergeConst: |
| 330 | case SectionKind::RODataMergeStr: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame] | 331 | return ".gnu.linkonce.r." + GV->getName(); |
Anton Korobeynikov | 04dda73 | 2008-07-22 17:09:59 +0000 | [diff] [blame] | 332 | case SectionKind::SmallROData: |
| 333 | return ".gnu.linkonce.s2." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 334 | case SectionKind::ThreadData: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame] | 335 | return ".gnu.linkonce.td." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 336 | case SectionKind::ThreadBSS: |
Anton Korobeynikov | 5248670 | 2008-07-09 13:24:55 +0000 | [diff] [blame] | 337 | return ".gnu.linkonce.tb." + GV->getName(); |
Anton Korobeynikov | 29b03f7 | 2008-07-09 13:19:38 +0000 | [diff] [blame] | 338 | default: |
| 339 | assert(0 && "Unknown section kind"); |
| 340 | } |
| 341 | } |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 342 | |
| 343 | const Section* |
Anton Korobeynikov | 328da65 | 2008-08-16 12:58:12 +0000 | [diff] [blame] | 344 | TargetAsmInfo::getNamedSection(const char *Name, unsigned Flags, |
| 345 | bool Override) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 346 | Section& S = Sections[Name]; |
| 347 | |
| 348 | // This is newly-created section, set it up properly. |
Anton Korobeynikov | 328da65 | 2008-08-16 12:58:12 +0000 | [diff] [blame] | 349 | if (S.Flags == SectionFlags::Invalid || Override) { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 350 | S.Flags = Flags | SectionFlags::Named; |
| 351 | S.Name = Name; |
| 352 | } |
| 353 | |
| 354 | return &S; |
| 355 | } |
| 356 | |
| 357 | const Section* |
Anton Korobeynikov | 328da65 | 2008-08-16 12:58:12 +0000 | [diff] [blame] | 358 | TargetAsmInfo::getUnnamedSection(const char *Directive, unsigned Flags, |
| 359 | bool Override) const { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 360 | Section& S = Sections[Directive]; |
| 361 | |
| 362 | // This is newly-created section, set it up properly. |
Anton Korobeynikov | 328da65 | 2008-08-16 12:58:12 +0000 | [diff] [blame] | 363 | if (S.Flags == SectionFlags::Invalid || Override) { |
Anton Korobeynikov | 0d44ba8 | 2008-07-09 13:28:49 +0000 | [diff] [blame] | 364 | S.Flags = Flags & ~SectionFlags::Named; |
| 365 | S.Name = Directive; |
| 366 | } |
| 367 | |
| 368 | return &S; |
| 369 | } |
Anton Korobeynikov | d0c1e29 | 2008-08-16 12:57:07 +0000 | [diff] [blame] | 370 | |
| 371 | const std::string& |
| 372 | TargetAsmInfo::getSectionFlags(unsigned Flags) const { |
| 373 | SectionFlags::FlagsStringsMapType::iterator I = FlagsStrings.find(Flags); |
| 374 | |
| 375 | // We didn't print these flags yet, print and save them to map. This reduces |
| 376 | // amount of heap trashing due to std::string construction / concatenation. |
| 377 | if (I == FlagsStrings.end()) |
| 378 | I = FlagsStrings.insert(std::make_pair(Flags, |
| 379 | printSectionFlags(Flags))).first; |
| 380 | |
| 381 | return I->second; |
| 382 | } |
Anton Korobeynikov | ffe31d7 | 2008-08-16 12:57:46 +0000 | [diff] [blame] | 383 | |
| 384 | unsigned TargetAsmInfo::getULEB128Size(unsigned Value) { |
| 385 | unsigned Size = 0; |
| 386 | do { |
| 387 | Value >>= 7; |
| 388 | Size += sizeof(int8_t); |
| 389 | } while (Value); |
| 390 | return Size; |
| 391 | } |
| 392 | |
| 393 | unsigned TargetAsmInfo::getSLEB128Size(int Value) { |
| 394 | unsigned Size = 0; |
| 395 | int Sign = Value >> (8 * sizeof(Value) - 1); |
| 396 | bool IsMore; |
| 397 | |
| 398 | do { |
| 399 | unsigned Byte = Value & 0x7f; |
| 400 | Value >>= 7; |
| 401 | IsMore = Value != Sign || ((Byte ^ Sign) & 0x40) != 0; |
| 402 | Size += sizeof(int8_t); |
| 403 | } while (IsMore); |
| 404 | return Size; |
| 405 | } |