blob: 606a1ed98d68673f48c79c1fc69a65b2dd8ec05c [file] [log] [blame]
buzbeee3acd072012-02-25 17:03:10 -08001/*
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
19namespace art {
20
21#define DISPLAY_MISSING_TARGETS (cUnit->enableDebug & \
Bill Buzbeea114add2012-05-03 15:00:40 -070022 (1 << kDebugDisplayMissingTargets))
buzbeee3acd072012-02-25 17:03:10 -080023
buzbee2cfc6392012-05-07 14:51:40 -070024const RegLocation badLoc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
25 INVALID_REG, INVALID_REG, INVALID_SREG,
26 INVALID_SREG};
buzbeee3acd072012-02-25 17:03:10 -080027
28/* Mark register usage state and return long retloc */
Ian Rogersf7d9ad32012-03-13 18:45:39 -070029RegLocation oatGetReturnWide(CompilationUnit* cUnit, bool isDouble)
buzbeee3acd072012-02-25 17:03:10 -080030{
Bill Buzbeea114add2012-05-03 15:00:40 -070031 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;
buzbeee3acd072012-02-25 17:03:10 -080040}
41
Ian Rogersf7d9ad32012-03-13 18:45:39 -070042RegLocation oatGetReturn(CompilationUnit* cUnit, bool isFloat)
buzbeee3acd072012-02-25 17:03:10 -080043{
Ian Rogersf7d9ad32012-03-13 18:45:39 -070044 RegLocation gpr_res = LOC_C_RETURN;
45 RegLocation fpr_res = LOC_C_RETURN_FLOAT;
46 RegLocation res = isFloat ? fpr_res : gpr_res;
Bill Buzbeea114add2012-05-03 15:00:40 -070047 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;
buzbeee3acd072012-02-25 17:03:10 -080054}
55
buzbee3b3dbdd2012-06-13 13:39:34 -070056void genInvoke(CompilationUnit* cUnit, CallInfo* info)
buzbeee3acd072012-02-25 17:03:10 -080057{
buzbee15bf9802012-06-12 17:49:27 -070058 if (genIntrinsic(cUnit, info)) {
Bill Buzbeea114add2012-05-03 15:00:40 -070059 return;
60 }
buzbee15bf9802012-06-12 17:49:27 -070061 InvokeType originalType = info->type; // avoiding mutation by ComputeInvokeInfo
Bill Buzbeea114add2012-05-03 15:00:40 -070062 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);
buzbeee3acd072012-02-25 17:03:10 -080069
Bill Buzbeea114add2012-05-03 15:00:40 -070070 OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070071 *cUnit->dex_file,
Bill Buzbeea114add2012-05-03 15:00:40 -070072 cUnit->code_item, cUnit->method_idx,
73 cUnit->access_flags);
Logan Chien4dd96f52012-02-29 01:26:58 +080074
buzbee3b3dbdd2012-06-13 13:39:34 -070075 uint32_t dexMethodIdx = info->index;
Bill Buzbeea114add2012-05-03 15:00:40 -070076 int vtableIdx;
77 uintptr_t directCode;
78 uintptr_t directMethod;
79 bool skipThis;
80 bool fastPath =
buzbee15bf9802012-06-12 17:49:27 -070081 cUnit->compiler->ComputeInvokeInfo(dexMethodIdx, &mUnit, info->type,
Bill Buzbeea114add2012-05-03 15:00:40 -070082 vtableIdx, directCode,
83 directMethod)
84 && !SLOW_INVOKE_PATH;
buzbee15bf9802012-06-12 17:49:27 -070085 if (info->type == kInterface) {
Bill Buzbeea114add2012-05-03 15:00:40 -070086 nextCallInsn = fastPath ? nextInterfaceCallInsn
87 : nextInterfaceCallInsnWithAccessCheck;
88 skipThis = false;
buzbee15bf9802012-06-12 17:49:27 -070089 } else if (info->type == kDirect) {
Bill Buzbeea114add2012-05-03 15:00:40 -070090 if (fastPath) {
91 pNullCk = &nullCk;
buzbeee3acd072012-02-25 17:03:10 -080092 }
Bill Buzbeea114add2012-05-03 15:00:40 -070093 nextCallInsn = fastPath ? nextSDCallInsn : nextDirectCallInsnSP;
94 skipThis = false;
buzbee15bf9802012-06-12 17:49:27 -070095 } else if (info->type == kStatic) {
Bill Buzbeea114add2012-05-03 15:00:40 -070096 nextCallInsn = fastPath ? nextSDCallInsn : nextStaticCallInsnSP;
97 skipThis = false;
buzbee15bf9802012-06-12 17:49:27 -070098 } else if (info->type == kSuper) {
Bill Buzbeea114add2012-05-03 15:00:40 -070099 DCHECK(!fastPath); // Fast path is a direct call.
100 nextCallInsn = nextSuperCallInsnSP;
101 skipThis = false;
102 } else {
buzbee15bf9802012-06-12 17:49:27 -0700103 DCHECK_EQ(info->type, kVirtual);
Bill Buzbeea114add2012-05-03 15:00:40 -0700104 nextCallInsn = fastPath ? nextVCallInsn : nextVCallInsnSP;
105 skipThis = fastPath;
106 }
buzbee15bf9802012-06-12 17:49:27 -0700107 if (!info->isRange) {
108 callState = genDalvikArgsNoRange(cUnit, info, callState, pNullCk,
Bill Buzbeea114add2012-05-03 15:00:40 -0700109 nextCallInsn, dexMethodIdx,
110 vtableIdx, directCode, directMethod,
111 originalType, skipThis);
112 } else {
buzbee15bf9802012-06-12 17:49:27 -0700113 callState = genDalvikArgsRange(cUnit, info, callState, pNullCk,
Bill Buzbeea114add2012-05-03 15:00:40 -0700114 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) {
buzbee15bf9802012-06-12 17:49:27 -0700120 callState = nextCallInsn(cUnit, info, callState, dexMethodIdx,
Bill Buzbeea114add2012-05-03 15:00:40 -0700121 vtableIdx, directCode, directMethod,
122 originalType);
123 }
124 if (DISPLAY_MISSING_TARGETS) {
125 genShowTarget(cUnit);
126 }
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700127#if !defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700128 opReg(cUnit, kOpBlx, rINVOKE_TGT);
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700129#else
buzbee15bf9802012-06-12 17:49:27 -0700130 if (fastPath && info->type != kInterface) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700131 opMem(cUnit, kOpBlx, rARG0, Method::GetCodeOffset().Int32Value());
132 } else {
133 int trampoline = 0;
buzbee15bf9802012-06-12 17:49:27 -0700134 switch (info->type) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700135 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 Rogers6cbb2bd2012-03-16 13:45:30 -0700153 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700154 opThreadMem(cUnit, kOpBlx, trampoline);
155 }
buzbeea7678db2012-03-05 15:35:46 -0800156#endif
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700157
Bill Buzbeea114add2012-05-03 15:00:40 -0700158 oatClobberCalleeSave(cUnit);
buzbee15bf9802012-06-12 17:49:27 -0700159 if (info->result.location != kLocInvalid) {
160 // We have a following MOVE_RESULT - do it now.
161 if (info->result.wide) {
buzbee52ed7762012-06-13 23:43:14 -0700162 RegLocation retLoc = oatGetReturnWide(cUnit, info->result.fp);
buzbee15bf9802012-06-12 17:49:27 -0700163 storeValueWide(cUnit, info->result, retLoc);
164 } else {
buzbee52ed7762012-06-13 23:43:14 -0700165 RegLocation retLoc = oatGetReturn(cUnit, info->result.fp);
buzbee15bf9802012-06-12 17:49:27 -0700166 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 */
buzbee6969d502012-06-15 16:40:31 -0700177CallInfo* oatNewCallInfo(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir,
178 InvokeType type, bool isRange)
buzbee15bf9802012-06-12 17:49:27 -0700179{
buzbee3b3dbdd2012-06-13 13:39:34 -0700180 CallInfo* info = (CallInfo*)oatNew(cUnit, sizeof(CallInfo), true,
buzbee15bf9802012-06-12 17:49:27 -0700181 kAllocMisc);
182 MIR* moveResultMIR = oatFindMoveResult(cUnit, bb, mir);
183 if (moveResultMIR == NULL) {
184 info->result.location = kLocInvalid;
185 } else {
186 info->result = oatGetRawDest(cUnit, moveResultMIR);
187 moveResultMIR->dalvikInsn.opcode = Instruction::NOP;
188 }
189 info->numArgWords = mir->ssaRep->numUses;
190 info->args = (info->numArgWords == 0) ? NULL : (RegLocation*)
191 oatNew(cUnit, sizeof(RegLocation) * info->numArgWords, false, kAllocMisc);
192 for (int i = 0; i < info->numArgWords; i++) {
193 info->args[i] = oatGetRawSrc(cUnit, mir, i);
194 }
195 info->optFlags = mir->optimizationFlags;
196 info->type = type;
197 info->isRange = isRange;
buzbee3b3dbdd2012-06-13 13:39:34 -0700198 info->index = mir->dalvikInsn.vB;
buzbee15bf9802012-06-12 17:49:27 -0700199 info->offset = mir->offset;
200 return info;
buzbeee3acd072012-02-25 17:03:10 -0800201}
202
203/*
204 * Target-independent code generation. Use only high-level
205 * load/store utilities here, or target-dependent genXX() handlers
206 * when necessary.
207 */
buzbee31a4a6f2012-02-28 15:36:15 -0800208bool compileDalvikInstruction(CompilationUnit* cUnit, MIR* mir,
209 BasicBlock* bb, LIR* labelList)
buzbeee3acd072012-02-25 17:03:10 -0800210{
Bill Buzbeea114add2012-05-03 15:00:40 -0700211 bool res = false; // Assume success
212 RegLocation rlSrc[3];
213 RegLocation rlDest = badLoc;
214 RegLocation rlResult = badLoc;
215 Instruction::Code opcode = mir->dalvikInsn.opcode;
buzbee408ad162012-06-06 16:45:18 -0700216 int optFlags = mir->optimizationFlags;
buzbee408ad162012-06-06 16:45:18 -0700217 uint32_t vB = mir->dalvikInsn.vB;
218 uint32_t vC = mir->dalvikInsn.vC;
buzbeee3acd072012-02-25 17:03:10 -0800219
Bill Buzbeea114add2012-05-03 15:00:40 -0700220 /* Prep Src and Dest locations */
221 int nextSreg = 0;
222 int nextLoc = 0;
223 int attrs = oatDataFlowAttributes[opcode];
224 rlSrc[0] = rlSrc[1] = rlSrc[2] = badLoc;
225 if (attrs & DF_UA) {
buzbeebff24652012-05-06 16:22:05 -0700226 if (attrs & DF_A_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700227 rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg);
buzbeebff24652012-05-06 16:22:05 -0700228 nextSreg+= 2;
229 } else {
230 rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg);
231 nextSreg++;
232 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700233 }
234 if (attrs & DF_UB) {
buzbeebff24652012-05-06 16:22:05 -0700235 if (attrs & DF_B_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700236 rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg);
buzbeebff24652012-05-06 16:22:05 -0700237 nextSreg+= 2;
238 } else {
239 rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg);
240 nextSreg++;
241 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700242 }
243 if (attrs & DF_UC) {
buzbeebff24652012-05-06 16:22:05 -0700244 if (attrs & DF_C_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700245 rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg);
buzbeebff24652012-05-06 16:22:05 -0700246 } else {
247 rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg);
248 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700249 }
250 if (attrs & DF_DA) {
buzbeebff24652012-05-06 16:22:05 -0700251 if (attrs & DF_A_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700252 rlDest = oatGetDestWide(cUnit, mir);
buzbeebff24652012-05-06 16:22:05 -0700253 } else {
buzbee15bf9802012-06-12 17:49:27 -0700254 rlDest = oatGetDest(cUnit, mir);
buzbeebff24652012-05-06 16:22:05 -0700255 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700256 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700257 switch (opcode) {
258 case Instruction::NOP:
259 break;
buzbeee3acd072012-02-25 17:03:10 -0800260
Bill Buzbeea114add2012-05-03 15:00:40 -0700261 case Instruction::MOVE_EXCEPTION: {
262 int exOffset = Thread::ExceptionOffset().Int32Value();
263 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
Ian Rogersc6f3bb82012-03-21 20:40:33 -0700264#if defined(TARGET_X86)
Bill Buzbeea114add2012-05-03 15:00:40 -0700265 newLIR2(cUnit, kX86Mov32RT, rlResult.lowReg, exOffset);
266 newLIR2(cUnit, kX86Mov32TI, exOffset, 0);
Ian Rogersc6f3bb82012-03-21 20:40:33 -0700267#else
Bill Buzbeea114add2012-05-03 15:00:40 -0700268 int resetReg = oatAllocTemp(cUnit);
269 loadWordDisp(cUnit, rSELF, exOffset, rlResult.lowReg);
270 loadConstant(cUnit, resetReg, 0);
271 storeWordDisp(cUnit, rSELF, exOffset, resetReg);
Bill Buzbeea114add2012-05-03 15:00:40 -0700272 oatFreeTemp(cUnit, resetReg);
buzbeea7678db2012-03-05 15:35:46 -0800273#endif
jeffhao41005dd2012-05-09 17:58:52 -0700274 storeValue(cUnit, rlDest, rlResult);
Bill Buzbeea114add2012-05-03 15:00:40 -0700275 break;
buzbeee3acd072012-02-25 17:03:10 -0800276 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700277 case Instruction::RETURN_VOID:
TDYa1274f2935e2012-06-22 06:25:03 -0700278 if (!(cUnit->attrs & METHOD_IS_LEAF)) {
buzbee408ad162012-06-06 16:45:18 -0700279 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700280 }
281 break;
282
283 case Instruction::RETURN:
284 case Instruction::RETURN_OBJECT:
TDYa1274f2935e2012-06-22 06:25:03 -0700285 if (!(cUnit->attrs & METHOD_IS_LEAF)) {
buzbee408ad162012-06-06 16:45:18 -0700286 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700287 }
288 storeValue(cUnit, oatGetReturn(cUnit, cUnit->shorty[0] == 'F'), rlSrc[0]);
289 break;
290
291 case Instruction::RETURN_WIDE:
TDYa1274f2935e2012-06-22 06:25:03 -0700292 if (!(cUnit->attrs & METHOD_IS_LEAF)) {
buzbee408ad162012-06-06 16:45:18 -0700293 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700294 }
295 storeValueWide(cUnit, oatGetReturnWide(cUnit,
296 cUnit->shorty[0] == 'D'), rlSrc[0]);
297 break;
298
299 case Instruction::MOVE_RESULT_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700300 if (optFlags & MIR_INLINED)
Bill Buzbeea114add2012-05-03 15:00:40 -0700301 break; // Nop - combined w/ previous invoke
302 storeValueWide(cUnit, rlDest, oatGetReturnWide(cUnit, rlDest.fp));
303 break;
304
305 case Instruction::MOVE_RESULT:
306 case Instruction::MOVE_RESULT_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700307 if (optFlags & MIR_INLINED)
Bill Buzbeea114add2012-05-03 15:00:40 -0700308 break; // Nop - combined w/ previous invoke
309 storeValue(cUnit, rlDest, oatGetReturn(cUnit, rlDest.fp));
310 break;
311
312 case Instruction::MOVE:
313 case Instruction::MOVE_OBJECT:
314 case Instruction::MOVE_16:
315 case Instruction::MOVE_OBJECT_16:
316 case Instruction::MOVE_FROM16:
317 case Instruction::MOVE_OBJECT_FROM16:
318 storeValue(cUnit, rlDest, rlSrc[0]);
319 break;
320
321 case Instruction::MOVE_WIDE:
322 case Instruction::MOVE_WIDE_16:
323 case Instruction::MOVE_WIDE_FROM16:
324 storeValueWide(cUnit, rlDest, rlSrc[0]);
325 break;
326
327 case Instruction::CONST:
328 case Instruction::CONST_4:
329 case Instruction::CONST_16:
330 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
buzbee408ad162012-06-06 16:45:18 -0700331 loadConstantNoClobber(cUnit, rlResult.lowReg, vB);
Bill Buzbeea114add2012-05-03 15:00:40 -0700332 storeValue(cUnit, rlDest, rlResult);
333 break;
334
335 case Instruction::CONST_HIGH16:
336 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
buzbee408ad162012-06-06 16:45:18 -0700337 loadConstantNoClobber(cUnit, rlResult.lowReg, vB << 16);
Bill Buzbeea114add2012-05-03 15:00:40 -0700338 storeValue(cUnit, rlDest, rlResult);
339 break;
340
341 case Instruction::CONST_WIDE_16:
342 case Instruction::CONST_WIDE_32:
343 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
buzbee408ad162012-06-06 16:45:18 -0700344 loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, vB,
345 (vB & 0x80000000) ? -1 : 0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700346 storeValueWide(cUnit, rlDest, rlResult);
347 break;
348
349 case Instruction::CONST_WIDE:
350 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
351 loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg,
352 mir->dalvikInsn.vB_wide & 0xffffffff,
353 (mir->dalvikInsn.vB_wide >> 32) & 0xffffffff);
354 storeValueWide(cUnit, rlDest, rlResult);
355 break;
356
357 case Instruction::CONST_WIDE_HIGH16:
358 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
359 loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg,
buzbee408ad162012-06-06 16:45:18 -0700360 0, vB << 16);
Bill Buzbeea114add2012-05-03 15:00:40 -0700361 storeValueWide(cUnit, rlDest, rlResult);
362 break;
363
364 case Instruction::MONITOR_ENTER:
buzbee408ad162012-06-06 16:45:18 -0700365 genMonitorEnter(cUnit, optFlags, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700366 break;
367
368 case Instruction::MONITOR_EXIT:
buzbee408ad162012-06-06 16:45:18 -0700369 genMonitorExit(cUnit, optFlags, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700370 break;
371
372 case Instruction::CHECK_CAST:
buzbee408ad162012-06-06 16:45:18 -0700373 genCheckCast(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700374 break;
375
376 case Instruction::INSTANCE_OF:
buzbee408ad162012-06-06 16:45:18 -0700377 genInstanceof(cUnit, vC, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700378 break;
379
380 case Instruction::NEW_INSTANCE:
buzbee408ad162012-06-06 16:45:18 -0700381 genNewInstance(cUnit, vB, rlDest);
Bill Buzbeea114add2012-05-03 15:00:40 -0700382 break;
383
384 case Instruction::THROW:
buzbee408ad162012-06-06 16:45:18 -0700385 genThrow(cUnit, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700386 break;
387
Bill Buzbeea114add2012-05-03 15:00:40 -0700388 case Instruction::ARRAY_LENGTH:
389 int lenOffset;
390 lenOffset = Array::LengthOffset().Int32Value();
391 rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg);
buzbee408ad162012-06-06 16:45:18 -0700392 genNullCheck(cUnit, rlSrc[0].sRegLow, rlSrc[0].lowReg, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700393 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
394 loadWordDisp(cUnit, rlSrc[0].lowReg, lenOffset, rlResult.lowReg);
395 storeValue(cUnit, rlDest, rlResult);
396 break;
397
398 case Instruction::CONST_STRING:
399 case Instruction::CONST_STRING_JUMBO:
buzbee6969d502012-06-15 16:40:31 -0700400 genConstString(cUnit, vB, rlDest);
Bill Buzbeea114add2012-05-03 15:00:40 -0700401 break;
402
403 case Instruction::CONST_CLASS:
buzbee6969d502012-06-15 16:40:31 -0700404 genConstClass(cUnit, vB, rlDest);
Bill Buzbeea114add2012-05-03 15:00:40 -0700405 break;
406
407 case Instruction::FILL_ARRAY_DATA:
buzbee408ad162012-06-06 16:45:18 -0700408 genFillArrayData(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700409 break;
410
411 case Instruction::FILLED_NEW_ARRAY:
buzbee6969d502012-06-15 16:40:31 -0700412 genFilledNewArray(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic,
buzbee3b3dbdd2012-06-13 13:39:34 -0700413 false /* not range */));
Bill Buzbeea114add2012-05-03 15:00:40 -0700414 break;
415
416 case Instruction::FILLED_NEW_ARRAY_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700417 genFilledNewArray(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic,
buzbee3b3dbdd2012-06-13 13:39:34 -0700418 true /* range */));
Bill Buzbeea114add2012-05-03 15:00:40 -0700419 break;
420
421 case Instruction::NEW_ARRAY:
buzbee408ad162012-06-06 16:45:18 -0700422 genNewArray(cUnit, vC, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700423 break;
424
425 case Instruction::GOTO:
426 case Instruction::GOTO_16:
427 case Instruction::GOTO_32:
428 if (bb->taken->startOffset <= mir->offset) {
buzbee408ad162012-06-06 16:45:18 -0700429 genSuspendTestAndBranch(cUnit, optFlags, &labelList[bb->taken->id]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700430 } else {
431 opUnconditionalBranch(cUnit, &labelList[bb->taken->id]);
432 }
433 break;
434
435 case Instruction::PACKED_SWITCH:
buzbee408ad162012-06-06 16:45:18 -0700436 genPackedSwitch(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700437 break;
438
439 case Instruction::SPARSE_SWITCH:
buzbeea1da8a52012-07-09 14:00:21 -0700440 genSparseSwitch(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700441 break;
442
443 case Instruction::CMPL_FLOAT:
444 case Instruction::CMPG_FLOAT:
445 case Instruction::CMPL_DOUBLE:
446 case Instruction::CMPG_DOUBLE:
buzbee408ad162012-06-06 16:45:18 -0700447 res = genCmpFP(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700448 break;
449
450 case Instruction::CMP_LONG:
buzbee408ad162012-06-06 16:45:18 -0700451 genCmpLong(cUnit, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700452 break;
453
454 case Instruction::IF_EQ:
455 case Instruction::IF_NE:
456 case Instruction::IF_LT:
457 case Instruction::IF_GE:
458 case Instruction::IF_GT:
459 case Instruction::IF_LE: {
buzbee3b3dbdd2012-06-13 13:39:34 -0700460 LIR* taken = &labelList[bb->taken->id];
461 LIR* fallThrough = &labelList[bb->fallThrough->id];
Bill Buzbeea114add2012-05-03 15:00:40 -0700462 bool backwardBranch;
463 backwardBranch = (bb->taken->startOffset <= mir->offset);
464 if (backwardBranch) {
buzbee408ad162012-06-06 16:45:18 -0700465 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700466 }
buzbee3b3dbdd2012-06-13 13:39:34 -0700467 genCompareAndBranch(cUnit, opcode, rlSrc[0], rlSrc[1], taken,
468 fallThrough);
Bill Buzbeea114add2012-05-03 15:00:40 -0700469 break;
470 }
471
472 case Instruction::IF_EQZ:
473 case Instruction::IF_NEZ:
474 case Instruction::IF_LTZ:
475 case Instruction::IF_GEZ:
476 case Instruction::IF_GTZ:
477 case Instruction::IF_LEZ: {
buzbee3b3dbdd2012-06-13 13:39:34 -0700478 LIR* taken = &labelList[bb->taken->id];
479 LIR* fallThrough = &labelList[bb->fallThrough->id];
Bill Buzbeea114add2012-05-03 15:00:40 -0700480 bool backwardBranch;
481 backwardBranch = (bb->taken->startOffset <= mir->offset);
482 if (backwardBranch) {
buzbee408ad162012-06-06 16:45:18 -0700483 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700484 }
buzbee3b3dbdd2012-06-13 13:39:34 -0700485 genCompareZeroAndBranch(cUnit, opcode, rlSrc[0], taken, fallThrough);
Bill Buzbeea114add2012-05-03 15:00:40 -0700486 break;
487 }
488
489 case Instruction::AGET_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700490 genArrayGet(cUnit, optFlags, kLong, rlSrc[0], rlSrc[1], rlDest, 3);
Bill Buzbeea114add2012-05-03 15:00:40 -0700491 break;
492 case Instruction::AGET:
493 case Instruction::AGET_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700494 genArrayGet(cUnit, optFlags, kWord, rlSrc[0], rlSrc[1], rlDest, 2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700495 break;
496 case Instruction::AGET_BOOLEAN:
buzbee408ad162012-06-06 16:45:18 -0700497 genArrayGet(cUnit, optFlags, kUnsignedByte, rlSrc[0], rlSrc[1], rlDest, 0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700498 break;
499 case Instruction::AGET_BYTE:
buzbee408ad162012-06-06 16:45:18 -0700500 genArrayGet(cUnit, optFlags, kSignedByte, rlSrc[0], rlSrc[1], rlDest, 0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700501 break;
502 case Instruction::AGET_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700503 genArrayGet(cUnit, optFlags, kUnsignedHalf, rlSrc[0], rlSrc[1], rlDest, 1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700504 break;
505 case Instruction::AGET_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700506 genArrayGet(cUnit, optFlags, kSignedHalf, rlSrc[0], rlSrc[1], rlDest, 1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700507 break;
508 case Instruction::APUT_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700509 genArrayPut(cUnit, optFlags, kLong, rlSrc[1], rlSrc[2], rlSrc[0], 3);
Bill Buzbeea114add2012-05-03 15:00:40 -0700510 break;
511 case Instruction::APUT:
buzbee408ad162012-06-06 16:45:18 -0700512 genArrayPut(cUnit, optFlags, kWord, rlSrc[1], rlSrc[2], rlSrc[0], 2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700513 break;
514 case Instruction::APUT_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700515 genArrayObjPut(cUnit, optFlags, rlSrc[1], rlSrc[2], rlSrc[0], 2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700516 break;
517 case Instruction::APUT_SHORT:
518 case Instruction::APUT_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700519 genArrayPut(cUnit, optFlags, kUnsignedHalf, rlSrc[1], rlSrc[2], rlSrc[0], 1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700520 break;
521 case Instruction::APUT_BYTE:
522 case Instruction::APUT_BOOLEAN:
buzbee408ad162012-06-06 16:45:18 -0700523 genArrayPut(cUnit, optFlags, kUnsignedByte, rlSrc[1], rlSrc[2],
Bill Buzbeea114add2012-05-03 15:00:40 -0700524 rlSrc[0], 0);
525 break;
526
527 case Instruction::IGET_OBJECT:
528 //case Instruction::IGET_OBJECT_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700529 genIGet(cUnit, vC, optFlags, kWord, rlDest, rlSrc[0], false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700530 break;
531
532 case Instruction::IGET_WIDE:
533 //case Instruction::IGET_WIDE_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700534 genIGet(cUnit, vC, optFlags, kLong, rlDest, rlSrc[0], true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700535 break;
536
537 case Instruction::IGET:
538 //case Instruction::IGET_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700539 genIGet(cUnit, vC, optFlags, kWord, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700540 break;
541
542 case Instruction::IGET_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700543 genIGet(cUnit, vC, optFlags, kUnsignedHalf, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700544 break;
545
546 case Instruction::IGET_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700547 genIGet(cUnit, vC, optFlags, kSignedHalf, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700548 break;
549
550 case Instruction::IGET_BOOLEAN:
551 case Instruction::IGET_BYTE:
buzbee408ad162012-06-06 16:45:18 -0700552 genIGet(cUnit, vC, optFlags, kUnsignedByte, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700553 break;
554
555 case Instruction::IPUT_WIDE:
556 //case Instruction::IPUT_WIDE_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700557 genIPut(cUnit, vC, optFlags, kLong, rlSrc[0], rlSrc[1], true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700558 break;
559
560 case Instruction::IPUT_OBJECT:
561 //case Instruction::IPUT_OBJECT_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700562 genIPut(cUnit, vC, optFlags, kWord, rlSrc[0], rlSrc[1], false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700563 break;
564
565 case Instruction::IPUT:
566 //case Instruction::IPUT_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700567 genIPut(cUnit, vC, optFlags, kWord, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700568 break;
569
570 case Instruction::IPUT_BOOLEAN:
571 case Instruction::IPUT_BYTE:
buzbee408ad162012-06-06 16:45:18 -0700572 genIPut(cUnit, vC, optFlags, kUnsignedByte, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700573 break;
574
575 case Instruction::IPUT_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700576 genIPut(cUnit, vC, optFlags, kUnsignedHalf, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700577 break;
578
579 case Instruction::IPUT_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700580 genIPut(cUnit, vC, optFlags, kSignedHalf, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700581 break;
582
583 case Instruction::SGET_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700584 genSget(cUnit, vB, rlDest, false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700585 break;
586 case Instruction::SGET:
587 case Instruction::SGET_BOOLEAN:
588 case Instruction::SGET_BYTE:
589 case Instruction::SGET_CHAR:
590 case Instruction::SGET_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700591 genSget(cUnit, vB, rlDest, false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700592 break;
593
594 case Instruction::SGET_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700595 genSget(cUnit, vB, rlDest, true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700596 break;
597
598 case Instruction::SPUT_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700599 genSput(cUnit, vB, rlSrc[0], false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700600 break;
601
602 case Instruction::SPUT:
603 case Instruction::SPUT_BOOLEAN:
604 case Instruction::SPUT_BYTE:
605 case Instruction::SPUT_CHAR:
606 case Instruction::SPUT_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700607 genSput(cUnit, vB, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700608 break;
609
610 case Instruction::SPUT_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700611 genSput(cUnit, vB, rlSrc[0], true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700612 break;
613
614 case Instruction::INVOKE_STATIC_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700615 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700616 break;
617 case Instruction::INVOKE_STATIC:
buzbee6969d502012-06-15 16:40:31 -0700618 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700619 break;
620
621 case Instruction::INVOKE_DIRECT:
buzbee6969d502012-06-15 16:40:31 -0700622 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kDirect, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700623 break;
624 case Instruction::INVOKE_DIRECT_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700625 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kDirect, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700626 break;
627
628 case Instruction::INVOKE_VIRTUAL:
buzbee6969d502012-06-15 16:40:31 -0700629 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kVirtual, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700630 break;
631 case Instruction::INVOKE_VIRTUAL_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700632 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kVirtual, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700633 break;
634
635 case Instruction::INVOKE_SUPER:
buzbee6969d502012-06-15 16:40:31 -0700636 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kSuper, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700637 break;
638 case Instruction::INVOKE_SUPER_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700639 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kSuper, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700640 break;
641
642 case Instruction::INVOKE_INTERFACE:
buzbee6969d502012-06-15 16:40:31 -0700643 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kInterface, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700644 break;
645 case Instruction::INVOKE_INTERFACE_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700646 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kInterface, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700647 break;
648
649 case Instruction::NEG_INT:
650 case Instruction::NOT_INT:
buzbee408ad162012-06-06 16:45:18 -0700651 res = genArithOpInt(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700652 break;
653
654 case Instruction::NEG_LONG:
655 case Instruction::NOT_LONG:
buzbee408ad162012-06-06 16:45:18 -0700656 res = genArithOpLong(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700657 break;
658
659 case Instruction::NEG_FLOAT:
buzbee408ad162012-06-06 16:45:18 -0700660 res = genArithOpFloat(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700661 break;
662
663 case Instruction::NEG_DOUBLE:
buzbee408ad162012-06-06 16:45:18 -0700664 res = genArithOpDouble(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700665 break;
666
667 case Instruction::INT_TO_LONG:
buzbee408ad162012-06-06 16:45:18 -0700668 genIntToLong(cUnit, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700669 break;
670
671 case Instruction::LONG_TO_INT:
672 rlSrc[0] = oatUpdateLocWide(cUnit, rlSrc[0]);
673 rlSrc[0] = oatWideToNarrow(cUnit, rlSrc[0]);
674 storeValue(cUnit, rlDest, rlSrc[0]);
675 break;
676
677 case Instruction::INT_TO_BYTE:
678 case Instruction::INT_TO_SHORT:
679 case Instruction::INT_TO_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700680 genIntNarrowing(cUnit, opcode, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700681 break;
682
683 case Instruction::INT_TO_FLOAT:
684 case Instruction::INT_TO_DOUBLE:
685 case Instruction::LONG_TO_FLOAT:
686 case Instruction::LONG_TO_DOUBLE:
687 case Instruction::FLOAT_TO_INT:
688 case Instruction::FLOAT_TO_LONG:
689 case Instruction::FLOAT_TO_DOUBLE:
690 case Instruction::DOUBLE_TO_INT:
691 case Instruction::DOUBLE_TO_LONG:
692 case Instruction::DOUBLE_TO_FLOAT:
buzbee408ad162012-06-06 16:45:18 -0700693 genConversion(cUnit, opcode, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700694 break;
695
696 case Instruction::ADD_INT:
697 case Instruction::SUB_INT:
698 case Instruction::MUL_INT:
699 case Instruction::DIV_INT:
700 case Instruction::REM_INT:
701 case Instruction::AND_INT:
702 case Instruction::OR_INT:
703 case Instruction::XOR_INT:
704 case Instruction::SHL_INT:
705 case Instruction::SHR_INT:
706 case Instruction::USHR_INT:
707 case Instruction::ADD_INT_2ADDR:
708 case Instruction::SUB_INT_2ADDR:
709 case Instruction::MUL_INT_2ADDR:
710 case Instruction::DIV_INT_2ADDR:
711 case Instruction::REM_INT_2ADDR:
712 case Instruction::AND_INT_2ADDR:
713 case Instruction::OR_INT_2ADDR:
714 case Instruction::XOR_INT_2ADDR:
715 case Instruction::SHL_INT_2ADDR:
716 case Instruction::SHR_INT_2ADDR:
717 case Instruction::USHR_INT_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700718 genArithOpInt(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700719 break;
720
721 case Instruction::ADD_LONG:
722 case Instruction::SUB_LONG:
723 case Instruction::MUL_LONG:
724 case Instruction::DIV_LONG:
725 case Instruction::REM_LONG:
726 case Instruction::AND_LONG:
727 case Instruction::OR_LONG:
728 case Instruction::XOR_LONG:
729 case Instruction::ADD_LONG_2ADDR:
730 case Instruction::SUB_LONG_2ADDR:
731 case Instruction::MUL_LONG_2ADDR:
732 case Instruction::DIV_LONG_2ADDR:
733 case Instruction::REM_LONG_2ADDR:
734 case Instruction::AND_LONG_2ADDR:
735 case Instruction::OR_LONG_2ADDR:
736 case Instruction::XOR_LONG_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700737 genArithOpLong(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700738 break;
739
740 case Instruction::SHL_LONG:
741 case Instruction::SHR_LONG:
742 case Instruction::USHR_LONG:
743 case Instruction::SHL_LONG_2ADDR:
744 case Instruction::SHR_LONG_2ADDR:
745 case Instruction::USHR_LONG_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700746 genShiftOpLong(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700747 break;
748
749 case Instruction::ADD_FLOAT:
750 case Instruction::SUB_FLOAT:
751 case Instruction::MUL_FLOAT:
752 case Instruction::DIV_FLOAT:
753 case Instruction::REM_FLOAT:
754 case Instruction::ADD_FLOAT_2ADDR:
755 case Instruction::SUB_FLOAT_2ADDR:
756 case Instruction::MUL_FLOAT_2ADDR:
757 case Instruction::DIV_FLOAT_2ADDR:
758 case Instruction::REM_FLOAT_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700759 genArithOpFloat(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700760 break;
761
762 case Instruction::ADD_DOUBLE:
763 case Instruction::SUB_DOUBLE:
764 case Instruction::MUL_DOUBLE:
765 case Instruction::DIV_DOUBLE:
766 case Instruction::REM_DOUBLE:
767 case Instruction::ADD_DOUBLE_2ADDR:
768 case Instruction::SUB_DOUBLE_2ADDR:
769 case Instruction::MUL_DOUBLE_2ADDR:
770 case Instruction::DIV_DOUBLE_2ADDR:
771 case Instruction::REM_DOUBLE_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700772 genArithOpDouble(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700773 break;
774
775 case Instruction::RSUB_INT:
776 case Instruction::ADD_INT_LIT16:
777 case Instruction::MUL_INT_LIT16:
778 case Instruction::DIV_INT_LIT16:
779 case Instruction::REM_INT_LIT16:
780 case Instruction::AND_INT_LIT16:
781 case Instruction::OR_INT_LIT16:
782 case Instruction::XOR_INT_LIT16:
783 case Instruction::ADD_INT_LIT8:
784 case Instruction::RSUB_INT_LIT8:
785 case Instruction::MUL_INT_LIT8:
786 case Instruction::DIV_INT_LIT8:
787 case Instruction::REM_INT_LIT8:
788 case Instruction::AND_INT_LIT8:
789 case Instruction::OR_INT_LIT8:
790 case Instruction::XOR_INT_LIT8:
791 case Instruction::SHL_INT_LIT8:
792 case Instruction::SHR_INT_LIT8:
793 case Instruction::USHR_INT_LIT8:
buzbee408ad162012-06-06 16:45:18 -0700794 genArithOpIntLit(cUnit, opcode, rlDest, rlSrc[0], vC);
Bill Buzbeea114add2012-05-03 15:00:40 -0700795 break;
796
797 default:
798 res = true;
799 }
800 return res;
buzbeee3acd072012-02-25 17:03:10 -0800801}
802
buzbee31a4a6f2012-02-28 15:36:15 -0800803const char* extendedMIROpNames[kMirOpLast - kMirOpFirst] = {
Bill Buzbeea114add2012-05-03 15:00:40 -0700804 "kMirOpPhi",
805 "kMirOpCopy",
806 "kMirFusedCmplFloat",
807 "kMirFusedCmpgFloat",
808 "kMirFusedCmplDouble",
809 "kMirFusedCmpgDouble",
810 "kMirFusedCmpLong",
811 "kMirNop",
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700812 "kMirOpNullCheck",
813 "kMirOpRangeCheck",
814 "kMirOpDivZeroCheck",
815 "kMirOpCheck",
buzbeee3acd072012-02-25 17:03:10 -0800816};
817
818/* Extended MIR instructions like PHI */
buzbee84fd6932012-03-29 16:44:16 -0700819void handleExtendedMethodMIR(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir)
buzbeee3acd072012-02-25 17:03:10 -0800820{
Bill Buzbeea114add2012-05-03 15:00:40 -0700821 int opOffset = mir->dalvikInsn.opcode - kMirOpFirst;
822 char* msg = NULL;
823 if (cUnit->printMe) {
824 msg = (char*)oatNew(cUnit, strlen(extendedMIROpNames[opOffset]) + 1,
825 false, kAllocDebugInfo);
826 strcpy(msg, extendedMIROpNames[opOffset]);
827 }
828 LIR* op = newLIR1(cUnit, kPseudoExtended, (int) msg);
buzbeee3acd072012-02-25 17:03:10 -0800829
Bill Buzbeea114add2012-05-03 15:00:40 -0700830 switch ((ExtendedMIROpcode)mir->dalvikInsn.opcode) {
831 case kMirOpPhi: {
832 char* ssaString = NULL;
833 if (cUnit->printMe) {
834 ssaString = oatGetSSAString(cUnit, mir->ssaRep);
835 }
836 op->flags.isNop = true;
837 newLIR1(cUnit, kPseudoSSARep, (int) ssaString);
838 break;
buzbeee3acd072012-02-25 17:03:10 -0800839 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700840 case kMirOpCopy: {
841 RegLocation rlSrc = oatGetSrc(cUnit, mir, 0);
buzbee15bf9802012-06-12 17:49:27 -0700842 RegLocation rlDest = oatGetDest(cUnit, mir);
Bill Buzbeea114add2012-05-03 15:00:40 -0700843 storeValue(cUnit, rlDest, rlSrc);
844 break;
845 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700846 case kMirOpFusedCmplFloat:
847 genFusedFPCmpBranch(cUnit, bb, mir, false /*gt bias*/, false /*double*/);
848 break;
849 case kMirOpFusedCmpgFloat:
850 genFusedFPCmpBranch(cUnit, bb, mir, true /*gt bias*/, false /*double*/);
851 break;
852 case kMirOpFusedCmplDouble:
853 genFusedFPCmpBranch(cUnit, bb, mir, false /*gt bias*/, true /*double*/);
854 break;
855 case kMirOpFusedCmpgDouble:
856 genFusedFPCmpBranch(cUnit, bb, mir, true /*gt bias*/, true /*double*/);
857 break;
858 case kMirOpFusedCmpLong:
859 genFusedLongCmpBranch(cUnit, bb, mir);
860 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700861 default:
862 break;
863 }
buzbeee3acd072012-02-25 17:03:10 -0800864}
865
866/* Handle the content in each basic block */
buzbee31a4a6f2012-02-28 15:36:15 -0800867bool methodBlockCodeGen(CompilationUnit* cUnit, BasicBlock* bb)
buzbeee3acd072012-02-25 17:03:10 -0800868{
buzbee488a78c2012-09-10 15:55:34 -0700869 if (bb->blockType == kDead) return false;
Bill Buzbeea114add2012-05-03 15:00:40 -0700870 MIR* mir;
buzbeea1da8a52012-07-09 14:00:21 -0700871 LIR* labelList = cUnit->blockLabelList;
Bill Buzbeea114add2012-05-03 15:00:40 -0700872 int blockId = bb->id;
buzbeee3acd072012-02-25 17:03:10 -0800873
Bill Buzbeea114add2012-05-03 15:00:40 -0700874 cUnit->curBlock = bb;
875 labelList[blockId].operands[0] = bb->startOffset;
buzbeee3acd072012-02-25 17:03:10 -0800876
Bill Buzbeea114add2012-05-03 15:00:40 -0700877 /* Insert the block label */
878 labelList[blockId].opcode = kPseudoNormalBlockLabel;
879 oatAppendLIR(cUnit, (LIR*) &labelList[blockId]);
buzbeee3acd072012-02-25 17:03:10 -0800880
Bill Buzbeea114add2012-05-03 15:00:40 -0700881 /* Free temp registers and reset redundant store tracking */
882 oatResetRegPool(cUnit);
883 oatResetDefTracking(cUnit);
884
buzbeed1643e42012-09-05 14:06:51 -0700885 oatClobberAllRegs(cUnit);
Bill Buzbeea114add2012-05-03 15:00:40 -0700886
887 LIR* headLIR = NULL;
888
889 if (bb->blockType == kEntryBlock) {
buzbeead8f15e2012-06-18 14:49:45 -0700890 int startVReg = cUnit->numDalvikRegisters - cUnit->numIns;
891 genEntrySequence(cUnit, &cUnit->regLocation[startVReg],
892 cUnit->regLocation[cUnit->methodSReg]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700893 } else if (bb->blockType == kExitBlock) {
buzbee2cfc6392012-05-07 14:51:40 -0700894 genExitSequence(cUnit);
Bill Buzbeea114add2012-05-03 15:00:40 -0700895 }
896
897 for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
buzbeee3acd072012-02-25 17:03:10 -0800898 oatResetRegPool(cUnit);
Bill Buzbeea114add2012-05-03 15:00:40 -0700899 if (cUnit->disableOpt & (1 << kTrackLiveTemps)) {
900 oatClobberAllRegs(cUnit);
buzbeee1965672012-03-11 18:39:19 -0700901 }
902
Bill Buzbeea114add2012-05-03 15:00:40 -0700903 if (cUnit->disableOpt & (1 << kSuppressLoads)) {
904 oatResetDefTracking(cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800905 }
906
buzbee3d661942012-03-14 17:37:27 -0700907#ifndef NDEBUG
Bill Buzbeea114add2012-05-03 15:00:40 -0700908 /* Reset temp tracking sanity check */
909 cUnit->liveSReg = INVALID_SREG;
buzbee3d661942012-03-14 17:37:27 -0700910#endif
911
Bill Buzbeea114add2012-05-03 15:00:40 -0700912 cUnit->currentDalvikOffset = mir->offset;
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700913 int opcode = mir->dalvikInsn.opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700914 LIR* boundaryLIR;
buzbeee3acd072012-02-25 17:03:10 -0800915
Bill Buzbeea114add2012-05-03 15:00:40 -0700916 /* Mark the beginning of a Dalvik instruction for line tracking */
917 char* instStr = cUnit->printMe ?
918 oatGetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL;
buzbeed1643e42012-09-05 14:06:51 -0700919 boundaryLIR = markBoundary(cUnit, mir->offset, instStr);
Bill Buzbeea114add2012-05-03 15:00:40 -0700920 /* Remember the first LIR for this block */
921 if (headLIR == NULL) {
922 headLIR = boundaryLIR;
923 /* Set the first boundaryLIR as a scheduling barrier */
924 headLIR->defMask = ENCODE_ALL;
buzbeee3acd072012-02-25 17:03:10 -0800925 }
926
Bill Buzbeea114add2012-05-03 15:00:40 -0700927 /* If we're compiling for the debugger, generate an update callout */
928 if (cUnit->genDebugger) {
929 genDebuggerUpdate(cUnit, mir->offset);
buzbeee3acd072012-02-25 17:03:10 -0800930 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700931
932 /* Don't generate the SSA annotation unless verbose mode is on */
933 if (cUnit->printMe && mir->ssaRep) {
934 char* ssaString = oatGetSSAString(cUnit, mir->ssaRep);
935 newLIR1(cUnit, kPseudoSSARep, (int) ssaString);
936 }
937
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700938 if (opcode == kMirOpCheck) {
939 // Combine check and work halves of throwing instruction.
940 MIR* workHalf = mir->meta.throwInsn;
941 mir->dalvikInsn.opcode = workHalf->dalvikInsn.opcode;
942 opcode = workHalf->dalvikInsn.opcode;
943 SSARepresentation* ssaRep = workHalf->ssaRep;
944 workHalf->ssaRep = mir->ssaRep;
945 mir->ssaRep = ssaRep;
946 workHalf->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop);
947 }
948
949 if (opcode >= kMirOpFirst) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700950 handleExtendedMethodMIR(cUnit, bb, mir);
951 continue;
952 }
953
954 bool notHandled = compileDalvikInstruction(cUnit, mir, bb, labelList);
955 if (notHandled) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700956 LOG(FATAL) << StringPrintf("%#06x: Opcode %#x (%s)",
957 mir->offset, opcode,
958 Instruction::Name(mir->dalvikInsn.opcode));
Bill Buzbeea114add2012-05-03 15:00:40 -0700959 }
960 }
961
962 if (headLIR) {
963 /*
964 * Eliminate redundant loads/stores and delay stores into later
965 * slots
966 */
967 oatApplyLocalOptimizations(cUnit, (LIR*) headLIR, cUnit->lastLIRInsn);
968
969 /*
970 * Generate an unconditional branch to the fallthrough block.
971 */
972 if (bb->fallThrough) {
973 opUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]);
974 }
975 }
976 return false;
buzbeee3acd072012-02-25 17:03:10 -0800977}
978
buzbee16da88c2012-03-20 10:38:17 -0700979/* Set basic block labels */
980bool labelBlocks(CompilationUnit* cUnit, BasicBlock* bb)
981{
buzbeea1da8a52012-07-09 14:00:21 -0700982 LIR* labelList = cUnit->blockLabelList;
Bill Buzbeea114add2012-05-03 15:00:40 -0700983 int blockId = bb->id;
buzbee16da88c2012-03-20 10:38:17 -0700984
Bill Buzbeea114add2012-05-03 15:00:40 -0700985 cUnit->curBlock = bb;
986 labelList[blockId].operands[0] = bb->startOffset;
buzbee16da88c2012-03-20 10:38:17 -0700987
Bill Buzbeea114add2012-05-03 15:00:40 -0700988 /* Insert the block label */
989 labelList[blockId].opcode = kPseudoNormalBlockLabel;
990 return false;
buzbee16da88c2012-03-20 10:38:17 -0700991}
992
993void oatSpecialMIR2LIR(CompilationUnit* cUnit, SpecialCaseHandler specialCase)
994{
Bill Buzbeea114add2012-05-03 15:00:40 -0700995 /* Find the first DalvikByteCode block */
996 int numReachableBlocks = cUnit->numReachableBlocks;
997 const GrowableList *blockList = &cUnit->blockList;
998 BasicBlock*bb = NULL;
999 for (int idx = 0; idx < numReachableBlocks; idx++) {
1000 int dfsIndex = cUnit->dfsOrder.elemList[idx];
1001 bb = (BasicBlock*)oatGrowableListGetElement(blockList, dfsIndex);
1002 if (bb->blockType == kDalvikByteCode) {
1003 break;
buzbee16da88c2012-03-20 10:38:17 -07001004 }
Bill Buzbeea114add2012-05-03 15:00:40 -07001005 }
1006 if (bb == NULL) {
1007 return;
1008 }
1009 DCHECK_EQ(bb->startOffset, 0);
Elliott Hughes74847412012-06-20 18:10:21 -07001010 DCHECK(bb->firstMIRInsn != NULL);
buzbee16da88c2012-03-20 10:38:17 -07001011
Bill Buzbeea114add2012-05-03 15:00:40 -07001012 /* Get the first instruction */
1013 MIR* mir = bb->firstMIRInsn;
buzbee16da88c2012-03-20 10:38:17 -07001014
Bill Buzbeea114add2012-05-03 15:00:40 -07001015 /* Free temp registers and reset redundant store tracking */
1016 oatResetRegPool(cUnit);
1017 oatResetDefTracking(cUnit);
1018 oatClobberAllRegs(cUnit);
buzbee16da88c2012-03-20 10:38:17 -07001019
Bill Buzbeea114add2012-05-03 15:00:40 -07001020 genSpecialCase(cUnit, bb, mir, specialCase);
buzbee16da88c2012-03-20 10:38:17 -07001021}
1022
buzbeee3acd072012-02-25 17:03:10 -08001023void oatMethodMIR2LIR(CompilationUnit* cUnit)
1024{
Bill Buzbeea114add2012-05-03 15:00:40 -07001025 /* Used to hold the labels of each block */
1026 cUnit->blockLabelList =
buzbeea1da8a52012-07-09 14:00:21 -07001027 (LIR*) oatNew(cUnit, sizeof(LIR) * cUnit->numBlocks, true, kAllocLIR);
buzbeee3acd072012-02-25 17:03:10 -08001028
Bill Buzbeea114add2012-05-03 15:00:40 -07001029 oatDataFlowAnalysisDispatcher(cUnit, methodBlockCodeGen,
1030 kPreOrderDFSTraversal, false /* Iterative */);
Ian Rogersab2b55d2012-03-18 00:06:11 -07001031
Bill Buzbeea114add2012-05-03 15:00:40 -07001032 handleSuspendLaunchpads(cUnit);
buzbeee3acd072012-02-25 17:03:10 -08001033
Bill Buzbeea114add2012-05-03 15:00:40 -07001034 handleThrowLaunchpads(cUnit);
buzbeee3acd072012-02-25 17:03:10 -08001035
Bill Buzbeea114add2012-05-03 15:00:40 -07001036 handleIntrinsicLaunchpads(cUnit);
buzbeefc9e6fa2012-03-23 15:14:29 -07001037
Bill Buzbeea114add2012-05-03 15:00:40 -07001038 if (!(cUnit->disableOpt & (1 << kSafeOptimizations))) {
1039 removeRedundantBranches(cUnit);
1040 }
buzbeee3acd072012-02-25 17:03:10 -08001041}
1042
1043/* Needed by the ld/st optmizatons */
buzbee31a4a6f2012-02-28 15:36:15 -08001044LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc)
buzbeee3acd072012-02-25 17:03:10 -08001045{
Bill Buzbeea114add2012-05-03 15:00:40 -07001046 return opRegCopyNoInsert(cUnit, rDest, rSrc);
buzbeee3acd072012-02-25 17:03:10 -08001047}
1048
1049/* Needed by the register allocator */
1050void oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc)
1051{
Bill Buzbeea114add2012-05-03 15:00:40 -07001052 opRegCopy(cUnit, rDest, rSrc);
buzbeee3acd072012-02-25 17:03:10 -08001053}
1054
1055/* Needed by the register allocator */
1056void oatRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi,
Bill Buzbeea114add2012-05-03 15:00:40 -07001057 int srcLo, int srcHi)
buzbeee3acd072012-02-25 17:03:10 -08001058{
Bill Buzbeea114add2012-05-03 15:00:40 -07001059 opRegCopyWide(cUnit, destLo, destHi, srcLo, srcHi);
buzbeee3acd072012-02-25 17:03:10 -08001060}
1061
1062void oatFlushRegImpl(CompilationUnit* cUnit, int rBase,
Bill Buzbeea114add2012-05-03 15:00:40 -07001063 int displacement, int rSrc, OpSize size)
buzbeee3acd072012-02-25 17:03:10 -08001064{
Bill Buzbeea114add2012-05-03 15:00:40 -07001065 storeBaseDisp(cUnit, rBase, displacement, rSrc, size);
buzbeee3acd072012-02-25 17:03:10 -08001066}
1067
1068void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase,
Bill Buzbeea114add2012-05-03 15:00:40 -07001069 int displacement, int rSrcLo, int rSrcHi)
buzbeee3acd072012-02-25 17:03:10 -08001070{
Bill Buzbeea114add2012-05-03 15:00:40 -07001071 storeBaseDispWide(cUnit, rBase, displacement, rSrcLo, rSrcHi);
buzbeee3acd072012-02-25 17:03:10 -08001072}
1073
1074} // namespace art