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 | |
| 97 | /* |
| 98 | * Bit of a hack here - in leiu of a real scheduling pass, |
| 99 | * emit the next instruction in static & direct invoke sequences. |
| 100 | */ |
| 101 | int nextSDCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 102 | int state, uint32_t dexIdx, uint32_t unused, |
| 103 | uintptr_t directCode, uintptr_t directMethod) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 104 | { |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 105 | if (directCode != 0 && directMethod != 0) { |
| 106 | switch(state) { |
| 107 | case 0: // Get the current Method* [sets rARG0] |
| 108 | loadConstant(cUnit, rINVOKE_TGT, directCode); |
| 109 | loadConstant(cUnit, rARG0, directMethod); |
| 110 | break; |
| 111 | default: |
| 112 | return -1; |
| 113 | } |
| 114 | } else { |
| 115 | switch(state) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 116 | case 0: // Get the current Method* [sets rARG0] |
| 117 | loadCurrMethodDirect(cUnit, rARG0); |
| 118 | break; |
| 119 | case 1: // Get method->dex_cache_resolved_methods_ |
| 120 | loadWordDisp(cUnit, rARG0, |
| 121 | Method::DexCacheResolvedMethodsOffset().Int32Value(), |
| 122 | rARG0); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 123 | // Set up direct code if known. |
| 124 | if (directCode != 0) { |
| 125 | loadConstant(cUnit, rINVOKE_TGT, directCode); |
| 126 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 127 | break; |
| 128 | case 2: // Grab target method* |
| 129 | loadWordDisp(cUnit, rARG0, |
| 130 | Array::DataOffset(sizeof(Object*)).Int32Value() + dexIdx * 4, |
| 131 | rARG0); |
| 132 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 133 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 134 | case 3: // Grab the code from the method* |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 135 | if (directCode == 0) { |
| 136 | loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(), |
| 137 | rINVOKE_TGT); |
| 138 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 139 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 140 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 141 | default: |
| 142 | return -1; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 143 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 144 | } |
| 145 | return state + 1; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * Bit of a hack here - in leiu of a real scheduling pass, |
| 150 | * emit the next instruction in a virtual invoke sequence. |
| 151 | * We can use rLR as a temp prior to target address loading |
| 152 | * Note also that we'll load the first argument ("this") into |
| 153 | * rARG1 here rather than the standard loadArgRegs. |
| 154 | */ |
| 155 | int nextVCallInsn(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 156 | int state, uint32_t dexIdx, uint32_t methodIdx, |
| 157 | uintptr_t unused, uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 158 | { |
| 159 | RegLocation rlArg; |
| 160 | /* |
| 161 | * This is the fast path in which the target virtual method is |
| 162 | * fully resolved at compile time. |
| 163 | */ |
| 164 | switch(state) { |
| 165 | case 0: // Get "this" [set rARG1] |
| 166 | rlArg = oatGetSrc(cUnit, mir, 0); |
| 167 | loadValueDirectFixed(cUnit, rlArg, rARG1); |
| 168 | break; |
| 169 | case 1: // Is "this" null? [use rARG1] |
| 170 | genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 171 | // get this->klass_ [use rARG1, set rINVOKE_TGT] |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 172 | loadWordDisp(cUnit, rARG1, Object::ClassOffset().Int32Value(), |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 173 | rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 174 | break; |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 175 | case 2: // Get this->klass_->vtable [usr rINVOKE_TGT, set rINVOKE_TGT] |
| 176 | loadWordDisp(cUnit, rINVOKE_TGT, Class::VTableOffset().Int32Value(), |
| 177 | rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 178 | break; |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 179 | case 3: // Get target method [use rINVOKE_TGT, set rARG0] |
| 180 | loadWordDisp(cUnit, rINVOKE_TGT, (methodIdx * 4) + |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 181 | Array::DataOffset(sizeof(Object*)).Int32Value(), |
| 182 | rARG0); |
| 183 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 184 | #if !defined(TARGET_X86) |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 185 | case 4: // Get the compiled code address [uses rARG0, sets rINVOKE_TGT] |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 186 | loadWordDisp(cUnit, rARG0, Method::GetCodeOffset().Int32Value(), |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 187 | rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 188 | break; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 189 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 190 | default: |
| 191 | return -1; |
| 192 | } |
| 193 | return state + 1; |
| 194 | } |
| 195 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 196 | int nextInvokeInsnSP(CompilationUnit* cUnit, MIR* mir, int trampoline, |
| 197 | int state, uint32_t dexIdx, uint32_t methodIdx) |
| 198 | { |
| 199 | /* |
| 200 | * This handles the case in which the base method is not fully |
| 201 | * resolved at compile time, we bail to a runtime helper. |
| 202 | */ |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 203 | #if !defined(TARGET_X86) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 204 | if (state == 0) { |
| 205 | // Load trampoline target |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 206 | loadWordDisp(cUnit, rSELF, trampoline, rINVOKE_TGT); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 207 | // Load rARG0 with method index |
| 208 | loadConstant(cUnit, rARG0, dexIdx); |
| 209 | return 1; |
| 210 | } |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 211 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 212 | return -1; |
| 213 | } |
| 214 | |
| 215 | int nextStaticCallInsnSP(CompilationUnit* cUnit, MIR* mir, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 216 | int state, uint32_t dexIdx, uint32_t methodIdx, |
| 217 | uintptr_t unused, uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 218 | { |
| 219 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeStaticTrampolineWithAccessCheck); |
| 220 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 221 | } |
| 222 | |
| 223 | int nextDirectCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 224 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
| 225 | uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 226 | { |
| 227 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeDirectTrampolineWithAccessCheck); |
| 228 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 229 | } |
| 230 | |
| 231 | int nextSuperCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 232 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
| 233 | uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 234 | { |
| 235 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeSuperTrampolineWithAccessCheck); |
| 236 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 237 | } |
| 238 | |
| 239 | int nextVCallInsnSP(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 240 | uint32_t dexIdx, uint32_t methodIdx, uintptr_t unused, |
| 241 | uintptr_t unused2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 242 | { |
| 243 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeVirtualTrampolineWithAccessCheck); |
| 244 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * All invoke-interface calls bounce off of art_invoke_interface_trampoline, |
| 249 | * which will locate the target and continue on via a tail call. |
| 250 | */ |
| 251 | int nextInterfaceCallInsn(CompilationUnit* cUnit, MIR* mir, int state, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 252 | uint32_t dexIdx, uint32_t unused, uintptr_t unused2, |
| 253 | uintptr_t unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 254 | { |
| 255 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampoline); |
| 256 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 257 | } |
| 258 | |
| 259 | int nextInterfaceCallInsnWithAccessCheck(CompilationUnit* cUnit, MIR* mir, |
| 260 | int state, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 261 | uint32_t unused, uintptr_t unused2, |
| 262 | uintptr_t unused3) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 263 | { |
| 264 | int trampoline = OFFSETOF_MEMBER(Thread, pInvokeInterfaceTrampolineWithAccessCheck); |
| 265 | return nextInvokeInsnSP(cUnit, mir, trampoline, state, dexIdx, 0); |
| 266 | } |
| 267 | |
| 268 | int loadArgRegs(CompilationUnit* cUnit, MIR* mir, DecodedInstruction* dInsn, |
| 269 | int callState, NextCallInsn nextCallInsn, uint32_t dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 270 | uint32_t methodIdx, uintptr_t directCode, |
| 271 | uintptr_t directMethod, bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 272 | { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 273 | #if !defined(TARGET_X86) |
| 274 | int lastArgReg = rARG3; |
| 275 | #else |
| 276 | int lastArgReg = rARG2; |
| 277 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 278 | int nextReg = rARG1; |
| 279 | int nextArg = 0; |
| 280 | if (skipThis) { |
| 281 | nextReg++; |
| 282 | nextArg++; |
| 283 | } |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 284 | for (; (nextReg <= lastArgReg) && (nextArg < mir->ssaRep->numUses); nextReg++) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 285 | RegLocation rlArg = oatGetRawSrc(cUnit, mir, nextArg++); |
| 286 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 287 | if (rlArg.wide && (nextReg <= rARG2)) { |
| 288 | loadValueDirectWideFixed(cUnit, rlArg, nextReg, nextReg + 1); |
| 289 | nextReg++; |
| 290 | nextArg++; |
| 291 | } else { |
| 292 | rlArg.wide = false; |
| 293 | loadValueDirectFixed(cUnit, rlArg, nextReg); |
| 294 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 295 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 296 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 297 | } |
| 298 | return callState; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Load up to 5 arguments, the first three of which will be in |
| 303 | * rARG1 .. rARG3. On entry rARG0 contains the current method pointer, |
| 304 | * and as part of the load sequence, it must be replaced with |
| 305 | * the target method pointer. Note, this may also be called |
| 306 | * for "range" variants if the number of arguments is 5 or fewer. |
| 307 | */ |
| 308 | int genDalvikArgsNoRange(CompilationUnit* cUnit, MIR* mir, |
| 309 | DecodedInstruction* dInsn, int callState, |
| 310 | LIR** pcrLabel, NextCallInsn nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 311 | uint32_t dexIdx, uint32_t methodIdx, |
| 312 | uintptr_t directCode, uintptr_t directMethod, |
| 313 | bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 314 | { |
| 315 | RegLocation rlArg; |
| 316 | |
| 317 | /* If no arguments, just return */ |
| 318 | if (dInsn->vA == 0) |
| 319 | return callState; |
| 320 | |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 321 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 322 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 323 | |
| 324 | DCHECK_LE(dInsn->vA, 5U); |
| 325 | if (dInsn->vA > 3) { |
| 326 | uint32_t nextUse = 3; |
| 327 | //Detect special case of wide arg spanning arg3/arg4 |
| 328 | RegLocation rlUse0 = oatGetRawSrc(cUnit, mir, 0); |
| 329 | RegLocation rlUse1 = oatGetRawSrc(cUnit, mir, 1); |
| 330 | RegLocation rlUse2 = oatGetRawSrc(cUnit, mir, 2); |
| 331 | if (((!rlUse0.wide && !rlUse1.wide) || rlUse0.wide) && |
| 332 | rlUse2.wide) { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 333 | int reg = -1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 334 | // Wide spans, we need the 2nd half of uses[2]. |
| 335 | rlArg = oatUpdateLocWide(cUnit, rlUse2); |
| 336 | if (rlArg.location == kLocPhysReg) { |
| 337 | reg = rlArg.highReg; |
| 338 | } else { |
| 339 | // rARG2 & rARG3 can safely be used here |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 340 | #if defined(TARGET_X86) |
| 341 | UNIMPLEMENTED(FATAL); |
| 342 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 343 | reg = rARG3; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 344 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 345 | loadWordDisp(cUnit, rSP, |
| 346 | oatSRegOffset(cUnit, rlArg.sRegLow) + 4, reg); |
| 347 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 348 | methodIdx, directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 349 | } |
| 350 | storeBaseDisp(cUnit, rSP, (nextUse + 1) * 4, reg, kWord); |
| 351 | storeBaseDisp(cUnit, rSP, 16 /* (3+1)*4 */, reg, kWord); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 352 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 353 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 354 | nextUse++; |
| 355 | } |
| 356 | // Loop through the rest |
| 357 | while (nextUse < dInsn->vA) { |
| 358 | int lowReg; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 359 | int highReg = -1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 360 | rlArg = oatGetRawSrc(cUnit, mir, nextUse); |
| 361 | rlArg = oatUpdateRawLoc(cUnit, rlArg); |
| 362 | if (rlArg.location == kLocPhysReg) { |
| 363 | lowReg = rlArg.lowReg; |
| 364 | highReg = rlArg.highReg; |
| 365 | } else { |
| 366 | lowReg = rARG2; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 367 | #if defined(TARGET_X86) |
| 368 | UNIMPLEMENTED(FATAL); |
| 369 | #else |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 370 | highReg = rARG3; |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 371 | #endif |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 372 | if (rlArg.wide) { |
| 373 | loadValueDirectWideFixed(cUnit, rlArg, lowReg, highReg); |
| 374 | } else { |
| 375 | loadValueDirectFixed(cUnit, rlArg, lowReg); |
| 376 | } |
| 377 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 378 | methodIdx, directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 379 | } |
| 380 | int outsOffset = (nextUse + 1) * 4; |
| 381 | if (rlArg.wide) { |
| 382 | storeBaseDispWide(cUnit, rSP, outsOffset, lowReg, highReg); |
| 383 | nextUse += 2; |
| 384 | } else { |
| 385 | storeWordDisp(cUnit, rSP, outsOffset, lowReg); |
| 386 | nextUse++; |
| 387 | } |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 388 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 389 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 390 | } |
| 391 | } |
| 392 | |
| 393 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 394 | dexIdx, methodIdx, directCode, directMethod, |
| 395 | skipThis); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 396 | |
| 397 | if (pcrLabel) { |
| 398 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
| 399 | } |
| 400 | return callState; |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * May have 0+ arguments (also used for jumbo). Note that |
| 405 | * source virtual registers may be in physical registers, so may |
| 406 | * need to be flushed to home location before copying. This |
| 407 | * applies to arg3 and above (see below). |
| 408 | * |
| 409 | * Two general strategies: |
| 410 | * If < 20 arguments |
| 411 | * Pass args 3-18 using vldm/vstm block copy |
| 412 | * Pass arg0, arg1 & arg2 in rARG1-rARG3 |
| 413 | * If 20+ arguments |
| 414 | * Pass args arg19+ using memcpy block copy |
| 415 | * Pass arg0, arg1 & arg2 in rARG1-rARG3 |
| 416 | * |
| 417 | */ |
| 418 | int genDalvikArgsRange(CompilationUnit* cUnit, MIR* mir, |
| 419 | DecodedInstruction* dInsn, int callState, |
| 420 | LIR** pcrLabel, NextCallInsn nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 421 | uint32_t dexIdx, uint32_t methodIdx, |
| 422 | uintptr_t directCode, uintptr_t directMethod, |
| 423 | bool skipThis) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 424 | { |
| 425 | int firstArg = dInsn->vC; |
| 426 | int numArgs = dInsn->vA; |
| 427 | |
| 428 | // If we can treat it as non-range (Jumbo ops will use range form) |
| 429 | if (numArgs <= 5) |
| 430 | return genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pcrLabel, |
| 431 | nextCallInsn, dexIdx, methodIdx, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 432 | directCode, directMethod, skipThis); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 433 | /* |
| 434 | * Make sure range list doesn't span the break between in normal |
| 435 | * Dalvik vRegs and the ins. |
| 436 | */ |
| 437 | int highestArg = oatGetSrc(cUnit, mir, numArgs-1).sRegLow; |
| 438 | int boundaryReg = cUnit->numDalvikRegisters - cUnit->numIns; |
| 439 | if ((firstArg < boundaryReg) && (highestArg >= boundaryReg)) { |
| 440 | LOG(FATAL) << "Argument list spanned locals & args"; |
| 441 | } |
| 442 | |
| 443 | /* |
| 444 | * First load the non-register arguments. Both forms expect all |
| 445 | * of the source arguments to be in their home frame location, so |
| 446 | * scan the sReg names and flush any that have been promoted to |
| 447 | * frame backing storage. |
| 448 | */ |
| 449 | // Scan the rest of the args - if in physReg flush to memory |
| 450 | for (int nextArg = 0; nextArg < numArgs;) { |
| 451 | RegLocation loc = oatGetRawSrc(cUnit, mir, nextArg); |
| 452 | if (loc.wide) { |
| 453 | loc = oatUpdateLocWide(cUnit, loc); |
| 454 | if ((nextArg >= 2) && (loc.location == kLocPhysReg)) { |
| 455 | storeBaseDispWide(cUnit, rSP, |
| 456 | oatSRegOffset(cUnit, loc.sRegLow), |
| 457 | loc.lowReg, loc.highReg); |
| 458 | } |
| 459 | nextArg += 2; |
| 460 | } else { |
| 461 | loc = oatUpdateLoc(cUnit, loc); |
| 462 | if ((nextArg >= 3) && (loc.location == kLocPhysReg)) { |
| 463 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 464 | loc.lowReg, kWord); |
| 465 | } |
| 466 | nextArg++; |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | int startOffset = oatSRegOffset(cUnit, |
| 471 | cUnit->regLocation[mir->ssaRep->uses[3]].sRegLow); |
| 472 | int outsOffset = 4 /* Method* */ + (3 * 4); |
| 473 | #if defined(TARGET_MIPS) |
| 474 | // Generate memcpy |
| 475 | opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset); |
| 476 | opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset); |
| 477 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy)); |
| 478 | loadConstant(cUnit, rARG2, (numArgs - 3) * 4); |
| 479 | callRuntimeHelper(cUnit, rTgt); |
| 480 | // Restore Method* |
| 481 | loadCurrMethodDirect(cUnit, rARG0); |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 482 | #elif defined(TARGET_X86) |
| 483 | // Generate memcpy |
| 484 | opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset); |
| 485 | opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset); |
| 486 | loadConstant(cUnit, rARG2, (numArgs - 3) * 4); |
| 487 | callRuntimeHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy)); |
| 488 | // Restore Method* |
| 489 | loadCurrMethodDirect(cUnit, rARG0); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 490 | #else |
| 491 | if (numArgs >= 20) { |
| 492 | // Generate memcpy |
| 493 | opRegRegImm(cUnit, kOpAdd, rARG0, rSP, outsOffset); |
| 494 | opRegRegImm(cUnit, kOpAdd, rARG1, rSP, startOffset); |
| 495 | int rTgt = loadHelper(cUnit, OFFSETOF_MEMBER(Thread, pMemcpy)); |
| 496 | loadConstant(cUnit, rARG2, (numArgs - 3) * 4); |
| 497 | callRuntimeHelper(cUnit, rTgt); |
| 498 | // Restore Method* |
| 499 | loadCurrMethodDirect(cUnit, rARG0); |
| 500 | } else { |
| 501 | // Use vldm/vstm pair using rARG3 as a temp |
| 502 | int regsLeft = std::min(numArgs - 3, 16); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 503 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 504 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 505 | opRegRegImm(cUnit, kOpAdd, rARG3, rSP, startOffset); |
| 506 | LIR* ld = newLIR3(cUnit, kThumb2Vldms, rARG3, fr0, regsLeft); |
| 507 | //TUNING: loosen barrier |
| 508 | ld->defMask = ENCODE_ALL; |
| 509 | setMemRefType(ld, true /* isLoad */, kDalvikReg); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 510 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 511 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 512 | opRegRegImm(cUnit, kOpAdd, rARG3, rSP, 4 /* Method* */ + (3 * 4)); |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 513 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 514 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 515 | LIR* st = newLIR3(cUnit, kThumb2Vstms, rARG3, fr0, regsLeft); |
| 516 | setMemRefType(st, false /* isLoad */, kDalvikReg); |
| 517 | st->defMask = ENCODE_ALL; |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 518 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 519 | directCode, directMethod); |
| 520 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 521 | } |
| 522 | #endif |
| 523 | |
| 524 | callState = loadArgRegs(cUnit, mir, dInsn, callState, nextCallInsn, |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 525 | dexIdx, methodIdx, directCode, directMethod, |
| 526 | skipThis); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 527 | |
Ian Rogers | 2ed3b95 | 2012-03-17 11:49:39 -0700 | [diff] [blame] | 528 | callState = nextCallInsn(cUnit, mir, callState, dexIdx, methodIdx, |
| 529 | directCode, directMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 530 | if (pcrLabel) { |
| 531 | *pcrLabel = genNullCheck(cUnit, oatSSASrc(mir,0), rARG1, mir); |
| 532 | } |
| 533 | return callState; |
| 534 | } |
| 535 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 536 | } // namespace art |