blob: 774dffcb4306bd0625aa4af99153f6dbf5cb2ced [file] [log] [blame]
buzbeee3acd072012-02-25 17:03:10 -08001/*
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
28namespace art {
29
30/*
buzbee31a4a6f2012-02-28 15:36:15 -080031 * 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
36void oatAdjustSpillMask(CompilationUnit* cUnit)
37{
38 cUnit->coreSpillMask |= (1 << r_RA);
39 cUnit->numCoreSpills++;
40}
41
42/*
buzbeee3acd072012-02-25 17:03:10 -080043 * 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 */
buzbee31a4a6f2012-02-28 15:36:15 -080048void oatMarkPreservedSingle(CompilationUnit* cUnit, int sReg, int reg)
buzbeee3acd072012-02-25 17:03:10 -080049{
50 UNIMPLEMENTED(FATAL) << "No support yet for promoted FP regs";
buzbeee3acd072012-02-25 17:03:10 -080051}
52
53void 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
78void 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 */
91bool oatIsFpReg(int reg) {
92 return FPREG(reg);
93}
94
95uint32_t oatFpRegMask() {
96 return FP_REG_MASK;
97}
98
99/* Clobber all regs that might be used by an external C call */
100extern 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);
buzbeee3acd072012-02-25 17:03:10 -0800125 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
143extern RegLocation oatGetReturnWide(CompilationUnit* cUnit)
144{
145 RegLocation res = LOC_C_RETURN_WIDE;
buzbee5de34942012-03-01 14:51:57 -0800146 oatClobber(cUnit, res.lowReg);
147 oatClobber(cUnit, res.highReg);
148 oatMarkInUse(cUnit, res.lowReg);
149 oatMarkInUse(cUnit, res.highReg);
buzbeee3acd072012-02-25 17:03:10 -0800150 oatMarkPair(cUnit, res.lowReg, res.highReg);
151 return res;
152}
153
154extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit)
155{
156 RegLocation res = LOC_C_RETURN_WIDE_ALT;
buzbee5de34942012-03-01 14:51:57 -0800157 oatClobber(cUnit, res.lowReg);
158 oatClobber(cUnit, res.highReg);
159 oatMarkInUse(cUnit, res.lowReg);
160 oatMarkInUse(cUnit, res.highReg);
buzbeee3acd072012-02-25 17:03:10 -0800161 oatMarkPair(cUnit, res.lowReg, res.highReg);
162 return res;
163}
164
165extern RegLocation oatGetReturn(CompilationUnit* cUnit)
166{
167 RegLocation res = LOC_C_RETURN;
buzbee5de34942012-03-01 14:51:57 -0800168 oatClobber(cUnit, res.lowReg);
169 oatMarkInUse(cUnit, res.lowReg);
buzbeee3acd072012-02-25 17:03:10 -0800170 return res;
171}
172
173extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit)
174{
175 RegLocation res = LOC_C_RETURN_ALT;
buzbee5de34942012-03-01 14:51:57 -0800176 oatClobber(cUnit, res.lowReg);
177 oatMarkInUse(cUnit, res.lowReg);
buzbeee3acd072012-02-25 17:03:10 -0800178 return res;
179}
180
181extern 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 */
188extern void oatLockCallTemps(CompilationUnit* cUnit)
189{
buzbee5de34942012-03-01 14:51:57 -0800190 oatLockTemp(cUnit, rARG0);
191 oatLockTemp(cUnit, rARG1);
192 oatLockTemp(cUnit, rARG2);
193 oatLockTemp(cUnit, rARG3);
buzbeee3acd072012-02-25 17:03:10 -0800194}
195
196/* To be used when explicitly managing register use */
197extern void oatFreeCallTemps(CompilationUnit* cUnit)
198{
buzbee5de34942012-03-01 14:51:57 -0800199 oatFreeTemp(cUnit, rARG0);
200 oatFreeTemp(cUnit, rARG1);
201 oatFreeTemp(cUnit, rARG2);
202 oatFreeTemp(cUnit, rARG3);
buzbeee3acd072012-02-25 17:03:10 -0800203}
204
buzbee31a4a6f2012-02-28 15:36:15 -0800205/* Convert an instruction to a NOP */
buzbee5de34942012-03-01 14:51:57 -0800206void oatNopLIR( LIR* lir)
buzbee31a4a6f2012-02-28 15:36:15 -0800207{
buzbee5de34942012-03-01 14:51:57 -0800208 ((LIR*)lir)->flags.isNop = true;
buzbee31a4a6f2012-02-28 15:36:15 -0800209}
210
buzbeee3acd072012-02-25 17:03:10 -0800211} // namespace art