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