blob: 2886b8f0570f86351aa6fd644e954bc941268ad9 [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
19/*
buzbeea7678db2012-03-05 15:35:46 -080020 * This file contains codegen for the X86 ISA and is intended to be
buzbeee88dfbf2012-03-05 11:19:57 -080021 * 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 */
31int oatAllocTypedTempPair(CompilationUnit *cUnit, bool fpHint,
Bill Buzbeea114add2012-05-03 15:00:40 -070032 int regClass)
33{
Ian Rogersf7d9ad32012-03-13 18:45:39 -070034 int highReg;
35 int lowReg;
36 int res = 0;
buzbeee88dfbf2012-03-05 11:19:57 -080037
Ian Rogersf7d9ad32012-03-13 18:45:39 -070038 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
39 lowReg = oatAllocTempDouble(cUnit);
40 highReg = lowReg + 1;
buzbeee88dfbf2012-03-05 11:19:57 -080041 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
42 return res;
Ian Rogersf7d9ad32012-03-13 18:45:39 -070043 }
44
45 lowReg = oatAllocTemp(cUnit);
46 highReg = oatAllocTemp(cUnit);
47 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
48 return res;
buzbeee88dfbf2012-03-05 11:19:57 -080049}
50
Ian Rogersf7d9ad32012-03-13 18:45:39 -070051int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass) {
52 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
53 return oatAllocTempFloat(cUnit);
54 }
55 return oatAllocTemp(cUnit);
buzbeee88dfbf2012-03-05 11:19:57 -080056}
57
Ian Rogersf7d9ad32012-03-13 18:45:39 -070058void oatInitializeRegAlloc(CompilationUnit* cUnit) {
59 int numRegs = sizeof(coreRegs)/sizeof(*coreRegs);
60 int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs);
61 int numTemps = sizeof(coreTemps)/sizeof(*coreTemps);
62 int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs);
63 int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps);
64 RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true,
65 kAllocRegAlloc);
66 cUnit->regPool = pool;
67 pool->numCoreRegs = numRegs;
68 pool->coreRegs = (RegisterInfo *)
Bill Buzbeea114add2012-05-03 15:00:40 -070069 oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs), true,
70 kAllocRegAlloc);
Ian Rogersf7d9ad32012-03-13 18:45:39 -070071 pool->numFPRegs = numFPRegs;
72 pool->FPRegs = (RegisterInfo *)
Bill Buzbeea114add2012-05-03 15:00:40 -070073 oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true,
74 kAllocRegAlloc);
Ian Rogersf7d9ad32012-03-13 18:45:39 -070075 oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs);
76 oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs);
77 // Keep special registers from being allocated
78 for (int i = 0; i < numReserved; i++) {
79 oatMarkInUse(cUnit, reservedRegs[i]);
80 }
81 // Mark temp regs - all others not in use can be used for promotion
82 for (int i = 0; i < numTemps; i++) {
83 oatMarkTemp(cUnit, coreTemps[i]);
84 }
85 for (int i = 0; i < numFPTemps; i++) {
86 oatMarkTemp(cUnit, fpTemps[i]);
87 }
88 // Construct the alias map.
89 cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs *
90 sizeof(cUnit->phiAliasMap[0]), false,
91 kAllocDFInfo);
92 for (int i = 0; i < cUnit->numSSARegs; i++) {
93 cUnit->phiAliasMap[i] = i;
94 }
95 for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) {
96 int defReg = phi->ssaRep->defs[0];
97 for (int i = 0; i < phi->ssaRep->numUses; i++) {
98 for (int j = 0; j < cUnit->numSSARegs; j++) {
99 if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) {
100 cUnit->phiAliasMap[j] = defReg;
buzbeee88dfbf2012-03-05 11:19:57 -0800101 }
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700102 }
buzbeee88dfbf2012-03-05 11:19:57 -0800103 }
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700104 }
buzbeee88dfbf2012-03-05 11:19:57 -0800105}
106
107void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
Bill Buzbeea114add2012-05-03 15:00:40 -0700108 RegLocation rlFree)
109{
Ian Rogersf7d9ad32012-03-13 18:45:39 -0700110 if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) &&
111 (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) {
112 // No overlap, free both
113 oatFreeTemp(cUnit, rlFree.lowReg);
114 oatFreeTemp(cUnit, rlFree.highReg);
115 }
buzbeee88dfbf2012-03-05 11:19:57 -0800116}
117
118
119} // namespace art