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 | { |
| 44 | UNIMPLEMENTED(WARNING) << "oatMarkPreservedSingle"; |
| 45 | #if 0 |
| 46 | LOG(FATAL) << "No support yet for promoted FP regs"; |
| 47 | #endif |
| 48 | } |
| 49 | |
| 50 | void oatFlushRegWide(CompilationUnit* cUnit, int reg1, int reg2) |
| 51 | { |
| 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"; |
| 61 | } |
| 62 | |
| 63 | info1->dirty = false; |
| 64 | info2->dirty = false; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 65 | if (SRegToVReg(cUnit, info2->sReg) < |
| 66 | SRegToVReg(cUnit, info1->sReg)) |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 67 | info1 = info2; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 68 | int vReg = SRegToVReg(cUnit, info1->sReg); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 69 | oatFlushRegWideImpl(cUnit, rSP, |
| 70 | oatVRegOffset(cUnit, vReg), |
| 71 | info1->reg, info1->partner); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | void oatFlushReg(CompilationUnit* cUnit, int reg) |
| 76 | { |
| 77 | RegisterInfo* info = oatGetRegInfo(cUnit, reg); |
| 78 | if (info->live && info->dirty) { |
| 79 | info->dirty = false; |
buzbee | e196567 | 2012-03-11 18:39:19 -0700 | [diff] [blame] | 80 | int vReg = SRegToVReg(cUnit, info->sReg); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 81 | oatFlushRegImpl(cUnit, rSP, |
| 82 | oatVRegOffset(cUnit, vReg), |
| 83 | reg, kWord); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /* Give access to the target-dependent FP register encoding to common code */ |
| 88 | bool oatIsFpReg(int reg) { |
| 89 | return FPREG(reg); |
| 90 | } |
| 91 | |
| 92 | uint32_t oatFpRegMask() { |
| 93 | return FP_REG_MASK; |
| 94 | } |
| 95 | |
| 96 | /* Clobber all regs that might be used by an external C call */ |
| 97 | extern void oatClobberCalleeSave(CompilationUnit *cUnit) |
| 98 | { |
Ian Rogers | 6cbb2bd | 2012-03-16 13:45:30 -0700 | [diff] [blame] | 99 | oatClobber(cUnit, rBP); |
| 100 | oatClobber(cUnit, rSI); |
| 101 | oatClobber(cUnit, rDI); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 102 | } |
| 103 | |
Ian Rogers | f7d9ad3 | 2012-03-13 18:45:39 -0700 | [diff] [blame] | 104 | extern RegLocation oatGetReturnWideAlt(CompilationUnit* cUnit) { |
| 105 | RegLocation res = LOC_C_RETURN_WIDE; |
| 106 | CHECK(res.lowReg == rAX); |
| 107 | CHECK(res.highReg == rDX); |
| 108 | oatClobber(cUnit, rAX); |
| 109 | oatClobber(cUnit, rDX); |
| 110 | oatMarkInUse(cUnit, rAX); |
| 111 | oatMarkInUse(cUnit, rDX); |
| 112 | oatMarkPair(cUnit, res.lowReg, res.highReg); |
| 113 | return res; |
Ian Rogers | b5d09b2 | 2012-03-06 22:14:17 -0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | extern RegLocation oatGetReturnAlt(CompilationUnit* cUnit) |
| 117 | { |
| 118 | RegLocation res = LOC_C_RETURN; |
| 119 | res.lowReg = rDX; |
| 120 | oatClobber(cUnit, rDX); |
| 121 | oatMarkInUse(cUnit, rDX); |
| 122 | return res; |
| 123 | } |
| 124 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 125 | extern RegisterInfo* oatGetRegInfo(CompilationUnit* cUnit, int reg) |
| 126 | { |
| 127 | return FPREG(reg) ? &cUnit->regPool->FPRegs[reg & FP_REG_MASK] |
| 128 | : &cUnit->regPool->coreRegs[reg]; |
| 129 | } |
| 130 | |
| 131 | /* To be used when explicitly managing register use */ |
| 132 | extern void oatLockCallTemps(CompilationUnit* cUnit) |
| 133 | { |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 134 | oatLockTemp(cUnit, rARG0); |
| 135 | oatLockTemp(cUnit, rARG1); |
| 136 | oatLockTemp(cUnit, rARG2); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | /* To be used when explicitly managing register use */ |
| 140 | extern void oatFreeCallTemps(CompilationUnit* cUnit) |
| 141 | { |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 142 | oatFreeTemp(cUnit, rARG0); |
| 143 | oatFreeTemp(cUnit, rARG1); |
| 144 | oatFreeTemp(cUnit, rARG2); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* Convert an instruction to a NOP */ |
| 148 | void oatNopLIR( LIR* lir) |
| 149 | { |
| 150 | ((LIR*)lir)->flags.isNop = true; |
| 151 | } |
| 152 | |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 153 | } // namespace art |