buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [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 | /* |
| 18 | * This file contains codegen for the Thumb2 ISA and is intended to be |
| 19 | * includes by: |
| 20 | * |
| 21 | * Codegen-$(TARGET_ARCH_VARIANT).c |
| 22 | * |
| 23 | */ |
| 24 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 25 | #include "oat_compilation_unit.h" |
| 26 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 27 | namespace art { |
| 28 | |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 29 | |
| 30 | /* Return the position of an ssa name within the argument list */ |
| 31 | int inPosition(CompilationUnit* cUnit, int sReg) |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 32 | { |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 33 | int vReg = SRegToVReg(cUnit, sReg); |
| 34 | return vReg - cUnit->numRegs; |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * Describe an argument. If it's already in an arg register, just leave it |
| 39 | * there. NOTE: all live arg registers must be locked prior to this call |
| 40 | * to avoid having them allocated as a temp by downstream utilities. |
| 41 | */ |
| 42 | RegLocation argLoc(CompilationUnit* cUnit, RegLocation loc) |
| 43 | { |
| 44 | int argNum = inPosition(cUnit, loc.sRegLow); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 45 | if (loc.wide) { |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 46 | if (argNum == 2) { |
| 47 | // Bad case - half in register, half in frame. Just punt |
| 48 | loc.location = kLocInvalid; |
| 49 | } else if (argNum < 2) { |
| 50 | loc.lowReg = rARG1 + argNum; |
| 51 | loc.highReg = loc.lowReg + 1; |
| 52 | loc.location = kLocPhysReg; |
| 53 | } else { |
| 54 | loc.location = kLocDalvikFrame; |
| 55 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 56 | } else { |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 57 | if (argNum < 3) { |
| 58 | loc.lowReg = rARG1 + argNum; |
| 59 | loc.location = kLocPhysReg; |
| 60 | } else { |
| 61 | loc.location = kLocDalvikFrame; |
| 62 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 63 | } |
| 64 | return loc; |
| 65 | } |
| 66 | |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 67 | /* |
| 68 | * Load an argument. If already in a register, just return. If in |
| 69 | * the frame, we can't use the normal loadValue() because it assumed |
| 70 | * a proper frame - and we're frameless. |
| 71 | */ |
| 72 | RegLocation loadArg(CompilationUnit* cUnit, RegLocation loc) |
| 73 | { |
| 74 | if (loc.location == kLocDalvikFrame) { |
| 75 | int start = (inPosition(cUnit, loc.sRegLow) + 1) * sizeof(uint32_t); |
| 76 | loc.lowReg = oatAllocTemp(cUnit); |
| 77 | loadWordDisp(cUnit, rSP, start, loc.lowReg); |
| 78 | if (loc.wide) { |
| 79 | loc.highReg = oatAllocTemp(cUnit); |
| 80 | loadWordDisp(cUnit, rSP, start + sizeof(uint32_t), loc.highReg); |
| 81 | } |
| 82 | loc.location = kLocPhysReg; |
| 83 | } |
| 84 | return loc; |
| 85 | } |
| 86 | |
| 87 | /* Lock any referenced arguments that arrive in registers */ |
| 88 | void lockLiveArgs(CompilationUnit* cUnit, MIR* mir) |
| 89 | { |
| 90 | int firstIn = cUnit->numRegs; |
| 91 | const int numArgRegs = 3; // TODO: generalize & move to RegUtil.cc |
| 92 | for (int i = 0; i < mir->ssaRep->numUses; i++) { |
| 93 | int vReg = SRegToVReg(cUnit, mir->ssaRep->uses[i]); |
| 94 | int inPosition = vReg - firstIn; |
| 95 | if (inPosition < numArgRegs) { |
| 96 | oatLockTemp(cUnit, rARG1 + inPosition); |
| 97 | } |
| 98 | } |
| 99 | } |
| 100 | |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 101 | /* Find the next MIR, which may be in a following basic block */ |
| 102 | MIR* getNextMir(CompilationUnit* cUnit, BasicBlock** pBb, MIR* mir) |
| 103 | { |
| 104 | BasicBlock* bb = *pBb; |
| 105 | MIR* origMir = mir; |
| 106 | while (bb != NULL) { |
| 107 | if (mir != NULL) { |
| 108 | mir = mir->next; |
| 109 | } |
| 110 | if (mir != NULL) { |
| 111 | return mir; |
| 112 | } else { |
| 113 | bb = bb->fallThrough; |
| 114 | *pBb = bb; |
| 115 | if (bb) { |
| 116 | mir = bb->firstMIRInsn; |
| 117 | if (mir != NULL) { |
| 118 | return mir; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | return origMir; |
| 124 | } |
| 125 | |
| 126 | /* Used for the "printMe" listing */ |
| 127 | void genPrintLabel(CompilationUnit *cUnit, MIR* mir) |
| 128 | { |
| 129 | LIR* boundaryLIR; |
| 130 | /* Mark the beginning of a Dalvik instruction for line tracking */ |
| 131 | char* instStr = cUnit->printMe ? |
| 132 | oatGetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL; |
| 133 | boundaryLIR = newLIR1(cUnit, kPseudoDalvikByteCodeBoundary, |
| 134 | (intptr_t) instStr); |
| 135 | cUnit->boundaryMap.insert(std::make_pair(mir->offset, |
| 136 | (LIR*)boundaryLIR)); |
| 137 | /* Don't generate the SSA annotation unless verbose mode is on */ |
| 138 | if (cUnit->printMe && mir->ssaRep) { |
| 139 | char* ssaString = oatGetSSAString(cUnit, mir->ssaRep); |
| 140 | newLIR1(cUnit, kPseudoSSARep, (int) ssaString); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | MIR* specialIGet(CompilationUnit* cUnit, BasicBlock** bb, MIR* mir, |
| 145 | OpSize size, bool longOrDouble, bool isObject) |
| 146 | { |
| 147 | int fieldOffset; |
| 148 | bool isVolatile; |
| 149 | uint32_t fieldIdx = mir->dalvikInsn.vC; |
| 150 | bool fastPath = fastInstance(cUnit, fieldIdx, fieldOffset, isVolatile, |
| 151 | false); |
| 152 | if (!fastPath) { |
| 153 | return NULL; |
| 154 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 155 | RegLocation rlObj = oatGetSrc(cUnit, mir, 0); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 156 | lockLiveArgs(cUnit, mir); |
| 157 | rlObj = argLoc(cUnit, rlObj); |
| 158 | // Reject if object reference is not "this" |
| 159 | if ((rlObj.location == kLocInvalid) || |
| 160 | (inPosition(cUnit, rlObj.sRegLow) != 0)) { |
| 161 | oatResetRegPool(cUnit); |
| 162 | return NULL; |
| 163 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 164 | RegLocation rlDest; |
| 165 | if (longOrDouble) { |
| 166 | rlDest = oatGetReturnWide(cUnit, false); |
| 167 | } else { |
| 168 | rlDest = oatGetReturn(cUnit, false); |
| 169 | } |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 170 | // Point of no return - no aborts after this |
| 171 | mir->optimizationFlags |= MIR_IGNORE_NULL_CHECK; |
| 172 | genPrintLabel(cUnit, mir); |
| 173 | rlObj = loadArg(cUnit, rlObj); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 174 | genIGet(cUnit, mir, size, rlDest, rlObj, longOrDouble, isObject); |
| 175 | return getNextMir(cUnit, bb, mir); |
| 176 | } |
| 177 | |
| 178 | MIR* specialIPut(CompilationUnit* cUnit, BasicBlock** bb, MIR* mir, |
| 179 | OpSize size, bool longOrDouble, bool isObject) |
| 180 | { |
| 181 | int fieldOffset; |
| 182 | bool isVolatile; |
| 183 | uint32_t fieldIdx = mir->dalvikInsn.vC; |
| 184 | bool fastPath = fastInstance(cUnit, fieldIdx, fieldOffset, isVolatile, |
| 185 | false); |
| 186 | if (!fastPath) { |
| 187 | return NULL; |
| 188 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 189 | RegLocation rlSrc; |
| 190 | RegLocation rlObj; |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 191 | lockLiveArgs(cUnit, mir); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 192 | if (longOrDouble) { |
| 193 | rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 194 | rlObj = oatGetSrc(cUnit, mir, 2); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 195 | } else { |
| 196 | rlSrc = oatGetSrc(cUnit, mir, 0); |
| 197 | rlObj = oatGetSrc(cUnit, mir, 1); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 198 | } |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 199 | rlSrc = argLoc(cUnit, rlSrc); |
| 200 | rlObj = argLoc(cUnit, rlObj); |
| 201 | // Reject if object reference is not "this" |
| 202 | if ((rlObj.location == kLocInvalid) || |
| 203 | (inPosition(cUnit, rlObj.sRegLow) != 0) || |
| 204 | (rlSrc.location == kLocInvalid)) { |
| 205 | oatResetRegPool(cUnit); |
| 206 | return NULL; |
| 207 | } |
| 208 | // Point of no return - no aborts after this |
| 209 | mir->optimizationFlags |= MIR_IGNORE_NULL_CHECK; |
| 210 | genPrintLabel(cUnit, mir); |
| 211 | rlObj = loadArg(cUnit, rlObj); |
| 212 | rlSrc = loadArg(cUnit, rlSrc); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 213 | genIPut(cUnit, mir, size, rlSrc, rlObj, longOrDouble, isObject); |
| 214 | return getNextMir(cUnit, bb, mir); |
| 215 | } |
| 216 | |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 217 | MIR* specialIdentity(CompilationUnit* cUnit, MIR* mir) |
| 218 | { |
| 219 | RegLocation rlSrc; |
| 220 | RegLocation rlDest; |
| 221 | bool wide = (mir->ssaRep->numUses == 2); |
| 222 | if (wide) { |
| 223 | rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 224 | rlDest = oatGetReturnWide(cUnit, false); |
| 225 | } else { |
| 226 | rlSrc = oatGetSrc(cUnit, mir, 0); |
| 227 | rlDest = oatGetReturn(cUnit, false); |
| 228 | } |
| 229 | lockLiveArgs(cUnit, mir); |
| 230 | rlSrc = argLoc(cUnit, rlSrc); |
| 231 | if (rlSrc.location == kLocInvalid) { |
| 232 | oatResetRegPool(cUnit); |
| 233 | return NULL; |
| 234 | } |
| 235 | // Point of no return - no aborts after this |
| 236 | genPrintLabel(cUnit, mir); |
| 237 | rlSrc = loadArg(cUnit, rlSrc); |
| 238 | if (wide) { |
| 239 | storeValueWide(cUnit, rlDest, rlSrc); |
| 240 | } else { |
| 241 | storeValue(cUnit, rlDest, rlSrc); |
| 242 | } |
| 243 | return mir; |
| 244 | } |
| 245 | |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 246 | /* |
| 247 | * Special-case code genration for simple non-throwing leaf methods. |
| 248 | */ |
| 249 | void genSpecialCase(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 250 | SpecialCaseHandler specialCase) |
| 251 | { |
| 252 | cUnit->currentDalvikOffset = mir->offset; |
| 253 | MIR* nextMir = NULL; |
| 254 | switch(specialCase) { |
| 255 | case kNullMethod: |
| 256 | DCHECK(mir->dalvikInsn.opcode == Instruction::RETURN_VOID); |
| 257 | nextMir = mir; |
| 258 | break; |
| 259 | case kConstFunction: |
| 260 | genPrintLabel(cUnit, mir); |
| 261 | loadConstant(cUnit, rRET0, mir->dalvikInsn.vB); |
| 262 | nextMir = getNextMir(cUnit, &bb, mir); |
| 263 | break; |
| 264 | case kIGet: |
| 265 | nextMir = specialIGet(cUnit, &bb, mir, kWord, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 266 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 267 | case kIGetBoolean: |
| 268 | case kIGetByte: |
| 269 | nextMir = specialIGet(cUnit, &bb, mir, kUnsignedByte, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 270 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 271 | case kIGetObject: |
| 272 | nextMir = specialIGet(cUnit, &bb, mir, kWord, false, true); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 273 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 274 | case kIGetChar: |
| 275 | nextMir = specialIGet(cUnit, &bb, mir, kUnsignedHalf, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 276 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 277 | case kIGetShort: |
| 278 | nextMir = specialIGet(cUnit, &bb, mir, kSignedHalf, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 279 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 280 | case kIGetWide: |
| 281 | nextMir = specialIGet(cUnit, &bb, mir, kLong, true, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 282 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 283 | case kIPut: |
| 284 | nextMir = specialIPut(cUnit, &bb, mir, kWord, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 285 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 286 | case kIPutBoolean: |
| 287 | case kIPutByte: |
| 288 | nextMir = specialIPut(cUnit, &bb, mir, kUnsignedByte, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 289 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 290 | case kIPutObject: |
| 291 | nextMir = specialIPut(cUnit, &bb, mir, kWord, false, true); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 292 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 293 | case kIPutChar: |
| 294 | nextMir = specialIPut(cUnit, &bb, mir, kUnsignedHalf, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 295 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 296 | case kIPutShort: |
| 297 | nextMir = specialIPut(cUnit, &bb, mir, kSignedHalf, false, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 298 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 299 | case kIPutWide: |
| 300 | nextMir = specialIPut(cUnit, &bb, mir, kLong, true, false); |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 301 | break; |
| 302 | case kIdentity: |
| 303 | nextMir = specialIdentity(cUnit, mir); |
| 304 | break; |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 305 | default: |
| 306 | return; |
| 307 | } |
| 308 | if (nextMir != NULL) { |
| 309 | cUnit->currentDalvikOffset = nextMir->offset; |
buzbee | e62076c | 2012-03-21 14:26:16 -0700 | [diff] [blame^] | 310 | if (specialCase != kIdentity) { |
| 311 | genPrintLabel(cUnit, nextMir); |
| 312 | } |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 313 | newLIR1(cUnit, kThumbBx, rLR); |
| 314 | cUnit->coreSpillMask = 0; |
| 315 | cUnit->numCoreSpills = 0; |
| 316 | cUnit->fpSpillMask = 0; |
| 317 | cUnit->numFPSpills = 0; |
| 318 | cUnit->frameSize = 0; |
| 319 | cUnit->coreVmapTable.clear(); |
| 320 | cUnit->fpVmapTable.clear(); |
| 321 | } |
| 322 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 323 | |
| 324 | /* |
| 325 | * Generate a Thumb2 IT instruction, which can nullify up to |
| 326 | * four subsequent instructions based on a condition and its |
| 327 | * inverse. The condition applies to the first instruction, which |
| 328 | * is executed if the condition is met. The string "guide" consists |
| 329 | * of 0 to 3 chars, and applies to the 2nd through 4th instruction. |
| 330 | * A "T" means the instruction is executed if the condition is |
| 331 | * met, and an "E" means the instruction is executed if the condition |
| 332 | * is not met. |
| 333 | */ |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 334 | LIR* opIT(CompilationUnit* cUnit, ArmConditionCode code, const char* guide) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 335 | { |
| 336 | int mask; |
| 337 | int condBit = code & 1; |
| 338 | int altBit = condBit ^ 1; |
| 339 | int mask3 = 0; |
| 340 | int mask2 = 0; |
| 341 | int mask1 = 0; |
| 342 | |
| 343 | //Note: case fallthroughs intentional |
| 344 | switch(strlen(guide)) { |
| 345 | case 3: |
| 346 | mask1 = (guide[2] == 'T') ? condBit : altBit; |
| 347 | case 2: |
| 348 | mask2 = (guide[1] == 'T') ? condBit : altBit; |
| 349 | case 1: |
| 350 | mask3 = (guide[0] == 'T') ? condBit : altBit; |
| 351 | break; |
| 352 | case 0: |
| 353 | break; |
| 354 | default: |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 355 | LOG(FATAL) << "OAT: bad case in opIT"; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 356 | } |
| 357 | mask = (mask3 << 3) | (mask2 << 2) | (mask1 << 1) | |
| 358 | (1 << (3 - strlen(guide))); |
| 359 | return newLIR2(cUnit, kThumb2It, code, mask); |
| 360 | } |
| 361 | |
| 362 | /* |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 363 | * The sparse table in the literal pool is an array of <key,displacement> |
| 364 | * pairs. For each set, we'll load them as a pair using ldmia. |
| 365 | * This means that the register number of the temp we use for the key |
| 366 | * must be lower than the reg for the displacement. |
| 367 | * |
| 368 | * The test loop will look something like: |
| 369 | * |
| 370 | * adr rBase, <table> |
| 371 | * ldr rVal, [rSP, vRegOff] |
| 372 | * mov rIdx, #tableSize |
| 373 | * lp: |
| 374 | * ldmia rBase!, {rKey, rDisp} |
| 375 | * sub rIdx, #1 |
| 376 | * cmp rVal, rKey |
| 377 | * ifeq |
| 378 | * add rPC, rDisp ; This is the branch from which we compute displacement |
| 379 | * cbnz rIdx, lp |
| 380 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 381 | void genSparseSwitch(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 382 | { |
| 383 | const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB; |
| 384 | if (cUnit->printMe) { |
| 385 | dumpSparseSwitchTable(table); |
| 386 | } |
| 387 | // Add the table to the list - we'll process it later |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 388 | SwitchTable *tabRec = (SwitchTable *)oatNew(cUnit, sizeof(SwitchTable), |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 389 | true, kAllocData); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 390 | tabRec->table = table; |
| 391 | tabRec->vaddr = mir->offset; |
| 392 | int size = table[1]; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 393 | tabRec->targets = (LIR* *)oatNew(cUnit, size * sizeof(LIR*), true, |
| 394 | kAllocLIR); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 395 | oatInsertGrowableList(cUnit, &cUnit->switchTables, (intptr_t)tabRec); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 396 | |
| 397 | // Get the switch value |
| 398 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 399 | int rBase = oatAllocTemp(cUnit); |
| 400 | /* Allocate key and disp temps */ |
| 401 | int rKey = oatAllocTemp(cUnit); |
| 402 | int rDisp = oatAllocTemp(cUnit); |
| 403 | // Make sure rKey's register number is less than rDisp's number for ldmia |
| 404 | if (rKey > rDisp) { |
| 405 | int tmp = rDisp; |
| 406 | rDisp = rKey; |
| 407 | rKey = tmp; |
| 408 | } |
| 409 | // Materialize a pointer to the switch table |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 410 | newLIR3(cUnit, kThumb2Adr, rBase, 0, (intptr_t)tabRec); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 411 | // Set up rIdx |
| 412 | int rIdx = oatAllocTemp(cUnit); |
| 413 | loadConstant(cUnit, rIdx, size); |
| 414 | // Establish loop branch target |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 415 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 416 | // Load next key/disp |
| 417 | newLIR2(cUnit, kThumb2LdmiaWB, rBase, (1 << rKey) | (1 << rDisp)); |
| 418 | opRegReg(cUnit, kOpCmp, rKey, rlSrc.lowReg); |
| 419 | // Go if match. NOTE: No instruction set switch here - must stay Thumb2 |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 420 | opIT(cUnit, kArmCondEq, ""); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 421 | LIR* switchBranch = newLIR1(cUnit, kThumb2AddPCR, rDisp); |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 422 | tabRec->anchor = switchBranch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 423 | // Needs to use setflags encoding here |
| 424 | newLIR3(cUnit, kThumb2SubsRRI12, rIdx, rIdx, 1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 425 | opCondBranch(cUnit, kCondNe, target); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 429 | void genPackedSwitch(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 430 | { |
| 431 | const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB; |
| 432 | if (cUnit->printMe) { |
| 433 | dumpPackedSwitchTable(table); |
| 434 | } |
| 435 | // Add the table to the list - we'll process it later |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 436 | SwitchTable *tabRec = (SwitchTable *)oatNew(cUnit, sizeof(SwitchTable), |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 437 | true, kAllocData); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 438 | tabRec->table = table; |
| 439 | tabRec->vaddr = mir->offset; |
| 440 | int size = table[1]; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 441 | tabRec->targets = (LIR* *)oatNew(cUnit, size * sizeof(LIR*), true, |
buzbee | 5abfa3e | 2012-01-31 17:01:43 -0800 | [diff] [blame] | 442 | kAllocLIR); |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 443 | oatInsertGrowableList(cUnit, &cUnit->switchTables, (intptr_t)tabRec); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 444 | |
| 445 | // Get the switch value |
| 446 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 447 | int tableBase = oatAllocTemp(cUnit); |
| 448 | // Materialize a pointer to the switch table |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 449 | newLIR3(cUnit, kThumb2Adr, tableBase, 0, (intptr_t)tabRec); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 450 | int lowKey = s4FromSwitchData(&table[2]); |
| 451 | int keyReg; |
| 452 | // Remove the bias, if necessary |
| 453 | if (lowKey == 0) { |
| 454 | keyReg = rlSrc.lowReg; |
| 455 | } else { |
| 456 | keyReg = oatAllocTemp(cUnit); |
| 457 | opRegRegImm(cUnit, kOpSub, keyReg, rlSrc.lowReg, lowKey); |
| 458 | } |
| 459 | // Bounds check - if < 0 or >= size continue following switch |
| 460 | opRegImm(cUnit, kOpCmp, keyReg, size-1); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 461 | LIR* branchOver = opCondBranch(cUnit, kCondHi, NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 462 | |
| 463 | // Load the displacement from the switch table |
| 464 | int dispReg = oatAllocTemp(cUnit); |
| 465 | loadBaseIndexed(cUnit, tableBase, keyReg, dispReg, 2, kWord); |
| 466 | |
| 467 | // ..and go! NOTE: No instruction set switch here - must stay Thumb2 |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 468 | LIR* switchBranch = newLIR1(cUnit, kThumb2AddPCR, dispReg); |
buzbee | c5159d5 | 2012-03-03 11:48:39 -0800 | [diff] [blame] | 469 | tabRec->anchor = switchBranch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 470 | |
| 471 | /* branchOver target here */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 472 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 473 | branchOver->target = (LIR*)target; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | /* |
| 477 | * Array data table format: |
| 478 | * ushort ident = 0x0300 magic value |
| 479 | * ushort width width of each element in the table |
| 480 | * uint size number of elements in the table |
| 481 | * ubyte data[size*width] table of data values (may contain a single-byte |
| 482 | * padding at the end) |
| 483 | * |
| 484 | * Total size is 4+(width * size + 1)/2 16-bit code units. |
| 485 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 486 | void genFillArrayData(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 487 | { |
| 488 | const u2* table = cUnit->insns + mir->offset + mir->dalvikInsn.vB; |
| 489 | // Add the table to the list - we'll process it later |
| 490 | FillArrayData *tabRec = (FillArrayData *) |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 491 | oatNew(cUnit, sizeof(FillArrayData), true, kAllocData); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 492 | tabRec->table = table; |
| 493 | tabRec->vaddr = mir->offset; |
| 494 | u2 width = tabRec->table[1]; |
| 495 | u4 size = tabRec->table[2] | (((u4)tabRec->table[3]) << 16); |
| 496 | tabRec->size = (size * width) + 8; |
| 497 | |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 498 | oatInsertGrowableList(cUnit, &cUnit->fillArrayData, (intptr_t)tabRec); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 499 | |
| 500 | // Making a call - use explicit registers |
| 501 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 502 | loadValueDirectFixed(cUnit, rlSrc, r0); |
| 503 | loadWordDisp(cUnit, rSELF, |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 504 | OFFSETOF_MEMBER(Thread, pHandleFillArrayDataFromCode), rLR); |
buzbee | e6d6196 | 2011-08-27 11:58:19 -0700 | [diff] [blame] | 505 | // Materialize a pointer to the fill data image |
buzbee | 03fa263 | 2011-09-20 17:10:57 -0700 | [diff] [blame] | 506 | newLIR3(cUnit, kThumb2Adr, r1, 0, (intptr_t)tabRec); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 507 | oatClobberCalleeSave(cUnit); |
| 508 | opReg(cUnit, kOpBlx, rLR); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 509 | } |
| 510 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 511 | void genNegFloat(CompilationUnit* cUnit, RegLocation rlDest, RegLocation rlSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 512 | { |
| 513 | RegLocation rlResult; |
| 514 | rlSrc = loadValue(cUnit, rlSrc, kFPReg); |
| 515 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 516 | newLIR2(cUnit, kThumb2Vnegs, rlResult.lowReg, rlSrc.lowReg); |
| 517 | storeValue(cUnit, rlDest, rlResult); |
| 518 | } |
| 519 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 520 | void genNegDouble(CompilationUnit* cUnit, RegLocation rlDest, RegLocation rlSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 521 | { |
| 522 | RegLocation rlResult; |
| 523 | rlSrc = loadValueWide(cUnit, rlSrc, kFPReg); |
| 524 | rlResult = oatEvalLoc(cUnit, rlDest, kFPReg, true); |
| 525 | newLIR2(cUnit, kThumb2Vnegd, S2D(rlResult.lowReg, rlResult.highReg), |
| 526 | S2D(rlSrc.lowReg, rlSrc.highReg)); |
| 527 | storeValueWide(cUnit, rlDest, rlResult); |
| 528 | } |
| 529 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 530 | /* |
| 531 | * Handle simple case (thin lock) inline. If it's complicated, bail |
| 532 | * out to the heavyweight lock/unlock routines. We'll use dedicated |
| 533 | * registers here in order to be in the right position in case we |
| 534 | * to bail to dvm[Lock/Unlock]Object(self, object) |
| 535 | * |
| 536 | * r0 -> self pointer [arg0 for dvm[Lock/Unlock]Object |
| 537 | * r1 -> object [arg1 for dvm[Lock/Unlock]Object |
| 538 | * r2 -> intial contents of object->lock, later result of strex |
| 539 | * r3 -> self->threadId |
| 540 | * r12 -> allow to be used by utilities as general temp |
| 541 | * |
| 542 | * The result of the strex is 0 if we acquire the lock. |
| 543 | * |
| 544 | * See comments in Sync.c for the layout of the lock word. |
| 545 | * Of particular interest to this code is the test for the |
| 546 | * simple case - which we handle inline. For monitor enter, the |
| 547 | * simple case is thin lock, held by no-one. For monitor exit, |
| 548 | * the simple case is thin lock, held by the unlocking thread with |
| 549 | * a recurse count of 0. |
| 550 | * |
| 551 | * A minor complication is that there is a field in the lock word |
| 552 | * unrelated to locking: the hash state. This field must be ignored, but |
| 553 | * preserved. |
| 554 | * |
| 555 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 556 | void genMonitorEnter(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 557 | { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 558 | oatFlushAllRegs(cUnit); |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 559 | DCHECK_EQ(LW_SHAPE_THIN, 0); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 560 | loadValueDirectFixed(cUnit, rlSrc, r0); // Get obj |
buzbee | 2e748f3 | 2011-08-29 21:02:19 -0700 | [diff] [blame] | 561 | oatLockCallTemps(cUnit); // Prepare for explicit register usage |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 562 | genNullCheck(cUnit, rlSrc.sRegLow, r0, mir); |
| 563 | loadWordDisp(cUnit, rSELF, Thread::ThinLockIdOffset().Int32Value(), r2); |
| 564 | newLIR3(cUnit, kThumb2Ldrex, r1, r0, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 565 | Object::MonitorOffset().Int32Value() >> 2); // Get object->lock |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 566 | // Align owner |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 567 | opRegImm(cUnit, kOpLsl, r2, LW_LOCK_OWNER_SHIFT); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 568 | // Is lock unheld on lock or held by us (==threadId) on unlock? |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 569 | newLIR4(cUnit, kThumb2Bfi, r2, r1, 0, LW_LOCK_OWNER_SHIFT - 1); |
| 570 | newLIR3(cUnit, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1); |
buzbee | 05eba36 | 2012-03-10 20:11:27 -0800 | [diff] [blame] | 571 | opRegImm(cUnit, kOpCmp, r1, 0); |
| 572 | opIT(cUnit, kArmCondEq, ""); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 573 | newLIR4(cUnit, kThumb2Strex, r1, r2, r0, |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 574 | Object::MonitorOffset().Int32Value() >> 2); |
buzbee | 05eba36 | 2012-03-10 20:11:27 -0800 | [diff] [blame] | 575 | opRegImm(cUnit, kOpCmp, r1, 0); |
| 576 | opIT(cUnit, kArmCondNe, "T"); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 577 | // Go expensive route - artLockObjectFromCode(self, obj); |
| 578 | loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pLockObjectFromCode), |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 579 | rLR); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 580 | oatClobberCalleeSave(cUnit); |
| 581 | opReg(cUnit, kOpBlx, rLR); |
buzbee | 05eba36 | 2012-03-10 20:11:27 -0800 | [diff] [blame] | 582 | oatGenMemBarrier(cUnit, kSY); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /* |
| 586 | * For monitor unlock, we don't have to use ldrex/strex. Once |
| 587 | * we've determined that the lock is thin and that we own it with |
| 588 | * a zero recursion count, it's safe to punch it back to the |
| 589 | * initial, unlock thin state with a store word. |
| 590 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 591 | void genMonitorExit(CompilationUnit* cUnit, MIR* mir, RegLocation rlSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 592 | { |
Elliott Hughes | 5f79133 | 2011-09-15 17:45:30 -0700 | [diff] [blame] | 593 | DCHECK_EQ(LW_SHAPE_THIN, 0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 594 | oatFlushAllRegs(cUnit); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 595 | loadValueDirectFixed(cUnit, rlSrc, r0); // Get obj |
buzbee | 2e748f3 | 2011-08-29 21:02:19 -0700 | [diff] [blame] | 596 | oatLockCallTemps(cUnit); // Prepare for explicit register usage |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 597 | genNullCheck(cUnit, rlSrc.sRegLow, r0, mir); |
| 598 | loadWordDisp(cUnit, r0, Object::MonitorOffset().Int32Value(), r1); // Get lock |
| 599 | loadWordDisp(cUnit, rSELF, Thread::ThinLockIdOffset().Int32Value(), r2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 600 | // Is lock unheld on lock or held by us (==threadId) on unlock? |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 601 | opRegRegImm(cUnit, kOpAnd, r3, r1, (LW_HASH_STATE_MASK << LW_HASH_STATE_SHIFT)); |
buzbee | c143c55 | 2011-08-20 17:38:58 -0700 | [diff] [blame] | 602 | // Align owner |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 603 | opRegImm(cUnit, kOpLsl, r2, LW_LOCK_OWNER_SHIFT); |
| 604 | newLIR3(cUnit, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1); |
| 605 | opRegReg(cUnit, kOpSub, r1, r2); |
buzbee | 05eba36 | 2012-03-10 20:11:27 -0800 | [diff] [blame] | 606 | opIT(cUnit, kArmCondEq, "EE"); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 607 | storeWordDisp(cUnit, r0, Object::MonitorOffset().Int32Value(), r3); |
Ian Rogers | 4f0d07c | 2011-10-06 23:38:47 -0700 | [diff] [blame] | 608 | // Go expensive route - UnlockObjectFromCode(obj); |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 609 | loadWordDisp(cUnit, rSELF, OFFSETOF_MEMBER(Thread, pUnlockObjectFromCode), |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 610 | rLR); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 611 | oatClobberCalleeSave(cUnit); |
| 612 | opReg(cUnit, kOpBlx, rLR); |
buzbee | 05eba36 | 2012-03-10 20:11:27 -0800 | [diff] [blame] | 613 | oatGenMemBarrier(cUnit, kSY); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | /* |
| 617 | * 64-bit 3way compare function. |
| 618 | * mov rX, #-1 |
| 619 | * cmp op1hi, op2hi |
| 620 | * blt done |
| 621 | * bgt flip |
| 622 | * sub rX, op1lo, op2lo (treat as unsigned) |
| 623 | * beq done |
| 624 | * ite hi |
| 625 | * mov(hi) rX, #-1 |
| 626 | * mov(!hi) rX, #1 |
| 627 | * flip: |
| 628 | * neg rX |
| 629 | * done: |
| 630 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 631 | void genCmpLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 632 | RegLocation rlSrc1, RegLocation rlSrc2) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 633 | { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 634 | LIR* target1; |
| 635 | LIR* target2; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 636 | rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg); |
| 637 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg); |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 638 | int tReg = oatAllocTemp(cUnit); |
| 639 | loadConstant(cUnit, tReg, -1); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 640 | opRegReg(cUnit, kOpCmp, rlSrc1.highReg, rlSrc2.highReg); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 641 | LIR* branch1 = opCondBranch(cUnit, kCondLt, NULL); |
| 642 | LIR* branch2 = opCondBranch(cUnit, kCondGt, NULL); |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 643 | opRegRegReg(cUnit, kOpSub, tReg, rlSrc1.lowReg, rlSrc2.lowReg); |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 644 | LIR* branch3 = opCondBranch(cUnit, kCondEq, NULL); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 645 | |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 646 | opIT(cUnit, kArmCondHi, "E"); |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 647 | newLIR2(cUnit, kThumb2MovImmShift, tReg, modifiedImmediate(-1)); |
| 648 | loadConstant(cUnit, tReg, 1); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 649 | genBarrier(cUnit); |
| 650 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 651 | target2 = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 652 | opRegReg(cUnit, kOpNeg, tReg, tReg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 653 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 654 | target1 = newLIR0(cUnit, kPseudoTargetLabel); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 655 | |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 656 | RegLocation rlTemp = LOC_C_RETURN; // Just using as template, will change |
| 657 | rlTemp.lowReg = tReg; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 658 | storeValue(cUnit, rlDest, rlTemp); |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 659 | oatFreeTemp(cUnit, tReg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 660 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 661 | branch1->target = (LIR*)target1; |
| 662 | branch2->target = (LIR*)target2; |
| 663 | branch3->target = branch1->target; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 664 | } |
| 665 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 666 | /* |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 667 | * Generate a register comparison to an immediate and branch. Caller |
| 668 | * is responsible for setting branch target field. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 669 | */ |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 670 | LIR* opCmpImmBranch(CompilationUnit* cUnit, ConditionCode cond, int reg, |
| 671 | int checkValue, LIR* target) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 672 | { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 673 | LIR* branch; |
| 674 | int modImm; |
| 675 | ArmConditionCode armCond = oatArmConditionEncoding(cond); |
| 676 | if ((LOWREG(reg)) && (checkValue == 0) && |
| 677 | ((armCond == kArmCondEq) || (armCond == kArmCondNe))) { |
| 678 | branch = newLIR2(cUnit, |
| 679 | (armCond == kArmCondEq) ? kThumb2Cbz : kThumb2Cbnz, |
| 680 | reg, 0); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 681 | } else { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 682 | modImm = modifiedImmediate(checkValue); |
| 683 | if (LOWREG(reg) && ((checkValue & 0xff) == checkValue)) { |
| 684 | newLIR2(cUnit, kThumbCmpRI8, reg, checkValue); |
| 685 | } else if (modImm >= 0) { |
| 686 | newLIR2(cUnit, kThumb2CmpRI8, reg, modImm); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 687 | } else { |
buzbee | 58f9274 | 2011-10-01 11:22:17 -0700 | [diff] [blame] | 688 | int tReg = oatAllocTemp(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 689 | loadConstant(cUnit, tReg, checkValue); |
| 690 | opRegReg(cUnit, kOpCmp, reg, tReg); |
buzbee | 58f9274 | 2011-10-01 11:22:17 -0700 | [diff] [blame] | 691 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 692 | branch = newLIR2(cUnit, kThumbBCond, 0, armCond); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 693 | } |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 694 | branch->target = target; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 695 | return branch; |
| 696 | } |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 697 | LIR* opRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 698 | { |
| 699 | LIR* res; |
| 700 | ArmOpcode opcode; |
| 701 | if (FPREG(rDest) || FPREG(rSrc)) |
| 702 | return fpRegCopy(cUnit, rDest, rSrc); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 703 | if (LOWREG(rDest) && LOWREG(rSrc)) |
| 704 | opcode = kThumbMovRR; |
| 705 | else if (!LOWREG(rDest) && !LOWREG(rSrc)) |
| 706 | opcode = kThumbMovRR_H2H; |
| 707 | else if (LOWREG(rDest)) |
| 708 | opcode = kThumbMovRR_H2L; |
| 709 | else |
| 710 | opcode = kThumbMovRR_L2H; |
buzbee | a2ebdd7 | 2012-03-04 14:57:06 -0800 | [diff] [blame] | 711 | res = rawLIR(cUnit, cUnit->currentDalvikOffset, opcode, rDest, rSrc); |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 712 | if (!(cUnit->disableOpt & (1 << kSafeOptimizations)) && rDest == rSrc) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 713 | res->flags.isNop = true; |
| 714 | } |
| 715 | return res; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 716 | } |
| 717 | |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 718 | LIR* opRegCopy(CompilationUnit* cUnit, int rDest, int rSrc) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 719 | { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 720 | LIR* res = opRegCopyNoInsert(cUnit, rDest, rSrc); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 721 | oatAppendLIR(cUnit, (LIR*)res); |
| 722 | return res; |
| 723 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 724 | |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 725 | void opRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 726 | int srcLo, int srcHi) |
| 727 | { |
| 728 | bool destFP = FPREG(destLo) && FPREG(destHi); |
| 729 | bool srcFP = FPREG(srcLo) && FPREG(srcHi); |
| 730 | DCHECK_EQ(FPREG(srcLo), FPREG(srcHi)); |
| 731 | DCHECK_EQ(FPREG(destLo), FPREG(destHi)); |
| 732 | if (destFP) { |
| 733 | if (srcFP) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 734 | opRegCopy(cUnit, S2D(destLo, destHi), S2D(srcLo, srcHi)); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 735 | } else { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 736 | newLIR3(cUnit, kThumb2Fmdrr, S2D(destLo, destHi), srcLo, srcHi); |
| 737 | } |
| 738 | } else { |
| 739 | if (srcFP) { |
| 740 | newLIR3(cUnit, kThumb2Fmrrd, destLo, destHi, S2D(srcLo, srcHi)); |
| 741 | } else { |
| 742 | // Handle overlap |
| 743 | if (srcHi == destLo) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 744 | opRegCopy(cUnit, destHi, srcHi); |
| 745 | opRegCopy(cUnit, destLo, srcLo); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 746 | } else { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 747 | opRegCopy(cUnit, destLo, srcLo); |
| 748 | opRegCopy(cUnit, destHi, srcHi); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 749 | } |
| 750 | } |
| 751 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 752 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 753 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 754 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 755 | } // namespace art |