blob: 894488a073719ee5ff639429dd686900e26738ca [file] [log] [blame]
buzbee67bf8852011-08-17 17:51:35 -07001/*
2 * Copyright (C) 2011 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
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080017namespace art {
18
buzbeeb046e162012-10-30 15:48:42 -070019/* This file contains codegen for the Thumb ISA. */
buzbee67bf8852011-08-17 17:51:35 -070020
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, int regClass)
26{
Bill Buzbeea114add2012-05-03 15:00:40 -070027 int highReg;
28 int lowReg;
29 int res = 0;
buzbee67bf8852011-08-17 17:51:35 -070030
Bill Buzbeea114add2012-05-03 15:00:40 -070031 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
32 lowReg = oatAllocTempDouble(cUnit);
33 highReg = lowReg + 1;
34 } else {
35 lowReg = oatAllocTemp(cUnit);
36 highReg = oatAllocTemp(cUnit);
37 }
38 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
39 return res;
buzbee67bf8852011-08-17 17:51:35 -070040}
41
42int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint, int regClass)
43{
Bill Buzbeea114add2012-05-03 15:00:40 -070044 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg))
45 return oatAllocTempFloat(cUnit);
46 return oatAllocTemp(cUnit);
buzbee67bf8852011-08-17 17:51:35 -070047}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080048
buzbee31a4a6f2012-02-28 15:36:15 -080049void oatInitializeRegAlloc(CompilationUnit* cUnit)
50{
Bill Buzbeea114add2012-05-03 15:00:40 -070051 int numRegs = sizeof(coreRegs)/sizeof(*coreRegs);
52 int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs);
53 int numTemps = sizeof(coreTemps)/sizeof(*coreTemps);
54 int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs);
55 int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps);
56 RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true,
57 kAllocRegAlloc);
58 cUnit->regPool = pool;
59 pool->numCoreRegs = numRegs;
60 pool->coreRegs = (RegisterInfo *)
61 oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs),
62 true, kAllocRegAlloc);
63 pool->numFPRegs = numFPRegs;
64 pool->FPRegs = (RegisterInfo *)
65 oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true,
66 kAllocRegAlloc);
67 oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs);
68 oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs);
69 // Keep special registers from being allocated
70 for (int i = 0; i < numReserved; i++) {
buzbeeb046e162012-10-30 15:48:42 -070071 if (NO_SUSPEND && (reservedRegs[i] == rSUSPEND)) {
Bill Buzbeea114add2012-05-03 15:00:40 -070072 //To measure cost of suspend check
73 continue;
buzbee31a4a6f2012-02-28 15:36:15 -080074 }
Bill Buzbeea114add2012-05-03 15:00:40 -070075 oatMarkInUse(cUnit, reservedRegs[i]);
76 }
77 // Mark temp regs - all others not in use can be used for promotion
78 for (int i = 0; i < numTemps; i++) {
79 oatMarkTemp(cUnit, coreTemps[i]);
80 }
81 for (int i = 0; i < numFPTemps; i++) {
82 oatMarkTemp(cUnit, fpTemps[i]);
83 }
buzbeee1965672012-03-11 18:39:19 -070084
Bill Buzbeea114add2012-05-03 15:00:40 -070085 // Start allocation at r2 in an attempt to avoid clobbering return values
86 pool->nextCoreReg = r2;
buzbeee1965672012-03-11 18:39:19 -070087
Bill Buzbeea114add2012-05-03 15:00:40 -070088 // 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;
101 }
102 }
buzbee31a4a6f2012-02-28 15:36:15 -0800103 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700104 }
buzbee31a4a6f2012-02-28 15:36:15 -0800105}
106
107void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
108 RegLocation rlFree)
109{
Bill Buzbeea114add2012-05-03 15:00:40 -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 }
buzbee31a4a6f2012-02-28 15:36:15 -0800116}
117
118
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800119} // namespace art