blob: 466faa4777e7b42c0b4d5af298aa9703c479277b [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{
Ian Rogers6cbb2bd2012-03-16 13:45:30 -070099 oatClobber(cUnit, rBX);
100 oatClobber(cUnit, rBP);
101 oatClobber(cUnit, rSI);
102 oatClobber(cUnit, rDI);
buzbeee88dfbf2012-03-05 11:19:57 -0800103}
104
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700105extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) {
106 RegLocation res = LOC_C_RETURN_WIDE;
107 CHECK(res.lowReg == rAX);
108 CHECK(res.highReg == rDX);
109 oatClobber(cUnit, rAX);
110 oatClobber(cUnit, rDX);
111 oatMarkInUse(cUnit, rAX);
112 oatMarkInUse(cUnit, rDX);
113 oatMarkPair(cUnit, res.lowReg, res.highReg);
114 return res;
Ian Rogersb5d09b22012-03-06 22:14:17 -0800115}
116
117extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit)
118{
119 RegLocation res = LOC_C_RETURN;
120 res.lowReg = rDX;
121 oatClobber(cUnit, rDX);
122 oatMarkInUse(cUnit, rDX);
123 return res;
124}
125
buzbeee88dfbf2012-03-05 11:19:57 -0800126extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg)
127{
128 return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK]
129 : &cUnit->regPool->coreRegs[reg];
130}
131
132/* To be used when explicitly managing register use */
133extern void oatLockCallTemps(CompilationUnit* cUnit)
134{
buzbeee88dfbf2012-03-05 11:19:57 -0800135 oatLockTemp(cUnit, rARG0);
136 oatLockTemp(cUnit, rARG1);
137 oatLockTemp(cUnit, rARG2);
buzbeee88dfbf2012-03-05 11:19:57 -0800138}
139
140/* To be used when explicitly managing register use */
141extern void oatFreeCallTemps(CompilationUnit* cUnit)
142{
buzbeee88dfbf2012-03-05 11:19:57 -0800143 oatFreeTemp(cUnit, rARG0);
144 oatFreeTemp(cUnit, rARG1);
145 oatFreeTemp(cUnit, rARG2);
buzbeee88dfbf2012-03-05 11:19:57 -0800146}
147
148/* Convert an instruction to a NOP */
149void oatNopLIR( LIR* lir)
150{
151 ((LIR*)lir)->flags.isNop = true;
152}
153
buzbeee88dfbf2012-03-05 11:19:57 -0800154} // namespace art