blob: a020687210cb389fdc2458387ac223b2acc99d0a [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
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 Hughes11d1b0c2012-01-23 16:57:47 -080018 * This file contains Arm-specific register allocation support.
buzbee67bf8852011-08-17 17:51:35 -070019 */
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 Hughes11d1b0c2012-01-23 16:57:47 -080028namespace art {
29
buzbee67bf8852011-08-17 17:51:35 -070030/*
buzbeee3acd072012-02-25 17:03:10 -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.
buzbee67bf8852011-08-17 17:51:35 -070034 */
35
buzbeee3acd072012-02-25 17:03:10 -080036void oatAdjustSpillMask(CompilationUnit* cUnit)
buzbee67bf8852011-08-17 17:51:35 -070037{
buzbeee3acd072012-02-25 17:03:10 -080038 cUnit->coreSpillMask |= (1 << rLR);
39 cUnit->numCoreSpills++;
buzbee67bf8852011-08-17 17:51:35 -070040}
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).
buzbee67bf8852011-08-17 17:51:35 -070047 */
buzbeee3acd072012-02-25 17:03:10 -080048void oatMarkPreservedSingle(CompilationUnit* cUnit, int sReg, int reg)
buzbee67bf8852011-08-17 17:51:35 -070049{
buzbeee3acd072012-02-25 17:03:10 -080050 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);
buzbee67bf8852011-08-17 17:51:35 -070056 }
buzbeee3acd072012-02-25 17:03:10 -080057 // 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}
buzbee67bf8852011-08-17 17:51:35 -070063
buzbeee3acd072012-02-25 17:03:10 -080064void 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";
buzbee67bf8852011-08-17 17:51:35 -070075 }
76
buzbeee3acd072012-02-25 17:03:10 -080077 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);
buzbee67bf8852011-08-17 17:51:35 -070086 }
87}
88
buzbeee3acd072012-02-25 17:03:10 -080089void oatFlushReg(CompilationUnit* cUnit, int reg)
buzbee67bf8852011-08-17 17:51:35 -070090{
buzbeee3acd072012-02-25 17:03:10 -080091 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 }
buzbee67bf8852011-08-17 17:51:35 -070099}
100
buzbeee3acd072012-02-25 17:03:10 -0800101/* Give access to the target-dependent FP register encoding to common code */
102bool oatIsFpReg(int reg) {
103 return FPREG(reg);
buzbee67bc2362011-10-11 18:08:40 -0700104}
105
buzbeee3acd072012-02-25 17:03:10 -0800106uint32_t oatFpRegMask() {
107 return FP_REG_MASK;
buzbeec41e5b52011-09-23 12:46:19 -0700108}
buzbee67bf8852011-08-17 17:51:35 -0700109
110/* Clobber all regs that might be used by an external C call */
buzbeee3acd072012-02-25 17:03:10 -0800111void oatClobberCalleeSave(CompilationUnit *cUnit)
buzbee67bf8852011-08-17 17:51:35 -0700112{
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
buzbee67bf8852011-08-17 17:51:35 -0700121extern 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
132extern 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
145extern RegLocation oatGetReturn(CompilationUnit* cUnit)
146{
147 RegLocation res = LOC_C_RETURN;
148 oatClobber(cUnit, r0);
149 oatMarkInUse(cUnit, r0);
150 return res;
151}
152
153extern 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}
buzbee68253262011-10-07 14:02:25 -0700161
162extern 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 Hughes11d1b0c2012-01-23 16:57:47 -0800167
buzbeee3acd072012-02-25 17:03:10 -0800168/* To be used when explicitly managing register use */
169extern 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 */
178extern 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 */
buzbee31a4a6f2012-02-28 15:36:15 -0800187void oatNopLIR( LIR* lir)
buzbeee3acd072012-02-25 17:03:10 -0800188{
buzbee31a4a6f2012-02-28 15:36:15 -0800189 ((LIR*)lir)->flags.isNop = true;
buzbeee3acd072012-02-25 17:03:10 -0800190}
191
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800192} // namespace art