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