blob: 9f392124ee07c431555fc990bd9ceec52fb9003d [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
19/*
20 * This file contains codegen for the Mips 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,
Bill Buzbeea114add2012-05-03 15:00:40 -070032 int regClass)
buzbeee3acd072012-02-25 17:03:10 -080033{
Bill Buzbeea114add2012-05-03 15:00:40 -070034 int highReg;
35 int lowReg;
36 int res = 0;
buzbeee3acd072012-02-25 17:03:10 -080037
38#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070039 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg)) {
40 lowReg = oatAllocTempDouble(cUnit);
41 highReg = lowReg + 1;
buzbeee3acd072012-02-25 17:03:10 -080042 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
43 return res;
Bill Buzbeea114add2012-05-03 15:00:40 -070044 }
45#endif
46
47 lowReg = oatAllocTemp(cUnit);
48 highReg = oatAllocTemp(cUnit);
49 res = (lowReg & 0xff) | ((highReg & 0xff) << 8);
50 return res;
buzbeee3acd072012-02-25 17:03:10 -080051}
52
53int oatAllocTypedTemp(CompilationUnit *cUnit, bool fpHint, int regClass)
54{
55#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070056 if (((regClass == kAnyReg) && fpHint) || (regClass == kFPReg))
buzbeee3acd072012-02-25 17:03:10 -080057{
Bill Buzbeea114add2012-05-03 15:00:40 -070058 return oatAllocTempFloat(cUnit);
buzbeee3acd072012-02-25 17:03:10 -080059}
60#endif
Bill Buzbeea114add2012-05-03 15:00:40 -070061 return oatAllocTemp(cUnit);
buzbeee3acd072012-02-25 17:03:10 -080062}
63
buzbee5de34942012-03-01 14:51:57 -080064void oatInitializeRegAlloc(CompilationUnit* cUnit)
65{
Bill Buzbeea114add2012-05-03 15:00:40 -070066 int numRegs = sizeof(coreRegs)/sizeof(*coreRegs);
67 int numReserved = sizeof(reservedRegs)/sizeof(*reservedRegs);
68 int numTemps = sizeof(coreTemps)/sizeof(*coreTemps);
buzbee5de34942012-03-01 14:51:57 -080069#ifdef __mips_hard_float
Bill Buzbeea114add2012-05-03 15:00:40 -070070 int numFPRegs = sizeof(fpRegs)/sizeof(*fpRegs);
71 int numFPTemps = sizeof(fpTemps)/sizeof(*fpTemps);
buzbee5de34942012-03-01 14:51:57 -080072#else
Bill Buzbeea114add2012-05-03 15:00:40 -070073 int numFPRegs = 0;
74 int numFPTemps = 0;
buzbee5de34942012-03-01 14:51:57 -080075#endif
Bill Buzbeea114add2012-05-03 15:00:40 -070076 RegisterPool *pool = (RegisterPool *)oatNew(cUnit, sizeof(*pool), true,
77 kAllocRegAlloc);
78 cUnit->regPool = pool;
79 pool->numCoreRegs = numRegs;
80 pool->coreRegs = (RegisterInfo *)
81 oatNew(cUnit, numRegs * sizeof(*cUnit->regPool->coreRegs),
82 true, kAllocRegAlloc);
83 pool->numFPRegs = numFPRegs;
84 pool->FPRegs = (RegisterInfo *)
85 oatNew(cUnit, numFPRegs * sizeof(*cUnit->regPool->FPRegs), true,
86 kAllocRegAlloc);
87 oatInitPool(pool->coreRegs, coreRegs, pool->numCoreRegs);
88 oatInitPool(pool->FPRegs, fpRegs, pool->numFPRegs);
89 // Keep special registers from being allocated
90 for (int i = 0; i < numReserved; i++) {
91 if (NO_SUSPEND && !cUnit->genDebugger &&
92 (reservedRegs[i] == rSUSPEND)) {
93 //To measure cost of suspend check
94 continue;
buzbee5de34942012-03-01 14:51:57 -080095 }
Bill Buzbeea114add2012-05-03 15:00:40 -070096 oatMarkInUse(cUnit, reservedRegs[i]);
97 }
98 // Mark temp regs - all others not in use can be used for promotion
99 for (int i = 0; i < numTemps; i++) {
100 oatMarkTemp(cUnit, coreTemps[i]);
101 }
102 for (int i = 0; i < numFPTemps; i++) {
103 oatMarkTemp(cUnit, fpTemps[i]);
104 }
105 // Construct the alias map.
106 cUnit->phiAliasMap = (int*)oatNew(cUnit, cUnit->numSSARegs *
107 sizeof(cUnit->phiAliasMap[0]), false,
108 kAllocDFInfo);
109 for (int i = 0; i < cUnit->numSSARegs; i++) {
110 cUnit->phiAliasMap[i] = i;
111 }
112 for (MIR* phi = cUnit->phiList; phi; phi = phi->meta.phiNext) {
113 int defReg = phi->ssaRep->defs[0];
114 for (int i = 0; i < phi->ssaRep->numUses; i++) {
115 for (int j = 0; j < cUnit->numSSARegs; j++) {
116 if (cUnit->phiAliasMap[j] == phi->ssaRep->uses[i]) {
117 cUnit->phiAliasMap[j] = defReg;
118 }
119 }
buzbee5de34942012-03-01 14:51:57 -0800120 }
Bill Buzbeea114add2012-05-03 15:00:40 -0700121 }
buzbee5de34942012-03-01 14:51:57 -0800122}
123
124void freeRegLocTemps(CompilationUnit* cUnit, RegLocation rlKeep,
Bill Buzbeea114add2012-05-03 15:00:40 -0700125 RegLocation rlFree)
buzbee5de34942012-03-01 14:51:57 -0800126{
Bill Buzbeea114add2012-05-03 15:00:40 -0700127 if ((rlFree.lowReg != rlKeep.lowReg) && (rlFree.lowReg != rlKeep.highReg) &&
128 (rlFree.highReg != rlKeep.lowReg) && (rlFree.highReg != rlKeep.highReg)) {
129 // No overlap, free both
130 oatFreeTemp(cUnit, rlFree.lowReg);
131 oatFreeTemp(cUnit, rlFree.highReg);
132 }
buzbee5de34942012-03-01 14:51:57 -0800133}
134
135
buzbeee3acd072012-02-25 17:03:10 -0800136} // namespace art