blob: 987638abfc7c5b3bd67a0610aad117ef418a1505 [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 Buzbeec6f10662010-02-09 11:16:15 -080030static inline int dvmCompilerS2VReg(CompilationUnit *cUnit, int sReg)
Ben Cheng5d90c202009-11-22 23:31:11 -080031{
32 assert(sReg != INVALID_SREG);
33 return DECODE_REG(dvmConvertSSARegToDalvik(cUnit, sReg));
34}
35
36/* Reset the tracker to unknown state */
Bill Buzbeec6f10662010-02-09 11:16:15 -080037static inline void dvmCompilerResetNullCheck(CompilationUnit *cUnit)
Ben Cheng5d90c202009-11-22 23:31:11 -080038{
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
Bill Buzbeec6f10662010-02-09 11:16:15 -080052static inline int dvmCompilerSRegHi(int lowSreg) {
Ben Cheng5d90c202009-11-22 23:31:11 -080053 return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1;
54}
55
56
Bill Buzbeec6f10662010-02-09 11:16:15 -080057static inline bool dvmCompilerLiveOut(CompilationUnit *cUnit, int sReg)
Ben Cheng5d90c202009-11-22 23:31:11 -080058{
59 //TODO: fully implement
60 return true;
61}
62
Bill Buzbeec6f10662010-02-09 11:16:15 -080063static inline int dvmCompilerSSASrc(MIR *mir, int num)
Ben Cheng5d90c202009-11-22 23:31:11 -080064{
65 assert(mir->ssaRep->numUses > num);
66 return mir->ssaRep->uses[num];
67}
68
Bill Buzbeec6f10662010-02-09 11:16:15 -080069extern RegLocation dvmCompilerEvalLoc(CompilationUnit *cUnit, RegLocation loc,
70 int regClass, bool update);
Ben Cheng5d90c202009-11-22 23:31:11 -080071/* Mark a temp register as dead. Does not affect allocation state. */
Bill Buzbeec6f10662010-02-09 11:16:15 -080072extern void dvmCompilerClobber(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -080073
Bill Buzbeec6f10662010-02-09 11:16:15 -080074extern RegLocation dvmCompilerUpdateLoc(CompilationUnit *cUnit,
75 RegLocation loc);
Ben Cheng5d90c202009-11-22 23:31:11 -080076
77/* see comments for updateLoc */
Bill Buzbeec6f10662010-02-09 11:16:15 -080078extern RegLocation dvmCompilerUpdateLocWide(CompilationUnit *cUnit,
79 RegLocation loc);
Ben Cheng5d90c202009-11-22 23:31:11 -080080
81/* Clobber all of the temps that might be used by a handler. */
Bill Buzbeec6f10662010-02-09 11:16:15 -080082extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -080083
Bill Buzbeec6f10662010-02-09 11:16:15 -080084extern void dvmCompilerMarkLive(CompilationUnit *cUnit, int reg, int sReg);
Ben Cheng5d90c202009-11-22 23:31:11 -080085
Bill Buzbeec6f10662010-02-09 11:16:15 -080086extern void dvmCompilerMarkDirty(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -080087
Bill Buzbeec6f10662010-02-09 11:16:15 -080088extern void dvmCompilerMarkPair(CompilationUnit *cUnit, int lowReg,
89 int highReg);
Ben Cheng5d90c202009-11-22 23:31:11 -080090
Bill Buzbeec6f10662010-02-09 11:16:15 -080091extern void dvmCompilerMarkClean(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -080092
Bill Buzbeec6f10662010-02-09 11:16:15 -080093extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -080094
Bill Buzbeec6f10662010-02-09 11:16:15 -080095extern void dvmCompilerResetDefLoc(CompilationUnit *cUnit, RegLocation rl);
Ben Cheng5d90c202009-11-22 23:31:11 -080096
97/* Set up temp & preserved register pools specialized by target */
Bill Buzbeec6f10662010-02-09 11:16:15 -080098extern void dvmCompilerInitPool(RegisterInfo *regs, int *regNums, int num);
Ben Cheng5d90c202009-11-22 23:31:11 -080099
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 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800105extern void dvmCompilerMarkDef(CompilationUnit *cUnit, RegLocation rl,
106 LIR *start, LIR *finish);
Ben Cheng5d90c202009-11-22 23:31:11 -0800107/*
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 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800112extern void dvmCompilerMarkDefWide(CompilationUnit *cUnit, RegLocation rl,
113 LIR *start, LIR *finish);
Ben Cheng5d90c202009-11-22 23:31:11 -0800114
Bill Buzbeec6f10662010-02-09 11:16:15 -0800115extern RegLocation dvmCompilerGetSrcWide(CompilationUnit *cUnit, MIR *mir,
Ben Cheng5d90c202009-11-22 23:31:11 -0800116 int low, int high);
117
Bill Buzbeec6f10662010-02-09 11:16:15 -0800118extern RegLocation dvmCompilerGetDestWide(CompilationUnit *cUnit, MIR *mir,
119 int low, int high);
Ben Cheng5d90c202009-11-22 23:31:11 -0800120// Get the LocRecord associated with an SSA name use.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800121extern RegLocation dvmCompilerGetSrc(CompilationUnit *cUnit, MIR *mir, int num);
Ben Cheng5d90c202009-11-22 23:31:11 -0800122
123// Get the LocRecord associated with an SSA name def.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800124extern RegLocation dvmCompilerGetDest(CompilationUnit *cUnit, MIR *mir,
125 int num);
Ben Cheng5d90c202009-11-22 23:31:11 -0800126
Bill Buzbeec6f10662010-02-09 11:16:15 -0800127extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800128
129/* Clobber all regs that might be used by an external C call */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800130extern void dvmCompilerColbberCallRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800131
Bill Buzbeec6f10662010-02-09 11:16:15 -0800132extern RegisterInfo *dvmCompilerIsTemp(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800133
Bill Buzbeec6f10662010-02-09 11:16:15 -0800134extern void dvmcompilerMarkInUse(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800135
Bill Buzbeec6f10662010-02-09 11:16:15 -0800136extern int dvmCompilerAllocTemp(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800137
Bill Buzbeec6f10662010-02-09 11:16:15 -0800138extern int dvmCompilerAllocTempFloat(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800139
140//REDO: too many assumptions.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800141extern int dvmCompilerAllocTempDouble(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800142
Bill Buzbeec6f10662010-02-09 11:16:15 -0800143extern void dvmCompilerFreeTemp(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800144
Bill Buzbeec6f10662010-02-09 11:16:15 -0800145extern void dvmCompilerResetDefLocWide(CompilationUnit *cUnit, RegLocation rl);
Ben Cheng5d90c202009-11-22 23:31:11 -0800146
Bill Buzbeec6f10662010-02-09 11:16:15 -0800147extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800148
149/* Kill the corresponding bit in the null-checked register list */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800150extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit,
151 RegLocation loc);
Ben Cheng5d90c202009-11-22 23:31:11 -0800152
153//FIXME - this needs to also check the preserved pool.
Bill Buzbeec6f10662010-02-09 11:16:15 -0800154extern RegisterInfo *dvmCompilerIsLive(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800155
156/* To be used when explicitly managing register use */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800157extern void dvmCompilerLockAllTemps(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800158
Bill Buzbeec6f10662010-02-09 11:16:15 -0800159extern void dvmCompilerFlushAllRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800160
Bill Buzbeec6f10662010-02-09 11:16:15 -0800161extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800162
Bill Buzbeec6f10662010-02-09 11:16:15 -0800163extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800164
Bill Buzbeec6f10662010-02-09 11:16:15 -0800165extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800166
167/* Clobber any temp associated with an sReg. Could be in either class */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800168extern void dvmCompilerClobberSReg(CompilationUnit *cUnit, int sReg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800169
170/* Return a temp if one is available, -1 otherwise */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800171extern int dvmCompilerAllocFreeTemp(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800172
173/*
Bill Buzbeec6f10662010-02-09 11:16:15 -0800174 * Similar to dvmCompilerAllocTemp(), but forces the allocation of a specific
Ben Cheng5d90c202009-11-22 23:31:11 -0800175 * register. No check is made to see if the register was previously
176 * allocated. Use with caution.
177 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800178extern void dvmCompilerLockTemp(CompilationUnit *cUnit, int reg);
Ben Cheng5d90c202009-11-22 23:31:11 -0800179
Bill Buzbeec6f10662010-02-09 11:16:15 -0800180extern RegLocation dvmCompilerWideToNarrow(CompilationUnit *cUnit,
181 RegLocation rl);
Ben Cheng5d90c202009-11-22 23:31:11 -0800182
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 */
Bill Buzbeec6f10662010-02-09 11:16:15 -0800188extern void dvmCompilerResetRegPool(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800189
Bill Buzbeec6f10662010-02-09 11:16:15 -0800190extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit);
Ben Cheng5d90c202009-11-22 23:31:11 -0800191
Bill Buzbeec6f10662010-02-09 11:16:15 -0800192extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit);