blob: cdd75a19c1e237ae3b0f4aef3b9afd8968c73b51 [file] [log] [blame]
buzbeee88dfbf2012-03-05 11:19:57 -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/*
buzbeea7678db2012-03-05 15:35:46 -080018 * This file contains X86-specific register allocation support.
buzbeee88dfbf2012-03-05 11:19:57 -080019 */
20
21#include "../../CompilerUtility.h"
22#include "../../CompilerIR.h"
23#include "../..//Dataflow.h"
buzbeea7678db2012-03-05 15:35:46 -080024#include "X86LIR.h"
buzbeee88dfbf2012-03-05 11:19:57 -080025#include "Codegen.h"
26#include "../Ralloc.h"
27
28namespace art {
29
30/*
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
36void oatAdjustSpillMask(CompilationUnit* cUnit)
37{
38 UNIMPLEMENTED(WARNING) << "oatAdjustSpillMask";
39#if 0
40 cUnit->coreSpillMask |= (1 << r_RA);
41 cUnit->numCoreSpills++;
42#endif
43}
44
45/*
46 * Mark a callee-save fp register as promoted. Note that
47 * vpush/vpop uses contiguous register lists so we must
48 * include any holes in the mask. Associate holes with
49 * Dalvik register INVALID_VREG (0xFFFFU).
50 */
51void oatMarkPreservedSingle(CompilationUnit* cUnit, int sReg, int reg)
52{
53 UNIMPLEMENTED(WARNING) << "oatMarkPreservedSingle";
54#if 0
55 LOG(FATAL) << "No support yet for promoted FP regs";
56#endif
57}
58
59void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2)
60{
61 RegisterInfo* info1 = oatGetRegInfo(cUnit, reg1);
62 RegisterInfo* info2 = oatGetRegInfo(cUnit, reg2);
63 DCHECK(info1 && info2 && info1->pair && info2->pair &&
64 (info1->partner == info2->reg) &&
65 (info2->partner == info1->reg));
66 if ((info1->live && info1->dirty) || (info2->live && info2->dirty)) {
67 if (!(info1->isTemp && info2->isTemp)) {
68 /* Should not happen. If it does, there's a problem in evalLoc */
69 LOG(FATAL) << "Long half-temp, half-promoted";
70 }
71
72 info1->dirty = false;
73 info2->dirty = false;
74 if (oatS2VReg(cUnit, info2->sReg) <
75 oatS2VReg(cUnit, info1->sReg))
76 info1 = info2;
77 int vReg = oatS2VReg(cUnit, info1->sReg);
78 oatFlushRegWideImpl(cUnit, rSP,
79 oatVRegOffset(cUnit, vReg),
80 info1->reg, info1->partner);
81 }
82}
83
84void oatFlushReg(CompilationUnit* cUnit, int reg)
85{
86 RegisterInfo* info = oatGetRegInfo(cUnit, reg);
87 if (info->live && info->dirty) {
88 info->dirty = false;
89 int vReg = oatS2VReg(cUnit, info->sReg);
90 oatFlushRegImpl(cUnit, rSP,
91 oatVRegOffset(cUnit, vReg),
92 reg, kWord);
93 }
94}
95
96/* Give access to the target-dependent FP register encoding to common code */
97bool oatIsFpReg(int reg) {
98 return FPREG(reg);
99}
100
101uint32_t oatFpRegMask() {
102 return FP_REG_MASK;
103}
104
105/* Clobber all regs that might be used by an external C call */
106extern void oatClobberCalleeSave(CompilationUnit *cUnit)
107{
108 UNIMPLEMENTED(WARNING) << "oatClobberCalleeSave";
109#if 0
110 oatClobber(cUnit, r_ZERO);
111 oatClobber(cUnit, r_AT);
112 oatClobber(cUnit, r_V0);
113 oatClobber(cUnit, r_V1);
114 oatClobber(cUnit, r_A0);
115 oatClobber(cUnit, r_A1);
116 oatClobber(cUnit, r_A2);
117 oatClobber(cUnit, r_A3);
118 oatClobber(cUnit, r_T0);
119 oatClobber(cUnit, r_T1);
120 oatClobber(cUnit, r_T2);
121 oatClobber(cUnit, r_T3);
122 oatClobber(cUnit, r_T4);
123 oatClobber(cUnit, r_T5);
124 oatClobber(cUnit, r_T6);
125 oatClobber(cUnit, r_T7);
126 oatClobber(cUnit, r_T8);
127 oatClobber(cUnit, r_T9);
128 oatClobber(cUnit, r_K0);
129 oatClobber(cUnit, r_K1);
130 oatClobber(cUnit, r_GP);
131 oatClobber(cUnit, r_FP);
132 oatClobber(cUnit, r_RA);
133 oatClobber(cUnit, r_F0);
134 oatClobber(cUnit, r_F1);
135 oatClobber(cUnit, r_F2);
136 oatClobber(cUnit, r_F3);
137 oatClobber(cUnit, r_F4);
138 oatClobber(cUnit, r_F5);
139 oatClobber(cUnit, r_F6);
140 oatClobber(cUnit, r_F7);
141 oatClobber(cUnit, r_F8);
142 oatClobber(cUnit, r_F9);
143 oatClobber(cUnit, r_F10);
144 oatClobber(cUnit, r_F11);
145 oatClobber(cUnit, r_F12);
146 oatClobber(cUnit, r_F13);
147 oatClobber(cUnit, r_F14);
148 oatClobber(cUnit, r_F15);
149#endif
150}
151
buzbeee88dfbf2012-03-05 11:19:57 -0800152extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg)
153{
154 return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK]
155 : &cUnit->regPool->coreRegs[reg];
156}
157
158/* To be used when explicitly managing register use */
159extern void oatLockCallTemps(CompilationUnit* cUnit)
160{
161 UNIMPLEMENTED(WARNING) << "oatLockCallTemps";
162#if 0
163 oatLockTemp(cUnit, rARG0);
164 oatLockTemp(cUnit, rARG1);
165 oatLockTemp(cUnit, rARG2);
166 oatLockTemp(cUnit, rARG3);
167#endif
168}
169
170/* To be used when explicitly managing register use */
171extern void oatFreeCallTemps(CompilationUnit* cUnit)
172{
173 UNIMPLEMENTED(WARNING) << "oatFreeCallTemps";
174#if 0
175 oatFreeTemp(cUnit, rARG0);
176 oatFreeTemp(cUnit, rARG1);
177 oatFreeTemp(cUnit, rARG2);
178 oatFreeTemp(cUnit, rARG3);
179#endif
180}
181
182/* Convert an instruction to a NOP */
183void oatNopLIR( LIR* lir)
184{
185 ((LIR*)lir)->flags.isNop = true;
186}
187
Elliott Hughese7825db2012-03-09 15:46:57 -0800188extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit)
189{
190 UNIMPLEMENTED(FATAL);
191 RegLocation res = LOC_C_RETURN;
192 return res;
193}
194
buzbeee88dfbf2012-03-05 11:19:57 -0800195} // namespace art