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