| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 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 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 30 | static inline int dvmCompilerS2VReg(CompilationUnit *cUnit, int sReg) |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 31 | { |
| 32 | assert(sReg != INVALID_SREG); |
| 33 | return DECODE_REG(dvmConvertSSARegToDalvik(cUnit, sReg)); |
| 34 | } |
| 35 | |
| 36 | /* Reset the tracker to unknown state */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 37 | static inline void dvmCompilerResetNullCheck(CompilationUnit *cUnit) |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 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 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 52 | static inline int dvmCompilerSRegHi(int lowSreg) { |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 53 | return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1; |
| 54 | } |
| 55 | |
| 56 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 57 | static inline bool dvmCompilerLiveOut(CompilationUnit *cUnit, int sReg) |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 58 | { |
| 59 | //TODO: fully implement |
| 60 | return true; |
| 61 | } |
| 62 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 63 | static inline int dvmCompilerSSASrc(MIR *mir, int num) |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 64 | { |
| 65 | assert(mir->ssaRep->numUses > num); |
| 66 | return mir->ssaRep->uses[num]; |
| 67 | } |
| 68 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 69 | extern RegLocation dvmCompilerEvalLoc(CompilationUnit *cUnit, RegLocation loc, |
| 70 | int regClass, bool update); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 71 | /* Mark a temp register as dead. Does not affect allocation state. */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 72 | extern void dvmCompilerClobber(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 73 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 74 | extern RegLocation dvmCompilerUpdateLoc(CompilationUnit *cUnit, |
| 75 | RegLocation loc); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 76 | |
| 77 | /* see comments for updateLoc */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 78 | extern RegLocation dvmCompilerUpdateLocWide(CompilationUnit *cUnit, |
| 79 | RegLocation loc); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 80 | |
| 81 | /* Clobber all of the temps that might be used by a handler. */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 82 | extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 83 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 84 | extern void dvmCompilerMarkLive(CompilationUnit *cUnit, int reg, int sReg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 85 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 86 | extern void dvmCompilerMarkDirty(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 87 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 88 | extern void dvmCompilerMarkPair(CompilationUnit *cUnit, int lowReg, |
| 89 | int highReg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 90 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 91 | extern void dvmCompilerMarkClean(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 92 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 93 | extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 94 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 95 | extern void dvmCompilerResetDefLoc(CompilationUnit *cUnit, RegLocation rl); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 96 | |
| 97 | /* Set up temp & preserved register pools specialized by target */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 98 | extern void dvmCompilerInitPool(RegisterInfo *regs, int *regNums, int num); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 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 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 105 | extern void dvmCompilerMarkDef(CompilationUnit *cUnit, RegLocation rl, |
| 106 | LIR *start, LIR *finish); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 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 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 112 | extern void dvmCompilerMarkDefWide(CompilationUnit *cUnit, RegLocation rl, |
| 113 | LIR *start, LIR *finish); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 114 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 115 | extern RegLocation dvmCompilerGetSrcWide(CompilationUnit *cUnit, MIR *mir, |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 116 | int low, int high); |
| 117 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 118 | extern RegLocation dvmCompilerGetDestWide(CompilationUnit *cUnit, MIR *mir, |
| 119 | int low, int high); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 120 | // Get the LocRecord associated with an SSA name use. |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 121 | extern RegLocation dvmCompilerGetSrc(CompilationUnit *cUnit, MIR *mir, int num); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 122 | |
| 123 | // Get the LocRecord associated with an SSA name def. |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 124 | extern RegLocation dvmCompilerGetDest(CompilationUnit *cUnit, MIR *mir, |
| 125 | int num); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 126 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 127 | extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 128 | |
| 129 | /* Clobber all regs that might be used by an external C call */ |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame^] | 130 | extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 131 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 132 | extern RegisterInfo *dvmCompilerIsTemp(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 133 | |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame^] | 134 | extern void dvmCompilerMarkInUse(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 135 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 136 | extern int dvmCompilerAllocTemp(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 137 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 138 | extern int dvmCompilerAllocTempFloat(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 139 | |
| 140 | //REDO: too many assumptions. |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 141 | extern int dvmCompilerAllocTempDouble(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 142 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 143 | extern void dvmCompilerFreeTemp(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 144 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 145 | extern void dvmCompilerResetDefLocWide(CompilationUnit *cUnit, RegLocation rl); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 146 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 147 | extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 148 | |
| 149 | /* Kill the corresponding bit in the null-checked register list */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 150 | extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit, |
| 151 | RegLocation loc); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 152 | |
| 153 | //FIXME - this needs to also check the preserved pool. |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 154 | extern RegisterInfo *dvmCompilerIsLive(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 155 | |
| 156 | /* To be used when explicitly managing register use */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 157 | extern void dvmCompilerLockAllTemps(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 158 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 159 | extern void dvmCompilerFlushAllRegs(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 160 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 161 | extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 162 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 163 | extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 164 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 165 | extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 166 | |
| 167 | /* Clobber any temp associated with an sReg. Could be in either class */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 168 | extern void dvmCompilerClobberSReg(CompilationUnit *cUnit, int sReg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 169 | |
| 170 | /* Return a temp if one is available, -1 otherwise */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 171 | extern int dvmCompilerAllocFreeTemp(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 172 | |
| 173 | /* |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 174 | * Similar to dvmCompilerAllocTemp(), but forces the allocation of a specific |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 175 | * register. No check is made to see if the register was previously |
| 176 | * allocated. Use with caution. |
| 177 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 178 | extern void dvmCompilerLockTemp(CompilationUnit *cUnit, int reg); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 179 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 180 | extern RegLocation dvmCompilerWideToNarrow(CompilationUnit *cUnit, |
| 181 | RegLocation rl); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 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 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 188 | extern void dvmCompilerResetRegPool(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 189 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 190 | extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 191 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 192 | extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit); |