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