| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | /* |
| 18 | * This file contains register alloction support and is intended to be |
| 19 | * included by: |
| 20 | * |
| 21 | * Codegen-$(TARGET_ARCH_VARIANT).c |
| 22 | * |
| 23 | */ |
| 24 | |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 25 | #include "compiler/CompilerUtility.h" |
| 26 | #include "compiler/CompilerIR.h" |
| 27 | #include "compiler/Dataflow.h" |
| 28 | #include "ArmLIR.h" |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 29 | #include "Codegen.h" |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 30 | #include "Ralloc.h" |
| 31 | |
| 32 | /* |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 33 | * Register usage for 16-bit Thumb systems: |
| 34 | * r0-r3: Temp/argument |
| 35 | * lr(r14): Temp for translations, return address for handlers |
| 36 | * rGLUE(r6): Pointer to InterpState |
| 37 | * rFP(r5): Dalvik frame pointer |
| 38 | * r4, r7: Temp for translations |
| 39 | * r8, r9, r10: Temp preserved across C calls |
| 40 | * r11, ip(r12): Temp not preserved across C calls |
| 41 | * |
| 42 | * Register usage for 32-bit Thumb systems: |
| 43 | * r0-r3: Temp/argument |
| 44 | * lr(r14): Temp for translations, return address for handlers |
| 45 | * rGLUE(r6): Pointer to InterpState |
| 46 | * rFP(r5): Dalvik frame pointer |
| 47 | * r4, r7: Temp for translations |
| 48 | * r8, r9, r10 Temp preserved across C calls |
| 49 | * r11, ip(r12): Temp not preserved across C calls |
| 50 | * fp0-fp15: Hot temps, not preserved across C calls |
| 51 | * fp16-fp31: Promotion pool |
| 52 | * |
| 53 | */ |
| 54 | |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 55 | #define SREG(c, s) ((c)->regLocation[(s)].sRegLow) |
| 56 | /* |
| 57 | * Get the "real" sreg number associated with an sReg slot. In general, |
| 58 | * sReg values passed through codegen are the SSA names created by |
| 59 | * dataflow analysis and refer to slot numbers in the cUnit->regLocation |
| 60 | * array. However, renaming is accomplished by simply replacing RegLocation |
| 61 | * entries in the cUnit->reglocation[] array. Therefore, when location |
| 62 | * records for operands are first created, we need to ask the locRecord |
| 63 | * identified by the dataflow pass what it's new name is. |
| 64 | */ |
| 65 | |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 66 | /* |
| 67 | * Free all allocated temps in the temp pools. Note that this does |
| 68 | * not affect the "liveness" of a temp register, which will stay |
| 69 | * live until it is either explicitly killed or reallocated. |
| 70 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 71 | extern void dvmCompilerResetRegPool(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 72 | { |
| 73 | int i; |
| 74 | for (i=0; i < cUnit->regPool->numCoreTemps; i++) { |
| 75 | cUnit->regPool->coreTemps[i].inUse = false; |
| 76 | } |
| 77 | for (i=0; i < cUnit->regPool->numFPTemps; i++) { |
| 78 | cUnit->regPool->FPTemps[i].inUse = false; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /* Set up temp & preserved register pools specialized by target */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 83 | extern void dvmCompilerInitPool(RegisterInfo *regs, int *regNums, int num) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 84 | { |
| 85 | int i; |
| 86 | for (i=0; i < num; i++) { |
| 87 | regs[i].reg = regNums[i]; |
| 88 | regs[i].inUse = false; |
| 89 | regs[i].pair = false; |
| 90 | regs[i].live = false; |
| 91 | regs[i].dirty = false; |
| 92 | regs[i].sReg = INVALID_SREG; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static void dumpRegPool(RegisterInfo *p, int numRegs) |
| 97 | { |
| 98 | int i; |
| 99 | LOGE("================================================"); |
| 100 | for (i=0; i < numRegs; i++ ){ |
| 101 | LOGE("R[%d]: U:%d, P:%d, part:%d, LV:%d, D:%d, SR:%d, ST:%x, EN:%x", |
| 102 | p[i].reg, p[i].inUse, p[i].pair, p[i].partner, p[i].live, |
| 103 | p[i].dirty, p[i].sReg,(int)p[i].defStart, (int)p[i].defEnd); |
| 104 | } |
| 105 | LOGE("================================================"); |
| 106 | } |
| 107 | |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 108 | static RegisterInfo *getRegInfo(CompilationUnit *cUnit, int reg) |
| 109 | { |
| 110 | int numTemps = cUnit->regPool->numCoreTemps; |
| 111 | RegisterInfo *p = cUnit->regPool->coreTemps; |
| 112 | int i; |
| 113 | for (i=0; i< numTemps; i++) { |
| 114 | if (p[i].reg == reg) { |
| 115 | return &p[i]; |
| 116 | } |
| 117 | } |
| 118 | p = cUnit->regPool->FPTemps; |
| 119 | numTemps = cUnit->regPool->numFPTemps; |
| 120 | for (i=0; i< numTemps; i++) { |
| 121 | if (p[i].reg == reg) { |
| 122 | return &p[i]; |
| 123 | } |
| 124 | } |
| 125 | LOGE("Tried to get info on a non-existant temp: r%d",reg); |
| Bill Buzbee | fc519dc | 2010-03-06 23:30:57 -0800 | [diff] [blame] | 126 | dvmCompilerAbort(cUnit); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 127 | return NULL; |
| 128 | } |
| 129 | |
| 130 | static void flushRegWide(CompilationUnit *cUnit, int reg1, int reg2) |
| 131 | { |
| 132 | RegisterInfo *info1 = getRegInfo(cUnit, reg1); |
| 133 | RegisterInfo *info2 = getRegInfo(cUnit, reg2); |
| 134 | assert(info1 && info2 && info1->pair && info2->pair && |
| 135 | (info1->partner == info2->reg) && |
| 136 | (info2->partner == info1->reg)); |
| 137 | if ((info1->live && info1->dirty) || (info2->live && info2->dirty)) { |
| 138 | info1->dirty = false; |
| 139 | info2->dirty = false; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 140 | if (dvmCompilerS2VReg(cUnit, info2->sReg) < |
| 141 | dvmCompilerS2VReg(cUnit, info1->sReg)) |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 142 | info1 = info2; |
| 143 | dvmCompilerFlushRegWideImpl(cUnit, rFP, |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 144 | dvmCompilerS2VReg(cUnit, info1->sReg) << 2, |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 145 | info1->reg, info1->partner); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | static void flushReg(CompilationUnit *cUnit, int reg) |
| 150 | { |
| 151 | RegisterInfo *info = getRegInfo(cUnit, reg); |
| 152 | if (info->live && info->dirty) { |
| 153 | info->dirty = false; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 154 | dvmCompilerFlushRegImpl(cUnit, rFP, |
| 155 | dvmCompilerS2VReg(cUnit, info->sReg) << 2, |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 156 | reg, kWord); |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | /* return true if found reg to clobber */ |
| 161 | static bool clobberRegBody(CompilationUnit *cUnit, RegisterInfo *p, |
| 162 | int numTemps, int reg) |
| 163 | { |
| 164 | int i; |
| 165 | for (i=0; i< numTemps; i++) { |
| 166 | if (p[i].reg == reg) { |
| 167 | if (p[i].live && p[i].dirty) { |
| 168 | if (p[i].pair) { |
| 169 | flushRegWide(cUnit, p[i].reg, p[i].partner); |
| 170 | } else { |
| 171 | flushReg(cUnit, p[i].reg); |
| 172 | } |
| 173 | } |
| 174 | p[i].live = false; |
| 175 | p[i].sReg = INVALID_SREG; |
| 176 | p[i].defStart = NULL; |
| 177 | p[i].defEnd = NULL; |
| 178 | if (p[i].pair) { |
| 179 | p[i].pair = false; |
| 180 | /* partners should be in same pool */ |
| 181 | clobberRegBody(cUnit, p, numTemps, p[i].partner); |
| 182 | } |
| 183 | return true; |
| 184 | } |
| 185 | } |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | /* Mark a temp register as dead. Does not affect allocation state. */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 190 | void dvmCompilerClobber(CompilationUnit *cUnit, int reg) |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 191 | { |
| 192 | if (!clobberRegBody(cUnit, cUnit->regPool->coreTemps, |
| 193 | cUnit->regPool->numCoreTemps, reg)) { |
| 194 | clobberRegBody(cUnit, cUnit->regPool->FPTemps, |
| 195 | cUnit->regPool->numFPTemps, reg); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | static void clobberSRegBody(RegisterInfo *p, int numTemps, int sReg) |
| 200 | { |
| 201 | int i; |
| 202 | for (i=0; i< numTemps; i++) { |
| 203 | if (p[i].sReg == sReg) { |
| 204 | p[i].live = false; |
| 205 | p[i].defStart = NULL; |
| 206 | p[i].defEnd = NULL; |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | /* Clobber any temp associated with an sReg. Could be in either class */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 212 | extern void dvmCompilerClobberSReg(CompilationUnit *cUnit, int sReg) |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 213 | { |
| 214 | clobberSRegBody(cUnit->regPool->coreTemps, cUnit->regPool->numCoreTemps, |
| 215 | sReg); |
| 216 | clobberSRegBody(cUnit->regPool->FPTemps, cUnit->regPool->numFPTemps, |
| 217 | sReg); |
| 218 | } |
| 219 | |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 220 | static int allocTempBody(CompilationUnit *cUnit, RegisterInfo *p, int numTemps, |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 221 | int *nextTemp, bool required) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 222 | { |
| 223 | int i; |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 224 | int next = *nextTemp; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 225 | for (i=0; i< numTemps; i++) { |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 226 | if (next >= numTemps) |
| 227 | next = 0; |
| 228 | if (!p[next].inUse && !p[next].live) { |
| 229 | dvmCompilerClobber(cUnit, p[next].reg); |
| 230 | p[next].inUse = true; |
| 231 | p[next].pair = false; |
| 232 | *nextTemp = next + 1; |
| 233 | return p[next].reg; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 234 | } |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 235 | next++; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 236 | } |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 237 | next = *nextTemp; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 238 | for (i=0; i< numTemps; i++) { |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 239 | if (next >= numTemps) |
| 240 | next = 0; |
| 241 | if (!p[next].inUse) { |
| 242 | dvmCompilerClobber(cUnit, p[next].reg); |
| 243 | p[next].inUse = true; |
| 244 | p[next].pair = false; |
| 245 | *nextTemp = next + 1; |
| 246 | return p[next].reg; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 247 | } |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 248 | next++; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 249 | } |
| 250 | if (required) { |
| 251 | LOGE("No free temp registers"); |
| Bill Buzbee | fc519dc | 2010-03-06 23:30:57 -0800 | [diff] [blame] | 252 | dvmCompilerAbort(cUnit); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 253 | } |
| 254 | return -1; // No register available |
| 255 | } |
| 256 | |
| 257 | //REDO: too many assumptions. |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 258 | extern int dvmCompilerAllocTempDouble(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 259 | { |
| 260 | RegisterInfo *p = cUnit->regPool->FPTemps; |
| 261 | int numTemps = cUnit->regPool->numFPTemps; |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 262 | int next = cUnit->regPool->nextFPTemp; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 263 | int i; |
| 264 | |
| 265 | for (i=0; i < numTemps; i+=2) { |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 266 | /* Cleanup - not all targets need aligned regs */ |
| 267 | if (next & 1) |
| 268 | next++; |
| 269 | if (next >= numTemps) |
| 270 | next = 0; |
| 271 | if ((!p[next].inUse && !p[next].live) && |
| 272 | (!p[next+1].inUse && !p[next+1].live)) { |
| 273 | dvmCompilerClobber(cUnit, p[next].reg); |
| 274 | dvmCompilerClobber(cUnit, p[next+1].reg); |
| 275 | p[next].inUse = true; |
| 276 | p[next+1].inUse = true; |
| 277 | assert((p[next].reg+1) == p[next+1].reg); |
| 278 | assert((p[next].reg & 0x1) == 0); |
| 279 | cUnit->regPool->nextFPTemp += 2; |
| 280 | return p[next].reg; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 281 | } |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 282 | next += 2; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 283 | } |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 284 | next = cUnit->regPool->nextFPTemp; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 285 | for (i=0; i < numTemps; i+=2) { |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 286 | if (next >= numTemps) |
| 287 | next = 0; |
| 288 | if (!p[next].inUse && !p[next+1].inUse) { |
| 289 | dvmCompilerClobber(cUnit, p[next].reg); |
| 290 | dvmCompilerClobber(cUnit, p[next+1].reg); |
| 291 | p[next].inUse = true; |
| 292 | p[next+1].inUse = true; |
| 293 | assert((p[next].reg+1) == p[next+1].reg); |
| 294 | assert((p[next].reg & 0x1) == 0); |
| 295 | cUnit->regPool->nextFPTemp += 2; |
| 296 | return p[next].reg; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 297 | } |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 298 | next += 2; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 299 | } |
| 300 | LOGE("No free temp registers"); |
| Bill Buzbee | fc519dc | 2010-03-06 23:30:57 -0800 | [diff] [blame] | 301 | dvmCompilerAbort(cUnit); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 302 | return -1; |
| 303 | } |
| 304 | |
| 305 | /* Return a temp if one is available, -1 otherwise */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 306 | extern int dvmCompilerAllocFreeTemp(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 307 | { |
| 308 | return allocTempBody(cUnit, cUnit->regPool->coreTemps, |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 309 | cUnit->regPool->numCoreTemps, |
| 310 | &cUnit->regPool->nextCoreTemp, true); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 313 | extern int dvmCompilerAllocTemp(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 314 | { |
| 315 | return allocTempBody(cUnit, cUnit->regPool->coreTemps, |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 316 | cUnit->regPool->numCoreTemps, |
| 317 | &cUnit->regPool->nextCoreTemp, true); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 320 | extern int dvmCompilerAllocTempFloat(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 321 | { |
| 322 | return allocTempBody(cUnit, cUnit->regPool->FPTemps, |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 323 | cUnit->regPool->numFPTemps, |
| 324 | &cUnit->regPool->nextFPTemp, true); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | static RegisterInfo *allocLiveBody(RegisterInfo *p, int numTemps, int sReg) |
| 328 | { |
| 329 | int i; |
| 330 | if (sReg == -1) |
| 331 | return NULL; |
| 332 | for (i=0; i < numTemps; i++) { |
| 333 | if (p[i].live && (p[i].sReg == sReg)) { |
| 334 | p[i].inUse = true; |
| 335 | return &p[i]; |
| 336 | } |
| 337 | } |
| 338 | return NULL; |
| 339 | } |
| 340 | |
| 341 | static RegisterInfo *allocLive(CompilationUnit *cUnit, int sReg, |
| 342 | int regClass) |
| 343 | { |
| 344 | RegisterInfo *res = NULL; |
| 345 | switch(regClass) { |
| 346 | case kAnyReg: |
| 347 | res = allocLiveBody(cUnit->regPool->FPTemps, |
| 348 | cUnit->regPool->numFPTemps, sReg); |
| 349 | if (res) |
| 350 | break; |
| 351 | /* Intentional fallthrough */ |
| 352 | case kCoreReg: |
| 353 | res = allocLiveBody(cUnit->regPool->coreTemps, |
| 354 | cUnit->regPool->numCoreTemps, sReg); |
| 355 | break; |
| 356 | case kFPReg: |
| 357 | res = allocLiveBody(cUnit->regPool->FPTemps, |
| 358 | cUnit->regPool->numFPTemps, sReg); |
| 359 | break; |
| 360 | default: |
| 361 | LOGE("Invalid register type"); |
| Bill Buzbee | fc519dc | 2010-03-06 23:30:57 -0800 | [diff] [blame] | 362 | dvmCompilerAbort(cUnit); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 363 | } |
| 364 | return res; |
| 365 | } |
| 366 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 367 | extern void dvmCompilerFreeTemp(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 368 | { |
| 369 | RegisterInfo *p = cUnit->regPool->coreTemps; |
| 370 | int numTemps = cUnit->regPool->numCoreTemps; |
| 371 | int i; |
| 372 | for (i=0; i< numTemps; i++) { |
| 373 | if (p[i].reg == reg) { |
| 374 | p[i].inUse = false; |
| 375 | p[i].pair = false; |
| 376 | return; |
| 377 | } |
| 378 | } |
| 379 | p = cUnit->regPool->FPTemps; |
| 380 | numTemps = cUnit->regPool->numFPTemps; |
| 381 | for (i=0; i< numTemps; i++) { |
| 382 | if (p[i].reg == reg) { |
| 383 | p[i].inUse = false; |
| 384 | p[i].pair = false; |
| 385 | return; |
| 386 | } |
| 387 | } |
| 388 | LOGE("Tried to free a non-existant temp: r%d",reg); |
| Bill Buzbee | fc519dc | 2010-03-06 23:30:57 -0800 | [diff] [blame] | 389 | dvmCompilerAbort(cUnit); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 390 | } |
| 391 | |
| Bill Buzbee | 1f74863 | 2010-03-02 16:14:41 -0800 | [diff] [blame] | 392 | /* |
| 393 | * FIXME - this needs to also check the preserved pool once we start |
| 394 | * start using preserved registers. |
| 395 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 396 | extern RegisterInfo *dvmCompilerIsLive(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 397 | { |
| 398 | RegisterInfo *p = cUnit->regPool->coreTemps; |
| 399 | int numTemps = cUnit->regPool->numCoreTemps; |
| 400 | int i; |
| 401 | for (i=0; i< numTemps; i++) { |
| 402 | if (p[i].reg == reg) { |
| 403 | return p[i].live ? &p[i] : NULL; |
| 404 | } |
| 405 | } |
| 406 | p = cUnit->regPool->FPTemps; |
| 407 | numTemps = cUnit->regPool->numFPTemps; |
| 408 | for (i=0; i< numTemps; i++) { |
| 409 | if (p[i].reg == reg) { |
| 410 | return p[i].live ? &p[i] : NULL; |
| 411 | } |
| 412 | } |
| 413 | return NULL; |
| 414 | } |
| 415 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 416 | extern RegisterInfo *dvmCompilerIsTemp(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 417 | { |
| 418 | RegisterInfo *p = cUnit->regPool->coreTemps; |
| 419 | int numTemps = cUnit->regPool->numCoreTemps; |
| 420 | int i; |
| 421 | for (i=0; i< numTemps; i++) { |
| 422 | if (p[i].reg == reg) { |
| 423 | return &p[i]; |
| 424 | } |
| 425 | } |
| 426 | p = cUnit->regPool->FPTemps; |
| 427 | numTemps = cUnit->regPool->numFPTemps; |
| 428 | for (i=0; i< numTemps; i++) { |
| 429 | if (p[i].reg == reg) { |
| 430 | return &p[i]; |
| 431 | } |
| 432 | } |
| 433 | return NULL; |
| 434 | } |
| 435 | |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 436 | /* |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 437 | * Similar to dvmCompilerAllocTemp(), but forces the allocation of a specific |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 438 | * register. No check is made to see if the register was previously |
| 439 | * allocated. Use with caution. |
| 440 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 441 | extern void dvmCompilerLockTemp(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 442 | { |
| 443 | RegisterInfo *p = cUnit->regPool->coreTemps; |
| 444 | int numTemps = cUnit->regPool->numCoreTemps; |
| 445 | int i; |
| 446 | for (i=0; i< numTemps; i++) { |
| 447 | if (p[i].reg == reg) { |
| 448 | p[i].inUse = true; |
| 449 | p[i].live = false; |
| 450 | return; |
| 451 | } |
| 452 | } |
| 453 | p = cUnit->regPool->FPTemps; |
| 454 | numTemps = cUnit->regPool->numFPTemps; |
| 455 | for (i=0; i< numTemps; i++) { |
| 456 | if (p[i].reg == reg) { |
| 457 | p[i].inUse = true; |
| 458 | p[i].live = false; |
| 459 | return; |
| 460 | } |
| 461 | } |
| 462 | LOGE("Tried to lock a non-existant temp: r%d",reg); |
| Bill Buzbee | fc519dc | 2010-03-06 23:30:57 -0800 | [diff] [blame] | 463 | dvmCompilerAbort(cUnit); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void lockArgRegs(CompilationUnit *cUnit) |
| 467 | { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 468 | dvmCompilerLockTemp(cUnit, r0); |
| 469 | dvmCompilerLockTemp(cUnit, r1); |
| 470 | dvmCompilerLockTemp(cUnit, r2); |
| 471 | dvmCompilerLockTemp(cUnit, r3); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | /* Clobber all regs that might be used by an external C call */ |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 475 | extern void dvmCompilerClobberCallRegs(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 476 | { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 477 | dvmCompilerClobber(cUnit, r0); |
| 478 | dvmCompilerClobber(cUnit, r1); |
| 479 | dvmCompilerClobber(cUnit, r2); |
| 480 | dvmCompilerClobber(cUnit, r3); |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 481 | dvmCompilerClobber(cUnit, r9); // Need to do this?, be conservative |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 482 | dvmCompilerClobber(cUnit, r11); |
| 483 | dvmCompilerClobber(cUnit, r12); |
| 484 | dvmCompilerClobber(cUnit, rlr); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /* Clobber all of the temps that might be used by a handler. */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 488 | extern void dvmCompilerClobberHandlerRegs(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 489 | { |
| 490 | //TUNING: reduce the set of regs used by handlers. Only a few need lots. |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 491 | dvmCompilerClobberCallRegs(cUnit); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 492 | dvmCompilerClobber(cUnit, r4PC); |
| 493 | dvmCompilerClobber(cUnit, r9); |
| 494 | dvmCompilerClobber(cUnit, r10); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 495 | } |
| 496 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 497 | extern void dvmCompilerResetDef(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 498 | { |
| 499 | RegisterInfo *p = getRegInfo(cUnit, reg); |
| 500 | p->defStart = NULL; |
| 501 | p->defEnd = NULL; |
| 502 | } |
| 503 | |
| 504 | static void nullifyRange(CompilationUnit *cUnit, LIR *start, LIR *finish, |
| 505 | int sReg1, int sReg2) |
| 506 | { |
| 507 | if (start && finish) { |
| 508 | LIR *p; |
| 509 | assert(sReg1 == sReg2); |
| 510 | for (p = start; ;p = p->next) { |
| 511 | ((ArmLIR *)p)->isNop = true; |
| 512 | if (p == finish) |
| 513 | break; |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * Mark the beginning and end LIR of a def sequence. Note that |
| 520 | * on entry start points to the LIR prior to the beginning of the |
| 521 | * sequence. |
| 522 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 523 | extern void dvmCompilerMarkDef(CompilationUnit *cUnit, RegLocation rl, |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 524 | LIR *start, LIR *finish) |
| 525 | { |
| 526 | assert(!rl.wide); |
| 527 | assert(start && start->next); |
| 528 | assert(finish); |
| 529 | RegisterInfo *p = getRegInfo(cUnit, rl.lowReg); |
| 530 | p->defStart = start->next; |
| 531 | p->defEnd = finish; |
| 532 | } |
| 533 | |
| 534 | /* |
| 535 | * Mark the beginning and end LIR of a def sequence. Note that |
| 536 | * on entry start points to the LIR prior to the beginning of the |
| 537 | * sequence. |
| 538 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 539 | extern void dvmCompilerMarkDefWide(CompilationUnit *cUnit, RegLocation rl, |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 540 | LIR *start, LIR *finish) |
| 541 | { |
| 542 | assert(rl.wide); |
| 543 | assert(start && start->next); |
| 544 | assert(finish); |
| 545 | RegisterInfo *p = getRegInfo(cUnit, rl.lowReg); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 546 | dvmCompilerResetDef(cUnit, rl.highReg); // Only track low of pair |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 547 | p->defStart = start->next; |
| 548 | p->defEnd = finish; |
| 549 | } |
| 550 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 551 | extern RegLocation dvmCompilerWideToNarrow(CompilationUnit *cUnit, |
| 552 | RegLocation rl) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 553 | { |
| 554 | assert(rl.wide); |
| 555 | if (rl.location == kLocPhysReg) { |
| 556 | RegisterInfo *infoLo = getRegInfo(cUnit, rl.lowReg); |
| 557 | RegisterInfo *infoHi = getRegInfo(cUnit, rl.highReg); |
| 558 | if (!infoLo->pair) { |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 559 | dumpRegPool(cUnit->regPool->coreTemps, |
| 560 | cUnit->regPool->numCoreTemps); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 561 | assert(infoLo->pair); |
| 562 | } |
| 563 | if (!infoHi->pair) { |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 564 | dumpRegPool(cUnit->regPool->coreTemps, |
| 565 | cUnit->regPool->numCoreTemps); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 566 | assert(infoHi->pair); |
| 567 | } |
| 568 | assert(infoLo->pair); |
| 569 | assert(infoHi->pair); |
| 570 | assert(infoLo->partner == infoHi->reg); |
| 571 | assert(infoHi->partner == infoLo->reg); |
| 572 | infoLo->pair = false; |
| 573 | infoHi->pair = false; |
| 574 | infoLo->defStart = NULL; |
| 575 | infoLo->defEnd = NULL; |
| 576 | infoHi->defStart = NULL; |
| 577 | infoHi->defEnd = NULL; |
| 578 | } |
| 579 | rl.wide = false; |
| 580 | return rl; |
| 581 | } |
| 582 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 583 | extern void dvmCompilerResetDefLoc(CompilationUnit *cUnit, RegLocation rl) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 584 | { |
| 585 | assert(!rl.wide); |
| 586 | if (!(gDvmJit.disableOpt & (1 << kSuppressLoads))) { |
| 587 | RegisterInfo *p = getRegInfo(cUnit, rl.lowReg); |
| 588 | assert(!p->pair); |
| 589 | nullifyRange(cUnit, p->defStart, p->defEnd, |
| 590 | p->sReg, rl.sRegLow); |
| 591 | } |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 592 | dvmCompilerResetDef(cUnit, rl.lowReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 595 | extern void dvmCompilerResetDefLocWide(CompilationUnit *cUnit, RegLocation rl) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 596 | { |
| 597 | assert(rl.wide); |
| 598 | if (!(gDvmJit.disableOpt & (1 << kSuppressLoads))) { |
| 599 | RegisterInfo *p = getRegInfo(cUnit, rl.lowReg); |
| 600 | assert(p->pair); |
| 601 | nullifyRange(cUnit, p->defStart, p->defEnd, |
| 602 | p->sReg, rl.sRegLow); |
| 603 | } |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 604 | dvmCompilerResetDef(cUnit, rl.lowReg); |
| 605 | dvmCompilerResetDef(cUnit, rl.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 606 | } |
| 607 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 608 | extern void dvmCompilerResetDefTracking(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 609 | { |
| 610 | int i; |
| 611 | for (i=0; i< cUnit->regPool->numCoreTemps; i++) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 612 | dvmCompilerResetDef(cUnit, cUnit->regPool->coreTemps[i].reg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 613 | } |
| 614 | for (i=0; i< cUnit->regPool->numFPTemps; i++) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 615 | dvmCompilerResetDef(cUnit, cUnit->regPool->FPTemps[i].reg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 619 | extern void dvmCompilerClobberAllRegs(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 620 | { |
| 621 | int i; |
| 622 | for (i=0; i< cUnit->regPool->numCoreTemps; i++) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 623 | dvmCompilerClobber(cUnit, cUnit->regPool->coreTemps[i].reg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 624 | } |
| 625 | for (i=0; i< cUnit->regPool->numFPTemps; i++) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 626 | dvmCompilerClobber(cUnit, cUnit->regPool->FPTemps[i].reg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
| 630 | /* To be used when explicitly managing register use */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 631 | extern void dvmCompilerLockAllTemps(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 632 | { |
| 633 | int i; |
| 634 | for (i=0; i< cUnit->regPool->numCoreTemps; i++) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 635 | dvmCompilerLockTemp(cUnit, cUnit->regPool->coreTemps[i].reg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
| 639 | // Make sure nothing is live and dirty |
| 640 | static void flushAllRegsBody(CompilationUnit *cUnit, RegisterInfo *info, |
| 641 | int numRegs) |
| 642 | { |
| 643 | int i; |
| 644 | for (i=0; i < numRegs; i++) { |
| 645 | if (info[i].live && info[i].dirty) { |
| 646 | if (info[i].pair) { |
| 647 | flushRegWide(cUnit, info[i].reg, info[i].partner); |
| 648 | } else { |
| 649 | flushReg(cUnit, info[i].reg); |
| 650 | } |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 655 | extern void dvmCompilerFlushAllRegs(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 656 | { |
| 657 | flushAllRegsBody(cUnit, cUnit->regPool->coreTemps, |
| 658 | cUnit->regPool->numCoreTemps); |
| 659 | flushAllRegsBody(cUnit, cUnit->regPool->FPTemps, |
| 660 | cUnit->regPool->numFPTemps); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 661 | dvmCompilerClobberAllRegs(cUnit); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
| 665 | //TUNING: rewrite all of this reg stuff. Probably use an attribute table |
| 666 | static bool regClassMatches(int regClass, int reg) |
| 667 | { |
| 668 | if (regClass == kAnyReg) { |
| 669 | return true; |
| 670 | } else if (regClass == kCoreReg) { |
| 671 | return !FPREG(reg); |
| 672 | } else { |
| 673 | return FPREG(reg); |
| 674 | } |
| 675 | } |
| 676 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 677 | extern void dvmCompilerMarkLive(CompilationUnit *cUnit, int reg, int sReg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 678 | { |
| 679 | RegisterInfo *info = getRegInfo(cUnit, reg); |
| 680 | if ((info->reg == reg) && (info->sReg == sReg) && info->live) { |
| 681 | return; /* already live */ |
| 682 | } else if (sReg != INVALID_SREG) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 683 | dvmCompilerClobberSReg(cUnit, sReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 684 | info->live = true; |
| 685 | } else { |
| 686 | /* Can't be live if no associated sReg */ |
| 687 | info->live = false; |
| 688 | } |
| 689 | info->sReg = sReg; |
| 690 | } |
| 691 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 692 | extern void dvmCompilerMarkPair(CompilationUnit *cUnit, int lowReg, int highReg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 693 | { |
| 694 | RegisterInfo *infoLo = getRegInfo(cUnit, lowReg); |
| 695 | RegisterInfo *infoHi = getRegInfo(cUnit, highReg); |
| 696 | infoLo->pair = infoHi->pair = true; |
| 697 | infoLo->partner = highReg; |
| 698 | infoHi->partner = lowReg; |
| 699 | } |
| 700 | |
| 701 | static void markRegSingle(CompilationUnit *cUnit, int reg) |
| 702 | { |
| 703 | RegisterInfo *info = getRegInfo(cUnit, reg); |
| 704 | info->pair = false; |
| 705 | } |
| 706 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 707 | extern void dvmCompilerMarkClean(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 708 | { |
| 709 | RegisterInfo *info = getRegInfo(cUnit, reg); |
| 710 | info->dirty = false; |
| 711 | } |
| 712 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 713 | extern void dvmCompilerMarkDirty(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 714 | { |
| 715 | RegisterInfo *info = getRegInfo(cUnit, reg); |
| 716 | info->dirty = true; |
| 717 | } |
| 718 | |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 719 | extern void dvmCompilerMarkInUse(CompilationUnit *cUnit, int reg) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 720 | { |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 721 | RegisterInfo *info = getRegInfo(cUnit, reg); |
| 722 | info->inUse = true; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | /* Return true if live & dirty */ |
| 726 | static bool isDirty(CompilationUnit *cUnit, int reg) |
| 727 | { |
| 728 | RegisterInfo *info = getRegInfo(cUnit, reg); |
| 729 | return (info && info->live && info->dirty); |
| 730 | } |
| 731 | |
| 732 | void copyRegInfo(CompilationUnit *cUnit, int newReg, int oldReg) |
| 733 | { |
| 734 | RegisterInfo *newInfo = getRegInfo(cUnit, newReg); |
| 735 | RegisterInfo *oldInfo = getRegInfo(cUnit, oldReg); |
| 736 | *newInfo = *oldInfo; |
| 737 | newInfo->reg = newReg; |
| 738 | } |
| 739 | |
| 740 | /* |
| 741 | * Return an updated location record with current in-register status. |
| 742 | * If the value lives in live temps, reflect that fact. No code |
| 743 | * is generated. The the live value is part of an older pair, |
| 744 | * clobber both low and high. |
| 745 | * TUNING: clobbering both is a bit heavy-handed, but the alternative |
| 746 | * is a bit complex when dealing with FP regs. Examine code to see |
| 747 | * if it's worthwhile trying to be more clever here. |
| 748 | */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 749 | extern RegLocation dvmCompilerUpdateLoc(CompilationUnit *cUnit, RegLocation loc) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 750 | { |
| 751 | assert(!loc.wide); |
| 752 | if (loc.location == kLocDalvikFrame) { |
| 753 | RegisterInfo *infoLo = allocLive(cUnit, loc.sRegLow, kAnyReg); |
| 754 | if (infoLo) { |
| 755 | if (infoLo->pair) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 756 | dvmCompilerClobber(cUnit, infoLo->reg); |
| 757 | dvmCompilerClobber(cUnit, infoLo->partner); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 758 | } else { |
| 759 | loc.lowReg = infoLo->reg; |
| 760 | loc.location = kLocPhysReg; |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | |
| 765 | return loc; |
| 766 | } |
| 767 | |
| 768 | /* see comments for updateLoc */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 769 | extern RegLocation dvmCompilerUpdateLocWide(CompilationUnit *cUnit, |
| 770 | RegLocation loc) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 771 | { |
| 772 | assert(loc.wide); |
| 773 | if (loc.location == kLocDalvikFrame) { |
| Bill Buzbee | 80cef86 | 2010-03-25 10:38:34 -0700 | [diff] [blame^] | 774 | // Are the dalvik regs already live in physical registers? |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 775 | RegisterInfo *infoLo = allocLive(cUnit, loc.sRegLow, kAnyReg); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 776 | RegisterInfo *infoHi = allocLive(cUnit, |
| 777 | dvmCompilerSRegHi(loc.sRegLow), kAnyReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 778 | bool match = true; |
| 779 | match = match && (infoLo != NULL); |
| 780 | match = match && (infoHi != NULL); |
| Bill Buzbee | 80cef86 | 2010-03-25 10:38:34 -0700 | [diff] [blame^] | 781 | // Are they both core or both FP? |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 782 | match = match && (FPREG(infoLo->reg) == FPREG(infoHi->reg)); |
| Bill Buzbee | 80cef86 | 2010-03-25 10:38:34 -0700 | [diff] [blame^] | 783 | // If a pair of floating point singles, are they properly aligned? |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 784 | if (match && FPREG(infoLo->reg)) { |
| 785 | match &= ((infoLo->reg & 0x1) == 0); |
| 786 | match &= ((infoHi->reg - infoLo->reg) == 1); |
| 787 | } |
| Bill Buzbee | 80cef86 | 2010-03-25 10:38:34 -0700 | [diff] [blame^] | 788 | // If previously used as a pair, it is the same pair? |
| 789 | if (match && (infoLo->pair || infoHi->pair)) { |
| 790 | match = (infoLo->pair == infoHi->pair); |
| 791 | match &= ((infoLo->reg == infoHi->partner) && |
| 792 | (infoHi->reg == infoLo->partner)); |
| 793 | } |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 794 | if (match) { |
| Bill Buzbee | 80cef86 | 2010-03-25 10:38:34 -0700 | [diff] [blame^] | 795 | // Can reuse - update the register usage info |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 796 | loc.lowReg = infoLo->reg; |
| 797 | loc.highReg = infoHi->reg; |
| 798 | loc.location = kLocPhysReg; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 799 | dvmCompilerMarkPair(cUnit, loc.lowReg, loc.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 800 | assert(!FPREG(loc.lowReg) || ((loc.lowReg & 0x1) == 0)); |
| 801 | return loc; |
| 802 | } |
| Bill Buzbee | 80cef86 | 2010-03-25 10:38:34 -0700 | [diff] [blame^] | 803 | // Can't easily reuse - clobber any overlaps |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 804 | if (infoLo) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 805 | dvmCompilerClobber(cUnit, infoLo->reg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 806 | if (infoLo->pair) |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 807 | dvmCompilerClobber(cUnit, infoLo->partner); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 808 | } |
| 809 | if (infoHi) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 810 | dvmCompilerClobber(cUnit, infoHi->reg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 811 | if (infoHi->pair) |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 812 | dvmCompilerClobber(cUnit, infoHi->partner); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 813 | } |
| 814 | } |
| 815 | |
| 816 | return loc; |
| 817 | } |
| 818 | |
| 819 | static RegLocation evalLocWide(CompilationUnit *cUnit, RegLocation loc, |
| 820 | int regClass, bool update) |
| 821 | { |
| 822 | assert(loc.wide); |
| 823 | int newRegs; |
| 824 | int lowReg; |
| 825 | int highReg; |
| 826 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 827 | loc = dvmCompilerUpdateLocWide(cUnit, loc); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 828 | |
| 829 | /* If already in registers, we can assume proper form. Right reg class? */ |
| 830 | if (loc.location == kLocPhysReg) { |
| 831 | assert(FPREG(loc.lowReg) == FPREG(loc.highReg)); |
| 832 | assert(!FPREG(loc.lowReg) || ((loc.lowReg & 0x1) == 0)); |
| 833 | if (!regClassMatches(regClass, loc.lowReg)) { |
| 834 | /* Wrong register class. Reallocate and copy */ |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 835 | newRegs = dvmCompilerAllocTypedTempPair(cUnit, loc.fp, regClass); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 836 | lowReg = newRegs & 0xff; |
| 837 | highReg = (newRegs >> 8) & 0xff; |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 838 | dvmCompilerRegCopyWide(cUnit, lowReg, highReg, loc.lowReg, |
| 839 | loc.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 840 | copyRegInfo(cUnit, lowReg, loc.lowReg); |
| 841 | copyRegInfo(cUnit, highReg, loc.highReg); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 842 | dvmCompilerClobber(cUnit, loc.lowReg); |
| 843 | dvmCompilerClobber(cUnit, loc.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 844 | loc.lowReg = lowReg; |
| 845 | loc.highReg = highReg; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 846 | dvmCompilerMarkPair(cUnit, loc.lowReg, loc.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 847 | assert(!FPREG(loc.lowReg) || ((loc.lowReg & 0x1) == 0)); |
| 848 | } |
| 849 | return loc; |
| 850 | } |
| 851 | |
| 852 | assert((loc.location != kLocRetval) || (loc.sRegLow == INVALID_SREG)); |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 853 | assert((loc.location != kLocRetval) || |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 854 | (dvmCompilerSRegHi(loc.sRegLow) == INVALID_SREG)); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 855 | |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 856 | newRegs = dvmCompilerAllocTypedTempPair(cUnit, loc.fp, regClass); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 857 | loc.lowReg = newRegs & 0xff; |
| 858 | loc.highReg = (newRegs >> 8) & 0xff; |
| 859 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 860 | dvmCompilerMarkPair(cUnit, loc.lowReg, loc.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 861 | if (update) { |
| 862 | loc.location = kLocPhysReg; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 863 | dvmCompilerMarkLive(cUnit, loc.lowReg, loc.sRegLow); |
| 864 | dvmCompilerMarkLive(cUnit, loc.highReg, dvmCompilerSRegHi(loc.sRegLow)); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 865 | } |
| 866 | assert(!FPREG(loc.lowReg) || ((loc.lowReg & 0x1) == 0)); |
| 867 | return loc; |
| 868 | } |
| 869 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 870 | extern RegLocation dvmCompilerEvalLoc(CompilationUnit *cUnit, RegLocation loc, |
| 871 | int regClass, bool update) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 872 | { |
| 873 | RegisterInfo *infoLo = NULL; |
| 874 | int newReg; |
| 875 | if (loc.wide) |
| 876 | return evalLocWide(cUnit, loc, regClass, update); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 877 | loc = dvmCompilerUpdateLoc(cUnit, loc); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 878 | |
| 879 | if (loc.location == kLocPhysReg) { |
| 880 | if (!regClassMatches(regClass, loc.lowReg)) { |
| 881 | /* Wrong register class. Realloc, copy and transfer ownership */ |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 882 | newReg = dvmCompilerAllocTypedTemp(cUnit, loc.fp, regClass); |
| 883 | dvmCompilerRegCopy(cUnit, newReg, loc.lowReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 884 | copyRegInfo(cUnit, newReg, loc.lowReg); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 885 | dvmCompilerClobber(cUnit, loc.lowReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 886 | loc.lowReg = newReg; |
| 887 | } |
| 888 | return loc; |
| 889 | } |
| 890 | |
| 891 | assert((loc.location != kLocRetval) || (loc.sRegLow == INVALID_SREG)); |
| 892 | |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 893 | newReg = dvmCompilerAllocTypedTemp(cUnit, loc.fp, regClass); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 894 | loc.lowReg = newReg; |
| 895 | |
| 896 | if (update) { |
| 897 | loc.location = kLocPhysReg; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 898 | dvmCompilerMarkLive(cUnit, loc.lowReg, loc.sRegLow); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 899 | } |
| 900 | return loc; |
| 901 | } |
| 902 | |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 903 | static inline int getDestSSAName(MIR *mir, int num) |
| 904 | { |
| 905 | assert(mir->ssaRep->numDefs > num); |
| 906 | return mir->ssaRep->defs[num]; |
| 907 | } |
| 908 | |
| 909 | // Get the LocRecord associated with an SSA name use. |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 910 | extern RegLocation dvmCompilerGetSrc(CompilationUnit *cUnit, MIR *mir, int num) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 911 | { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 912 | RegLocation loc = cUnit->regLocation[ |
| 913 | SREG(cUnit, dvmCompilerSSASrc(mir, num))]; |
| 914 | loc.fp = cUnit->regLocation[dvmCompilerSSASrc(mir, num)].fp; |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 915 | loc.wide = false; |
| 916 | return loc; |
| 917 | } |
| 918 | |
| 919 | // Get the LocRecord associated with an SSA name def. |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 920 | extern RegLocation dvmCompilerGetDest(CompilationUnit *cUnit, MIR *mir, |
| 921 | int num) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 922 | { |
| 923 | RegLocation loc = cUnit->regLocation[SREG(cUnit, getDestSSAName(mir, num))]; |
| 924 | loc.fp = cUnit->regLocation[getDestSSAName(mir, num)].fp; |
| 925 | loc.wide = false; |
| 926 | return loc; |
| 927 | } |
| 928 | |
| 929 | static RegLocation getLocWide(CompilationUnit *cUnit, MIR *mir, |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 930 | int low, int high, bool isSrc) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 931 | { |
| 932 | RegLocation lowLoc; |
| 933 | RegLocation highLoc; |
| 934 | /* Copy loc record for low word and patch in data from high word */ |
| 935 | if (isSrc) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 936 | lowLoc = dvmCompilerGetSrc(cUnit, mir, low); |
| 937 | highLoc = dvmCompilerGetSrc(cUnit, mir, high); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 938 | } else { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 939 | lowLoc = dvmCompilerGetDest(cUnit, mir, low); |
| 940 | highLoc = dvmCompilerGetDest(cUnit, mir, high); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 941 | } |
| 942 | /* Avoid this case by either promoting both or neither. */ |
| 943 | assert(lowLoc.location == highLoc.location); |
| 944 | if (lowLoc.location == kLocPhysReg) { |
| 945 | /* This case shouldn't happen if we've named correctly */ |
| 946 | assert(lowLoc.fp == highLoc.fp); |
| 947 | } |
| 948 | lowLoc.wide = true; |
| 949 | lowLoc.highReg = highLoc.lowReg; |
| 950 | return lowLoc; |
| 951 | } |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 952 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 953 | extern RegLocation dvmCompilerGetDestWide(CompilationUnit *cUnit, MIR *mir, |
| 954 | int low, int high) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 955 | { |
| 956 | return getLocWide(cUnit, mir, low, high, false); |
| 957 | } |
| 958 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 959 | extern RegLocation dvmCompilerGetSrcWide(CompilationUnit *cUnit, MIR *mir, |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 960 | int low, int high) |
| 961 | { |
| 962 | return getLocWide(cUnit, mir, low, high, true); |
| 963 | } |
| 964 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 965 | extern RegLocation dvmCompilerGetReturnWide(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 966 | { |
| 967 | RegLocation res = LOC_C_RETURN_WIDE; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 968 | dvmCompilerClobber(cUnit, r0); |
| 969 | dvmCompilerClobber(cUnit, r1); |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 970 | dvmCompilerMarkInUse(cUnit, r0); |
| 971 | dvmCompilerMarkInUse(cUnit, r1); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 972 | dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 973 | return res; |
| 974 | } |
| 975 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 976 | extern RegLocation dvmCompilerGetReturnWideAlt(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 977 | { |
| 978 | RegLocation res = LOC_C_RETURN_WIDE; |
| 979 | res.lowReg = r2; |
| 980 | res.highReg = r3; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 981 | dvmCompilerClobber(cUnit, r2); |
| 982 | dvmCompilerClobber(cUnit, r3); |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 983 | dvmCompilerMarkInUse(cUnit, r2); |
| 984 | dvmCompilerMarkInUse(cUnit, r3); |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 985 | dvmCompilerMarkPair(cUnit, res.lowReg, res.highReg); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 986 | return res; |
| 987 | } |
| 988 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 989 | extern RegLocation dvmCompilerGetReturn(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 990 | { |
| 991 | RegLocation res = LOC_C_RETURN; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 992 | dvmCompilerClobber(cUnit, r0); |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 993 | dvmCompilerMarkInUse(cUnit, r0); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 994 | return res; |
| 995 | } |
| 996 | |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 997 | extern RegLocation dvmCompilerGetReturnAlt(CompilationUnit *cUnit) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 998 | { |
| 999 | RegLocation res = LOC_C_RETURN; |
| 1000 | res.lowReg = r1; |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 1001 | dvmCompilerClobber(cUnit, r1); |
| Elliott Hughes | 6a55513 | 2010-02-25 15:41:42 -0800 | [diff] [blame] | 1002 | dvmCompilerMarkInUse(cUnit, r1); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 1003 | return res; |
| 1004 | } |
| 1005 | |
| 1006 | /* Kill the corresponding bit in the null-checked register list */ |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 1007 | extern void dvmCompilerKillNullCheckedLoc(CompilationUnit *cUnit, |
| 1008 | RegLocation loc) |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 1009 | { |
| 1010 | if (loc.location != kLocRetval) { |
| 1011 | assert(loc.sRegLow != INVALID_SREG); |
| 1012 | dvmClearBit(cUnit->regPool->nullCheckedRegs, loc.sRegLow); |
| 1013 | if (loc.wide) { |
| Bill Buzbee | c6f1066 | 2010-02-09 11:16:15 -0800 | [diff] [blame] | 1014 | assert(dvmCompilerSRegHi(loc.sRegLow) != INVALID_SREG); |
| 1015 | dvmClearBit(cUnit->regPool->nullCheckedRegs, |
| 1016 | dvmCompilerSRegHi(loc.sRegLow)); |
| Bill Buzbee | 1465db5 | 2009-09-23 17:17:35 -0700 | [diff] [blame] | 1017 | } |
| 1018 | } |
| 1019 | } |
| Ben Cheng | 5d90c20 | 2009-11-22 23:31:11 -0800 | [diff] [blame] | 1020 | |
| 1021 | extern void dvmCompilerFlushRegWideForV5TEVFP(CompilationUnit *cUnit, |
| 1022 | int reg1, int reg2) |
| 1023 | { |
| 1024 | flushRegWide(cUnit, reg1, reg2); |
| 1025 | } |
| 1026 | |
| 1027 | extern void dvmCompilerFlushRegForV5TEVFP(CompilationUnit *cUnit, int reg) |
| 1028 | { |
| 1029 | flushReg(cUnit, reg); |
| 1030 | } |