buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | #ifndef ART_SRC_COMPILER_RALLOC_H_ |
| 18 | #define ART_SRC_COMPILER_RALLOC_H_ |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 19 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 20 | /* |
| 21 | * This file contains target independent register alloction support. |
| 22 | */ |
| 23 | |
| 24 | #include "../CompilerUtility.h" |
| 25 | #include "../CompilerIR.h" |
| 26 | #include "../Dataflow.h" |
| 27 | #include "arm/ArmLIR.h" |
| 28 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 29 | namespace art { |
| 30 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 31 | /* |
| 32 | * Return most flexible allowed register class based on size. |
| 33 | * Bug: 2813841 |
| 34 | * Must use a core register for data types narrower than word (due |
| 35 | * to possible unaligned load/store. |
| 36 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 37 | STATIC inline RegisterClass oatRegClassBySize(OpSize size) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 38 | { |
| 39 | return (size == kUnsignedHalf || |
| 40 | size == kSignedHalf || |
| 41 | size == kUnsignedByte || |
| 42 | size == kSignedByte ) ? kCoreReg : kAnyReg; |
| 43 | } |
| 44 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 45 | STATIC inline int oatS2VReg(CompilationUnit* cUnit, int sReg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 46 | { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 47 | DCHECK_NE(sReg, INVALID_SREG); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 48 | return DECODE_REG(oatConvertSSARegToDalvik(cUnit, sReg)); |
| 49 | } |
| 50 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 51 | /* |
| 52 | * Get the "real" sreg number associated with an sReg slot. In general, |
| 53 | * sReg values passed through codegen are the SSA names created by |
| 54 | * dataflow analysis and refer to slot numbers in the cUnit->regLocation |
| 55 | * array. However, renaming is accomplished by simply replacing RegLocation |
| 56 | * entries in the cUnit->reglocation[] array. Therefore, when location |
| 57 | * records for operands are first created, we need to ask the locRecord |
| 58 | * identified by the dataflow pass what it's new name is. |
| 59 | */ |
| 60 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 61 | STATIC inline int oatSRegHi(int lowSreg) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 62 | return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1; |
| 63 | } |
| 64 | |
| 65 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 66 | STATIC inline bool oatLiveOut(CompilationUnit* cUnit, int sReg) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 67 | { |
| 68 | //For now. |
| 69 | return true; |
| 70 | } |
| 71 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 72 | STATIC inline int oatSSASrc(MIR* mir, int num) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 73 | { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 74 | DCHECK_GT(mir->ssaRep->numUses, num); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 75 | return mir->ssaRep->uses[num]; |
| 76 | } |
| 77 | |
| 78 | extern RegLocation oatEvalLoc(CompilationUnit* cUnit, RegLocation loc, |
| 79 | int regClass, bool update); |
| 80 | /* Mark a temp register as dead. Does not affect allocation state. */ |
| 81 | extern void oatClobber(CompilationUnit* cUnit, int reg); |
| 82 | |
| 83 | extern RegLocation oatUpdateLoc(CompilationUnit* cUnit, |
| 84 | RegLocation loc); |
| 85 | |
| 86 | /* see comments for updateLoc */ |
| 87 | extern RegLocation oatUpdateLocWide(CompilationUnit* cUnit, |
| 88 | RegLocation loc); |
| 89 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 90 | extern RegLocation oatUpdateRawLoc(CompilationUnit* cUnit, |
| 91 | RegLocation loc); |
| 92 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 93 | extern void oatMarkLive(CompilationUnit* cUnit, int reg, int sReg); |
| 94 | |
| 95 | extern void oatMarkTemp(CompilationUnit* cUnit, int reg); |
| 96 | |
buzbee | 9e0f9b0 | 2011-08-24 15:32:46 -0700 | [diff] [blame] | 97 | extern void oatUnmarkTemp(CompilationUnit* cUnit, int reg); |
| 98 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 99 | extern void oatMarkDirty(CompilationUnit* cUnit, RegLocation loc); |
| 100 | |
| 101 | extern void oatMarkPair(CompilationUnit* cUnit, int lowReg, |
| 102 | int highReg); |
| 103 | |
| 104 | extern void oatMarkClean(CompilationUnit* cUnit, RegLocation loc); |
| 105 | |
| 106 | extern void oatResetDef(CompilationUnit* cUnit, int reg); |
| 107 | |
| 108 | extern void oatResetDefLoc(CompilationUnit* cUnit, RegLocation rl); |
| 109 | |
| 110 | /* Set up temp & preserved register pools specialized by target */ |
| 111 | extern void oatInitPool(RegisterInfo* regs, int* regNums, int num); |
| 112 | |
| 113 | /* |
| 114 | * Mark the beginning and end LIR of a def sequence. Note that |
| 115 | * on entry start points to the LIR prior to the beginning of the |
| 116 | * sequence. |
| 117 | */ |
| 118 | extern void oatMarkDef(CompilationUnit* cUnit, RegLocation rl, |
| 119 | LIR* start, LIR* finish); |
| 120 | /* |
| 121 | * Mark the beginning and end LIR of a def sequence. Note that |
| 122 | * on entry start points to the LIR prior to the beginning of the |
| 123 | * sequence. |
| 124 | */ |
| 125 | extern void oatMarkDefWide(CompilationUnit* cUnit, RegLocation rl, |
| 126 | LIR* start, LIR* finish); |
| 127 | |
| 128 | extern RegLocation oatGetSrcWide(CompilationUnit* cUnit, MIR* mir, |
| 129 | int low, int high); |
| 130 | |
| 131 | extern RegLocation oatGetDestWide(CompilationUnit* cUnit, MIR* mir, |
| 132 | int low, int high); |
| 133 | // Get the LocRecord associated with an SSA name use. |
| 134 | extern RegLocation oatGetSrc(CompilationUnit* cUnit, MIR* mir, int num); |
buzbee | e9a72f6 | 2011-09-04 17:59:07 -0700 | [diff] [blame] | 135 | extern RegLocation oatGetRawSrc(CompilationUnit* cUnit, MIR* mir, int num); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 136 | |
| 137 | // Get the LocRecord associated with an SSA name def. |
| 138 | extern RegLocation oatGetDest(CompilationUnit* cUnit, MIR* mir, int num); |
| 139 | |
| 140 | extern RegLocation oatGetReturnWide(CompilationUnit* cUnit); |
| 141 | |
| 142 | /* Clobber all regs that might be used by an external C call */ |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 143 | extern void oatClobberCalleeSave(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 144 | |
| 145 | extern RegisterInfo *oatIsTemp(CompilationUnit* cUnit, int reg); |
| 146 | |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 147 | extern RegisterInfo *oatIsPromoted(CompilationUnit* cUnit, int reg); |
| 148 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 149 | extern bool oatIsDirty(CompilationUnit* cUnit, int reg); |
| 150 | |
| 151 | extern void oatMarkInUse(CompilationUnit* cUnit, int reg); |
| 152 | |
| 153 | extern int oatAllocTemp(CompilationUnit* cUnit); |
| 154 | |
| 155 | extern int oatAllocTempFloat(CompilationUnit* cUnit); |
| 156 | |
| 157 | //REDO: too many assumptions. |
| 158 | extern int oatAllocTempDouble(CompilationUnit* cUnit); |
| 159 | |
| 160 | extern void oatFreeTemp(CompilationUnit* cUnit, int reg); |
| 161 | |
| 162 | extern void oatResetDefLocWide(CompilationUnit* cUnit, RegLocation rl); |
| 163 | |
| 164 | extern void oatResetDefTracking(CompilationUnit* cUnit); |
| 165 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 166 | extern RegisterInfo *oatIsLive(CompilationUnit* cUnit, int reg); |
| 167 | |
| 168 | /* To be used when explicitly managing register use */ |
buzbee | 2e748f3 | 2011-08-29 21:02:19 -0700 | [diff] [blame] | 169 | extern void oatLockCallTemps(CompilationUnit* cUnit); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 170 | |
buzbee | 0d966cf | 2011-09-08 17:34:58 -0700 | [diff] [blame] | 171 | extern void oatFreeCallTemps(CompilationUnit* cUnit); |
| 172 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 173 | extern void oatFlushAllRegs(CompilationUnit* cUnit); |
| 174 | |
| 175 | extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit); |
| 176 | |
| 177 | extern RegLocation oatGetReturn(CompilationUnit* cUnit); |
| 178 | |
| 179 | extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit); |
| 180 | |
| 181 | /* Clobber any temp associated with an sReg. Could be in either class */ |
| 182 | extern void oatClobberSReg(CompilationUnit* cUnit, int sReg); |
| 183 | |
| 184 | /* Return a temp if one is available, -1 otherwise */ |
| 185 | extern int oatAllocFreeTemp(CompilationUnit* cUnit); |
| 186 | |
| 187 | /* Attempt to allocate a callee-save register */ |
| 188 | extern int oatAllocPreservedCoreReg(CompilationUnit* cUnit, int sreg); |
| 189 | extern int oatAllocPreservedFPReg(CompilationUnit* cUnit, int sReg, |
| 190 | bool doubleStart); |
| 191 | |
| 192 | /* |
| 193 | * Similar to oatAllocTemp(), but forces the allocation of a specific |
| 194 | * register. No check is made to see if the register was previously |
| 195 | * allocated. Use with caution. |
| 196 | */ |
| 197 | extern void oatLockTemp(CompilationUnit* cUnit, int reg); |
| 198 | |
| 199 | extern RegLocation oatWideToNarrow(CompilationUnit* cUnit, |
| 200 | RegLocation rl); |
| 201 | |
| 202 | /* |
| 203 | * Free all allocated temps in the temp pools. Note that this does |
| 204 | * not affect the "liveness" of a temp register, which will stay |
| 205 | * live until it is either explicitly killed or reallocated. |
| 206 | */ |
| 207 | extern void oatResetRegPool(CompilationUnit* cUnit); |
| 208 | |
| 209 | extern void oatClobberAllRegs(CompilationUnit* cUnit); |
| 210 | |
| 211 | extern void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2); |
| 212 | |
| 213 | extern void oatFlushReg(CompilationUnit* cUnit, int reg); |
| 214 | |
| 215 | /* |
| 216 | * Architecture-dependent register allocation routines implemented in |
| 217 | * ${TARGET_ARCH}/${TARGET_ARCH_VARIANT}/Ralloc.c |
| 218 | */ |
| 219 | extern int oatAllocTypedTempPair(CompilationUnit* cUnit, |
| 220 | bool fpHint, int regClass); |
| 221 | |
| 222 | extern int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint, |
| 223 | int regClass); |
| 224 | |
| 225 | extern ArmLIR* oatRegCopy(CompilationUnit* cUnit, int rDest, int rSrc); |
| 226 | |
| 227 | extern void oatRegCopyWide(CompilationUnit* cUnit, int destLo, |
| 228 | int destHi, int srcLo, int srcHi); |
| 229 | |
| 230 | extern void oatFlushRegImpl(CompilationUnit* cUnit, int rBase, |
| 231 | int displacement, int rSrc, OpSize size); |
| 232 | |
| 233 | extern void oatFlushRegWideImpl(CompilationUnit* cUnit, int rBase, |
| 234 | int displacement, int rSrcLo, int rSrcHi); |
| 235 | |
| 236 | extern void oatDoPromotion(CompilationUnit* cUnit); |
| 237 | extern int oatVRegOffset(CompilationUnit* cUnit, int reg); |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 238 | extern int oatSRegOffset(CompilationUnit* cUnit, int reg); |
buzbee | 6181f79 | 2011-09-29 11:14:04 -0700 | [diff] [blame] | 239 | extern void oatDumpCoreRegPool(CompilationUnit* cUint); |
| 240 | extern void oatDumpFPRegPool(CompilationUnit* cUint); |
| 241 | extern bool oatCheckCorePoolSanity(CompilationUnit* cUnit); |
buzbee | 6825326 | 2011-10-07 14:02:25 -0700 | [diff] [blame] | 242 | extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg); |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 243 | |
| 244 | } // namespace art |
| 245 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 246 | #endif // ART_SRC_COMPILER_RALLOC_H_ |