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