blob: 8fd6045a8d9fbfc2ce2d3a6f6329c8f66a532c5a [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
buzbee2cfc6392012-05-07 14:51:40 -070021const RegLocation badLoc = {kLocDalvikFrame, 0, 0, 0, 0, 0, 0, 0, 0,
22 INVALID_REG, INVALID_REG, INVALID_SREG,
23 INVALID_SREG};
buzbeee3acd072012-02-25 17:03:10 -080024
25/* Mark register usage state and return long retloc */
Ian Rogersf7d9ad32012-03-13 18:45:39 -070026RegLocation oatGetReturnWide(CompilationUnit* cUnit, bool isDouble)
buzbeee3acd072012-02-25 17:03:10 -080027{
Bill Buzbeea114add2012-05-03 15:00:40 -070028 RegLocation gpr_res = LOC_C_RETURN_WIDE;
29 RegLocation fpr_res = LOC_C_RETURN_WIDE_DOUBLE;
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;
buzbeee3acd072012-02-25 17:03:10 -080037}
38
Ian Rogersf7d9ad32012-03-13 18:45:39 -070039RegLocation oatGetReturn(CompilationUnit* cUnit, bool isFloat)
buzbeee3acd072012-02-25 17:03:10 -080040{
Ian Rogersf7d9ad32012-03-13 18:45:39 -070041 RegLocation gpr_res = LOC_C_RETURN;
42 RegLocation fpr_res = LOC_C_RETURN_FLOAT;
43 RegLocation res = isFloat ? fpr_res : gpr_res;
Bill Buzbeea114add2012-05-03 15:00:40 -070044 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;
buzbeee3acd072012-02-25 17:03:10 -080051}
52
buzbee3b3dbdd2012-06-13 13:39:34 -070053void genInvoke(CompilationUnit* cUnit, CallInfo* info)
buzbeee3acd072012-02-25 17:03:10 -080054{
buzbee15bf9802012-06-12 17:49:27 -070055 if (genIntrinsic(cUnit, info)) {
Bill Buzbeea114add2012-05-03 15:00:40 -070056 return;
57 }
buzbee15bf9802012-06-12 17:49:27 -070058 InvokeType originalType = info->type; // avoiding mutation by ComputeInvokeInfo
Bill Buzbeea114add2012-05-03 15:00:40 -070059 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);
buzbeee3acd072012-02-25 17:03:10 -080066
Bill Buzbeea114add2012-05-03 15:00:40 -070067 OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070068 *cUnit->dex_file,
Bill Buzbeea114add2012-05-03 15:00:40 -070069 cUnit->code_item, cUnit->method_idx,
70 cUnit->access_flags);
Logan Chien4dd96f52012-02-29 01:26:58 +080071
buzbee3b3dbdd2012-06-13 13:39:34 -070072 uint32_t dexMethodIdx = info->index;
Bill Buzbeea114add2012-05-03 15:00:40 -070073 int vtableIdx;
74 uintptr_t directCode;
75 uintptr_t directMethod;
76 bool skipThis;
77 bool fastPath =
buzbee15bf9802012-06-12 17:49:27 -070078 cUnit->compiler->ComputeInvokeInfo(dexMethodIdx, &mUnit, info->type,
Bill Buzbeea114add2012-05-03 15:00:40 -070079 vtableIdx, directCode,
80 directMethod)
81 && !SLOW_INVOKE_PATH;
buzbee15bf9802012-06-12 17:49:27 -070082 if (info->type == kInterface) {
Ian Rogers137e88f2012-10-08 17:46:47 -070083 if (fastPath) {
84 pNullCk = &nullCk;
85 }
Bill Buzbeea114add2012-05-03 15:00:40 -070086 nextCallInsn = fastPath ? nextInterfaceCallInsn
Ian Rogers137e88f2012-10-08 17:46:47 -070087 : nextInterfaceCallInsnWithAccessCheck;
Bill Buzbeea114add2012-05-03 15:00:40 -070088 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 }
buzbeeb046e162012-10-30 15:48:42 -0700124 if (cUnit->enableDebug & (1 << kDebugDisplayMissingTargets)) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700125 genShowTarget(cUnit);
126 }
buzbee8320f382012-09-11 16:29:42 -0700127 LIR* callInst;
buzbeeb046e162012-10-30 15:48:42 -0700128 if (cUnit->instructionSet != kX86) {
129 callInst = opReg(cUnit, kOpBlx, rINVOKE_TGT);
Bill Buzbeea114add2012-05-03 15:00:40 -0700130 } else {
buzbeeb046e162012-10-30 15:48:42 -0700131 if (fastPath && info->type != kInterface) {
132 callInst = opMem(cUnit, kOpBlx, rARG0, AbstractMethod::GetCodeOffset().Int32Value());
133 } else {
134 int trampoline = 0;
135 switch (info->type) {
136 case kInterface:
137 trampoline = fastPath ? ENTRYPOINT_OFFSET(pInvokeInterfaceTrampoline)
138 : ENTRYPOINT_OFFSET(pInvokeInterfaceTrampolineWithAccessCheck);
139 break;
140 case kDirect:
141 trampoline = ENTRYPOINT_OFFSET(pInvokeDirectTrampolineWithAccessCheck);
142 break;
143 case kStatic:
144 trampoline = ENTRYPOINT_OFFSET(pInvokeStaticTrampolineWithAccessCheck);
145 break;
146 case kSuper:
147 trampoline = ENTRYPOINT_OFFSET(pInvokeSuperTrampolineWithAccessCheck);
148 break;
149 case kVirtual:
150 trampoline = ENTRYPOINT_OFFSET(pInvokeVirtualTrampolineWithAccessCheck);
151 break;
152 default:
153 LOG(FATAL) << "Unexpected invoke type";
154 }
155 callInst = opThreadMem(cUnit, kOpBlx, trampoline);
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700156 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700157 }
buzbee8320f382012-09-11 16:29:42 -0700158 markSafepointPC(cUnit, callInst);
Ian Rogers6cbb2bd2012-03-16 13:45:30 -0700159
Bill Buzbeea114add2012-05-03 15:00:40 -0700160 oatClobberCalleeSave(cUnit);
buzbee15bf9802012-06-12 17:49:27 -0700161 if (info->result.location != kLocInvalid) {
162 // We have a following MOVE_RESULT - do it now.
163 if (info->result.wide) {
buzbee52ed7762012-06-13 23:43:14 -0700164 RegLocation retLoc = oatGetReturnWide(cUnit, info->result.fp);
buzbee15bf9802012-06-12 17:49:27 -0700165 storeValueWide(cUnit, info->result, retLoc);
166 } else {
buzbee52ed7762012-06-13 23:43:14 -0700167 RegLocation retLoc = oatGetReturn(cUnit, info->result.fp);
buzbee15bf9802012-06-12 17:49:27 -0700168 storeValue(cUnit, info->result, retLoc);
169 }
170 }
171}
172
173/*
174 * Build an array of location records for the incoming arguments.
175 * Note: one location record per word of arguments, with dummy
176 * high-word loc for wide arguments. Also pull up any following
177 * MOVE_RESULT and incorporate it into the invoke.
178 */
buzbee6969d502012-06-15 16:40:31 -0700179CallInfo* oatNewCallInfo(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir,
180 InvokeType type, bool isRange)
buzbee15bf9802012-06-12 17:49:27 -0700181{
buzbee3b3dbdd2012-06-13 13:39:34 -0700182 CallInfo* info = (CallInfo*)oatNew(cUnit, sizeof(CallInfo), true,
buzbee15bf9802012-06-12 17:49:27 -0700183 kAllocMisc);
184 MIR* moveResultMIR = oatFindMoveResult(cUnit, bb, mir);
185 if (moveResultMIR == NULL) {
186 info->result.location = kLocInvalid;
187 } else {
188 info->result = oatGetRawDest(cUnit, moveResultMIR);
189 moveResultMIR->dalvikInsn.opcode = Instruction::NOP;
190 }
191 info->numArgWords = mir->ssaRep->numUses;
192 info->args = (info->numArgWords == 0) ? NULL : (RegLocation*)
193 oatNew(cUnit, sizeof(RegLocation) * info->numArgWords, false, kAllocMisc);
194 for (int i = 0; i < info->numArgWords; i++) {
195 info->args[i] = oatGetRawSrc(cUnit, mir, i);
196 }
197 info->optFlags = mir->optimizationFlags;
198 info->type = type;
199 info->isRange = isRange;
buzbee3b3dbdd2012-06-13 13:39:34 -0700200 info->index = mir->dalvikInsn.vB;
buzbee15bf9802012-06-12 17:49:27 -0700201 info->offset = mir->offset;
202 return info;
buzbeee3acd072012-02-25 17:03:10 -0800203}
204
205/*
206 * Target-independent code generation. Use only high-level
207 * load/store utilities here, or target-dependent genXX() handlers
208 * when necessary.
209 */
buzbee31a4a6f2012-02-28 15:36:15 -0800210bool compileDalvikInstruction(CompilationUnit* cUnit, MIR* mir,
211 BasicBlock* bb, LIR* labelList)
buzbeee3acd072012-02-25 17:03:10 -0800212{
Bill Buzbeea114add2012-05-03 15:00:40 -0700213 bool res = false; // Assume success
214 RegLocation rlSrc[3];
215 RegLocation rlDest = badLoc;
216 RegLocation rlResult = badLoc;
217 Instruction::Code opcode = mir->dalvikInsn.opcode;
buzbee408ad162012-06-06 16:45:18 -0700218 int optFlags = mir->optimizationFlags;
buzbee408ad162012-06-06 16:45:18 -0700219 uint32_t vB = mir->dalvikInsn.vB;
220 uint32_t vC = mir->dalvikInsn.vC;
buzbeee3acd072012-02-25 17:03:10 -0800221
Bill Buzbeea114add2012-05-03 15:00:40 -0700222 /* Prep Src and Dest locations */
223 int nextSreg = 0;
224 int nextLoc = 0;
225 int attrs = oatDataFlowAttributes[opcode];
226 rlSrc[0] = rlSrc[1] = rlSrc[2] = badLoc;
227 if (attrs & DF_UA) {
buzbeebff24652012-05-06 16:22:05 -0700228 if (attrs & DF_A_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700229 rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg);
buzbeebff24652012-05-06 16:22:05 -0700230 nextSreg+= 2;
231 } else {
232 rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg);
233 nextSreg++;
234 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700235 }
236 if (attrs & DF_UB) {
buzbeebff24652012-05-06 16:22:05 -0700237 if (attrs & DF_B_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700238 rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg);
buzbeebff24652012-05-06 16:22:05 -0700239 nextSreg+= 2;
240 } else {
241 rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg);
242 nextSreg++;
243 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700244 }
245 if (attrs & DF_UC) {
buzbeebff24652012-05-06 16:22:05 -0700246 if (attrs & DF_C_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700247 rlSrc[nextLoc++] = oatGetSrcWide(cUnit, mir, nextSreg);
buzbeebff24652012-05-06 16:22:05 -0700248 } else {
249 rlSrc[nextLoc++] = oatGetSrc(cUnit, mir, nextSreg);
250 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700251 }
252 if (attrs & DF_DA) {
buzbeebff24652012-05-06 16:22:05 -0700253 if (attrs & DF_A_WIDE) {
buzbee15bf9802012-06-12 17:49:27 -0700254 rlDest = oatGetDestWide(cUnit, mir);
buzbeebff24652012-05-06 16:22:05 -0700255 } else {
buzbee15bf9802012-06-12 17:49:27 -0700256 rlDest = oatGetDest(cUnit, mir);
buzbeebff24652012-05-06 16:22:05 -0700257 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700258 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700259 switch (opcode) {
260 case Instruction::NOP:
261 break;
buzbeee3acd072012-02-25 17:03:10 -0800262
Ian Rogers474b6da2012-09-25 00:20:38 -0700263 case Instruction::MOVE_EXCEPTION:
264 genMoveException(cUnit, rlDest);
Bill Buzbeea114add2012-05-03 15:00:40 -0700265 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700266 case Instruction::RETURN_VOID:
TDYa1274f2935e2012-06-22 06:25:03 -0700267 if (!(cUnit->attrs & METHOD_IS_LEAF)) {
buzbee408ad162012-06-06 16:45:18 -0700268 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700269 }
270 break;
271
272 case Instruction::RETURN:
273 case Instruction::RETURN_OBJECT:
TDYa1274f2935e2012-06-22 06:25:03 -0700274 if (!(cUnit->attrs & METHOD_IS_LEAF)) {
buzbee408ad162012-06-06 16:45:18 -0700275 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700276 }
277 storeValue(cUnit, oatGetReturn(cUnit, cUnit->shorty[0] == 'F'), rlSrc[0]);
278 break;
279
280 case Instruction::RETURN_WIDE:
TDYa1274f2935e2012-06-22 06:25:03 -0700281 if (!(cUnit->attrs & METHOD_IS_LEAF)) {
buzbee408ad162012-06-06 16:45:18 -0700282 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700283 }
284 storeValueWide(cUnit, oatGetReturnWide(cUnit,
285 cUnit->shorty[0] == 'D'), rlSrc[0]);
286 break;
287
288 case Instruction::MOVE_RESULT_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700289 if (optFlags & MIR_INLINED)
Bill Buzbeea114add2012-05-03 15:00:40 -0700290 break; // Nop - combined w/ previous invoke
291 storeValueWide(cUnit, rlDest, oatGetReturnWide(cUnit, rlDest.fp));
292 break;
293
294 case Instruction::MOVE_RESULT:
295 case Instruction::MOVE_RESULT_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700296 if (optFlags & MIR_INLINED)
Bill Buzbeea114add2012-05-03 15:00:40 -0700297 break; // Nop - combined w/ previous invoke
298 storeValue(cUnit, rlDest, oatGetReturn(cUnit, rlDest.fp));
299 break;
300
301 case Instruction::MOVE:
302 case Instruction::MOVE_OBJECT:
303 case Instruction::MOVE_16:
304 case Instruction::MOVE_OBJECT_16:
305 case Instruction::MOVE_FROM16:
306 case Instruction::MOVE_OBJECT_FROM16:
307 storeValue(cUnit, rlDest, rlSrc[0]);
308 break;
309
310 case Instruction::MOVE_WIDE:
311 case Instruction::MOVE_WIDE_16:
312 case Instruction::MOVE_WIDE_FROM16:
313 storeValueWide(cUnit, rlDest, rlSrc[0]);
314 break;
315
316 case Instruction::CONST:
317 case Instruction::CONST_4:
318 case Instruction::CONST_16:
319 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
buzbee408ad162012-06-06 16:45:18 -0700320 loadConstantNoClobber(cUnit, rlResult.lowReg, vB);
Bill Buzbeea114add2012-05-03 15:00:40 -0700321 storeValue(cUnit, rlDest, rlResult);
322 break;
323
324 case Instruction::CONST_HIGH16:
325 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
buzbee408ad162012-06-06 16:45:18 -0700326 loadConstantNoClobber(cUnit, rlResult.lowReg, vB << 16);
Bill Buzbeea114add2012-05-03 15:00:40 -0700327 storeValue(cUnit, rlDest, rlResult);
328 break;
329
330 case Instruction::CONST_WIDE_16:
331 case Instruction::CONST_WIDE_32:
332 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
buzbee408ad162012-06-06 16:45:18 -0700333 loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg, vB,
334 (vB & 0x80000000) ? -1 : 0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700335 storeValueWide(cUnit, rlDest, rlResult);
336 break;
337
338 case Instruction::CONST_WIDE:
339 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
340 loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg,
341 mir->dalvikInsn.vB_wide & 0xffffffff,
342 (mir->dalvikInsn.vB_wide >> 32) & 0xffffffff);
343 storeValueWide(cUnit, rlDest, rlResult);
344 break;
345
346 case Instruction::CONST_WIDE_HIGH16:
347 rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true);
348 loadConstantValueWide(cUnit, rlResult.lowReg, rlResult.highReg,
buzbee408ad162012-06-06 16:45:18 -0700349 0, vB << 16);
Bill Buzbeea114add2012-05-03 15:00:40 -0700350 storeValueWide(cUnit, rlDest, rlResult);
351 break;
352
353 case Instruction::MONITOR_ENTER:
buzbee408ad162012-06-06 16:45:18 -0700354 genMonitorEnter(cUnit, optFlags, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700355 break;
356
357 case Instruction::MONITOR_EXIT:
buzbee408ad162012-06-06 16:45:18 -0700358 genMonitorExit(cUnit, optFlags, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700359 break;
360
361 case Instruction::CHECK_CAST:
buzbee408ad162012-06-06 16:45:18 -0700362 genCheckCast(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700363 break;
364
365 case Instruction::INSTANCE_OF:
buzbee408ad162012-06-06 16:45:18 -0700366 genInstanceof(cUnit, vC, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700367 break;
368
369 case Instruction::NEW_INSTANCE:
buzbee408ad162012-06-06 16:45:18 -0700370 genNewInstance(cUnit, vB, rlDest);
Bill Buzbeea114add2012-05-03 15:00:40 -0700371 break;
372
373 case Instruction::THROW:
buzbee408ad162012-06-06 16:45:18 -0700374 genThrow(cUnit, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700375 break;
376
Bill Buzbeea114add2012-05-03 15:00:40 -0700377 case Instruction::ARRAY_LENGTH:
378 int lenOffset;
379 lenOffset = Array::LengthOffset().Int32Value();
380 rlSrc[0] = loadValue(cUnit, rlSrc[0], kCoreReg);
buzbee408ad162012-06-06 16:45:18 -0700381 genNullCheck(cUnit, rlSrc[0].sRegLow, rlSrc[0].lowReg, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700382 rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true);
383 loadWordDisp(cUnit, rlSrc[0].lowReg, lenOffset, rlResult.lowReg);
384 storeValue(cUnit, rlDest, rlResult);
385 break;
386
387 case Instruction::CONST_STRING:
388 case Instruction::CONST_STRING_JUMBO:
buzbee6969d502012-06-15 16:40:31 -0700389 genConstString(cUnit, vB, rlDest);
Bill Buzbeea114add2012-05-03 15:00:40 -0700390 break;
391
392 case Instruction::CONST_CLASS:
buzbee6969d502012-06-15 16:40:31 -0700393 genConstClass(cUnit, vB, rlDest);
Bill Buzbeea114add2012-05-03 15:00:40 -0700394 break;
395
396 case Instruction::FILL_ARRAY_DATA:
buzbee408ad162012-06-06 16:45:18 -0700397 genFillArrayData(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700398 break;
399
400 case Instruction::FILLED_NEW_ARRAY:
buzbee6969d502012-06-15 16:40:31 -0700401 genFilledNewArray(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic,
buzbee3b3dbdd2012-06-13 13:39:34 -0700402 false /* not range */));
Bill Buzbeea114add2012-05-03 15:00:40 -0700403 break;
404
405 case Instruction::FILLED_NEW_ARRAY_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700406 genFilledNewArray(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic,
buzbee3b3dbdd2012-06-13 13:39:34 -0700407 true /* range */));
Bill Buzbeea114add2012-05-03 15:00:40 -0700408 break;
409
410 case Instruction::NEW_ARRAY:
buzbee408ad162012-06-06 16:45:18 -0700411 genNewArray(cUnit, vC, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700412 break;
413
414 case Instruction::GOTO:
415 case Instruction::GOTO_16:
416 case Instruction::GOTO_32:
417 if (bb->taken->startOffset <= mir->offset) {
buzbee408ad162012-06-06 16:45:18 -0700418 genSuspendTestAndBranch(cUnit, optFlags, &labelList[bb->taken->id]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700419 } else {
420 opUnconditionalBranch(cUnit, &labelList[bb->taken->id]);
421 }
422 break;
423
424 case Instruction::PACKED_SWITCH:
buzbee408ad162012-06-06 16:45:18 -0700425 genPackedSwitch(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700426 break;
427
428 case Instruction::SPARSE_SWITCH:
buzbeea1da8a52012-07-09 14:00:21 -0700429 genSparseSwitch(cUnit, vB, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700430 break;
431
432 case Instruction::CMPL_FLOAT:
433 case Instruction::CMPG_FLOAT:
434 case Instruction::CMPL_DOUBLE:
435 case Instruction::CMPG_DOUBLE:
buzbee408ad162012-06-06 16:45:18 -0700436 res = genCmpFP(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700437 break;
438
439 case Instruction::CMP_LONG:
buzbee408ad162012-06-06 16:45:18 -0700440 genCmpLong(cUnit, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700441 break;
442
443 case Instruction::IF_EQ:
444 case Instruction::IF_NE:
445 case Instruction::IF_LT:
446 case Instruction::IF_GE:
447 case Instruction::IF_GT:
448 case Instruction::IF_LE: {
buzbee3b3dbdd2012-06-13 13:39:34 -0700449 LIR* taken = &labelList[bb->taken->id];
450 LIR* fallThrough = &labelList[bb->fallThrough->id];
Bill Buzbeea114add2012-05-03 15:00:40 -0700451 bool backwardBranch;
452 backwardBranch = (bb->taken->startOffset <= mir->offset);
453 if (backwardBranch) {
buzbee408ad162012-06-06 16:45:18 -0700454 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700455 }
buzbee3b3dbdd2012-06-13 13:39:34 -0700456 genCompareAndBranch(cUnit, opcode, rlSrc[0], rlSrc[1], taken,
457 fallThrough);
Bill Buzbeea114add2012-05-03 15:00:40 -0700458 break;
459 }
460
461 case Instruction::IF_EQZ:
462 case Instruction::IF_NEZ:
463 case Instruction::IF_LTZ:
464 case Instruction::IF_GEZ:
465 case Instruction::IF_GTZ:
466 case Instruction::IF_LEZ: {
buzbee3b3dbdd2012-06-13 13:39:34 -0700467 LIR* taken = &labelList[bb->taken->id];
468 LIR* fallThrough = &labelList[bb->fallThrough->id];
Bill Buzbeea114add2012-05-03 15:00:40 -0700469 bool backwardBranch;
470 backwardBranch = (bb->taken->startOffset <= mir->offset);
471 if (backwardBranch) {
buzbee408ad162012-06-06 16:45:18 -0700472 genSuspendTest(cUnit, optFlags);
Bill Buzbeea114add2012-05-03 15:00:40 -0700473 }
buzbee3b3dbdd2012-06-13 13:39:34 -0700474 genCompareZeroAndBranch(cUnit, opcode, rlSrc[0], taken, fallThrough);
Bill Buzbeea114add2012-05-03 15:00:40 -0700475 break;
476 }
477
478 case Instruction::AGET_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700479 genArrayGet(cUnit, optFlags, kLong, rlSrc[0], rlSrc[1], rlDest, 3);
Bill Buzbeea114add2012-05-03 15:00:40 -0700480 break;
481 case Instruction::AGET:
482 case Instruction::AGET_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700483 genArrayGet(cUnit, optFlags, kWord, rlSrc[0], rlSrc[1], rlDest, 2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700484 break;
485 case Instruction::AGET_BOOLEAN:
buzbee408ad162012-06-06 16:45:18 -0700486 genArrayGet(cUnit, optFlags, kUnsignedByte, rlSrc[0], rlSrc[1], rlDest, 0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700487 break;
488 case Instruction::AGET_BYTE:
buzbee408ad162012-06-06 16:45:18 -0700489 genArrayGet(cUnit, optFlags, kSignedByte, rlSrc[0], rlSrc[1], rlDest, 0);
Bill Buzbeea114add2012-05-03 15:00:40 -0700490 break;
491 case Instruction::AGET_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700492 genArrayGet(cUnit, optFlags, kUnsignedHalf, rlSrc[0], rlSrc[1], rlDest, 1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700493 break;
494 case Instruction::AGET_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700495 genArrayGet(cUnit, optFlags, kSignedHalf, rlSrc[0], rlSrc[1], rlDest, 1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700496 break;
497 case Instruction::APUT_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700498 genArrayPut(cUnit, optFlags, kLong, rlSrc[1], rlSrc[2], rlSrc[0], 3);
Bill Buzbeea114add2012-05-03 15:00:40 -0700499 break;
500 case Instruction::APUT:
buzbee408ad162012-06-06 16:45:18 -0700501 genArrayPut(cUnit, optFlags, kWord, rlSrc[1], rlSrc[2], rlSrc[0], 2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700502 break;
503 case Instruction::APUT_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700504 genArrayObjPut(cUnit, optFlags, rlSrc[1], rlSrc[2], rlSrc[0], 2);
Bill Buzbeea114add2012-05-03 15:00:40 -0700505 break;
506 case Instruction::APUT_SHORT:
507 case Instruction::APUT_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700508 genArrayPut(cUnit, optFlags, kUnsignedHalf, rlSrc[1], rlSrc[2], rlSrc[0], 1);
Bill Buzbeea114add2012-05-03 15:00:40 -0700509 break;
510 case Instruction::APUT_BYTE:
511 case Instruction::APUT_BOOLEAN:
buzbee408ad162012-06-06 16:45:18 -0700512 genArrayPut(cUnit, optFlags, kUnsignedByte, rlSrc[1], rlSrc[2],
Bill Buzbeea114add2012-05-03 15:00:40 -0700513 rlSrc[0], 0);
514 break;
515
516 case Instruction::IGET_OBJECT:
517 //case Instruction::IGET_OBJECT_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700518 genIGet(cUnit, vC, optFlags, kWord, rlDest, rlSrc[0], false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700519 break;
520
521 case Instruction::IGET_WIDE:
522 //case Instruction::IGET_WIDE_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700523 genIGet(cUnit, vC, optFlags, kLong, rlDest, rlSrc[0], true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700524 break;
525
526 case Instruction::IGET:
527 //case Instruction::IGET_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700528 genIGet(cUnit, vC, optFlags, kWord, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700529 break;
530
531 case Instruction::IGET_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700532 genIGet(cUnit, vC, optFlags, kUnsignedHalf, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700533 break;
534
535 case Instruction::IGET_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700536 genIGet(cUnit, vC, optFlags, kSignedHalf, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700537 break;
538
539 case Instruction::IGET_BOOLEAN:
540 case Instruction::IGET_BYTE:
buzbee408ad162012-06-06 16:45:18 -0700541 genIGet(cUnit, vC, optFlags, kUnsignedByte, rlDest, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700542 break;
543
544 case Instruction::IPUT_WIDE:
545 //case Instruction::IPUT_WIDE_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700546 genIPut(cUnit, vC, optFlags, kLong, rlSrc[0], rlSrc[1], true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700547 break;
548
549 case Instruction::IPUT_OBJECT:
550 //case Instruction::IPUT_OBJECT_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700551 genIPut(cUnit, vC, optFlags, kWord, rlSrc[0], rlSrc[1], false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700552 break;
553
554 case Instruction::IPUT:
555 //case Instruction::IPUT_VOLATILE:
buzbee408ad162012-06-06 16:45:18 -0700556 genIPut(cUnit, vC, optFlags, kWord, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700557 break;
558
559 case Instruction::IPUT_BOOLEAN:
560 case Instruction::IPUT_BYTE:
buzbee408ad162012-06-06 16:45:18 -0700561 genIPut(cUnit, vC, optFlags, kUnsignedByte, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700562 break;
563
564 case Instruction::IPUT_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700565 genIPut(cUnit, vC, optFlags, kUnsignedHalf, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700566 break;
567
568 case Instruction::IPUT_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700569 genIPut(cUnit, vC, optFlags, kSignedHalf, rlSrc[0], rlSrc[1], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700570 break;
571
572 case Instruction::SGET_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700573 genSget(cUnit, vB, rlDest, false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700574 break;
575 case Instruction::SGET:
576 case Instruction::SGET_BOOLEAN:
577 case Instruction::SGET_BYTE:
578 case Instruction::SGET_CHAR:
579 case Instruction::SGET_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700580 genSget(cUnit, vB, rlDest, false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700581 break;
582
583 case Instruction::SGET_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700584 genSget(cUnit, vB, rlDest, true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700585 break;
586
587 case Instruction::SPUT_OBJECT:
buzbee408ad162012-06-06 16:45:18 -0700588 genSput(cUnit, vB, rlSrc[0], false, true);
Bill Buzbeea114add2012-05-03 15:00:40 -0700589 break;
590
591 case Instruction::SPUT:
592 case Instruction::SPUT_BOOLEAN:
593 case Instruction::SPUT_BYTE:
594 case Instruction::SPUT_CHAR:
595 case Instruction::SPUT_SHORT:
buzbee408ad162012-06-06 16:45:18 -0700596 genSput(cUnit, vB, rlSrc[0], false, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700597 break;
598
599 case Instruction::SPUT_WIDE:
buzbee408ad162012-06-06 16:45:18 -0700600 genSput(cUnit, vB, rlSrc[0], true, false);
Bill Buzbeea114add2012-05-03 15:00:40 -0700601 break;
602
603 case Instruction::INVOKE_STATIC_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700604 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700605 break;
606 case Instruction::INVOKE_STATIC:
buzbee6969d502012-06-15 16:40:31 -0700607 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kStatic, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700608 break;
609
610 case Instruction::INVOKE_DIRECT:
buzbee6969d502012-06-15 16:40:31 -0700611 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kDirect, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700612 break;
613 case Instruction::INVOKE_DIRECT_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700614 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kDirect, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700615 break;
616
617 case Instruction::INVOKE_VIRTUAL:
buzbee6969d502012-06-15 16:40:31 -0700618 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kVirtual, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700619 break;
620 case Instruction::INVOKE_VIRTUAL_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700621 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kVirtual, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700622 break;
623
624 case Instruction::INVOKE_SUPER:
buzbee6969d502012-06-15 16:40:31 -0700625 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kSuper, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700626 break;
627 case Instruction::INVOKE_SUPER_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700628 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kSuper, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700629 break;
630
631 case Instruction::INVOKE_INTERFACE:
buzbee6969d502012-06-15 16:40:31 -0700632 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kInterface, false));
Bill Buzbeea114add2012-05-03 15:00:40 -0700633 break;
634 case Instruction::INVOKE_INTERFACE_RANGE:
buzbee6969d502012-06-15 16:40:31 -0700635 genInvoke(cUnit, oatNewCallInfo(cUnit, bb, mir, kInterface, true));
Bill Buzbeea114add2012-05-03 15:00:40 -0700636 break;
637
638 case Instruction::NEG_INT:
639 case Instruction::NOT_INT:
buzbee408ad162012-06-06 16:45:18 -0700640 res = genArithOpInt(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700641 break;
642
643 case Instruction::NEG_LONG:
644 case Instruction::NOT_LONG:
buzbee408ad162012-06-06 16:45:18 -0700645 res = genArithOpLong(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700646 break;
647
648 case Instruction::NEG_FLOAT:
buzbee408ad162012-06-06 16:45:18 -0700649 res = genArithOpFloat(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700650 break;
651
652 case Instruction::NEG_DOUBLE:
buzbee408ad162012-06-06 16:45:18 -0700653 res = genArithOpDouble(cUnit, opcode, rlDest, rlSrc[0], rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700654 break;
655
656 case Instruction::INT_TO_LONG:
buzbee408ad162012-06-06 16:45:18 -0700657 genIntToLong(cUnit, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700658 break;
659
660 case Instruction::LONG_TO_INT:
661 rlSrc[0] = oatUpdateLocWide(cUnit, rlSrc[0]);
662 rlSrc[0] = oatWideToNarrow(cUnit, rlSrc[0]);
663 storeValue(cUnit, rlDest, rlSrc[0]);
664 break;
665
666 case Instruction::INT_TO_BYTE:
667 case Instruction::INT_TO_SHORT:
668 case Instruction::INT_TO_CHAR:
buzbee408ad162012-06-06 16:45:18 -0700669 genIntNarrowing(cUnit, opcode, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700670 break;
671
672 case Instruction::INT_TO_FLOAT:
673 case Instruction::INT_TO_DOUBLE:
674 case Instruction::LONG_TO_FLOAT:
675 case Instruction::LONG_TO_DOUBLE:
676 case Instruction::FLOAT_TO_INT:
677 case Instruction::FLOAT_TO_LONG:
678 case Instruction::FLOAT_TO_DOUBLE:
679 case Instruction::DOUBLE_TO_INT:
680 case Instruction::DOUBLE_TO_LONG:
681 case Instruction::DOUBLE_TO_FLOAT:
buzbee408ad162012-06-06 16:45:18 -0700682 genConversion(cUnit, opcode, rlDest, rlSrc[0]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700683 break;
684
685 case Instruction::ADD_INT:
686 case Instruction::SUB_INT:
687 case Instruction::MUL_INT:
688 case Instruction::DIV_INT:
689 case Instruction::REM_INT:
690 case Instruction::AND_INT:
691 case Instruction::OR_INT:
692 case Instruction::XOR_INT:
693 case Instruction::SHL_INT:
694 case Instruction::SHR_INT:
695 case Instruction::USHR_INT:
696 case Instruction::ADD_INT_2ADDR:
697 case Instruction::SUB_INT_2ADDR:
698 case Instruction::MUL_INT_2ADDR:
699 case Instruction::DIV_INT_2ADDR:
700 case Instruction::REM_INT_2ADDR:
701 case Instruction::AND_INT_2ADDR:
702 case Instruction::OR_INT_2ADDR:
703 case Instruction::XOR_INT_2ADDR:
704 case Instruction::SHL_INT_2ADDR:
705 case Instruction::SHR_INT_2ADDR:
706 case Instruction::USHR_INT_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700707 genArithOpInt(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700708 break;
709
710 case Instruction::ADD_LONG:
711 case Instruction::SUB_LONG:
712 case Instruction::MUL_LONG:
713 case Instruction::DIV_LONG:
714 case Instruction::REM_LONG:
715 case Instruction::AND_LONG:
716 case Instruction::OR_LONG:
717 case Instruction::XOR_LONG:
718 case Instruction::ADD_LONG_2ADDR:
719 case Instruction::SUB_LONG_2ADDR:
720 case Instruction::MUL_LONG_2ADDR:
721 case Instruction::DIV_LONG_2ADDR:
722 case Instruction::REM_LONG_2ADDR:
723 case Instruction::AND_LONG_2ADDR:
724 case Instruction::OR_LONG_2ADDR:
725 case Instruction::XOR_LONG_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700726 genArithOpLong(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700727 break;
728
729 case Instruction::SHL_LONG:
730 case Instruction::SHR_LONG:
731 case Instruction::USHR_LONG:
732 case Instruction::SHL_LONG_2ADDR:
733 case Instruction::SHR_LONG_2ADDR:
734 case Instruction::USHR_LONG_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700735 genShiftOpLong(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700736 break;
737
738 case Instruction::ADD_FLOAT:
739 case Instruction::SUB_FLOAT:
740 case Instruction::MUL_FLOAT:
741 case Instruction::DIV_FLOAT:
742 case Instruction::REM_FLOAT:
743 case Instruction::ADD_FLOAT_2ADDR:
744 case Instruction::SUB_FLOAT_2ADDR:
745 case Instruction::MUL_FLOAT_2ADDR:
746 case Instruction::DIV_FLOAT_2ADDR:
747 case Instruction::REM_FLOAT_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700748 genArithOpFloat(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700749 break;
750
751 case Instruction::ADD_DOUBLE:
752 case Instruction::SUB_DOUBLE:
753 case Instruction::MUL_DOUBLE:
754 case Instruction::DIV_DOUBLE:
755 case Instruction::REM_DOUBLE:
756 case Instruction::ADD_DOUBLE_2ADDR:
757 case Instruction::SUB_DOUBLE_2ADDR:
758 case Instruction::MUL_DOUBLE_2ADDR:
759 case Instruction::DIV_DOUBLE_2ADDR:
760 case Instruction::REM_DOUBLE_2ADDR:
buzbee408ad162012-06-06 16:45:18 -0700761 genArithOpDouble(cUnit, opcode, rlDest, rlSrc[0], rlSrc[1]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700762 break;
763
764 case Instruction::RSUB_INT:
765 case Instruction::ADD_INT_LIT16:
766 case Instruction::MUL_INT_LIT16:
767 case Instruction::DIV_INT_LIT16:
768 case Instruction::REM_INT_LIT16:
769 case Instruction::AND_INT_LIT16:
770 case Instruction::OR_INT_LIT16:
771 case Instruction::XOR_INT_LIT16:
772 case Instruction::ADD_INT_LIT8:
773 case Instruction::RSUB_INT_LIT8:
774 case Instruction::MUL_INT_LIT8:
775 case Instruction::DIV_INT_LIT8:
776 case Instruction::REM_INT_LIT8:
777 case Instruction::AND_INT_LIT8:
778 case Instruction::OR_INT_LIT8:
779 case Instruction::XOR_INT_LIT8:
780 case Instruction::SHL_INT_LIT8:
781 case Instruction::SHR_INT_LIT8:
782 case Instruction::USHR_INT_LIT8:
buzbee408ad162012-06-06 16:45:18 -0700783 genArithOpIntLit(cUnit, opcode, rlDest, rlSrc[0], vC);
Bill Buzbeea114add2012-05-03 15:00:40 -0700784 break;
785
786 default:
787 res = true;
788 }
789 return res;
buzbeee3acd072012-02-25 17:03:10 -0800790}
791
buzbee31a4a6f2012-02-28 15:36:15 -0800792const char* extendedMIROpNames[kMirOpLast - kMirOpFirst] = {
Bill Buzbeea114add2012-05-03 15:00:40 -0700793 "kMirOpPhi",
794 "kMirOpCopy",
795 "kMirFusedCmplFloat",
796 "kMirFusedCmpgFloat",
797 "kMirFusedCmplDouble",
798 "kMirFusedCmpgDouble",
799 "kMirFusedCmpLong",
800 "kMirNop",
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700801 "kMirOpNullCheck",
802 "kMirOpRangeCheck",
803 "kMirOpDivZeroCheck",
804 "kMirOpCheck",
buzbeee3acd072012-02-25 17:03:10 -0800805};
806
807/* Extended MIR instructions like PHI */
buzbee84fd6932012-03-29 16:44:16 -0700808void handleExtendedMethodMIR(CompilationUnit* cUnit, BasicBlock* bb, MIR* mir)
buzbeee3acd072012-02-25 17:03:10 -0800809{
Bill Buzbeea114add2012-05-03 15:00:40 -0700810 int opOffset = mir->dalvikInsn.opcode - kMirOpFirst;
811 char* msg = NULL;
812 if (cUnit->printMe) {
813 msg = (char*)oatNew(cUnit, strlen(extendedMIROpNames[opOffset]) + 1,
814 false, kAllocDebugInfo);
815 strcpy(msg, extendedMIROpNames[opOffset]);
816 }
817 LIR* op = newLIR1(cUnit, kPseudoExtended, (int) msg);
buzbeee3acd072012-02-25 17:03:10 -0800818
Bill Buzbeea114add2012-05-03 15:00:40 -0700819 switch ((ExtendedMIROpcode)mir->dalvikInsn.opcode) {
820 case kMirOpPhi: {
821 char* ssaString = NULL;
822 if (cUnit->printMe) {
823 ssaString = oatGetSSAString(cUnit, mir->ssaRep);
824 }
825 op->flags.isNop = true;
826 newLIR1(cUnit, kPseudoSSARep, (int) ssaString);
827 break;
buzbeee3acd072012-02-25 17:03:10 -0800828 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700829 case kMirOpCopy: {
830 RegLocation rlSrc = oatGetSrc(cUnit, mir, 0);
buzbee15bf9802012-06-12 17:49:27 -0700831 RegLocation rlDest = oatGetDest(cUnit, mir);
Bill Buzbeea114add2012-05-03 15:00:40 -0700832 storeValue(cUnit, rlDest, rlSrc);
833 break;
834 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700835 case kMirOpFusedCmplFloat:
836 genFusedFPCmpBranch(cUnit, bb, mir, false /*gt bias*/, false /*double*/);
837 break;
838 case kMirOpFusedCmpgFloat:
839 genFusedFPCmpBranch(cUnit, bb, mir, true /*gt bias*/, false /*double*/);
840 break;
841 case kMirOpFusedCmplDouble:
842 genFusedFPCmpBranch(cUnit, bb, mir, false /*gt bias*/, true /*double*/);
843 break;
844 case kMirOpFusedCmpgDouble:
845 genFusedFPCmpBranch(cUnit, bb, mir, true /*gt bias*/, true /*double*/);
846 break;
847 case kMirOpFusedCmpLong:
848 genFusedLongCmpBranch(cUnit, bb, mir);
849 break;
Bill Buzbeea114add2012-05-03 15:00:40 -0700850 default:
851 break;
852 }
buzbeee3acd072012-02-25 17:03:10 -0800853}
854
855/* Handle the content in each basic block */
buzbee31a4a6f2012-02-28 15:36:15 -0800856bool methodBlockCodeGen(CompilationUnit* cUnit, BasicBlock* bb)
buzbeee3acd072012-02-25 17:03:10 -0800857{
buzbee488a78c2012-09-10 15:55:34 -0700858 if (bb->blockType == kDead) return false;
buzbee8320f382012-09-11 16:29:42 -0700859 cUnit->currentDalvikOffset = bb->startOffset;
Bill Buzbeea114add2012-05-03 15:00:40 -0700860 MIR* mir;
buzbeea1da8a52012-07-09 14:00:21 -0700861 LIR* labelList = cUnit->blockLabelList;
Bill Buzbeea114add2012-05-03 15:00:40 -0700862 int blockId = bb->id;
buzbeee3acd072012-02-25 17:03:10 -0800863
Bill Buzbeea114add2012-05-03 15:00:40 -0700864 cUnit->curBlock = bb;
865 labelList[blockId].operands[0] = bb->startOffset;
buzbeee3acd072012-02-25 17:03:10 -0800866
Bill Buzbeea114add2012-05-03 15:00:40 -0700867 /* Insert the block label */
868 labelList[blockId].opcode = kPseudoNormalBlockLabel;
869 oatAppendLIR(cUnit, (LIR*) &labelList[blockId]);
buzbeee3acd072012-02-25 17:03:10 -0800870
buzbee8320f382012-09-11 16:29:42 -0700871 LIR* headLIR = NULL;
872
Bill Buzbeea5b30242012-09-28 07:19:44 -0700873 /* If this is a catch block, export the start address */
buzbee8320f382012-09-11 16:29:42 -0700874 if (bb->catchEntry) {
Bill Buzbeea5b30242012-09-28 07:19:44 -0700875 headLIR = newLIR0(cUnit, kPseudoExportedPC);
buzbee8320f382012-09-11 16:29:42 -0700876 }
877
Bill Buzbeea114add2012-05-03 15:00:40 -0700878 /* Free temp registers and reset redundant store tracking */
879 oatResetRegPool(cUnit);
880 oatResetDefTracking(cUnit);
881
buzbeed1643e42012-09-05 14:06:51 -0700882 oatClobberAllRegs(cUnit);
Bill Buzbeea114add2012-05-03 15:00:40 -0700883
Bill Buzbeea114add2012-05-03 15:00:40 -0700884
885 if (bb->blockType == kEntryBlock) {
buzbeead8f15e2012-06-18 14:49:45 -0700886 int startVReg = cUnit->numDalvikRegisters - cUnit->numIns;
887 genEntrySequence(cUnit, &cUnit->regLocation[startVReg],
888 cUnit->regLocation[cUnit->methodSReg]);
Bill Buzbeea114add2012-05-03 15:00:40 -0700889 } else if (bb->blockType == kExitBlock) {
buzbee2cfc6392012-05-07 14:51:40 -0700890 genExitSequence(cUnit);
Bill Buzbeea114add2012-05-03 15:00:40 -0700891 }
892
893 for (mir = bb->firstMIRInsn; mir; mir = mir->next) {
buzbeee3acd072012-02-25 17:03:10 -0800894 oatResetRegPool(cUnit);
Bill Buzbeea114add2012-05-03 15:00:40 -0700895 if (cUnit->disableOpt & (1 << kTrackLiveTemps)) {
896 oatClobberAllRegs(cUnit);
buzbeee1965672012-03-11 18:39:19 -0700897 }
898
Bill Buzbeea114add2012-05-03 15:00:40 -0700899 if (cUnit->disableOpt & (1 << kSuppressLoads)) {
900 oatResetDefTracking(cUnit);
buzbeee3acd072012-02-25 17:03:10 -0800901 }
902
buzbee3d661942012-03-14 17:37:27 -0700903#ifndef NDEBUG
Bill Buzbeea114add2012-05-03 15:00:40 -0700904 /* Reset temp tracking sanity check */
905 cUnit->liveSReg = INVALID_SREG;
buzbee3d661942012-03-14 17:37:27 -0700906#endif
907
Bill Buzbeea114add2012-05-03 15:00:40 -0700908 cUnit->currentDalvikOffset = mir->offset;
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700909 int opcode = mir->dalvikInsn.opcode;
Bill Buzbeea114add2012-05-03 15:00:40 -0700910 LIR* boundaryLIR;
buzbeee3acd072012-02-25 17:03:10 -0800911
Bill Buzbeea114add2012-05-03 15:00:40 -0700912 /* Mark the beginning of a Dalvik instruction for line tracking */
913 char* instStr = cUnit->printMe ?
914 oatGetDalvikDisassembly(cUnit, mir->dalvikInsn, "") : NULL;
buzbeed1643e42012-09-05 14:06:51 -0700915 boundaryLIR = markBoundary(cUnit, mir->offset, instStr);
Bill Buzbeea114add2012-05-03 15:00:40 -0700916 /* Remember the first LIR for this block */
917 if (headLIR == NULL) {
918 headLIR = boundaryLIR;
919 /* Set the first boundaryLIR as a scheduling barrier */
920 headLIR->defMask = ENCODE_ALL;
buzbeee3acd072012-02-25 17:03:10 -0800921 }
922
Bill Buzbeea114add2012-05-03 15:00:40 -0700923 /* Don't generate the SSA annotation unless verbose mode is on */
924 if (cUnit->printMe && mir->ssaRep) {
925 char* ssaString = oatGetSSAString(cUnit, mir->ssaRep);
926 newLIR1(cUnit, kPseudoSSARep, (int) ssaString);
927 }
928
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700929 if (opcode == kMirOpCheck) {
930 // Combine check and work halves of throwing instruction.
931 MIR* workHalf = mir->meta.throwInsn;
932 mir->dalvikInsn.opcode = workHalf->dalvikInsn.opcode;
933 opcode = workHalf->dalvikInsn.opcode;
934 SSARepresentation* ssaRep = workHalf->ssaRep;
935 workHalf->ssaRep = mir->ssaRep;
936 mir->ssaRep = ssaRep;
937 workHalf->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop);
938 }
939
940 if (opcode >= kMirOpFirst) {
Bill Buzbeea114add2012-05-03 15:00:40 -0700941 handleExtendedMethodMIR(cUnit, bb, mir);
942 continue;
943 }
944
945 bool notHandled = compileDalvikInstruction(cUnit, mir, bb, labelList);
946 if (notHandled) {
Bill Buzbeec9f40dd2012-08-15 11:35:25 -0700947 LOG(FATAL) << StringPrintf("%#06x: Opcode %#x (%s)",
948 mir->offset, opcode,
949 Instruction::Name(mir->dalvikInsn.opcode));
Bill Buzbeea114add2012-05-03 15:00:40 -0700950 }
951 }
952
953 if (headLIR) {
954 /*
955 * Eliminate redundant loads/stores and delay stores into later
956 * slots
957 */
958 oatApplyLocalOptimizations(cUnit, (LIR*) headLIR, cUnit->lastLIRInsn);
959
960 /*
961 * Generate an unconditional branch to the fallthrough block.
962 */
963 if (bb->fallThrough) {
964 opUnconditionalBranch(cUnit, &labelList[bb->fallThrough->id]);
965 }
966 }
967 return false;
buzbeee3acd072012-02-25 17:03:10 -0800968}
969
buzbee16da88c2012-03-20 10:38:17 -0700970/* Set basic block labels */
971bool labelBlocks(CompilationUnit* cUnit, BasicBlock* bb)
972{
buzbeea1da8a52012-07-09 14:00:21 -0700973 LIR* labelList = cUnit->blockLabelList;
Bill Buzbeea114add2012-05-03 15:00:40 -0700974 int blockId = bb->id;
buzbee16da88c2012-03-20 10:38:17 -0700975
Bill Buzbeea114add2012-05-03 15:00:40 -0700976 cUnit->curBlock = bb;
977 labelList[blockId].operands[0] = bb->startOffset;
buzbee16da88c2012-03-20 10:38:17 -0700978
Bill Buzbeea114add2012-05-03 15:00:40 -0700979 /* Insert the block label */
980 labelList[blockId].opcode = kPseudoNormalBlockLabel;
981 return false;
buzbee16da88c2012-03-20 10:38:17 -0700982}
983
984void oatSpecialMIR2LIR(CompilationUnit* cUnit, SpecialCaseHandler specialCase)
985{
Bill Buzbeea114add2012-05-03 15:00:40 -0700986 /* Find the first DalvikByteCode block */
987 int numReachableBlocks = cUnit->numReachableBlocks;
988 const GrowableList *blockList = &cUnit->blockList;
989 BasicBlock*bb = NULL;
990 for (int idx = 0; idx < numReachableBlocks; idx++) {
991 int dfsIndex = cUnit->dfsOrder.elemList[idx];
992 bb = (BasicBlock*)oatGrowableListGetElement(blockList, dfsIndex);
993 if (bb->blockType == kDalvikByteCode) {
994 break;
buzbee16da88c2012-03-20 10:38:17 -0700995 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700996 }
997 if (bb == NULL) {
998 return;
999 }
1000 DCHECK_EQ(bb->startOffset, 0);
Elliott Hughes74847412012-06-20 18:10:21 -07001001 DCHECK(bb->firstMIRInsn != NULL);
buzbee16da88c2012-03-20 10:38:17 -07001002
Bill Buzbeea114add2012-05-03 15:00:40 -07001003 /* Get the first instruction */
1004 MIR* mir = bb->firstMIRInsn;
buzbee16da88c2012-03-20 10:38:17 -07001005
Bill Buzbeea114add2012-05-03 15:00:40 -07001006 /* Free temp registers and reset redundant store tracking */
1007 oatResetRegPool(cUnit);
1008 oatResetDefTracking(cUnit);
1009 oatClobberAllRegs(cUnit);
buzbee16da88c2012-03-20 10:38:17 -07001010
Bill Buzbeea114add2012-05-03 15:00:40 -07001011 genSpecialCase(cUnit, bb, mir, specialCase);
buzbee16da88c2012-03-20 10:38:17 -07001012}
1013
buzbeee3acd072012-02-25 17:03:10 -08001014void oatMethodMIR2LIR(CompilationUnit* cUnit)
1015{
Bill Buzbeea114add2012-05-03 15:00:40 -07001016 /* Used to hold the labels of each block */
1017 cUnit->blockLabelList =
buzbeea1da8a52012-07-09 14:00:21 -07001018 (LIR*) oatNew(cUnit, sizeof(LIR) * cUnit->numBlocks, true, kAllocLIR);
buzbeee3acd072012-02-25 17:03:10 -08001019
Bill Buzbeea114add2012-05-03 15:00:40 -07001020 oatDataFlowAnalysisDispatcher(cUnit, methodBlockCodeGen,
1021 kPreOrderDFSTraversal, false /* Iterative */);
Ian Rogersab2b55d2012-03-18 00:06:11 -07001022
Bill Buzbeea114add2012-05-03 15:00:40 -07001023 handleSuspendLaunchpads(cUnit);
buzbeee3acd072012-02-25 17:03:10 -08001024
Bill Buzbeea114add2012-05-03 15:00:40 -07001025 handleThrowLaunchpads(cUnit);
buzbeee3acd072012-02-25 17:03:10 -08001026
Bill Buzbeea114add2012-05-03 15:00:40 -07001027 handleIntrinsicLaunchpads(cUnit);
buzbeefc9e6fa2012-03-23 15:14:29 -07001028
Bill Buzbeea114add2012-05-03 15:00:40 -07001029 if (!(cUnit->disableOpt & (1 << kSafeOptimizations))) {
1030 removeRedundantBranches(cUnit);
1031 }
buzbeee3acd072012-02-25 17:03:10 -08001032}
1033
1034/* Needed by the ld/st optmizatons */
buzbee31a4a6f2012-02-28 15:36:15 -08001035LIR* oatRegCopyNoInsert(CompilationUnit* cUnit, int rDest, int rSrc)
buzbeee3acd072012-02-25 17:03:10 -08001036{
Bill Buzbeea114add2012-05-03 15:00:40 -07001037 return opRegCopyNoInsert(cUnit, rDest, rSrc);
buzbeee3acd072012-02-25 17:03:10 -08001038}
1039
1040/* Needed by the register allocator */
1041void oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc)
1042{
Bill Buzbeea114add2012-05-03 15:00:40 -07001043 opRegCopy(cUnit, rDest, rSrc);
buzbeee3acd072012-02-25 17:03:10 -08001044}
1045
1046/* Needed by the register allocator */
1047void oatRegCopyWide(CompilationUnit* cUnit, int destLo, int destHi,
Bill Buzbeea114add2012-05-03 15:00:40 -07001048 int srcLo, int srcHi)
buzbeee3acd072012-02-25 17:03:10 -08001049{
Bill Buzbeea114add2012-05-03 15:00:40 -07001050 opRegCopyWide(cUnit, destLo, destHi, srcLo, srcHi);
buzbeee3acd072012-02-25 17:03:10 -08001051}
1052
1053void oatFlushRegImpl(CompilationUnit* cUnit, int rBase,
Bill Buzbeea114add2012-05-03 15:00:40 -07001054 int displacement, int rSrc, OpSize size)
buzbeee3acd072012-02-25 17:03:10 -08001055{
Bill Buzbeea114add2012-05-03 15:00:40 -07001056 storeBaseDisp(cUnit, rBase, displacement, rSrc, size);
buzbeee3acd072012-02-25 17:03:10 -08001057}
1058
1059void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase,
Bill Buzbeea114add2012-05-03 15:00:40 -07001060 int displacement, int rSrcLo, int rSrcHi)
buzbeee3acd072012-02-25 17:03:10 -08001061{
Bill Buzbeea114add2012-05-03 15:00:40 -07001062 storeBaseDispWide(cUnit, rBase, displacement, rSrcLo, rSrcHi);
buzbeee3acd072012-02-25 17:03:10 -08001063}
1064
1065} // namespace art