buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | namespace art { |
| 18 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 19 | /* This file contains codegen for the Mips ISA */ |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Alloc a pair of core registers, or a double. Low reg in low byte, |
| 23 | * high reg in next byte. |
| 24 | */ |
| 25 | int oatAllocTypedTempPair(CompilationUnit *cUnit, bool fpHint, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 26 | int regClass) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 27 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 28 | int highReg; |
| 29 | int lowReg; |
| 30 | int res = 0; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 31 | |
| 32 | #ifdef __mips_hard_float |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 33 | if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) { |
| 34 | lowReg = oatAllocTempDouble(cUnit); |
| 35 | highReg = lowReg + 1; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 36 | res = (lowReg & 0xff) | ((highReg & 0xff) << 8); |
| 37 | return res; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 38 | } |
| 39 | #endif |
| 40 | |
| 41 | lowReg = oatAllocTemp(cUnit); |
| 42 | highReg = oatAllocTemp(cUnit); |
| 43 | res = (lowReg & 0xff) | ((highReg & 0xff) << 8); |
| 44 | return res; |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass) |
| 48 | { |
| 49 | #ifdef __mips_hard_float |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 50 | if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 51 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 52 | return oatAllocTempFloat(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 53 | } |
| 54 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 55 | return oatAllocTemp(cUnit); |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 56 | } |
| 57 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 58 | void oatInitializeRegAlloc(CompilationUnit* cUnit) |
| 59 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 60 | int numRegs = sizeof(coreRegs)/sizeof(*coreRegs); |
| 61 | int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs); |
| 62 | int numTemps = sizeof(coreTemps)/sizeof(*coreTemps); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 63 | #ifdef __mips_hard_float |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 64 | int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs); |
| 65 | int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps); |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 66 | #else |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 67 | int numFPRegs = 0; |
| 68 | int numFPTemps = 0; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 69 | #endif |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 70 | RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true, |
| 71 | kAllocRegAlloc); |
| 72 | cUnit->regPool = pool; |
| 73 | pool->numCoreRegs = numRegs; |
| 74 | pool->coreRegs = (RegisterInfo *) |
| 75 | oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs), |
| 76 | true, kAllocRegAlloc); |
| 77 | pool->numFPRegs = numFPRegs; |
| 78 | pool->FPRegs = (RegisterInfo *) |
| 79 | oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true, |
| 80 | kAllocRegAlloc); |
| 81 | oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs); |
| 82 | oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs); |
| 83 | // Keep special registers from being allocated |
| 84 | for (int i = 0; i < numReserved; i++) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 85 | if (NO_SUSPEND && (reservedRegs[i] == rSUSPEND)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 86 | //To measure cost of suspend check |
| 87 | continue; |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 88 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 89 | oatMarkInUse(cUnit, reservedRegs[i]); |
| 90 | } |
| 91 | // Mark temp regs - all others not in use can be used for promotion |
| 92 | for (int i = 0; i < numTemps; i++) { |
| 93 | oatMarkTemp(cUnit, coreTemps[i]); |
| 94 | } |
| 95 | for (int i = 0; i < numFPTemps; i++) { |
| 96 | oatMarkTemp(cUnit, fpTemps[i]); |
| 97 | } |
| 98 | // Construct the alias map. |
| 99 | cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs * |
| 100 | sizeof(cUnit->phiAliasMap[0]), false, |
| 101 | kAllocDFInfo); |
| 102 | for (int i = 0; i < cUnit->numSSARegs; i++) { |
| 103 | cUnit->phiAliasMap[i] = i; |
| 104 | } |
| 105 | for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) { |
| 106 | int defReg = phi->ssaRep->defs[0]; |
| 107 | for (int i = 0; i < phi->ssaRep->numUses; i++) { |
| 108 | for (int j = 0; j < cUnit->numSSARegs; j++) { |
| 109 | if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) { |
| 110 | cUnit->phiAliasMap[j] = defReg; |
| 111 | } |
| 112 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 113 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 114 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 118 | RegLocation rlFree) |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 119 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 120 | if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) && |
| 121 | (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) { |
| 122 | // No overlap, free both |
| 123 | oatFreeTemp(cUnit, rlFree.lowReg); |
| 124 | oatFreeTemp(cUnit, rlFree.highReg); |
| 125 | } |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | |
buzbee | e3acd07 | 2012-02-25 17:03:10 -0800 | [diff] [blame] | 129 | } // namespace art |