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