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 | |
| 39 | /* |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 40 | * Perform a "reg cmp imm" operation and jump to the PCR region if condition |
| 41 | * satisfies. |
| 42 | */ |
| 43 | static TGT_LIR* genRegImmCheck(CompilationUnit* cUnit, |
| 44 | ArmConditionCode cond, int reg, |
| 45 | int checkValue, int dOffset, |
| 46 | TGT_LIR* pcrLabel) |
| 47 | { |
| 48 | TGT_LIR* branch = genCmpImmBranch(cUnit, cond, reg, checkValue); |
| 49 | BasicBlock* bb = cUnit->curBlock; |
| 50 | if (bb->taken) { |
| 51 | ArmLIR *exceptionLabel = (ArmLIR* ) cUnit->blockLabelList; |
| 52 | exceptionLabel += bb->taken->id; |
| 53 | branch->generic.target = (LIR* ) exceptionLabel; |
| 54 | return exceptionLabel; |
| 55 | } else { |
| 56 | LOG(FATAL) << "Catch blocks not handled yet"; |
| 57 | return NULL; // quiet gcc |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* |
| 62 | * Perform null-check on a register. sReg is the ssa register being checked, |
| 63 | * and mReg is the machine register holding the actual value. If internal state |
| 64 | * indicates that sReg has been checked before the check request is ignored. |
| 65 | */ |
| 66 | static TGT_LIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, |
| 67 | int dOffset, TGT_LIR* pcrLabel) |
| 68 | { |
| 69 | /* This particular Dalvik register has been null-checked */ |
buzbee | 7b1b86d | 2011-08-26 18:59:10 -0700 | [diff] [blame] | 70 | UNIMPLEMENTED(WARNING) << "Need null check & throw support"; |
| 71 | return pcrLabel; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 72 | if (oatIsBitSet(cUnit->regPool->nullCheckedRegs, sReg)) { |
| 73 | return pcrLabel; |
| 74 | } |
| 75 | oatSetBit(cUnit->regPool->nullCheckedRegs, sReg); |
| 76 | return genRegImmCheck(cUnit, kArmCondEq, mReg, 0, dOffset, pcrLabel); |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Perform a "reg cmp reg" operation and jump to the PCR region if condition |
| 81 | * satisfies. |
| 82 | */ |
| 83 | static TGT_LIR* genRegRegCheck(CompilationUnit* cUnit, |
| 84 | ArmConditionCode cond, |
| 85 | int reg1, int reg2, int dOffset, |
| 86 | TGT_LIR* pcrLabel) |
| 87 | { |
| 88 | TGT_LIR* res; |
| 89 | res = opRegReg(cUnit, kOpCmp, reg1, reg2); |
| 90 | TGT_LIR* branch = opCondBranch(cUnit, cond); |
| 91 | genCheckCommon(cUnit, dOffset, branch, pcrLabel); |
| 92 | return res; |
| 93 | } |
| 94 | |
| 95 | /* Perform bound check on two registers */ |
| 96 | static TGT_LIR* genBoundsCheck(CompilationUnit* cUnit, int rIndex, |
| 97 | int rBound, int dOffset, TGT_LIR* pcrLabel) |
| 98 | { |
| 99 | return genRegRegCheck(cUnit, kArmCondCs, rIndex, rBound, dOffset, |
| 100 | pcrLabel); |
| 101 | } |