buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | /* |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 18 | * This file contains X86-specific register allocation support. |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include "../../CompilerUtility.h" |
| 22 | #include "../../CompilerIR.h" |
| 23 | #include "../..//Dataflow.h" |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame] | 24 | #include "X86LIR.h" |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 25 | #include "Codegen.h" |
| 26 | #include "../Ralloc.h" |
| 27 | |
| 28 | namespace art { |
| 29 | |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 30 | void oatAdjustSpillMask(CompilationUnit* cUnit) { |
| 31 | // Adjustment for LR spilling, x86 has no LR so nothing to do here |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 32 | cUnit->coreSpillMask |= (1 << rRET); |
| 33 | cUnit->numCoreSpills++; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* |
| 37 | * Mark a callee-save fp register as promoted. Note that |
| 38 | * vpush/vpop uses contiguous register lists so we must |
| 39 | * include any holes in the mask. Associate holes with |
| 40 | * Dalvik register INVALID_VREG (0xFFFFU). |
| 41 | */ |
buzbee | 9c044ce | 2012-03-18 13:24:07 -0700 | [diff] [blame] | 42 | void oatMarkPreservedSingle(CompilationUnit* cUnit, int vReg, int reg) |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 43 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 44 | UNIMPLEMENTED(WARNING) << "oatMarkPreservedSingle"; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 45 | #if 0 |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 46 | LOG(FATAL) << "No support yet for promoted FP regs"; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 47 | #endif |
| 48 | } |
| 49 | |
| 50 | void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2) |
| 51 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 52 | RegisterInfo* info1 = oatGetRegInfo(cUnit, reg1); |
| 53 | RegisterInfo* info2 = oatGetRegInfo(cUnit, reg2); |
| 54 | DCHECK(info1 && info2 && info1->pair && info2->pair && |
| 55 | (info1->partner == info2->reg) && |
| 56 | (info2->partner == info1->reg)); |
| 57 | if ((info1->live && info1->dirty) || (info2->live && info2->dirty)) { |
| 58 | if (!(info1->isTemp && info2->isTemp)) { |
| 59 | /* Should not happen. If it does, there's a problem in evalLoc */ |
| 60 | LOG(FATAL) << "Long half-temp, half-promoted"; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 61 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 62 | |
| 63 | info1->dirty = false; |
| 64 | info2->dirty = false; |
| 65 | if (SRegToVReg(cUnit, info2->sReg) < SRegToVReg(cUnit, info1->sReg)) |
| 66 | info1 = info2; |
| 67 | int vReg = SRegToVReg(cUnit, info1->sReg); |
| 68 | oatFlushRegWideImpl(cUnit, rSP, oatVRegOffset(cUnit, vReg), |
| 69 | info1->reg, info1->partner); |
| 70 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void oatFlushReg(CompilationUnit* cUnit, int reg) |
| 74 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 75 | RegisterInfo* info = oatGetRegInfo(cUnit, reg); |
| 76 | if (info->live && info->dirty) { |
| 77 | info->dirty = false; |
| 78 | int vReg = SRegToVReg(cUnit, info->sReg); |
| 79 | oatFlushRegImpl(cUnit, rSP, oatVRegOffset(cUnit, vReg), reg, kWord); |
| 80 | } |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /* Give access to the target-dependent FP register encoding to common code */ |
| 84 | bool oatIsFpReg(int reg) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 85 | return FPREG(reg); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | uint32_t oatFpRegMask() { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 89 | return FP_REG_MASK; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | /* Clobber all regs that might be used by an external C call */ |
| 93 | extern void oatClobberCalleeSave(CompilationUnit *cUnit) |
| 94 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 95 | oatClobber(cUnit, rAX); |
| 96 | oatClobber(cUnit, rCX); |
| 97 | oatClobber(cUnit, rDX); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 100 | extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) { |
| 101 | RegLocation res = LOC_C_RETURN_WIDE; |
| 102 | CHECK(res.lowReg == rAX); |
| 103 | CHECK(res.highReg == rDX); |
| 104 | oatClobber(cUnit, rAX); |
| 105 | oatClobber(cUnit, rDX); |
| 106 | oatMarkInUse(cUnit, rAX); |
| 107 | oatMarkInUse(cUnit, rDX); |
| 108 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 109 | return res; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit) |
| 113 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 114 | RegLocation res = LOC_C_RETURN; |
| 115 | res.lowReg = rDX; |
| 116 | oatClobber(cUnit, rDX); |
| 117 | oatMarkInUse(cUnit, rDX); |
| 118 | return res; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 119 | } |
| 120 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 121 | extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg) |
| 122 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 123 | return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK] |
| 124 | : &cUnit->regPool->coreRegs[reg]; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* To be used when explicitly managing register use */ |
| 128 | extern void oatLockCallTemps(CompilationUnit* cUnit) |
| 129 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 130 | oatLockTemp(cUnit, rARG0); |
| 131 | oatLockTemp(cUnit, rARG1); |
| 132 | oatLockTemp(cUnit, rARG2); |
| 133 | oatLockTemp(cUnit, rARG3); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | /* To be used when explicitly managing register use */ |
| 137 | extern void oatFreeCallTemps(CompilationUnit* cUnit) |
| 138 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 139 | oatFreeTemp(cUnit, rARG0); |
| 140 | oatFreeTemp(cUnit, rARG1); |
| 141 | oatFreeTemp(cUnit, rARG2); |
| 142 | oatFreeTemp(cUnit, rARG3); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* Convert an instruction to a NOP */ |
| 146 | void oatNopLIR( LIR* lir) |
| 147 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 148 | ((LIR*)lir)->flags.isNop = true; |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 149 | } |
| 150 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 151 | } // namespace art |