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