buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * This file contains arm-specific codegen factory support. |
| 19 | * It is included by |
| 20 | * |
| 21 | * Codegen-$(TARGET_ARCH_VARIANT).c |
| 22 | * |
| 23 | */ |
| 24 | |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 25 | static ArmLIR* genUnconditionalBranch(CompilationUnit*, ArmLIR*); |
| 26 | static ArmLIR* genConditionalBranch(CompilationUnit*, ArmConditionCode, |
| 27 | ArmLIR*); |
| 28 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 29 | /* |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 30 | * Utiltiy to load the current Method*. Broken out |
| 31 | * to allow easy change between placing the current Method* in a |
| 32 | * dedicated register or its home location in the frame. |
| 33 | */ |
| 34 | static void loadCurrMethodDirect(CompilationUnit *cUnit, int rTgt) |
| 35 | { |
| 36 | #if defined(METHOD_IN_REG) |
| 37 | genRegCopy(cUnit, rTgt, rMETHOD); |
| 38 | #else |
| 39 | loadWordDisp(cUnit, rSP, 0, rTgt); |
| 40 | #endif |
| 41 | } |
| 42 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 43 | static int loadCurrMethod(CompilationUnit *cUnit) |
| 44 | { |
| 45 | #if defined(METHOD_IN_REG) |
| 46 | return rMETHOD; |
| 47 | #else |
| 48 | int mReg = oatAllocTemp(cUnit); |
| 49 | loadCurrMethodDirect(cUnit, mReg); |
| 50 | return mReg; |
| 51 | #endif |
| 52 | } |
| 53 | |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 54 | static ArmLIR* genImmedCheck(CompilationUnit* cUnit, ArmConditionCode cCode, |
| 55 | int reg, int immVal, MIR* mir, ArmThrowKind kind) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 56 | { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 57 | ArmLIR* tgt = (ArmLIR*)oatNew(sizeof(ArmLIR), true); |
| 58 | tgt->opcode = kArmPseudoThrowTarget; |
| 59 | tgt->operands[0] = kind; |
| 60 | tgt->operands[1] = mir->offset; |
| 61 | ArmLIR* branch; |
| 62 | if (cCode == kArmCondAl) { |
| 63 | branch = genUnconditionalBranch(cUnit, tgt); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 64 | } else { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 65 | branch = genCmpImmBranch(cUnit, kArmCondEq, reg, 0); |
| 66 | branch->generic.target = (LIR*)tgt; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 67 | } |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 68 | // Remember branch target - will process later |
| 69 | oatInsertGrowableList(&cUnit->throwLaunchpads, (intptr_t)tgt); |
| 70 | return branch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* |
| 74 | * Perform null-check on a register. sReg is the ssa register being checked, |
| 75 | * and mReg is the machine register holding the actual value. If internal state |
| 76 | * indicates that sReg has been checked before the check request is ignored. |
| 77 | */ |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 78 | static ArmLIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, |
| 79 | MIR* mir) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 80 | { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 81 | if (oatIsBitSet(cUnit->regPool->nullCheckedRegs, sReg)) { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 82 | /* This particular Dalvik register has been null-checked */ |
| 83 | return NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 84 | } |
| 85 | oatSetBit(cUnit->regPool->nullCheckedRegs, sReg); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 86 | return genImmedCheck(cUnit, kArmCondEq, mReg, 0, mir, kArmThrowNullPointer); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* Perform bound check on two registers */ |
| 90 | static TGT_LIR* genBoundsCheck(CompilationUnit* cUnit, int rIndex, |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 91 | int rBound, MIR* mir, ArmThrowKind kind) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 92 | { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 93 | ArmLIR* tgt = (ArmLIR*)oatNew(sizeof(ArmLIR), true); |
| 94 | tgt->opcode = kArmPseudoThrowTarget; |
| 95 | tgt->operands[0] = kind; |
| 96 | tgt->operands[1] = mir->offset; |
| 97 | tgt->operands[2] = rIndex; |
| 98 | tgt->operands[3] = rBound; |
| 99 | opRegReg(cUnit, kOpCmp, rIndex, rBound); |
| 100 | ArmLIR* branch = genConditionalBranch(cUnit, kArmCondCs, tgt); |
| 101 | // Remember branch target - will process later |
| 102 | oatInsertGrowableList(&cUnit->throwLaunchpads, (intptr_t)tgt); |
| 103 | return branch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 104 | } |