blob: ff5391d8dc6a951802969d6c7aa086dc55e9be1c [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
Ian Rogersb5d09b22012-03-06 22:14:17 -080030void oatAdjustSpillMask(CompilationUnit* cUnit) {
31 // Adjustment for LR spilling, x86 has no LR so nothing to do here
Ian Rogersf7d9ad32012-03-13 18:45:39 -070032 cUnit->coreSpillMask |= (1 << rRET);
33 cUnit->numCoreSpills++;
buzbeee88dfbf2012-03-05 11:19:57 -080034}
35
36/*
37 * Mark a callee-save fp register as promoted. Note that
38 * vpush/vpop uses contiguous register lists so we must
39 * include any holes in the mask. Associate holes with
40 * Dalvik register INVALID_VREG (0xFFFFU).
41 */
42void oatMarkPreservedSingle(CompilationUnit* cUnit, int sReg, int reg)
43{
44 UNIMPLEMENTED(WARNING) << "oatMarkPreservedSingle";
45#if 0
46 LOG(FATAL) << "No support yet for promoted FP regs";
47#endif
48}
49
50void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2)
51{
52 RegisterInfo* info1 = oatGetRegInfo(cUnit, reg1);
53 RegisterInfo* info2 = oatGetRegInfo(cUnit, reg2);
54 DCHECK(info1 && info2 && info1->pair && info2->pair &&
55 (info1->partner == info2->reg) &&
56 (info2->partner == info1->reg));
57 if ((info1->live && info1->dirty) || (info2->live && info2->dirty)) {
58 if (!(info1->isTemp && info2->isTemp)) {
59 /* Should not happen. If it does, there's a problem in evalLoc */
60 LOG(FATAL) << "Long half-temp, half-promoted";
61 }
62
63 info1->dirty = false;
64 info2->dirty = false;
buzbeee1965672012-03-11 18:39:19 -070065 if (SRegToVReg(cUnit, info2->sReg) <
66 SRegToVReg(cUnit, info1->sReg))
buzbeee88dfbf2012-03-05 11:19:57 -080067 info1 = info2;
buzbeee1965672012-03-11 18:39:19 -070068 int vReg = SRegToVReg(cUnit, info1->sReg);
buzbeee88dfbf2012-03-05 11:19:57 -080069 oatFlushRegWideImpl(cUnit, rSP,
70 oatVRegOffset(cUnit, vReg),
71 info1->reg, info1->partner);
72 }
73}
74
75void oatFlushReg(CompilationUnit* cUnit, int reg)
76{
77 RegisterInfo* info = oatGetRegInfo(cUnit, reg);
78 if (info->live && info->dirty) {
79 info->dirty = false;
buzbeee1965672012-03-11 18:39:19 -070080 int vReg = SRegToVReg(cUnit, info->sReg);
buzbeee88dfbf2012-03-05 11:19:57 -080081 oatFlushRegImpl(cUnit, rSP,
82 oatVRegOffset(cUnit, vReg),
83 reg, kWord);
84 }
85}
86
87/* Give access to the target-dependent FP register encoding to common code */
88bool oatIsFpReg(int reg) {
89 return FPREG(reg);
90}
91
92uint32_t oatFpRegMask() {
93 return FP_REG_MASK;
94}
95
96/* Clobber all regs that might be used by an external C call */
97extern void oatClobberCalleeSave(CompilationUnit *cUnit)
98{
99 UNIMPLEMENTED(WARNING) << "oatClobberCalleeSave";
100#if 0
101 oatClobber(cUnit, r_ZERO);
102 oatClobber(cUnit, r_AT);
103 oatClobber(cUnit, r_V0);
104 oatClobber(cUnit, r_V1);
105 oatClobber(cUnit, r_A0);
106 oatClobber(cUnit, r_A1);
107 oatClobber(cUnit, r_A2);
108 oatClobber(cUnit, r_A3);
109 oatClobber(cUnit, r_T0);
110 oatClobber(cUnit, r_T1);
111 oatClobber(cUnit, r_T2);
112 oatClobber(cUnit, r_T3);
113 oatClobber(cUnit, r_T4);
114 oatClobber(cUnit, r_T5);
115 oatClobber(cUnit, r_T6);
116 oatClobber(cUnit, r_T7);
117 oatClobber(cUnit, r_T8);
118 oatClobber(cUnit, r_T9);
119 oatClobber(cUnit, r_K0);
120 oatClobber(cUnit, r_K1);
121 oatClobber(cUnit, r_GP);
122 oatClobber(cUnit, r_FP);
123 oatClobber(cUnit, r_RA);
124 oatClobber(cUnit, r_F0);
125 oatClobber(cUnit, r_F1);
126 oatClobber(cUnit, r_F2);
127 oatClobber(cUnit, r_F3);
128 oatClobber(cUnit, r_F4);
129 oatClobber(cUnit, r_F5);
130 oatClobber(cUnit, r_F6);
131 oatClobber(cUnit, r_F7);
132 oatClobber(cUnit, r_F8);
133 oatClobber(cUnit, r_F9);
134 oatClobber(cUnit, r_F10);
135 oatClobber(cUnit, r_F11);
136 oatClobber(cUnit, r_F12);
137 oatClobber(cUnit, r_F13);
138 oatClobber(cUnit, r_F14);
139 oatClobber(cUnit, r_F15);
140#endif
141}
142
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700143extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) {
144 RegLocation res = LOC_C_RETURN_WIDE;
145 CHECK(res.lowReg == rAX);
146 CHECK(res.highReg == rDX);
147 oatClobber(cUnit, rAX);
148 oatClobber(cUnit, rDX);
149 oatMarkInUse(cUnit, rAX);
150 oatMarkInUse(cUnit, rDX);
151 oatMarkPair(cUnit, res.lowReg, res.highReg);
152 return res;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800153}
154
155extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit)
156{
157 RegLocation res = LOC_C_RETURN;
158 res.lowReg = rDX;
159 oatClobber(cUnit, rDX);
160 oatMarkInUse(cUnit, rDX);
161 return res;
162}
163
buzbeee88dfbf2012-03-05 11:19:57 -0800164extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg)
165{
166 return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK]
167 : &cUnit->regPool->coreRegs[reg];
168}
169
170/* To be used when explicitly managing register use */
171extern void oatLockCallTemps(CompilationUnit* cUnit)
172{
173 UNIMPLEMENTED(WARNING) << "oatLockCallTemps";
174#if 0
175 oatLockTemp(cUnit, rARG0);
176 oatLockTemp(cUnit, rARG1);
177 oatLockTemp(cUnit, rARG2);
178 oatLockTemp(cUnit, rARG3);
179#endif
180}
181
182/* To be used when explicitly managing register use */
183extern void oatFreeCallTemps(CompilationUnit* cUnit)
184{
185 UNIMPLEMENTED(WARNING) << "oatFreeCallTemps";
186#if 0
187 oatFreeTemp(cUnit, rARG0);
188 oatFreeTemp(cUnit, rARG1);
189 oatFreeTemp(cUnit, rARG2);
190 oatFreeTemp(cUnit, rARG3);
191#endif
192}
193
194/* Convert an instruction to a NOP */
195void oatNopLIR( LIR* lir)
196{
197 ((LIR*)lir)->flags.isNop = true;
198}
199
buzbeee88dfbf2012-03-05 11:19:57 -0800200} // namespace art