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