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 | |
| 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) { |
| 367 | genSuspendTest(cUnit, mir); |
| 368 | } |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 369 | opUnconditionalBranch(cUnit, &labelList[bb->taken->id]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 370 | break; |
| 371 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 372 | case Instruction::PACKED_SWITCH: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 373 | genPackedSwitch(cUnit, mir, rlSrc[0]); |
| 374 | break; |
| 375 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 376 | case Instruction::SPARSE_SWITCH: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 377 | genSparseSwitch(cUnit, mir, rlSrc[0]); |
| 378 | break; |
| 379 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 380 | case Instruction::CMPL_FLOAT: |
| 381 | case Instruction::CMPG_FLOAT: |
| 382 | case Instruction::CMPL_DOUBLE: |
| 383 | case Instruction::CMPG_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 384 | res = genCmpFP(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::CMP_LONG: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 388 | genCmpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 389 | break; |
| 390 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 391 | case Instruction::IF_EQ: |
| 392 | case Instruction::IF_NE: |
| 393 | case Instruction::IF_LT: |
| 394 | case Instruction::IF_GE: |
| 395 | case Instruction::IF_GT: |
| 396 | case Instruction::IF_LE: { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 397 | bool backwardBranch; |
| 398 | backwardBranch = (bb->taken->startOffset <= mir->offset); |
| 399 | if (backwardBranch) { |
| 400 | genSuspendTest(cUnit, mir); |
| 401 | } |
| 402 | genCompareAndBranch(cUnit, bb, mir, rlSrc[0], rlSrc[1], labelList); |
| 403 | break; |
| 404 | } |
| 405 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 406 | case Instruction::IF_EQZ: |
| 407 | case Instruction::IF_NEZ: |
| 408 | case Instruction::IF_LTZ: |
| 409 | case Instruction::IF_GEZ: |
| 410 | case Instruction::IF_GTZ: |
| 411 | case Instruction::IF_LEZ: { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 412 | bool backwardBranch; |
| 413 | backwardBranch = (bb->taken->startOffset <= mir->offset); |
| 414 | if (backwardBranch) { |
| 415 | genSuspendTest(cUnit, mir); |
| 416 | } |
| 417 | genCompareZeroAndBranch(cUnit, bb, mir, rlSrc[0], labelList); |
| 418 | break; |
| 419 | } |
| 420 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 421 | case Instruction::AGET_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 422 | genArrayGet(cUnit, mir, kLong, rlSrc[0], rlSrc[1], rlDest, 3); |
| 423 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 424 | case Instruction::AGET: |
| 425 | case Instruction::AGET_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 426 | genArrayGet(cUnit, mir, kWord, rlSrc[0], rlSrc[1], rlDest, 2); |
| 427 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 428 | case Instruction::AGET_BOOLEAN: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 429 | genArrayGet(cUnit, mir, kUnsignedByte, rlSrc[0], rlSrc[1], |
| 430 | rlDest, 0); |
| 431 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 432 | case Instruction::AGET_BYTE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 433 | genArrayGet(cUnit, mir, kSignedByte, rlSrc[0], rlSrc[1], rlDest, 0); |
| 434 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 435 | case Instruction::AGET_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 436 | genArrayGet(cUnit, mir, kUnsignedHalf, rlSrc[0], rlSrc[1], |
| 437 | rlDest, 1); |
| 438 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 439 | case Instruction::AGET_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 440 | genArrayGet(cUnit, mir, kSignedHalf, rlSrc[0], rlSrc[1], rlDest, 1); |
| 441 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 442 | case Instruction::APUT_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 443 | genArrayPut(cUnit, mir, kLong, rlSrc[1], rlSrc[2], rlSrc[0], 3); |
| 444 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 445 | case Instruction::APUT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 446 | genArrayPut(cUnit, mir, kWord, rlSrc[1], rlSrc[2], rlSrc[0], 2); |
| 447 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 448 | case Instruction::APUT_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 449 | genArrayObjPut(cUnit, mir, rlSrc[1], rlSrc[2], rlSrc[0], 2); |
| 450 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 451 | case Instruction::APUT_SHORT: |
| 452 | case Instruction::APUT_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 453 | genArrayPut(cUnit, mir, kUnsignedHalf, rlSrc[1], rlSrc[2], |
| 454 | rlSrc[0], 1); |
| 455 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 456 | case Instruction::APUT_BYTE: |
| 457 | case Instruction::APUT_BOOLEAN: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 458 | genArrayPut(cUnit, mir, kUnsignedByte, rlSrc[1], rlSrc[2], |
| 459 | rlSrc[0], 0); |
| 460 | break; |
| 461 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 462 | case Instruction::IGET_OBJECT: |
| 463 | //case Instruction::IGET_OBJECT_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 464 | genIGet(cUnit, mir, kWord, rlDest, rlSrc[0], false, true); |
| 465 | break; |
| 466 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 467 | case Instruction::IGET_WIDE: |
| 468 | //case Instruction::IGET_WIDE_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 469 | genIGet(cUnit, mir, kLong, rlDest, rlSrc[0], true, false); |
| 470 | break; |
| 471 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 472 | case Instruction::IGET: |
| 473 | //case Instruction::IGET_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 474 | genIGet(cUnit, mir, kWord, rlDest, rlSrc[0], false, false); |
| 475 | break; |
| 476 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 477 | case Instruction::IGET_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 478 | genIGet(cUnit, mir, kUnsignedHalf, rlDest, rlSrc[0], false, false); |
| 479 | break; |
| 480 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 481 | case Instruction::IGET_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 482 | genIGet(cUnit, mir, kSignedHalf, rlDest, rlSrc[0], false, false); |
| 483 | break; |
| 484 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 485 | case Instruction::IGET_BOOLEAN: |
| 486 | case Instruction::IGET_BYTE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 487 | genIGet(cUnit, mir, kUnsignedByte, rlDest, rlSrc[0], false, false); |
| 488 | break; |
| 489 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 490 | case Instruction::IPUT_WIDE: |
| 491 | //case Instruction::IPUT_WIDE_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 492 | genIPut(cUnit, mir, kLong, rlSrc[0], rlSrc[1], true, false); |
| 493 | break; |
| 494 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 495 | case Instruction::IPUT_OBJECT: |
| 496 | //case Instruction::IPUT_OBJECT_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 497 | genIPut(cUnit, mir, kWord, rlSrc[0], rlSrc[1], false, true); |
| 498 | break; |
| 499 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 500 | case Instruction::IPUT: |
| 501 | //case Instruction::IPUT_VOLATILE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 502 | genIPut(cUnit, mir, kWord, rlSrc[0], rlSrc[1], false, false); |
| 503 | break; |
| 504 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 505 | case Instruction::IPUT_BOOLEAN: |
| 506 | case Instruction::IPUT_BYTE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 507 | genIPut(cUnit, mir, kUnsignedByte, 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_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 511 | genIPut(cUnit, mir, kUnsignedHalf, rlSrc[0], rlSrc[1], false, false); |
| 512 | break; |
| 513 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 514 | case Instruction::IPUT_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 515 | genIPut(cUnit, mir, kSignedHalf, rlSrc[0], rlSrc[1], false, false); |
| 516 | break; |
| 517 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 518 | case Instruction::SGET_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 519 | genSget(cUnit, mir, rlDest, false, true); |
| 520 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 521 | case Instruction::SGET: |
| 522 | case Instruction::SGET_BOOLEAN: |
| 523 | case Instruction::SGET_BYTE: |
| 524 | case Instruction::SGET_CHAR: |
| 525 | case Instruction::SGET_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 526 | genSget(cUnit, mir, rlDest, false, false); |
| 527 | break; |
| 528 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 529 | case Instruction::SGET_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 530 | genSget(cUnit, mir, rlDest, true, false); |
| 531 | break; |
| 532 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 533 | case Instruction::SPUT_OBJECT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 534 | genSput(cUnit, mir, rlSrc[0], false, true); |
| 535 | break; |
| 536 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 537 | case Instruction::SPUT: |
| 538 | case Instruction::SPUT_BOOLEAN: |
| 539 | case Instruction::SPUT_BYTE: |
| 540 | case Instruction::SPUT_CHAR: |
| 541 | case Instruction::SPUT_SHORT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 542 | genSput(cUnit, mir, rlSrc[0], false, false); |
| 543 | break; |
| 544 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 545 | case Instruction::SPUT_WIDE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 546 | genSput(cUnit, mir, rlSrc[0], true, false); |
| 547 | break; |
| 548 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 549 | case Instruction::INVOKE_STATIC_RANGE: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 550 | genInvoke(cUnit, bb, mir, kStatic, true /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 551 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 552 | case Instruction::INVOKE_STATIC: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 553 | genInvoke(cUnit, bb, mir, kStatic, false /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 554 | break; |
| 555 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 556 | case Instruction::INVOKE_DIRECT: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 557 | genInvoke(cUnit, bb, mir, kDirect, false /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 558 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 559 | case Instruction::INVOKE_DIRECT_RANGE: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 560 | genInvoke(cUnit, bb, mir, kDirect, true /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 561 | break; |
| 562 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 563 | case Instruction::INVOKE_VIRTUAL: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 564 | genInvoke(cUnit, bb, mir, kVirtual, false /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 565 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 566 | case Instruction::INVOKE_VIRTUAL_RANGE: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 567 | genInvoke(cUnit, bb, mir, kVirtual, true /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 568 | break; |
| 569 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 570 | case Instruction::INVOKE_SUPER: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 571 | genInvoke(cUnit, bb, mir, kSuper, false /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 572 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 573 | case Instruction::INVOKE_SUPER_RANGE: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 574 | genInvoke(cUnit, bb, mir, kSuper, true /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 575 | break; |
| 576 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 577 | case Instruction::INVOKE_INTERFACE: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 578 | genInvoke(cUnit, bb, mir, kInterface, false /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 579 | break; |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 580 | case Instruction::INVOKE_INTERFACE_RANGE: |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 581 | genInvoke(cUnit, bb, mir, kInterface, true /*range*/); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 582 | break; |
| 583 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 584 | case Instruction::NEG_INT: |
| 585 | case Instruction::NOT_INT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 586 | res = genArithOpInt(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 587 | break; |
| 588 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 589 | case Instruction::NEG_LONG: |
| 590 | case Instruction::NOT_LONG: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 591 | res = genArithOpLong(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_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 595 | res = genArithOpFloat(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::NEG_DOUBLE: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 599 | res = genArithOpDouble(cUnit, mir, rlDest, rlSrc[0], rlSrc[0]); |
| 600 | break; |
| 601 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 602 | case Instruction::INT_TO_LONG: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 603 | genIntToLong(cUnit, mir, rlDest, rlSrc[0]); |
| 604 | break; |
| 605 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 606 | case Instruction::LONG_TO_INT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 607 | rlSrc[0] = oatUpdateLocWide(cUnit, rlSrc[0]); |
| 608 | rlSrc[0] = oatWideToNarrow(cUnit, rlSrc[0]); |
| 609 | storeValue(cUnit, rlDest, rlSrc[0]); |
| 610 | break; |
| 611 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 612 | case Instruction::INT_TO_BYTE: |
| 613 | case Instruction::INT_TO_SHORT: |
| 614 | case Instruction::INT_TO_CHAR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 615 | genIntNarrowing(cUnit, mir, rlDest, rlSrc[0]); |
| 616 | break; |
| 617 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 618 | case Instruction::INT_TO_FLOAT: |
| 619 | case Instruction::INT_TO_DOUBLE: |
| 620 | case Instruction::LONG_TO_FLOAT: |
| 621 | case Instruction::LONG_TO_DOUBLE: |
| 622 | case Instruction::FLOAT_TO_INT: |
| 623 | case Instruction::FLOAT_TO_LONG: |
| 624 | case Instruction::FLOAT_TO_DOUBLE: |
| 625 | case Instruction::DOUBLE_TO_INT: |
| 626 | case Instruction::DOUBLE_TO_LONG: |
| 627 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 628 | genConversion(cUnit, mir); |
| 629 | break; |
| 630 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 631 | case Instruction::ADD_INT: |
| 632 | case Instruction::SUB_INT: |
| 633 | case Instruction::MUL_INT: |
| 634 | case Instruction::DIV_INT: |
| 635 | case Instruction::REM_INT: |
| 636 | case Instruction::AND_INT: |
| 637 | case Instruction::OR_INT: |
| 638 | case Instruction::XOR_INT: |
| 639 | case Instruction::SHL_INT: |
| 640 | case Instruction::SHR_INT: |
| 641 | case Instruction::USHR_INT: |
| 642 | case Instruction::ADD_INT_2ADDR: |
| 643 | case Instruction::SUB_INT_2ADDR: |
| 644 | case Instruction::MUL_INT_2ADDR: |
| 645 | case Instruction::DIV_INT_2ADDR: |
| 646 | case Instruction::REM_INT_2ADDR: |
| 647 | case Instruction::AND_INT_2ADDR: |
| 648 | case Instruction::OR_INT_2ADDR: |
| 649 | case Instruction::XOR_INT_2ADDR: |
| 650 | case Instruction::SHL_INT_2ADDR: |
| 651 | case Instruction::SHR_INT_2ADDR: |
| 652 | case Instruction::USHR_INT_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 653 | genArithOpInt(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 654 | break; |
| 655 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 656 | case Instruction::ADD_LONG: |
| 657 | case Instruction::SUB_LONG: |
| 658 | case Instruction::MUL_LONG: |
| 659 | case Instruction::DIV_LONG: |
| 660 | case Instruction::REM_LONG: |
| 661 | case Instruction::AND_LONG: |
| 662 | case Instruction::OR_LONG: |
| 663 | case Instruction::XOR_LONG: |
| 664 | case Instruction::ADD_LONG_2ADDR: |
| 665 | case Instruction::SUB_LONG_2ADDR: |
| 666 | case Instruction::MUL_LONG_2ADDR: |
| 667 | case Instruction::DIV_LONG_2ADDR: |
| 668 | case Instruction::REM_LONG_2ADDR: |
| 669 | case Instruction::AND_LONG_2ADDR: |
| 670 | case Instruction::OR_LONG_2ADDR: |
| 671 | case Instruction::XOR_LONG_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 672 | genArithOpLong(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 673 | break; |
| 674 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 675 | case Instruction::SHL_LONG: |
| 676 | case Instruction::SHR_LONG: |
| 677 | case Instruction::USHR_LONG: |
| 678 | case Instruction::SHL_LONG_2ADDR: |
| 679 | case Instruction::SHR_LONG_2ADDR: |
| 680 | case Instruction::USHR_LONG_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 681 | genShiftOpLong(cUnit,mir, rlDest, rlSrc[0], rlSrc[1]); |
| 682 | break; |
| 683 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 684 | case Instruction::ADD_FLOAT: |
| 685 | case Instruction::SUB_FLOAT: |
| 686 | case Instruction::MUL_FLOAT: |
| 687 | case Instruction::DIV_FLOAT: |
| 688 | case Instruction::REM_FLOAT: |
| 689 | case Instruction::ADD_FLOAT_2ADDR: |
| 690 | case Instruction::SUB_FLOAT_2ADDR: |
| 691 | case Instruction::MUL_FLOAT_2ADDR: |
| 692 | case Instruction::DIV_FLOAT_2ADDR: |
| 693 | case Instruction::REM_FLOAT_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 694 | genArithOpFloat(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 695 | break; |
| 696 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 697 | case Instruction::ADD_DOUBLE: |
| 698 | case Instruction::SUB_DOUBLE: |
| 699 | case Instruction::MUL_DOUBLE: |
| 700 | case Instruction::DIV_DOUBLE: |
| 701 | case Instruction::REM_DOUBLE: |
| 702 | case Instruction::ADD_DOUBLE_2ADDR: |
| 703 | case Instruction::SUB_DOUBLE_2ADDR: |
| 704 | case Instruction::MUL_DOUBLE_2ADDR: |
| 705 | case Instruction::DIV_DOUBLE_2ADDR: |
| 706 | case Instruction::REM_DOUBLE_2ADDR: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 707 | genArithOpDouble(cUnit, mir, rlDest, rlSrc[0], rlSrc[1]); |
| 708 | break; |
| 709 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 710 | case Instruction::RSUB_INT: |
| 711 | case Instruction::ADD_INT_LIT16: |
| 712 | case Instruction::MUL_INT_LIT16: |
| 713 | case Instruction::DIV_INT_LIT16: |
| 714 | case Instruction::REM_INT_LIT16: |
| 715 | case Instruction::AND_INT_LIT16: |
| 716 | case Instruction::OR_INT_LIT16: |
| 717 | case Instruction::XOR_INT_LIT16: |
| 718 | case Instruction::ADD_INT_LIT8: |
| 719 | case Instruction::RSUB_INT_LIT8: |
| 720 | case Instruction::MUL_INT_LIT8: |
| 721 | case Instruction::DIV_INT_LIT8: |
| 722 | case Instruction::REM_INT_LIT8: |
| 723 | case Instruction::AND_INT_LIT8: |
| 724 | case Instruction::OR_INT_LIT8: |
| 725 | case Instruction::XOR_INT_LIT8: |
| 726 | case Instruction::SHL_INT_LIT8: |
| 727 | case Instruction::SHR_INT_LIT8: |
| 728 | case Instruction::USHR_INT_LIT8: |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 729 | genArithOpIntLit(cUnit, mir, rlDest, rlSrc[0], mir->dalvikInsn.vC); |
| 730 | break; |
| 731 | |
| 732 | default: |
| 733 | res = true; |
| 734 | } |
| 735 | return res; |
| 736 | } |
| 737 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 738 | const char* extendedMIROpNames[kMirOpLast - kMirOpFirst] = { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 739 | "kMirOpPhi", |
| 740 | "kMirOpNullNRangeUpCheck", |
| 741 | "kMirOpNullNRangeDownCheck", |
| 742 | "kMirOpLowerBound", |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 743 | "kMirOpCopy", |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 744 | }; |
| 745 | |
| 746 | /* Extended MIR instructions like PHI */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 747 | void handleExtendedMethodMIR(CompilationUnit* cUnit, MIR* mir) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 748 | { |
| 749 | int opOffset = mir->dalvikInsn.opcode - kMirOpFirst; |
| 750 | char* msg = NULL; |
| 751 | if (cUnit->printMe) { |
| 752 | msg = (char*)oatNew(cUnit, strlen(extendedMIROpNames[opOffset]) + 1, |
| 753 | false, kAllocDebugInfo); |
| 754 | strcpy(msg, extendedMIROpNames[opOffset]); |
| 755 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 756 | LIR* op = newLIR1(cUnit, kPseudoExtended, (int) msg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 757 | |
| 758 | switch ((ExtendedMIROpcode)mir->dalvikInsn.opcode) { |
| 759 | case kMirOpPhi: { |
| 760 | char* ssaString = NULL; |
| 761 | if (cUnit->printMe) { |
| 762 | ssaString = oatGetSSAString(cUnit, mir->ssaRep); |
| 763 | } |
| 764 | op->flags.isNop = true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 765 | newLIR1(cUnit, kPseudoSSARep, (int) ssaString); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 766 | break; |
| 767 | } |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 768 | case kMirOpCopy: { |
| 769 | RegLocation rlSrc = oatGetSrc(cUnit, mir, 0); |
| 770 | RegLocation rlDest = oatGetDest(cUnit, mir, 0); |
| 771 | storeValue(cUnit, rlDest, rlSrc); |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 772 | break; |
buzbee | 239c4e7 | 2012-03-16 08:42:29 -0700 | [diff] [blame] | 773 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 774 | default: |
| 775 | break; |
| 776 | } |
| 777 | } |
| 778 | |
| 779 | /* Handle the content in each basic block */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 780 | bool methodBlockCodeGen(CompilationUnit* cUnit, BasicBlock* bb) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 781 | { |
| 782 | MIR* mir; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 783 | LIR* labelList = (LIR*) cUnit->blockLabelList; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 784 | int blockId = bb->id; |
| 785 | |
| 786 | cUnit->curBlock = bb; |
| 787 | labelList[blockId].operands[0] = bb->startOffset; |
| 788 | |
| 789 | /* Insert the block label */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 790 | labelList[blockId].opcode = kPseudoNormalBlockLabel; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 791 | oatAppendLIR(cUnit, (LIR*) &labelList[blockId]); |
| 792 | |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 793 | /* Free temp registers and reset redundant store tracking */ |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 794 | oatResetRegPool(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 795 | oatResetDefTracking(cUnit); |
| 796 | |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 797 | /* |
| 798 | * If control reached us from our immediate predecessor via |
| 799 | * fallthrough and we have no other incoming arcs we can |
| 800 | * reuse existing liveness. Otherwise, reset. |
| 801 | */ |
| 802 | if (!bb->fallThroughTarget || bb->predecessors->numUsed != 1) { |
| 803 | oatClobberAllRegs(cUnit); |
| 804 | } |
| 805 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 806 | LIR* headLIR = NULL; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 807 | |
| 808 | if (bb->blockType == kEntryBlock) { |
| 809 | genEntrySequence(cUnit, bb); |
| 810 | } else if (bb->blockType == kExitBlock) { |
| 811 | genExitSequence(cUnit, bb); |
| 812 | } |
| 813 | |
| 814 | for (mir = bb->firstMIRInsn; mir; mir = mir->next) { |
| 815 | |
| 816 | oatResetRegPool(cUnit); |
| 817 | if (cUnit->disableOpt & (1 << kTrackLiveTemps)) { |
| 818 | oatClobberAllRegs(cUnit); |
| 819 | } |
| 820 | |
| 821 | if (cUnit->disableOpt & (1 << kSuppressLoads)) { |
| 822 | oatResetDefTracking(cUnit); |
| 823 | } |
| 824 | |
buzbee | 3d66194 | 2012-03-14 17:37:27 -0700 | [diff] [blame] | 825 | #ifndef NDEBUG |
| 826 | /* Reset temp tracking sanity check */ |
| 827 | cUnit->liveSReg = INVALID_SREG; |
| 828 | #endif |
| 829 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 830 | if ((int)mir->dalvikInsn.opcode >= (int)kMirOpFirst) { |
| 831 | handleExtendedMethodMIR(cUnit, mir); |
| 832 | continue; |
| 833 | } |
| 834 | |
| 835 | cUnit->currentDalvikOffset = mir->offset; |
| 836 | |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 837 | Instruction::Code dalvikOpcode = mir->dalvikInsn.opcode; |
| 838 | Instruction::Format dalvikFormat = Instruction::FormatOf(dalvikOpcode); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 839 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 840 | LIR* boundaryLIR; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 841 | |
| 842 | /* Mark the beginning of a Dalvik instruction for line tracking */ |
| 843 | char* instStr = cUnit->printMe ? |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 844 | oatGetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 845 | boundaryLIR = newLIR1(cUnit, kPseudoDalvikByteCodeBoundary, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 846 | (intptr_t) instStr); |
| 847 | cUnit->boundaryMap.insert(std::make_pair(mir->offset, |
| 848 | (LIR*)boundaryLIR)); |
| 849 | /* Remember the first LIR for this block */ |
| 850 | if (headLIR == NULL) { |
| 851 | headLIR = boundaryLIR; |
| 852 | /* Set the first boundaryLIR as a scheduling barrier */ |
| 853 | headLIR->defMask = ENCODE_ALL; |
| 854 | } |
| 855 | |
| 856 | /* If we're compiling for the debugger, generate an update callout */ |
| 857 | if (cUnit->genDebugger) { |
| 858 | genDebuggerUpdate(cUnit, mir->offset); |
| 859 | } |
| 860 | |
| 861 | /* Don't generate the SSA annotation unless verbose mode is on */ |
| 862 | if (cUnit->printMe && mir->ssaRep) { |
| 863 | char* ssaString = oatGetSSAString(cUnit, mir->ssaRep); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 864 | newLIR1(cUnit, kPseudoSSARep, (int) ssaString); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | bool notHandled = compileDalvikInstruction(cUnit, mir, bb, labelList); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 868 | if (notHandled) { |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 869 | LOG(FATAL) << StringPrintf("%#06x: Opcode %#x (%s) / Fmt %d not handled", |
| 870 | mir->offset, dalvikOpcode, Instruction::Name(dalvikOpcode), dalvikFormat); |
| 871 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 872 | } |
| 873 | } |
| 874 | |
| 875 | if (headLIR) { |
| 876 | /* |
| 877 | * Eliminate redundant loads/stores and delay stores into later |
| 878 | * slots |
| 879 | */ |
| 880 | oatApplyLocalOptimizations(cUnit, (LIR*) headLIR, |
| 881 | cUnit->lastLIRInsn); |
| 882 | |
| 883 | /* |
| 884 | * Generate an unconditional branch to the fallthrough block. |
| 885 | */ |
| 886 | if (bb->fallThrough) { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 887 | opUnconditionalBranch(cUnit, |
| 888 | &labelList[bb->fallThrough->id]); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 889 | } |
| 890 | } |
| 891 | return false; |
| 892 | } |
| 893 | |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 894 | /* Set basic block labels */ |
| 895 | bool labelBlocks(CompilationUnit* cUnit, BasicBlock* bb) |
| 896 | { |
| 897 | LIR* labelList = (LIR*) cUnit->blockLabelList; |
| 898 | int blockId = bb->id; |
| 899 | |
| 900 | cUnit->curBlock = bb; |
| 901 | labelList[blockId].operands[0] = bb->startOffset; |
| 902 | |
| 903 | /* Insert the block label */ |
| 904 | labelList[blockId].opcode = kPseudoNormalBlockLabel; |
| 905 | return false; |
| 906 | } |
| 907 | |
| 908 | void oatSpecialMIR2LIR(CompilationUnit* cUnit, SpecialCaseHandler specialCase) |
| 909 | { |
| 910 | /* Find the first DalvikByteCode block */ |
| 911 | int numReachableBlocks = cUnit->numReachableBlocks; |
| 912 | const GrowableList *blockList = &cUnit->blockList; |
| 913 | BasicBlock*bb = NULL; |
| 914 | for (int idx = 0; idx < numReachableBlocks; idx++) { |
| 915 | int dfsIndex = cUnit->dfsOrder.elemList[idx]; |
| 916 | bb = (BasicBlock*)oatGrowableListGetElement(blockList, dfsIndex); |
| 917 | if (bb->blockType == kDalvikByteCode) { |
| 918 | break; |
| 919 | } |
| 920 | } |
| 921 | if (bb == NULL) { |
| 922 | return; |
| 923 | } |
| 924 | DCHECK_EQ(bb->startOffset, 0); |
| 925 | DCHECK(bb->firstMIRInsn != 0); |
| 926 | |
| 927 | /* Get the first instruction */ |
| 928 | MIR* mir = bb->firstMIRInsn; |
| 929 | |
| 930 | /* Free temp registers and reset redundant store tracking */ |
| 931 | oatResetRegPool(cUnit); |
| 932 | oatResetDefTracking(cUnit); |
| 933 | oatClobberAllRegs(cUnit); |
| 934 | |
| 935 | genSpecialCase(cUnit, bb, mir, specialCase); |
| 936 | } |
| 937 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 938 | void oatMethodMIR2LIR(CompilationUnit* cUnit) |
| 939 | { |
| 940 | /* Used to hold the labels of each block */ |
| 941 | cUnit->blockLabelList = |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 942 | (void *) oatNew(cUnit, sizeof(LIR) * cUnit->numBlocks, true, |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 943 | kAllocLIR); |
| 944 | |
| 945 | oatDataFlowAnalysisDispatcher(cUnit, methodBlockCodeGen, |
| 946 | kPreOrderDFSTraversal, false /* Iterative */); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 947 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 948 | handleSuspendLaunchpads(cUnit); |
| 949 | |
| 950 | handleThrowLaunchpads(cUnit); |
| 951 | |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame^] | 952 | handleIntrinsicLaunchpads(cUnit); |
| 953 | |
buzbee | 86a4bce | 2012-03-06 18:15:00 -0800 | [diff] [blame] | 954 | if (!(cUnit->disableOpt & (1 << kSafeOptimizations))) { |
| 955 | removeRedundantBranches(cUnit); |
| 956 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | /* Needed by the ld/st optmizatons */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 960 | LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 961 | { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 962 | return opRegCopyNoInsert(cUnit, rDest, rSrc); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | /* Needed by the register allocator */ |
| 966 | void oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc) |
| 967 | { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 968 | opRegCopy(cUnit, rDest, rSrc); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | /* Needed by the register allocator */ |
| 972 | void oatRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi, |
| 973 | int srcLo, int srcHi) |
| 974 | { |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 975 | opRegCopyWide(cUnit, destLo, destHi, srcLo, srcHi); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | void oatFlushRegImpl(CompilationUnit* cUnit, int rBase, |
| 979 | int displacement, int rSrc, OpSize size) |
| 980 | { |
| 981 | storeBaseDisp(cUnit, rBase, displacement, rSrc, size); |
| 982 | } |
| 983 | |
| 984 | void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase, |
| 985 | int displacement, int rSrcLo, int rSrcHi) |
| 986 | { |
| 987 | storeBaseDispWide(cUnit, rBase, displacement, rSrcLo, rSrcHi); |
| 988 | } |
| 989 | |
| 990 | } // namespace art |