buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 Mips-specific register allocation support. |
| 19 | */ |
| 20 | |
| 21 | #include "../../CompilerUtility.h" |
| 22 | #include "../../CompilerIR.h" |
| 23 | #include "../..//Dataflow.h" |
| 24 | #include "MipsLIR.h" |
| 25 | #include "Codegen.h" |
| 26 | #include "../Ralloc.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
| 30 | /* |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -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. |
| 34 | */ |
| 35 | |
| 36 | void oatAdjustSpillMask(CompilationUnit* cUnit) |
| 37 | { |
| 38 | cUnit->coreSpillMask |= (1 << r_RA); |
| 39 | cUnit->numCoreSpills++; |
| 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). |
| 47 | */ |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 48 | void oatMarkPreservedSingle(CompilationUnit* cUnit, int sReg, int reg) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 49 | { |
| 50 | UNIMPLEMENTED(FATAL) << "No support yet for promoted FP regs"; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2) |
| 54 | { |
| 55 | RegisterInfo* info1 = oatGetRegInfo(cUnit, reg1); |
| 56 | RegisterInfo* info2 = oatGetRegInfo(cUnit, reg2); |
| 57 | DCHECK(info1 && info2 && info1->pair && info2->pair && |
| 58 | (info1->partner == info2->reg) && |
| 59 | (info2->partner == info1->reg)); |
| 60 | if ((info1->live && info1->dirty) || (info2->live && info2->dirty)) { |
| 61 | if (!(info1->isTemp && info2->isTemp)) { |
| 62 | /* Should not happen. If it does, there's a problem in evalLoc */ |
| 63 | LOG(FATAL) << "Long half-temp, half-promoted"; |
| 64 | } |
| 65 | |
| 66 | info1->dirty = false; |
| 67 | info2->dirty = false; |
| 68 | if (oatS2VReg(cUnit, info2->sReg) < |
| 69 | oatS2VReg(cUnit, info1->sReg)) |
| 70 | info1 = info2; |
| 71 | int vReg = oatS2VReg(cUnit, info1->sReg); |
| 72 | oatFlushRegWideImpl(cUnit, rSP, |
| 73 | oatVRegOffset(cUnit, vReg), |
| 74 | info1->reg, info1->partner); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | void oatFlushReg(CompilationUnit* cUnit, int reg) |
| 79 | { |
| 80 | RegisterInfo* info = oatGetRegInfo(cUnit, reg); |
| 81 | if (info->live && info->dirty) { |
| 82 | info->dirty = false; |
| 83 | int vReg = oatS2VReg(cUnit, info->sReg); |
| 84 | oatFlushRegImpl(cUnit, rSP, |
| 85 | oatVRegOffset(cUnit, vReg), |
| 86 | reg, kWord); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | /* Give access to the target-dependent FP register encoding to common code */ |
| 91 | bool oatIsFpReg(int reg) { |
| 92 | return FPREG(reg); |
| 93 | } |
| 94 | |
| 95 | uint32_t oatFpRegMask() { |
| 96 | return FP_REG_MASK; |
| 97 | } |
| 98 | |
| 99 | /* Clobber all regs that might be used by an external C call */ |
| 100 | extern void oatClobberCalleeSave(CompilationUnit *cUnit) |
| 101 | { |
| 102 | oatClobber(cUnit, r_ZERO); |
| 103 | oatClobber(cUnit, r_AT); |
| 104 | oatClobber(cUnit, r_V0); |
| 105 | oatClobber(cUnit, r_V1); |
| 106 | oatClobber(cUnit, r_A0); |
| 107 | oatClobber(cUnit, r_A1); |
| 108 | oatClobber(cUnit, r_A2); |
| 109 | oatClobber(cUnit, r_A3); |
| 110 | oatClobber(cUnit, r_T0); |
| 111 | oatClobber(cUnit, r_T1); |
| 112 | oatClobber(cUnit, r_T2); |
| 113 | oatClobber(cUnit, r_T3); |
| 114 | oatClobber(cUnit, r_T4); |
| 115 | oatClobber(cUnit, r_T5); |
| 116 | oatClobber(cUnit, r_T6); |
| 117 | oatClobber(cUnit, r_T7); |
| 118 | oatClobber(cUnit, r_T8); |
| 119 | oatClobber(cUnit, r_T9); |
| 120 | oatClobber(cUnit, r_K0); |
| 121 | oatClobber(cUnit, r_K1); |
| 122 | oatClobber(cUnit, r_GP); |
| 123 | oatClobber(cUnit, r_FP); |
| 124 | oatClobber(cUnit, r_RA); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 125 | oatClobber(cUnit, r_F0); |
| 126 | oatClobber(cUnit, r_F1); |
| 127 | oatClobber(cUnit, r_F2); |
| 128 | oatClobber(cUnit, r_F3); |
| 129 | oatClobber(cUnit, r_F4); |
| 130 | oatClobber(cUnit, r_F5); |
| 131 | oatClobber(cUnit, r_F6); |
| 132 | oatClobber(cUnit, r_F7); |
| 133 | oatClobber(cUnit, r_F8); |
| 134 | oatClobber(cUnit, r_F9); |
| 135 | oatClobber(cUnit, r_F10); |
| 136 | oatClobber(cUnit, r_F11); |
| 137 | oatClobber(cUnit, r_F12); |
| 138 | oatClobber(cUnit, r_F13); |
| 139 | oatClobber(cUnit, r_F14); |
| 140 | oatClobber(cUnit, r_F15); |
| 141 | } |
| 142 | |
| 143 | extern RegLocation oatGetReturnWide(CompilationUnit* cUnit) |
| 144 | { |
| 145 | RegLocation res = LOC_C_RETURN_WIDE; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 146 | oatClobber(cUnit, res.lowReg); |
| 147 | oatClobber(cUnit, res.highReg); |
| 148 | oatMarkInUse(cUnit, res.lowReg); |
| 149 | oatMarkInUse(cUnit, res.highReg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 150 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 151 | return res; |
| 152 | } |
| 153 | |
| 154 | extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) |
| 155 | { |
| 156 | RegLocation res = LOC_C_RETURN_WIDE_ALT; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 157 | oatClobber(cUnit, res.lowReg); |
| 158 | oatClobber(cUnit, res.highReg); |
| 159 | oatMarkInUse(cUnit, res.lowReg); |
| 160 | oatMarkInUse(cUnit, res.highReg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 161 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 162 | return res; |
| 163 | } |
| 164 | |
| 165 | extern RegLocation oatGetReturn(CompilationUnit* cUnit) |
| 166 | { |
| 167 | RegLocation res = LOC_C_RETURN; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 168 | oatClobber(cUnit, res.lowReg); |
| 169 | oatMarkInUse(cUnit, res.lowReg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 170 | return res; |
| 171 | } |
| 172 | |
| 173 | extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit) |
| 174 | { |
| 175 | RegLocation res = LOC_C_RETURN_ALT; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 176 | oatClobber(cUnit, res.lowReg); |
| 177 | oatMarkInUse(cUnit, res.lowReg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 178 | return res; |
| 179 | } |
| 180 | |
| 181 | extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg) |
| 182 | { |
| 183 | return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK] |
| 184 | : &cUnit->regPool->coreRegs[reg]; |
| 185 | } |
| 186 | |
| 187 | /* To be used when explicitly managing register use */ |
| 188 | extern void oatLockCallTemps(CompilationUnit* cUnit) |
| 189 | { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 190 | oatLockTemp(cUnit, rARG0); |
| 191 | oatLockTemp(cUnit, rARG1); |
| 192 | oatLockTemp(cUnit, rARG2); |
| 193 | oatLockTemp(cUnit, rARG3); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | /* To be used when explicitly managing register use */ |
| 197 | extern void oatFreeCallTemps(CompilationUnit* cUnit) |
| 198 | { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 199 | oatFreeTemp(cUnit, rARG0); |
| 200 | oatFreeTemp(cUnit, rARG1); |
| 201 | oatFreeTemp(cUnit, rARG2); |
| 202 | oatFreeTemp(cUnit, rARG3); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 203 | } |
| 204 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 205 | /* Convert an instruction to a NOP */ |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 206 | void oatNopLIR( LIR* lir) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 207 | { |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 208 | ((LIR*)lir)->flags.isNop = true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 209 | } |
| 210 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 211 | } // namespace art |