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