blob: ba5c063c8852f83620c3e3cc994691ca2cf347ff [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 */
buzbee9c044ce2012-03-18 13:24:07 -070042void oatMarkPreservedSingle(CompilationUnit* cUnit, int vReg, int reg)
buzbeee88dfbf2012-03-05 11:19:57 -080043{
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{
Ian Rogers6cbb2bd2012-03-16 13:45:30 -070099 oatClobber(cUnit, rBP);
100 oatClobber(cUnit, rSI);
101 oatClobber(cUnit, rDI);
buzbeee88dfbf2012-03-05 11:19:57 -0800102}
103
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700104extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) {
105 RegLocation res = LOC_C_RETURN_WIDE;
106 CHECK(res.lowReg == rAX);
107 CHECK(res.highReg == rDX);
108 oatClobber(cUnit, rAX);
109 oatClobber(cUnit, rDX);
110 oatMarkInUse(cUnit, rAX);
111 oatMarkInUse(cUnit, rDX);
112 oatMarkPair(cUnit, res.lowReg, res.highReg);
113 return res;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800114}
115
116extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit)
117{
118 RegLocation res = LOC_C_RETURN;
119 res.lowReg = rDX;
120 oatClobber(cUnit, rDX);
121 oatMarkInUse(cUnit, rDX);
122 return res;
123}
124
buzbeee88dfbf2012-03-05 11:19:57 -0800125extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg)
126{
127 return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK]
128 : &cUnit->regPool->coreRegs[reg];
129}
130
131/* To be used when explicitly managing register use */
132extern void oatLockCallTemps(CompilationUnit* cUnit)
133{
buzbeee88dfbf2012-03-05 11:19:57 -0800134 oatLockTemp(cUnit, rARG0);
135 oatLockTemp(cUnit, rARG1);
136 oatLockTemp(cUnit, rARG2);
buzbeee88dfbf2012-03-05 11:19:57 -0800137}
138
139/* To be used when explicitly managing register use */
140extern void oatFreeCallTemps(CompilationUnit* cUnit)
141{
buzbeee88dfbf2012-03-05 11:19:57 -0800142 oatFreeTemp(cUnit, rARG0);
143 oatFreeTemp(cUnit, rARG1);
144 oatFreeTemp(cUnit, rARG2);
buzbeee88dfbf2012-03-05 11:19:57 -0800145}
146
147/* Convert an instruction to a NOP */
148void oatNopLIR( LIR* lir)
149{
150 ((LIR*)lir)->flags.isNop = true;
151}
152
buzbeee88dfbf2012-03-05 11:19:57 -0800153} // namespace art