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