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