blob: ad19475b9b30a8abc9055546ab9dc92836d84426 [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
buzbee67bf8852011-08-17 17:51:35 -070048/*
49 * Get the "real" sreg number associated with an sReg slot. In general,
50 * sReg values passed through codegen are the SSA names created by
51 * dataflow analysis and refer to slot numbers in the cUnit->regLocation
52 * array. However, renaming is accomplished by simply replacing RegLocation
53 * entries in the cUnit->reglocation[] array. Therefore, when location
54 * records for operands are first created, we need to ask the locRecord
55 * identified by the dataflow pass what it's new name is.
56 */
57
58static inline int oatSRegHi(int lowSreg) {
59 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
60}
61
62
63static inline bool oatLiveOut(CompilationUnit* cUnit, int sReg)
64{
65 //For now.
66 return true;
67}
68
69static inline int oatSSASrc(MIR* mir, int num)
70{
71 assert(mir->ssaRep->numUses > num);
72 return mir->ssaRep->uses[num];
73}
74
75extern RegLocation oatEvalLoc(CompilationUnit* cUnit, RegLocation loc,
76 int regClass, bool update);
77/* Mark a temp register as dead. Does not affect allocation state. */
78extern void oatClobber(CompilationUnit* cUnit, int reg);
79
80extern RegLocation oatUpdateLoc(CompilationUnit* cUnit,
81 RegLocation loc);
82
83/* see comments for updateLoc */
84extern RegLocation oatUpdateLocWide(CompilationUnit* cUnit,
85 RegLocation loc);
86
buzbee67bf8852011-08-17 17:51:35 -070087extern void oatMarkLive(CompilationUnit* cUnit, int reg, int sReg);
88
89extern void oatMarkTemp(CompilationUnit* cUnit, int reg);
90
buzbee9e0f9b02011-08-24 15:32:46 -070091extern void oatUnmarkTemp(CompilationUnit* cUnit, int reg);
92
buzbee67bf8852011-08-17 17:51:35 -070093extern void oatMarkDirty(CompilationUnit* cUnit, RegLocation loc);
94
95extern void oatMarkPair(CompilationUnit* cUnit, int lowReg,
96 int highReg);
97
98extern void oatMarkClean(CompilationUnit* cUnit, RegLocation loc);
99
100extern void oatResetDef(CompilationUnit* cUnit, int reg);
101
102extern void oatResetDefLoc(CompilationUnit* cUnit, RegLocation rl);
103
104/* Set up temp & preserved register pools specialized by target */
105extern void oatInitPool(RegisterInfo* regs, int* regNums, int num);
106
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 oatMarkDef(CompilationUnit* cUnit, RegLocation rl,
113 LIR* start, LIR* finish);
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 oatMarkDefWide(CompilationUnit* cUnit, RegLocation rl,
120 LIR* start, LIR* finish);
121
122extern RegLocation oatGetSrcWide(CompilationUnit* cUnit, MIR* mir,
123 int low, int high);
124
125extern RegLocation oatGetDestWide(CompilationUnit* cUnit, MIR* mir,
126 int low, int high);
127// Get the LocRecord associated with an SSA name use.
128extern RegLocation oatGetSrc(CompilationUnit* cUnit, MIR* mir, int num);
buzbeee9a72f62011-09-04 17:59:07 -0700129extern RegLocation oatGetRawSrc(CompilationUnit* cUnit, MIR* mir, int num);
buzbee67bf8852011-08-17 17:51:35 -0700130
131// Get the LocRecord associated with an SSA name def.
132extern RegLocation oatGetDest(CompilationUnit* cUnit, MIR* mir, int num);
133
134extern RegLocation oatGetReturnWide(CompilationUnit* cUnit);
135
136/* Clobber all regs that might be used by an external C call */
137extern void oatClobberCallRegs(CompilationUnit* cUnit);
138
139extern RegisterInfo *oatIsTemp(CompilationUnit* cUnit, int reg);
140
141extern bool oatIsDirty(CompilationUnit* cUnit, int reg);
142
143extern void oatMarkInUse(CompilationUnit* cUnit, int reg);
144
145extern int oatAllocTemp(CompilationUnit* cUnit);
146
147extern int oatAllocTempFloat(CompilationUnit* cUnit);
148
149//REDO: too many assumptions.
150extern int oatAllocTempDouble(CompilationUnit* cUnit);
151
152extern void oatFreeTemp(CompilationUnit* cUnit, int reg);
153
154extern void oatResetDefLocWide(CompilationUnit* cUnit, RegLocation rl);
155
156extern void oatResetDefTracking(CompilationUnit* cUnit);
157
buzbee67bf8852011-08-17 17:51:35 -0700158extern RegisterInfo *oatIsLive(CompilationUnit* cUnit, int reg);
159
160/* To be used when explicitly managing register use */
buzbee2e748f32011-08-29 21:02:19 -0700161extern void oatLockCallTemps(CompilationUnit* cUnit);
buzbee67bf8852011-08-17 17:51:35 -0700162
buzbee0d966cf2011-09-08 17:34:58 -0700163extern void oatFreeCallTemps(CompilationUnit* cUnit);
164
buzbee67bf8852011-08-17 17:51:35 -0700165extern void oatFlushAllRegs(CompilationUnit* cUnit);
166
167extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit);
168
169extern RegLocation oatGetReturn(CompilationUnit* cUnit);
170
171extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit);
172
173/* Clobber any temp associated with an sReg. Could be in either class */
174extern void oatClobberSReg(CompilationUnit* cUnit, int sReg);
175
176/* Return a temp if one is available, -1 otherwise */
177extern int oatAllocFreeTemp(CompilationUnit* cUnit);
178
179/* Attempt to allocate a callee-save register */
180extern int oatAllocPreservedCoreReg(CompilationUnit* cUnit, int sreg);
181extern int oatAllocPreservedFPReg(CompilationUnit* cUnit, int sReg,
182 bool doubleStart);
183
184/*
185 * Similar to oatAllocTemp(), but forces the allocation of a specific
186 * register. No check is made to see if the register was previously
187 * allocated. Use with caution.
188 */
189extern void oatLockTemp(CompilationUnit* cUnit, int reg);
190
191extern RegLocation oatWideToNarrow(CompilationUnit* cUnit,
192 RegLocation rl);
193
194/*
195 * Free all allocated temps in the temp pools. Note that this does
196 * not affect the "liveness" of a temp register, which will stay
197 * live until it is either explicitly killed or reallocated.
198 */
199extern void oatResetRegPool(CompilationUnit* cUnit);
200
201extern void oatClobberAllRegs(CompilationUnit* cUnit);
202
203extern void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2);
204
205extern void oatFlushReg(CompilationUnit* cUnit, int reg);
206
207/*
208 * Architecture-dependent register allocation routines implemented in
209 * ${TARGET_ARCH}/${TARGET_ARCH_VARIANT}/Ralloc.c
210 */
211extern int oatAllocTypedTempPair(CompilationUnit* cUnit,
212 bool fpHint, int regClass);
213
214extern int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint,
215 int regClass);
216
217extern ArmLIR* oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc);
218
219extern 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
228extern void oatDoPromotion(CompilationUnit* cUnit);
229extern int oatVRegOffset(CompilationUnit* cUnit, int reg);
230#endif // ART_SRC_COMPILER_RALLOC_H_