buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | namespace art { |
| 18 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 19 | void setMemRefType(LIR* lir, bool isLoad, int memType) |
| 20 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 21 | u8 *maskPtr; |
| 22 | u8 mask = ENCODE_MEM;; |
| 23 | DCHECK(EncodingMap[lir->opcode].flags & (IS_LOAD | IS_STORE)); |
| 24 | if (isLoad) { |
| 25 | maskPtr = &lir->useMask; |
| 26 | } else { |
| 27 | maskPtr = &lir->defMask; |
| 28 | } |
| 29 | /* Clear out the memref flags */ |
| 30 | *maskPtr &= ~mask; |
| 31 | /* ..and then add back the one we need */ |
| 32 | switch (memType) { |
| 33 | case kLiteral: |
| 34 | DCHECK(isLoad); |
| 35 | *maskPtr |= ENCODE_LITERAL; |
| 36 | break; |
| 37 | case kDalvikReg: |
| 38 | *maskPtr |= ENCODE_DALVIK_REG; |
| 39 | break; |
| 40 | case kHeapRef: |
| 41 | *maskPtr |= ENCODE_HEAP_REF; |
| 42 | break; |
| 43 | case kMustNotAlias: |
| 44 | /* Currently only loads can be marked as kMustNotAlias */ |
| 45 | DCHECK(!(EncodingMap[lir->opcode].flags & IS_STORE)); |
| 46 | *maskPtr |= ENCODE_MUST_NOT_ALIAS; |
| 47 | break; |
| 48 | default: |
| 49 | LOG(FATAL) << "Oat: invalid memref kind - " << memType; |
| 50 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | /* |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 54 | * Mark load/store instructions that access Dalvik registers through the stack. |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 55 | */ |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 56 | void annotateDalvikRegAccess(LIR* lir, int regId, bool isLoad, bool is64bit) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 57 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 58 | setMemRefType(lir, isLoad, kDalvikReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 59 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 60 | /* |
| 61 | * Store the Dalvik register id in aliasInfo. Mark the MSB if it is a 64-bit |
| 62 | * access. |
| 63 | */ |
| 64 | lir->aliasInfo = regId; |
| 65 | if (is64bit) { |
| 66 | lir->aliasInfo |= 0x80000000; |
| 67 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | /* |
| 71 | * Decode the register id. |
| 72 | */ |
| 73 | inline u8 getRegMaskCommon(int reg) |
| 74 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 75 | u8 seed; |
| 76 | int shift; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 77 | |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 78 | #if defined(TARGET_X86) |
jeffhao | 854029c | 2012-07-23 17:31:30 -0700 | [diff] [blame] | 79 | int regId = reg & 0xf; |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 80 | /* |
| 81 | * Double registers in x86 are just a single FP register |
| 82 | */ |
| 83 | seed = 1; |
| 84 | #else |
jeffhao | 854029c | 2012-07-23 17:31:30 -0700 | [diff] [blame] | 85 | int regId = reg & 0x1f; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 86 | /* |
| 87 | * Each double register is equal to a pair of single-precision FP registers |
| 88 | */ |
| 89 | seed = DOUBLEREG(reg) ? 3 : 1; |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 90 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 91 | /* FP register starts at bit position 16 */ |
| 92 | shift = FPREG(reg) ? kFPReg0 : 0; |
| 93 | /* Expand the double register id into single offset */ |
| 94 | shift += regId; |
| 95 | return (seed << shift); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Mark the corresponding bit(s). |
| 100 | */ |
| 101 | inline void setupRegMask(u8* mask, int reg) |
| 102 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 103 | *mask |= getRegMaskCommon(reg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* |
| 107 | * Set up the proper fields in the resource mask |
| 108 | */ |
| 109 | void setupResourceMasks(LIR* lir) |
| 110 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 111 | int opcode = lir->opcode; |
| 112 | int flags; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 113 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 114 | if (opcode <= 0) { |
| 115 | lir->useMask = lir->defMask = 0; |
| 116 | return; |
| 117 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 118 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 119 | flags = EncodingMap[lir->opcode].flags; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 120 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 121 | if (flags & NEEDS_FIXUP) { |
| 122 | lir->flags.pcRelFixup = true; |
| 123 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 124 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 125 | /* Get the starting size of the instruction's template */ |
| 126 | lir->flags.size = oatGetInsnSize(lir); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 127 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 128 | /* Set up the mask for resources that are updated */ |
| 129 | if (flags & (IS_LOAD | IS_STORE)) { |
| 130 | /* Default to heap - will catch specialized classes later */ |
| 131 | setMemRefType(lir, flags & IS_LOAD, kHeapRef); |
| 132 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 133 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 134 | /* |
| 135 | * Conservatively assume the branch here will call out a function that in |
| 136 | * turn will trash everything. |
| 137 | */ |
| 138 | if (flags & IS_BRANCH) { |
| 139 | lir->defMask = lir->useMask = ENCODE_ALL; |
| 140 | return; |
| 141 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 142 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 143 | if (flags & REG_DEF0) { |
| 144 | setupRegMask(&lir->defMask, lir->operands[0]); |
| 145 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 146 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 147 | if (flags & REG_DEF1) { |
| 148 | setupRegMask(&lir->defMask, lir->operands[1]); |
| 149 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 150 | |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 151 | #if defined(TARGET_X86) |
| 152 | if (flags & REG_DEFA) { |
| 153 | setupRegMask(&lir->defMask, rAX); |
| 154 | } |
| 155 | |
| 156 | if (flags & REG_DEFD) { |
| 157 | setupRegMask(&lir->defMask, rDX); |
| 158 | } |
| 159 | #endif |
| 160 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 161 | if (flags & REG_DEF_SP) { |
| 162 | lir->defMask |= ENCODE_REG_SP; |
| 163 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 164 | |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 165 | #if !defined(TARGET_X86) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 166 | if (flags & REG_DEF_LR) { |
| 167 | lir->defMask |= ENCODE_REG_LR; |
| 168 | } |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 169 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 170 | |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 171 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 172 | if (flags & REG_DEF_LIST0) { |
| 173 | lir->defMask |= ENCODE_REG_LIST(lir->operands[0]); |
| 174 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 175 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 176 | if (flags & REG_DEF_LIST1) { |
| 177 | lir->defMask |= ENCODE_REG_LIST(lir->operands[1]); |
| 178 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 179 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 180 | if (flags & REG_DEF_FPCS_LIST0) { |
| 181 | lir->defMask |= ENCODE_REG_FPCS_LIST(lir->operands[0]); |
| 182 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 183 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 184 | if (flags & REG_DEF_FPCS_LIST2) { |
| 185 | for (int i = 0; i < lir->operands[2]; i++) { |
| 186 | setupRegMask(&lir->defMask, lir->operands[1] + i); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 187 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 188 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 189 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 190 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 191 | if (flags & SETS_CCODES) { |
| 192 | lir->defMask |= ENCODE_CCODE; |
| 193 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 194 | |
| 195 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 196 | /* Conservatively treat the IT block */ |
| 197 | if (flags & IS_IT) { |
| 198 | lir->defMask = ENCODE_ALL; |
| 199 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 200 | #endif |
| 201 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 202 | if (flags & (REG_USE0 | REG_USE1 | REG_USE2 | REG_USE3)) { |
| 203 | int i; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 204 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 205 | for (i = 0; i < 4; i++) { |
| 206 | if (flags & (1 << (kRegUse0 + i))) { |
| 207 | setupRegMask(&lir->useMask, lir->operands[i]); |
| 208 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 209 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 210 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 211 | |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 212 | #if defined(TARGET_X86) |
| 213 | if (flags & REG_USEA) { |
| 214 | setupRegMask(&lir->useMask, rAX); |
| 215 | } |
| 216 | |
| 217 | if (flags & REG_USEC) { |
| 218 | setupRegMask(&lir->useMask, rCX); |
| 219 | } |
| 220 | |
| 221 | if (flags & REG_USED) { |
| 222 | setupRegMask(&lir->useMask, rDX); |
| 223 | } |
| 224 | #endif |
| 225 | |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 226 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 227 | if (flags & REG_USE_PC) { |
| 228 | lir->useMask |= ENCODE_REG_PC; |
| 229 | } |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 230 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 231 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 232 | if (flags & REG_USE_SP) { |
| 233 | lir->useMask |= ENCODE_REG_SP; |
| 234 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 235 | |
jeffhao | e296248 | 2012-06-28 11:29:57 -0700 | [diff] [blame] | 236 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 237 | if (flags & REG_USE_LIST0) { |
| 238 | lir->useMask |= ENCODE_REG_LIST(lir->operands[0]); |
| 239 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 240 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 241 | if (flags & REG_USE_LIST1) { |
| 242 | lir->useMask |= ENCODE_REG_LIST(lir->operands[1]); |
| 243 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 244 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 245 | if (flags & REG_USE_FPCS_LIST0) { |
| 246 | lir->useMask |= ENCODE_REG_FPCS_LIST(lir->operands[0]); |
| 247 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 248 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 249 | if (flags & REG_USE_FPCS_LIST2) { |
| 250 | for (int i = 0; i < lir->operands[2]; i++) { |
| 251 | setupRegMask(&lir->useMask, lir->operands[1] + i); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 252 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 253 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 254 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 255 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 256 | if (flags & USES_CCODES) { |
| 257 | lir->useMask |= ENCODE_CCODE; |
| 258 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 259 | |
| 260 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 261 | /* Fixup for kThumbPush/lr and kThumbPop/pc */ |
| 262 | if (opcode == kThumbPush || opcode == kThumbPop) { |
| 263 | u8 r8Mask = getRegMaskCommon(r8); |
| 264 | if ((opcode == kThumbPush) && (lir->useMask & r8Mask)) { |
| 265 | lir->useMask &= ~r8Mask; |
| 266 | lir->useMask |= ENCODE_REG_LR; |
| 267 | } else if ((opcode == kThumbPop) && (lir->defMask & r8Mask)) { |
| 268 | lir->defMask &= ~r8Mask; |
| 269 | lir->defMask |= ENCODE_REG_PC; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 270 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 271 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 272 | #endif |
| 273 | } |
| 274 | |
| 275 | /* |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 276 | * Debugging macros |
| 277 | */ |
| 278 | #define DUMP_RESOURCE_MASK(X) |
| 279 | #define DUMP_SSA_REP(X) |
| 280 | |
| 281 | /* Pretty-print a LIR instruction */ |
| 282 | void oatDumpLIRInsn(CompilationUnit* cUnit, LIR* arg, unsigned char* baseAddr) |
| 283 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 284 | LIR* lir = (LIR*) arg; |
| 285 | int offset = lir->offset; |
| 286 | int dest = lir->operands[0]; |
| 287 | const bool dumpNop = (cUnit->enableDebug & (1 << kDebugShowNops)); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 288 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 289 | /* Handle pseudo-ops individually, and all regular insns as a group */ |
| 290 | switch (lir->opcode) { |
| 291 | case kPseudoMethodEntry: |
| 292 | LOG(INFO) << "-------- method entry " |
| 293 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file); |
| 294 | break; |
| 295 | case kPseudoMethodExit: |
| 296 | LOG(INFO) << "-------- Method_Exit"; |
| 297 | break; |
| 298 | case kPseudoBarrier: |
| 299 | LOG(INFO) << "-------- BARRIER"; |
| 300 | break; |
| 301 | case kPseudoExtended: |
| 302 | LOG(INFO) << "-------- " << (char* ) dest; |
| 303 | break; |
| 304 | case kPseudoSSARep: |
| 305 | DUMP_SSA_REP(LOG(INFO) << "-------- kMirOpPhi: " << (char* ) dest); |
| 306 | break; |
| 307 | case kPseudoEntryBlock: |
| 308 | LOG(INFO) << "-------- entry offset: 0x" << std::hex << dest; |
| 309 | break; |
| 310 | case kPseudoDalvikByteCodeBoundary: |
| 311 | LOG(INFO) << "-------- dalvik offset: 0x" << std::hex |
| 312 | << lir->dalvikOffset << " @ " << (char* )lir->operands[0]; |
| 313 | break; |
| 314 | case kPseudoExitBlock: |
| 315 | LOG(INFO) << "-------- exit offset: 0x" << std::hex << dest; |
| 316 | break; |
| 317 | case kPseudoPseudoAlign4: |
| 318 | LOG(INFO) << (intptr_t)baseAddr + offset << " (0x" << std::hex |
| 319 | << offset << "): .align4"; |
| 320 | break; |
| 321 | case kPseudoEHBlockLabel: |
| 322 | LOG(INFO) << "Exception_Handling:"; |
| 323 | break; |
| 324 | case kPseudoTargetLabel: |
| 325 | case kPseudoNormalBlockLabel: |
| 326 | LOG(INFO) << "L" << (void*)lir << ":"; |
| 327 | break; |
| 328 | case kPseudoThrowTarget: |
| 329 | LOG(INFO) << "LT" << (void*)lir << ":"; |
| 330 | break; |
| 331 | case kPseudoIntrinsicRetry: |
| 332 | LOG(INFO) << "IR" << (void*)lir << ":"; |
| 333 | break; |
| 334 | case kPseudoSuspendTarget: |
| 335 | LOG(INFO) << "LS" << (void*)lir << ":"; |
| 336 | break; |
| 337 | case kPseudoCaseLabel: |
| 338 | LOG(INFO) << "LC" << (void*)lir << ": Case target 0x" |
| 339 | << std::hex << lir->operands[0] << "|" << std::dec << |
| 340 | lir->operands[0]; |
| 341 | break; |
| 342 | default: |
| 343 | if (lir->flags.isNop && !dumpNop) { |
| 344 | break; |
| 345 | } else { |
| 346 | std::string op_name(buildInsnString(EncodingMap[lir->opcode].name, |
| 347 | lir, baseAddr)); |
| 348 | std::string op_operands(buildInsnString(EncodingMap[lir->opcode].fmt |
| 349 | , lir, baseAddr)); |
| 350 | LOG(INFO) << StringPrintf("%05x: %-9s%s%s", |
| 351 | (unsigned int)(baseAddr + offset), |
| 352 | op_name.c_str(), op_operands.c_str(), |
| 353 | lir->flags.isNop ? "(nop)" : ""); |
| 354 | } |
| 355 | break; |
| 356 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 357 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 358 | if (lir->useMask && (!lir->flags.isNop || dumpNop)) { |
| 359 | DUMP_RESOURCE_MASK(oatDumpResourceMask((LIR* ) lir, lir->useMask, "use")); |
| 360 | } |
| 361 | if (lir->defMask && (!lir->flags.isNop || dumpNop)) { |
| 362 | DUMP_RESOURCE_MASK(oatDumpResourceMask((LIR* ) lir, lir->defMask, "def")); |
| 363 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void oatDumpPromotionMap(CompilationUnit *cUnit) |
| 367 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 368 | int numRegs = cUnit->numDalvikRegisters + cUnit->numCompilerTemps + 1; |
| 369 | for (int i = 0; i < numRegs; i++) { |
| 370 | PromotionMap vRegMap = cUnit->promotionMap[i]; |
| 371 | std::string buf; |
| 372 | if (vRegMap.fpLocation == kLocPhysReg) { |
| 373 | StringAppendF(&buf, " : s%d", vRegMap.fpReg & FP_REG_MASK); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 374 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 375 | |
| 376 | std::string buf3; |
| 377 | if (i < cUnit->numDalvikRegisters) { |
| 378 | StringAppendF(&buf3, "%02d", i); |
| 379 | } else if (i == cUnit->methodSReg) { |
| 380 | buf3 = "Method*"; |
| 381 | } else { |
| 382 | StringAppendF(&buf3, "ct%d", i - cUnit->numDalvikRegisters); |
| 383 | } |
| 384 | |
| 385 | LOG(INFO) << StringPrintf("V[%s] -> %s%d%s", buf3.c_str(), |
| 386 | vRegMap.coreLocation == kLocPhysReg ? |
| 387 | "r" : "SP+", vRegMap.coreLocation == kLocPhysReg ? |
| 388 | vRegMap.coreReg : oatSRegOffset(cUnit, i), |
| 389 | buf.c_str()); |
| 390 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 391 | } |
| 392 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 393 | /* Dump instructions and constant pool contents */ |
| 394 | void oatCodegenDump(CompilationUnit* cUnit) |
| 395 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 396 | LOG(INFO) << "Dumping LIR insns for " |
| 397 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file); |
| 398 | LIR* lirInsn; |
| 399 | LIR* thisLIR; |
| 400 | int insnsSize = cUnit->insnsSize; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 401 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 402 | LOG(INFO) << "Regs (excluding ins) : " << cUnit->numRegs; |
| 403 | LOG(INFO) << "Ins : " << cUnit->numIns; |
| 404 | LOG(INFO) << "Outs : " << cUnit->numOuts; |
| 405 | LOG(INFO) << "CoreSpills : " << cUnit->numCoreSpills; |
| 406 | LOG(INFO) << "FPSpills : " << cUnit->numFPSpills; |
| 407 | LOG(INFO) << "CompilerTemps : " << cUnit->numCompilerTemps; |
| 408 | LOG(INFO) << "Frame size : " << cUnit->frameSize; |
| 409 | LOG(INFO) << "code size is " << cUnit->totalSize << |
| 410 | " bytes, Dalvik size is " << insnsSize * 2; |
| 411 | LOG(INFO) << "expansion factor: " |
| 412 | << (float)cUnit->totalSize / (float)(insnsSize * 2); |
| 413 | oatDumpPromotionMap(cUnit); |
| 414 | for (lirInsn = cUnit->firstLIRInsn; lirInsn; lirInsn = lirInsn->next) { |
| 415 | oatDumpLIRInsn(cUnit, lirInsn, 0); |
| 416 | } |
| 417 | for (lirInsn = cUnit->classPointerList; lirInsn; lirInsn = lirInsn->next) { |
| 418 | thisLIR = (LIR*) lirInsn; |
| 419 | LOG(INFO) << StringPrintf("%x (%04x): .class (%s)", |
| 420 | thisLIR->offset, thisLIR->offset, |
| 421 | ((CallsiteInfo *) |
| 422 | thisLIR->operands[0])->classDescriptor); |
| 423 | } |
| 424 | for (lirInsn = cUnit->literalList; lirInsn; lirInsn = lirInsn->next) { |
| 425 | thisLIR = (LIR*) lirInsn; |
| 426 | LOG(INFO) << StringPrintf("%x (%04x): .word (%#x)", |
| 427 | thisLIR->offset, thisLIR->offset, |
| 428 | thisLIR->operands[0]); |
| 429 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 430 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 431 | const DexFile::MethodId& method_id = |
| 432 | cUnit->dex_file->GetMethodId(cUnit->method_idx); |
| 433 | std::string signature(cUnit->dex_file->GetMethodSignature(method_id)); |
| 434 | std::string name(cUnit->dex_file->GetMethodName(method_id)); |
| 435 | std::string descriptor(cUnit->dex_file->GetMethodDeclaringClassDescriptor(method_id)); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 436 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 437 | // Dump mapping table |
| 438 | if (cUnit->mappingTable.size() > 0) { |
| 439 | std::string |
| 440 | line(StringPrintf("\n MappingTable %s%s_%s_mappingTable[%zu] = {", |
| 441 | descriptor.c_str(), name.c_str(), signature.c_str(), |
| 442 | cUnit->mappingTable.size())); |
| 443 | std::replace(line.begin(), line.end(), ';', '_'); |
| 444 | LOG(INFO) << line; |
| 445 | for (uint32_t i = 0; i < cUnit->mappingTable.size(); i+=2) { |
| 446 | line = StringPrintf(" {0x%05x, 0x%04x},", |
| 447 | cUnit->mappingTable[i], cUnit->mappingTable[i+1]); |
| 448 | LOG(INFO) << line; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 449 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 450 | LOG(INFO) <<" };\n\n"; |
| 451 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 452 | } |
| 453 | |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 454 | |
| 455 | LIR* rawLIR(CompilationUnit* cUnit, int dalvikOffset, int opcode, int op0, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 456 | int op1, int op2, int op3, int op4, LIR* target) |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 457 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 458 | LIR* insn = (LIR* ) oatNew(cUnit, sizeof(LIR), true, kAllocLIR); |
| 459 | insn->dalvikOffset = dalvikOffset; |
| 460 | insn->opcode = opcode; |
| 461 | insn->operands[0] = op0; |
| 462 | insn->operands[1] = op1; |
| 463 | insn->operands[2] = op2; |
| 464 | insn->operands[3] = op3; |
| 465 | insn->operands[4] = op4; |
| 466 | insn->target = target; |
| 467 | oatSetupResourceMasks(insn); |
| 468 | if (opcode == kPseudoTargetLabel) { |
| 469 | // Always make labels scheduling barriers |
| 470 | insn->defMask = ENCODE_ALL; |
| 471 | } |
| 472 | return insn; |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 473 | } |
| 474 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 475 | /* |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 476 | * The following are building blocks to construct low-level IRs with 0 - 4 |
| 477 | * operands. |
| 478 | */ |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 479 | LIR* newLIR0(CompilationUnit* cUnit, int opcode) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 480 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 481 | DCHECK(isPseudoOpcode(opcode) || (EncodingMap[opcode].flags & NO_OPERAND)) |
| 482 | << EncodingMap[opcode].name << " " << (int)opcode << " " |
| 483 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " " |
| 484 | << cUnit->currentDalvikOffset; |
| 485 | LIR* insn = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode); |
| 486 | oatAppendLIR(cUnit, (LIR*) insn); |
| 487 | return insn; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 488 | } |
| 489 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 490 | LIR* newLIR1(CompilationUnit* cUnit, int opcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 491 | int dest) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 492 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 493 | DCHECK(isPseudoOpcode(opcode) || (EncodingMap[opcode].flags & IS_UNARY_OP)) |
| 494 | << EncodingMap[opcode].name << " " << (int)opcode << " " |
| 495 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " " |
| 496 | << cUnit->currentDalvikOffset; |
| 497 | LIR* insn = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode, dest); |
| 498 | oatAppendLIR(cUnit, (LIR*) insn); |
| 499 | return insn; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 500 | } |
| 501 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 502 | LIR* newLIR2(CompilationUnit* cUnit, int opcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 503 | int dest, int src1) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 504 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 505 | DCHECK(isPseudoOpcode(opcode) || (EncodingMap[opcode].flags & IS_BINARY_OP)) |
| 506 | << EncodingMap[opcode].name << " " << (int)opcode << " " |
| 507 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " " |
| 508 | << cUnit->currentDalvikOffset; |
| 509 | LIR* insn = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode, dest, src1); |
| 510 | oatAppendLIR(cUnit, (LIR*) insn); |
| 511 | return insn; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 512 | } |
| 513 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 514 | LIR* newLIR3(CompilationUnit* cUnit, int opcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 515 | int dest, int src1, int src2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 516 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 517 | DCHECK(isPseudoOpcode(opcode) || (EncodingMap[opcode].flags & IS_TERTIARY_OP)) |
| 518 | << EncodingMap[opcode].name << " " << (int)opcode << " " |
| 519 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " " |
| 520 | << cUnit->currentDalvikOffset; |
| 521 | LIR* insn = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode, dest, src1, |
| 522 | src2); |
| 523 | oatAppendLIR(cUnit, (LIR*) insn); |
| 524 | return insn; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 525 | } |
| 526 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 527 | LIR* newLIR4(CompilationUnit* cUnit, int opcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 528 | int dest, int src1, int src2, int info) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 529 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 530 | DCHECK(isPseudoOpcode(opcode) || (EncodingMap[opcode].flags & IS_QUAD_OP)) |
| 531 | << EncodingMap[opcode].name << " " << (int)opcode << " " |
| 532 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " " |
| 533 | << cUnit->currentDalvikOffset; |
| 534 | LIR* insn = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode, dest, src1, |
| 535 | src2, info); |
| 536 | oatAppendLIR(cUnit, (LIR*) insn); |
| 537 | return insn; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 538 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 539 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 540 | LIR* newLIR5(CompilationUnit* cUnit, int opcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 541 | int dest, int src1, int src2, int info1, int info2) |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 542 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 543 | DCHECK(isPseudoOpcode(opcode) || (EncodingMap[opcode].flags & IS_QUIN_OP)) |
| 544 | << EncodingMap[opcode].name << " " << (int)opcode << " " |
| 545 | << PrettyMethod(cUnit->method_idx, *cUnit->dex_file) << " " |
| 546 | << cUnit->currentDalvikOffset; |
| 547 | LIR* insn = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode, dest, src1, |
| 548 | src2, info1, info2); |
| 549 | oatAppendLIR(cUnit, (LIR*) insn); |
| 550 | return insn; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 551 | } |
| 552 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 553 | /* |
| 554 | * Search the existing constants in the literal pool for an exact or close match |
| 555 | * within specified delta (greater or equal to 0). |
| 556 | */ |
| 557 | LIR* scanLiteralPool(LIR* dataTarget, int value, unsigned int delta) |
| 558 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 559 | while (dataTarget) { |
| 560 | if (((unsigned) (value - ((LIR* ) dataTarget)->operands[0])) <= delta) |
| 561 | return (LIR* ) dataTarget; |
| 562 | dataTarget = dataTarget->next; |
| 563 | } |
| 564 | return NULL; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | /* Search the existing constants in the literal pool for an exact wide match */ |
| 568 | LIR* scanLiteralPoolWide(LIR* dataTarget, int valLo, int valHi) |
| 569 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 570 | bool loMatch = false; |
| 571 | LIR* loTarget = NULL; |
| 572 | while (dataTarget) { |
| 573 | if (loMatch && (((LIR*)dataTarget)->operands[0] == valHi)) { |
| 574 | return (LIR*)loTarget; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 575 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 576 | loMatch = false; |
| 577 | if (((LIR*)dataTarget)->operands[0] == valLo) { |
| 578 | loMatch = true; |
| 579 | loTarget = dataTarget; |
| 580 | } |
| 581 | dataTarget = dataTarget->next; |
| 582 | } |
| 583 | return NULL; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | /* |
| 587 | * The following are building blocks to insert constants into the pool or |
| 588 | * instruction streams. |
| 589 | */ |
| 590 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 591 | /* Add a 32-bit constant either in the constant pool */ |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 592 | LIR* addWordData(CompilationUnit* cUnit, LIR* *constantListP, int value) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 593 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 594 | /* Add the constant to the literal pool */ |
| 595 | if (constantListP) { |
| 596 | LIR* newValue = (LIR* ) oatNew(cUnit, sizeof(LIR), true, kAllocData); |
| 597 | newValue->operands[0] = value; |
| 598 | newValue->next = *constantListP; |
| 599 | *constantListP = (LIR*) newValue; |
| 600 | return newValue; |
| 601 | } |
| 602 | return NULL; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | /* Add a 64-bit constant to the constant pool or mixed with code */ |
| 606 | LIR* addWideData(CompilationUnit* cUnit, LIR* *constantListP, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 607 | int valLo, int valHi) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 608 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 609 | //FIXME: hard-coded little endian, need BE variant |
| 610 | // Insert high word into list first |
| 611 | addWordData(cUnit, constantListP, valHi); |
| 612 | return addWordData(cUnit, constantListP, valLo); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 613 | } |
| 614 | |
Ian Rogers | ab058bb | 2012-03-11 22:19:38 -0700 | [diff] [blame] | 615 | void pushWord(std::vector<uint8_t>&buf, int data) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 616 | buf.push_back( data & 0xff); |
| 617 | buf.push_back( (data >> 8) & 0xff); |
| 618 | buf.push_back( (data >> 16) & 0xff); |
| 619 | buf.push_back( (data >> 24) & 0xff); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 620 | } |
| 621 | |
Ian Rogers | ab058bb | 2012-03-11 22:19:38 -0700 | [diff] [blame] | 622 | void alignBuffer(std::vector<uint8_t>&buf, size_t offset) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 623 | while (buf.size() < offset) { |
| 624 | buf.push_back(0); |
| 625 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 626 | } |
| 627 | |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 628 | bool IsDirect(int invokeType) { |
| 629 | InvokeType type = static_cast<InvokeType>(invokeType); |
| 630 | return type == kStatic || type == kDirect; |
| 631 | } |
| 632 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 633 | /* Write the literal pool to the output stream */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 634 | void installLiteralPools(CompilationUnit* cUnit) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 635 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 636 | alignBuffer(cUnit->codeBuffer, cUnit->dataOffset); |
| 637 | LIR* dataLIR = cUnit->literalList; |
| 638 | while (dataLIR != NULL) { |
| 639 | pushWord(cUnit->codeBuffer, dataLIR->operands[0]); |
| 640 | dataLIR = NEXT_LIR(dataLIR); |
| 641 | } |
| 642 | // Push code and method literals, record offsets for the compiler to patch. |
| 643 | dataLIR = cUnit->codeLiteralList; |
| 644 | if (dataLIR != NULL) { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 645 | while (dataLIR != NULL) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 646 | uint32_t target = dataLIR->operands[0]; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 647 | cUnit->compiler->AddCodePatch(cUnit->dex_file, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 648 | cUnit->method_idx, |
| 649 | cUnit->access_flags, |
| 650 | target, |
| 651 | IsDirect(dataLIR->operands[1]), |
| 652 | cUnit->codeBuffer.size()); |
| 653 | const DexFile::MethodId& id = cUnit->dex_file->GetMethodId(target); |
| 654 | // unique based on target to ensure code deduplication works |
| 655 | uint32_t unique_patch_value = reinterpret_cast<uint32_t>(&id); |
| 656 | pushWord(cUnit->codeBuffer, unique_patch_value); |
| 657 | dataLIR = NEXT_LIR(dataLIR); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 658 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 659 | dataLIR = cUnit->methodLiteralList; |
| 660 | while (dataLIR != NULL) { |
| 661 | uint32_t target = dataLIR->operands[0]; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame^] | 662 | cUnit->compiler->AddMethodPatch(cUnit->dex_file, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 663 | cUnit->method_idx, |
| 664 | cUnit->access_flags, |
| 665 | target, |
| 666 | IsDirect(dataLIR->operands[1]), |
| 667 | cUnit->codeBuffer.size()); |
| 668 | const DexFile::MethodId& id = cUnit->dex_file->GetMethodId(target); |
| 669 | // unique based on target to ensure code deduplication works |
| 670 | uint32_t unique_patch_value = reinterpret_cast<uint32_t>(&id); |
| 671 | pushWord(cUnit->codeBuffer, unique_patch_value); |
| 672 | dataLIR = NEXT_LIR(dataLIR); |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 673 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 674 | } |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 675 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | /* Write the switch tables to the output stream */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 679 | void installSwitchTables(CompilationUnit* cUnit) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 680 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 681 | GrowableListIterator iterator; |
| 682 | oatGrowableListIteratorInit(&cUnit->switchTables, &iterator); |
| 683 | while (true) { |
| 684 | SwitchTable* tabRec = (SwitchTable *) oatGrowableListIteratorNext( |
| 685 | &iterator); |
| 686 | if (tabRec == NULL) break; |
| 687 | alignBuffer(cUnit->codeBuffer, tabRec->offset); |
| 688 | /* |
| 689 | * For Arm, our reference point is the address of the bx |
| 690 | * instruction that does the launch, so we have to subtract |
| 691 | * the auto pc-advance. For other targets the reference point |
| 692 | * is a label, so we can use the offset as-is. |
| 693 | */ |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 694 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 695 | int bxOffset = tabRec->anchor->offset + 4; |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 696 | #elif defined(TARGET_X86) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 697 | int bxOffset = 0; |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 698 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 699 | int bxOffset = tabRec->anchor->offset; |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 700 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 701 | if (cUnit->printMe) { |
| 702 | LOG(INFO) << "Switch table for offset 0x" << std::hex << bxOffset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 703 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 704 | if (tabRec->table[0] == Instruction::kSparseSwitchSignature) { |
| 705 | int* keys = (int*)&(tabRec->table[2]); |
| 706 | for (int elems = 0; elems < tabRec->table[1]; elems++) { |
| 707 | int disp = tabRec->targets[elems]->offset - bxOffset; |
| 708 | if (cUnit->printMe) { |
| 709 | LOG(INFO) << " Case[" << elems << "] key: 0x" |
| 710 | << std::hex << keys[elems] << ", disp: 0x" |
| 711 | << std::hex << disp; |
| 712 | } |
| 713 | pushWord(cUnit->codeBuffer, keys[elems]); |
| 714 | pushWord(cUnit->codeBuffer, |
| 715 | tabRec->targets[elems]->offset - bxOffset); |
| 716 | } |
| 717 | } else { |
| 718 | DCHECK_EQ(static_cast<int>(tabRec->table[0]), |
| 719 | static_cast<int>(Instruction::kPackedSwitchSignature)); |
| 720 | for (int elems = 0; elems < tabRec->table[1]; elems++) { |
| 721 | int disp = tabRec->targets[elems]->offset - bxOffset; |
| 722 | if (cUnit->printMe) { |
| 723 | LOG(INFO) << " Case[" << elems << "] disp: 0x" |
| 724 | << std::hex << disp; |
| 725 | } |
| 726 | pushWord(cUnit->codeBuffer, tabRec->targets[elems]->offset - bxOffset); |
| 727 | } |
| 728 | } |
| 729 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* Write the fill array dta to the output stream */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 733 | void installFillArrayData(CompilationUnit* cUnit) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 734 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 735 | GrowableListIterator iterator; |
| 736 | oatGrowableListIteratorInit(&cUnit->fillArrayData, &iterator); |
| 737 | while (true) { |
| 738 | FillArrayData *tabRec = (FillArrayData *) oatGrowableListIteratorNext( |
| 739 | &iterator); |
| 740 | if (tabRec == NULL) break; |
| 741 | alignBuffer(cUnit->codeBuffer, tabRec->offset); |
| 742 | for (int i = 0; i < (tabRec->size + 1) / 2; i++) { |
| 743 | cUnit->codeBuffer.push_back( tabRec->table[i] & 0xFF); |
| 744 | cUnit->codeBuffer.push_back( (tabRec->table[i] >> 8) & 0xFF); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 745 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 746 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 747 | } |
| 748 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 749 | int assignLiteralOffsetCommon(LIR* lir, int offset) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 750 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 751 | for (;lir != NULL; lir = lir->next) { |
| 752 | lir->offset = offset; |
| 753 | offset += 4; |
| 754 | } |
| 755 | return offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 756 | } |
| 757 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 758 | void createMappingTable(CompilationUnit* cUnit) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 759 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 760 | LIR* tgtLIR; |
| 761 | int currentDalvikOffset = -1; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 762 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 763 | for (tgtLIR = (LIR *) cUnit->firstLIRInsn; |
| 764 | tgtLIR; |
| 765 | tgtLIR = NEXT_LIR(tgtLIR)) { |
| 766 | if ((tgtLIR->opcode >= 0) && !tgtLIR->flags.isNop && |
| 767 | (currentDalvikOffset != tgtLIR->dalvikOffset)) { |
| 768 | // Changed - need to emit a record |
| 769 | cUnit->mappingTable.push_back(tgtLIR->offset); |
| 770 | cUnit->mappingTable.push_back(tgtLIR->dalvikOffset); |
| 771 | currentDalvikOffset = tgtLIR->dalvikOffset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 772 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 773 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | /* Determine the offset of each literal field */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 777 | int assignLiteralOffset(CompilationUnit* cUnit, int offset) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 778 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 779 | offset = assignLiteralOffsetCommon(cUnit->literalList, offset); |
| 780 | offset = assignLiteralOffsetCommon(cUnit->codeLiteralList, offset); |
| 781 | offset = assignLiteralOffsetCommon(cUnit->methodLiteralList, offset); |
| 782 | return offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 783 | } |
| 784 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 785 | int assignSwitchTablesOffset(CompilationUnit* cUnit, int offset) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 786 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 787 | GrowableListIterator iterator; |
| 788 | oatGrowableListIteratorInit(&cUnit->switchTables, &iterator); |
| 789 | while (true) { |
| 790 | SwitchTable *tabRec = (SwitchTable *) oatGrowableListIteratorNext( |
| 791 | &iterator); |
| 792 | if (tabRec == NULL) break; |
| 793 | tabRec->offset = offset; |
| 794 | if (tabRec->table[0] == Instruction::kSparseSwitchSignature) { |
| 795 | offset += tabRec->table[1] * (sizeof(int) * 2); |
| 796 | } else { |
| 797 | DCHECK_EQ(static_cast<int>(tabRec->table[0]), |
| 798 | static_cast<int>(Instruction::kPackedSwitchSignature)); |
| 799 | offset += tabRec->table[1] * sizeof(int); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 800 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 801 | } |
| 802 | return offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 803 | } |
| 804 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 805 | int assignFillArrayDataOffset(CompilationUnit* cUnit, int offset) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 806 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 807 | GrowableListIterator iterator; |
| 808 | oatGrowableListIteratorInit(&cUnit->fillArrayData, &iterator); |
| 809 | while (true) { |
| 810 | FillArrayData *tabRec = (FillArrayData *) oatGrowableListIteratorNext( |
| 811 | &iterator); |
| 812 | if (tabRec == NULL) break; |
| 813 | tabRec->offset = offset; |
| 814 | offset += tabRec->size; |
| 815 | // word align |
| 816 | offset = (offset + 3) & ~3; |
| 817 | } |
| 818 | return offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | /* |
| 822 | * Walk the compilation unit and assign offsets to instructions |
| 823 | * and literals and compute the total size of the compiled unit. |
| 824 | */ |
| 825 | void oatAssignOffsets(CompilationUnit* cUnit) |
| 826 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 827 | int offset = oatAssignInsnOffsets(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 828 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 829 | /* Const values have to be word aligned */ |
| 830 | offset = (offset + 3) & ~3; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 831 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 832 | /* Set up offsets for literals */ |
| 833 | cUnit->dataOffset = offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 834 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 835 | offset = assignLiteralOffset(cUnit, offset); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 836 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 837 | offset = assignSwitchTablesOffset(cUnit, offset); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 838 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 839 | offset = assignFillArrayDataOffset(cUnit, offset); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 840 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 841 | cUnit->totalSize = offset; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | /* |
| 845 | * Go over each instruction in the list and calculate the offset from the top |
| 846 | * before sending them off to the assembler. If out-of-range branch distance is |
| 847 | * seen rearrange the instructions a bit to correct it. |
| 848 | */ |
| 849 | void oatAssembleLIR(CompilationUnit* cUnit) |
| 850 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 851 | oatAssignOffsets(cUnit); |
| 852 | /* |
| 853 | * Assemble here. Note that we generate code with optimistic assumptions |
| 854 | * and if found now to work, we'll have to redo the sequence and retry. |
| 855 | */ |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 856 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 857 | while (true) { |
| 858 | AssemblerStatus res = oatAssembleInstructions(cUnit, 0); |
| 859 | if (res == kSuccess) { |
| 860 | break; |
| 861 | } else { |
| 862 | cUnit->assemblerRetries++; |
| 863 | if (cUnit->assemblerRetries > MAX_ASSEMBLER_RETRIES) { |
| 864 | oatCodegenDump(cUnit); |
| 865 | LOG(FATAL) << "Assembler error - too many retries"; |
| 866 | } |
| 867 | // Redo offsets and try again |
| 868 | oatAssignOffsets(cUnit); |
| 869 | cUnit->codeBuffer.clear(); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 870 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 871 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 872 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 873 | // Install literals |
| 874 | installLiteralPools(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 875 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 876 | // Install switch tables |
| 877 | installSwitchTables(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 878 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 879 | // Install fill array data |
| 880 | installFillArrayData(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 881 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 882 | /* |
| 883 | * Create the mapping table |
| 884 | */ |
| 885 | createMappingTable(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 886 | } |
| 887 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 888 | /* |
| 889 | * Insert a kPseudoCaseLabel at the beginning of the Dalvik |
| 890 | * offset vaddr. This label will be used to fix up the case |
| 891 | * branch table during the assembly phase. Be sure to set |
| 892 | * all resource flags on this to prevent code motion across |
| 893 | * target boundaries. KeyVal is just there for debugging. |
| 894 | */ |
| 895 | LIR* insertCaseLabel(CompilationUnit* cUnit, int vaddr, int keyVal) |
| 896 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 897 | SafeMap<unsigned int, LIR*>::iterator it; |
| 898 | it = cUnit->boundaryMap.find(vaddr); |
| 899 | if (it == cUnit->boundaryMap.end()) { |
| 900 | LOG(FATAL) << "Error: didn't find vaddr 0x" << std::hex << vaddr; |
| 901 | } |
| 902 | LIR* newLabel = (LIR*)oatNew(cUnit, sizeof(LIR), true, kAllocLIR); |
| 903 | newLabel->dalvikOffset = vaddr; |
| 904 | newLabel->opcode = kPseudoCaseLabel; |
| 905 | newLabel->operands[0] = keyVal; |
| 906 | oatInsertLIRAfter(it->second, (LIR*)newLabel); |
| 907 | return newLabel; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | void markPackedCaseLabels(CompilationUnit* cUnit, SwitchTable *tabRec) |
| 911 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 912 | const u2* table = tabRec->table; |
| 913 | int baseVaddr = tabRec->vaddr; |
| 914 | int *targets = (int*)&table[4]; |
| 915 | int entries = table[1]; |
| 916 | int lowKey = s4FromSwitchData(&table[2]); |
| 917 | for (int i = 0; i < entries; i++) { |
| 918 | tabRec->targets[i] = insertCaseLabel(cUnit, baseVaddr + targets[i], |
| 919 | i + lowKey); |
| 920 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | void markSparseCaseLabels(CompilationUnit* cUnit, SwitchTable *tabRec) |
| 924 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 925 | const u2* table = tabRec->table; |
| 926 | int baseVaddr = tabRec->vaddr; |
| 927 | int entries = table[1]; |
| 928 | int* keys = (int*)&table[2]; |
| 929 | int* targets = &keys[entries]; |
| 930 | for (int i = 0; i < entries; i++) { |
| 931 | tabRec->targets[i] = insertCaseLabel(cUnit, baseVaddr + targets[i], |
| 932 | keys[i]); |
| 933 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | void oatProcessSwitchTables(CompilationUnit* cUnit) |
| 937 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 938 | GrowableListIterator iterator; |
| 939 | oatGrowableListIteratorInit(&cUnit->switchTables, &iterator); |
| 940 | while (true) { |
| 941 | SwitchTable *tabRec = |
| 942 | (SwitchTable *) oatGrowableListIteratorNext(&iterator); |
| 943 | if (tabRec == NULL) break; |
| 944 | if (tabRec->table[0] == Instruction::kPackedSwitchSignature) { |
| 945 | markPackedCaseLabels(cUnit, tabRec); |
| 946 | } else if (tabRec->table[0] == Instruction::kSparseSwitchSignature) { |
| 947 | markSparseCaseLabels(cUnit, tabRec); |
| 948 | } else { |
| 949 | LOG(FATAL) << "Invalid switch table"; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 950 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 951 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | //FIXME: Do we have endian issues here? |
| 955 | |
| 956 | void dumpSparseSwitchTable(const u2* table) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 957 | /* |
| 958 | * Sparse switch data format: |
| 959 | * ushort ident = 0x0200 magic value |
| 960 | * ushort size number of entries in the table; > 0 |
| 961 | * int keys[size] keys, sorted low-to-high; 32-bit aligned |
| 962 | * int targets[size] branch targets, relative to switch opcode |
| 963 | * |
| 964 | * Total size is (2+size*4) 16-bit code units. |
| 965 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 966 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 967 | u2 ident = table[0]; |
| 968 | int entries = table[1]; |
| 969 | int* keys = (int*)&table[2]; |
| 970 | int* targets = &keys[entries]; |
| 971 | LOG(INFO) << "Sparse switch table - ident:0x" << std::hex << ident |
| 972 | << ", entries: " << std::dec << entries; |
| 973 | for (int i = 0; i < entries; i++) { |
| 974 | LOG(INFO) << " Key[" << keys[i] << "] -> 0x" << std::hex << targets[i]; |
| 975 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | void dumpPackedSwitchTable(const u2* table) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 979 | /* |
| 980 | * Packed switch data format: |
| 981 | * ushort ident = 0x0100 magic value |
| 982 | * ushort size number of entries in the table |
| 983 | * int first_key first (and lowest) switch case value |
| 984 | * int targets[size] branch targets, relative to switch opcode |
| 985 | * |
| 986 | * Total size is (4+size*2) 16-bit code units. |
| 987 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 988 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 989 | u2 ident = table[0]; |
| 990 | int* targets = (int*)&table[4]; |
| 991 | int entries = table[1]; |
| 992 | int lowKey = s4FromSwitchData(&table[2]); |
| 993 | LOG(INFO) << "Packed switch table - ident:0x" << std::hex << ident |
| 994 | << ", entries: " << std::dec << entries << ", lowKey: " << lowKey; |
| 995 | for (int i = 0; i < entries; i++) { |
| 996 | LOG(INFO) << " Key[" << (i + lowKey) << "] -> 0x" << std::hex |
| 997 | << targets[i]; |
| 998 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 999 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1000 | |
| 1001 | |
| 1002 | } // namespace art |