blob: 58ad25ac68dfa7587e0254cc1d41917b98cf2301 [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{
Bill Buzbeea114add2012-05-03 15:00:40 -070044 UNIMPLEMENTED(WARNING) << "oatMarkPreservedSingle";
buzbeee88dfbf2012-03-05 11:19:57 -080045#if 0
Bill Buzbeea114add2012-05-03 15:00:40 -070046 LOG(FATAL) << "No support yet for promoted FP regs";
buzbeee88dfbf2012-03-05 11:19:57 -080047#endif
48}
49
50void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2)
51{
Bill Buzbeea114add2012-05-03 15:00:40 -070052 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";
buzbeee88dfbf2012-03-05 11:19:57 -080061 }
Bill Buzbeea114add2012-05-03 15:00:40 -070062
63 info1->dirty = false;
64 info2->dirty = false;
65 if (SRegToVReg(cUnit, info2->sReg) < SRegToVReg(cUnit, info1->sReg))
66 info1 = info2;
67 int vReg = SRegToVReg(cUnit, info1->sReg);
68 oatFlushRegWideImpl(cUnit, rSP, oatVRegOffset(cUnit, vReg),
69 info1->reg, info1->partner);
70 }
buzbeee88dfbf2012-03-05 11:19:57 -080071}
72
73void oatFlushReg(CompilationUnit* cUnit, int reg)
74{
Bill Buzbeea114add2012-05-03 15:00:40 -070075 RegisterInfo* info = oatGetRegInfo(cUnit, reg);
76 if (info->live && info->dirty) {
77 info->dirty = false;
78 int vReg = SRegToVReg(cUnit, info->sReg);
79 oatFlushRegImpl(cUnit, rSP, oatVRegOffset(cUnit, vReg), reg, kWord);
80 }
buzbeee88dfbf2012-03-05 11:19:57 -080081}
82
83/* Give access to the target-dependent FP register encoding to common code */
84bool oatIsFpReg(int reg) {
Bill Buzbeea114add2012-05-03 15:00:40 -070085 return FPREG(reg);
buzbeee88dfbf2012-03-05 11:19:57 -080086}
87
88uint32_t oatFpRegMask() {
Bill Buzbeea114add2012-05-03 15:00:40 -070089 return FP_REG_MASK;
buzbeee88dfbf2012-03-05 11:19:57 -080090}
91
92/* Clobber all regs that might be used by an external C call */
93extern void oatClobberCalleeSave(CompilationUnit *cUnit)
94{
Bill Buzbeea114add2012-05-03 15:00:40 -070095 oatClobber(cUnit, rAX);
96 oatClobber(cUnit, rCX);
97 oatClobber(cUnit, rDX);
buzbeee88dfbf2012-03-05 11:19:57 -080098}
99
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700100extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) {
101 RegLocation res = LOC_C_RETURN_WIDE;
102 CHECK(res.lowReg == rAX);
103 CHECK(res.highReg == rDX);
104 oatClobber(cUnit, rAX);
105 oatClobber(cUnit, rDX);
106 oatMarkInUse(cUnit, rAX);
107 oatMarkInUse(cUnit, rDX);
108 oatMarkPair(cUnit, res.lowReg, res.highReg);
109 return res;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800110}
111
112extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit)
113{
Bill Buzbeea114add2012-05-03 15:00:40 -0700114 RegLocation res = LOC_C_RETURN;
115 res.lowReg = rDX;
116 oatClobber(cUnit, rDX);
117 oatMarkInUse(cUnit, rDX);
118 return res;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800119}
120
buzbeee88dfbf2012-03-05 11:19:57 -0800121extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg)
122{
Bill Buzbeea114add2012-05-03 15:00:40 -0700123 return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK]
124 : &cUnit->regPool->coreRegs[reg];
buzbeee88dfbf2012-03-05 11:19:57 -0800125}
126
127/* To be used when explicitly managing register use */
128extern void oatLockCallTemps(CompilationUnit* cUnit)
129{
Bill Buzbeea114add2012-05-03 15:00:40 -0700130 oatLockTemp(cUnit, rARG0);
131 oatLockTemp(cUnit, rARG1);
132 oatLockTemp(cUnit, rARG2);
133 oatLockTemp(cUnit, rARG3);
buzbeee88dfbf2012-03-05 11:19:57 -0800134}
135
136/* To be used when explicitly managing register use */
137extern void oatFreeCallTemps(CompilationUnit* cUnit)
138{
Bill Buzbeea114add2012-05-03 15:00:40 -0700139 oatFreeTemp(cUnit, rARG0);
140 oatFreeTemp(cUnit, rARG1);
141 oatFreeTemp(cUnit, rARG2);
142 oatFreeTemp(cUnit, rARG3);
buzbeee88dfbf2012-03-05 11:19:57 -0800143}
144
145/* Convert an instruction to a NOP */
146void oatNopLIR( LIR* lir)
147{
Bill Buzbeea114add2012-05-03 15:00:40 -0700148 ((LIR*)lir)->flags.isNop = true;
buzbeee88dfbf2012-03-05 11:19:57 -0800149}
150
buzbeee88dfbf2012-03-05 11:19:57 -0800151} // namespace art