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 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 17 | #ifndef ART_SRC_COMPILER_CODEGEN_RALLOCUTIL_H_ |
| 18 | #define ART_SRC_COMPILER_CODEGEN_RALLOCUTIL_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 | |
Brian Carlstrom | 641ce03 | 2013-01-31 15:21:37 -0800 | [diff] [blame] | 24 | #include "compiler/compiler_ir.h" |
| 25 | #include "compiler/compiler_utility.h" |
| 26 | #include "compiler/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; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 33 | int s_reg; |
| 34 | bool double_start; // Starting v_reg 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 | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 37 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 38 | * Get the "real" sreg number associated with an s_reg slot. In general, |
| 39 | * s_reg values passed through codegen are the SSA names created by |
| 40 | * dataflow analysis and refer to slot numbers in the cu->reg_location |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 41 | * array. However, renaming is accomplished by simply replacing RegLocation |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 42 | * entries in the cu->reglocation[] array. Therefore, when location |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 43 | * records for operands are first created, we need to ask the locRecord |
| 44 | * identified by the dataflow pass what it's new name is. |
| 45 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 46 | inline int GetSRegHi(int lowSreg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 47 | return (lowSreg == INVALID_SREG) ? INVALID_SREG : lowSreg + 1; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 48 | } |
| 49 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 50 | inline bool oat_live_out(CompilationUnit* cu, int s_reg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 51 | //For now. |
| 52 | return true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 55 | inline int oatSSASrc(MIR* mir, int num) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 56 | DCHECK_GT(mir->ssa_rep->num_uses, num); |
| 57 | return mir->ssa_rep->uses[num]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 58 | } |
| 59 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 60 | void ClobberSReg(CompilationUnit* cu, int s_reg); |
| 61 | RegLocation EvalLoc(CompilationUnit* cu, RegLocation loc, |
| 62 | int reg_class, bool update); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 63 | // Mark a temp register as dead. Does not affect allocation state. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 64 | void Clobber(CompilationUnit* cu, int reg); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 65 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 66 | RegLocation UpdateLoc(CompilationUnit* cu, RegLocation loc); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 67 | RegLocation UpdateLocWide(CompilationUnit* cu, RegLocation loc); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 68 | RegLocation UpdateRawLoc(CompilationUnit* cu, RegLocation loc); |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 69 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 70 | void MarkLive(CompilationUnit* cu, int reg, int s_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 71 | void MarkTemp(CompilationUnit* cu, int reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 72 | void UnmarkTemp(CompilationUnit* cu, int reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 73 | void MarkDirty(CompilationUnit* cu, RegLocation loc); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 74 | void MarkPair(CompilationUnit* cu, int low_reg, int high_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 75 | void MarkClean(CompilationUnit* cu, RegLocation loc); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 76 | void ResetDef(CompilationUnit* cu, int reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 77 | void ResetDefLoc(CompilationUnit* cu, RegLocation rl); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 78 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 79 | // Set up temp & preserved register pools specialized by target. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 80 | void CompilerInitPool(RegisterInfo* regs, int* reg_nums, int num); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 81 | |
| 82 | /* |
| 83 | * Mark the beginning and end LIR of a def sequence. Note that |
| 84 | * on entry start points to the LIR prior to the beginning of the |
| 85 | * sequence. |
| 86 | */ |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 87 | void MarkDef(CompilationUnit* cu, RegLocation rl, LIR* start, LIR* finish); |
| 88 | void MarkDefWide(CompilationUnit* cu, RegLocation rl, LIR* start, LIR* finish); |
| 89 | void ResetDefLocWide(CompilationUnit* cu, RegLocation rl); |
| 90 | void ResetDefTracking(CompilationUnit* cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 91 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 92 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 93 | // Get the LocRecord associated with an SSA name use. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 94 | RegLocation GetSrc(CompilationUnit* cu, MIR* mir, int num); |
| 95 | RegLocation GetSrcWide(CompilationUnit* cu, MIR* mir, int low); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 96 | // Non-width checking version. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 97 | RegLocation GetRawSrc(CompilationUnit* cu, MIR* mir, int num); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 98 | |
| 99 | // Get the LocRecord associated with an SSA name def. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 100 | RegLocation GetDest(CompilationUnit* cu, MIR* mir); |
| 101 | RegLocation GetDestWide(CompilationUnit* cu, MIR* mir); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 102 | // Non-width checking version. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 103 | RegLocation GetRawDest(CompilationUnit* cu, MIR* mir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 104 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 105 | // Clobber all regs that might be used by an external C call. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 106 | void ClobberCalleeSave(CompilationUnit* cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 108 | RegisterInfo *IsTemp(CompilationUnit* cu, int reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 109 | RegisterInfo *IsPromoted(CompilationUnit* cu, int reg); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 110 | RegisterInfo *IsLive(CompilationUnit* cu, int reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 111 | bool IsDirty(CompilationUnit* cu, int reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 112 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 113 | void MarkInUse(CompilationUnit* cu, int reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 114 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 115 | int AllocTemp(CompilationUnit* cu); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 116 | int AllocTempFloat(CompilationUnit* cu); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 117 | int AllocTempDouble(CompilationUnit* cu); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 118 | void FreeTemp(CompilationUnit* cu, int reg); |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 119 | // Return a temp if one is available, -1 otherwise. |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 120 | int AllocFreeTemp(CompilationUnit* cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 121 | /* |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 122 | * Attempt to allocate a callee-save register. |
buzbee | 52a77fc | 2012-11-20 19:50:46 -0800 | [diff] [blame] | 123 | * Similar to AllocTemp(), but forces the allocation of a specific |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 124 | * register. No check is made to see if the register was previously |
| 125 | * allocated. Use with caution. |
| 126 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 127 | void LockTemp(CompilationUnit* cu, int reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 128 | |
buzbee | 02031b1 | 2012-11-23 09:41:35 -0800 | [diff] [blame] | 129 | /* To be used when explicitly managing register use */ |
| 130 | void LockCallTemps(CompilationUnit* cu); |
| 131 | void FreeCallTemps(CompilationUnit* cu); |
| 132 | |
| 133 | void FlushAllRegs(CompilationUnit* cu); |
| 134 | |
| 135 | RegLocation GetReturn(CompilationUnit* cu, bool is_float); |
| 136 | RegLocation GetReturnWide(CompilationUnit* cu, bool is_double); |
| 137 | RegLocation GetBadLoc(); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 138 | RegLocation WideToNarrow(CompilationUnit* cu, RegLocation rl); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 139 | |
| 140 | /* |
| 141 | * Free all allocated temps in the temp pools. Note that this does |
| 142 | * not affect the "liveness" of a temp register, which will stay |
| 143 | * live until it is either explicitly killed or reallocated. |
| 144 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 145 | void ResetRegPool(CompilationUnit* cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 146 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 147 | void ClobberAllRegs(CompilationUnit* cu); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 148 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 149 | void FlushRegWide(CompilationUnit* cu, int reg1, int reg2); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 150 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 151 | void FlushReg(CompilationUnit* cu, int reg); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 152 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 153 | void DoPromotion(CompilationUnit* cu); |
| 154 | int VRegOffset(CompilationUnit* cu, int reg); |
| 155 | int SRegOffset(CompilationUnit* cu, int reg); |
| 156 | void RecordCorePromotion(CompilationUnit* cu, int reg, int s_reg); |
| 157 | void RecordFpPromotion(CompilationUnit* cu, int reg, int s_reg); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 158 | int ComputeFrameSize(CompilationUnit* cu); |
buzbee | 5f61f67 | 2012-11-28 17:22:17 -0800 | [diff] [blame] | 159 | int SRegToPMap(CompilationUnit* cu, int s_reg); |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 160 | void DumpRegPool(RegisterInfo* p, int num_regs); |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 161 | |
| 162 | } // namespace art |
| 163 | |
buzbee | eaf09bc | 2012-11-15 14:51:41 -0800 | [diff] [blame] | 164 | #endif // ART_SRC_COMPILER_CODEGEN_RALLOCUTIL_H_ |