blob: 3335f5997ea996be2ebc5ec126cdff33b487c2fa [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);
buzbee5de34942012-03-01 14:51:57 -0800119 oatClobber(cUnit, fr0);
120 oatClobber(cUnit, fr1);
121 oatClobber(cUnit, fr2);
122 oatClobber(cUnit, fr3);
123 oatClobber(cUnit, fr4);
124 oatClobber(cUnit, fr5);
125 oatClobber(cUnit, fr6);
126 oatClobber(cUnit, fr7);
127 oatClobber(cUnit, fr8);
128 oatClobber(cUnit, fr9);
129 oatClobber(cUnit, fr10);
130 oatClobber(cUnit, fr11);
131 oatClobber(cUnit, fr12);
132 oatClobber(cUnit, fr13);
133 oatClobber(cUnit, fr14);
134 oatClobber(cUnit, fr15);
buzbee67bf8852011-08-17 17:51:35 -0700135}
136
buzbee67bf8852011-08-17 17:51:35 -0700137extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit)
138{
139 RegLocation res = LOC_C_RETURN_WIDE;
140 res.lowReg = r2;
141 res.highReg = r3;
142 oatClobber(cUnit, r2);
143 oatClobber(cUnit, r3);
144 oatMarkInUse(cUnit, r2);
145 oatMarkInUse(cUnit, r3);
146 oatMarkPair(cUnit, res.lowReg, res.highReg);
147 return res;
148}
149
buzbee67bf8852011-08-17 17:51:35 -0700150extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit)
151{
152 RegLocation res = LOC_C_RETURN;
153 res.lowReg = r1;
154 oatClobber(cUnit, r1);
155 oatMarkInUse(cUnit, r1);
156 return res;
157}
buzbee68253262011-10-07 14:02:25 -0700158
159extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg)
160{
161 return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK]
162 : &cUnit->regPool->coreRegs[reg];
163}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800164
buzbeee3acd072012-02-25 17:03:10 -0800165/* To be used when explicitly managing register use */
166extern void oatLockCallTemps(CompilationUnit* cUnit)
167{
168 oatLockTemp(cUnit, r0);
169 oatLockTemp(cUnit, r1);
170 oatLockTemp(cUnit, r2);
171 oatLockTemp(cUnit, r3);
172}
173
174/* To be used when explicitly managing register use */
175extern void oatFreeCallTemps(CompilationUnit* cUnit)
176{
177 oatFreeTemp(cUnit, r0);
178 oatFreeTemp(cUnit, r1);
179 oatFreeTemp(cUnit, r2);
180 oatFreeTemp(cUnit, r3);
181}
182
183/* Convert an instruction to a NOP */
buzbee31a4a6f2012-02-28 15:36:15 -0800184void oatNopLIR( LIR* lir)
buzbeee3acd072012-02-25 17:03:10 -0800185{
buzbee31a4a6f2012-02-28 15:36:15 -0800186 ((LIR*)lir)->flags.isNop = true;
buzbeee3acd072012-02-25 17:03:10 -0800187}
188
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800189} // namespace art