Ralloc.h revision 6a55513b0d268bc0721834050a3698316854fa0a
1/*
2 * Copyright (C) 2009 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/*
18 * This file contains register alloction support and is intended to be
19 * included by:
20 *
21 *        Codegen-$(TARGET_ARCH_VARIANT).c
22 *
23 */
24
25#include "compiler/CompilerUtility.h"
26#include "compiler/CompilerIR.h"
27#include "compiler/Dataflow.h"
28#include "compiler/codegen/arm/ArmLIR.h"
29
30static inline int dvmCompilerS2VReg(CompilationUnit *cUnit, int sReg)
31{
32    assert(sReg != INVALID_SREG);
33    return DECODE_REG(dvmConvertSSARegToDalvik(cUnit, sReg));
34}
35
36/* Reset the tracker to unknown state */
37static inline void dvmCompilerResetNullCheck(CompilationUnit *cUnit)
38{
39    dvmClearAllBits(cUnit->regPool->nullCheckedRegs);
40}
41
42/*
43 * Get the "real" sreg number associated with an sReg slot.  In general,
44 * sReg values passed through codegen are the SSA names created by
45 * dataflow analysis and refer to slot numbers in the cUnit->regLocation
46 * array.  However, renaming is accomplished by simply replacing RegLocation
47 * entries in the cUnit->reglocation[] array.  Therefore, when location
48 * records for operands are first created, we need to ask the locRecord
49 * identified by the dataflow pass what it's new name is.
50 */
51
52static inline int dvmCompilerSRegHi(int lowSreg) {
53    return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
54}
55
56
57static inline bool dvmCompilerLiveOut(CompilationUnit *cUnit, int sReg)
58{
59    //TODO: fully implement
60    return true;
61}
62
63static inline int dvmCompilerSSASrc(MIR *mir, int num)
64{
65    assert(mir->ssaRep->numUses > num);
66    return mir->ssaRep->uses[num];
67}
68
69extern RegLocation dvmCompilerEvalLoc(CompilationUnit *cUnit, RegLocation loc,
70                                      int regClass, bool update);
71/* Mark a temp register as dead.  Does not affect allocation state. */
72extern void dvmCompilerClobber(CompilationUnit *cUnit, int reg);
73
74extern RegLocation dvmCompilerUpdateLoc(CompilationUnit *cUnit,
75                                        RegLocation loc);
76
77/* see comments for updateLoc */
78extern RegLocation dvmCompilerUpdateLocWide(CompilationUnit *cUnit,
79                                            RegLocation loc);
80
81/* Clobber all of the temps that might be used by a handler. */
82extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit);
83
84extern void dvmCompilerMarkLive(CompilationUnit *cUnit, int reg, int sReg);
85
86extern void dvmCompilerMarkDirty(CompilationUnit *cUnit, int reg);
87
88extern void dvmCompilerMarkPair(CompilationUnit *cUnit, int lowReg,
89                                int highReg);
90
91extern void dvmCompilerMarkClean(CompilationUnit *cUnit, int reg);
92
93extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg);
94
95extern void dvmCompilerResetDefLoc(CompilationUnit *cUnit, RegLocation rl);
96
97/* Set up temp & preserved register pools specialized by target */
98extern void dvmCompilerInitPool(RegisterInfo *regs, int *regNums, int num);
99
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 dvmCompilerMarkDef(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 dvmCompilerMarkDefWide(CompilationUnit *cUnit, RegLocation rl,
113                                   LIR *start, LIR *finish);
114
115extern RegLocation dvmCompilerGetSrcWide(CompilationUnit *cUnit, MIR *mir,
116                                         int low, int high);
117
118extern RegLocation dvmCompilerGetDestWide(CompilationUnit *cUnit, MIR *mir,
119                                          int low, int high);
120// Get the LocRecord associated with an SSA name use.
121extern RegLocation dvmCompilerGetSrc(CompilationUnit *cUnit, MIR *mir, int num);
122
123// Get the LocRecord associated with an SSA name def.
124extern RegLocation dvmCompilerGetDest(CompilationUnit *cUnit, MIR *mir,
125                                      int num);
126
127extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit);
128
129/* Clobber all regs that might be used by an external C call */
130extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit);
131
132extern RegisterInfo *dvmCompilerIsTemp(CompilationUnit *cUnit, int reg);
133
134extern void dvmCompilerMarkInUse(CompilationUnit *cUnit, int reg);
135
136extern int dvmCompilerAllocTemp(CompilationUnit *cUnit);
137
138extern int dvmCompilerAllocTempFloat(CompilationUnit *cUnit);
139
140//REDO: too many assumptions.
141extern int dvmCompilerAllocTempDouble(CompilationUnit *cUnit);
142
143extern void dvmCompilerFreeTemp(CompilationUnit *cUnit, int reg);
144
145extern void dvmCompilerResetDefLocWide(CompilationUnit *cUnit, RegLocation rl);
146
147extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
148
149/* Kill the corresponding bit in the null-checked register list */
150extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit,
151                                          RegLocation loc);
152
153//FIXME - this needs to also check the preserved pool.
154extern RegisterInfo *dvmCompilerIsLive(CompilationUnit *cUnit, int reg);
155
156/* To be used when explicitly managing register use */
157extern void dvmCompilerLockAllTemps(CompilationUnit *cUnit);
158
159extern void dvmCompilerFlushAllRegs(CompilationUnit *cUnit);
160
161extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit);
162
163extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit);
164
165extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit);
166
167/* Clobber any temp associated with an sReg.  Could be in either class */
168extern void dvmCompilerClobberSReg(CompilationUnit *cUnit, int sReg);
169
170/* Return a temp if one is available, -1 otherwise */
171extern int dvmCompilerAllocFreeTemp(CompilationUnit *cUnit);
172
173/*
174 * Similar to dvmCompilerAllocTemp(), but forces the allocation of a specific
175 * register.  No check is made to see if the register was previously
176 * allocated.  Use with caution.
177 */
178extern void dvmCompilerLockTemp(CompilationUnit *cUnit, int reg);
179
180extern RegLocation dvmCompilerWideToNarrow(CompilationUnit *cUnit,
181                                           RegLocation rl);
182
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 dvmCompilerResetRegPool(CompilationUnit *cUnit);
189
190extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit);
191
192extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
193