blob: 98a110cb2b101a0f5e700f881ab3abece8aa95d2 [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
buzbee67bf8852011-08-17 17:51:35 -070019/*
20 * This file contains codegen for the Thumb ISA and is intended to be
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 */
31int oatAllocTypedTempPair(CompilationUnit* cUnit, bool fpHint, int regClass)
32{
Bill Buzbeea114add2012-05-03 15:00:40 -070033 int highReg;
34 int lowReg;
35 int res = 0;
buzbee67bf8852011-08-17 17:51:35 -070036
Bill Buzbeea114add2012-05-03 15:00:40 -070037 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
38 lowReg = oatAllocTempDouble(cUnit);
39 highReg = lowReg + 1;
40 } else {
41 lowReg = oatAllocTemp(cUnit);
42 highReg = oatAllocTemp(cUnit);
43 }
44 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
45 return res;
buzbee67bf8852011-08-17 17:51:35 -070046}
47
48int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint, int regClass)
49{
Bill Buzbeea114add2012-05-03 15:00:40 -070050 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg))
51 return oatAllocTempFloat(cUnit);
52 return oatAllocTemp(cUnit);
buzbee67bf8852011-08-17 17:51:35 -070053}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080054
buzbee31a4a6f2012-02-28 15:36:15 -080055void oatInitializeRegAlloc(CompilationUnit* cUnit)
56{
Bill Buzbeea114add2012-05-03 15:00:40 -070057 int numRegs = sizeof(coreRegs)/sizeof(*coreRegs);
58 int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs);
59 int numTemps = sizeof(coreTemps)/sizeof(*coreTemps);
60 int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs);
61 int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps);
62 RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true,
63 kAllocRegAlloc);
64 cUnit->regPool = pool;
65 pool->numCoreRegs = numRegs;
66 pool->coreRegs = (RegisterInfo *)
67 oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs),
68 true, kAllocRegAlloc);
69 pool->numFPRegs = numFPRegs;
70 pool->FPRegs = (RegisterInfo *)
71 oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true,
72 kAllocRegAlloc);
73 oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs);
74 oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs);
75 // Keep special registers from being allocated
76 for (int i = 0; i < numReserved; i++) {
77 if (NO_SUSPEND && !cUnit->genDebugger &&
78 (reservedRegs[i] == rSUSPEND)) {
79 //To measure cost of suspend check
80 continue;
buzbee31a4a6f2012-02-28 15:36:15 -080081 }
Bill Buzbeea114add2012-05-03 15:00:40 -070082 oatMarkInUse(cUnit, reservedRegs[i]);
83 }
84 // Mark temp regs - all others not in use can be used for promotion
85 for (int i = 0; i < numTemps; i++) {
86 oatMarkTemp(cUnit, coreTemps[i]);
87 }
88 for (int i = 0; i < numFPTemps; i++) {
89 oatMarkTemp(cUnit, fpTemps[i]);
90 }
buzbeee1965672012-03-11 18:39:19 -070091
Bill Buzbeea114add2012-05-03 15:00:40 -070092 // Start allocation at r2 in an attempt to avoid clobbering return values
93 pool->nextCoreReg = r2;
buzbeee1965672012-03-11 18:39:19 -070094
Bill Buzbeea114add2012-05-03 15:00:40 -070095 // Construct the alias map.
96 cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs *
97 sizeof(cUnit->phiAliasMap[0]), false,
98 kAllocDFInfo);
99 for (int i = 0; i < cUnit->numSSARegs; i++) {
100 cUnit->phiAliasMap[i] = i;
101 }
102 for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) {
103 int defReg = phi->ssaRep->defs[0];
104 for (int i = 0; i < phi->ssaRep->numUses; i++) {
105 for (int j = 0; j < cUnit->numSSARegs; j++) {
106 if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) {
107 cUnit->phiAliasMap[j] = defReg;
108 }
109 }
buzbee31a4a6f2012-02-28 15:36:15 -0800110 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700111 }
buzbee31a4a6f2012-02-28 15:36:15 -0800112}
113
114void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
115 RegLocation rlFree)
116{
Bill Buzbeea114add2012-05-03 15:00:40 -0700117 if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) &&
118 (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) {
119 // No overlap, free both
120 oatFreeTemp(cUnit, rlFree.lowReg);
121 oatFreeTemp(cUnit, rlFree.highReg);
122 }
buzbee31a4a6f2012-02-28 15:36:15 -0800123}
124
125
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800126} // namespace art