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