blob: b73ae3078ff8972f2d8160378eed726aabb38e56 [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
buzbee67bf8852011-08-17 17:51:35 -070093extern void oatMarkLive(CompilationUnit* cUnit, int reg, int sReg);
94
95extern void oatMarkTemp(CompilationUnit* cUnit, int reg);
96
buzbee9e0f9b02011-08-24 15:32:46 -070097extern void oatUnmarkTemp(CompilationUnit* cUnit, int reg);
98
buzbee67bf8852011-08-17 17:51:35 -070099extern void oatMarkDirty(CompilationUnit* cUnit, RegLocation loc);
100
101extern void oatMarkPair(CompilationUnit* cUnit, int lowReg,
102 int highReg);
103
104extern void oatMarkClean(CompilationUnit* cUnit, RegLocation loc);
105
106extern void oatResetDef(CompilationUnit* cUnit, int reg);
107
108extern void oatResetDefLoc(CompilationUnit* cUnit, RegLocation rl);
109
110/* Set up temp & preserved register pools specialized by target */
111extern void oatInitPool(RegisterInfo* regs, int* regNums, int num);
112
113/*
114 * Mark the beginning and end LIR of a def sequence. Note that
115 * on entry start points to the LIR prior to the beginning of the
116 * sequence.
117 */
118extern void oatMarkDef(CompilationUnit* cUnit, RegLocation rl,
119 LIR* start, LIR* finish);
120/*
121 * Mark the beginning and end LIR of a def sequence. Note that
122 * on entry start points to the LIR prior to the beginning of the
123 * sequence.
124 */
125extern void oatMarkDefWide(CompilationUnit* cUnit, RegLocation rl,
126 LIR* start, LIR* finish);
127
128extern RegLocation oatGetSrcWide(CompilationUnit* cUnit, MIR* mir,
129 int low, int high);
130
131extern RegLocation oatGetDestWide(CompilationUnit* cUnit, MIR* mir,
132 int low, int high);
133// Get the LocRecord associated with an SSA name use.
134extern RegLocation oatGetSrc(CompilationUnit* cUnit, MIR* mir, int num);
135
136// Get the LocRecord associated with an SSA name def.
137extern RegLocation oatGetDest(CompilationUnit* cUnit, MIR* mir, int num);
138
139extern RegLocation oatGetReturnWide(CompilationUnit* cUnit);
140
141/* Clobber all regs that might be used by an external C call */
142extern void oatClobberCallRegs(CompilationUnit* cUnit);
143
144extern RegisterInfo *oatIsTemp(CompilationUnit* cUnit, int reg);
145
146extern bool oatIsDirty(CompilationUnit* cUnit, int reg);
147
148extern void oatMarkInUse(CompilationUnit* cUnit, int reg);
149
150extern int oatAllocTemp(CompilationUnit* cUnit);
151
152extern int oatAllocTempFloat(CompilationUnit* cUnit);
153
154//REDO: too many assumptions.
155extern int oatAllocTempDouble(CompilationUnit* cUnit);
156
157extern void oatFreeTemp(CompilationUnit* cUnit, int reg);
158
159extern void oatResetDefLocWide(CompilationUnit* cUnit, RegLocation rl);
160
161extern void oatResetDefTracking(CompilationUnit* cUnit);
162
163/* Kill the corresponding bit in the null-checked register list */
164extern void oatKillNullCheckedLoc(CompilationUnit* cUnit,
165 RegLocation loc);
166
167//FIXME - this needs to also check the preserved pool.
168extern RegisterInfo *oatIsLive(CompilationUnit* cUnit, int reg);
169
170/* To be used when explicitly managing register use */
buzbee2e748f32011-08-29 21:02:19 -0700171extern void oatLockCallTemps(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700172
173extern void oatFlushAllRegs(CompilationUnit* cUnit);
174
175extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit);
176
177extern RegLocation oatGetReturn(CompilationUnit* cUnit);
178
179extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit);
180
181/* Clobber any temp associated with an sReg. Could be in either class */
182extern void oatClobberSReg(CompilationUnit* cUnit, int sReg);
183
184/* Return a temp if one is available, -1 otherwise */
185extern int oatAllocFreeTemp(CompilationUnit* cUnit);
186
187/* Attempt to allocate a callee-save register */
188extern int oatAllocPreservedCoreReg(CompilationUnit* cUnit, int sreg);
189extern int oatAllocPreservedFPReg(CompilationUnit* cUnit, int sReg,
190 bool doubleStart);
191
192/*
193 * Similar to oatAllocTemp(), but forces the allocation of a specific
194 * register. No check is made to see if the register was previously
195 * allocated. Use with caution.
196 */
197extern void oatLockTemp(CompilationUnit* cUnit, int reg);
198
199extern RegLocation oatWideToNarrow(CompilationUnit* cUnit,
200 RegLocation rl);
201
202/*
203 * Free all allocated temps in the temp pools. Note that this does
204 * not affect the "liveness" of a temp register, which will stay
205 * live until it is either explicitly killed or reallocated.
206 */
207extern void oatResetRegPool(CompilationUnit* cUnit);
208
209extern void oatClobberAllRegs(CompilationUnit* cUnit);
210
211extern void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2);
212
213extern void oatFlushReg(CompilationUnit* cUnit, int reg);
214
215/*
216 * Architecture-dependent register allocation routines implemented in
217 * ${TARGET_ARCH}/${TARGET_ARCH_VARIANT}/Ralloc.c
218 */
219extern int oatAllocTypedTempPair(CompilationUnit* cUnit,
220 bool fpHint, int regClass);
221
222extern int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint,
223 int regClass);
224
225extern ArmLIR* oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
226
227extern void oatRegCopyWide(CompilationUnit* cUnit, int destLo,
228 int destHi, int srcLo, int srcHi);
229
230extern void oatFlushRegImpl(CompilationUnit* cUnit, int rBase,
231 int displacement, int rSrc, OpSize size);
232
233extern void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase,
234 int displacement, int rSrcLo, int rSrcHi);
235
236extern void oatDoPromotion(CompilationUnit* cUnit);
237extern int oatVRegOffset(CompilationUnit* cUnit, int reg);
238#endif // ART_SRC_COMPILER_RALLOC_H_