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