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 | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 25 | STATIC ArmLIR* genUnconditionalBranch(CompilationUnit*, ArmLIR*); |
| 26 | STATIC ArmLIR* genConditionalBranch(CompilationUnit*, ArmConditionCode, |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 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 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 34 | STATIC void loadCurrMethodDirect(CompilationUnit *cUnit, int rTgt) |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 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 | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 43 | STATIC int loadCurrMethod(CompilationUnit *cUnit) |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 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 | 58f9274 | 2011-10-01 11:22:17 -0700 | [diff] [blame] | 54 | STATIC ArmLIR* genCheck(CompilationUnit* cUnit, ArmConditionCode cCode, |
| 55 | MIR* mir, ArmThrowKind kind) |
| 56 | { |
| 57 | ArmLIR* tgt = (ArmLIR*)oatNew(sizeof(ArmLIR), true); |
| 58 | tgt->opcode = kArmPseudoThrowTarget; |
| 59 | tgt->operands[0] = kind; |
| 60 | tgt->operands[1] = mir ? mir->offset : 0; |
| 61 | ArmLIR* branch = genConditionalBranch(cUnit, cCode, tgt); |
| 62 | // Remember branch target - will process later |
| 63 | oatInsertGrowableList(&cUnit->throwLaunchpads, (intptr_t)tgt); |
| 64 | return branch; |
| 65 | } |
| 66 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 67 | STATIC ArmLIR* genImmedCheck(CompilationUnit* cUnit, ArmConditionCode cCode, |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 68 | int reg, int immVal, MIR* mir, ArmThrowKind kind) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 69 | { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 70 | ArmLIR* tgt = (ArmLIR*)oatNew(sizeof(ArmLIR), true); |
| 71 | tgt->opcode = kArmPseudoThrowTarget; |
| 72 | tgt->operands[0] = kind; |
| 73 | tgt->operands[1] = mir->offset; |
| 74 | ArmLIR* branch; |
| 75 | if (cCode == kArmCondAl) { |
| 76 | branch = genUnconditionalBranch(cUnit, tgt); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 77 | } else { |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 78 | branch = genCmpImmBranch(cUnit, cCode, reg, immVal); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 79 | branch->generic.target = (LIR*)tgt; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 80 | } |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 81 | // Remember branch target - will process later |
| 82 | oatInsertGrowableList(&cUnit->throwLaunchpads, (intptr_t)tgt); |
| 83 | return branch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 84 | } |
| 85 | |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 86 | /* Perform null-check on a register. */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 87 | STATIC ArmLIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 88 | MIR* mir) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 89 | { |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 90 | if (!(cUnit->disableOpt & (1 << kNullCheckElimination)) && |
| 91 | mir->optimizationFlags & MIR_IGNORE_NULL_CHECK) { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 92 | return NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 93 | } |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 94 | return genImmedCheck(cUnit, kArmCondEq, mReg, 0, mir, kArmThrowNullPointer); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 95 | } |
| 96 | |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 97 | /* Perform check on two registers */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 98 | STATIC TGT_LIR* genRegRegCheck(CompilationUnit* cUnit, ArmConditionCode cCode, |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 99 | int reg1, int reg2, MIR* mir, ArmThrowKind kind) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 100 | { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 101 | ArmLIR* tgt = (ArmLIR*)oatNew(sizeof(ArmLIR), true); |
| 102 | tgt->opcode = kArmPseudoThrowTarget; |
| 103 | tgt->operands[0] = kind; |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 104 | tgt->operands[1] = mir ? mir->offset : 0; |
| 105 | tgt->operands[2] = reg1; |
| 106 | tgt->operands[3] = reg2; |
| 107 | opRegReg(cUnit, kOpCmp, reg1, reg2); |
| 108 | ArmLIR* branch = genConditionalBranch(cUnit, cCode, tgt); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 109 | // Remember branch target - will process later |
| 110 | oatInsertGrowableList(&cUnit->throwLaunchpads, (intptr_t)tgt); |
| 111 | return branch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 112 | } |