buzbee | e88dfbf | 2012-03-05 11:19:57 -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 | /* |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 20 | * This file contains codegen for the X86 ISA and is intended to be |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 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, |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 32 | int regClass) { |
| 33 | int highReg; |
| 34 | int lowReg; |
| 35 | int res = 0; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 36 | |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 37 | if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) { |
| 38 | lowReg = oatAllocTempDouble(cUnit); |
| 39 | highReg = lowReg + 1; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 40 | res = (lowReg & 0xff) | ((highReg & 0xff) << 8); |
| 41 | return res; |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | lowReg = oatAllocTemp(cUnit); |
| 45 | highReg = oatAllocTemp(cUnit); |
| 46 | res = (lowReg & 0xff) | ((highReg & 0xff) << 8); |
| 47 | return res; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 50 | int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass) { |
| 51 | if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) { |
| 52 | return oatAllocTempFloat(cUnit); |
| 53 | } |
| 54 | return oatAllocTemp(cUnit); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 55 | } |
| 56 | |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 57 | void oatInitializeRegAlloc(CompilationUnit* cUnit) { |
| 58 | int numRegs = sizeof(coreRegs)/sizeof(*coreRegs); |
| 59 | int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs); |
| 60 | int numTemps = sizeof(coreTemps)/sizeof(*coreTemps); |
| 61 | int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs); |
| 62 | int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps); |
| 63 | RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true, |
| 64 | kAllocRegAlloc); |
| 65 | cUnit->regPool = pool; |
| 66 | pool->numCoreRegs = numRegs; |
| 67 | pool->coreRegs = (RegisterInfo *) |
| 68 | oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs), |
| 69 | true, kAllocRegAlloc); |
| 70 | pool->numFPRegs = numFPRegs; |
| 71 | pool->FPRegs = (RegisterInfo *) |
| 72 | oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true, |
| 73 | kAllocRegAlloc); |
| 74 | oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs); |
| 75 | oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs); |
| 76 | // Keep special registers from being allocated |
| 77 | for (int i = 0; i < numReserved; i++) { |
| 78 | oatMarkInUse(cUnit, reservedRegs[i]); |
| 79 | } |
| 80 | // Mark temp regs - all others not in use can be used for promotion |
| 81 | for (int i = 0; i < numTemps; i++) { |
| 82 | oatMarkTemp(cUnit, coreTemps[i]); |
| 83 | } |
| 84 | for (int i = 0; i < numFPTemps; i++) { |
| 85 | oatMarkTemp(cUnit, fpTemps[i]); |
| 86 | } |
| 87 | // Construct the alias map. |
| 88 | cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs * |
| 89 | sizeof(cUnit->phiAliasMap[0]), false, |
| 90 | kAllocDFInfo); |
| 91 | for (int i = 0; i < cUnit->numSSARegs; i++) { |
| 92 | cUnit->phiAliasMap[i] = i; |
| 93 | } |
| 94 | for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) { |
| 95 | int defReg = phi->ssaRep->defs[0]; |
| 96 | for (int i = 0; i < phi->ssaRep->numUses; i++) { |
| 97 | for (int j = 0; j < cUnit->numSSARegs; j++) { |
| 98 | if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) { |
| 99 | cUnit->phiAliasMap[j] = defReg; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 100 | } |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 101 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 102 | } |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 103 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep, |
Ian Rogers | abda43c | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 107 | RegLocation rlFree) { |
| 108 | if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) && |
| 109 | (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) { |
| 110 | // No overlap, free both |
| 111 | oatFreeTemp(cUnit, rlFree.lowReg); |
| 112 | oatFreeTemp(cUnit, rlFree.highReg); |
| 113 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
| 117 | } // namespace art |