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