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, |
| 32 | int regClass) |
| 33 | { |
| 34 | UNIMPLEMENTED(WARNING) << "oatAllocTypedTemp"; |
| 35 | return 0; |
| 36 | #if 0 |
| 37 | int highReg; |
| 38 | int lowReg; |
| 39 | int res = 0; |
| 40 | |
| 41 | if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) { |
| 42 | lowReg = oatAllocTempDouble(cUnit); |
| 43 | highReg = lowReg + 1; |
| 44 | res = (lowReg & 0xff) | ((highReg & 0xff) << 8); |
| 45 | return res; |
| 46 | } |
| 47 | |
| 48 | lowReg = oatAllocTemp(cUnit); |
| 49 | highReg = oatAllocTemp(cUnit); |
| 50 | res = (lowReg & 0xff) | ((highReg & 0xff) << 8); |
| 51 | return res; |
| 52 | #endif |
| 53 | } |
| 54 | |
| 55 | int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass) |
| 56 | { |
| 57 | if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) |
| 58 | { |
| 59 | return oatAllocTempFloat(cUnit); |
| 60 | } |
| 61 | return oatAllocTemp(cUnit); |
| 62 | } |
| 63 | |
| 64 | void oatInitializeRegAlloc(CompilationUnit* cUnit) |
| 65 | { |
| 66 | UNIMPLEMENTED(WARNING) << "oatInitializeRegAlloc"; |
| 67 | #if 0 |
| 68 | int numRegs = sizeof(coreRegs)/sizeof(*coreRegs); |
| 69 | int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs); |
| 70 | int numTemps = sizeof(coreTemps)/sizeof(*coreTemps); |
| 71 | int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs); |
| 72 | int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps); |
| 73 | RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true, |
| 74 | kAllocRegAlloc); |
| 75 | cUnit->regPool = pool; |
| 76 | pool->numCoreRegs = numRegs; |
| 77 | pool->coreRegs = (RegisterInfo *) |
| 78 | oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs), |
| 79 | true, kAllocRegAlloc); |
| 80 | pool->numFPRegs = numFPRegs; |
| 81 | pool->FPRegs = (RegisterInfo *) |
| 82 | oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true, |
| 83 | kAllocRegAlloc); |
| 84 | oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs); |
| 85 | oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs); |
| 86 | // Keep special registers from being allocated |
| 87 | for (int i = 0; i < numReserved; i++) { |
| 88 | if (NO_SUSPEND && !cUnit->genDebugger && |
| 89 | (reservedRegs[i] == rSUSPEND)) { |
| 90 | //To measure cost of suspend check |
| 91 | continue; |
| 92 | } |
| 93 | oatMarkInUse(cUnit, reservedRegs[i]); |
| 94 | } |
| 95 | // Mark temp regs - all others not in use can be used for promotion |
| 96 | for (int i = 0; i < numTemps; i++) { |
| 97 | oatMarkTemp(cUnit, coreTemps[i]); |
| 98 | } |
| 99 | for (int i = 0; i < numFPTemps; i++) { |
| 100 | oatMarkTemp(cUnit, fpTemps[i]); |
| 101 | } |
| 102 | // Construct the alias map. |
| 103 | cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs * |
| 104 | sizeof(cUnit->phiAliasMap[0]), false, |
| 105 | kAllocDFInfo); |
| 106 | for (int i = 0; i < cUnit->numSSARegs; i++) { |
| 107 | cUnit->phiAliasMap[i] = i; |
| 108 | } |
| 109 | for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) { |
| 110 | int defReg = phi->ssaRep->defs[0]; |
| 111 | for (int i = 0; i < phi->ssaRep->numUses; i++) { |
| 112 | for (int j = 0; j < cUnit->numSSARegs; j++) { |
| 113 | if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) { |
| 114 | cUnit->phiAliasMap[j] = defReg; |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | #endif |
| 120 | } |
| 121 | |
| 122 | void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep, |
| 123 | RegLocation rlFree) |
| 124 | { |
| 125 | if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) && |
| 126 | (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) { |
| 127 | // No overlap, free both |
| 128 | oatFreeTemp(cUnit, rlFree.lowReg); |
| 129 | oatFreeTemp(cUnit, rlFree.highReg); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | |
| 134 | } // namespace art |