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