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 | |
| 17 | namespace art { |
| 18 | |
| 19 | /* |
| 20 | * This source files contains "gen" codegen routines that should |
| 21 | * be applicable to most targets. Only mid-level support utilities |
| 22 | * and "op" calls may be used here. |
| 23 | */ |
| 24 | |
| 25 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 26 | typedef int (*NextCallInsn)(CompilationUnit*, MIR*, int, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 27 | uint32_t methodIdx, uintptr_t directCode, |
| 28 | uintptr_t directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 29 | /* |
| 30 | * If there are any ins passed in registers that have not been promoted |
| 31 | * to a callee-save register, flush them to the frame. Perform intial |
| 32 | * assignment of promoted arguments. |
| 33 | */ |
| 34 | void flushIns(CompilationUnit* cUnit) |
| 35 | { |
| 36 | if (cUnit->numIns == 0) |
| 37 | return; |
| 38 | int firstArgReg = rARG1; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 39 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 40 | int lastArgReg = rARG3; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 41 | #else |
| 42 | int lastArgReg = rARG2; |
| 43 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 44 | int startVReg = cUnit->numDalvikRegisters - cUnit->numIns; |
| 45 | /* |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 46 | * Copy incoming arguments to their proper home locations. |
| 47 | * NOTE: an older version of dx had an issue in which |
| 48 | * it would reuse static method argument registers. |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 49 | * This could result in the same Dalvik virtual register |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 50 | * being promoted to both core and fp regs. To account for this, |
| 51 | * we only copy to the corresponding promoted physical register |
| 52 | * if it matches the type of the SSA name for the incoming |
| 53 | * argument. It is also possible that long and double arguments |
| 54 | * end up half-promoted. In those cases, we must flush the promoted |
| 55 | * half to memory as well. |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 56 | */ |
| 57 | for (int i = 0; i < cUnit->numIns; i++) { |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 58 | PromotionMap* vMap = &cUnit->promotionMap[startVReg + i]; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 59 | if (i <= (lastArgReg - firstArgReg)) { |
| 60 | // If arriving in register |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 61 | bool needFlush = true; |
| 62 | RegLocation* tLoc = &cUnit->regLocation[startVReg + i]; |
| 63 | if ((vMap->coreLocation == kLocPhysReg) && !tLoc->fp) { |
| 64 | opRegCopy(cUnit, vMap->coreReg, firstArgReg + i); |
| 65 | needFlush = false; |
| 66 | } else if ((vMap->fpLocation == kLocPhysReg) && tLoc->fp) { |
| 67 | opRegCopy(cUnit, vMap->fpReg, firstArgReg + i); |
| 68 | needFlush = false; |
| 69 | } else { |
| 70 | needFlush = true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 71 | } |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 72 | |
| 73 | // For wide args, force flush if only half is promoted |
| 74 | if (tLoc->wide) { |
| 75 | PromotionMap* pMap = vMap + (tLoc->highWord ? -1 : +1); |
| 76 | needFlush |= (pMap->coreLocation != vMap->coreLocation) || |
| 77 | (pMap->fpLocation != vMap->fpLocation); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 78 | } |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 79 | if (needFlush) { |
| 80 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
| 81 | firstArgReg + i, kWord); |
| 82 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 83 | } else { |
| 84 | // If arriving in frame & promoted |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 85 | if (vMap->coreLocation == kLocPhysReg) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 86 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 87 | vMap->coreReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 88 | } |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 89 | if (vMap->fpLocation == kLocPhysReg) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 90 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, startVReg + i), |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 91 | vMap->fpReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame^] | 97 | void scanMethodLiteralPool(CompilationUnit* cUnit, LIR** methodTarget, LIR** codeTarget, const DexFile* dexFile, uint32_t dexMethodIdx) |
| 98 | { |
| 99 | LIR* curTarget = cUnit->methodLiteralList; |
| 100 | LIR* nextTarget = curTarget != NULL ? curTarget->next : NULL; |
| 101 | while (curTarget != NULL && nextTarget != NULL) { |
| 102 | if (curTarget->operands[0] == (int)dexFile && |
| 103 | nextTarget->operands[0] == (int)dexMethodIdx) { |
| 104 | *codeTarget = curTarget; |
| 105 | *methodTarget = nextTarget; |
| 106 | DCHECK((*codeTarget)->next == *methodTarget); |
| 107 | DCHECK_EQ((*codeTarget)->operands[0], (int)dexFile); |
| 108 | DCHECK_EQ((*methodTarget)->operands[0], (int)dexMethodIdx); |
| 109 | break; |
| 110 | } |
| 111 | curTarget = nextTarget->next; |
| 112 | nextTarget = curTarget != NULL ? curTarget->next : NULL; |
| 113 | } |
| 114 | } |
| 115 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 116 | /* |
| 117 | * Bit of a hack here - in leiu of a real scheduling pass, |
| 118 | * emit the next instruction in static & direct invoke sequences. |
| 119 | */ |
| 120 | int nextSDCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 121 | int state, uint32_t dexIdx, uint32_t unused, |
| 122 | uintptr_t directCode, uintptr_t directMethod) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 123 | { |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 124 | if (directCode != 0 && directMethod != 0) { |
| 125 | switch(state) { |
| 126 | case 0: // Get the current Method* [sets rARG0] |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame^] | 127 | if (directCode != (uintptr_t)-1) { |
| 128 | loadConstant(cUnit, rINVOKE_TGT, directCode); |
| 129 | } else { |
| 130 | LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0); |
| 131 | if (dataTarget == NULL) { |
| 132 | dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx); |
| 133 | } |
| 134 | #if defined(TARGET_ARM) |
| 135 | LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset, |
| 136 | kThumb2LdrPcRel12, rINVOKE_TGT, 0, 0, 0, 0, dataTarget); |
| 137 | oatAppendLIR(cUnit, loadPcRel); |
| 138 | #else |
| 139 | UNIMPLEMENTED(FATAL) << (void*)dataTarget; |
| 140 | #endif |
| 141 | } |
| 142 | if (directMethod != (uintptr_t)-1) { |
| 143 | loadConstant(cUnit, rARG0, directMethod); |
| 144 | } else { |
| 145 | LIR* dataTarget = scanLiteralPool(cUnit->methodLiteralList, dexIdx, 0); |
| 146 | if (dataTarget == NULL) { |
| 147 | dataTarget = addWordData(cUnit, &cUnit->methodLiteralList, dexIdx); |
| 148 | } |
| 149 | #if defined(TARGET_ARM) |
| 150 | LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset, |
| 151 | kThumb2LdrPcRel12, rARG0, 0, 0, 0, 0, dataTarget); |
| 152 | oatAppendLIR(cUnit, loadPcRel); |
| 153 | #else |
| 154 | UNIMPLEMENTED(FATAL) << (void*)dataTarget; |
| 155 | #endif |
| 156 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 157 | break; |
| 158 | default: |
| 159 | return -1; |
| 160 | } |
| 161 | } else { |
| 162 | switch(state) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 163 | case 0: // Get the current Method* [sets rARG0] |
| 164 | loadCurrMethodDirect(cUnit, rARG0); |
| 165 | break; |
| 166 | case 1: // Get method->dex_cache_resolved_methods_ |
| 167 | loadWordDisp(cUnit, rARG0, |
| 168 | Method::DexCacheResolvedMethodsOffset().Int32Value(), |
| 169 | rARG0); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 170 | // Set up direct code if known. |
| 171 | if (directCode != 0) { |
Ian Rogers | 3fa1379 | 2012-03-18 15:53:45 -0700 | [diff] [blame^] | 172 | if (directCode != (uintptr_t)-1) { |
| 173 | loadConstant(cUnit, rINVOKE_TGT, directCode); |
| 174 | } else { |
| 175 | LIR* dataTarget = scanLiteralPool(cUnit->codeLiteralList, dexIdx, 0); |
| 176 | if (dataTarget == NULL) { |
| 177 | dataTarget = addWordData(cUnit, &cUnit->codeLiteralList, dexIdx); |
| 178 | } |
| 179 | #if defined(TARGET_ARM) |
| 180 | LIR* loadPcRel = rawLIR(cUnit, cUnit->currentDalvikOffset, |
| 181 | kThumb2LdrPcRel12, rINVOKE_TGT, 0, 0, 0, 0, dataTarget); |
| 182 | oatAppendLIR(cUnit, loadPcRel); |
| 183 | #else |
| 184 | UNIMPLEMENTED(FATAL) << (void*)dataTarget; |
| 185 | #endif |
| 186 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 187 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 188 | break; |
| 189 | case 2: // Grab target method* |
| 190 | loadWordDisp(cUnit, rARG0, |
| 191 | Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4, |
| 192 | rARG0); |
| 193 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 194 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 195 | case 3: // Grab the code from the method* |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 196 | if (directCode == 0) { |
| 197 | loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(), |
| 198 | rINVOKE_TGT); |
| 199 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 200 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 201 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 202 | default: |
| 203 | return -1; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 204 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 205 | } |
| 206 | return state + 1; |
| 207 | } |
| 208 | |
| 209 | /* |
| 210 | * Bit of a hack here - in leiu of a real scheduling pass, |
| 211 | * emit the next instruction in a virtual invoke sequence. |
| 212 | * We can use rLR as a temp prior to target address loading |
| 213 | * Note also that we'll load the first argument ("this") into |
| 214 | * rARG1 here rather than the standard loadArgRegs. |
| 215 | */ |
| 216 | int nextVCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 217 | int state, uint32_t dexIdx, uint32_t methodIdx, |
| 218 | uintptr_t unused, uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 219 | { |
| 220 | RegLocation rlArg; |
| 221 | /* |
| 222 | * This is the fast path in which the target virtual method is |
| 223 | * fully resolved at compile time. |
| 224 | */ |
| 225 | switch(state) { |
| 226 | case 0: // Get "this" [set rARG1] |
| 227 | rlArg = oatGetSrc(cUnit, mir, 0); |
| 228 | loadValueDirectFixed(cUnit, rlArg, rARG1); |
| 229 | break; |
| 230 | case 1: // Is "this" null? [use rARG1] |
| 231 | genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 232 | // get this->klass_ [use rARG1, set rINVOKE_TGT] |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 233 | loadWordDisp(cUnit, rARG1, Object::ClassOffset().Int32Value(), |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 234 | rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 235 | break; |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 236 | case 2: // Get this->klass_->vtable [usr rINVOKE_TGT, set rINVOKE_TGT] |
| 237 | loadWordDisp(cUnit, rINVOKE_TGT, Class::VTableOffset().Int32Value(), |
| 238 | rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 239 | break; |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 240 | case 3: // Get target method [use rINVOKE_TGT, set rARG0] |
| 241 | loadWordDisp(cUnit, rINVOKE_TGT, (methodIdx * 4) + |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 242 | Array::DataOffset(sizeof(Object*)).Int32Value(), |
| 243 | rARG0); |
| 244 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 245 | #if !defined(TARGET_X86) |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 246 | case 4: // Get the compiled code address [uses rARG0, sets rINVOKE_TGT] |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 247 | loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(), |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 248 | rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 249 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 250 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 251 | default: |
| 252 | return -1; |
| 253 | } |
| 254 | return state + 1; |
| 255 | } |
| 256 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 257 | int nextInvokeInsnSP(CompilationUnit* cUnit, MIR* mir, int trampoline, |
| 258 | int state, uint32_t dexIdx, uint32_t methodIdx) |
| 259 | { |
| 260 | /* |
| 261 | * This handles the case in which the base method is not fully |
| 262 | * resolved at compile time, we bail to a runtime helper. |
| 263 | */ |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 264 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 265 | if (state == 0) { |
| 266 | // Load trampoline target |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 267 | loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 268 | // Load rARG0 with method index |
| 269 | loadConstant(cUnit, rARG0, dexIdx); |
| 270 | return 1; |
| 271 | } |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 272 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 273 | return -1; |
| 274 | } |
| 275 | |
| 276 | int nextStaticCallInsnSP(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 277 | int state, uint32_t dexIdx, uint32_t methodIdx, |
| 278 | uintptr_t unused, uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 279 | { |
| 280 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeStaticTrampolineWithAccessCheck); |
| 281 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 282 | } |
| 283 | |
| 284 | int nextDirectCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 285 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
| 286 | uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 287 | { |
| 288 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeDirectTrampolineWithAccessCheck); |
| 289 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 290 | } |
| 291 | |
| 292 | int nextSuperCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 293 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
| 294 | uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 295 | { |
| 296 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeSuperTrampolineWithAccessCheck); |
| 297 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 298 | } |
| 299 | |
| 300 | int nextVCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 301 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
| 302 | uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 303 | { |
| 304 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeVirtualTrampolineWithAccessCheck); |
| 305 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 306 | } |
| 307 | |
| 308 | /* |
| 309 | * All invoke-interface calls bounce off of art_invoke_interface_trampoline, |
| 310 | * which will locate the target and continue on via a tail call. |
| 311 | */ |
| 312 | int nextInterfaceCallInsn(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 313 | uint32_t dexIdx, uint32_t unused, uintptr_t unused2, |
| 314 | uintptr_t unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 315 | { |
| 316 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampoline); |
| 317 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 318 | } |
| 319 | |
| 320 | int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit, MIR* mir, |
| 321 | int state, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 322 | uint32_t unused, uintptr_t unused2, |
| 323 | uintptr_t unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 324 | { |
| 325 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampolineWithAccessCheck); |
| 326 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 327 | } |
| 328 | |
| 329 | int loadArgRegs(CompilationUnit* cUnit, MIR* mir, DecodedInstruction* dInsn, |
| 330 | int callState, NextCallInsn nextCallInsn, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 331 | uint32_t methodIdx, uintptr_t directCode, |
| 332 | uintptr_t directMethod, bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 333 | { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 334 | #if !defined(TARGET_X86) |
| 335 | int lastArgReg = rARG3; |
| 336 | #else |
| 337 | int lastArgReg = rARG2; |
| 338 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 339 | int nextReg = rARG1; |
| 340 | int nextArg = 0; |
| 341 | if (skipThis) { |
| 342 | nextReg++; |
| 343 | nextArg++; |
| 344 | } |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 345 | for (; (nextReg <= lastArgReg) && (nextArg < mir->ssaRep->numUses); nextReg++) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 346 | RegLocation rlArg = oatGetRawSrc(cUnit, mir, nextArg++); |
| 347 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 348 | if (rlArg.wide && (nextReg <= rARG2)) { |
| 349 | loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1); |
| 350 | nextReg++; |
| 351 | nextArg++; |
| 352 | } else { |
| 353 | rlArg.wide = false; |
| 354 | loadValueDirectFixed(cUnit, rlArg, nextReg); |
| 355 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 356 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 357 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 358 | } |
| 359 | return callState; |
| 360 | } |
| 361 | |
| 362 | /* |
| 363 | * Load up to 5 arguments, the first three of which will be in |
| 364 | * rARG1 .. rARG3. On entry rARG0 contains the current method pointer, |
| 365 | * and as part of the load sequence, it must be replaced with |
| 366 | * the target method pointer. Note, this may also be called |
| 367 | * for "range" variants if the number of arguments is 5 or fewer. |
| 368 | */ |
| 369 | int genDalvikArgsNoRange(CompilationUnit* cUnit, MIR* mir, |
| 370 | DecodedInstruction* dInsn, int callState, |
| 371 | LIR** pcrLabel, NextCallInsn nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 372 | uint32_t dexIdx, uint32_t methodIdx, |
| 373 | uintptr_t directCode, uintptr_t directMethod, |
| 374 | bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 375 | { |
| 376 | RegLocation rlArg; |
| 377 | |
| 378 | /* If no arguments, just return */ |
| 379 | if (dInsn->vA == 0) |
| 380 | return callState; |
| 381 | |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 382 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 383 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 384 | |
| 385 | DCHECK_LE(dInsn->vA, 5U); |
| 386 | if (dInsn->vA > 3) { |
| 387 | uint32_t nextUse = 3; |
| 388 | //Detect special case of wide arg spanning arg3/arg4 |
| 389 | RegLocation rlUse0 = oatGetRawSrc(cUnit, mir, 0); |
| 390 | RegLocation rlUse1 = oatGetRawSrc(cUnit, mir, 1); |
| 391 | RegLocation rlUse2 = oatGetRawSrc(cUnit, mir, 2); |
| 392 | if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) && |
| 393 | rlUse2.wide) { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 394 | int reg = -1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 395 | // Wide spans, we need the 2nd half of uses[2]. |
| 396 | rlArg = oatUpdateLocWide(cUnit, rlUse2); |
| 397 | if (rlArg.location == kLocPhysReg) { |
| 398 | reg = rlArg.highReg; |
| 399 | } else { |
| 400 | // rARG2 & rARG3 can safely be used here |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 401 | #if defined(TARGET_X86) |
| 402 | UNIMPLEMENTED(FATAL); |
| 403 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 404 | reg = rARG3; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 405 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 406 | loadWordDisp(cUnit, rSP, |
| 407 | oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg); |
| 408 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 409 | methodIdx, directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 410 | } |
| 411 | storeBaseDisp(cUnit, rSP, (nextUse + 1) * 4, reg, kWord); |
| 412 | storeBaseDisp(cUnit, rSP, 16 /* (3+1)*4 */, reg, kWord); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 413 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 414 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 415 | nextUse++; |
| 416 | } |
| 417 | // Loop through the rest |
| 418 | while (nextUse < dInsn->vA) { |
| 419 | int lowReg; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 420 | int highReg = -1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 421 | rlArg = oatGetRawSrc(cUnit, mir, nextUse); |
| 422 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 423 | if (rlArg.location == kLocPhysReg) { |
| 424 | lowReg = rlArg.lowReg; |
| 425 | highReg = rlArg.highReg; |
| 426 | } else { |
| 427 | lowReg = rARG2; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 428 | #if defined(TARGET_X86) |
| 429 | UNIMPLEMENTED(FATAL); |
| 430 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 431 | highReg = rARG3; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 432 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 433 | if (rlArg.wide) { |
| 434 | loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg); |
| 435 | } else { |
| 436 | loadValueDirectFixed(cUnit, rlArg, lowReg); |
| 437 | } |
| 438 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 439 | methodIdx, directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 440 | } |
| 441 | int outsOffset = (nextUse + 1) * 4; |
| 442 | if (rlArg.wide) { |
| 443 | storeBaseDispWide(cUnit, rSP, outsOffset, lowReg, highReg); |
| 444 | nextUse += 2; |
| 445 | } else { |
| 446 | storeWordDisp(cUnit, rSP, outsOffset, lowReg); |
| 447 | nextUse++; |
| 448 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 449 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 450 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | |
| 454 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 455 | dexIdx, methodIdx, directCode, directMethod, |
| 456 | skipThis); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 457 | |
| 458 | if (pcrLabel) { |
| 459 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
| 460 | } |
| 461 | return callState; |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * May have 0+ arguments (also used for jumbo). Note that |
| 466 | * source virtual registers may be in physical registers, so may |
| 467 | * need to be flushed to home location before copying. This |
| 468 | * applies to arg3 and above (see below). |
| 469 | * |
| 470 | * Two general strategies: |
| 471 | * If < 20 arguments |
| 472 | * Pass args 3-18 using vldm/vstm block copy |
| 473 | * Pass arg0, arg1 & arg2 in rARG1-rARG3 |
| 474 | * If 20+ arguments |
| 475 | * Pass args arg19+ using memcpy block copy |
| 476 | * Pass arg0, arg1 & arg2 in rARG1-rARG3 |
| 477 | * |
| 478 | */ |
| 479 | int genDalvikArgsRange(CompilationUnit* cUnit, MIR* mir, |
| 480 | DecodedInstruction* dInsn, int callState, |
| 481 | LIR** pcrLabel, NextCallInsn nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 482 | uint32_t dexIdx, uint32_t methodIdx, |
| 483 | uintptr_t directCode, uintptr_t directMethod, |
| 484 | bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 485 | { |
| 486 | int firstArg = dInsn->vC; |
| 487 | int numArgs = dInsn->vA; |
| 488 | |
| 489 | // If we can treat it as non-range (Jumbo ops will use range form) |
| 490 | if (numArgs <= 5) |
| 491 | return genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pcrLabel, |
| 492 | nextCallInsn, dexIdx, methodIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 493 | directCode, directMethod, skipThis); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 494 | /* |
| 495 | * Make sure range list doesn't span the break between in normal |
| 496 | * Dalvik vRegs and the ins. |
| 497 | */ |
| 498 | int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow; |
| 499 | int boundaryReg = cUnit->numDalvikRegisters - cUnit->numIns; |
| 500 | if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) { |
| 501 | LOG(FATAL) << "Argument list spanned locals & args"; |
| 502 | } |
| 503 | |
| 504 | /* |
| 505 | * First load the non-register arguments. Both forms expect all |
| 506 | * of the source arguments to be in their home frame location, so |
| 507 | * scan the sReg names and flush any that have been promoted to |
| 508 | * frame backing storage. |
| 509 | */ |
| 510 | // Scan the rest of the args - if in physReg flush to memory |
| 511 | for (int nextArg = 0; nextArg < numArgs;) { |
| 512 | RegLocation loc = oatGetRawSrc(cUnit, mir, nextArg); |
| 513 | if (loc.wide) { |
| 514 | loc = oatUpdateLocWide(cUnit, loc); |
| 515 | if ((nextArg >= 2) && (loc.location == kLocPhysReg)) { |
| 516 | storeBaseDispWide(cUnit, rSP, |
| 517 | oatSRegOffset(cUnit, loc.sRegLow), |
| 518 | loc.lowReg, loc.highReg); |
| 519 | } |
| 520 | nextArg += 2; |
| 521 | } else { |
| 522 | loc = oatUpdateLoc(cUnit, loc); |
| 523 | if ((nextArg >= 3) && (loc.location == kLocPhysReg)) { |
| 524 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 525 | loc.lowReg, kWord); |
| 526 | } |
| 527 | nextArg++; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | int startOffset = oatSRegOffset(cUnit, |
| 532 | cUnit->regLocation[mir->ssaRep->uses[3]].sRegLow); |
| 533 | int outsOffset = 4 /* Method* */ + (3 * 4); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 534 | #if defined(TARGET_MIPS) || defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 535 | // Generate memcpy |
| 536 | opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset); |
| 537 | opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 538 | callRuntimeHelperRegRegImm(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy), |
| 539 | rARG0, rARG1, (numArgs - 3) * 4); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 540 | // Restore Method* |
| 541 | loadCurrMethodDirect(cUnit, rARG0); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 542 | #else |
| 543 | if (numArgs >= 20) { |
| 544 | // Generate memcpy |
| 545 | opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset); |
| 546 | opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 547 | callRuntimeHelperRegRegImm(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy), |
| 548 | rARG0, rARG1, (numArgs - 3) * 4); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 549 | // Restore Method* |
| 550 | loadCurrMethodDirect(cUnit, rARG0); |
| 551 | } else { |
| 552 | // Use vldm/vstm pair using rARG3 as a temp |
| 553 | int regsLeft = std::min(numArgs - 3, 16); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 554 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 555 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [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); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 561 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 562 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 563 | opRegRegImm(cUnit, kOpAdd, rARG3, rSP, 4 /* Method* */ + (3 * 4)); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 564 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 565 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 566 | LIR* st = newLIR3(cUnit, kThumb2Vstms, rARG3, fr0, regsLeft); |
| 567 | setMemRefType(st, false /* isLoad */, kDalvikReg); |
| 568 | st->defMask = ENCODE_ALL; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 569 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 570 | directCode, directMethod); |
| 571 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 572 | } |
| 573 | #endif |
| 574 | |
| 575 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 576 | dexIdx, methodIdx, directCode, directMethod, |
| 577 | skipThis); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 578 | |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 579 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 580 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 581 | if (pcrLabel) { |
| 582 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
| 583 | } |
| 584 | return callState; |
| 585 | } |
| 586 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 587 | } // namespace art |