blob: ef72e5251554143bd74e5f54b60f3b1de7f01531 [file] [log] [blame]
buzbeee88dfbf2012-03-05 11:19:57 -08001/*
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
17namespace art {
18
buzbeeb046e162012-10-30 15:48:42 -070019/* This file contains codegen for the X86 ISA */
buzbeee88dfbf2012-03-05 11:19:57 -080020
21/*
22 * Alloc a pair of core registers, or a double. Low reg in low byte,
23 * high reg in next byte.
24 */
25int oatAllocTypedTempPair(CompilationUnit *cUnit, bool fpHint,
Bill Buzbeea114add2012-05-03 15:00:40 -070026 int regClass)
27{
Ian Rogersf7d9ad32012-03-13 18:45:39 -070028 int highReg;
29 int lowReg;
30 int res = 0;
buzbeee88dfbf2012-03-05 11:19:57 -080031
Ian Rogersf7d9ad32012-03-13 18:45:39 -070032 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
33 lowReg = oatAllocTempDouble(cUnit);
34 highReg = lowReg + 1;
buzbeee88dfbf2012-03-05 11:19:57 -080035 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
36 return res;
Ian Rogersf7d9ad32012-03-13 18:45:39 -070037 }
38
39 lowReg = oatAllocTemp(cUnit);
40 highReg = oatAllocTemp(cUnit);
41 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
42 return res;
buzbeee88dfbf2012-03-05 11:19:57 -080043}
44
Ian Rogersf7d9ad32012-03-13 18:45:39 -070045int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass) {
46 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
47 return oatAllocTempFloat(cUnit);
48 }
49 return oatAllocTemp(cUnit);
buzbeee88dfbf2012-03-05 11:19:57 -080050}
51
Ian Rogersf7d9ad32012-03-13 18:45:39 -070052void oatInitializeRegAlloc(CompilationUnit* cUnit) {
53 int numRegs = sizeof(coreRegs)/sizeof(*coreRegs);
54 int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs);
55 int numTemps = sizeof(coreTemps)/sizeof(*coreTemps);
56 int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs);
57 int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps);
58 RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true,
59 kAllocRegAlloc);
60 cUnit->regPool = pool;
61 pool->numCoreRegs = numRegs;
62 pool->coreRegs = (RegisterInfo *)
Bill Buzbeea114add2012-05-03 15:00:40 -070063 oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs), true,
64 kAllocRegAlloc);
Ian Rogersf7d9ad32012-03-13 18:45:39 -070065 pool->numFPRegs = numFPRegs;
66 pool->FPRegs = (RegisterInfo *)
Bill Buzbeea114add2012-05-03 15:00:40 -070067 oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true,
68 kAllocRegAlloc);
Ian Rogersf7d9ad32012-03-13 18:45:39 -070069 oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs);
70 oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs);
71 // Keep special registers from being allocated
72 for (int i = 0; i < numReserved; i++) {
73 oatMarkInUse(cUnit, reservedRegs[i]);
74 }
75 // Mark temp regs - all others not in use can be used for promotion
76 for (int i = 0; i < numTemps; i++) {
77 oatMarkTemp(cUnit, coreTemps[i]);
78 }
79 for (int i = 0; i < numFPTemps; i++) {
80 oatMarkTemp(cUnit, fpTemps[i]);
81 }
82 // Construct the alias map.
83 cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs *
84 sizeof(cUnit->phiAliasMap[0]), false,
85 kAllocDFInfo);
86 for (int i = 0; i < cUnit->numSSARegs; i++) {
87 cUnit->phiAliasMap[i] = i;
88 }
89 for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) {
90 int defReg = phi->ssaRep->defs[0];
91 for (int i = 0; i < phi->ssaRep->numUses; i++) {
92 for (int j = 0; j < cUnit->numSSARegs; j++) {
93 if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) {
94 cUnit->phiAliasMap[j] = defReg;
buzbeee88dfbf2012-03-05 11:19:57 -080095 }
Ian Rogersf7d9ad32012-03-13 18:45:39 -070096 }
buzbeee88dfbf2012-03-05 11:19:57 -080097 }
Ian Rogersf7d9ad32012-03-13 18:45:39 -070098 }
buzbeee88dfbf2012-03-05 11:19:57 -080099}
100
101void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
Bill Buzbeea114add2012-05-03 15:00:40 -0700102 RegLocation rlFree)
103{
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700104 if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) &&
105 (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) {
106 // No overlap, free both
107 oatFreeTemp(cUnit, rlFree.lowReg);
108 oatFreeTemp(cUnit, rlFree.highReg);
109 }
buzbeee88dfbf2012-03-05 11:19:57 -0800110}
111
112
113} // namespace art