buzbee | efc6369 | 2012-11-14 16:31:52 -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 | /* This file contains codegen for the Thumb2 ISA. */ |
| 18 | |
| 19 | #include "oat_compilation_unit.h" |
| 20 | #include "oat/runtime/oat_support_entrypoints.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 21 | #include "arm_lir.h" |
| 22 | #include "../codegen_util.h" |
| 23 | #include "../ralloc_util.h" |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | |
| 28 | /* Return the position of an ssa name within the argument list */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 29 | int InPosition(CompilationUnit* cUnit, int sReg) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 30 | { |
| 31 | int vReg = SRegToVReg(cUnit, sReg); |
| 32 | return vReg - cUnit->numRegs; |
| 33 | } |
| 34 | |
| 35 | /* |
| 36 | * Describe an argument. If it's already in an arg register, just leave it |
| 37 | * there. NOTE: all live arg registers must be locked prior to this call |
| 38 | * to avoid having them allocated as a temp by downstream utilities. |
| 39 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 40 | RegLocation ArgLoc(CompilationUnit* cUnit, RegLocation loc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 41 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 42 | int argNum = InPosition(cUnit, loc.sRegLow); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 43 | if (loc.wide) { |
| 44 | if (argNum == 2) { |
| 45 | // Bad case - half in register, half in frame. Just punt |
| 46 | loc.location = kLocInvalid; |
| 47 | } else if (argNum < 2) { |
| 48 | loc.lowReg = rARM_ARG1 + argNum; |
| 49 | loc.highReg = loc.lowReg + 1; |
| 50 | loc.location = kLocPhysReg; |
| 51 | } else { |
| 52 | loc.location = kLocDalvikFrame; |
| 53 | } |
| 54 | } else { |
| 55 | if (argNum < 3) { |
| 56 | loc.lowReg = rARM_ARG1 + argNum; |
| 57 | loc.location = kLocPhysReg; |
| 58 | } else { |
| 59 | loc.location = kLocDalvikFrame; |
| 60 | } |
| 61 | } |
| 62 | return loc; |
| 63 | } |
| 64 | |
| 65 | /* |
| 66 | * Load an argument. If already in a register, just return. If in |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 67 | * the frame, we can't use the normal LoadValue() because it assumed |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 68 | * a proper frame - and we're frameless. |
| 69 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 70 | RegLocation LoadArg(CompilationUnit* cUnit, RegLocation loc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 71 | { |
| 72 | if (loc.location == kLocDalvikFrame) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 73 | int start = (InPosition(cUnit, loc.sRegLow) + 1) * sizeof(uint32_t); |
| 74 | loc.lowReg = AllocTemp(cUnit); |
| 75 | LoadWordDisp(cUnit, rARM_SP, start, loc.lowReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 76 | if (loc.wide) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 77 | loc.highReg = AllocTemp(cUnit); |
| 78 | LoadWordDisp(cUnit, rARM_SP, start + sizeof(uint32_t), loc.highReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 79 | } |
| 80 | loc.location = kLocPhysReg; |
| 81 | } |
| 82 | return loc; |
| 83 | } |
| 84 | |
| 85 | /* Lock any referenced arguments that arrive in registers */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 86 | void LockLiveArgs(CompilationUnit* cUnit, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 87 | { |
| 88 | int firstIn = cUnit->numRegs; |
| 89 | const int numArgRegs = 3; // TODO: generalize & move to RegUtil.cc |
| 90 | for (int i = 0; i < mir->ssaRep->numUses; i++) { |
| 91 | int vReg = SRegToVReg(cUnit, mir->ssaRep->uses[i]); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 92 | int InPosition = vReg - firstIn; |
| 93 | if (InPosition < numArgRegs) { |
| 94 | LockTemp(cUnit, rARM_ARG1 + InPosition); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | /* Find the next MIR, which may be in a following basic block */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 100 | MIR* GetNextMir(CompilationUnit* cUnit, BasicBlock** pBb, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 101 | { |
| 102 | BasicBlock* bb = *pBb; |
| 103 | MIR* origMir = mir; |
| 104 | while (bb != NULL) { |
| 105 | if (mir != NULL) { |
| 106 | mir = mir->next; |
| 107 | } |
| 108 | if (mir != NULL) { |
| 109 | return mir; |
| 110 | } else { |
| 111 | bb = bb->fallThrough; |
| 112 | *pBb = bb; |
| 113 | if (bb) { |
| 114 | mir = bb->firstMIRInsn; |
| 115 | if (mir != NULL) { |
| 116 | return mir; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | return origMir; |
| 122 | } |
| 123 | |
| 124 | /* Used for the "printMe" listing */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 125 | void GenPrintLabel(CompilationUnit *cUnit, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 126 | { |
| 127 | /* Mark the beginning of a Dalvik instruction for line tracking */ |
| 128 | char* instStr = cUnit->printMe ? |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 129 | GetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL; |
| 130 | MarkBoundary(cUnit, mir->offset, instStr); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 131 | /* Don't generate the SSA annotation unless verbose mode is on */ |
| 132 | if (cUnit->printMe && mir->ssaRep) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 133 | char* ssaString = GetSSAString(cUnit, mir->ssaRep); |
| 134 | NewLIR1(cUnit, kPseudoSSARep, reinterpret_cast<uintptr_t>(ssaString)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 138 | MIR* SpecialIGet(CompilationUnit* cUnit, BasicBlock** bb, MIR* mir, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 139 | OpSize size, bool longOrDouble, bool isObject) |
| 140 | { |
| 141 | int fieldOffset; |
| 142 | bool isVolatile; |
| 143 | uint32_t fieldIdx = mir->dalvikInsn.vC; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 144 | bool fastPath = FastInstance(cUnit, fieldIdx, fieldOffset, isVolatile, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 145 | if (!fastPath || !(mir->optimizationFlags & MIR_IGNORE_NULL_CHECK)) { |
| 146 | return NULL; |
| 147 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 148 | RegLocation rlObj = GetSrc(cUnit, mir, 0); |
| 149 | LockLiveArgs(cUnit, mir); |
| 150 | rlObj = ArgLoc(cUnit, rlObj); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 151 | RegLocation rlDest; |
| 152 | if (longOrDouble) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 153 | rlDest = GetReturnWide(cUnit, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 154 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 155 | rlDest = GetReturn(cUnit, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 156 | } |
| 157 | // Point of no return - no aborts after this |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 158 | GenPrintLabel(cUnit, mir); |
| 159 | rlObj = LoadArg(cUnit, rlObj); |
| 160 | GenIGet(cUnit, fieldIdx, mir->optimizationFlags, size, rlDest, rlObj, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 161 | longOrDouble, isObject); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 162 | return GetNextMir(cUnit, bb, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 163 | } |
| 164 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 165 | MIR* SpecialIPut(CompilationUnit* cUnit, BasicBlock** bb, MIR* mir, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 166 | OpSize size, bool longOrDouble, bool isObject) |
| 167 | { |
| 168 | int fieldOffset; |
| 169 | bool isVolatile; |
| 170 | uint32_t fieldIdx = mir->dalvikInsn.vC; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 171 | bool fastPath = FastInstance(cUnit, fieldIdx, fieldOffset, isVolatile, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 172 | if (!fastPath || !(mir->optimizationFlags & MIR_IGNORE_NULL_CHECK)) { |
| 173 | return NULL; |
| 174 | } |
| 175 | RegLocation rlSrc; |
| 176 | RegLocation rlObj; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 177 | LockLiveArgs(cUnit, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 178 | if (longOrDouble) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 179 | rlSrc = GetSrcWide(cUnit, mir, 0); |
| 180 | rlObj = GetSrc(cUnit, mir, 2); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 181 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 182 | rlSrc = GetSrc(cUnit, mir, 0); |
| 183 | rlObj = GetSrc(cUnit, mir, 1); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 184 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 185 | rlSrc = ArgLoc(cUnit, rlSrc); |
| 186 | rlObj = ArgLoc(cUnit, rlObj); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 187 | // Reject if source is split across registers & frame |
| 188 | if (rlObj.location == kLocInvalid) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 189 | ResetRegPool(cUnit); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 190 | return NULL; |
| 191 | } |
| 192 | // Point of no return - no aborts after this |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 193 | GenPrintLabel(cUnit, mir); |
| 194 | rlObj = LoadArg(cUnit, rlObj); |
| 195 | rlSrc = LoadArg(cUnit, rlSrc); |
| 196 | GenIPut(cUnit, fieldIdx, mir->optimizationFlags, size, rlSrc, rlObj, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 197 | longOrDouble, isObject); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 198 | return GetNextMir(cUnit, bb, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 199 | } |
| 200 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 201 | MIR* SpecialIdentity(CompilationUnit* cUnit, MIR* mir) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 202 | { |
| 203 | RegLocation rlSrc; |
| 204 | RegLocation rlDest; |
| 205 | bool wide = (mir->ssaRep->numUses == 2); |
| 206 | if (wide) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 207 | rlSrc = GetSrcWide(cUnit, mir, 0); |
| 208 | rlDest = GetReturnWide(cUnit, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 209 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 210 | rlSrc = GetSrc(cUnit, mir, 0); |
| 211 | rlDest = GetReturn(cUnit, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 212 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 213 | LockLiveArgs(cUnit, mir); |
| 214 | rlSrc = ArgLoc(cUnit, rlSrc); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 215 | if (rlSrc.location == kLocInvalid) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 216 | ResetRegPool(cUnit); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 217 | return NULL; |
| 218 | } |
| 219 | // Point of no return - no aborts after this |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 220 | GenPrintLabel(cUnit, mir); |
| 221 | rlSrc = LoadArg(cUnit, rlSrc); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 222 | if (wide) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 223 | StoreValueWide(cUnit, rlDest, rlSrc); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 224 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 225 | StoreValue(cUnit, rlDest, rlSrc); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 226 | } |
| 227 | return mir; |
| 228 | } |
| 229 | |
| 230 | /* |
| 231 | * Special-case code genration for simple non-throwing leaf methods. |
| 232 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 233 | void GenSpecialCase(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 234 | SpecialCaseHandler specialCase) |
| 235 | { |
| 236 | cUnit->currentDalvikOffset = mir->offset; |
| 237 | MIR* nextMir = NULL; |
| 238 | switch (specialCase) { |
| 239 | case kNullMethod: |
| 240 | DCHECK(mir->dalvikInsn.opcode == Instruction::RETURN_VOID); |
| 241 | nextMir = mir; |
| 242 | break; |
| 243 | case kConstFunction: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 244 | GenPrintLabel(cUnit, mir); |
| 245 | LoadConstant(cUnit, rARM_RET0, mir->dalvikInsn.vB); |
| 246 | nextMir = GetNextMir(cUnit, &bb, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 247 | break; |
| 248 | case kIGet: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 249 | nextMir = SpecialIGet(cUnit, &bb, mir, kWord, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 250 | break; |
| 251 | case kIGetBoolean: |
| 252 | case kIGetByte: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 253 | nextMir = SpecialIGet(cUnit, &bb, mir, kUnsignedByte, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 254 | break; |
| 255 | case kIGetObject: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 256 | nextMir = SpecialIGet(cUnit, &bb, mir, kWord, false, true); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 257 | break; |
| 258 | case kIGetChar: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 259 | nextMir = SpecialIGet(cUnit, &bb, mir, kUnsignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 260 | break; |
| 261 | case kIGetShort: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 262 | nextMir = SpecialIGet(cUnit, &bb, mir, kSignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 263 | break; |
| 264 | case kIGetWide: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 265 | nextMir = SpecialIGet(cUnit, &bb, mir, kLong, true, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 266 | break; |
| 267 | case kIPut: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 268 | nextMir = SpecialIPut(cUnit, &bb, mir, kWord, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 269 | break; |
| 270 | case kIPutBoolean: |
| 271 | case kIPutByte: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 272 | nextMir = SpecialIPut(cUnit, &bb, mir, kUnsignedByte, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 273 | break; |
| 274 | case kIPutObject: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 275 | nextMir = SpecialIPut(cUnit, &bb, mir, kWord, false, true); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 276 | break; |
| 277 | case kIPutChar: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 278 | nextMir = SpecialIPut(cUnit, &bb, mir, kUnsignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 279 | break; |
| 280 | case kIPutShort: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 281 | nextMir = SpecialIPut(cUnit, &bb, mir, kSignedHalf, false, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 282 | break; |
| 283 | case kIPutWide: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 284 | nextMir = SpecialIPut(cUnit, &bb, mir, kLong, true, false); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 285 | break; |
| 286 | case kIdentity: |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 287 | nextMir = SpecialIdentity(cUnit, mir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 288 | break; |
| 289 | default: |
| 290 | return; |
| 291 | } |
| 292 | if (nextMir != NULL) { |
| 293 | cUnit->currentDalvikOffset = nextMir->offset; |
| 294 | if (specialCase != kIdentity) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 295 | GenPrintLabel(cUnit, nextMir); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 296 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 297 | NewLIR1(cUnit, kThumbBx, rARM_LR); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 298 | cUnit->coreSpillMask = 0; |
| 299 | cUnit->numCoreSpills = 0; |
| 300 | cUnit->fpSpillMask = 0; |
| 301 | cUnit->numFPSpills = 0; |
| 302 | cUnit->frameSize = 0; |
| 303 | cUnit->coreVmapTable.clear(); |
| 304 | cUnit->fpVmapTable.clear(); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * The sparse table in the literal pool is an array of <key,displacement> |
| 310 | * pairs. For each set, we'll load them as a pair using ldmia. |
| 311 | * This means that the register number of the temp we use for the key |
| 312 | * must be lower than the reg for the displacement. |
| 313 | * |
| 314 | * The test loop will look something like: |
| 315 | * |
| 316 | * adr rBase, <table> |
| 317 | * ldr rVal, [rARM_SP, vRegOff] |
| 318 | * mov rIdx, #tableSize |
| 319 | * lp: |
| 320 | * ldmia rBase!, {rKey, rDisp} |
| 321 | * sub rIdx, #1 |
| 322 | * cmp rVal, rKey |
| 323 | * ifeq |
| 324 | * add rARM_PC, rDisp ; This is the branch from which we compute displacement |
| 325 | * cbnz rIdx, lp |
| 326 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 327 | void GenSparseSwitch(CompilationUnit* cUnit, uint32_t tableOffset, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 328 | RegLocation rlSrc) |
| 329 | { |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 330 | const uint16_t* table = cUnit->insns + cUnit->currentDalvikOffset + tableOffset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 331 | if (cUnit->printMe) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 332 | DumpSparseSwitchTable(table); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 333 | } |
| 334 | // Add the table to the list - we'll process it later |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 335 | SwitchTable *tabRec = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 336 | static_cast<SwitchTable*>(NewMem(cUnit, sizeof(SwitchTable), true, kAllocData)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 337 | tabRec->table = table; |
| 338 | tabRec->vaddr = cUnit->currentDalvikOffset; |
| 339 | int size = table[1]; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 340 | tabRec->targets = static_cast<LIR**>(NewMem(cUnit, size * sizeof(LIR*), true, kAllocLIR)); |
| 341 | InsertGrowableList(cUnit, &cUnit->switchTables, reinterpret_cast<uintptr_t>(tabRec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 342 | |
| 343 | // Get the switch value |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 344 | rlSrc = LoadValue(cUnit, rlSrc, kCoreReg); |
| 345 | int rBase = AllocTemp(cUnit); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 346 | /* Allocate key and disp temps */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 347 | int rKey = AllocTemp(cUnit); |
| 348 | int rDisp = AllocTemp(cUnit); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 349 | // Make sure rKey's register number is less than rDisp's number for ldmia |
| 350 | if (rKey > rDisp) { |
| 351 | int tmp = rDisp; |
| 352 | rDisp = rKey; |
| 353 | rKey = tmp; |
| 354 | } |
| 355 | // Materialize a pointer to the switch table |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 356 | NewLIR3(cUnit, kThumb2Adr, rBase, 0, reinterpret_cast<uintptr_t>(tabRec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 357 | // Set up rIdx |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 358 | int rIdx = AllocTemp(cUnit); |
| 359 | LoadConstant(cUnit, rIdx, size); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 360 | // Establish loop branch target |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 361 | LIR* target = NewLIR0(cUnit, kPseudoTargetLabel); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 362 | // Load next key/disp |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 363 | NewLIR2(cUnit, kThumb2LdmiaWB, rBase, (1 << rKey) | (1 << rDisp)); |
| 364 | OpRegReg(cUnit, kOpCmp, rKey, rlSrc.lowReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 365 | // Go if match. NOTE: No instruction set switch here - must stay Thumb2 |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 366 | OpIT(cUnit, kArmCondEq, ""); |
| 367 | LIR* switchBranch = NewLIR1(cUnit, kThumb2AddPCR, rDisp); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 368 | tabRec->anchor = switchBranch; |
| 369 | // Needs to use setflags encoding here |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 370 | NewLIR3(cUnit, kThumb2SubsRRI12, rIdx, rIdx, 1); |
| 371 | OpCondBranch(cUnit, kCondNe, target); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 375 | void GenPackedSwitch(CompilationUnit* cUnit, uint32_t tableOffset, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 376 | RegLocation rlSrc) |
| 377 | { |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 378 | const uint16_t* table = cUnit->insns + cUnit->currentDalvikOffset + tableOffset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 379 | if (cUnit->printMe) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 380 | DumpPackedSwitchTable(table); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 381 | } |
| 382 | // Add the table to the list - we'll process it later |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 383 | SwitchTable *tabRec = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 384 | static_cast<SwitchTable*>(NewMem(cUnit, sizeof(SwitchTable), true, kAllocData)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 385 | tabRec->table = table; |
| 386 | tabRec->vaddr = cUnit->currentDalvikOffset; |
| 387 | int size = table[1]; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 388 | tabRec->targets = static_cast<LIR**>(NewMem(cUnit, size * sizeof(LIR*), true, kAllocLIR)); |
| 389 | InsertGrowableList(cUnit, &cUnit->switchTables, reinterpret_cast<uintptr_t>(tabRec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 390 | |
| 391 | // Get the switch value |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 392 | rlSrc = LoadValue(cUnit, rlSrc, kCoreReg); |
| 393 | int tableBase = AllocTemp(cUnit); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 394 | // Materialize a pointer to the switch table |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 395 | NewLIR3(cUnit, kThumb2Adr, tableBase, 0, reinterpret_cast<uintptr_t>(tabRec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 396 | int lowKey = s4FromSwitchData(&table[2]); |
| 397 | int keyReg; |
| 398 | // Remove the bias, if necessary |
| 399 | if (lowKey == 0) { |
| 400 | keyReg = rlSrc.lowReg; |
| 401 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 402 | keyReg = AllocTemp(cUnit); |
| 403 | OpRegRegImm(cUnit, kOpSub, keyReg, rlSrc.lowReg, lowKey); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 404 | } |
| 405 | // Bounds check - if < 0 or >= size continue following switch |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 406 | OpRegImm(cUnit, kOpCmp, keyReg, size-1); |
| 407 | LIR* branchOver = OpCondBranch(cUnit, kCondHi, NULL); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 408 | |
| 409 | // Load the displacement from the switch table |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 410 | int dispReg = AllocTemp(cUnit); |
| 411 | LoadBaseIndexed(cUnit, tableBase, keyReg, dispReg, 2, kWord); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 412 | |
| 413 | // ..and go! NOTE: No instruction set switch here - must stay Thumb2 |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 414 | LIR* switchBranch = NewLIR1(cUnit, kThumb2AddPCR, dispReg); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 415 | tabRec->anchor = switchBranch; |
| 416 | |
| 417 | /* branchOver target here */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 418 | LIR* target = NewLIR0(cUnit, kPseudoTargetLabel); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 419 | branchOver->target = target; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* |
| 423 | * Array data table format: |
| 424 | * ushort ident = 0x0300 magic value |
| 425 | * ushort width width of each element in the table |
| 426 | * uint size number of elements in the table |
| 427 | * ubyte data[size*width] table of data values (may contain a single-byte |
| 428 | * padding at the end) |
| 429 | * |
| 430 | * Total size is 4+(width * size + 1)/2 16-bit code units. |
| 431 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 432 | void GenFillArrayData(CompilationUnit* cUnit, uint32_t tableOffset, RegLocation rlSrc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 433 | { |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 434 | const uint16_t* table = cUnit->insns + cUnit->currentDalvikOffset + tableOffset; |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 435 | // Add the table to the list - we'll process it later |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 436 | FillArrayData *tabRec = |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 437 | static_cast<FillArrayData*>(NewMem(cUnit, sizeof(FillArrayData), true, kAllocData)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 438 | tabRec->table = table; |
| 439 | tabRec->vaddr = cUnit->currentDalvikOffset; |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 440 | uint16_t width = tabRec->table[1]; |
| 441 | uint32_t size = tabRec->table[2] | ((static_cast<uint32_t>(tabRec->table[3])) << 16); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 442 | tabRec->size = (size * width) + 8; |
| 443 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 444 | InsertGrowableList(cUnit, &cUnit->fillArrayData, reinterpret_cast<uintptr_t>(tabRec)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 445 | |
| 446 | // Making a call - use explicit registers |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 447 | FlushAllRegs(cUnit); /* Everything to home location */ |
| 448 | LoadValueDirectFixed(cUnit, rlSrc, r0); |
| 449 | LoadWordDisp(cUnit, rARM_SELF, ENTRYPOINT_OFFSET(pHandleFillArrayDataFromCode), |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 450 | rARM_LR); |
| 451 | // Materialize a pointer to the fill data image |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 452 | NewLIR3(cUnit, kThumb2Adr, r1, 0, reinterpret_cast<uintptr_t>(tabRec)); |
| 453 | ClobberCalleeSave(cUnit); |
| 454 | LIR* callInst = OpReg(cUnit, kOpBlx, rARM_LR); |
| 455 | MarkSafepointPC(cUnit, callInst); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Handle simple case (thin lock) inline. If it's complicated, bail |
| 460 | * out to the heavyweight lock/unlock routines. We'll use dedicated |
| 461 | * registers here in order to be in the right position in case we |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 462 | * to bail to oat[Lock/Unlock]Object(self, object) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 463 | * |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 464 | * r0 -> self pointer [arg0 for oat[Lock/Unlock]Object |
| 465 | * r1 -> object [arg1 for oat[Lock/Unlock]Object |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 466 | * r2 -> intial contents of object->lock, later result of strex |
| 467 | * r3 -> self->threadId |
| 468 | * r12 -> allow to be used by utilities as general temp |
| 469 | * |
| 470 | * The result of the strex is 0 if we acquire the lock. |
| 471 | * |
| 472 | * See comments in Sync.c for the layout of the lock word. |
| 473 | * Of particular interest to this code is the test for the |
| 474 | * simple case - which we handle inline. For monitor enter, the |
| 475 | * simple case is thin lock, held by no-one. For monitor exit, |
| 476 | * the simple case is thin lock, held by the unlocking thread with |
| 477 | * a recurse count of 0. |
| 478 | * |
| 479 | * A minor complication is that there is a field in the lock word |
| 480 | * unrelated to locking: the hash state. This field must be ignored, but |
| 481 | * preserved. |
| 482 | * |
| 483 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 484 | void GenMonitorEnter(CompilationUnit* cUnit, int optFlags, RegLocation rlSrc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 485 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 486 | FlushAllRegs(cUnit); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 487 | DCHECK_EQ(LW_SHAPE_THIN, 0); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 488 | LoadValueDirectFixed(cUnit, rlSrc, r0); // Get obj |
| 489 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 490 | GenNullCheck(cUnit, rlSrc.sRegLow, r0, optFlags); |
| 491 | LoadWordDisp(cUnit, rARM_SELF, Thread::ThinLockIdOffset().Int32Value(), r2); |
| 492 | NewLIR3(cUnit, kThumb2Ldrex, r1, r0, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 493 | Object::MonitorOffset().Int32Value() >> 2); // Get object->lock |
| 494 | // Align owner |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 495 | OpRegImm(cUnit, kOpLsl, r2, LW_LOCK_OWNER_SHIFT); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 496 | // Is lock unheld on lock or held by us (==threadId) on unlock? |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 497 | NewLIR4(cUnit, kThumb2Bfi, r2, r1, 0, LW_LOCK_OWNER_SHIFT - 1); |
| 498 | NewLIR3(cUnit, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1); |
| 499 | OpRegImm(cUnit, kOpCmp, r1, 0); |
| 500 | OpIT(cUnit, kArmCondEq, ""); |
| 501 | NewLIR4(cUnit, kThumb2Strex, r1, r2, r0, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 502 | Object::MonitorOffset().Int32Value() >> 2); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 503 | OpRegImm(cUnit, kOpCmp, r1, 0); |
| 504 | OpIT(cUnit, kArmCondNe, "T"); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 505 | // Go expensive route - artLockObjectFromCode(self, obj); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 506 | LoadWordDisp(cUnit, rARM_SELF, ENTRYPOINT_OFFSET(pLockObjectFromCode), rARM_LR); |
| 507 | ClobberCalleeSave(cUnit); |
| 508 | LIR* callInst = OpReg(cUnit, kOpBlx, rARM_LR); |
| 509 | MarkSafepointPC(cUnit, callInst); |
| 510 | GenMemBarrier(cUnit, kLoadLoad); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /* |
| 514 | * For monitor unlock, we don't have to use ldrex/strex. Once |
| 515 | * we've determined that the lock is thin and that we own it with |
| 516 | * a zero recursion count, it's safe to punch it back to the |
| 517 | * initial, unlock thin state with a store word. |
| 518 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 519 | void GenMonitorExit(CompilationUnit* cUnit, int optFlags, RegLocation rlSrc) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 520 | { |
| 521 | DCHECK_EQ(LW_SHAPE_THIN, 0); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 522 | FlushAllRegs(cUnit); |
| 523 | LoadValueDirectFixed(cUnit, rlSrc, r0); // Get obj |
| 524 | LockCallTemps(cUnit); // Prepare for explicit register usage |
| 525 | GenNullCheck(cUnit, rlSrc.sRegLow, r0, optFlags); |
| 526 | LoadWordDisp(cUnit, r0, Object::MonitorOffset().Int32Value(), r1); // Get lock |
| 527 | LoadWordDisp(cUnit, rARM_SELF, Thread::ThinLockIdOffset().Int32Value(), r2); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 528 | // Is lock unheld on lock or held by us (==threadId) on unlock? |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 529 | OpRegRegImm(cUnit, kOpAnd, r3, r1, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 530 | (LW_HASH_STATE_MASK << LW_HASH_STATE_SHIFT)); |
| 531 | // Align owner |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 532 | OpRegImm(cUnit, kOpLsl, r2, LW_LOCK_OWNER_SHIFT); |
| 533 | NewLIR3(cUnit, kThumb2Bfc, r1, LW_HASH_STATE_SHIFT, LW_LOCK_OWNER_SHIFT - 1); |
| 534 | OpRegReg(cUnit, kOpSub, r1, r2); |
| 535 | OpIT(cUnit, kArmCondEq, "EE"); |
| 536 | StoreWordDisp(cUnit, r0, Object::MonitorOffset().Int32Value(), r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 537 | // Go expensive route - UnlockObjectFromCode(obj); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 538 | LoadWordDisp(cUnit, rARM_SELF, ENTRYPOINT_OFFSET(pUnlockObjectFromCode), rARM_LR); |
| 539 | ClobberCalleeSave(cUnit); |
| 540 | LIR* callInst = OpReg(cUnit, kOpBlx, rARM_LR); |
| 541 | MarkSafepointPC(cUnit, callInst); |
| 542 | GenMemBarrier(cUnit, kStoreLoad); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | /* |
| 546 | * Mark garbage collection card. Skip if the value we're storing is null. |
| 547 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 548 | void MarkGCCard(CompilationUnit* cUnit, int valReg, int tgtAddrReg) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 549 | { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 550 | int regCardBase = AllocTemp(cUnit); |
| 551 | int regCardNo = AllocTemp(cUnit); |
| 552 | LIR* branchOver = OpCmpImmBranch(cUnit, kCondEq, valReg, 0, NULL); |
| 553 | LoadWordDisp(cUnit, rARM_SELF, Thread::CardTableOffset().Int32Value(), regCardBase); |
| 554 | OpRegRegImm(cUnit, kOpLsr, regCardNo, tgtAddrReg, CardTable::kCardShift); |
| 555 | StoreBaseIndexed(cUnit, regCardBase, regCardNo, regCardBase, 0, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 556 | kUnsignedByte); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 557 | LIR* target = NewLIR0(cUnit, kPseudoTargetLabel); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 558 | branchOver->target = target; |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 559 | FreeTemp(cUnit, regCardBase); |
| 560 | FreeTemp(cUnit, regCardNo); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 561 | } |
| 562 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 563 | void GenEntrySequence(CompilationUnit* cUnit, RegLocation* ArgLocs, |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 564 | RegLocation rlMethod) |
| 565 | { |
| 566 | int spillCount = cUnit->numCoreSpills + cUnit->numFPSpills; |
| 567 | /* |
| 568 | * On entry, r0, r1, r2 & r3 are live. Let the register allocation |
| 569 | * mechanism know so it doesn't try to use any of them when |
| 570 | * expanding the frame or flushing. This leaves the utility |
| 571 | * code with a single temp: r12. This should be enough. |
| 572 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 573 | LockTemp(cUnit, r0); |
| 574 | LockTemp(cUnit, r1); |
| 575 | LockTemp(cUnit, r2); |
| 576 | LockTemp(cUnit, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 577 | |
| 578 | /* |
| 579 | * We can safely skip the stack overflow check if we're |
| 580 | * a leaf *and* our frame size < fudge factor. |
| 581 | */ |
| 582 | bool skipOverflowCheck = ((cUnit->attrs & METHOD_IS_LEAF) && |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 583 | (static_cast<size_t>(cUnit->frameSize) < |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 584 | Thread::kStackOverflowReservedBytes)); |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 585 | NewLIR0(cUnit, kPseudoMethodEntry); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 586 | if (!skipOverflowCheck) { |
| 587 | /* Load stack limit */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 588 | LoadWordDisp(cUnit, rARM_SELF, Thread::StackEndOffset().Int32Value(), r12); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 589 | } |
| 590 | /* Spill core callee saves */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 591 | NewLIR1(cUnit, kThumb2Push, cUnit->coreSpillMask); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 592 | /* Need to spill any FP regs? */ |
| 593 | if (cUnit->numFPSpills) { |
| 594 | /* |
| 595 | * NOTE: fp spills are a little different from core spills in that |
| 596 | * they are pushed as a contiguous block. When promoting from |
| 597 | * the fp set, we must allocate all singles from s16..highest-promoted |
| 598 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 599 | NewLIR1(cUnit, kThumb2VPushCS, cUnit->numFPSpills); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 600 | } |
| 601 | if (!skipOverflowCheck) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 602 | OpRegRegImm(cUnit, kOpSub, rARM_LR, rARM_SP, cUnit->frameSize - (spillCount * 4)); |
| 603 | GenRegRegCheck(cUnit, kCondCc, rARM_LR, r12, kThrowStackOverflow); |
| 604 | OpRegCopy(cUnit, rARM_SP, rARM_LR); // Establish stack |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 605 | } else { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 606 | OpRegImm(cUnit, kOpSub, rARM_SP, cUnit->frameSize - (spillCount * 4)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 607 | } |
| 608 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 609 | FlushIns(cUnit, ArgLocs, rlMethod); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 610 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 611 | FreeTemp(cUnit, r0); |
| 612 | FreeTemp(cUnit, r1); |
| 613 | FreeTemp(cUnit, r2); |
| 614 | FreeTemp(cUnit, r3); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 615 | } |
| 616 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 617 | void GenExitSequence(CompilationUnit* cUnit) |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 618 | { |
| 619 | int spillCount = cUnit->numCoreSpills + cUnit->numFPSpills; |
| 620 | /* |
| 621 | * In the exit path, r0/r1 are live - make sure they aren't |
| 622 | * allocated by the register utilities as temps. |
| 623 | */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 624 | LockTemp(cUnit, r0); |
| 625 | LockTemp(cUnit, r1); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 626 | |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 627 | NewLIR0(cUnit, kPseudoMethodExit); |
| 628 | OpRegImm(cUnit, kOpAdd, rARM_SP, cUnit->frameSize - (spillCount * 4)); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 629 | /* Need to restore any FP callee saves? */ |
| 630 | if (cUnit->numFPSpills) { |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 631 | NewLIR1(cUnit, kThumb2VPopCS, cUnit->numFPSpills); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 632 | } |
| 633 | if (cUnit->coreSpillMask & (1 << rARM_LR)) { |
| 634 | /* Unspill rARM_LR to rARM_PC */ |
| 635 | cUnit->coreSpillMask &= ~(1 << rARM_LR); |
| 636 | cUnit->coreSpillMask |= (1 << rARM_PC); |
| 637 | } |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 638 | NewLIR1(cUnit, kThumb2Pop, cUnit->coreSpillMask); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 639 | if (!(cUnit->coreSpillMask & (1 << rARM_PC))) { |
| 640 | /* We didn't pop to rARM_PC, so must do a bv rARM_LR */ |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame^] | 641 | NewLIR1(cUnit, kThumbBx, rARM_LR); |
buzbee | efc6369 | 2012-11-14 16:31:52 -0800 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
| 645 | } // namespace art |