buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #include "object_utils.h" |
| 18 | |
| 19 | namespace art { |
| 20 | |
| 21 | #define DISPLAY_MISSING_TARGETS (cUnit->enableDebug & \ |
| 22 | (1 << kDebugDisplayMissingTargets)) |
| 23 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 24 | const RegLocation badLoc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, |
| 25 | INVALID_REG, INVALID_REG, INVALID_SREG}; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 26 | |
| 27 | /* Mark register usage state and return long retloc */ |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 28 | RegLocation oatGetReturnWide(CompilationUnit* cUnit) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 29 | { |
| 30 | RegLocation res = LOC_C_RETURN_WIDE; |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 31 | oatClobber(cUnit, res.lowReg); |
| 32 | oatClobber(cUnit, res.highReg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 33 | oatLockTemp(cUnit, res.lowReg); |
| 34 | oatLockTemp(cUnit, res.highReg); |
| 35 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 36 | return res; |
| 37 | } |
| 38 | |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 39 | RegLocation oatGetReturn(CompilationUnit* cUnit) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 40 | { |
| 41 | RegLocation res = LOC_C_RETURN; |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 42 | oatClobber(cUnit, res.lowReg); |
Elliott Hughes | b3cd122 | 2012-03-09 16:00:38 -0800 | [diff] [blame^] | 43 | if (cUnit->instructionSet == kMips) { |
| 44 | oatMarkInUse(cUnit, res.lowReg); |
| 45 | } else { |
| 46 | oatLockTemp(cUnit, res.lowReg); |
| 47 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 48 | return res; |
| 49 | } |
| 50 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 51 | void genInvoke(CompilationUnit* cUnit, MIR* mir, InvokeType type, bool isRange) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 52 | { |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 53 | #if defined(TARGET_X86) |
| 54 | UNIMPLEMENTED(WARNING) << "genInvoke"; |
| 55 | #else |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 56 | DecodedInstruction* dInsn = &mir->dalvikInsn; |
| 57 | int callState = 0; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 58 | LIR* nullCk; |
| 59 | LIR** pNullCk = NULL; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 60 | NextCallInsn nextCallInsn; |
| 61 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 62 | // Explicit register usage |
| 63 | oatLockCallTemps(cUnit); |
| 64 | |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 65 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 66 | *cUnit->dex_file, *cUnit->dex_cache, |
| 67 | cUnit->code_item, cUnit->method_idx, |
| 68 | cUnit->access_flags); |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 69 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 70 | uint32_t dexMethodIdx = dInsn->vB; |
| 71 | int vtableIdx; |
| 72 | bool skipThis; |
| 73 | bool fastPath = |
Logan Chien | 4dd96f5 | 2012-02-29 01:26:58 +0800 | [diff] [blame] | 74 | cUnit->compiler->ComputeInvokeInfo(dexMethodIdx, &mUnit, type, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 75 | vtableIdx) |
| 76 | && !SLOW_INVOKE_PATH; |
| 77 | if (type == kInterface) { |
| 78 | nextCallInsn = fastPath ? nextInterfaceCallInsn |
| 79 | : nextInterfaceCallInsnWithAccessCheck; |
| 80 | skipThis = false; |
| 81 | } else if (type == kDirect) { |
| 82 | if (fastPath) { |
| 83 | pNullCk = &nullCk; |
| 84 | } |
| 85 | nextCallInsn = fastPath ? nextSDCallInsn : nextDirectCallInsnSP; |
| 86 | skipThis = false; |
| 87 | } else if (type == kStatic) { |
| 88 | nextCallInsn = fastPath ? nextSDCallInsn : nextStaticCallInsnSP; |
| 89 | skipThis = false; |
| 90 | } else if (type == kSuper) { |
| 91 | nextCallInsn = fastPath ? nextSuperCallInsn : nextSuperCallInsnSP; |
| 92 | skipThis = fastPath; |
| 93 | } else { |
| 94 | DCHECK_EQ(type, kVirtual); |
| 95 | nextCallInsn = fastPath ? nextVCallInsn : nextVCallInsnSP; |
| 96 | skipThis = fastPath; |
| 97 | } |
| 98 | if (!isRange) { |
| 99 | callState = genDalvikArgsNoRange(cUnit, mir, dInsn, callState, pNullCk, |
| 100 | nextCallInsn, dexMethodIdx, |
| 101 | vtableIdx, skipThis); |
| 102 | } else { |
| 103 | callState = genDalvikArgsRange(cUnit, mir, dInsn, callState, pNullCk, |
| 104 | nextCallInsn, dexMethodIdx, vtableIdx, |
| 105 | skipThis); |
| 106 | } |
| 107 | // Finish up any of the call sequence not interleaved in arg loading |
| 108 | while (callState >= 0) { |
| 109 | callState = nextCallInsn(cUnit, mir, callState, dexMethodIdx, |
| 110 | vtableIdx); |
| 111 | } |
| 112 | if (DISPLAY_MISSING_TARGETS) { |
| 113 | genShowTarget(cUnit); |
| 114 | } |
buzbee | 0398c42 | 2012-03-02 15:22:47 -0800 | [diff] [blame] | 115 | opReg(cUnit, kOpBlx, rINVOKE_TGT); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 116 | oatClobberCalleeSave(cUnit); |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 117 | #endif |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Target-independent code generation. Use only high-level |
| 122 | * load/store utilities here, or target-dependent genXX() handlers |
| 123 | * when necessary. |
| 124 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 125 | bool compileDalvikInstruction(CompilationUnit* cUnit, MIR* mir, |
| 126 | BasicBlock* bb, LIR* labelList) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 127 | { |
| 128 | bool res = false; // Assume success |
| 129 | RegLocation rlSrc[3]; |
| 130 | RegLocation rlDest = badLoc; |
| 131 | RegLocation rlResult = badLoc; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 132 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 133 | |
| 134 | /* Prep Src and Dest locations */ |
| 135 | int nextSreg = 0; |
| 136 | int nextLoc = 0; |
| 137 | int attrs = oatDataFlowAttributes[opcode]; |
| 138 | rlSrc[0] = rlSrc[1] = rlSrc[2] = badLoc; |
| 139 | if (attrs & DF_UA) { |
| 140 | rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg); |
| 141 | nextSreg++; |
| 142 | } else if (attrs & DF_UA_WIDE) { |
| 143 | rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg, |
| 144 | nextSreg + 1); |
| 145 | nextSreg+= 2; |
| 146 | } |
| 147 | if (attrs & DF_UB) { |
| 148 | rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg); |
| 149 | nextSreg++; |
| 150 | } else if (attrs & DF_UB_WIDE) { |
| 151 | rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg, |
| 152 | nextSreg + 1); |
| 153 | nextSreg+= 2; |
| 154 | } |
| 155 | if (attrs & DF_UC) { |
| 156 | rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg); |
| 157 | } else if (attrs & DF_UC_WIDE) { |
| 158 | rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg, |
| 159 | nextSreg + 1); |
| 160 | } |
| 161 | if (attrs & DF_DA) { |
| 162 | rlDest = oatGetDest(cUnit, mir, 0); |
| 163 | } else if (attrs & DF_DA_WIDE) { |
| 164 | rlDest = oatGetDestWide(cUnit, mir, 0, 1); |
| 165 | } |
| 166 | |
| 167 | switch(opcode) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 168 | case Instruction::NOP: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 169 | break; |
| 170 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 171 | case Instruction::MOVE_EXCEPTION: |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 172 | #if defined(TARGET_X86) |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 173 | UNIMPLEMENTED(WARNING) << "Instruction::MOVE_EXCEPTION"; |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 174 | #else |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 175 | int exOffset; |
| 176 | int resetReg; |
| 177 | exOffset = Thread::ExceptionOffset().Int32Value(); |
| 178 | resetReg = oatAllocTemp(cUnit); |
| 179 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 180 | loadWordDisp(cUnit, rSELF, exOffset, rlResult.lowReg); |
| 181 | loadConstant(cUnit, resetReg, 0); |
| 182 | storeWordDisp(cUnit, rSELF, exOffset, resetReg); |
| 183 | storeValue(cUnit, rlDest, rlResult); |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 184 | #endif |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 185 | break; |
| 186 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 187 | case Instruction::RETURN_VOID: |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 188 | if (!cUnit->attrs & METHOD_IS_LEAF) { |
| 189 | genSuspendTest(cUnit, mir); |
| 190 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 191 | break; |
| 192 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 193 | case Instruction::RETURN: |
| 194 | case Instruction::RETURN_OBJECT: |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 195 | if (!cUnit->attrs & METHOD_IS_LEAF) { |
| 196 | genSuspendTest(cUnit, mir); |
| 197 | } |
| 198 | storeValue(cUnit, oatGetReturn(cUnit), rlSrc[0]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 199 | break; |
| 200 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 201 | case Instruction::RETURN_WIDE: |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 202 | if (!cUnit->attrs & METHOD_IS_LEAF) { |
| 203 | genSuspendTest(cUnit, mir); |
| 204 | } |
| 205 | storeValueWide(cUnit, oatGetReturnWide(cUnit), rlSrc[0]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 206 | break; |
| 207 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 208 | case Instruction::MOVE_RESULT_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 209 | if (mir->optimizationFlags & MIR_INLINED) |
| 210 | break; // Nop - combined w/ previous invoke |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 211 | storeValueWide(cUnit, rlDest, oatGetReturnWide(cUnit)); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 212 | break; |
| 213 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 214 | case Instruction::MOVE_RESULT: |
| 215 | case Instruction::MOVE_RESULT_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 216 | if (mir->optimizationFlags & MIR_INLINED) |
| 217 | break; // Nop - combined w/ previous invoke |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 218 | storeValue(cUnit, rlDest, oatGetReturn(cUnit)); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 219 | break; |
| 220 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 221 | case Instruction::MOVE: |
| 222 | case Instruction::MOVE_OBJECT: |
| 223 | case Instruction::MOVE_16: |
| 224 | case Instruction::MOVE_OBJECT_16: |
| 225 | case Instruction::MOVE_FROM16: |
| 226 | case Instruction::MOVE_OBJECT_FROM16: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 227 | storeValue(cUnit, rlDest, rlSrc[0]); |
| 228 | break; |
| 229 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 230 | case Instruction::MOVE_WIDE: |
| 231 | case Instruction::MOVE_WIDE_16: |
| 232 | case Instruction::MOVE_WIDE_FROM16: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 233 | storeValueWide(cUnit, rlDest, rlSrc[0]); |
| 234 | break; |
| 235 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 236 | case Instruction::CONST: |
| 237 | case Instruction::CONST_4: |
| 238 | case Instruction::CONST_16: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 239 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 240 | loadConstantNoClobber(cUnit, rlResult.lowReg, mir->dalvikInsn.vB); |
| 241 | storeValue(cUnit, rlDest, rlResult); |
| 242 | break; |
| 243 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 244 | case Instruction::CONST_HIGH16: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 245 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 246 | loadConstantNoClobber(cUnit, rlResult.lowReg, |
| 247 | mir->dalvikInsn.vB << 16); |
| 248 | storeValue(cUnit, rlDest, rlResult); |
| 249 | break; |
| 250 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 251 | case Instruction::CONST_WIDE_16: |
| 252 | case Instruction::CONST_WIDE_32: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 253 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 254 | loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, |
| 255 | mir->dalvikInsn.vB, |
| 256 | (mir->dalvikInsn.vB & 0x80000000) ? -1 : 0); |
| 257 | storeValueWide(cUnit, rlDest, rlResult); |
| 258 | break; |
| 259 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 260 | case Instruction::CONST_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 261 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 262 | loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, |
| 263 | mir->dalvikInsn.vB_wide & 0xffffffff, |
| 264 | (mir->dalvikInsn.vB_wide >> 32) & 0xffffffff); |
| 265 | storeValueWide(cUnit, rlDest, rlResult); |
| 266 | break; |
| 267 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 268 | case Instruction::CONST_WIDE_HIGH16: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 269 | rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 270 | loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, |
| 271 | 0, mir->dalvikInsn.vB << 16); |
| 272 | storeValueWide(cUnit, rlDest, rlResult); |
| 273 | break; |
| 274 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 275 | case Instruction::MONITOR_ENTER: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 276 | genMonitorEnter(cUnit, mir, rlSrc[0]); |
| 277 | break; |
| 278 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 279 | case Instruction::MONITOR_EXIT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 280 | genMonitorExit(cUnit, mir, rlSrc[0]); |
| 281 | break; |
| 282 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 283 | case Instruction::CHECK_CAST: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 284 | genCheckCast(cUnit, mir, rlSrc[0]); |
| 285 | break; |
| 286 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 287 | case Instruction::INSTANCE_OF: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 288 | genInstanceof(cUnit, mir, rlDest, rlSrc[0]); |
| 289 | break; |
| 290 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 291 | case Instruction::NEW_INSTANCE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 292 | genNewInstance(cUnit, mir, rlDest); |
| 293 | break; |
| 294 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 295 | case Instruction::THROW: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 296 | genThrow(cUnit, mir, rlSrc[0]); |
| 297 | break; |
| 298 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 299 | case Instruction::THROW_VERIFICATION_ERROR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 300 | genThrowVerificationError(cUnit, mir); |
| 301 | break; |
| 302 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 303 | case Instruction::ARRAY_LENGTH: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 304 | int lenOffset; |
| 305 | lenOffset = Array::LengthOffset().Int32Value(); |
| 306 | rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg); |
| 307 | genNullCheck(cUnit, rlSrc[0].sRegLow, rlSrc[0].lowReg, mir); |
| 308 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 309 | loadWordDisp(cUnit, rlSrc[0].lowReg, lenOffset, |
| 310 | rlResult.lowReg); |
| 311 | storeValue(cUnit, rlDest, rlResult); |
| 312 | break; |
| 313 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 314 | case Instruction::CONST_STRING: |
| 315 | case Instruction::CONST_STRING_JUMBO: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 316 | genConstString(cUnit, mir, rlDest, rlSrc[0]); |
| 317 | break; |
| 318 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 319 | case Instruction::CONST_CLASS: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 320 | genConstClass(cUnit, mir, rlDest, rlSrc[0]); |
| 321 | break; |
| 322 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 323 | case Instruction::FILL_ARRAY_DATA: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 324 | genFillArrayData(cUnit, mir, rlSrc[0]); |
| 325 | break; |
| 326 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 327 | case Instruction::FILLED_NEW_ARRAY: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 328 | genFilledNewArray(cUnit, mir, false /* not range */); |
| 329 | break; |
| 330 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 331 | case Instruction::FILLED_NEW_ARRAY_RANGE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 332 | genFilledNewArray(cUnit, mir, true /* range */); |
| 333 | break; |
| 334 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 335 | case Instruction::NEW_ARRAY: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 336 | genNewArray(cUnit, mir, rlDest, rlSrc[0]); |
| 337 | break; |
| 338 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 339 | case Instruction::GOTO: |
| 340 | case Instruction::GOTO_16: |
| 341 | case Instruction::GOTO_32: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 342 | if (bb->taken->startOffset <= mir->offset) { |
| 343 | genSuspendTest(cUnit, mir); |
| 344 | } |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 345 | opUnconditionalBranch(cUnit, &labelList[bb->taken->id]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 346 | break; |
| 347 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 348 | case Instruction::PACKED_SWITCH: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 349 | genPackedSwitch(cUnit, mir, rlSrc[0]); |
| 350 | break; |
| 351 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 352 | case Instruction::SPARSE_SWITCH: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 353 | genSparseSwitch(cUnit, mir, rlSrc[0]); |
| 354 | break; |
| 355 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 356 | case Instruction::CMPL_FLOAT: |
| 357 | case Instruction::CMPG_FLOAT: |
| 358 | case Instruction::CMPL_DOUBLE: |
| 359 | case Instruction::CMPG_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 360 | res = genCmpFP(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 361 | break; |
| 362 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 363 | case Instruction::CMP_LONG: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 364 | genCmpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 365 | break; |
| 366 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 367 | case Instruction::IF_EQ: |
| 368 | case Instruction::IF_NE: |
| 369 | case Instruction::IF_LT: |
| 370 | case Instruction::IF_GE: |
| 371 | case Instruction::IF_GT: |
| 372 | case Instruction::IF_LE: { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 373 | bool backwardBranch; |
| 374 | backwardBranch = (bb->taken->startOffset <= mir->offset); |
| 375 | if (backwardBranch) { |
| 376 | genSuspendTest(cUnit, mir); |
| 377 | } |
| 378 | genCompareAndBranch(cUnit, bb, mir, rlSrc[0], rlSrc[1], labelList); |
| 379 | break; |
| 380 | } |
| 381 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 382 | case Instruction::IF_EQZ: |
| 383 | case Instruction::IF_NEZ: |
| 384 | case Instruction::IF_LTZ: |
| 385 | case Instruction::IF_GEZ: |
| 386 | case Instruction::IF_GTZ: |
| 387 | case Instruction::IF_LEZ: { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 388 | bool backwardBranch; |
| 389 | backwardBranch = (bb->taken->startOffset <= mir->offset); |
| 390 | if (backwardBranch) { |
| 391 | genSuspendTest(cUnit, mir); |
| 392 | } |
| 393 | genCompareZeroAndBranch(cUnit, bb, mir, rlSrc[0], labelList); |
| 394 | break; |
| 395 | } |
| 396 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 397 | case Instruction::AGET_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 398 | genArrayGet(cUnit, mir, kLong, rlSrc[0], rlSrc[1], rlDest, 3); |
| 399 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 400 | case Instruction::AGET: |
| 401 | case Instruction::AGET_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 402 | genArrayGet(cUnit, mir, kWord, rlSrc[0], rlSrc[1], rlDest, 2); |
| 403 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 404 | case Instruction::AGET_BOOLEAN: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 405 | genArrayGet(cUnit, mir, kUnsignedByte, rlSrc[0], rlSrc[1], |
| 406 | rlDest, 0); |
| 407 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 408 | case Instruction::AGET_BYTE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 409 | genArrayGet(cUnit, mir, kSignedByte, rlSrc[0], rlSrc[1], rlDest, 0); |
| 410 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 411 | case Instruction::AGET_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 412 | genArrayGet(cUnit, mir, kUnsignedHalf, rlSrc[0], rlSrc[1], |
| 413 | rlDest, 1); |
| 414 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 415 | case Instruction::AGET_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 416 | genArrayGet(cUnit, mir, kSignedHalf, rlSrc[0], rlSrc[1], rlDest, 1); |
| 417 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 418 | case Instruction::APUT_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 419 | genArrayPut(cUnit, mir, kLong, rlSrc[1], rlSrc[2], rlSrc[0], 3); |
| 420 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 421 | case Instruction::APUT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 422 | genArrayPut(cUnit, mir, kWord, rlSrc[1], rlSrc[2], rlSrc[0], 2); |
| 423 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 424 | case Instruction::APUT_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 425 | genArrayObjPut(cUnit, mir, rlSrc[1], rlSrc[2], rlSrc[0], 2); |
| 426 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 427 | case Instruction::APUT_SHORT: |
| 428 | case Instruction::APUT_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 429 | genArrayPut(cUnit, mir, kUnsignedHalf, rlSrc[1], rlSrc[2], |
| 430 | rlSrc[0], 1); |
| 431 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 432 | case Instruction::APUT_BYTE: |
| 433 | case Instruction::APUT_BOOLEAN: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 434 | genArrayPut(cUnit, mir, kUnsignedByte, rlSrc[1], rlSrc[2], |
| 435 | rlSrc[0], 0); |
| 436 | break; |
| 437 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 438 | case Instruction::IGET_OBJECT: |
| 439 | //case Instruction::IGET_OBJECT_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 440 | genIGet(cUnit, mir, kWord, rlDest, rlSrc[0], false, true); |
| 441 | break; |
| 442 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 443 | case Instruction::IGET_WIDE: |
| 444 | //case Instruction::IGET_WIDE_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 445 | genIGet(cUnit, mir, kLong, rlDest, rlSrc[0], true, false); |
| 446 | break; |
| 447 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 448 | case Instruction::IGET: |
| 449 | //case Instruction::IGET_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 450 | genIGet(cUnit, mir, kWord, rlDest, rlSrc[0], false, false); |
| 451 | break; |
| 452 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 453 | case Instruction::IGET_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 454 | genIGet(cUnit, mir, kUnsignedHalf, rlDest, rlSrc[0], false, false); |
| 455 | break; |
| 456 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 457 | case Instruction::IGET_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 458 | genIGet(cUnit, mir, kSignedHalf, rlDest, rlSrc[0], false, false); |
| 459 | break; |
| 460 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 461 | case Instruction::IGET_BOOLEAN: |
| 462 | case Instruction::IGET_BYTE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 463 | genIGet(cUnit, mir, kUnsignedByte, rlDest, rlSrc[0], false, false); |
| 464 | break; |
| 465 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 466 | case Instruction::IPUT_WIDE: |
| 467 | //case Instruction::IPUT_WIDE_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 468 | genIPut(cUnit, mir, kLong, rlSrc[0], rlSrc[1], true, false); |
| 469 | break; |
| 470 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 471 | case Instruction::IPUT_OBJECT: |
| 472 | //case Instruction::IPUT_OBJECT_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 473 | genIPut(cUnit, mir, kWord, rlSrc[0], rlSrc[1], false, true); |
| 474 | break; |
| 475 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 476 | case Instruction::IPUT: |
| 477 | //case Instruction::IPUT_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 478 | genIPut(cUnit, mir, kWord, rlSrc[0], rlSrc[1], false, false); |
| 479 | break; |
| 480 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 481 | case Instruction::IPUT_BOOLEAN: |
| 482 | case Instruction::IPUT_BYTE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 483 | genIPut(cUnit, mir, kUnsignedByte, rlSrc[0], rlSrc[1], false, false); |
| 484 | break; |
| 485 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 486 | case Instruction::IPUT_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 487 | genIPut(cUnit, mir, kUnsignedHalf, rlSrc[0], rlSrc[1], false, false); |
| 488 | break; |
| 489 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 490 | case Instruction::IPUT_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 491 | genIPut(cUnit, mir, kSignedHalf, rlSrc[0], rlSrc[1], false, false); |
| 492 | break; |
| 493 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 494 | case Instruction::SGET_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 495 | genSget(cUnit, mir, rlDest, false, true); |
| 496 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 497 | case Instruction::SGET: |
| 498 | case Instruction::SGET_BOOLEAN: |
| 499 | case Instruction::SGET_BYTE: |
| 500 | case Instruction::SGET_CHAR: |
| 501 | case Instruction::SGET_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 502 | genSget(cUnit, mir, rlDest, false, false); |
| 503 | break; |
| 504 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 505 | case Instruction::SGET_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 506 | genSget(cUnit, mir, rlDest, true, false); |
| 507 | break; |
| 508 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 509 | case Instruction::SPUT_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 510 | genSput(cUnit, mir, rlSrc[0], false, true); |
| 511 | break; |
| 512 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 513 | case Instruction::SPUT: |
| 514 | case Instruction::SPUT_BOOLEAN: |
| 515 | case Instruction::SPUT_BYTE: |
| 516 | case Instruction::SPUT_CHAR: |
| 517 | case Instruction::SPUT_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 518 | genSput(cUnit, mir, rlSrc[0], false, false); |
| 519 | break; |
| 520 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 521 | case Instruction::SPUT_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 522 | genSput(cUnit, mir, rlSrc[0], true, false); |
| 523 | break; |
| 524 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 525 | case Instruction::INVOKE_STATIC_RANGE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 526 | genInvoke(cUnit, mir, kStatic, true /*range*/); |
| 527 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 528 | case Instruction::INVOKE_STATIC: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 529 | genInvoke(cUnit, mir, kStatic, false /*range*/); |
| 530 | break; |
| 531 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 532 | case Instruction::INVOKE_DIRECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 533 | genInvoke(cUnit, mir, kDirect, false /*range*/); |
| 534 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 535 | case Instruction::INVOKE_DIRECT_RANGE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 536 | genInvoke(cUnit, mir, kDirect, true /*range*/); |
| 537 | break; |
| 538 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 539 | case Instruction::INVOKE_VIRTUAL: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 540 | genInvoke(cUnit, mir, kVirtual, false /*range*/); |
| 541 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 542 | case Instruction::INVOKE_VIRTUAL_RANGE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 543 | genInvoke(cUnit, mir, kVirtual, true /*range*/); |
| 544 | break; |
| 545 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 546 | case Instruction::INVOKE_SUPER: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 547 | genInvoke(cUnit, mir, kSuper, false /*range*/); |
| 548 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 549 | case Instruction::INVOKE_SUPER_RANGE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 550 | genInvoke(cUnit, mir, kSuper, true /*range*/); |
| 551 | break; |
| 552 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 553 | case Instruction::INVOKE_INTERFACE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 554 | genInvoke(cUnit, mir, kInterface, false /*range*/); |
| 555 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 556 | case Instruction::INVOKE_INTERFACE_RANGE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 557 | genInvoke(cUnit, mir, kInterface, true /*range*/); |
| 558 | break; |
| 559 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 560 | case Instruction::NEG_INT: |
| 561 | case Instruction::NOT_INT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 562 | res = genArithOpInt(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 563 | break; |
| 564 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 565 | case Instruction::NEG_LONG: |
| 566 | case Instruction::NOT_LONG: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 567 | res = genArithOpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 568 | break; |
| 569 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 570 | case Instruction::NEG_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 571 | res = genArithOpFloat(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 572 | break; |
| 573 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 574 | case Instruction::NEG_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 575 | res = genArithOpDouble(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 576 | break; |
| 577 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 578 | case Instruction::INT_TO_LONG: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 579 | genIntToLong(cUnit, mir, rlDest, rlSrc[0]); |
| 580 | break; |
| 581 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 582 | case Instruction::LONG_TO_INT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 583 | rlSrc[0] = oatUpdateLocWide(cUnit, rlSrc[0]); |
| 584 | rlSrc[0] = oatWideToNarrow(cUnit, rlSrc[0]); |
| 585 | storeValue(cUnit, rlDest, rlSrc[0]); |
| 586 | break; |
| 587 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 588 | case Instruction::INT_TO_BYTE: |
| 589 | case Instruction::INT_TO_SHORT: |
| 590 | case Instruction::INT_TO_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 591 | genIntNarrowing(cUnit, mir, rlDest, rlSrc[0]); |
| 592 | break; |
| 593 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 594 | case Instruction::INT_TO_FLOAT: |
| 595 | case Instruction::INT_TO_DOUBLE: |
| 596 | case Instruction::LONG_TO_FLOAT: |
| 597 | case Instruction::LONG_TO_DOUBLE: |
| 598 | case Instruction::FLOAT_TO_INT: |
| 599 | case Instruction::FLOAT_TO_LONG: |
| 600 | case Instruction::FLOAT_TO_DOUBLE: |
| 601 | case Instruction::DOUBLE_TO_INT: |
| 602 | case Instruction::DOUBLE_TO_LONG: |
| 603 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 604 | genConversion(cUnit, mir); |
| 605 | break; |
| 606 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 607 | case Instruction::ADD_INT: |
| 608 | case Instruction::SUB_INT: |
| 609 | case Instruction::MUL_INT: |
| 610 | case Instruction::DIV_INT: |
| 611 | case Instruction::REM_INT: |
| 612 | case Instruction::AND_INT: |
| 613 | case Instruction::OR_INT: |
| 614 | case Instruction::XOR_INT: |
| 615 | case Instruction::SHL_INT: |
| 616 | case Instruction::SHR_INT: |
| 617 | case Instruction::USHR_INT: |
| 618 | case Instruction::ADD_INT_2ADDR: |
| 619 | case Instruction::SUB_INT_2ADDR: |
| 620 | case Instruction::MUL_INT_2ADDR: |
| 621 | case Instruction::DIV_INT_2ADDR: |
| 622 | case Instruction::REM_INT_2ADDR: |
| 623 | case Instruction::AND_INT_2ADDR: |
| 624 | case Instruction::OR_INT_2ADDR: |
| 625 | case Instruction::XOR_INT_2ADDR: |
| 626 | case Instruction::SHL_INT_2ADDR: |
| 627 | case Instruction::SHR_INT_2ADDR: |
| 628 | case Instruction::USHR_INT_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 629 | genArithOpInt(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 630 | break; |
| 631 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 632 | case Instruction::ADD_LONG: |
| 633 | case Instruction::SUB_LONG: |
| 634 | case Instruction::MUL_LONG: |
| 635 | case Instruction::DIV_LONG: |
| 636 | case Instruction::REM_LONG: |
| 637 | case Instruction::AND_LONG: |
| 638 | case Instruction::OR_LONG: |
| 639 | case Instruction::XOR_LONG: |
| 640 | case Instruction::ADD_LONG_2ADDR: |
| 641 | case Instruction::SUB_LONG_2ADDR: |
| 642 | case Instruction::MUL_LONG_2ADDR: |
| 643 | case Instruction::DIV_LONG_2ADDR: |
| 644 | case Instruction::REM_LONG_2ADDR: |
| 645 | case Instruction::AND_LONG_2ADDR: |
| 646 | case Instruction::OR_LONG_2ADDR: |
| 647 | case Instruction::XOR_LONG_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 648 | genArithOpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 649 | break; |
| 650 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 651 | case Instruction::SHL_LONG: |
| 652 | case Instruction::SHR_LONG: |
| 653 | case Instruction::USHR_LONG: |
| 654 | case Instruction::SHL_LONG_2ADDR: |
| 655 | case Instruction::SHR_LONG_2ADDR: |
| 656 | case Instruction::USHR_LONG_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 657 | genShiftOpLong(cUnit,mir, rlDest, rlSrc[0], rlSrc[1]); |
| 658 | break; |
| 659 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 660 | case Instruction::ADD_FLOAT: |
| 661 | case Instruction::SUB_FLOAT: |
| 662 | case Instruction::MUL_FLOAT: |
| 663 | case Instruction::DIV_FLOAT: |
| 664 | case Instruction::REM_FLOAT: |
| 665 | case Instruction::ADD_FLOAT_2ADDR: |
| 666 | case Instruction::SUB_FLOAT_2ADDR: |
| 667 | case Instruction::MUL_FLOAT_2ADDR: |
| 668 | case Instruction::DIV_FLOAT_2ADDR: |
| 669 | case Instruction::REM_FLOAT_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 670 | genArithOpFloat(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 671 | break; |
| 672 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 673 | case Instruction::ADD_DOUBLE: |
| 674 | case Instruction::SUB_DOUBLE: |
| 675 | case Instruction::MUL_DOUBLE: |
| 676 | case Instruction::DIV_DOUBLE: |
| 677 | case Instruction::REM_DOUBLE: |
| 678 | case Instruction::ADD_DOUBLE_2ADDR: |
| 679 | case Instruction::SUB_DOUBLE_2ADDR: |
| 680 | case Instruction::MUL_DOUBLE_2ADDR: |
| 681 | case Instruction::DIV_DOUBLE_2ADDR: |
| 682 | case Instruction::REM_DOUBLE_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 683 | genArithOpDouble(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 684 | break; |
| 685 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 686 | case Instruction::RSUB_INT: |
| 687 | case Instruction::ADD_INT_LIT16: |
| 688 | case Instruction::MUL_INT_LIT16: |
| 689 | case Instruction::DIV_INT_LIT16: |
| 690 | case Instruction::REM_INT_LIT16: |
| 691 | case Instruction::AND_INT_LIT16: |
| 692 | case Instruction::OR_INT_LIT16: |
| 693 | case Instruction::XOR_INT_LIT16: |
| 694 | case Instruction::ADD_INT_LIT8: |
| 695 | case Instruction::RSUB_INT_LIT8: |
| 696 | case Instruction::MUL_INT_LIT8: |
| 697 | case Instruction::DIV_INT_LIT8: |
| 698 | case Instruction::REM_INT_LIT8: |
| 699 | case Instruction::AND_INT_LIT8: |
| 700 | case Instruction::OR_INT_LIT8: |
| 701 | case Instruction::XOR_INT_LIT8: |
| 702 | case Instruction::SHL_INT_LIT8: |
| 703 | case Instruction::SHR_INT_LIT8: |
| 704 | case Instruction::USHR_INT_LIT8: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 705 | genArithOpIntLit(cUnit, mir, rlDest, rlSrc[0], mir->dalvikInsn.vC); |
| 706 | break; |
| 707 | |
| 708 | default: |
| 709 | res = true; |
| 710 | } |
| 711 | return res; |
| 712 | } |
| 713 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 714 | const char* extendedMIROpNames[kMirOpLast - kMirOpFirst] = { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 715 | "kMirOpPhi", |
| 716 | "kMirOpNullNRangeUpCheck", |
| 717 | "kMirOpNullNRangeDownCheck", |
| 718 | "kMirOpLowerBound", |
| 719 | "kMirOpPunt", |
| 720 | "kMirOpCheckInlinePrediction", |
| 721 | }; |
| 722 | |
| 723 | /* Extended MIR instructions like PHI */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 724 | void handleExtendedMethodMIR(CompilationUnit* cUnit, MIR* mir) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 725 | { |
| 726 | int opOffset = mir->dalvikInsn.opcode - kMirOpFirst; |
| 727 | char* msg = NULL; |
| 728 | if (cUnit->printMe) { |
| 729 | msg = (char*)oatNew(cUnit, strlen(extendedMIROpNames[opOffset]) + 1, |
| 730 | false, kAllocDebugInfo); |
| 731 | strcpy(msg, extendedMIROpNames[opOffset]); |
| 732 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 733 | LIR* op = newLIR1(cUnit, kPseudoExtended, (int) msg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 734 | |
| 735 | switch ((ExtendedMIROpcode)mir->dalvikInsn.opcode) { |
| 736 | case kMirOpPhi: { |
| 737 | char* ssaString = NULL; |
| 738 | if (cUnit->printMe) { |
| 739 | ssaString = oatGetSSAString(cUnit, mir->ssaRep); |
| 740 | } |
| 741 | op->flags.isNop = true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 742 | newLIR1(cUnit, kPseudoSSARep, (int) ssaString); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 743 | break; |
| 744 | } |
| 745 | default: |
| 746 | break; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | /* Handle the content in each basic block */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 751 | bool methodBlockCodeGen(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 752 | { |
| 753 | MIR* mir; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 754 | LIR* labelList = (LIR*) cUnit->blockLabelList; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 755 | int blockId = bb->id; |
| 756 | |
| 757 | cUnit->curBlock = bb; |
| 758 | labelList[blockId].operands[0] = bb->startOffset; |
| 759 | |
| 760 | /* Insert the block label */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 761 | labelList[blockId].opcode = kPseudoNormalBlockLabel; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 762 | oatAppendLIR(cUnit, (LIR*) &labelList[blockId]); |
| 763 | |
| 764 | /* Reset local optimization data on block boundaries */ |
| 765 | oatResetRegPool(cUnit); |
| 766 | oatClobberAllRegs(cUnit); |
| 767 | oatResetDefTracking(cUnit); |
| 768 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 769 | LIR* headLIR = NULL; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 770 | |
| 771 | if (bb->blockType == kEntryBlock) { |
| 772 | genEntrySequence(cUnit, bb); |
| 773 | } else if (bb->blockType == kExitBlock) { |
| 774 | genExitSequence(cUnit, bb); |
| 775 | } |
| 776 | |
| 777 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 778 | |
| 779 | oatResetRegPool(cUnit); |
| 780 | if (cUnit->disableOpt & (1 << kTrackLiveTemps)) { |
| 781 | oatClobberAllRegs(cUnit); |
| 782 | } |
| 783 | |
| 784 | if (cUnit->disableOpt & (1 << kSuppressLoads)) { |
| 785 | oatResetDefTracking(cUnit); |
| 786 | } |
| 787 | |
| 788 | if ((int)mir->dalvikInsn.opcode >= (int)kMirOpFirst) { |
| 789 | handleExtendedMethodMIR(cUnit, mir); |
| 790 | continue; |
| 791 | } |
| 792 | |
| 793 | cUnit->currentDalvikOffset = mir->offset; |
| 794 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 795 | Instruction::Code dalvikOpcode = mir->dalvikInsn.opcode; |
| 796 | Instruction::Format dalvikFormat = Instruction::FormatOf(dalvikOpcode); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 797 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 798 | LIR* boundaryLIR; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 799 | |
| 800 | /* Mark the beginning of a Dalvik instruction for line tracking */ |
| 801 | char* instStr = cUnit->printMe ? |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 802 | oatGetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 803 | boundaryLIR = newLIR1(cUnit, kPseudoDalvikByteCodeBoundary, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 804 | (intptr_t) instStr); |
| 805 | cUnit->boundaryMap.insert(std::make_pair(mir->offset, |
| 806 | (LIR*)boundaryLIR)); |
| 807 | /* Remember the first LIR for this block */ |
| 808 | if (headLIR == NULL) { |
| 809 | headLIR = boundaryLIR; |
| 810 | /* Set the first boundaryLIR as a scheduling barrier */ |
| 811 | headLIR->defMask = ENCODE_ALL; |
| 812 | } |
| 813 | |
| 814 | /* If we're compiling for the debugger, generate an update callout */ |
| 815 | if (cUnit->genDebugger) { |
| 816 | genDebuggerUpdate(cUnit, mir->offset); |
| 817 | } |
| 818 | |
| 819 | /* Don't generate the SSA annotation unless verbose mode is on */ |
| 820 | if (cUnit->printMe && mir->ssaRep) { |
| 821 | char* ssaString = oatGetSSAString(cUnit, mir->ssaRep); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 822 | newLIR1(cUnit, kPseudoSSARep, (int) ssaString); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | bool notHandled = compileDalvikInstruction(cUnit, mir, bb, labelList); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 826 | if (notHandled) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 827 | LOG(FATAL) << StringPrintf("%#06x: Opcode %#x (%s) / Fmt %d not handled", |
| 828 | mir->offset, dalvikOpcode, Instruction::Name(dalvikOpcode), dalvikFormat); |
| 829 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | |
| 833 | if (headLIR) { |
| 834 | /* |
| 835 | * Eliminate redundant loads/stores and delay stores into later |
| 836 | * slots |
| 837 | */ |
| 838 | oatApplyLocalOptimizations(cUnit, (LIR*) headLIR, |
| 839 | cUnit->lastLIRInsn); |
| 840 | |
| 841 | /* |
| 842 | * Generate an unconditional branch to the fallthrough block. |
| 843 | */ |
| 844 | if (bb->fallThrough) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 845 | opUnconditionalBranch(cUnit, |
| 846 | &labelList[bb->fallThrough->id]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 847 | } |
| 848 | } |
| 849 | return false; |
| 850 | } |
| 851 | |
| 852 | void oatMethodMIR2LIR(CompilationUnit* cUnit) |
| 853 | { |
| 854 | /* Used to hold the labels of each block */ |
| 855 | cUnit->blockLabelList = |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 856 | (void *) oatNew(cUnit, sizeof(LIR) * cUnit->numBlocks, true, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 857 | kAllocLIR); |
| 858 | |
| 859 | oatDataFlowAnalysisDispatcher(cUnit, methodBlockCodeGen, |
| 860 | kPreOrderDFSTraversal, false /* Iterative */); |
| 861 | handleSuspendLaunchpads(cUnit); |
| 862 | |
| 863 | handleThrowLaunchpads(cUnit); |
| 864 | |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 865 | if (!(cUnit->disableOpt & (1 << kSafeOptimizations))) { |
| 866 | removeRedundantBranches(cUnit); |
| 867 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | /* Needed by the ld/st optmizatons */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 871 | LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 872 | { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 873 | return opRegCopyNoInsert(cUnit, rDest, rSrc); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 874 | } |
| 875 | |
| 876 | /* Needed by the register allocator */ |
| 877 | void oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc) |
| 878 | { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 879 | opRegCopy(cUnit, rDest, rSrc); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | /* Needed by the register allocator */ |
| 883 | void oatRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi, |
| 884 | int srcLo, int srcHi) |
| 885 | { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 886 | opRegCopyWide(cUnit, destLo, destHi, srcLo, srcHi); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 887 | } |
| 888 | |
| 889 | void oatFlushRegImpl(CompilationUnit* cUnit, int rBase, |
| 890 | int displacement, int rSrc, OpSize size) |
| 891 | { |
| 892 | storeBaseDisp(cUnit, rBase, displacement, rSrc, size); |
| 893 | } |
| 894 | |
| 895 | void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase, |
| 896 | int displacement, int rSrcLo, int rSrcHi) |
| 897 | { |
| 898 | storeBaseDispWide(cUnit, rBase, displacement, rSrcLo, rSrcHi); |
| 899 | } |
| 900 | |
| 901 | } // namespace art |