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 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 17 | namespace art { |
| 18 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 19 | /* |
| 20 | * This file contains target-independent codegen and support, and is |
| 21 | * included by: |
| 22 | * |
| 23 | * $(TARGET_ARCH)/Codegen-$(TARGET_ARCH_VARIANT).c |
| 24 | * |
| 25 | * which combines this common code with specific support found in the |
| 26 | * applicable directories below this one. |
| 27 | * |
| 28 | * Prior to including this file, TGT_LIR should be #defined. |
| 29 | * For example, for arm: |
| 30 | * #define TGT_LIR ArmLIR |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame^] | 31 | * for MIPS: |
| 32 | * #define TGT_LIR MipsLIR |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 33 | * and for x86: |
| 34 | * #define TGT_LIR X86LIR |
| 35 | */ |
| 36 | |
| 37 | |
| 38 | /* Load a word at base + displacement. Displacement must be word multiple */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 39 | STATIC TGT_LIR* loadWordDisp(CompilationUnit* cUnit, int rBase, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 40 | int displacement, int rDest) |
| 41 | { |
| 42 | return loadBaseDisp(cUnit, NULL, rBase, displacement, rDest, kWord, |
| 43 | INVALID_SREG); |
| 44 | } |
| 45 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 46 | STATIC TGT_LIR* storeWordDisp(CompilationUnit* cUnit, int rBase, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 47 | int displacement, int rSrc) |
| 48 | { |
| 49 | return storeBaseDisp(cUnit, rBase, displacement, rSrc, kWord); |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * Load a Dalvik register into a physical register. Take care when |
| 54 | * using this routine, as it doesn't perform any bookkeeping regarding |
| 55 | * register liveness. That is the responsibility of the caller. |
| 56 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 57 | STATIC void loadValueDirect(CompilationUnit* cUnit, RegLocation rlSrc, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 58 | int reg1) |
| 59 | { |
| 60 | rlSrc = oatUpdateLoc(cUnit, rlSrc); |
| 61 | if (rlSrc.location == kLocPhysReg) { |
| 62 | genRegCopy(cUnit, reg1, rlSrc.lowReg); |
| 63 | } else { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 64 | DCHECK(rlSrc.location == kLocDalvikFrame); |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 65 | loadWordDisp(cUnit, rSP, oatSRegOffset(cUnit, rlSrc.sRegLow), reg1); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 66 | } |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | * Similar to loadValueDirect, but clobbers and allocates the target |
| 71 | * register. Should be used when loading to a fixed register (for example, |
| 72 | * loading arguments to an out of line call. |
| 73 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 74 | STATIC void loadValueDirectFixed(CompilationUnit* cUnit, RegLocation rlSrc, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 75 | int reg1) |
| 76 | { |
| 77 | oatClobber(cUnit, reg1); |
| 78 | oatMarkInUse(cUnit, reg1); |
| 79 | loadValueDirect(cUnit, rlSrc, reg1); |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Load a Dalvik register pair into a physical register[s]. Take care when |
| 84 | * using this routine, as it doesn't perform any bookkeeping regarding |
| 85 | * register liveness. That is the responsibility of the caller. |
| 86 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 87 | STATIC void loadValueDirectWide(CompilationUnit* cUnit, RegLocation rlSrc, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 88 | int regLo, int regHi) |
| 89 | { |
| 90 | rlSrc = oatUpdateLocWide(cUnit, rlSrc); |
| 91 | if (rlSrc.location == kLocPhysReg) { |
| 92 | genRegCopyWide(cUnit, regLo, regHi, rlSrc.lowReg, rlSrc.highReg); |
| 93 | } else { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 94 | DCHECK(rlSrc.location == kLocDalvikFrame); |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 95 | loadBaseDispWide(cUnit, NULL, rSP, |
| 96 | oatSRegOffset(cUnit, rlSrc.sRegLow), |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 97 | regLo, regHi, INVALID_SREG); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * Similar to loadValueDirect, but clobbers and allocates the target |
| 103 | * registers. Should be used when loading to a fixed registers (for example, |
| 104 | * loading arguments to an out of line call. |
| 105 | */ |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 106 | STATIC void loadValueDirectWideFixed(CompilationUnit* cUnit, RegLocation rlSrc, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 107 | int regLo, int regHi) |
| 108 | { |
| 109 | oatClobber(cUnit, regLo); |
| 110 | oatClobber(cUnit, regHi); |
| 111 | oatMarkInUse(cUnit, regLo); |
| 112 | oatMarkInUse(cUnit, regHi); |
| 113 | loadValueDirectWide(cUnit, rlSrc, regLo, regHi); |
| 114 | } |
| 115 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 116 | STATIC RegLocation loadValue(CompilationUnit* cUnit, RegLocation rlSrc, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 117 | RegisterClass opKind) |
| 118 | { |
| 119 | rlSrc = oatEvalLoc(cUnit, rlSrc, opKind, false); |
| 120 | if (rlSrc.location == kLocDalvikFrame) { |
| 121 | loadValueDirect(cUnit, rlSrc, rlSrc.lowReg); |
| 122 | rlSrc.location = kLocPhysReg; |
| 123 | oatMarkLive(cUnit, rlSrc.lowReg, rlSrc.sRegLow); |
| 124 | } |
| 125 | return rlSrc; |
| 126 | } |
| 127 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 128 | STATIC void storeValue(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 129 | RegLocation rlSrc) |
| 130 | { |
| 131 | LIR* defStart; |
| 132 | LIR* defEnd; |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 133 | DCHECK(!rlDest.wide); |
| 134 | DCHECK(!rlSrc.wide); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 135 | rlSrc = oatUpdateLoc(cUnit, rlSrc); |
| 136 | rlDest = oatUpdateLoc(cUnit, rlDest); |
| 137 | if (rlSrc.location == kLocPhysReg) { |
| 138 | if (oatIsLive(cUnit, rlSrc.lowReg) || |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 139 | oatIsPromoted(cUnit, rlSrc.lowReg) || |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 140 | (rlDest.location == kLocPhysReg)) { |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 141 | // Src is live/promoted or Dest has assigned reg. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 142 | rlDest = oatEvalLoc(cUnit, rlDest, kAnyReg, false); |
| 143 | genRegCopy(cUnit, rlDest.lowReg, rlSrc.lowReg); |
| 144 | } else { |
| 145 | // Just re-assign the registers. Dest gets Src's regs |
| 146 | rlDest.lowReg = rlSrc.lowReg; |
| 147 | oatClobber(cUnit, rlSrc.lowReg); |
| 148 | } |
| 149 | } else { |
| 150 | // Load Src either into promoted Dest or temps allocated for Dest |
| 151 | rlDest = oatEvalLoc(cUnit, rlDest, kAnyReg, false); |
| 152 | loadValueDirect(cUnit, rlSrc, rlDest.lowReg); |
| 153 | } |
| 154 | |
| 155 | // Dest is now live and dirty (until/if we flush it to home location) |
| 156 | oatMarkLive(cUnit, rlDest.lowReg, rlDest.sRegLow); |
| 157 | oatMarkDirty(cUnit, rlDest); |
| 158 | |
| 159 | |
| 160 | oatResetDefLoc(cUnit, rlDest); |
| 161 | if (oatIsDirty(cUnit, rlDest.lowReg) && |
| 162 | oatLiveOut(cUnit, rlDest.sRegLow)) { |
| 163 | defStart = (LIR* )cUnit->lastLIRInsn; |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 164 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, rlDest.sRegLow), |
| 165 | rlDest.lowReg, kWord); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 166 | oatMarkClean(cUnit, rlDest); |
| 167 | defEnd = (LIR* )cUnit->lastLIRInsn; |
| 168 | oatMarkDef(cUnit, rlDest, defStart, defEnd); |
| 169 | } |
| 170 | } |
| 171 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 172 | STATIC RegLocation loadValueWide(CompilationUnit* cUnit, RegLocation rlSrc, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 173 | RegisterClass opKind) |
| 174 | { |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 175 | DCHECK(rlSrc.wide); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 176 | rlSrc = oatEvalLoc(cUnit, rlSrc, opKind, false); |
| 177 | if (rlSrc.location == kLocDalvikFrame) { |
| 178 | loadValueDirectWide(cUnit, rlSrc, rlSrc.lowReg, rlSrc.highReg); |
| 179 | rlSrc.location = kLocPhysReg; |
| 180 | oatMarkLive(cUnit, rlSrc.lowReg, rlSrc.sRegLow); |
| 181 | oatMarkLive(cUnit, rlSrc.highReg, |
| 182 | oatSRegHi(rlSrc.sRegLow)); |
| 183 | } |
| 184 | return rlSrc; |
| 185 | } |
| 186 | |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 187 | STATIC void storeValueWide(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 188 | RegLocation rlSrc) |
| 189 | { |
| 190 | LIR* defStart; |
| 191 | LIR* defEnd; |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 192 | DCHECK_EQ(FPREG(rlSrc.lowReg), FPREG(rlSrc.highReg)); |
| 193 | DCHECK(rlDest.wide); |
| 194 | DCHECK(rlSrc.wide); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 195 | if (rlSrc.location == kLocPhysReg) { |
| 196 | if (oatIsLive(cUnit, rlSrc.lowReg) || |
| 197 | oatIsLive(cUnit, rlSrc.highReg) || |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 198 | oatIsPromoted(cUnit, rlSrc.lowReg) || |
| 199 | oatIsPromoted(cUnit, rlSrc.highReg) || |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 200 | (rlDest.location == kLocPhysReg)) { |
buzbee | b29e4d1 | 2011-09-26 15:05:48 -0700 | [diff] [blame] | 201 | // Src is live or promoted or Dest has assigned reg. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 202 | rlDest = oatEvalLoc(cUnit, rlDest, kAnyReg, false); |
| 203 | genRegCopyWide(cUnit, rlDest.lowReg, rlDest.highReg, |
| 204 | rlSrc.lowReg, rlSrc.highReg); |
| 205 | } else { |
| 206 | // Just re-assign the registers. Dest gets Src's regs |
| 207 | rlDest.lowReg = rlSrc.lowReg; |
| 208 | rlDest.highReg = rlSrc.highReg; |
| 209 | oatClobber(cUnit, rlSrc.lowReg); |
| 210 | oatClobber(cUnit, rlSrc.highReg); |
| 211 | } |
| 212 | } else { |
| 213 | // Load Src either into promoted Dest or temps allocated for Dest |
| 214 | rlDest = oatEvalLoc(cUnit, rlDest, kAnyReg, false); |
| 215 | loadValueDirectWide(cUnit, rlSrc, rlDest.lowReg, |
| 216 | rlDest.highReg); |
| 217 | } |
| 218 | |
| 219 | // Dest is now live and dirty (until/if we flush it to home location) |
| 220 | oatMarkLive(cUnit, rlDest.lowReg, rlDest.sRegLow); |
| 221 | oatMarkLive(cUnit, rlDest.highReg, |
| 222 | oatSRegHi(rlDest.sRegLow)); |
| 223 | oatMarkDirty(cUnit, rlDest); |
| 224 | oatMarkPair(cUnit, rlDest.lowReg, rlDest.highReg); |
| 225 | |
| 226 | |
| 227 | oatResetDefLocWide(cUnit, rlDest); |
| 228 | if ((oatIsDirty(cUnit, rlDest.lowReg) || |
| 229 | oatIsDirty(cUnit, rlDest.highReg)) && |
| 230 | (oatLiveOut(cUnit, rlDest.sRegLow) || |
| 231 | oatLiveOut(cUnit, oatSRegHi(rlDest.sRegLow)))) { |
| 232 | defStart = (LIR*)cUnit->lastLIRInsn; |
buzbee | ed3e930 | 2011-09-23 17:34:19 -0700 | [diff] [blame] | 233 | DCHECK_EQ((oatS2VReg(cUnit, rlDest.sRegLow)+1), |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 234 | oatS2VReg(cUnit, oatSRegHi(rlDest.sRegLow))); |
buzbee | 67bc236 | 2011-10-11 18:08:40 -0700 | [diff] [blame] | 235 | storeBaseDispWide(cUnit, rSP, oatSRegOffset(cUnit, rlDest.sRegLow), |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 236 | rlDest.lowReg, rlDest.highReg); |
| 237 | oatMarkClean(cUnit, rlDest); |
| 238 | defEnd = (LIR*)cUnit->lastLIRInsn; |
| 239 | oatMarkDefWide(cUnit, rlDest, defStart, defEnd); |
| 240 | } |
| 241 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 242 | |
| 243 | } // namespace art |