blob: 671dffed2ff7017ead435943a36de2f8ac0f19a8 [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 {
buzbeee3acd072012-02-25 17:03:10 -080032 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) {
buzbee67bf8852011-08-17 17:51:35 -070049 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
50}
51
52
buzbeee3acd072012-02-25 17:03:10 -080053inline bool oatLiveOut(CompilationUnit* cUnit, int sReg)
buzbee67bf8852011-08-17 17:51:35 -070054{
55 //For now.
56 return true;
57}
58
buzbeee3acd072012-02-25 17:03:10 -080059inline int oatSSASrc(MIR* mir, int num)
buzbee67bf8852011-08-17 17:51:35 -070060{
buzbeeed3e9302011-09-23 17:34:19 -070061 DCHECK_GT(mir->ssaRep->numUses, num);
buzbee67bf8852011-08-17 17:51:35 -070062 return mir->ssaRep->uses[num];
63}
64
65extern RegLocation oatEvalLoc(CompilationUnit* cUnit, RegLocation loc,
66 int regClass, bool update);
67/* Mark a temp register as dead. Does not affect allocation state. */
68extern void oatClobber(CompilationUnit* cUnit, int reg);
69
70extern RegLocation oatUpdateLoc(CompilationUnit* cUnit,
71 RegLocation loc);
72
73/* see comments for updateLoc */
74extern RegLocation oatUpdateLocWide(CompilationUnit* cUnit,
75 RegLocation loc);
76
buzbeeed3e9302011-09-23 17:34:19 -070077extern RegLocation oatUpdateRawLoc(CompilationUnit* cUnit,
78 RegLocation loc);
79
buzbee67bf8852011-08-17 17:51:35 -070080extern void oatMarkLive(CompilationUnit* cUnit, int reg, int sReg);
81
82extern void oatMarkTemp(CompilationUnit* cUnit, int reg);
83
buzbee9e0f9b02011-08-24 15:32:46 -070084extern void oatUnmarkTemp(CompilationUnit* cUnit, int reg);
85
buzbee67bf8852011-08-17 17:51:35 -070086extern void oatMarkDirty(CompilationUnit* cUnit, RegLocation loc);
87
88extern void oatMarkPair(CompilationUnit* cUnit, int lowReg,
89 int highReg);
90
91extern void oatMarkClean(CompilationUnit* cUnit, RegLocation loc);
92
93extern void oatResetDef(CompilationUnit* cUnit, int reg);
94
95extern void oatResetDefLoc(CompilationUnit* cUnit, RegLocation rl);
96
97/* Set up temp & preserved register pools specialized by target */
Elliott Hughes7b9d9962012-04-20 18:48:18 -070098extern void oatInitPool(RegisterInfo* regs, int* regNums, int num);
buzbee67bf8852011-08-17 17:51:35 -070099
100/*
101 * Mark the beginning and end LIR of a def sequence. Note that
102 * on entry start points to the LIR prior to the beginning of the
103 * sequence.
104 */
105extern void oatMarkDef(CompilationUnit* cUnit, RegLocation rl,
106 LIR* start, LIR* finish);
107/*
108 * Mark the beginning and end LIR of a def sequence. Note that
109 * on entry start points to the LIR prior to the beginning of the
110 * sequence.
111 */
112extern void oatMarkDefWide(CompilationUnit* cUnit, RegLocation rl,
113 LIR* start, LIR* finish);
114
115extern RegLocation oatGetSrcWide(CompilationUnit* cUnit, MIR* mir,
116 int low, int high);
117
118extern RegLocation oatGetDestWide(CompilationUnit* cUnit, MIR* mir,
119 int low, int high);
120// Get the LocRecord associated with an SSA name use.
121extern RegLocation oatGetSrc(CompilationUnit* cUnit, MIR* mir, int num);
buzbeee9a72f62011-09-04 17:59:07 -0700122extern RegLocation oatGetRawSrc(CompilationUnit* cUnit, MIR* mir, int num);
buzbee67bf8852011-08-17 17:51:35 -0700123
124// Get the LocRecord associated with an SSA name def.
125extern RegLocation oatGetDest(CompilationUnit* cUnit, MIR* mir, int num);
126
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700127extern RegLocation oatGetReturnWide(CompilationUnit* cUnit, bool isDouble);
buzbee67bf8852011-08-17 17:51:35 -0700128
129/* Clobber all regs that might be used by an external C call */
buzbee6181f792011-09-29 11:14:04 -0700130extern void oatClobberCalleeSave(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700131
132extern RegisterInfo *oatIsTemp(CompilationUnit* cUnit, int reg);
133
buzbeeb29e4d12011-09-26 15:05:48 -0700134extern RegisterInfo *oatIsPromoted(CompilationUnit* cUnit, int reg);
135
buzbee67bf8852011-08-17 17:51:35 -0700136extern bool oatIsDirty(CompilationUnit* cUnit, int reg);
137
138extern void oatMarkInUse(CompilationUnit* cUnit, int reg);
139
140extern int oatAllocTemp(CompilationUnit* cUnit);
141
142extern int oatAllocTempFloat(CompilationUnit* cUnit);
143
144//REDO: too many assumptions.
145extern int oatAllocTempDouble(CompilationUnit* cUnit);
146
147extern void oatFreeTemp(CompilationUnit* cUnit, int reg);
148
149extern void oatResetDefLocWide(CompilationUnit* cUnit, RegLocation rl);
150
151extern void oatResetDefTracking(CompilationUnit* cUnit);
152
buzbee67bf8852011-08-17 17:51:35 -0700153extern RegisterInfo *oatIsLive(CompilationUnit* cUnit, int reg);
154
155/* To be used when explicitly managing register use */
buzbee2e748f32011-08-29 21:02:19 -0700156extern void oatLockCallTemps(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700157
buzbee0d966cf2011-09-08 17:34:58 -0700158extern void oatFreeCallTemps(CompilationUnit* cUnit);
159
buzbee67bf8852011-08-17 17:51:35 -0700160extern void oatFlushAllRegs(CompilationUnit* cUnit);
161
162extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit);
163
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700164extern RegLocation oatGetReturn(CompilationUnit* cUnit, bool isFloat);
buzbee67bf8852011-08-17 17:51:35 -0700165
166extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit);
167
168/* Clobber any temp associated with an sReg. Could be in either class */
169extern void oatClobberSReg(CompilationUnit* cUnit, int sReg);
170
171/* Return a temp if one is available, -1 otherwise */
172extern int oatAllocFreeTemp(CompilationUnit* cUnit);
173
174/* Attempt to allocate a callee-save register */
175extern int oatAllocPreservedCoreReg(CompilationUnit* cUnit, int sreg);
176extern int oatAllocPreservedFPReg(CompilationUnit* cUnit, int sReg,
177 bool doubleStart);
178
179/*
180 * Similar to oatAllocTemp(), but forces the allocation of a specific
181 * register. No check is made to see if the register was previously
182 * allocated. Use with caution.
183 */
184extern void oatLockTemp(CompilationUnit* cUnit, int reg);
185
186extern RegLocation oatWideToNarrow(CompilationUnit* cUnit,
187 RegLocation rl);
188
189/*
190 * Free all allocated temps in the temp pools. Note that this does
191 * not affect the "liveness" of a temp register, which will stay
192 * live until it is either explicitly killed or reallocated.
193 */
194extern void oatResetRegPool(CompilationUnit* cUnit);
195
196extern void oatClobberAllRegs(CompilationUnit* cUnit);
197
198extern void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2);
199
200extern void oatFlushReg(CompilationUnit* cUnit, int reg);
201
buzbeee3acd072012-02-25 17:03:10 -0800202extern void oatDoPromotion(CompilationUnit* cUnit);
203extern int oatVRegOffset(CompilationUnit* cUnit, int reg);
204extern int oatSRegOffset(CompilationUnit* cUnit, int reg);
205extern void oatCountRefs(CompilationUnit*, BasicBlock*, RefCounts*, RefCounts*);
206extern int oatSortCounts(const void *val1, const void *val2);
207extern void oatDumpCounts(const RefCounts* arr, int size, const char* msg);
208
buzbee67bf8852011-08-17 17:51:35 -0700209/*
210 * Architecture-dependent register allocation routines implemented in
211 * ${TARGET_ARCH}/${TARGET_ARCH_VARIANT}/Ralloc.c
212 */
213extern int oatAllocTypedTempPair(CompilationUnit* cUnit,
214 bool fpHint, int regClass);
215
216extern int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint,
217 int regClass);
218
buzbee67bf8852011-08-17 17:51:35 -0700219extern void oatRegCopyWide(CompilationUnit* cUnit, int destLo,
220 int destHi, int srcLo, int srcHi);
221
222extern void oatFlushRegImpl(CompilationUnit* cUnit, int rBase,
223 int displacement, int rSrc, OpSize size);
224
225extern void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase,
226 int displacement, int rSrcLo, int rSrcHi);
227
buzbee6181f792011-09-29 11:14:04 -0700228extern void oatDumpCoreRegPool(CompilationUnit* cUint);
229extern void oatDumpFPRegPool(CompilationUnit* cUint);
230extern bool oatCheckCorePoolSanity(CompilationUnit* cUnit);
buzbee68253262011-10-07 14:02:25 -0700231extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg);
buzbeee3acd072012-02-25 17:03:10 -0800232extern void oatNopLIR(LIR* lir);
233extern bool oatIsFPReg(int reg);
234extern uint32_t oatFPRegMask(void);
235extern void oatAdjustSpillMask(CompilationUnit* cUnit);
buzbee9c044ce2012-03-18 13:24:07 -0700236void oatMarkPreservedSingle(CompilationUnit* cUnit, int vReg, int reg);
buzbeee3acd072012-02-25 17:03:10 -0800237void oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800238
239} // namespace art
240
buzbee67bf8852011-08-17 17:51:35 -0700241#endif // ART_SRC_COMPILER_RALLOC_H_