buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | /* |
| 18 | * This file contains x86-specific codegen factory support. |
| 19 | * It is included by |
| 20 | * |
| 21 | * Codegen-$(TARGET_ARCH_VARIANT).c |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | namespace art { |
| 26 | |
| 27 | bool genAddLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 28 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 29 | { |
| 30 | UNIMPLEMENTED(WARNING) << "genAddLong"; |
| 31 | #if 0 |
| 32 | rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg); |
| 33 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg); |
| 34 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 35 | /* |
| 36 | * [v1 v0] = [a1 a0] + [a3 a2]; |
| 37 | * addu v0,a2,a0 |
| 38 | * addu t1,a3,a1 |
| 39 | * sltu v1,v0,a2 |
| 40 | * addu v1,v1,t1 |
| 41 | */ |
| 42 | |
| 43 | opRegRegReg(cUnit, kOpAdd, rlResult.lowReg, rlSrc2.lowReg, rlSrc1.lowReg); |
| 44 | int tReg = oatAllocTemp(cUnit); |
| 45 | opRegRegReg(cUnit, kOpAdd, tReg, rlSrc2.highReg, rlSrc1.highReg); |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame^] | 46 | newLIR3(cUnit, kX86Sltu, rlResult.highReg, rlResult.lowReg, rlSrc2.lowReg); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 47 | opRegRegReg(cUnit, kOpAdd, rlResult.highReg, rlResult.highReg, tReg); |
| 48 | oatFreeTemp(cUnit, tReg); |
| 49 | storeValueWide(cUnit, rlDest, rlResult); |
| 50 | #endif |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | bool genSubLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 55 | RegLocation rlSrc1, RegLocation rlSrc2) |
| 56 | { |
| 57 | UNIMPLEMENTED(WARNING) << "genSubLong"; |
| 58 | #if 0 |
| 59 | rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg); |
| 60 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg); |
| 61 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 62 | /* |
| 63 | * [v1 v0] = [a1 a0] - [a3 a2]; |
| 64 | * subu v0,a0,a2 |
| 65 | * subu v1,a1,a3 |
| 66 | * sltu t1,a0,v0 |
| 67 | * subu v1,v1,t1 |
| 68 | */ |
| 69 | |
| 70 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg); |
| 71 | opRegRegReg(cUnit, kOpSub, rlResult.highReg, rlSrc1.highReg, rlSrc2.highReg); |
| 72 | int tReg = oatAllocTemp(cUnit); |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame^] | 73 | newLIR3(cUnit, kX86Sltu, tReg, rlSrc1.lowReg, rlResult.lowReg); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 74 | opRegRegReg(cUnit, kOpSub, rlResult.highReg, rlResult.highReg, tReg); |
| 75 | oatFreeTemp(cUnit, tReg); |
| 76 | storeValueWide(cUnit, rlDest, rlResult); |
| 77 | #endif |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | bool genNegLong(CompilationUnit* cUnit, MIR* mir, RegLocation rlDest, |
| 82 | RegLocation rlSrc) |
| 83 | { |
| 84 | UNIMPLEMENTED(WARNING) << "genNegLong"; |
| 85 | #if 0 |
| 86 | rlSrc = loadValueWide(cUnit, rlSrc, kCoreReg); |
| 87 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 88 | /* |
| 89 | * [v1 v0] = -[a1 a0] |
| 90 | * negu v0,a0 |
| 91 | * negu v1,a1 |
| 92 | * sltu t1,r_zero |
| 93 | * subu v1,v1,t1 |
| 94 | */ |
| 95 | |
| 96 | opRegReg(cUnit, kOpNeg, rlResult.lowReg, rlSrc.lowReg); |
| 97 | opRegReg(cUnit, kOpNeg, rlResult.highReg, rlSrc.highReg); |
| 98 | int tReg = oatAllocTemp(cUnit); |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame^] | 99 | newLIR3(cUnit, kX86Sltu, tReg, r_ZERO, rlResult.lowReg); |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 100 | opRegRegReg(cUnit, kOpSub, rlResult.highReg, rlResult.highReg, tReg); |
| 101 | oatFreeTemp(cUnit, tReg); |
| 102 | storeValueWide(cUnit, rlDest, rlResult); |
| 103 | #endif |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | void genDebuggerUpdate(CompilationUnit* cUnit, int32_t offset); |
| 108 | |
| 109 | /* |
| 110 | * In the Arm code a it is typical to use the link register |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame^] | 111 | * to hold the target address. However, for X86 we must |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 112 | * ensure that all branch instructions can be restarted if |
| 113 | * there is a trap in the shadow. Allocate a temp register. |
| 114 | */ |
| 115 | int loadHelper(CompilationUnit* cUnit, int offset) |
| 116 | { |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame^] | 117 | UNIMPLEMENTED(WARNING); |
| 118 | return 0; |
| 119 | #if 0 |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 120 | int tReg = oatAllocTemp(cUnit); |
| 121 | loadWordDisp(cUnit, rSELF, offset, tReg); |
| 122 | return tReg; |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame^] | 123 | #endif |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void spillCoreRegs(CompilationUnit* cUnit) |
| 127 | { |
| 128 | if (cUnit->numCoreSpills == 0) { |
| 129 | return; |
| 130 | } |
| 131 | UNIMPLEMENTED(WARNING) << "spillCoreRegs"; |
| 132 | #if 0 |
| 133 | uint32_t mask = cUnit->coreSpillMask; |
| 134 | int offset = cUnit->numCoreSpills * 4; |
| 135 | opRegImm(cUnit, kOpSub, rSP, offset); |
| 136 | for (int reg = 0; mask; mask >>= 1, reg++) { |
| 137 | if (mask & 0x1) { |
| 138 | offset -= 4; |
| 139 | storeWordDisp(cUnit, rSP, offset, reg); |
| 140 | } |
| 141 | } |
| 142 | #endif |
| 143 | } |
| 144 | |
| 145 | void unSpillCoreRegs(CompilationUnit* cUnit) |
| 146 | { |
| 147 | if (cUnit->numCoreSpills == 0) { |
| 148 | return; |
| 149 | } |
| 150 | UNIMPLEMENTED(WARNING) << "unSpillCoreRegs"; |
| 151 | #if 0 |
| 152 | uint32_t mask = cUnit->coreSpillMask; |
| 153 | int offset = cUnit->frameSize; |
| 154 | for (int reg = 0; mask; mask >>= 1, reg++) { |
| 155 | if (mask & 0x1) { |
| 156 | offset -= 4; |
| 157 | loadWordDisp(cUnit, rSP, offset, reg); |
| 158 | } |
| 159 | } |
| 160 | opRegImm(cUnit, kOpAdd, rSP, cUnit->frameSize); |
| 161 | #endif |
| 162 | } |
| 163 | |
| 164 | void genEntrySequence(CompilationUnit* cUnit, BasicBlock* bb) |
| 165 | { |
| 166 | UNIMPLEMENTED(WARNING) << "genEntrySequence"; |
| 167 | #if 0 |
| 168 | int spillCount = cUnit->numCoreSpills + cUnit->numFPSpills; |
| 169 | /* |
| 170 | * On entry, rARG0, rARG1, rARG2 & rARG3 are live. Let the register |
| 171 | * allocation mechanism know so it doesn't try to use any of them when |
| 172 | * expanding the frame or flushing. This leaves the utility |
| 173 | * code with a single temp: r12. This should be enough. |
| 174 | */ |
| 175 | oatLockTemp(cUnit, rARG0); |
| 176 | oatLockTemp(cUnit, rARG1); |
| 177 | oatLockTemp(cUnit, rARG2); |
| 178 | oatLockTemp(cUnit, rARG3); |
| 179 | |
| 180 | /* |
| 181 | * We can safely skip the stack overflow check if we're |
| 182 | * a leaf *and* our frame size < fudge factor. |
| 183 | */ |
| 184 | bool skipOverflowCheck = ((cUnit->attrs & METHOD_IS_LEAF) && |
| 185 | ((size_t)cUnit->frameSize < |
| 186 | Thread::kStackOverflowReservedBytes)); |
| 187 | newLIR0(cUnit, kPseudoMethodEntry); |
| 188 | int checkReg = oatAllocTemp(cUnit); |
| 189 | int newSP = oatAllocTemp(cUnit); |
| 190 | if (!skipOverflowCheck) { |
| 191 | /* Load stack limit */ |
| 192 | loadWordDisp(cUnit, rSELF, |
| 193 | Thread::StackEndOffset().Int32Value(), checkReg); |
| 194 | } |
| 195 | /* Spill core callee saves */ |
| 196 | spillCoreRegs(cUnit); |
| 197 | /* NOTE: promotion of FP regs currently unsupported, thus no FP spill */ |
| 198 | DCHECK_EQ(cUnit->numFPSpills, 0); |
| 199 | if (!skipOverflowCheck) { |
| 200 | opRegRegImm(cUnit, kOpSub, newSP, rSP, |
| 201 | cUnit->frameSize - (spillCount * 4)); |
| 202 | genRegRegCheck(cUnit, kCondCc, newSP, checkReg, NULL, |
| 203 | kThrowStackOverflow); |
| 204 | opRegCopy(cUnit, rSP, newSP); // Establish stack |
| 205 | } else { |
| 206 | opRegImm(cUnit, kOpSub, rSP, |
| 207 | cUnit->frameSize - (spillCount * 4)); |
| 208 | } |
| 209 | storeBaseDisp(cUnit, rSP, 0, rARG0, kWord); |
| 210 | flushIns(cUnit); |
| 211 | |
| 212 | if (cUnit->genDebugger) { |
| 213 | // Refresh update debugger callout |
| 214 | loadWordDisp(cUnit, rSELF, |
| 215 | OFFSETOF_MEMBER(Thread, pUpdateDebuggerFromCode), rSUSPEND); |
| 216 | genDebuggerUpdate(cUnit, DEBUGGER_METHOD_ENTRY); |
| 217 | } |
| 218 | |
| 219 | oatFreeTemp(cUnit, rARG0); |
| 220 | oatFreeTemp(cUnit, rARG1); |
| 221 | oatFreeTemp(cUnit, rARG2); |
| 222 | oatFreeTemp(cUnit, rARG3); |
| 223 | #endif |
| 224 | } |
| 225 | |
| 226 | void genExitSequence(CompilationUnit* cUnit, BasicBlock* bb) |
| 227 | { |
| 228 | UNIMPLEMENTED(WARNING) << "genExitSequence"; |
| 229 | #if 0 |
| 230 | /* |
| 231 | * In the exit path, rRET0/rRET1 are live - make sure they aren't |
| 232 | * allocated by the register utilities as temps. |
| 233 | */ |
| 234 | oatLockTemp(cUnit, rRET0); |
| 235 | oatLockTemp(cUnit, rRET1); |
| 236 | |
| 237 | newLIR0(cUnit, kPseudoMethodExit); |
| 238 | /* If we're compiling for the debugger, generate an update callout */ |
| 239 | if (cUnit->genDebugger) { |
| 240 | genDebuggerUpdate(cUnit, DEBUGGER_METHOD_EXIT); |
| 241 | } |
| 242 | unSpillCoreRegs(cUnit); |
| 243 | opReg(cUnit, kOpBx, r_RA); |
| 244 | #endif |
| 245 | } |
| 246 | |
| 247 | /* |
| 248 | * Nop any unconditional branches that go to the next instruction. |
| 249 | * Note: new redundant branches may be inserted later, and we'll |
| 250 | * use a check in final instruction assembly to nop those out. |
| 251 | */ |
| 252 | void removeRedundantBranches(CompilationUnit* cUnit) |
| 253 | { |
| 254 | UNIMPLEMENTED(WARNING) << "removeRedundantBranches"; |
| 255 | #if 0 |
| 256 | LIR* thisLIR; |
| 257 | |
| 258 | for (thisLIR = (LIR*) cUnit->firstLIRInsn; |
| 259 | thisLIR != (LIR*) cUnit->lastLIRInsn; |
| 260 | thisLIR = NEXT_LIR(thisLIR)) { |
| 261 | |
| 262 | /* Branch to the next instruction */ |
buzbee | a7678db | 2012-03-05 15:35:46 -0800 | [diff] [blame^] | 263 | if (thisLIR->opcode == kX86B) { |
buzbee | e88dfbf | 2012-03-05 11:19:57 -0800 | [diff] [blame] | 264 | LIR* nextLIR = thisLIR; |
| 265 | |
| 266 | while (true) { |
| 267 | nextLIR = NEXT_LIR(nextLIR); |
| 268 | |
| 269 | /* |
| 270 | * Is the branch target the next instruction? |
| 271 | */ |
| 272 | if (nextLIR == (LIR*) thisLIR->target) { |
| 273 | thisLIR->flags.isNop = true; |
| 274 | break; |
| 275 | } |
| 276 | |
| 277 | /* |
| 278 | * Found real useful stuff between the branch and the target. |
| 279 | * Need to explicitly check the lastLIRInsn here because it |
| 280 | * might be the last real instruction. |
| 281 | */ |
| 282 | if (!isPseudoOpcode(nextLIR->opcode) || |
| 283 | (nextLIR = (LIR*) cUnit->lastLIRInsn)) |
| 284 | break; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | #endif |
| 289 | } |
| 290 | |
| 291 | |
| 292 | /* Common initialization routine for an architecture family */ |
| 293 | bool oatArchInit() |
| 294 | { |
| 295 | int i; |
| 296 | |
| 297 | for (i = 0; i < kX86Last; i++) { |
| 298 | if (EncodingMap[i].opcode != i) { |
| 299 | LOG(FATAL) << "Encoding order for " << EncodingMap[i].name << |
| 300 | " is wrong: expecting " << i << ", seeing " << |
| 301 | (int)EncodingMap[i].opcode; |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | return oatArchVariantInit(); |
| 306 | } |
| 307 | |
| 308 | } // namespace art |