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 | |
| 25 | /* |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 26 | * Utiltiy to load the current Method*. Broken out |
| 27 | * to allow easy change between placing the current Method* in a |
| 28 | * dedicated register or its home location in the frame. |
| 29 | */ |
| 30 | static void loadCurrMethodDirect(CompilationUnit *cUnit, int rTgt) |
| 31 | { |
| 32 | #if defined(METHOD_IN_REG) |
| 33 | genRegCopy(cUnit, rTgt, rMETHOD); |
| 34 | #else |
| 35 | loadWordDisp(cUnit, rSP, 0, rTgt); |
| 36 | #endif |
| 37 | } |
| 38 | |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 39 | static int loadCurrMethod(CompilationUnit *cUnit) |
| 40 | { |
| 41 | #if defined(METHOD_IN_REG) |
| 42 | return rMETHOD; |
| 43 | #else |
| 44 | int mReg = oatAllocTemp(cUnit); |
| 45 | loadCurrMethodDirect(cUnit, mReg); |
| 46 | return mReg; |
| 47 | #endif |
| 48 | } |
| 49 | |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 50 | /* |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 51 | * Perform a "reg cmp imm" operation and jump to the PCR region if condition |
| 52 | * satisfies. |
| 53 | */ |
| 54 | static TGT_LIR* genRegImmCheck(CompilationUnit* cUnit, |
| 55 | ArmConditionCode cond, int reg, |
| 56 | int checkValue, int dOffset, |
| 57 | TGT_LIR* pcrLabel) |
| 58 | { |
| 59 | TGT_LIR* branch = genCmpImmBranch(cUnit, cond, reg, checkValue); |
| 60 | BasicBlock* bb = cUnit->curBlock; |
| 61 | if (bb->taken) { |
| 62 | ArmLIR *exceptionLabel = (ArmLIR* ) cUnit->blockLabelList; |
| 63 | exceptionLabel += bb->taken->id; |
| 64 | branch->generic.target = (LIR* ) exceptionLabel; |
| 65 | return exceptionLabel; |
| 66 | } else { |
| 67 | LOG(FATAL) << "Catch blocks not handled yet"; |
| 68 | return NULL; // quiet gcc |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /* |
| 73 | * Perform null-check on a register. sReg is the ssa register being checked, |
| 74 | * and mReg is the machine register holding the actual value. If internal state |
| 75 | * indicates that sReg has been checked before the check request is ignored. |
| 76 | */ |
| 77 | static TGT_LIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, |
| 78 | int dOffset, TGT_LIR* pcrLabel) |
| 79 | { |
| 80 | /* This particular Dalvik register has been null-checked */ |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 81 | UNIMPLEMENTED(WARNING) << "Need null check & throw support"; |
| 82 | return pcrLabel; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 83 | if (oatIsBitSet(cUnit->regPool->nullCheckedRegs, sReg)) { |
| 84 | return pcrLabel; |
| 85 | } |
| 86 | oatSetBit(cUnit->regPool->nullCheckedRegs, sReg); |
| 87 | return genRegImmCheck(cUnit, kArmCondEq, mReg, 0, dOffset, pcrLabel); |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Perform a "reg cmp reg" operation and jump to the PCR region if condition |
| 92 | * satisfies. |
| 93 | */ |
| 94 | static TGT_LIR* genRegRegCheck(CompilationUnit* cUnit, |
| 95 | ArmConditionCode cond, |
| 96 | int reg1, int reg2, int dOffset, |
| 97 | TGT_LIR* pcrLabel) |
| 98 | { |
| 99 | TGT_LIR* res; |
| 100 | res = opRegReg(cUnit, kOpCmp, reg1, reg2); |
| 101 | TGT_LIR* branch = opCondBranch(cUnit, cond); |
| 102 | genCheckCommon(cUnit, dOffset, branch, pcrLabel); |
| 103 | return res; |
| 104 | } |
| 105 | |
| 106 | /* Perform bound check on two registers */ |
| 107 | static TGT_LIR* genBoundsCheck(CompilationUnit* cUnit, int rIndex, |
| 108 | int rBound, int dOffset, TGT_LIR* pcrLabel) |
| 109 | { |
| 110 | return genRegRegCheck(cUnit, kArmCondCs, rIndex, rBound, dOffset, |
| 111 | pcrLabel); |
| 112 | } |