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 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 38 | cUnit->coreSpillMask |= (1 << r_RA); |
| 39 | cUnit->numCoreSpills++; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [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). |
| 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 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 50 | LOG(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 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 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"; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 64 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 65 | |
| 66 | info1->dirty = false; |
| 67 | info2->dirty = false; |
| 68 | if (SRegToVReg(cUnit, info2->sReg) < SRegToVReg(cUnit, info1->sReg)) |
| 69 | info1 = info2; |
| 70 | int vReg = SRegToVReg(cUnit, info1->sReg); |
| 71 | oatFlushRegWideImpl(cUnit, rSP, oatVRegOffset(cUnit, vReg), info1->reg, |
| 72 | info1->partner); |
| 73 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void oatFlushReg(CompilationUnit* cUnit, int reg) |
| 77 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 78 | RegisterInfo* info = oatGetRegInfo(cUnit, reg); |
| 79 | if (info->live && info->dirty) { |
| 80 | info->dirty = false; |
| 81 | int vReg = SRegToVReg(cUnit, info->sReg); |
| 82 | oatFlushRegImpl(cUnit, rSP, oatVRegOffset(cUnit, vReg), reg, kWord); |
| 83 | } |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /* Give access to the target-dependent FP register encoding to common code */ |
| 87 | bool oatIsFpReg(int reg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 88 | return FPREG(reg); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | uint32_t oatFpRegMask() { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 92 | return FP_REG_MASK; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /* Clobber all regs that might be used by an external C call */ |
| 96 | extern void oatClobberCalleeSave(CompilationUnit *cUnit) |
| 97 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 98 | oatClobber(cUnit, r_ZERO); |
| 99 | oatClobber(cUnit, r_AT); |
| 100 | oatClobber(cUnit, r_V0); |
| 101 | oatClobber(cUnit, r_V1); |
| 102 | oatClobber(cUnit, r_A0); |
| 103 | oatClobber(cUnit, r_A1); |
| 104 | oatClobber(cUnit, r_A2); |
| 105 | oatClobber(cUnit, r_A3); |
| 106 | oatClobber(cUnit, r_T0); |
| 107 | oatClobber(cUnit, r_T1); |
| 108 | oatClobber(cUnit, r_T2); |
| 109 | oatClobber(cUnit, r_T3); |
| 110 | oatClobber(cUnit, r_T4); |
| 111 | oatClobber(cUnit, r_T5); |
| 112 | oatClobber(cUnit, r_T6); |
| 113 | oatClobber(cUnit, r_T7); |
| 114 | oatClobber(cUnit, r_T8); |
| 115 | oatClobber(cUnit, r_T9); |
| 116 | oatClobber(cUnit, r_K0); |
| 117 | oatClobber(cUnit, r_K1); |
| 118 | oatClobber(cUnit, r_GP); |
| 119 | oatClobber(cUnit, r_FP); |
| 120 | oatClobber(cUnit, r_RA); |
| 121 | oatClobber(cUnit, r_F0); |
| 122 | oatClobber(cUnit, r_F1); |
| 123 | oatClobber(cUnit, r_F2); |
| 124 | oatClobber(cUnit, r_F3); |
| 125 | oatClobber(cUnit, r_F4); |
| 126 | oatClobber(cUnit, r_F5); |
| 127 | oatClobber(cUnit, r_F6); |
| 128 | oatClobber(cUnit, r_F7); |
| 129 | oatClobber(cUnit, r_F8); |
| 130 | oatClobber(cUnit, r_F9); |
| 131 | oatClobber(cUnit, r_F10); |
| 132 | oatClobber(cUnit, r_F11); |
| 133 | oatClobber(cUnit, r_F12); |
| 134 | oatClobber(cUnit, r_F13); |
| 135 | oatClobber(cUnit, r_F14); |
| 136 | oatClobber(cUnit, r_F15); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 137 | } |
| 138 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 139 | extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) |
| 140 | { |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 141 | UNIMPLEMENTED(FATAL) << "No oatGetReturnWideAlt for MIPS"; |
| 142 | RegLocation res = LOC_C_RETURN_WIDE; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 143 | return res; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 144 | } |
| 145 | |
Elliott Hughes | e7825db | 2012-03-09 15:46:57 -0800 | [diff] [blame] | 146 | extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit) |
| 147 | { |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 148 | UNIMPLEMENTED(FATAL) << "No oatGetReturnAlt for MIPS"; |
| 149 | RegLocation res = LOC_C_RETURN; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 150 | return res; |
Elliott Hughes | e7825db | 2012-03-09 15:46:57 -0800 | [diff] [blame] | 151 | } |
| 152 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 153 | extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg) |
| 154 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 155 | return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK] |
| 156 | : &cUnit->regPool->coreRegs[reg]; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /* To be used when explicitly managing register use */ |
| 160 | extern void oatLockCallTemps(CompilationUnit* cUnit) |
| 161 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 162 | oatLockTemp(cUnit, rARG0); |
| 163 | oatLockTemp(cUnit, rARG1); |
| 164 | oatLockTemp(cUnit, rARG2); |
| 165 | oatLockTemp(cUnit, rARG3); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | /* To be used when explicitly managing register use */ |
| 169 | extern void oatFreeCallTemps(CompilationUnit* cUnit) |
| 170 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 171 | oatFreeTemp(cUnit, rARG0); |
| 172 | oatFreeTemp(cUnit, rARG1); |
| 173 | oatFreeTemp(cUnit, rARG2); |
| 174 | oatFreeTemp(cUnit, rARG3); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 175 | } |
| 176 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 177 | /* Convert an instruction to a NOP */ |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 178 | void oatNopLIR( LIR* lir) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 179 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 180 | ((LIR*)lir)->flags.isNop = true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 181 | } |
| 182 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 183 | } // namespace art |