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