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 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 25 | namespace art { |
| 26 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 27 | STATIC ArmLIR* genUnconditionalBranch(CompilationUnit*, ArmLIR*); |
| 28 | STATIC ArmLIR* genConditionalBranch(CompilationUnit*, ArmConditionCode, |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 29 | ArmLIR*); |
| 30 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 31 | /* |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 32 | * Utiltiy to load the current Method*. Broken out |
| 33 | * to allow easy change between placing the current Method* in a |
| 34 | * dedicated register or its home location in the frame. |
| 35 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 36 | STATIC void loadCurrMethodDirect(CompilationUnit *cUnit, int rTgt) |
buzbee | dfd3d70 | 2011-08-28 12:56:51 -0700 | [diff] [blame] | 37 | { |
| 38 | #if defined(METHOD_IN_REG) |
| 39 | genRegCopy(cUnit, rTgt, rMETHOD); |
| 40 | #else |
| 41 | loadWordDisp(cUnit, rSP, 0, rTgt); |
| 42 | #endif |
| 43 | } |
| 44 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 45 | STATIC int loadCurrMethod(CompilationUnit *cUnit) |
buzbee | 1b4c859 | 2011-08-31 10:43:51 -0700 | [diff] [blame] | 46 | { |
| 47 | #if defined(METHOD_IN_REG) |
| 48 | return rMETHOD; |
| 49 | #else |
| 50 | int mReg = oatAllocTemp(cUnit); |
| 51 | loadCurrMethodDirect(cUnit, mReg); |
| 52 | return mReg; |
| 53 | #endif |
| 54 | } |
| 55 | |
buzbee | 58f9274 | 2011-10-01 11:22:17 -0700 | [diff] [blame] | 56 | STATIC ArmLIR* genCheck(CompilationUnit* cUnit, ArmConditionCode cCode, |
| 57 | MIR* mir, ArmThrowKind kind) |
| 58 | { |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 59 | ArmLIR* tgt = (ArmLIR*)oatNew(cUnit, sizeof(ArmLIR), true, kAllocLIR); |
buzbee | 58f9274 | 2011-10-01 11:22:17 -0700 | [diff] [blame] | 60 | tgt->opcode = kArmPseudoThrowTarget; |
| 61 | tgt->operands[0] = kind; |
| 62 | tgt->operands[1] = mir ? mir->offset : 0; |
| 63 | ArmLIR* branch = genConditionalBranch(cUnit, cCode, tgt); |
| 64 | // Remember branch target - will process later |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 65 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
buzbee | 58f9274 | 2011-10-01 11:22:17 -0700 | [diff] [blame] | 66 | return branch; |
| 67 | } |
| 68 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 69 | STATIC ArmLIR* genImmedCheck(CompilationUnit* cUnit, ArmConditionCode cCode, |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 70 | int reg, int immVal, MIR* mir, ArmThrowKind kind) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 71 | { |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 72 | ArmLIR* tgt = (ArmLIR*)oatNew(cUnit, sizeof(ArmLIR), true, kAllocLIR); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 73 | tgt->opcode = kArmPseudoThrowTarget; |
| 74 | tgt->operands[0] = kind; |
| 75 | tgt->operands[1] = mir->offset; |
| 76 | ArmLIR* branch; |
| 77 | if (cCode == kArmCondAl) { |
| 78 | branch = genUnconditionalBranch(cUnit, tgt); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 79 | } else { |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 80 | branch = genCmpImmBranch(cUnit, cCode, reg, immVal); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 81 | branch->generic.target = (LIR*)tgt; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 82 | } |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 83 | // Remember branch target - will process later |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 84 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 85 | return branch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 86 | } |
| 87 | |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 88 | /* Perform null-check on a register. */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 89 | STATIC ArmLIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 90 | MIR* mir) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 91 | { |
buzbee | 43a3642 | 2011-09-14 14:00:13 -0700 | [diff] [blame] | 92 | if (!(cUnit->disableOpt & (1 << kNullCheckElimination)) && |
| 93 | mir->optimizationFlags & MIR_IGNORE_NULL_CHECK) { |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 94 | return NULL; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 95 | } |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 96 | return genImmedCheck(cUnit, kArmCondEq, mReg, 0, mir, kArmThrowNullPointer); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 97 | } |
| 98 | |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 99 | /* Perform check on two registers */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 100 | STATIC TGT_LIR* genRegRegCheck(CompilationUnit* cUnit, ArmConditionCode cCode, |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 101 | int reg1, int reg2, MIR* mir, ArmThrowKind kind) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 102 | { |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 103 | ArmLIR* tgt = (ArmLIR*)oatNew(cUnit, sizeof(ArmLIR), true, kAllocLIR); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 104 | tgt->opcode = kArmPseudoThrowTarget; |
| 105 | tgt->operands[0] = kind; |
buzbee | ec5adf3 | 2011-09-11 15:25:43 -0700 | [diff] [blame] | 106 | tgt->operands[1] = mir ? mir->offset : 0; |
| 107 | tgt->operands[2] = reg1; |
| 108 | tgt->operands[3] = reg2; |
| 109 | opRegReg(cUnit, kOpCmp, reg1, reg2); |
| 110 | ArmLIR* branch = genConditionalBranch(cUnit, cCode, tgt); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 111 | // Remember branch target - will process later |
buzbee | ba938cb | 2012-02-03 14:47:55 -0800 | [diff] [blame] | 112 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
buzbee | 5ade1d2 | 2011-09-09 14:44:52 -0700 | [diff] [blame] | 113 | return branch; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 114 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 115 | |
| 116 | } // namespace art |