blob: 12e5f130da8f8e7f239a09921bd2470f61a6d694 [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 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#ifndef ART_SRC_COMPILER_RALLOC_H_
18#define ART_SRC_COMPILER_RALLOC_H_
19/*
20 * This file contains target independent register alloction support.
21 */
22
23#include "../CompilerUtility.h"
24#include "../CompilerIR.h"
25#include "../Dataflow.h"
26#include "arm/ArmLIR.h"
27
28/*
29 * Return most flexible allowed register class based on size.
30 * Bug: 2813841
31 * Must use a core register for data types narrower than word (due
32 * to possible unaligned load/store.
33 */
34static inline RegisterClass oatRegClassBySize(OpSize size)
35{
36 return (size == kUnsignedHalf ||
37 size == kSignedHalf ||
38 size == kUnsignedByte ||
39 size == kSignedByte ) ? kCoreReg : kAnyReg;
40}
41
42static inline int oatS2VReg(CompilationUnit* cUnit, int sReg)
43{
44 assert(sReg != INVALID_SREG);
45 return DECODE_REG(oatConvertSSARegToDalvik(cUnit, sReg));
46}
47
48/* Reset the tracker to unknown state */
49static inline void oatResetNullCheck(CompilationUnit* cUnit)
50{
51 oatClearAllBits(cUnit->regPool->nullCheckedRegs);
52}
53
54/*
55 * Get the "real" sreg number associated with an sReg slot. In general,
56 * sReg values passed through codegen are the SSA names created by
57 * dataflow analysis and refer to slot numbers in the cUnit->regLocation
58 * array. However, renaming is accomplished by simply replacing RegLocation
59 * entries in the cUnit->reglocation[] array. Therefore, when location
60 * records for operands are first created, we need to ask the locRecord
61 * identified by the dataflow pass what it's new name is.
62 */
63
64static inline int oatSRegHi(int lowSreg) {
65 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
66}
67
68
69static inline bool oatLiveOut(CompilationUnit* cUnit, int sReg)
70{
71 //For now.
72 return true;
73}
74
75static inline int oatSSASrc(MIR* mir, int num)
76{
77 assert(mir->ssaRep->numUses > num);
78 return mir->ssaRep->uses[num];
79}
80
81extern RegLocation oatEvalLoc(CompilationUnit* cUnit, RegLocation loc,
82 int regClass, bool update);
83/* Mark a temp register as dead. Does not affect allocation state. */
84extern void oatClobber(CompilationUnit* cUnit, int reg);
85
86extern RegLocation oatUpdateLoc(CompilationUnit* cUnit,
87 RegLocation loc);
88
89/* see comments for updateLoc */
90extern RegLocation oatUpdateLocWide(CompilationUnit* cUnit,
91 RegLocation loc);
92
93/* Clobber all of the temps that might be used by a handler. */
94extern void oatClobberHandlerRegs(CompilationUnit* cUnit);
95
96extern void oatMarkLive(CompilationUnit* cUnit, int reg, int sReg);
97
98extern void oatMarkTemp(CompilationUnit* cUnit, int reg);
99
100extern void oatMarkDirty(CompilationUnit* cUnit, RegLocation loc);
101
102extern void oatMarkPair(CompilationUnit* cUnit, int lowReg,
103 int highReg);
104
105extern void oatMarkClean(CompilationUnit* cUnit, RegLocation loc);
106
107extern void oatResetDef(CompilationUnit* cUnit, int reg);
108
109extern void oatResetDefLoc(CompilationUnit* cUnit, RegLocation rl);
110
111/* Set up temp & preserved register pools specialized by target */
112extern void oatInitPool(RegisterInfo* regs, int* regNums, int num);
113
114/*
115 * Mark the beginning and end LIR of a def sequence. Note that
116 * on entry start points to the LIR prior to the beginning of the
117 * sequence.
118 */
119extern void oatMarkDef(CompilationUnit* cUnit, RegLocation rl,
120 LIR* start, LIR* finish);
121/*
122 * Mark the beginning and end LIR of a def sequence. Note that
123 * on entry start points to the LIR prior to the beginning of the
124 * sequence.
125 */
126extern void oatMarkDefWide(CompilationUnit* cUnit, RegLocation rl,
127 LIR* start, LIR* finish);
128
129extern RegLocation oatGetSrcWide(CompilationUnit* cUnit, MIR* mir,
130 int low, int high);
131
132extern RegLocation oatGetDestWide(CompilationUnit* cUnit, MIR* mir,
133 int low, int high);
134// Get the LocRecord associated with an SSA name use.
135extern RegLocation oatGetSrc(CompilationUnit* cUnit, MIR* mir, int num);
136
137// Get the LocRecord associated with an SSA name def.
138extern RegLocation oatGetDest(CompilationUnit* cUnit, MIR* mir, int num);
139
140extern RegLocation oatGetReturnWide(CompilationUnit* cUnit);
141
142/* Clobber all regs that might be used by an external C call */
143extern void oatClobberCallRegs(CompilationUnit* cUnit);
144
145extern RegisterInfo *oatIsTemp(CompilationUnit* cUnit, int reg);
146
147extern bool oatIsDirty(CompilationUnit* cUnit, int reg);
148
149extern void oatMarkInUse(CompilationUnit* cUnit, int reg);
150
151extern int oatAllocTemp(CompilationUnit* cUnit);
152
153extern int oatAllocTempFloat(CompilationUnit* cUnit);
154
155//REDO: too many assumptions.
156extern int oatAllocTempDouble(CompilationUnit* cUnit);
157
158extern void oatFreeTemp(CompilationUnit* cUnit, int reg);
159
160extern void oatResetDefLocWide(CompilationUnit* cUnit, RegLocation rl);
161
162extern void oatResetDefTracking(CompilationUnit* cUnit);
163
164/* Kill the corresponding bit in the null-checked register list */
165extern void oatKillNullCheckedLoc(CompilationUnit* cUnit,
166 RegLocation loc);
167
168//FIXME - this needs to also check the preserved pool.
169extern RegisterInfo *oatIsLive(CompilationUnit* cUnit, int reg);
170
171/* To be used when explicitly managing register use */
172extern void oatLockAllTemps(CompilationUnit* cUnit);
173
174extern void oatFlushAllRegs(CompilationUnit* cUnit);
175
176extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit);
177
178extern RegLocation oatGetReturn(CompilationUnit* cUnit);
179
180extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit);
181
182/* Clobber any temp associated with an sReg. Could be in either class */
183extern void oatClobberSReg(CompilationUnit* cUnit, int sReg);
184
185/* Return a temp if one is available, -1 otherwise */
186extern int oatAllocFreeTemp(CompilationUnit* cUnit);
187
188/* Attempt to allocate a callee-save register */
189extern int oatAllocPreservedCoreReg(CompilationUnit* cUnit, int sreg);
190extern int oatAllocPreservedFPReg(CompilationUnit* cUnit, int sReg,
191 bool doubleStart);
192
193/*
194 * Similar to oatAllocTemp(), but forces the allocation of a specific
195 * register. No check is made to see if the register was previously
196 * allocated. Use with caution.
197 */
198extern void oatLockTemp(CompilationUnit* cUnit, int reg);
199
200extern RegLocation oatWideToNarrow(CompilationUnit* cUnit,
201 RegLocation rl);
202
203/*
204 * Free all allocated temps in the temp pools. Note that this does
205 * not affect the "liveness" of a temp register, which will stay
206 * live until it is either explicitly killed or reallocated.
207 */
208extern void oatResetRegPool(CompilationUnit* cUnit);
209
210extern void oatClobberAllRegs(CompilationUnit* cUnit);
211
212extern void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2);
213
214extern void oatFlushReg(CompilationUnit* cUnit, int reg);
215
216/*
217 * Architecture-dependent register allocation routines implemented in
218 * ${TARGET_ARCH}/${TARGET_ARCH_VARIANT}/Ralloc.c
219 */
220extern int oatAllocTypedTempPair(CompilationUnit* cUnit,
221 bool fpHint, int regClass);
222
223extern int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint,
224 int regClass);
225
226extern ArmLIR* oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
227
228extern void oatRegCopyWide(CompilationUnit* cUnit, int destLo,
229 int destHi, int srcLo, int srcHi);
230
231extern void oatFlushRegImpl(CompilationUnit* cUnit, int rBase,
232 int displacement, int rSrc, OpSize size);
233
234extern void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase,
235 int displacement, int rSrcLo, int rSrcHi);
236
237extern void oatDoPromotion(CompilationUnit* cUnit);
238extern int oatVRegOffset(CompilationUnit* cUnit, int reg);
239#endif // ART_SRC_COMPILER_RALLOC_H_