2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * This file contains register alloction support and is intended to be
21 * Codegen-$(TARGET_ARCH_VARIANT).c
25 #include "compiler/CompilerUtility.h"
26 #include "compiler/CompilerIR.h"
27 #include "compiler/Dataflow.h"
28 #include "compiler/codegen/mips/MipsLIR.h"
31 * Return most flexible allowed register class based on size.
33 * Must use a core register for data types narrower than word (due
34 * to possible unaligned load/store.
36 static inline RegisterClass dvmCompilerRegClassBySize(OpSize size)
38 return (size == kUnsignedHalf ||
39 size == kSignedHalf ||
40 size == kUnsignedByte ||
41 size == kSignedByte ) ? kCoreReg : kAnyReg;
44 static inline int dvmCompilerS2VReg(CompilationUnit *cUnit, int sReg)
46 assert(sReg != INVALID_SREG);
47 return DECODE_REG(dvmConvertSSARegToDalvik(cUnit, sReg));
50 /* Reset the tracker to unknown state */
51 static inline void dvmCompilerResetNullCheck(CompilationUnit *cUnit)
53 dvmClearAllBits(cUnit->regPool->nullCheckedRegs);
57 * Get the "real" sreg number associated with an sReg slot. In general,
58 * sReg values passed through codegen are the SSA names created by
59 * dataflow analysis and refer to slot numbers in the cUnit->regLocation
60 * array. However, renaming is accomplished by simply replacing RegLocation
61 * entries in the cUnit->reglocation[] array. Therefore, when location
62 * records for operands are first created, we need to ask the locRecord
63 * identified by the dataflow pass what it's new name is.
66 static inline int dvmCompilerSRegHi(int lowSreg) {
67 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
71 static inline bool dvmCompilerLiveOut(CompilationUnit *cUnit, int sReg)
73 //TODO: fully implement
77 static inline int dvmCompilerSSASrc(MIR *mir, int num)
79 assert(mir->ssaRep->numUses > num);
80 return mir->ssaRep->uses[num];
83 extern RegLocation dvmCompilerEvalLoc(CompilationUnit *cUnit, RegLocation loc,
84 int regClass, bool update);
85 /* Mark a temp register as dead. Does not affect allocation state. */
86 extern void dvmCompilerClobber(CompilationUnit *cUnit, int reg);
88 extern RegLocation dvmCompilerUpdateLoc(CompilationUnit *cUnit,
91 /* see comments for updateLoc */
92 extern RegLocation dvmCompilerUpdateLocWide(CompilationUnit *cUnit,
95 /* Clobber all of the temps that might be used by a handler. */
96 extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit);
98 extern void dvmCompilerMarkLive(CompilationUnit *cUnit, int reg, int sReg);
100 extern void dvmCompilerMarkDirty(CompilationUnit *cUnit, int reg);
102 extern void dvmCompilerMarkPair(CompilationUnit *cUnit, int lowReg,
105 extern void dvmCompilerMarkClean(CompilationUnit *cUnit, int reg);
107 extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg);
109 extern void dvmCompilerResetDefLoc(CompilationUnit *cUnit, RegLocation rl);
111 /* Set up temp & preserved register pools specialized by target */
112 extern void dvmCompilerInitPool(RegisterInfo *regs, int *regNums, int num);
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
119 extern void dvmCompilerMarkDef(CompilationUnit *cUnit, RegLocation rl,
120 LIR *start, LIR *finish);
122 * Mark the beginning and end LIR of a def sequence. Note that
123 * on entry start points to the LIR prior to the beginning of the
126 extern void dvmCompilerMarkDefWide(CompilationUnit *cUnit, RegLocation rl,
127 LIR *start, LIR *finish);
129 extern RegLocation dvmCompilerGetSrcWide(CompilationUnit *cUnit, MIR *mir,
132 extern RegLocation dvmCompilerGetDestWide(CompilationUnit *cUnit, MIR *mir,
134 // Get the LocRecord associated with an SSA name use.
135 extern RegLocation dvmCompilerGetSrc(CompilationUnit *cUnit, MIR *mir, int num);
137 // Get the LocRecord associated with an SSA name def.
138 extern RegLocation dvmCompilerGetDest(CompilationUnit *cUnit, MIR *mir,
141 extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit);
143 /* Clobber all regs that might be used by an external C call */
144 extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit);
146 extern RegisterInfo *dvmCompilerIsTemp(CompilationUnit *cUnit, int reg);
148 extern void dvmCompilerMarkInUse(CompilationUnit *cUnit, int reg);
150 extern int dvmCompilerAllocTemp(CompilationUnit *cUnit);
152 extern int dvmCompilerAllocTempFloat(CompilationUnit *cUnit);
154 //REDO: too many assumptions.
155 extern int dvmCompilerAllocTempDouble(CompilationUnit *cUnit);
157 extern void dvmCompilerFreeTemp(CompilationUnit *cUnit, int reg);
159 extern void dvmCompilerResetDefLocWide(CompilationUnit *cUnit, RegLocation rl);
161 extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
163 /* Kill the corresponding bit in the null-checked register list */
164 extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit,
167 //FIXME - this needs to also check the preserved pool.
168 extern RegisterInfo *dvmCompilerIsLive(CompilationUnit *cUnit, int reg);
170 /* To be used when explicitly managing register use */
171 extern void dvmCompilerLockAllTemps(CompilationUnit *cUnit);
173 extern void dvmCompilerFlushAllRegs(CompilationUnit *cUnit);
175 extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit);
177 extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit);
179 extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit);
181 /* Clobber any temp associated with an sReg. Could be in either class */
182 extern void dvmCompilerClobberSReg(CompilationUnit *cUnit, int sReg);
184 /* Return a temp if one is available, -1 otherwise */
185 extern int dvmCompilerAllocFreeTemp(CompilationUnit *cUnit);
188 * Similar to dvmCompilerAllocTemp(), but forces the allocation of a specific
189 * register. No check is made to see if the register was previously
190 * allocated. Use with caution.
192 extern void dvmCompilerLockTemp(CompilationUnit *cUnit, int reg);
194 extern RegLocation dvmCompilerWideToNarrow(CompilationUnit *cUnit,
198 * Free all allocated temps in the temp pools. Note that this does
199 * not affect the "liveness" of a temp register, which will stay
200 * live until it is either explicitly killed or reallocated.
202 extern void dvmCompilerResetRegPool(CompilationUnit *cUnit);
204 extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit);
206 extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);