blob: e7ad60c838b48191475d9b1c85587a521dedc297 [file] [log] [blame]
buzbeee3acd072012-02-25 17:03:10 -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
buzbeeb046e162012-10-30 15:48:42 -070019/* This file contains codegen for the Mips ISA */
buzbeee3acd072012-02-25 17:03:10 -080020
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,
Bill Buzbeea114add2012-05-03 15:00:40 -070026 int regClass)
buzbeee3acd072012-02-25 17:03:10 -080027{
Bill Buzbeea114add2012-05-03 15:00:40 -070028 int highReg;
29 int lowReg;
30 int res = 0;
buzbeee3acd072012-02-25 17:03:10 -080031
32#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070033 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
34 lowReg = oatAllocTempDouble(cUnit);
35 highReg = lowReg + 1;
buzbeee3acd072012-02-25 17:03:10 -080036 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
37 return res;
Bill Buzbeea114add2012-05-03 15:00:40 -070038 }
39#endif
40
41 lowReg = oatAllocTemp(cUnit);
42 highReg = oatAllocTemp(cUnit);
43 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
44 return res;
buzbeee3acd072012-02-25 17:03:10 -080045}
46
47int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass)
48{
49#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070050 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg))
buzbeee3acd072012-02-25 17:03:10 -080051{
Bill Buzbeea114add2012-05-03 15:00:40 -070052 return oatAllocTempFloat(cUnit);
buzbeee3acd072012-02-25 17:03:10 -080053}
54#endif
Bill Buzbeea114add2012-05-03 15:00:40 -070055 return oatAllocTemp(cUnit);
buzbeee3acd072012-02-25 17:03:10 -080056}
57
buzbee5de34942012-03-01 14:51:57 -080058void oatInitializeRegAlloc(CompilationUnit* cUnit)
59{
Bill Buzbeea114add2012-05-03 15:00:40 -070060 int numRegs = sizeof(coreRegs)/sizeof(*coreRegs);
61 int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs);
62 int numTemps = sizeof(coreTemps)/sizeof(*coreTemps);
buzbee5de34942012-03-01 14:51:57 -080063#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070064 int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs);
65 int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps);
buzbee5de34942012-03-01 14:51:57 -080066#else
Bill Buzbeea114add2012-05-03 15:00:40 -070067 int numFPRegs = 0;
68 int numFPTemps = 0;
buzbee5de34942012-03-01 14:51:57 -080069#endif
Bill Buzbeea114add2012-05-03 15:00:40 -070070 RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true,
71 kAllocRegAlloc);
72 cUnit->regPool = pool;
73 pool->numCoreRegs = numRegs;
74 pool->coreRegs = (RegisterInfo *)
75 oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs),
76 true, kAllocRegAlloc);
77 pool->numFPRegs = numFPRegs;
78 pool->FPRegs = (RegisterInfo *)
79 oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true,
80 kAllocRegAlloc);
81 oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs);
82 oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs);
83 // Keep special registers from being allocated
84 for (int i = 0; i < numReserved; i++) {
buzbeeb046e162012-10-30 15:48:42 -070085 if (NO_SUSPEND && (reservedRegs[i] == rSUSPEND)) {
Bill Buzbeea114add2012-05-03 15:00:40 -070086 //To measure cost of suspend check
87 continue;
buzbee5de34942012-03-01 14:51:57 -080088 }
Bill Buzbeea114add2012-05-03 15:00:40 -070089 oatMarkInUse(cUnit, reservedRegs[i]);
90 }
91 // Mark temp regs - all others not in use can be used for promotion
92 for (int i = 0; i < numTemps; i++) {
93 oatMarkTemp(cUnit, coreTemps[i]);
94 }
95 for (int i = 0; i < numFPTemps; i++) {
96 oatMarkTemp(cUnit, fpTemps[i]);
97 }
98 // Construct the alias map.
99 cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs *
100 sizeof(cUnit->phiAliasMap[0]), false,
101 kAllocDFInfo);
102 for (int i = 0; i < cUnit->numSSARegs; i++) {
103 cUnit->phiAliasMap[i] = i;
104 }
105 for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) {
106 int defReg = phi->ssaRep->defs[0];
107 for (int i = 0; i < phi->ssaRep->numUses; i++) {
108 for (int j = 0; j < cUnit->numSSARegs; j++) {
109 if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) {
110 cUnit->phiAliasMap[j] = defReg;
111 }
112 }
buzbee5de34942012-03-01 14:51:57 -0800113 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700114 }
buzbee5de34942012-03-01 14:51:57 -0800115}
116
117void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
Bill Buzbeea114add2012-05-03 15:00:40 -0700118 RegLocation rlFree)
buzbee5de34942012-03-01 14:51:57 -0800119{
Bill Buzbeea114add2012-05-03 15:00:40 -0700120 if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) &&
121 (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) {
122 // No overlap, free both
123 oatFreeTemp(cUnit, rlFree.lowReg);
124 oatFreeTemp(cUnit, rlFree.highReg);
125 }
buzbee5de34942012-03-01 14:51:57 -0800126}
127
128
buzbeee3acd072012-02-25 17:03:10 -0800129} // namespace art