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