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