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