blob: cf606a34afab3c752551999194f703b7f7a6fc9c [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
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/*
18 * This file contains arm-specific codegen factory support.
19 * It is included by
20 *
21 * Codegen-$(TARGET_ARCH_VARIANT).c
22 *
23 */
24
25/*
26 * Perform a "reg cmp imm" operation and jump to the PCR region if condition
27 * satisfies.
28 */
29static TGT_LIR* genRegImmCheck(CompilationUnit* cUnit,
30 ArmConditionCode cond, int reg,
31 int checkValue, int dOffset,
32 TGT_LIR* pcrLabel)
33{
34 TGT_LIR* branch = genCmpImmBranch(cUnit, cond, reg, checkValue);
35 BasicBlock* bb = cUnit->curBlock;
36 if (bb->taken) {
37 ArmLIR *exceptionLabel = (ArmLIR* ) cUnit->blockLabelList;
38 exceptionLabel += bb->taken->id;
39 branch->generic.target = (LIR* ) exceptionLabel;
40 return exceptionLabel;
41 } else {
42 LOG(FATAL) << "Catch blocks not handled yet";
43 return NULL; // quiet gcc
44 }
45}
46
47/*
48 * Perform null-check on a register. sReg is the ssa register being checked,
49 * and mReg is the machine register holding the actual value. If internal state
50 * indicates that sReg has been checked before the check request is ignored.
51 */
52static TGT_LIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg,
53 int dOffset, TGT_LIR* pcrLabel)
54{
55 /* This particular Dalvik register has been null-checked */
buzbee7b1b86d2011-08-26 18:59:10 -070056 UNIMPLEMENTED(WARNING) << "Need null check & throw support";
57 return pcrLabel;
buzbee67bf8852011-08-17 17:51:35 -070058 if (oatIsBitSet(cUnit->regPool->nullCheckedRegs, sReg)) {
59 return pcrLabel;
60 }
61 oatSetBit(cUnit->regPool->nullCheckedRegs, sReg);
62 return genRegImmCheck(cUnit, kArmCondEq, mReg, 0, dOffset, pcrLabel);
63}
64
65/*
66 * Perform a "reg cmp reg" operation and jump to the PCR region if condition
67 * satisfies.
68 */
69static TGT_LIR* genRegRegCheck(CompilationUnit* cUnit,
70 ArmConditionCode cond,
71 int reg1, int reg2, int dOffset,
72 TGT_LIR* pcrLabel)
73{
74 TGT_LIR* res;
75 res = opRegReg(cUnit, kOpCmp, reg1, reg2);
76 TGT_LIR* branch = opCondBranch(cUnit, cond);
77 genCheckCommon(cUnit, dOffset, branch, pcrLabel);
78 return res;
79}
80
81/* Perform bound check on two registers */
82static TGT_LIR* genBoundsCheck(CompilationUnit* cUnit, int rIndex,
83 int rBound, int dOffset, TGT_LIR* pcrLabel)
84{
85 return genRegRegCheck(cUnit, kArmCondCs, rIndex, rBound, dOffset,
86 pcrLabel);
87}