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