blob: e72cdcbff4b7c807bf250714628b6d5ce86b7a0e [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_
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080019
buzbee67bf8852011-08-17 17:51:35 -070020/*
21 * This file contains target independent register alloction support.
22 */
23
24#include "../CompilerUtility.h"
25#include "../CompilerIR.h"
26#include "../Dataflow.h"
27#include "arm/ArmLIR.h"
28
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080029namespace art {
30
buzbee67bf8852011-08-17 17:51:35 -070031/*
32 * Return most flexible allowed register class based on size.
33 * Bug: 2813841
34 * Must use a core register for data types narrower than word (due
35 * to possible unaligned load/store.
36 */
buzbeeed3e9302011-09-23 17:34:19 -070037STATIC inline RegisterClass oatRegClassBySize(OpSize size)
buzbee67bf8852011-08-17 17:51:35 -070038{
39 return (size == kUnsignedHalf ||
40 size == kSignedHalf ||
41 size == kUnsignedByte ||
42 size == kSignedByte ) ? kCoreReg : kAnyReg;
43}
44
buzbeeed3e9302011-09-23 17:34:19 -070045STATIC inline int oatS2VReg(CompilationUnit* cUnit, int sReg)
buzbee67bf8852011-08-17 17:51:35 -070046{
buzbeeed3e9302011-09-23 17:34:19 -070047 DCHECK_NE(sReg, INVALID_SREG);
buzbee67bf8852011-08-17 17:51:35 -070048 return DECODE_REG(oatConvertSSARegToDalvik(cUnit, sReg));
49}
50
buzbee67bf8852011-08-17 17:51:35 -070051/*
52 * Get the "real" sreg number associated with an sReg slot. In general,
53 * sReg values passed through codegen are the SSA names created by
54 * dataflow analysis and refer to slot numbers in the cUnit->regLocation
55 * array. However, renaming is accomplished by simply replacing RegLocation
56 * entries in the cUnit->reglocation[] array. Therefore, when location
57 * records for operands are first created, we need to ask the locRecord
58 * identified by the dataflow pass what it's new name is.
59 */
60
buzbeeed3e9302011-09-23 17:34:19 -070061STATIC inline int oatSRegHi(int lowSreg) {
buzbee67bf8852011-08-17 17:51:35 -070062 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
63}
64
65
buzbeeed3e9302011-09-23 17:34:19 -070066STATIC inline bool oatLiveOut(CompilationUnit* cUnit, int sReg)
buzbee67bf8852011-08-17 17:51:35 -070067{
68 //For now.
69 return true;
70}
71
buzbeeed3e9302011-09-23 17:34:19 -070072STATIC inline int oatSSASrc(MIR* mir, int num)
buzbee67bf8852011-08-17 17:51:35 -070073{
buzbeeed3e9302011-09-23 17:34:19 -070074 DCHECK_GT(mir->ssaRep->numUses, num);
buzbee67bf8852011-08-17 17:51:35 -070075 return mir->ssaRep->uses[num];
76}
77
78extern RegLocation oatEvalLoc(CompilationUnit* cUnit, RegLocation loc,
79 int regClass, bool update);
80/* Mark a temp register as dead. Does not affect allocation state. */
81extern void oatClobber(CompilationUnit* cUnit, int reg);
82
83extern RegLocation oatUpdateLoc(CompilationUnit* cUnit,
84 RegLocation loc);
85
86/* see comments for updateLoc */
87extern RegLocation oatUpdateLocWide(CompilationUnit* cUnit,
88 RegLocation loc);
89
buzbeeed3e9302011-09-23 17:34:19 -070090extern RegLocation oatUpdateRawLoc(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);
buzbeee9a72f62011-09-04 17:59:07 -0700135extern RegLocation oatGetRawSrc(CompilationUnit* cUnit, MIR* mir, int num);
buzbee67bf8852011-08-17 17:51:35 -0700136
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 */
buzbee6181f792011-09-29 11:14:04 -0700143extern void oatClobberCalleeSave(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700144
145extern RegisterInfo *oatIsTemp(CompilationUnit* cUnit, int reg);
146
buzbeeb29e4d12011-09-26 15:05:48 -0700147extern RegisterInfo *oatIsPromoted(CompilationUnit* cUnit, int reg);
148
buzbee67bf8852011-08-17 17:51:35 -0700149extern bool oatIsDirty(CompilationUnit* cUnit, int reg);
150
151extern void oatMarkInUse(CompilationUnit* cUnit, int reg);
152
153extern int oatAllocTemp(CompilationUnit* cUnit);
154
155extern int oatAllocTempFloat(CompilationUnit* cUnit);
156
157//REDO: too many assumptions.
158extern int oatAllocTempDouble(CompilationUnit* cUnit);
159
160extern void oatFreeTemp(CompilationUnit* cUnit, int reg);
161
162extern void oatResetDefLocWide(CompilationUnit* cUnit, RegLocation rl);
163
164extern void oatResetDefTracking(CompilationUnit* cUnit);
165
buzbee67bf8852011-08-17 17:51:35 -0700166extern RegisterInfo *oatIsLive(CompilationUnit* cUnit, int reg);
167
168/* To be used when explicitly managing register use */
buzbee2e748f32011-08-29 21:02:19 -0700169extern void oatLockCallTemps(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700170
buzbee0d966cf2011-09-08 17:34:58 -0700171extern void oatFreeCallTemps(CompilationUnit* cUnit);
172
buzbee67bf8852011-08-17 17:51:35 -0700173extern 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);
buzbee67bc2362011-10-11 18:08:40 -0700238extern int oatSRegOffset(CompilationUnit* cUnit, int reg);
buzbee6181f792011-09-29 11:14:04 -0700239extern void oatDumpCoreRegPool(CompilationUnit* cUint);
240extern void oatDumpFPRegPool(CompilationUnit* cUint);
241extern bool oatCheckCorePoolSanity(CompilationUnit* cUnit);
buzbee68253262011-10-07 14:02:25 -0700242extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg);
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800243
244} // namespace art
245
buzbee67bf8852011-08-17 17:51:35 -0700246#endif // ART_SRC_COMPILER_RALLOC_H_