blob: c0b60689a0b3d0f7ae901e67de4bc21e292b4db9 [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"
buzbee67bf8852011-08-17 17:51:35 -070027
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080028namespace art {
29
buzbeee3acd072012-02-25 17:03:10 -080030/* Static register use counts */
Elliott Hughes719ace42012-03-09 18:06:03 -080031struct RefCounts {
Bill Buzbeea114add2012-05-03 15:00:40 -070032 int count;
33 int sReg;
34 bool doubleStart; // Starting vReg for a double
Elliott Hughes719ace42012-03-09 18:06:03 -080035};
buzbee67bf8852011-08-17 17:51:35 -070036
buzbeee3acd072012-02-25 17:03:10 -080037
buzbee67bf8852011-08-17 17:51:35 -070038/*
39 * Get the "real" sreg number associated with an sReg slot. In general,
40 * sReg values passed through codegen are the SSA names created by
41 * dataflow analysis and refer to slot numbers in the cUnit->regLocation
42 * array. However, renaming is accomplished by simply replacing RegLocation
43 * entries in the cUnit->reglocation[] array. Therefore, when location
44 * records for operands are first created, we need to ask the locRecord
45 * identified by the dataflow pass what it's new name is.
46 */
47
buzbeee3acd072012-02-25 17:03:10 -080048inline int oatSRegHi(int lowSreg) {
Bill Buzbeea114add2012-05-03 15:00:40 -070049 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
buzbee67bf8852011-08-17 17:51:35 -070050}
51
52
buzbeee3acd072012-02-25 17:03:10 -080053inline bool oatLiveOut(CompilationUnit* cUnit, int sReg)
buzbee67bf8852011-08-17 17:51:35 -070054{
Bill Buzbeea114add2012-05-03 15:00:40 -070055 //For now.
56 return true;
buzbee67bf8852011-08-17 17:51:35 -070057}
58
buzbeee3acd072012-02-25 17:03:10 -080059inline int oatSSASrc(MIR* mir, int num)
buzbee67bf8852011-08-17 17:51:35 -070060{
Bill Buzbeea114add2012-05-03 15:00:40 -070061 DCHECK_GT(mir->ssaRep->numUses, num);
62 return mir->ssaRep->uses[num];
buzbee67bf8852011-08-17 17:51:35 -070063}
64
65extern RegLocation oatEvalLoc(CompilationUnit* cUnit, RegLocation loc,
Bill Buzbeea114add2012-05-03 15:00:40 -070066 int regClass, bool update);
buzbee67bf8852011-08-17 17:51:35 -070067/* Mark a temp register as dead. Does not affect allocation state. */
68extern void oatClobber(CompilationUnit* cUnit, int reg);
Bill Buzbeea114add2012-05-03 15:00:40 -070069extern RegLocation oatUpdateLoc(CompilationUnit* cUnit, RegLocation loc);
buzbee67bf8852011-08-17 17:51:35 -070070
71/* see comments for updateLoc */
Bill Buzbeea114add2012-05-03 15:00:40 -070072extern RegLocation oatUpdateLocWide(CompilationUnit* cUnit, RegLocation loc);
buzbee67bf8852011-08-17 17:51:35 -070073
Bill Buzbeea114add2012-05-03 15:00:40 -070074extern RegLocation oatUpdateRawLoc(CompilationUnit* cUnit, RegLocation loc);
buzbeeed3e9302011-09-23 17:34:19 -070075
buzbee67bf8852011-08-17 17:51:35 -070076extern void oatMarkLive(CompilationUnit* cUnit, int reg, int sReg);
77
78extern void oatMarkTemp(CompilationUnit* cUnit, int reg);
79
buzbee9e0f9b02011-08-24 15:32:46 -070080extern void oatUnmarkTemp(CompilationUnit* cUnit, int reg);
81
buzbee67bf8852011-08-17 17:51:35 -070082extern void oatMarkDirty(CompilationUnit* cUnit, RegLocation loc);
83
Bill Buzbeea114add2012-05-03 15:00:40 -070084extern void oatMarkPair(CompilationUnit* cUnit, int lowReg, int highReg);
buzbee67bf8852011-08-17 17:51:35 -070085
86extern void oatMarkClean(CompilationUnit* cUnit, RegLocation loc);
87
88extern void oatResetDef(CompilationUnit* cUnit, int reg);
89
90extern void oatResetDefLoc(CompilationUnit* cUnit, RegLocation rl);
91
92/* Set up temp & preserved register pools specialized by target */
Elliott Hughes7b9d9962012-04-20 18:48:18 -070093extern void oatInitPool(RegisterInfo* regs, int* regNums, int num);
buzbee67bf8852011-08-17 17:51:35 -070094
95/*
96 * Mark the beginning and end LIR of a def sequence. Note that
97 * on entry start points to the LIR prior to the beginning of the
98 * sequence.
99 */
Bill Buzbeea114add2012-05-03 15:00:40 -0700100extern void oatMarkDef(CompilationUnit* cUnit, RegLocation rl, LIR* start,
101 LIR* finish);
buzbee67bf8852011-08-17 17:51:35 -0700102/*
103 * Mark the beginning and end LIR of a def sequence. Note that
104 * on entry start points to the LIR prior to the beginning of the
105 * sequence.
106 */
107extern void oatMarkDefWide(CompilationUnit* cUnit, RegLocation rl,
Bill Buzbeea114add2012-05-03 15:00:40 -0700108 LIR* start, LIR* finish);
buzbee67bf8852011-08-17 17:51:35 -0700109
110extern RegLocation oatGetSrcWide(CompilationUnit* cUnit, MIR* mir,
111 int low, int high);
112
113extern RegLocation oatGetDestWide(CompilationUnit* cUnit, MIR* mir,
114 int low, int high);
115// Get the LocRecord associated with an SSA name use.
116extern RegLocation oatGetSrc(CompilationUnit* cUnit, MIR* mir, int num);
buzbeee9a72f62011-09-04 17:59:07 -0700117extern RegLocation oatGetRawSrc(CompilationUnit* cUnit, MIR* mir, int num);
buzbee67bf8852011-08-17 17:51:35 -0700118
119// Get the LocRecord associated with an SSA name def.
120extern RegLocation oatGetDest(CompilationUnit* cUnit, MIR* mir, int num);
121
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700122extern RegLocation oatGetReturnWide(CompilationUnit* cUnit, bool isDouble);
buzbee67bf8852011-08-17 17:51:35 -0700123
124/* Clobber all regs that might be used by an external C call */
buzbee6181f792011-09-29 11:14:04 -0700125extern void oatClobberCalleeSave(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700126
127extern RegisterInfo *oatIsTemp(CompilationUnit* cUnit, int reg);
128
buzbeeb29e4d12011-09-26 15:05:48 -0700129extern RegisterInfo *oatIsPromoted(CompilationUnit* cUnit, int reg);
130
buzbee67bf8852011-08-17 17:51:35 -0700131extern bool oatIsDirty(CompilationUnit* cUnit, int reg);
132
133extern void oatMarkInUse(CompilationUnit* cUnit, int reg);
134
135extern int oatAllocTemp(CompilationUnit* cUnit);
136
137extern int oatAllocTempFloat(CompilationUnit* cUnit);
138
139//REDO: too many assumptions.
140extern int oatAllocTempDouble(CompilationUnit* cUnit);
141
142extern void oatFreeTemp(CompilationUnit* cUnit, int reg);
143
144extern void oatResetDefLocWide(CompilationUnit* cUnit, RegLocation rl);
145
146extern void oatResetDefTracking(CompilationUnit* cUnit);
147
buzbee67bf8852011-08-17 17:51:35 -0700148extern RegisterInfo *oatIsLive(CompilationUnit* cUnit, int reg);
149
150/* To be used when explicitly managing register use */
buzbee2e748f32011-08-29 21:02:19 -0700151extern void oatLockCallTemps(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700152
buzbee0d966cf2011-09-08 17:34:58 -0700153extern void oatFreeCallTemps(CompilationUnit* cUnit);
154
buzbee67bf8852011-08-17 17:51:35 -0700155extern void oatFlushAllRegs(CompilationUnit* cUnit);
156
157extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit);
158
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700159extern RegLocation oatGetReturn(CompilationUnit* cUnit, bool isFloat);
buzbee67bf8852011-08-17 17:51:35 -0700160
161extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit);
162
163/* Clobber any temp associated with an sReg. Could be in either class */
164extern void oatClobberSReg(CompilationUnit* cUnit, int sReg);
165
166/* Return a temp if one is available, -1 otherwise */
167extern int oatAllocFreeTemp(CompilationUnit* cUnit);
168
169/* Attempt to allocate a callee-save register */
170extern int oatAllocPreservedCoreReg(CompilationUnit* cUnit, int sreg);
171extern int oatAllocPreservedFPReg(CompilationUnit* cUnit, int sReg,
172 bool doubleStart);
173
174/*
175 * Similar to oatAllocTemp(), but forces the allocation of a specific
176 * register. No check is made to see if the register was previously
177 * allocated. Use with caution.
178 */
179extern void oatLockTemp(CompilationUnit* cUnit, int reg);
180
Bill Buzbeea114add2012-05-03 15:00:40 -0700181extern RegLocation oatWideToNarrow(CompilationUnit* cUnit, RegLocation rl);
buzbee67bf8852011-08-17 17:51:35 -0700182
183/*
184 * Free all allocated temps in the temp pools. Note that this does
185 * not affect the "liveness" of a temp register, which will stay
186 * live until it is either explicitly killed or reallocated.
187 */
188extern void oatResetRegPool(CompilationUnit* cUnit);
189
190extern void oatClobberAllRegs(CompilationUnit* cUnit);
191
192extern void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2);
193
194extern void oatFlushReg(CompilationUnit* cUnit, int reg);
195
buzbeee3acd072012-02-25 17:03:10 -0800196extern void oatDoPromotion(CompilationUnit* cUnit);
197extern int oatVRegOffset(CompilationUnit* cUnit, int reg);
198extern int oatSRegOffset(CompilationUnit* cUnit, int reg);
199extern void oatCountRefs(CompilationUnit*, BasicBlock*, RefCounts*, RefCounts*);
200extern int oatSortCounts(const void *val1, const void *val2);
201extern void oatDumpCounts(const RefCounts* arr, int size, const char* msg);
202
buzbee67bf8852011-08-17 17:51:35 -0700203/*
204 * Architecture-dependent register allocation routines implemented in
205 * ${TARGET_ARCH}/${TARGET_ARCH_VARIANT}/Ralloc.c
206 */
207extern int oatAllocTypedTempPair(CompilationUnit* cUnit,
208 bool fpHint, int regClass);
209
Bill Buzbeea114add2012-05-03 15:00:40 -0700210extern int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint, int regClass);
buzbee67bf8852011-08-17 17:51:35 -0700211
buzbee67bf8852011-08-17 17:51:35 -0700212extern void oatRegCopyWide(CompilationUnit* cUnit, int destLo,
213 int destHi, int srcLo, int srcHi);
214
215extern void oatFlushRegImpl(CompilationUnit* cUnit, int rBase,
216 int displacement, int rSrc, OpSize size);
217
218extern void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase,
219 int displacement, int rSrcLo, int rSrcHi);
220
buzbee6181f792011-09-29 11:14:04 -0700221extern void oatDumpCoreRegPool(CompilationUnit* cUint);
222extern void oatDumpFPRegPool(CompilationUnit* cUint);
223extern bool oatCheckCorePoolSanity(CompilationUnit* cUnit);
buzbee68253262011-10-07 14:02:25 -0700224extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg);
buzbeee3acd072012-02-25 17:03:10 -0800225extern void oatNopLIR(LIR* lir);
226extern bool oatIsFPReg(int reg);
227extern uint32_t oatFPRegMask(void);
228extern void oatAdjustSpillMask(CompilationUnit* cUnit);
buzbee9c044ce2012-03-18 13:24:07 -0700229void oatMarkPreservedSingle(CompilationUnit* cUnit, int vReg, int reg);
buzbeee3acd072012-02-25 17:03:10 -0800230void oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800231
232} // namespace art
233
buzbee67bf8852011-08-17 17:51:35 -0700234#endif // ART_SRC_COMPILER_RALLOC_H_