buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 17 | #include "oat/runtime/oat_support_entrypoints.h" |
| 18 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 19 | namespace art { |
| 20 | |
| 21 | /* |
| 22 | * This source files contains "gen" codegen routines that should |
| 23 | * be applicable to most targets. Only mid-level support utilities |
| 24 | * and "op" calls may be used here. |
| 25 | */ |
| 26 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 27 | typedef int (*NextCallInsn)(CompilationUnit*, MIR*, int, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 28 | uint32_t methodIdx, uintptr_t directCode, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 29 | uintptr_t directMethod, InvokeType type); |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 30 | LIR* opCondBranch(CompilationUnit* cUnit, ConditionCode cc, LIR* target); |
| 31 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 32 | /* |
| 33 | * If there are any ins passed in registers that have not been promoted |
| 34 | * to a callee-save register, flush them to the frame. Perform intial |
| 35 | * assignment of promoted arguments. |
| 36 | */ |
| 37 | void flushIns(CompilationUnit* cUnit) |
| 38 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 39 | /* |
| 40 | * Dummy up a RegLocation for the incoming Method* |
| 41 | * It will attempt to keep rARG0 live (or copy it to home location |
| 42 | * if promoted). |
| 43 | */ |
| 44 | RegLocation rlSrc = cUnit->regLocation[cUnit->methodSReg]; |
| 45 | RegLocation rlMethod = cUnit->regLocation[cUnit->methodSReg]; |
| 46 | rlSrc.location = kLocPhysReg; |
| 47 | rlSrc.lowReg = rARG0; |
| 48 | rlSrc.home = false; |
| 49 | oatMarkLive(cUnit, rlSrc.lowReg, rlSrc.sRegLow); |
| 50 | storeValue(cUnit, rlMethod, rlSrc); |
| 51 | // If Method* has been promoted, explicitly flush |
| 52 | if (rlMethod.location == kLocPhysReg) { |
| 53 | storeWordDisp(cUnit, rSP, 0, rARG0); |
| 54 | } |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 55 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 56 | if (cUnit->numIns == 0) |
| 57 | return; |
| 58 | const int numArgRegs = 3; |
| 59 | static int argRegs[] = {rARG1, rARG2, rARG3}; |
| 60 | int startVReg = cUnit->numDalvikRegisters - cUnit->numIns; |
| 61 | /* |
| 62 | * Copy incoming arguments to their proper home locations. |
| 63 | * NOTE: an older version of dx had an issue in which |
| 64 | * it would reuse static method argument registers. |
| 65 | * This could result in the same Dalvik virtual register |
| 66 | * being promoted to both core and fp regs. To account for this, |
| 67 | * we only copy to the corresponding promoted physical register |
| 68 | * if it matches the type of the SSA name for the incoming |
| 69 | * argument. It is also possible that long and double arguments |
| 70 | * end up half-promoted. In those cases, we must flush the promoted |
| 71 | * half to memory as well. |
| 72 | */ |
| 73 | for (int i = 0; i < cUnit->numIns; i++) { |
| 74 | PromotionMap* vMap = &cUnit->promotionMap[startVReg + i]; |
| 75 | if (i < numArgRegs) { |
| 76 | // If arriving in register |
| 77 | bool needFlush = true; |
| 78 | RegLocation* tLoc = &cUnit->regLocation[startVReg + i]; |
| 79 | if ((vMap->coreLocation == kLocPhysReg) && !tLoc->fp) { |
| 80 | opRegCopy(cUnit, vMap->coreReg, argRegs[i]); |
| 81 | needFlush = false; |
| 82 | } else if ((vMap->fpLocation == kLocPhysReg) && tLoc->fp) { |
| 83 | opRegCopy(cUnit, vMap->fpReg, argRegs[i]); |
| 84 | needFlush = false; |
| 85 | } else { |
| 86 | needFlush = true; |
| 87 | } |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 88 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 89 | // For wide args, force flush if only half is promoted |
| 90 | if (tLoc->wide) { |
| 91 | PromotionMap* pMap = vMap + (tLoc->highWord ? -1 : +1); |
| 92 | needFlush |= (pMap->coreLocation != vMap->coreLocation) || |
| 93 | (pMap->fpLocation != vMap->fpLocation); |
| 94 | } |
| 95 | if (needFlush) { |
| 96 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
| 97 | argRegs[i], kWord); |
| 98 | } |
| 99 | } else { |
| 100 | // If arriving in frame & promoted |
| 101 | if (vMap->coreLocation == kLocPhysReg) { |
| 102 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
| 103 | vMap->coreReg); |
| 104 | } |
| 105 | if (vMap->fpLocation == kLocPhysReg) { |
| 106 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
| 107 | vMap->fpReg); |
| 108 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 109 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 110 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 111 | } |
| 112 | |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 113 | void scanMethodLiteralPool(CompilationUnit* cUnit, LIR** methodTarget, LIR** codeTarget, const DexFile* dexFile, uint32_t dexMethodIdx) |
| 114 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 115 | LIR* curTarget = cUnit->methodLiteralList; |
| 116 | LIR* nextTarget = curTarget != NULL ? curTarget->next : NULL; |
| 117 | while (curTarget != NULL && nextTarget != NULL) { |
| 118 | if (curTarget->operands[0] == (int)dexFile && |
| 119 | nextTarget->operands[0] == (int)dexMethodIdx) { |
| 120 | *codeTarget = curTarget; |
| 121 | *methodTarget = nextTarget; |
| 122 | DCHECK((*codeTarget)->next == *methodTarget); |
| 123 | DCHECK_EQ((*codeTarget)->operands[0], (int)dexFile); |
| 124 | DCHECK_EQ((*methodTarget)->operands[0], (int)dexMethodIdx); |
| 125 | break; |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 126 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 127 | curTarget = nextTarget->next; |
| 128 | nextTarget = curTarget != NULL ? curTarget->next : NULL; |
| 129 | } |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame] | 130 | } |
| 131 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 132 | /* |
Elliott Hughes | bdf6c3d | 2012-03-20 13:43:53 -0700 | [diff] [blame] | 133 | * Bit of a hack here - in the absence of a real scheduling pass, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 134 | * emit the next instruction in static & direct invoke sequences. |
| 135 | */ |
| 136 | int nextSDCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 137 | int state, uint32_t dexIdx, uint32_t unused, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 138 | uintptr_t directCode, uintptr_t directMethod, |
| 139 | InvokeType type) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 140 | { |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 141 | #if !defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 142 | directCode = 0; |
| 143 | directMethod = 0; |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 144 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 145 | if (directCode != 0 && directMethod != 0) { |
| 146 | switch (state) { |
| 147 | case 0: // Get the current Method* [sets rARG0] |
| 148 | if (directCode != (uintptr_t)-1) { |
| 149 | loadConstant(cUnit, rINVOKE_TGT, directCode); |
| 150 | } else { |
| 151 | LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0); |
| 152 | if (dataTarget == NULL) { |
| 153 | dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx); |
| 154 | dataTarget->operands[1] = type; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 155 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 156 | #if defined(TARGET_ARM) |
| 157 | LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset, |
| 158 | kThumb2LdrPcRel12, rINVOKE_TGT, 0, 0, 0, 0, |
| 159 | dataTarget); |
| 160 | oatAppendLIR(cUnit, loadPcRel); |
| 161 | #else |
| 162 | UNIMPLEMENTED(FATAL) << (void*)dataTarget; |
| 163 | #endif |
| 164 | } |
| 165 | if (directMethod != (uintptr_t)-1) { |
| 166 | loadConstant(cUnit, rARG0, directMethod); |
| 167 | } else { |
| 168 | LIR* dataTarget = scanLiteralPool(cUnit->methodLiteralList, dexIdx, 0); |
| 169 | if (dataTarget == NULL) { |
| 170 | dataTarget = addWordData(cUnit, &cUnit->methodLiteralList, dexIdx); |
| 171 | dataTarget->operands[1] = type; |
| 172 | } |
| 173 | #if defined(TARGET_ARM) |
| 174 | LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset, |
| 175 | kThumb2LdrPcRel12, rARG0, 0, 0, 0, 0, |
| 176 | dataTarget); |
| 177 | oatAppendLIR(cUnit, loadPcRel); |
| 178 | #else |
| 179 | UNIMPLEMENTED(FATAL) << (void*)dataTarget; |
| 180 | #endif |
| 181 | } |
| 182 | break; |
| 183 | default: |
| 184 | return -1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 185 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 186 | } else { |
| 187 | switch (state) { |
| 188 | case 0: // Get the current Method* [sets rARG0] |
| 189 | // TUNING: we can save a reg copy if Method* has been promoted |
| 190 | loadCurrMethodDirect(cUnit, rARG0); |
| 191 | break; |
| 192 | case 1: // Get method->dex_cache_resolved_methods_ |
| 193 | loadWordDisp(cUnit, rARG0, |
| 194 | Method::DexCacheResolvedMethodsOffset().Int32Value(), |
| 195 | rARG0); |
| 196 | // Set up direct code if known. |
| 197 | if (directCode != 0) { |
| 198 | if (directCode != (uintptr_t)-1) { |
| 199 | loadConstant(cUnit, rINVOKE_TGT, directCode); |
| 200 | } else { |
| 201 | LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0); |
| 202 | if (dataTarget == NULL) { |
| 203 | dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx); |
| 204 | dataTarget->operands[1] = type; |
| 205 | } |
| 206 | #if defined(TARGET_ARM) |
| 207 | LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset, |
| 208 | kThumb2LdrPcRel12, rINVOKE_TGT, 0, 0, 0, 0, |
| 209 | dataTarget); |
| 210 | oatAppendLIR(cUnit, loadPcRel); |
| 211 | #else |
| 212 | UNIMPLEMENTED(FATAL) << (void*)dataTarget; |
| 213 | #endif |
| 214 | } |
| 215 | } |
| 216 | break; |
| 217 | case 2: // Grab target method* |
| 218 | loadWordDisp(cUnit, rARG0, |
| 219 | Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4, |
| 220 | rARG0); |
| 221 | break; |
| 222 | #if !defined(TARGET_X86) |
| 223 | case 3: // Grab the code from the method* |
| 224 | if (directCode == 0) { |
| 225 | loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(), |
| 226 | rINVOKE_TGT); |
| 227 | } |
| 228 | break; |
| 229 | #endif |
| 230 | default: |
| 231 | return -1; |
| 232 | } |
| 233 | } |
| 234 | return state + 1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /* |
Elliott Hughes | bdf6c3d | 2012-03-20 13:43:53 -0700 | [diff] [blame] | 238 | * Bit of a hack here - in the absence of a real scheduling pass, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 239 | * emit the next instruction in a virtual invoke sequence. |
| 240 | * We can use rLR as a temp prior to target address loading |
| 241 | * Note also that we'll load the first argument ("this") into |
| 242 | * rARG1 here rather than the standard loadArgRegs. |
| 243 | */ |
| 244 | int nextVCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 245 | int state, uint32_t dexIdx, uint32_t methodIdx, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 246 | uintptr_t unused, uintptr_t unused2, InvokeType unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 247 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 248 | RegLocation rlArg; |
| 249 | /* |
| 250 | * This is the fast path in which the target virtual method is |
| 251 | * fully resolved at compile time. |
| 252 | */ |
| 253 | switch (state) { |
| 254 | case 0: // Get "this" [set rARG1] |
| 255 | rlArg = oatGetSrc(cUnit, mir, 0); |
| 256 | loadValueDirectFixed(cUnit, rlArg, rARG1); |
| 257 | break; |
| 258 | case 1: // Is "this" null? [use rARG1] |
| 259 | genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
| 260 | // get this->klass_ [use rARG1, set rINVOKE_TGT] |
| 261 | loadWordDisp(cUnit, rARG1, Object::ClassOffset().Int32Value(), |
| 262 | rINVOKE_TGT); |
| 263 | break; |
| 264 | case 2: // Get this->klass_->vtable [usr rINVOKE_TGT, set rINVOKE_TGT] |
| 265 | loadWordDisp(cUnit, rINVOKE_TGT, Class::VTableOffset().Int32Value(), |
| 266 | rINVOKE_TGT); |
| 267 | break; |
| 268 | case 3: // Get target method [use rINVOKE_TGT, set rARG0] |
| 269 | loadWordDisp(cUnit, rINVOKE_TGT, (methodIdx * 4) + |
| 270 | Array::DataOffset(sizeof(Object*)).Int32Value(), rARG0); |
| 271 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 272 | #if !defined(TARGET_X86) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 273 | case 4: // Get the compiled code address [uses rARG0, sets rINVOKE_TGT] |
| 274 | loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(), |
| 275 | rINVOKE_TGT); |
| 276 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 277 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 278 | default: |
| 279 | return -1; |
| 280 | } |
| 281 | return state + 1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 282 | } |
| 283 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 284 | int nextInvokeInsnSP(CompilationUnit* cUnit, MIR* mir, int trampoline, |
| 285 | int state, uint32_t dexIdx, uint32_t methodIdx) |
| 286 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 287 | /* |
| 288 | * This handles the case in which the base method is not fully |
| 289 | * resolved at compile time, we bail to a runtime helper. |
| 290 | */ |
| 291 | if (state == 0) { |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 292 | #if !defined(TARGET_X86) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 293 | // Load trampoline target |
| 294 | loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT); |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 295 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 296 | // Load rARG0 with method index |
| 297 | loadConstant(cUnit, rARG0, dexIdx); |
| 298 | return 1; |
| 299 | } |
| 300 | return -1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | int nextStaticCallInsnSP(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 304 | int state, uint32_t dexIdx, uint32_t methodIdx, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 305 | uintptr_t unused, uintptr_t unused2, |
| 306 | InvokeType unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 307 | { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 308 | int trampoline = ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 309 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 310 | } |
| 311 | |
| 312 | int nextDirectCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 313 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 314 | uintptr_t unused2, InvokeType unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 315 | { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 316 | int trampoline = ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 317 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 318 | } |
| 319 | |
| 320 | int nextSuperCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 321 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 322 | uintptr_t unused2, InvokeType unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 323 | { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 324 | int trampoline = ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 325 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 326 | } |
| 327 | |
| 328 | int nextVCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 329 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 330 | uintptr_t unused2, InvokeType unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 331 | { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 332 | int trampoline = ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 333 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | * All invoke-interface calls bounce off of art_invoke_interface_trampoline, |
| 338 | * which will locate the target and continue on via a tail call. |
| 339 | */ |
| 340 | int nextInterfaceCallInsn(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 341 | uint32_t dexIdx, uint32_t unused, uintptr_t unused2, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 342 | uintptr_t unused3, InvokeType unused4) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 343 | { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 344 | int trampoline = ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 345 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 346 | } |
| 347 | |
| 348 | int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit, MIR* mir, |
| 349 | int state, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 350 | uint32_t unused, uintptr_t unused2, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 351 | uintptr_t unused3, InvokeType unused4) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 352 | { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 353 | int trampoline = ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 354 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 355 | } |
| 356 | |
| 357 | int loadArgRegs(CompilationUnit* cUnit, MIR* mir, DecodedInstruction* dInsn, |
| 358 | int callState, NextCallInsn nextCallInsn, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 359 | uint32_t methodIdx, uintptr_t directCode, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 360 | uintptr_t directMethod, InvokeType type, bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 361 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 362 | int lastArgReg = rARG3; |
| 363 | int nextReg = rARG1; |
| 364 | int nextArg = 0; |
| 365 | if (skipThis) { |
| 366 | nextReg++; |
| 367 | nextArg++; |
| 368 | } |
| 369 | for (; (nextReg <= lastArgReg) && (nextArg < mir->ssaRep->numUses); nextReg++) { |
| 370 | RegLocation rlArg = oatGetRawSrc(cUnit, mir, nextArg++); |
| 371 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 372 | if (rlArg.wide && (nextReg <= rARG2)) { |
| 373 | loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1); |
| 374 | nextReg++; |
| 375 | nextArg++; |
| 376 | } else { |
| 377 | rlArg.wide = false; |
| 378 | loadValueDirectFixed(cUnit, rlArg, nextReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 379 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 380 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 381 | directCode, directMethod, type); |
| 382 | } |
| 383 | return callState; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* |
| 387 | * Load up to 5 arguments, the first three of which will be in |
| 388 | * rARG1 .. rARG3. On entry rARG0 contains the current method pointer, |
| 389 | * and as part of the load sequence, it must be replaced with |
| 390 | * the target method pointer. Note, this may also be called |
| 391 | * for "range" variants if the number of arguments is 5 or fewer. |
| 392 | */ |
| 393 | int genDalvikArgsNoRange(CompilationUnit* cUnit, MIR* mir, |
| 394 | DecodedInstruction* dInsn, int callState, |
| 395 | LIR** pcrLabel, NextCallInsn nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 396 | uint32_t dexIdx, uint32_t methodIdx, |
| 397 | uintptr_t directCode, uintptr_t directMethod, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 398 | InvokeType type, bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 399 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 400 | RegLocation rlArg; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 401 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 402 | /* If no arguments, just return */ |
| 403 | if (dInsn->vA == 0) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 404 | return callState; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 405 | |
| 406 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 407 | directCode, directMethod, type); |
| 408 | |
| 409 | DCHECK_LE(dInsn->vA, 5U); |
| 410 | if (dInsn->vA > 3) { |
| 411 | uint32_t nextUse = 3; |
| 412 | //Detect special case of wide arg spanning arg3/arg4 |
| 413 | RegLocation rlUse0 = oatGetRawSrc(cUnit, mir, 0); |
| 414 | RegLocation rlUse1 = oatGetRawSrc(cUnit, mir, 1); |
| 415 | RegLocation rlUse2 = oatGetRawSrc(cUnit, mir, 2); |
| 416 | if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) && |
| 417 | rlUse2.wide) { |
| 418 | int reg = -1; |
| 419 | // Wide spans, we need the 2nd half of uses[2]. |
| 420 | rlArg = oatUpdateLocWide(cUnit, rlUse2); |
| 421 | if (rlArg.location == kLocPhysReg) { |
| 422 | reg = rlArg.highReg; |
| 423 | } else { |
| 424 | // rARG2 & rARG3 can safely be used here |
| 425 | reg = rARG3; |
| 426 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg); |
| 427 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
| 428 | methodIdx, directCode, directMethod, type); |
| 429 | } |
| 430 | storeBaseDisp(cUnit, rSP, (nextUse + 1) * 4, reg, kWord); |
| 431 | storeBaseDisp(cUnit, rSP, 16 /* (3+1)*4 */, reg, kWord); |
| 432 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 433 | directCode, directMethod, type); |
| 434 | nextUse++; |
| 435 | } |
| 436 | // Loop through the rest |
| 437 | while (nextUse < dInsn->vA) { |
| 438 | int lowReg; |
| 439 | int highReg = -1; |
| 440 | rlArg = oatGetRawSrc(cUnit, mir, nextUse); |
| 441 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 442 | if (rlArg.location == kLocPhysReg) { |
| 443 | lowReg = rlArg.lowReg; |
| 444 | highReg = rlArg.highReg; |
| 445 | } else { |
| 446 | lowReg = rARG2; |
| 447 | if (rlArg.wide) { |
| 448 | highReg = rARG3; |
| 449 | loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg); |
| 450 | } else { |
| 451 | loadValueDirectFixed(cUnit, rlArg, lowReg); |
| 452 | } |
| 453 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
| 454 | methodIdx, directCode, directMethod, type); |
| 455 | } |
| 456 | int outsOffset = (nextUse + 1) * 4; |
| 457 | if (rlArg.wide) { |
| 458 | storeBaseDispWide(cUnit, rSP, outsOffset, lowReg, highReg); |
| 459 | nextUse += 2; |
| 460 | } else { |
| 461 | storeWordDisp(cUnit, rSP, outsOffset, lowReg); |
| 462 | nextUse++; |
| 463 | } |
| 464 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 465 | directCode, directMethod, type); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
| 470 | dexIdx, methodIdx, directCode, directMethod, |
| 471 | type, skipThis); |
| 472 | |
| 473 | if (pcrLabel) { |
| 474 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
| 475 | } |
| 476 | return callState; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | /* |
| 480 | * May have 0+ arguments (also used for jumbo). Note that |
| 481 | * source virtual registers may be in physical registers, so may |
| 482 | * need to be flushed to home location before copying. This |
| 483 | * applies to arg3 and above (see below). |
| 484 | * |
| 485 | * Two general strategies: |
| 486 | * If < 20 arguments |
| 487 | * Pass args 3-18 using vldm/vstm block copy |
| 488 | * Pass arg0, arg1 & arg2 in rARG1-rARG3 |
| 489 | * If 20+ arguments |
| 490 | * Pass args arg19+ using memcpy block copy |
| 491 | * Pass arg0, arg1 & arg2 in rARG1-rARG3 |
| 492 | * |
| 493 | */ |
| 494 | int genDalvikArgsRange(CompilationUnit* cUnit, MIR* mir, |
| 495 | DecodedInstruction* dInsn, int callState, |
| 496 | LIR** pcrLabel, NextCallInsn nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 497 | uint32_t dexIdx, uint32_t methodIdx, |
| 498 | uintptr_t directCode, uintptr_t directMethod, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 499 | InvokeType type, bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 500 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 501 | int firstArg = dInsn->vC; |
| 502 | int numArgs = dInsn->vA; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 503 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 504 | // If we can treat it as non-range (Jumbo ops will use range form) |
| 505 | if (numArgs <= 5) |
| 506 | return genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pcrLabel, |
| 507 | nextCallInsn, dexIdx, methodIdx, |
| 508 | directCode, directMethod, type, skipThis); |
| 509 | /* |
| 510 | * Make sure range list doesn't span the break between in normal |
| 511 | * Dalvik vRegs and the ins. |
| 512 | */ |
| 513 | int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow; |
| 514 | int boundaryReg = cUnit->numDalvikRegisters - cUnit->numIns; |
| 515 | if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) { |
| 516 | LOG(FATAL) << "Argument list spanned locals & args"; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | * First load the non-register arguments. Both forms expect all |
| 521 | * of the source arguments to be in their home frame location, so |
| 522 | * scan the sReg names and flush any that have been promoted to |
| 523 | * frame backing storage. |
| 524 | */ |
| 525 | // Scan the rest of the args - if in physReg flush to memory |
| 526 | for (int nextArg = 0; nextArg < numArgs;) { |
| 527 | RegLocation loc = oatGetRawSrc(cUnit, mir, nextArg); |
| 528 | if (loc.wide) { |
| 529 | loc = oatUpdateLocWide(cUnit, loc); |
| 530 | if ((nextArg >= 2) && (loc.location == kLocPhysReg)) { |
| 531 | storeBaseDispWide(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 532 | loc.lowReg, loc.highReg); |
| 533 | } |
| 534 | nextArg += 2; |
| 535 | } else { |
| 536 | loc = oatUpdateLoc(cUnit, loc); |
| 537 | if ((nextArg >= 3) && (loc.location == kLocPhysReg)) { |
| 538 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 539 | loc.lowReg, kWord); |
| 540 | } |
| 541 | nextArg++; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 542 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 543 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 544 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 545 | int startOffset = oatSRegOffset(cUnit, |
| 546 | cUnit->regLocation[mir->ssaRep->uses[3]].sRegLow); |
| 547 | int outsOffset = 4 /* Method* */ + (3 * 4); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 548 | #if defined(TARGET_MIPS) || defined(TARGET_X86) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 549 | // Generate memcpy |
| 550 | opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset); |
| 551 | opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset); |
| 552 | callRuntimeHelperRegRegImm(cUnit, ENTRYPOINT_OFFSET(pMemcpy), |
| 553 | rARG0, rARG1, (numArgs - 3) * 4); |
| 554 | #else |
| 555 | if (numArgs >= 20) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 556 | // Generate memcpy |
| 557 | opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset); |
| 558 | opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 559 | callRuntimeHelperRegRegImm(cUnit, ENTRYPOINT_OFFSET(pMemcpy), |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 560 | rARG0, rARG1, (numArgs - 3) * 4); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 561 | } else { |
| 562 | // Use vldm/vstm pair using rARG3 as a temp |
| 563 | int regsLeft = std::min(numArgs - 3, 16); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 564 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
Brian Carlstrom | f582258 | 2012-03-19 22:34:31 -0700 | [diff] [blame] | 565 | directCode, directMethod, type); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 566 | opRegRegImm(cUnit, kOpAdd, rARG3, rSP, startOffset); |
| 567 | LIR* ld = newLIR3(cUnit, kThumb2Vldms, rARG3, fr0, regsLeft); |
| 568 | //TUNING: loosen barrier |
| 569 | ld->defMask = ENCODE_ALL; |
| 570 | setMemRefType(ld, true /* isLoad */, kDalvikReg); |
| 571 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 572 | directCode, directMethod, type); |
| 573 | opRegRegImm(cUnit, kOpAdd, rARG3, rSP, 4 /* Method* */ + (3 * 4)); |
| 574 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 575 | directCode, directMethod, type); |
| 576 | LIR* st = newLIR3(cUnit, kThumb2Vstms, rARG3, fr0, regsLeft); |
| 577 | setMemRefType(st, false /* isLoad */, kDalvikReg); |
| 578 | st->defMask = ENCODE_ALL; |
| 579 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 580 | directCode, directMethod, type); |
| 581 | |
| 582 | } |
| 583 | #endif |
| 584 | |
| 585 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
| 586 | dexIdx, methodIdx, directCode, directMethod, |
| 587 | type, skipThis); |
| 588 | |
| 589 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 590 | directCode, directMethod, type); |
| 591 | if (pcrLabel) { |
| 592 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
| 593 | } |
| 594 | return callState; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 595 | } |
| 596 | |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 597 | RegLocation inlineTarget(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir) |
| 598 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 599 | RegLocation res; |
| 600 | mir = oatFindMoveResult(cUnit, bb, mir, false); |
| 601 | if (mir == NULL) { |
| 602 | res = oatGetReturn(cUnit, false); |
| 603 | } else { |
| 604 | res = oatGetDest(cUnit, mir, 0); |
| 605 | mir->dalvikInsn.opcode = Instruction::NOP; |
| 606 | } |
| 607 | return res; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | RegLocation inlineTargetWide(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir) |
| 611 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 612 | RegLocation res; |
| 613 | mir = oatFindMoveResult(cUnit, bb, mir, true); |
| 614 | if (mir == NULL) { |
| 615 | res = oatGetReturnWide(cUnit, false); |
| 616 | } else { |
| 617 | res = oatGetDestWide(cUnit, mir, 0, 1); |
| 618 | mir->dalvikInsn.opcode = Instruction::NOP; |
| 619 | } |
| 620 | return res; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | bool genInlinedCharAt(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 624 | InvokeType type, bool isRange) |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 625 | { |
| 626 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 627 | // Location of reference to data array |
| 628 | int valueOffset = String::ValueOffset().Int32Value(); |
| 629 | // Location of count |
| 630 | int countOffset = String::CountOffset().Int32Value(); |
| 631 | // Starting offset within data array |
| 632 | int offsetOffset = String::OffsetOffset().Int32Value(); |
| 633 | // Start of char data with array_ |
| 634 | int dataOffset = Array::DataOffset(sizeof(uint16_t)).Int32Value(); |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 635 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 636 | RegLocation rlObj = oatGetSrc(cUnit, mir, 0); |
| 637 | RegLocation rlIdx = oatGetSrc(cUnit, mir, 1); |
| 638 | rlObj = loadValue(cUnit, rlObj, kCoreReg); |
| 639 | rlIdx = loadValue(cUnit, rlIdx, kCoreReg); |
| 640 | int regMax; |
| 641 | int regOff = oatAllocTemp(cUnit); |
| 642 | int regPtr = oatAllocTemp(cUnit); |
| 643 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir); |
| 644 | bool rangeCheck = (!(mir->optimizationFlags & MIR_IGNORE_RANGE_CHECK)); |
| 645 | if (rangeCheck) { |
| 646 | regMax = oatAllocTemp(cUnit); |
| 647 | loadWordDisp(cUnit, rlObj.lowReg, countOffset, regMax); |
| 648 | } |
| 649 | loadWordDisp(cUnit, rlObj.lowReg, offsetOffset, regOff); |
| 650 | loadWordDisp(cUnit, rlObj.lowReg, valueOffset, regPtr); |
| 651 | LIR* launchPad = NULL; |
| 652 | if (rangeCheck) { |
| 653 | // Set up a launch pad to allow retry in case of bounds violation */ |
| 654 | launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, (int)mir, type); |
| 655 | oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads, |
| 656 | (intptr_t)launchPad); |
| 657 | opRegReg(cUnit, kOpCmp, rlIdx.lowReg, regMax); |
| 658 | oatFreeTemp(cUnit, regMax); |
| 659 | opCondBranch(cUnit, kCondCs, launchPad); |
| 660 | } |
| 661 | opRegImm(cUnit, kOpAdd, regPtr, dataOffset); |
| 662 | opRegReg(cUnit, kOpAdd, regOff, rlIdx.lowReg); |
| 663 | RegLocation rlDest = inlineTarget(cUnit, bb, mir); |
| 664 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 665 | loadBaseIndexed(cUnit, regPtr, regOff, rlResult.lowReg, 1, kUnsignedHalf); |
| 666 | oatFreeTemp(cUnit, regOff); |
| 667 | oatFreeTemp(cUnit, regPtr); |
| 668 | storeValue(cUnit, rlDest, rlResult); |
| 669 | if (rangeCheck) { |
Elliott Hughes | 6023456 | 2012-06-01 12:25:59 -0700 | [diff] [blame^] | 670 | launchPad->operands[2] = 0; // no resumption |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 671 | launchPad->operands[3] = (uintptr_t)bb; |
| 672 | } |
| 673 | // Record that we've already inlined & null checked |
| 674 | mir->optimizationFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK); |
| 675 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 676 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 677 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 678 | #endif |
| 679 | } |
| 680 | |
| 681 | bool genInlinedMinMaxInt(CompilationUnit *cUnit, BasicBlock* bb, MIR *mir, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 682 | bool isMin) |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 683 | { |
| 684 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 685 | RegLocation rlSrc1 = oatGetSrc(cUnit, mir, 0); |
| 686 | RegLocation rlSrc2 = oatGetSrc(cUnit, mir, 1); |
| 687 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 688 | rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg); |
| 689 | RegLocation rlDest = inlineTarget(cUnit, bb, mir); |
| 690 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 691 | opRegReg(cUnit, kOpCmp, rlSrc1.lowReg, rlSrc2.lowReg); |
| 692 | opIT(cUnit, (isMin) ? kArmCondGt : kArmCondLt, "E"); |
| 693 | opRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc2.lowReg); |
| 694 | opRegReg(cUnit, kOpMov, rlResult.lowReg, rlSrc1.lowReg); |
| 695 | genBarrier(cUnit); |
| 696 | storeValue(cUnit, rlDest, rlResult); |
| 697 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 698 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 699 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 700 | #endif |
| 701 | } |
| 702 | |
| 703 | // Generates an inlined String.isEmpty or String.length. |
| 704 | bool genInlinedStringIsEmptyOrLength(CompilationUnit* cUnit, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 705 | BasicBlock* bb, MIR* mir, bool isEmpty) |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 706 | { |
| 707 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 708 | // dst = src.length(); |
| 709 | RegLocation rlObj = oatGetSrc(cUnit, mir, 0); |
| 710 | rlObj = loadValue(cUnit, rlObj, kCoreReg); |
| 711 | RegLocation rlDest = inlineTarget(cUnit, bb, mir); |
| 712 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 713 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, mir); |
| 714 | loadWordDisp(cUnit, rlObj.lowReg, String::CountOffset().Int32Value(), |
| 715 | rlResult.lowReg); |
| 716 | if (isEmpty) { |
| 717 | // dst = (dst == 0); |
| 718 | int tReg = oatAllocTemp(cUnit); |
| 719 | opRegReg(cUnit, kOpNeg, tReg, rlResult.lowReg); |
| 720 | opRegRegReg(cUnit, kOpAdc, rlResult.lowReg, rlResult.lowReg, tReg); |
| 721 | } |
| 722 | storeValue(cUnit, rlDest, rlResult); |
| 723 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 724 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 725 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 726 | #endif |
| 727 | } |
| 728 | |
| 729 | bool genInlinedAbsInt(CompilationUnit *cUnit, BasicBlock* bb, MIR *mir) |
| 730 | { |
| 731 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 732 | RegLocation rlSrc = oatGetSrc(cUnit, mir, 0); |
| 733 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 734 | RegLocation rlDest = inlineTarget(cUnit, bb, mir); |
| 735 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 736 | int signReg = oatAllocTemp(cUnit); |
| 737 | // abs(x) = y<=x>>31, (x+y)^y. |
| 738 | opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.lowReg, 31); |
| 739 | opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg); |
| 740 | opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg); |
| 741 | storeValue(cUnit, rlDest, rlResult); |
| 742 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 743 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 744 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 745 | #endif |
| 746 | } |
| 747 | |
| 748 | bool genInlinedAbsLong(CompilationUnit *cUnit, BasicBlock* bb, MIR *mir) |
| 749 | { |
| 750 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 751 | RegLocation rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 752 | rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg); |
| 753 | RegLocation rlDest = inlineTargetWide(cUnit, bb, mir); |
| 754 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 755 | int signReg = oatAllocTemp(cUnit); |
| 756 | // abs(x) = y<=x>>31, (x+y)^y. |
| 757 | opRegRegImm(cUnit, kOpAsr, signReg, rlSrc.highReg, 31); |
| 758 | opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc.lowReg, signReg); |
| 759 | opRegRegReg(cUnit, kOpAdc, rlResult.highReg, rlSrc.highReg, signReg); |
| 760 | opRegReg(cUnit, kOpXor, rlResult.lowReg, signReg); |
| 761 | opRegReg(cUnit, kOpXor, rlResult.highReg, signReg); |
| 762 | storeValueWide(cUnit, rlDest, rlResult); |
| 763 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 764 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 765 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 766 | #endif |
| 767 | } |
| 768 | |
| 769 | bool genInlinedFloatCvt(CompilationUnit *cUnit, BasicBlock* bb, MIR *mir) |
| 770 | { |
| 771 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 772 | RegLocation rlSrc = oatGetSrc(cUnit, mir, 0); |
| 773 | RegLocation rlDest = inlineTarget(cUnit, bb, mir); |
| 774 | storeValue(cUnit, rlDest, rlSrc); |
| 775 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 776 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 777 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 778 | #endif |
| 779 | } |
| 780 | |
| 781 | bool genInlinedDoubleCvt(CompilationUnit *cUnit, BasicBlock* bb, MIR *mir) |
| 782 | { |
| 783 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 784 | RegLocation rlSrc = oatGetSrcWide(cUnit, mir, 0, 1); |
| 785 | RegLocation rlDest = inlineTargetWide(cUnit, bb, mir); |
| 786 | storeValueWide(cUnit, rlDest, rlSrc); |
| 787 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 788 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 789 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 790 | #endif |
| 791 | } |
| 792 | |
| 793 | /* |
| 794 | * Fast string.indexOf(I) & (II). Tests for simple case of char <= 0xffff, |
| 795 | * otherwise bails to standard library code. |
| 796 | */ |
| 797 | bool genInlinedIndexOf(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 798 | InvokeType type, bool zeroBased) |
| 799 | { |
| 800 | #if defined(TARGET_ARM) |
| 801 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 802 | oatClobberCalleeSave(cUnit); |
| 803 | oatLockCallTemps(cUnit); // Using fixed registers |
| 804 | int regPtr = rARG0; |
| 805 | int regChar = rARG1; |
| 806 | int regStart = rARG2; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 807 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 808 | RegLocation rlObj = oatGetSrc(cUnit, mir, 0); |
| 809 | RegLocation rlChar = oatGetSrc(cUnit, mir, 1); |
| 810 | RegLocation rlStart = oatGetSrc(cUnit, mir, 2); |
| 811 | loadValueDirectFixed(cUnit, rlObj, regPtr); |
| 812 | loadValueDirectFixed(cUnit, rlChar, regChar); |
| 813 | if (zeroBased) { |
| 814 | loadConstant(cUnit, regStart, 0); |
| 815 | } else { |
| 816 | loadValueDirectFixed(cUnit, rlStart, regStart); |
| 817 | } |
| 818 | int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pIndexOf)); |
| 819 | genNullCheck(cUnit, rlObj.sRegLow, regPtr, mir); |
| 820 | LIR* launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, (int)mir, type); |
| 821 | oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads, |
| 822 | (intptr_t)launchPad); |
| 823 | opCmpImmBranch(cUnit, kCondGt, regChar, 0xFFFF, launchPad); |
| 824 | opReg(cUnit, kOpBlx, rTgt); |
| 825 | LIR* resumeTgt = newLIR0(cUnit, kPseudoTargetLabel); |
| 826 | launchPad->operands[2] = (uintptr_t)resumeTgt; |
| 827 | launchPad->operands[3] = (uintptr_t)bb; |
| 828 | // Record that we've already inlined & null checked |
| 829 | mir->optimizationFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK); |
| 830 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 831 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 832 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 833 | #endif |
| 834 | } |
| 835 | |
| 836 | /* Fast string.compareTo(Ljava/lang/string;)I. */ |
| 837 | bool genInlinedStringCompareTo(CompilationUnit* cUnit, BasicBlock* bb, |
| 838 | MIR* mir, InvokeType type) |
| 839 | { |
| 840 | #if defined(TARGET_ARM) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 841 | oatClobberCalleeSave(cUnit); |
| 842 | oatLockCallTemps(cUnit); // Using fixed registers |
| 843 | int regThis = rARG0; |
| 844 | int regCmp = rARG1; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 845 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 846 | RegLocation rlThis = oatGetSrc(cUnit, mir, 0); |
| 847 | RegLocation rlCmp = oatGetSrc(cUnit, mir, 1); |
| 848 | loadValueDirectFixed(cUnit, rlThis, regThis); |
| 849 | loadValueDirectFixed(cUnit, rlCmp, regCmp); |
| 850 | int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pStringCompareTo)); |
| 851 | genNullCheck(cUnit, rlThis.sRegLow, regThis, mir); |
| 852 | //TUNING: check if rlCmp.sRegLow is already null checked |
| 853 | LIR* launchPad = rawLIR(cUnit, 0, kPseudoIntrinsicRetry, (int)mir, type); |
| 854 | oatInsertGrowableList(cUnit, &cUnit->intrinsicLaunchpads, |
Elliott Hughes | 6023456 | 2012-06-01 12:25:59 -0700 | [diff] [blame^] | 855 | (intptr_t)launchPad); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 856 | opCmpImmBranch(cUnit, kCondEq, regCmp, 0, launchPad); |
| 857 | opReg(cUnit, kOpBlx, rTgt); |
Elliott Hughes | 6023456 | 2012-06-01 12:25:59 -0700 | [diff] [blame^] | 858 | launchPad->operands[2] = 0; // No return possible |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 859 | launchPad->operands[3] = (uintptr_t)bb; |
| 860 | // Record that we've already inlined & null checked |
| 861 | mir->optimizationFlags |= (MIR_INLINED | MIR_IGNORE_NULL_CHECK); |
| 862 | return true; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 863 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 864 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 865 | #endif |
| 866 | } |
| 867 | |
| 868 | bool genIntrinsic(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir, |
| 869 | InvokeType type, bool isRange) |
| 870 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 871 | if ((mir->optimizationFlags & MIR_INLINED) || isRange) { |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 872 | return false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 873 | } |
| 874 | /* |
| 875 | * TODO: move these to a target-specific structured constant array |
| 876 | * and use a generic match function. The list of intrinsics may be |
| 877 | * slightly different depending on target. |
| 878 | * TODO: Fold this into a matching function that runs during |
| 879 | * basic block building. This should be part of the action for |
| 880 | * small method inlining and recognition of the special object init |
| 881 | * method. By doing this during basic block construction, we can also |
| 882 | * take advantage of/generate new useful dataflow info. |
| 883 | */ |
| 884 | std::string tgtMethod(PrettyMethod(mir->dalvikInsn.vB, *cUnit->dex_file)); |
| 885 | if (tgtMethod.compare("char java.lang.String.charAt(int)") == 0) { |
| 886 | return genInlinedCharAt(cUnit, bb, mir, type, isRange); |
| 887 | } |
| 888 | if (tgtMethod.compare("int java.lang.Math.min(int, int)") == 0) { |
| 889 | return genInlinedMinMaxInt(cUnit, bb, mir, true /* isMin */); |
| 890 | } |
| 891 | if (tgtMethod.compare("int java.lang.Math.max(int, int)") == 0) { |
| 892 | return genInlinedMinMaxInt(cUnit, bb, mir, false /* isMin */); |
| 893 | } |
| 894 | if (tgtMethod.compare("int java.lang.String.length()") == 0) { |
| 895 | return genInlinedStringIsEmptyOrLength(cUnit, bb, mir, false /* isEmpty */); |
| 896 | } |
| 897 | if (tgtMethod.compare("boolean java.lang.String.isEmpty()") == 0) { |
| 898 | return genInlinedStringIsEmptyOrLength(cUnit, bb, mir, true /* isEmpty */); |
| 899 | } |
| 900 | if (tgtMethod.compare("int java.lang.Math.abs(int)") == 0) { |
| 901 | return genInlinedAbsInt(cUnit, bb, mir); |
| 902 | } |
| 903 | if (tgtMethod.compare("long java.lang.Math.abs(long)") == 0) { |
| 904 | return genInlinedAbsLong(cUnit, bb, mir); |
| 905 | } |
| 906 | if (tgtMethod.compare("int java.lang.Float.floatToRawIntBits(float)") == 0) { |
| 907 | return genInlinedFloatCvt(cUnit, bb, mir); |
| 908 | } |
| 909 | if (tgtMethod.compare("float java.lang.Float.intBitsToFloat(int)") == 0) { |
| 910 | return genInlinedFloatCvt(cUnit, bb, mir); |
| 911 | } |
| 912 | if (tgtMethod.compare("long java.lang.Double.doubleToRawLongBits(double)") == 0) { |
| 913 | return genInlinedDoubleCvt(cUnit, bb, mir); |
| 914 | } |
| 915 | if (tgtMethod.compare("double java.lang.Double.longBitsToDouble(long)") == 0) { |
| 916 | return genInlinedDoubleCvt(cUnit, bb, mir); |
| 917 | } |
| 918 | if (tgtMethod.compare("int java.lang.String.indexOf(int, int)") == 0) { |
| 919 | return genInlinedIndexOf(cUnit, bb, mir, type, false /* base 0 */); |
| 920 | } |
| 921 | if (tgtMethod.compare("int java.lang.String.indexOf(int)") == 0) { |
| 922 | return genInlinedIndexOf(cUnit, bb, mir, type, true /* base 0 */); |
| 923 | } |
| 924 | if (tgtMethod.compare("int java.lang.String.compareTo(java.lang.String)") == 0) { |
| 925 | return genInlinedStringCompareTo(cUnit, bb, mir, type); |
| 926 | } |
| 927 | return false; |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 931 | } // namespace art |