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