blob: c0f2c771cae4e7ca1a657d3d52842645da48a39d [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{
33 int highReg;
34 int lowReg;
35 int res = 0;
36
37 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;
46}
47
48int oatAllocTypedTemp(CompilationUnit* cUnit, bool fpHint, int regClass)
49{
50 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg))
51 return oatAllocTempFloat(cUnit);
52 return oatAllocTemp(cUnit);
53}
Elliott Hughes11d1b0c2012-01-23 16:57:47 -080054
buzbee31a4a6f2012-02-28 15:36:15 -080055void oatInitializeRegAlloc(CompilationUnit* cUnit)
56{
57 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;
81 }
82 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 }
91 // Construct the alias map.
92 cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs *
93 sizeof(cUnit->phiAliasMap[0]), false,
94 kAllocDFInfo);
95 for (int i = 0; i < cUnit->numSSARegs; i++) {
96 cUnit->phiAliasMap[i] = i;
97 }
98 for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) {
99 int defReg = phi->ssaRep->defs[0];
100 for (int i = 0; i < phi->ssaRep->numUses; i++) {
101 for (int j = 0; j < cUnit->numSSARegs; j++) {
102 if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) {
103 cUnit->phiAliasMap[j] = defReg;
104 }
105 }
106 }
107 }
108}
109
110void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
111 RegLocation rlFree)
112{
113 if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) &&
114 (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) {
115 // No overlap, free both
116 oatFreeTemp(cUnit, rlFree.lowReg);
117 oatFreeTemp(cUnit, rlFree.highReg);
118 }
119}
120
121
Elliott Hughes11d1b0c2012-01-23 16:57:47 -0800122} // namespace art