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