blob: cc3e60587a6c1df79edd4ececade90d3aa37635e [file] [log] [blame]
Ben Cheng5d90c202009-11-22 23:31:11 -08001/*
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
Bill Buzbee749e8162010-07-07 06:55:56 -070030/*
31 * Return most flexible allowed register class based on size.
32 * Bug: 2813841
33 * Must use a core register for data types narrower than word (due
34 * to possible unaligned load/store.
35 */
36static inline RegisterClass dvmCompilerRegClassBySize(OpSize size)
37{
38 return (size == kUnsignedHalf ||
39 size == kSignedHalf ||
40 size == kUnsignedByte ||
41 size == kSignedByte ) ? kCoreReg : kAnyReg;
42}
43
Bill Buzbeec6f10662010-02-09 11:16:15 -080044static inline int dvmCompilerS2VReg(CompilationUnit *cUnit, int sReg)
Ben Cheng5d90c202009-11-22 23:31:11 -080045{
46 assert(sReg != INVALID_SREG);
47 return DECODE_REG(dvmConvertSSARegToDalvik(cUnit, sReg));
48}
49
50/* Reset the tracker to unknown state */
Bill Buzbeec6f10662010-02-09 11:16:15 -080051static inline void dvmCompilerResetNullCheck(CompilationUnit *cUnit)
Ben Cheng5d90c202009-11-22 23:31:11 -080052{
53 dvmClearAllBits(cUnit->regPool->nullCheckedRegs);
54}
55
56/*
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.
64 */
65
Bill Buzbeec6f10662010-02-09 11:16:15 -080066static inline int dvmCompilerSRegHi(int lowSreg) {
Ben Cheng5d90c202009-11-22 23:31:11 -080067 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
68}
69
70
Bill Buzbeec6f10662010-02-09 11:16:15 -080071static inline bool dvmCompilerLiveOut(CompilationUnit *cUnit, int sReg)
Ben Cheng5d90c202009-11-22 23:31:11 -080072{
73 //TODO: fully implement
74 return true;
75}
76
Bill Buzbeec6f10662010-02-09 11:16:15 -080077static inline int dvmCompilerSSASrc(MIR *mir, int num)
Ben Cheng5d90c202009-11-22 23:31:11 -080078{
79 assert(mir->ssaRep->numUses > num);
80 return mir->ssaRep->uses[num];
81}
82
Bill Buzbeec6f10662010-02-09 11:16:15 -080083extern RegLocation dvmCompilerEvalLoc(CompilationUnit *cUnit, RegLocation loc,
84 int regClass, bool update);
Ben Cheng5d90c202009-11-22 23:31:11 -080085/* Mark a temp register as dead. Does not affect allocation state. */
Bill Buzbeec6f10662010-02-09 11:16:15 -080086extern void dvmCompilerClobber(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -080087
Bill Buzbeec6f10662010-02-09 11:16:15 -080088extern RegLocation dvmCompilerUpdateLoc(CompilationUnit *cUnit,
89 RegLocation loc);
Ben Cheng5d90c202009-11-22 23:31:11 -080090
91/* see comments for updateLoc */
Bill Buzbeec6f10662010-02-09 11:16:15 -080092extern RegLocation dvmCompilerUpdateLocWide(CompilationUnit *cUnit,
93 RegLocation loc);
Ben Cheng5d90c202009-11-22 23:31:11 -080094
95/* Clobber all of the temps that might be used by a handler. */
Bill Buzbeec6f10662010-02-09 11:16:15 -080096extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -080097
Bill Buzbeec6f10662010-02-09 11:16:15 -080098extern void dvmCompilerMarkLive(CompilationUnit *cUnit, int reg, int sReg);
Ben Cheng5d90c202009-11-22 23:31:11 -080099
Bill Buzbeec6f10662010-02-09 11:16:15 -0800100extern void dvmCompilerMarkDirty(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800101
Bill Buzbeec6f10662010-02-09 11:16:15 -0800102extern void dvmCompilerMarkPair(CompilationUnit *cUnit, int lowReg,
103 int highReg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800104
Bill Buzbeec6f10662010-02-09 11:16:15 -0800105extern void dvmCompilerMarkClean(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800106
Bill Buzbeec6f10662010-02-09 11:16:15 -0800107extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800108
Bill Buzbeec6f10662010-02-09 11:16:15 -0800109extern void dvmCompilerResetDefLoc(CompilationUnit *cUnit, RegLocation rl);
Ben Cheng5d90c202009-11-22 23:31:11 -0800110
111/* Set up temp & preserved register pools specialized by target */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800112extern void dvmCompilerInitPool(RegisterInfo *regs, int *regNums, int num);
Ben Cheng5d90c202009-11-22 23:31:11 -0800113
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 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800119extern void dvmCompilerMarkDef(CompilationUnit *cUnit, RegLocation rl,
120 LIR *start, LIR *finish);
Ben Cheng5d90c202009-11-22 23:31:11 -0800121/*
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
124 * sequence.
125 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800126extern void dvmCompilerMarkDefWide(CompilationUnit *cUnit, RegLocation rl,
127 LIR *start, LIR *finish);
Ben Cheng5d90c202009-11-22 23:31:11 -0800128
Bill Buzbeec6f10662010-02-09 11:16:15 -0800129extern RegLocation dvmCompilerGetSrcWide(CompilationUnit *cUnit, MIR *mir,
Ben Cheng5d90c202009-11-22 23:31:11 -0800130 int low, int high);
131
Bill Buzbeec6f10662010-02-09 11:16:15 -0800132extern RegLocation dvmCompilerGetDestWide(CompilationUnit *cUnit, MIR *mir,
133 int low, int high);
Ben Cheng5d90c202009-11-22 23:31:11 -0800134// Get the LocRecord associated with an SSA name use.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800135extern RegLocation dvmCompilerGetSrc(CompilationUnit *cUnit, MIR *mir, int num);
Ben Cheng5d90c202009-11-22 23:31:11 -0800136
137// Get the LocRecord associated with an SSA name def.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800138extern RegLocation dvmCompilerGetDest(CompilationUnit *cUnit, MIR *mir,
139 int num);
Ben Cheng5d90c202009-11-22 23:31:11 -0800140
Bill Buzbeec6f10662010-02-09 11:16:15 -0800141extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800142
143/* Clobber all regs that might be used by an external C call */
Elliott Hughes6a555132010-02-25 15:41:42 -0800144extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800145
Bill Buzbeec6f10662010-02-09 11:16:15 -0800146extern RegisterInfo *dvmCompilerIsTemp(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800147
Elliott Hughes6a555132010-02-25 15:41:42 -0800148extern void dvmCompilerMarkInUse(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800149
Bill Buzbeec6f10662010-02-09 11:16:15 -0800150extern int dvmCompilerAllocTemp(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800151
Bill Buzbeec6f10662010-02-09 11:16:15 -0800152extern int dvmCompilerAllocTempFloat(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800153
154//REDO: too many assumptions.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800155extern int dvmCompilerAllocTempDouble(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800156
Bill Buzbeec6f10662010-02-09 11:16:15 -0800157extern void dvmCompilerFreeTemp(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800158
Bill Buzbeec6f10662010-02-09 11:16:15 -0800159extern void dvmCompilerResetDefLocWide(CompilationUnit *cUnit, RegLocation rl);
Ben Cheng5d90c202009-11-22 23:31:11 -0800160
Bill Buzbeec6f10662010-02-09 11:16:15 -0800161extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800162
163/* Kill the corresponding bit in the null-checked register list */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800164extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit,
165 RegLocation loc);
Ben Cheng5d90c202009-11-22 23:31:11 -0800166
167//FIXME - this needs to also check the preserved pool.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800168extern RegisterInfo *dvmCompilerIsLive(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800169
170/* To be used when explicitly managing register use */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800171extern void dvmCompilerLockAllTemps(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800172
Bill Buzbeec6f10662010-02-09 11:16:15 -0800173extern void dvmCompilerFlushAllRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800174
Bill Buzbeec6f10662010-02-09 11:16:15 -0800175extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800176
Bill Buzbeec6f10662010-02-09 11:16:15 -0800177extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800178
Bill Buzbeec6f10662010-02-09 11:16:15 -0800179extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800180
181/* Clobber any temp associated with an sReg. Could be in either class */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800182extern void dvmCompilerClobberSReg(CompilationUnit *cUnit, int sReg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800183
184/* Return a temp if one is available, -1 otherwise */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800185extern int dvmCompilerAllocFreeTemp(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800186
187/*
Bill Buzbeec6f10662010-02-09 11:16:15 -0800188 * Similar to dvmCompilerAllocTemp(), but forces the allocation of a specific
Ben Cheng5d90c202009-11-22 23:31:11 -0800189 * register. No check is made to see if the register was previously
190 * allocated. Use with caution.
191 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800192extern void dvmCompilerLockTemp(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800193
Bill Buzbeec6f10662010-02-09 11:16:15 -0800194extern RegLocation dvmCompilerWideToNarrow(CompilationUnit *cUnit,
195 RegLocation rl);
Ben Cheng5d90c202009-11-22 23:31:11 -0800196
197/*
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.
201 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800202extern void dvmCompilerResetRegPool(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800203
Bill Buzbeec6f10662010-02-09 11:16:15 -0800204extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800205
Bill Buzbeec6f10662010-02-09 11:16:15 -0800206extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);