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