Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 1 | //===-- ARMTargetAsmInfo.cpp - ARM asm properties ---------------*- C++ -*-===// |
| 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 | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the declarations of the ARMTargetAsmInfo properties. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "ARMTargetAsmInfo.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 15 | #include "ARMTargetMachine.h" |
Dale Johannesen | 24fb52d | 2007-04-23 20:04:35 +0000 | [diff] [blame] | 16 | #include <cstring> |
| 17 | #include <cctype> |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
Dan Gohman | cfbb2f0 | 2008-03-25 21:45:14 +0000 | [diff] [blame] | 20 | static const char *const arm_asm_table[] = { |
| 21 | "{r0}", "r0", |
Lauro Ramos Venancio | 61718a6 | 2007-06-08 21:06:23 +0000 | [diff] [blame] | 22 | "{r1}", "r1", |
| 23 | "{r2}", "r2", |
| 24 | "{r3}", "r3", |
| 25 | "{r4}", "r4", |
| 26 | "{r5}", "r5", |
| 27 | "{r6}", "r6", |
| 28 | "{r7}", "r7", |
| 29 | "{r8}", "r8", |
| 30 | "{r9}", "r9", |
| 31 | "{r10}", "r10", |
| 32 | "{r11}", "r11", |
| 33 | "{r12}", "r12", |
| 34 | "{r13}", "r13", |
| 35 | "{r14}", "r14", |
| 36 | "{lr}", "lr", |
| 37 | "{sp}", "sp", |
| 38 | "{ip}", "ip", |
| 39 | "{fp}", "fp", |
| 40 | "{sl}", "sl", |
| 41 | "{memory}", "memory", |
| 42 | "{cc}", "cc", |
| 43 | 0,0}; |
| 44 | |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 45 | ARMTargetAsmInfo::ARMTargetAsmInfo(const ARMTargetMachine &TM) { |
Lauro Ramos Venancio | 61718a6 | 2007-06-08 21:06:23 +0000 | [diff] [blame] | 46 | AsmTransCBE = arm_asm_table; |
Lauro Ramos Venancio | e8e5495 | 2007-05-03 20:28:35 +0000 | [diff] [blame] | 47 | |
Lauro Ramos Venancio | ea9fc58 | 2007-01-26 23:24:43 +0000 | [diff] [blame] | 48 | AlignmentIsInBytes = false; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 49 | Data64bitsDirective = 0; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 50 | CommentString = "@"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 51 | DataSection = "\t.data"; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 52 | ConstantPoolSection = "\t.text\n"; |
Lauro Ramos Venancio | ea9fc58 | 2007-01-26 23:24:43 +0000 | [diff] [blame] | 53 | COMMDirectiveTakesAlignment = false; |
| 54 | InlineAsmStart = "@ InlineAsm Start"; |
| 55 | InlineAsmEnd = "@ InlineAsm End"; |
| 56 | LCOMMDirective = "\t.lcomm\t"; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 57 | } |
| 58 | |
Anton Korobeynikov | 0f3cc65 | 2008-08-07 09:54:23 +0000 | [diff] [blame^] | 59 | ARMDarwinTargetAsmInfo::ARMDarwinTargetAsmInfo(const ARMTargetMachine &TM): |
| 60 | ARMTargetAsmInfo(TM), DarwinTargetAsmInfo(TM) { |
| 61 | Subtarget = &DTM->getSubtarget<ARMSubtarget>(); |
| 62 | |
| 63 | GlobalPrefix = "_"; |
| 64 | PrivateGlobalPrefix = "L"; |
| 65 | StringConstantPrefix = "\1LC"; |
| 66 | BSSSection = 0; // no BSS section |
| 67 | ZeroDirective = "\t.space\t"; |
| 68 | ZeroFillDirective = "\t.zerofill\t"; // Uses .zerofill |
| 69 | SetDirective = "\t.set\t"; |
| 70 | WeakRefDirective = "\t.weak_reference\t"; |
| 71 | HiddenDirective = "\t.private_extern\t"; |
| 72 | ProtectedDirective = NULL; |
| 73 | JumpTableDataSection = ".const"; |
| 74 | CStringSection = "\t.cstring"; |
| 75 | FourByteConstantSection = "\t.literal4\n"; |
| 76 | EightByteConstantSection = "\t.literal8\n"; |
| 77 | ReadOnlySection = "\t.const\n"; |
| 78 | HasDotTypeDotSizeDirective = false; |
| 79 | NeedsIndirectEncoding = true; |
| 80 | if (TM.getRelocationModel() == Reloc::Static) { |
| 81 | StaticCtorsSection = ".constructor"; |
| 82 | StaticDtorsSection = ".destructor"; |
| 83 | } else { |
| 84 | StaticCtorsSection = ".mod_init_func"; |
| 85 | StaticDtorsSection = ".mod_term_func"; |
| 86 | } |
| 87 | |
| 88 | // In non-PIC modes, emit a special label before jump tables so that the |
| 89 | // linker can perform more accurate dead code stripping. |
| 90 | if (TM.getRelocationModel() != Reloc::PIC_) { |
| 91 | // Emit a local label that is preserved until the linker runs. |
| 92 | JumpTableSpecialLabelPrefix = "l"; |
| 93 | } |
| 94 | |
| 95 | NeedsSet = true; |
| 96 | DwarfAbbrevSection = ".section __DWARF,__debug_abbrev,regular,debug"; |
| 97 | DwarfInfoSection = ".section __DWARF,__debug_info,regular,debug"; |
| 98 | DwarfLineSection = ".section __DWARF,__debug_line,regular,debug"; |
| 99 | DwarfFrameSection = ".section __DWARF,__debug_frame,regular,debug"; |
| 100 | DwarfPubNamesSection = ".section __DWARF,__debug_pubnames,regular,debug"; |
| 101 | DwarfPubTypesSection = ".section __DWARF,__debug_pubtypes,regular,debug"; |
| 102 | DwarfStrSection = ".section __DWARF,__debug_str,regular,debug"; |
| 103 | DwarfLocSection = ".section __DWARF,__debug_loc,regular,debug"; |
| 104 | DwarfARangesSection = ".section __DWARF,__debug_aranges,regular,debug"; |
| 105 | DwarfRangesSection = ".section __DWARF,__debug_ranges,regular,debug"; |
| 106 | DwarfMacInfoSection = ".section __DWARF,__debug_macinfo,regular,debug"; |
| 107 | } |
| 108 | |
| 109 | ARMELFTargetAsmInfo::ARMELFTargetAsmInfo(const ARMTargetMachine &TM): |
| 110 | ARMTargetAsmInfo(TM), ELFTargetAsmInfo(TM) { |
| 111 | Subtarget = &ETM->getSubtarget<ARMSubtarget>(); |
| 112 | |
| 113 | NeedsSet = false; |
| 114 | HasLEB128 = true; |
| 115 | AbsoluteDebugSectionOffsets = true; |
| 116 | CStringSection = ".rodata.str"; |
| 117 | ReadOnlySection = "\t.section\t.rodata\n"; |
| 118 | FourByteConstantSection = "\t.section\t.rodata.cst4,\"aM\",@progbits,4"; |
| 119 | EightByteConstantSection = "\t.section\t.rodata.cst8,\"aM\",@progbits,8"; |
| 120 | SixteenByteConstantSection = "\t.section\t.rodata.cst16,\"aM\",@progbits,16"; |
| 121 | PrivateGlobalPrefix = ".L"; |
| 122 | WeakRefDirective = "\t.weak\t"; |
| 123 | SetDirective = "\t.set\t"; |
| 124 | DwarfRequiresFrameSection = false; |
| 125 | DwarfAbbrevSection = "\t.section\t.debug_abbrev,\"\",%progbits"; |
| 126 | DwarfInfoSection = "\t.section\t.debug_info,\"\",%progbits"; |
| 127 | DwarfLineSection = "\t.section\t.debug_line,\"\",%progbits"; |
| 128 | DwarfFrameSection = "\t.section\t.debug_frame,\"\",%progbits"; |
| 129 | DwarfPubNamesSection ="\t.section\t.debug_pubnames,\"\",%progbits"; |
| 130 | DwarfPubTypesSection ="\t.section\t.debug_pubtypes,\"\",%progbits"; |
| 131 | DwarfStrSection = "\t.section\t.debug_str,\"\",%progbits"; |
| 132 | DwarfLocSection = "\t.section\t.debug_loc,\"\",%progbits"; |
| 133 | DwarfARangesSection = "\t.section\t.debug_aranges,\"\",%progbits"; |
| 134 | DwarfRangesSection = "\t.section\t.debug_ranges,\"\",%progbits"; |
| 135 | DwarfMacInfoSection = "\t.section\t.debug_macinfo,\"\",%progbits"; |
| 136 | |
| 137 | if (Subtarget->isAAPCS_ABI()) { |
| 138 | StaticCtorsSection = "\t.section .init_array,\"aw\",%init_array"; |
| 139 | StaticDtorsSection = "\t.section .fini_array,\"aw\",%fini_array"; |
| 140 | } else { |
| 141 | StaticCtorsSection = "\t.section .ctors,\"aw\",%progbits"; |
| 142 | StaticDtorsSection = "\t.section .dtors,\"aw\",%progbits"; |
| 143 | } |
| 144 | TLSDataSection = "\t.section .tdata,\"awT\",%progbits"; |
| 145 | TLSBSSSection = "\t.section .tbss,\"awT\",%nobits"; |
| 146 | } |
| 147 | |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 148 | /// Count the number of comma-separated arguments. |
| 149 | /// Do not try to detect errors. |
| 150 | unsigned ARMTargetAsmInfo::countArguments(const char* p) const { |
| 151 | unsigned count = 0; |
| 152 | while (*p && isspace(*p) && *p != '\n') |
| 153 | p++; |
| 154 | count++; |
| 155 | while (*p && *p!='\n' && |
| 156 | strncmp(p, CommentString, strlen(CommentString))!=0) { |
| 157 | if (*p==',') |
| 158 | count++; |
| 159 | p++; |
| 160 | } |
| 161 | return count; |
| 162 | } |
| 163 | |
| 164 | /// Count the length of a string enclosed in quote characters. |
| 165 | /// Do not try to detect errors. |
| 166 | unsigned ARMTargetAsmInfo::countString(const char* p) const { |
| 167 | unsigned count = 0; |
| 168 | while (*p && isspace(*p) && *p!='\n') |
| 169 | p++; |
| 170 | if (!*p || *p != '\"') |
| 171 | return count; |
| 172 | while (*++p && *p != '\"') |
| 173 | count++; |
| 174 | return count; |
Jim Laskey | 8e8de8f | 2006-09-07 22:05:02 +0000 | [diff] [blame] | 175 | } |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 176 | |
| 177 | /// ARM-specific version of TargetAsmInfo::getInlineAsmLength. |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 178 | unsigned ARMTargetAsmInfo::getInlineAsmLength(const char *s) const { |
| 179 | // Make a lowercase-folded version of s for counting purposes. |
| 180 | char *q, *s_copy = (char *)malloc(strlen(s) + 1); |
| 181 | strcpy(s_copy, s); |
| 182 | for (q=s_copy; *q; q++) |
| 183 | *q = tolower(*q); |
| 184 | const char *Str = s_copy; |
| 185 | |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 186 | // Count the number of bytes in the asm. |
| 187 | bool atInsnStart = true; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 188 | bool inTextSection = true; |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 189 | unsigned Length = 0; |
| 190 | for (; *Str; ++Str) { |
| 191 | if (atInsnStart) { |
| 192 | // Skip whitespace |
| 193 | while (*Str && isspace(*Str) && *Str != '\n') |
| 194 | Str++; |
| 195 | // Skip label |
| 196 | for (const char* p = Str; *p && !isspace(*p); p++) |
| 197 | if (*p == ':') { |
| 198 | Str = p+1; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 199 | while (*Str && isspace(*Str) && *Str != '\n') |
| 200 | Str++; |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 201 | break; |
| 202 | } |
| 203 | // Ignore everything from comment char(s) to EOL |
| 204 | if (strncmp(Str, CommentString, strlen(CommentString))==-0) |
| 205 | atInsnStart = false; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 206 | // FIXME do something like the following for non-Darwin |
| 207 | else if (*Str == '.' && Subtarget->isTargetDarwin()) { |
| 208 | // Directive. |
| 209 | atInsnStart = false; |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 210 | |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 211 | // Some change the section, but don't generate code. |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 212 | if (strncmp(Str, ".literal4", strlen(".literal4"))==0 || |
| 213 | strncmp(Str, ".literal8", strlen(".literal8"))==0 || |
| 214 | strncmp(Str, ".const", strlen(".const"))==0 || |
| 215 | strncmp(Str, ".constructor", strlen(".constructor"))==0 || |
| 216 | strncmp(Str, ".cstring", strlen(".cstring"))==0 || |
| 217 | strncmp(Str, ".data", strlen(".data"))==0 || |
| 218 | strncmp(Str, ".destructor", strlen(".destructor"))==0 || |
| 219 | strncmp(Str, ".fvmlib_init0", strlen(".fvmlib_init0"))==0 || |
| 220 | strncmp(Str, ".fvmlib_init1", strlen(".fvmlib_init1"))==0 || |
| 221 | strncmp(Str, ".mod_init_func", strlen(".mod_init_func"))==0 || |
| 222 | strncmp(Str, ".mod_term_func", strlen(".mod_term_func"))==0 || |
| 223 | strncmp(Str, ".picsymbol_stub", strlen(".picsymbol_stub"))==0 || |
| 224 | strncmp(Str, ".symbol_stub", strlen(".symbol_stub"))==0 || |
| 225 | strncmp(Str, ".static_data", strlen(".static_data"))==0 || |
| 226 | strncmp(Str, ".section", strlen(".section"))==0 || |
| 227 | strncmp(Str, ".lazy_symbol_pointer", strlen(".lazy_symbol_pointer"))==0 || |
| 228 | strncmp(Str, ".non_lazy_symbol_pointer", strlen(".non_lazy_symbol_pointer"))==0 || |
| 229 | strncmp(Str, ".dyld", strlen(".dyld"))==0 || |
| 230 | strncmp(Str, ".const_data", strlen(".const_data"))==0 || |
| 231 | strncmp(Str, ".objc", strlen(".objc"))==0 || //// many directives |
| 232 | strncmp(Str, ".static_const", strlen(".static_const"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 233 | inTextSection=false; |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 234 | else if (strncmp(Str, ".text", strlen(".text"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 235 | inTextSection = true; |
| 236 | // Some can't really be handled without implementing significant pieces |
| 237 | // of an assembler. Others require dynamic adjustment of block sizes in |
| 238 | // AdjustBBOffsetsAfter; it's a big compile-time speed hit to check every |
| 239 | // instruction in there, and none of these are currently used in the kernel. |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 240 | else if (strncmp(Str, ".macro", strlen(".macro"))==0 || |
| 241 | strncmp(Str, ".if", strlen(".if"))==0 || |
| 242 | strncmp(Str, ".align", strlen(".align"))==0 || |
| 243 | strncmp(Str, ".fill", strlen(".fill"))==0 || |
| 244 | strncmp(Str, ".space", strlen(".space"))==0 || |
| 245 | strncmp(Str, ".zerofill", strlen(".zerofill"))==0 || |
| 246 | strncmp(Str, ".p2align", strlen(".p2align"))==0 || |
| 247 | strncmp(Str, ".p2alignw", strlen(".p2alignw"))==0 || |
| 248 | strncmp(Str, ".p2alignl", strlen(".p2alignl"))==0 || |
| 249 | strncmp(Str, ".align32", strlen(".p2align32"))==0 || |
| 250 | strncmp(Str, ".include", strlen(".include"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 251 | cerr << "Directive " << Str << " in asm may lead to invalid offsets for" << |
| 252 | " constant pools (the assembler will tell you if this happens).\n"; |
| 253 | // Some generate code, but this is only interesting in the text section. |
| 254 | else if (inTextSection) { |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 255 | if (strncmp(Str, ".long", strlen(".long"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 256 | Length += 4*countArguments(Str+strlen(".long")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 257 | else if (strncmp(Str, ".short", strlen(".short"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 258 | Length += 2*countArguments(Str+strlen(".short")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 259 | else if (strncmp(Str, ".byte", strlen(".byte"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 260 | Length += 1*countArguments(Str+strlen(".byte")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 261 | else if (strncmp(Str, ".single", strlen(".single"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 262 | Length += 4*countArguments(Str+strlen(".single")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 263 | else if (strncmp(Str, ".double", strlen(".double"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 264 | Length += 8*countArguments(Str+strlen(".double")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 265 | else if (strncmp(Str, ".quad", strlen(".quad"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 266 | Length += 16*countArguments(Str+strlen(".quad")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 267 | else if (strncmp(Str, ".ascii", strlen(".ascii"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 268 | Length += countString(Str+strlen(".ascii")); |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 269 | else if (strncmp(Str, ".asciz", strlen(".asciz"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 270 | Length += countString(Str+strlen(".asciz"))+1; |
| 271 | } |
| 272 | } else if (inTextSection) { |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 273 | // An instruction |
| 274 | atInsnStart = false; |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 275 | if (Subtarget->isThumb()) { |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 276 | // BL and BLX <non-reg> are 4 bytes, all others 2. |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 277 | if (strncmp(Str, "blx", strlen("blx"))==0) { |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 278 | const char* p = Str+3; |
| 279 | while (*p && isspace(*p)) |
| 280 | p++; |
| 281 | if (*p == 'r' || *p=='R') |
| 282 | Length += 2; // BLX reg |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 283 | else |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 284 | Length += 4; // BLX non-reg |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 285 | } else if (strncmp(Str, "bl", strlen("bl"))==0) |
Dale Johannesen | 67cf561 | 2007-05-02 01:02:40 +0000 | [diff] [blame] | 286 | Length += 4; // BL |
| 287 | else |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 288 | Length += 2; // Thumb anything else |
| 289 | } |
| 290 | else |
| 291 | Length += 4; // ARM |
| 292 | } |
| 293 | } |
| 294 | if (*Str == '\n' || *Str == SeparatorChar) |
| 295 | atInsnStart = true; |
| 296 | } |
Dale Johannesen | ca4571e | 2007-10-25 21:54:43 +0000 | [diff] [blame] | 297 | free(s_copy); |
Dale Johannesen | 8650199 | 2007-04-29 19:17:45 +0000 | [diff] [blame] | 298 | return Length; |
| 299 | } |