blob: 38b9df813c1c1991e4cfff873f15c5381f0ef01a [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,
Ian Rogersabda43c2012-03-13 18:45:39 -070032 int regClass) {
33 int highReg;
34 int lowReg;
35 int res = 0;
buzbeee88dfbf2012-03-05 11:19:57 -080036
Ian Rogersabda43c2012-03-13 18:45:39 -070037 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
38 lowReg = oatAllocTempDouble(cUnit);
39 highReg = lowReg + 1;
buzbeee88dfbf2012-03-05 11:19:57 -080040 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
41 return res;
Ian Rogersabda43c2012-03-13 18:45:39 -070042 }
43
44 lowReg = oatAllocTemp(cUnit);
45 highReg = oatAllocTemp(cUnit);
46 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
47 return res;
buzbeee88dfbf2012-03-05 11:19:57 -080048}
49
Ian Rogersabda43c2012-03-13 18:45:39 -070050int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass) {
51 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
52 return oatAllocTempFloat(cUnit);
53 }
54 return oatAllocTemp(cUnit);
buzbeee88dfbf2012-03-05 11:19:57 -080055}
56
Ian Rogersabda43c2012-03-13 18:45:39 -070057void 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;
buzbeee88dfbf2012-03-05 11:19:57 -0800100 }
Ian Rogersabda43c2012-03-13 18:45:39 -0700101 }
buzbeee88dfbf2012-03-05 11:19:57 -0800102 }
Ian Rogersabda43c2012-03-13 18:45:39 -0700103 }
buzbeee88dfbf2012-03-05 11:19:57 -0800104}
105
106void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
Ian Rogersabda43c2012-03-13 18:45:39 -0700107 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 }
buzbeee88dfbf2012-03-05 11:19:57 -0800114}
115
116
117} // namespace art