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 | /* |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 18 | * This file contains Arm-specific register allocation support. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "../../CompilerUtility.h" |
| 22 | #include "../../CompilerIR.h" |
| 23 | #include "../..//Dataflow.h" |
| 24 | #include "ArmLIR.h" |
| 25 | #include "Codegen.h" |
| 26 | #include "../Ralloc.h" |
| 27 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 28 | namespace art { |
| 29 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 30 | /* |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 31 | * TUNING: is leaf? Can't just use "hasInvoke" to determine as some |
| 32 | * instructions might call out to C/assembly helper functions. Until |
| 33 | * machinery is in place, always spill lr. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 34 | */ |
| 35 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 36 | void oatAdjustSpillMask(CompilationUnit* cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 37 | { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 38 | cUnit->coreSpillMask |= (1 << rLR); |
| 39 | cUnit->numCoreSpills++; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 43 | * Mark a callee-save fp register as promoted. Note that |
| 44 | * vpush/vpop uses contiguous register lists so we must |
| 45 | * include any holes in the mask. Associate holes with |
| 46 | * Dalvik register INVALID_VREG (0xFFFFU). |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 47 | */ |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 48 | void oatMarkPreservedSingle(CompilationUnit* cUnit, int sReg, int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 49 | { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 50 | DCHECK_GE(reg, FP_REG_MASK + FP_CALLEE_SAVE_BASE); |
| 51 | reg = (reg & FP_REG_MASK) - FP_CALLEE_SAVE_BASE; |
| 52 | // Ensure fpVmapTable is large enough |
| 53 | int tableSize = cUnit->fpVmapTable.size(); |
| 54 | for (int i = tableSize; i < (reg + 1); i++) { |
| 55 | cUnit->fpVmapTable.push_back(INVALID_VREG); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 56 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 57 | // Add the current mapping |
| 58 | cUnit->fpVmapTable[reg] = sReg; |
| 59 | // Size of fpVmapTable is high-water mark, use to set mask |
| 60 | cUnit->numFPSpills = cUnit->fpVmapTable.size(); |
| 61 | cUnit->fpSpillMask = ((1 << cUnit->numFPSpills) - 1) << FP_CALLEE_SAVE_BASE; |
| 62 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 63 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 64 | void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2) |
| 65 | { |
| 66 | RegisterInfo* info1 = oatGetRegInfo(cUnit, reg1); |
| 67 | RegisterInfo* info2 = oatGetRegInfo(cUnit, reg2); |
| 68 | DCHECK(info1 && info2 && info1->pair && info2->pair && |
| 69 | (info1->partner == info2->reg) && |
| 70 | (info2->partner == info1->reg)); |
| 71 | if ((info1->live && info1->dirty) || (info2->live && info2->dirty)) { |
| 72 | if (!(info1->isTemp && info2->isTemp)) { |
| 73 | /* Should not happen. If it does, there's a problem in evalLoc */ |
| 74 | LOG(FATAL) << "Long half-temp, half-promoted"; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 75 | } |
| 76 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 77 | info1->dirty = false; |
| 78 | info2->dirty = false; |
| 79 | if (oatS2VReg(cUnit, info2->sReg) < |
| 80 | oatS2VReg(cUnit, info1->sReg)) |
| 81 | info1 = info2; |
| 82 | int vReg = oatS2VReg(cUnit, info1->sReg); |
| 83 | oatFlushRegWideImpl(cUnit, rSP, |
| 84 | oatVRegOffset(cUnit, vReg), |
| 85 | info1->reg, info1->partner); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 86 | } |
| 87 | } |
| 88 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 89 | void oatFlushReg(CompilationUnit* cUnit, int reg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 90 | { |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 91 | RegisterInfo* info = oatGetRegInfo(cUnit, reg); |
| 92 | if (info->live && info->dirty) { |
| 93 | info->dirty = false; |
| 94 | int vReg = oatS2VReg(cUnit, info->sReg); |
| 95 | oatFlushRegImpl(cUnit, rSP, |
| 96 | oatVRegOffset(cUnit, vReg), |
| 97 | reg, kWord); |
| 98 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 99 | } |
| 100 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 101 | /* Give access to the target-dependent FP register encoding to common code */ |
| 102 | bool oatIsFpReg(int reg) { |
| 103 | return FPREG(reg); |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 104 | } |
| 105 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 106 | uint32_t oatFpRegMask() { |
| 107 | return FP_REG_MASK; |
buzbee | c41e5b5 | 2011-09-23 12:46:19 -0700 | [diff] [blame] | 108 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 109 | |
| 110 | /* Clobber all regs that might be used by an external C call */ |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 111 | void oatClobberCalleeSave(CompilationUnit *cUnit) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 112 | { |
| 113 | oatClobber(cUnit, r0); |
| 114 | oatClobber(cUnit, r1); |
| 115 | oatClobber(cUnit, r2); |
| 116 | oatClobber(cUnit, r3); |
| 117 | oatClobber(cUnit, r12); |
| 118 | oatClobber(cUnit, r14lr); |
| 119 | } |
| 120 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 121 | extern RegLocation oatGetReturnWide(CompilationUnit* cUnit) |
| 122 | { |
| 123 | RegLocation res = LOC_C_RETURN_WIDE; |
| 124 | oatClobber(cUnit, r0); |
| 125 | oatClobber(cUnit, r1); |
| 126 | oatMarkInUse(cUnit, r0); |
| 127 | oatMarkInUse(cUnit, r1); |
| 128 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 129 | return res; |
| 130 | } |
| 131 | |
| 132 | extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) |
| 133 | { |
| 134 | RegLocation res = LOC_C_RETURN_WIDE; |
| 135 | res.lowReg = r2; |
| 136 | res.highReg = r3; |
| 137 | oatClobber(cUnit, r2); |
| 138 | oatClobber(cUnit, r3); |
| 139 | oatMarkInUse(cUnit, r2); |
| 140 | oatMarkInUse(cUnit, r3); |
| 141 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 142 | return res; |
| 143 | } |
| 144 | |
| 145 | extern RegLocation oatGetReturn(CompilationUnit* cUnit) |
| 146 | { |
| 147 | RegLocation res = LOC_C_RETURN; |
| 148 | oatClobber(cUnit, r0); |
| 149 | oatMarkInUse(cUnit, r0); |
| 150 | return res; |
| 151 | } |
| 152 | |
| 153 | extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit) |
| 154 | { |
| 155 | RegLocation res = LOC_C_RETURN; |
| 156 | res.lowReg = r1; |
| 157 | oatClobber(cUnit, r1); |
| 158 | oatMarkInUse(cUnit, r1); |
| 159 | return res; |
| 160 | } |
buzbee | 6825326 | 2011-10-07 14:02:25 -0700 | [diff] [blame] | 161 | |
| 162 | extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg) |
| 163 | { |
| 164 | return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK] |
| 165 | : &cUnit->regPool->coreRegs[reg]; |
| 166 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 167 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 168 | /* To be used when explicitly managing register use */ |
| 169 | extern void oatLockCallTemps(CompilationUnit* cUnit) |
| 170 | { |
| 171 | oatLockTemp(cUnit, r0); |
| 172 | oatLockTemp(cUnit, r1); |
| 173 | oatLockTemp(cUnit, r2); |
| 174 | oatLockTemp(cUnit, r3); |
| 175 | } |
| 176 | |
| 177 | /* To be used when explicitly managing register use */ |
| 178 | extern void oatFreeCallTemps(CompilationUnit* cUnit) |
| 179 | { |
| 180 | oatFreeTemp(cUnit, r0); |
| 181 | oatFreeTemp(cUnit, r1); |
| 182 | oatFreeTemp(cUnit, r2); |
| 183 | oatFreeTemp(cUnit, r3); |
| 184 | } |
| 185 | |
| 186 | /* Convert an instruction to a NOP */ |
| 187 | STATIC void oatNopLIR( LIR* lir) |
| 188 | { |
| 189 | ((ArmLIR*)lir)->flags.isNop = true; |
| 190 | } |
| 191 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 192 | } // namespace art |