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