buzbee | 31a4a6f | 2012-02-28 15:36:15 -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 | |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 17 | #include "oat/runtime/oat_support_entrypoints.h" |
| 18 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 19 | namespace art { |
| 20 | |
| 21 | /* |
| 22 | * This source files contains "gen" codegen routines that should |
| 23 | * be applicable to most targets. Only mid-level support utilities |
| 24 | * and "op" calls may be used here. |
| 25 | */ |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 26 | void genInvoke(CompilationUnit* cUnit, CallInfo* info); |
buzbee | f3aac97 | 2012-04-11 16:33:36 -0700 | [diff] [blame] | 27 | bool smallLiteralDivide(CompilationUnit* cUnit, Instruction::Code dalvikOpcode, |
| 28 | RegLocation rlSrc, RegLocation rlDest, int lit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 29 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 30 | void markSafepointPC(CompilationUnit* cUnit, LIR* inst) |
| 31 | { |
| 32 | inst->defMask = ENCODE_ALL; |
| 33 | LIR* safepointPC = newLIR0(cUnit, kPseudoSafepointPC); |
| 34 | DCHECK_EQ(safepointPC->defMask, ENCODE_ALL); |
| 35 | } |
| 36 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 37 | /* |
| 38 | * To save scheduling time, helper calls are broken into two parts: generation of |
| 39 | * the helper target address, and the actuall call to the helper. Because x86 |
| 40 | * has a memory call operation, part 1 is a NOP for x86. For other targets, |
| 41 | * load arguments between the two parts. |
| 42 | */ |
| 43 | int callHelperSetup(CompilationUnit* cUnit, int helperOffset) |
| 44 | { |
| 45 | return (cUnit->instructionSet == kX86) ? 0 : loadHelper(cUnit, helperOffset); |
| 46 | } |
| 47 | |
| 48 | /* NOTE: if rTgt is a temp, it will be freed following use */ |
| 49 | LIR* callHelper(CompilationUnit* cUnit, int rTgt, int helperOffset, bool safepointPC) |
| 50 | { |
| 51 | LIR* callInst; |
| 52 | if (cUnit->instructionSet == kX86) { |
| 53 | callInst = opThreadMem(cUnit, kOpBlx, helperOffset); |
| 54 | } else { |
| 55 | callInst = opReg(cUnit, kOpBlx, rTgt); |
| 56 | oatFreeTemp(cUnit, rTgt); |
| 57 | } |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 58 | if (safepointPC) { |
| 59 | markSafepointPC(cUnit, callInst); |
| 60 | } |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 61 | return callInst; |
| 62 | } |
| 63 | |
| 64 | void callRuntimeHelperImm(CompilationUnit* cUnit, int helperOffset, int arg0, bool safepointPC) { |
| 65 | int rTgt = callHelperSetup(cUnit, helperOffset); |
| 66 | loadConstant(cUnit, rARG0, arg0); |
| 67 | oatClobberCalleeSave(cUnit); |
| 68 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 69 | } |
| 70 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 71 | void callRuntimeHelperReg(CompilationUnit* cUnit, int helperOffset, int arg0, bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 72 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 73 | opRegCopy(cUnit, rARG0, arg0); |
| 74 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 75 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | 7caad77 | 2012-03-30 01:07:54 -0700 | [diff] [blame] | 76 | } |
| 77 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 78 | void callRuntimeHelperRegLocation(CompilationUnit* cUnit, int helperOffset, RegLocation arg0, |
| 79 | bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 80 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 81 | if (arg0.wide == 0) { |
| 82 | loadValueDirectFixed(cUnit, arg0, rARG0); |
| 83 | } else { |
| 84 | loadValueDirectWideFixed(cUnit, arg0, rARG0, rARG1); |
| 85 | } |
| 86 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 87 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 88 | } |
| 89 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 90 | void callRuntimeHelperImmImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1, |
| 91 | bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 92 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 93 | loadConstant(cUnit, rARG0, arg0); |
| 94 | loadConstant(cUnit, rARG1, arg1); |
| 95 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 96 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 97 | } |
| 98 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 99 | void callRuntimeHelperImmRegLocation(CompilationUnit* cUnit, int helperOffset, int arg0, |
| 100 | RegLocation arg1, bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 101 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 102 | if (arg1.wide == 0) { |
| 103 | loadValueDirectFixed(cUnit, arg1, rARG1); |
| 104 | } else { |
| 105 | loadValueDirectWideFixed(cUnit, arg1, rARG1, rARG2); |
| 106 | } |
| 107 | loadConstant(cUnit, rARG0, arg0); |
| 108 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 109 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 110 | } |
| 111 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 112 | void callRuntimeHelperRegLocationImm(CompilationUnit* cUnit, int helperOffset, RegLocation arg0, |
| 113 | int arg1, bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 114 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 115 | loadValueDirectFixed(cUnit, arg0, rARG0); |
| 116 | loadConstant(cUnit, rARG1, arg1); |
| 117 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 118 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 119 | } |
| 120 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 121 | void callRuntimeHelperImmReg(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1, |
| 122 | bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 123 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 124 | opRegCopy(cUnit, rARG1, arg1); |
| 125 | loadConstant(cUnit, rARG0, arg0); |
| 126 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 127 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 128 | } |
| 129 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 130 | void callRuntimeHelperRegImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1, |
| 131 | bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 132 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 133 | opRegCopy(cUnit, rARG0, arg0); |
| 134 | loadConstant(cUnit, rARG1, arg1); |
| 135 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 136 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 137 | } |
| 138 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 139 | void callRuntimeHelperImmMethod(CompilationUnit* cUnit, int helperOffset, int arg0, bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 140 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 141 | loadCurrMethodDirect(cUnit, rARG1); |
| 142 | loadConstant(cUnit, rARG0, arg0); |
| 143 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 144 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 145 | } |
| 146 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 147 | void callRuntimeHelperRegLocationRegLocation(CompilationUnit* cUnit, int helperOffset, |
| 148 | RegLocation arg0, RegLocation arg1, bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 149 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 150 | if (arg0.wide == 0) { |
jeffhao | 30a3317 | 2012-10-22 18:16:22 -0700 | [diff] [blame] | 151 | loadValueDirectFixed(cUnit, arg0, arg0.fp ? rFARG0 : rARG0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 152 | if (arg1.wide == 0) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 153 | if (cUnit->instructionSet == kMips) { |
| 154 | loadValueDirectFixed(cUnit, arg1, arg1.fp ? rFARG2 : rARG1); |
| 155 | } else { |
| 156 | loadValueDirectFixed(cUnit, arg1, rARG1); |
| 157 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 158 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 159 | if (cUnit->instructionSet == kMips) { |
| 160 | loadValueDirectWideFixed(cUnit, arg1, arg1.fp ? rFARG2 : rARG1, arg1.fp ? rFARG3 : rARG2); |
| 161 | } else { |
| 162 | loadValueDirectWideFixed(cUnit, arg1, rARG1, rARG2); |
| 163 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 164 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 165 | } else { |
jeffhao | 30a3317 | 2012-10-22 18:16:22 -0700 | [diff] [blame] | 166 | loadValueDirectWideFixed(cUnit, arg0, arg0.fp ? rFARG0 : rARG0, arg0.fp ? rFARG1 : rARG1); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 167 | if (arg1.wide == 0) { |
jeffhao | 30a3317 | 2012-10-22 18:16:22 -0700 | [diff] [blame] | 168 | loadValueDirectFixed(cUnit, arg1, arg1.fp ? rFARG2 : rARG2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 169 | } else { |
jeffhao | 30a3317 | 2012-10-22 18:16:22 -0700 | [diff] [blame] | 170 | loadValueDirectWideFixed(cUnit, arg1, arg1.fp ? rFARG2 : rARG2, arg1.fp ? rFARG3 : rARG3); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 171 | } |
| 172 | } |
| 173 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 174 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 175 | } |
| 176 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 177 | void callRuntimeHelperRegReg(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1, |
| 178 | bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 179 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 180 | DCHECK_NE((int)rARG0, arg1); // check copy into arg0 won't clobber arg1 |
| 181 | opRegCopy(cUnit, rARG0, arg0); |
| 182 | opRegCopy(cUnit, rARG1, arg1); |
| 183 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 184 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 185 | } |
| 186 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 187 | void callRuntimeHelperRegRegImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg1, |
| 188 | int arg2, bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 189 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 190 | DCHECK_NE((int)rARG0, arg1); // check copy into arg0 won't clobber arg1 |
| 191 | opRegCopy(cUnit, rARG0, arg0); |
| 192 | opRegCopy(cUnit, rARG1, arg1); |
| 193 | loadConstant(cUnit, rARG2, arg2); |
| 194 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 195 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 196 | } |
| 197 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 198 | void callRuntimeHelperImmMethodRegLocation(CompilationUnit* cUnit, int helperOffset, int arg0, |
| 199 | RegLocation arg2, bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 200 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 201 | loadValueDirectFixed(cUnit, arg2, rARG2); |
| 202 | loadCurrMethodDirect(cUnit, rARG1); |
| 203 | loadConstant(cUnit, rARG0, arg0); |
| 204 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 205 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 206 | } |
| 207 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 208 | void callRuntimeHelperImmMethodImm(CompilationUnit* cUnit, int helperOffset, int arg0, int arg2, |
| 209 | bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 210 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 211 | loadCurrMethodDirect(cUnit, rARG1); |
| 212 | loadConstant(cUnit, rARG2, arg2); |
| 213 | loadConstant(cUnit, rARG0, arg0); |
| 214 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 215 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 216 | } |
| 217 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 218 | void callRuntimeHelperImmRegLocationRegLocation(CompilationUnit* cUnit, int helperOffset, |
| 219 | int arg0, RegLocation arg1, RegLocation arg2, |
| 220 | bool safepointPC) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 221 | int rTgt = callHelperSetup(cUnit, helperOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 222 | loadValueDirectFixed(cUnit, arg1, rARG1); |
| 223 | if (arg2.wide == 0) { |
| 224 | loadValueDirectFixed(cUnit, arg2, rARG2); |
| 225 | } else { |
| 226 | loadValueDirectWideFixed(cUnit, arg2, rARG2, rARG3); |
| 227 | } |
| 228 | loadConstant(cUnit, rARG0, arg0); |
| 229 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 230 | callHelper(cUnit, rTgt, helperOffset, safepointPC); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Generate an kPseudoBarrier marker to indicate the boundary of special |
| 235 | * blocks. |
| 236 | */ |
| 237 | void genBarrier(CompilationUnit* cUnit) |
| 238 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 239 | LIR* barrier = newLIR0(cUnit, kPseudoBarrier); |
| 240 | /* Mark all resources as being clobbered */ |
| 241 | barrier->defMask = -1; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 242 | } |
| 243 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 244 | |
| 245 | /* Generate unconditional branch instructions */ |
buzbee | 82488f5 | 2012-03-02 08:20:26 -0800 | [diff] [blame] | 246 | LIR* opUnconditionalBranch(CompilationUnit* cUnit, LIR* target) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 247 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 248 | LIR* branch = opBranchUnconditional(cUnit, kOpUncondBr); |
| 249 | branch->target = (LIR*) target; |
| 250 | return branch; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 251 | } |
| 252 | |
buzbee | 5de3494 | 2012-03-01 14:51:57 -0800 | [diff] [blame] | 253 | // FIXME: need to do some work to split out targets with |
| 254 | // condition codes and those without |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 255 | LIR* genCheck(CompilationUnit* cUnit, ConditionCode cCode, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 256 | ThrowKind kind) |
| 257 | { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 258 | DCHECK_NE(cUnit->instructionSet, kMips); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 259 | LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind, |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 260 | cUnit->currentDalvikOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 261 | LIR* branch = opCondBranch(cUnit, cCode, tgt); |
| 262 | // Remember branch target - will process later |
| 263 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
| 264 | return branch; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | LIR* genImmedCheck(CompilationUnit* cUnit, ConditionCode cCode, |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 268 | int reg, int immVal, ThrowKind kind) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 269 | { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 270 | LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind, |
| 271 | cUnit->currentDalvikOffset); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 272 | LIR* branch; |
| 273 | if (cCode == kCondAl) { |
| 274 | branch = opUnconditionalBranch(cUnit, tgt); |
| 275 | } else { |
| 276 | branch = opCmpImmBranch(cUnit, cCode, reg, immVal, tgt); |
| 277 | } |
| 278 | // Remember branch target - will process later |
| 279 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
| 280 | return branch; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | /* Perform null-check on a register. */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 284 | LIR* genNullCheck(CompilationUnit* cUnit, int sReg, int mReg, int optFlags) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 285 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 286 | if (!(cUnit->disableOpt & (1 << kNullCheckElimination)) && |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 287 | optFlags & MIR_IGNORE_NULL_CHECK) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 288 | return NULL; |
| 289 | } |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 290 | return genImmedCheck(cUnit, kCondEq, mReg, 0, kThrowNullPointer); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /* Perform check on two registers */ |
| 294 | LIR* genRegRegCheck(CompilationUnit* cUnit, ConditionCode cCode, |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 295 | int reg1, int reg2, ThrowKind kind) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 296 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 297 | LIR* tgt = rawLIR(cUnit, 0, kPseudoThrowTarget, kind, |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 298 | cUnit->currentDalvikOffset, reg1, reg2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 299 | LIR* branch = opCmpBranch(cUnit, cCode, reg1, reg2, tgt); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 300 | // Remember branch target - will process later |
| 301 | oatInsertGrowableList(cUnit, &cUnit->throwLaunchpads, (intptr_t)tgt); |
| 302 | return branch; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 303 | } |
| 304 | |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 305 | void genCompareAndBranch(CompilationUnit* cUnit, Instruction::Code opcode, |
| 306 | RegLocation rlSrc1, RegLocation rlSrc2, LIR* taken, |
| 307 | LIR* fallThrough) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 308 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 309 | ConditionCode cond; |
| 310 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 311 | rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 312 | switch (opcode) { |
| 313 | case Instruction::IF_EQ: |
| 314 | cond = kCondEq; |
| 315 | break; |
| 316 | case Instruction::IF_NE: |
| 317 | cond = kCondNe; |
| 318 | break; |
| 319 | case Instruction::IF_LT: |
| 320 | cond = kCondLt; |
| 321 | break; |
| 322 | case Instruction::IF_GE: |
| 323 | cond = kCondGe; |
| 324 | break; |
| 325 | case Instruction::IF_GT: |
| 326 | cond = kCondGt; |
| 327 | break; |
| 328 | case Instruction::IF_LE: |
| 329 | cond = kCondLe; |
| 330 | break; |
| 331 | default: |
| 332 | cond = (ConditionCode)0; |
| 333 | LOG(FATAL) << "Unexpected opcode " << (int)opcode; |
| 334 | } |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 335 | opCmpBranch(cUnit, cond, rlSrc1.lowReg, rlSrc2.lowReg, taken); |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 336 | opUnconditionalBranch(cUnit, fallThrough); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 337 | } |
| 338 | |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 339 | void genCompareZeroAndBranch(CompilationUnit* cUnit, Instruction::Code opcode, |
| 340 | RegLocation rlSrc, LIR* taken, LIR* fallThrough) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 341 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 342 | ConditionCode cond; |
| 343 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 344 | switch (opcode) { |
| 345 | case Instruction::IF_EQZ: |
| 346 | cond = kCondEq; |
| 347 | break; |
| 348 | case Instruction::IF_NEZ: |
| 349 | cond = kCondNe; |
| 350 | break; |
| 351 | case Instruction::IF_LTZ: |
| 352 | cond = kCondLt; |
| 353 | break; |
| 354 | case Instruction::IF_GEZ: |
| 355 | cond = kCondGe; |
| 356 | break; |
| 357 | case Instruction::IF_GTZ: |
| 358 | cond = kCondGt; |
| 359 | break; |
| 360 | case Instruction::IF_LEZ: |
| 361 | cond = kCondLe; |
| 362 | break; |
| 363 | default: |
| 364 | cond = (ConditionCode)0; |
| 365 | LOG(FATAL) << "Unexpected opcode " << (int)opcode; |
| 366 | } |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 367 | if (cUnit->instructionSet == kThumb2) { |
| 368 | opRegImm(cUnit, kOpCmp, rlSrc.lowReg, 0); |
| 369 | opCondBranch(cUnit, cond, taken); |
| 370 | } else { |
| 371 | opCmpImmBranch(cUnit, cond, rlSrc.lowReg, 0, taken); |
| 372 | } |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 373 | opUnconditionalBranch(cUnit, fallThrough); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 374 | } |
| 375 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 376 | void genIntToLong(CompilationUnit* cUnit, RegLocation rlDest, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 377 | RegLocation rlSrc) |
| 378 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 379 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 380 | if (rlSrc.location == kLocPhysReg) { |
| 381 | opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg); |
| 382 | } else { |
| 383 | loadValueDirect(cUnit, rlSrc, rlResult.lowReg); |
| 384 | } |
| 385 | opRegRegImm(cUnit, kOpAsr, rlResult.highReg, rlResult.lowReg, 31); |
| 386 | storeValueWide(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 387 | } |
| 388 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 389 | void genIntNarrowing(CompilationUnit* cUnit, Instruction::Code opcode, |
| 390 | RegLocation rlDest, RegLocation rlSrc) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 391 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 392 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 393 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 394 | OpKind op = kOpInvalid; |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 395 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 396 | case Instruction::INT_TO_BYTE: |
| 397 | op = kOp2Byte; |
| 398 | break; |
| 399 | case Instruction::INT_TO_SHORT: |
| 400 | op = kOp2Short; |
| 401 | break; |
| 402 | case Instruction::INT_TO_CHAR: |
| 403 | op = kOp2Char; |
| 404 | break; |
| 405 | default: |
| 406 | LOG(ERROR) << "Bad int conversion type"; |
| 407 | } |
| 408 | opRegReg(cUnit, op, rlResult.lowReg, rlSrc.lowReg); |
| 409 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | /* |
| 413 | * Let helper function take care of everything. Will call |
| 414 | * Array::AllocFromCode(type_idx, method, count); |
| 415 | * Note: AllocFromCode will handle checks for errNegativeArraySize. |
| 416 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 417 | void genNewArray(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlDest, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 418 | RegLocation rlSrc) |
| 419 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 420 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 421 | int funcOffset; |
| 422 | if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 423 | *cUnit->dex_file, |
| 424 | type_idx)) { |
| 425 | funcOffset = ENTRYPOINT_OFFSET(pAllocArrayFromCode); |
| 426 | } else { |
| 427 | funcOffset= ENTRYPOINT_OFFSET(pAllocArrayFromCodeWithAccessCheck); |
| 428 | } |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 429 | callRuntimeHelperImmMethodRegLocation(cUnit, funcOffset, type_idx, rlSrc, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 430 | RegLocation rlResult = oatGetReturn(cUnit, false); |
| 431 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /* |
| 435 | * Similar to genNewArray, but with post-allocation initialization. |
| 436 | * Verifier guarantees we're dealing with an array class. Current |
| 437 | * code throws runtime exception "bad Filled array req" for 'D' and 'J'. |
| 438 | * Current code also throws internal unimp if not 'L', '[' or 'I'. |
| 439 | */ |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 440 | void genFilledNewArray(CompilationUnit* cUnit, CallInfo* info) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 441 | { |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 442 | int elems = info->numArgWords; |
| 443 | int typeIdx = info->index; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 444 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 445 | int funcOffset; |
| 446 | if (cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 447 | *cUnit->dex_file, |
| 448 | typeIdx)) { |
| 449 | funcOffset = ENTRYPOINT_OFFSET(pCheckAndAllocArrayFromCode); |
| 450 | } else { |
| 451 | funcOffset = ENTRYPOINT_OFFSET(pCheckAndAllocArrayFromCodeWithAccessCheck); |
| 452 | } |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 453 | callRuntimeHelperImmMethodImm(cUnit, funcOffset, typeIdx, elems, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 454 | oatFreeTemp(cUnit, rARG2); |
| 455 | oatFreeTemp(cUnit, rARG1); |
| 456 | /* |
| 457 | * NOTE: the implicit target for Instruction::FILLED_NEW_ARRAY is the |
| 458 | * return region. Because AllocFromCode placed the new array |
| 459 | * in rRET0, we'll just lock it into place. When debugger support is |
| 460 | * added, it may be necessary to additionally copy all return |
| 461 | * values to a home location in thread-local storage |
| 462 | */ |
| 463 | oatLockTemp(cUnit, rRET0); |
| 464 | |
| 465 | // TODO: use the correct component size, currently all supported types |
| 466 | // share array alignment with ints (see comment at head of function) |
| 467 | size_t component_size = sizeof(int32_t); |
| 468 | |
| 469 | // Having a range of 0 is legal |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 470 | if (info->isRange && (elems > 0)) { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 471 | /* |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 472 | * Bit of ugliness here. We're going generate a mem copy loop |
| 473 | * on the register range, but it is possible that some regs |
| 474 | * in the range have been promoted. This is unlikely, but |
| 475 | * before generating the copy, we'll just force a flush |
| 476 | * of any regs in the source range that have been promoted to |
| 477 | * home location. |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 478 | */ |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 479 | for (int i = 0; i < elems; i++) { |
| 480 | RegLocation loc = oatUpdateLoc(cUnit, info->args[i]); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 481 | if (loc.location == kLocPhysReg) { |
| 482 | storeBaseDisp(cUnit, rSP, oatSRegOffset(cUnit, loc.sRegLow), |
| 483 | loc.lowReg, kWord); |
| 484 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 485 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 486 | /* |
| 487 | * TUNING note: generated code here could be much improved, but |
| 488 | * this is an uncommon operation and isn't especially performance |
| 489 | * critical. |
| 490 | */ |
| 491 | int rSrc = oatAllocTemp(cUnit); |
| 492 | int rDst = oatAllocTemp(cUnit); |
| 493 | int rIdx = oatAllocTemp(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 494 | int rVal = INVALID_REG; |
| 495 | switch(cUnit->instructionSet) { |
| 496 | case kThumb2: |
| 497 | rVal = rLR; |
| 498 | break; |
| 499 | case kX86: |
| 500 | oatFreeTemp(cUnit, rRET0); |
| 501 | rVal = oatAllocTemp(cUnit); |
| 502 | break; |
| 503 | case kMips: |
| 504 | rVal = oatAllocTemp(cUnit); |
| 505 | break; |
| 506 | default: LOG(FATAL) << "Unexpected instruction set: " << cUnit->instructionSet; |
| 507 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 508 | // Set up source pointer |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 509 | RegLocation rlFirst = info->args[0]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 510 | opRegRegImm(cUnit, kOpAdd, rSrc, rSP, |
| 511 | oatSRegOffset(cUnit, rlFirst.sRegLow)); |
| 512 | // Set up the target pointer |
| 513 | opRegRegImm(cUnit, kOpAdd, rDst, rRET0, |
| 514 | Array::DataOffset(component_size).Int32Value()); |
| 515 | // Set up the loop counter (known to be > 0) |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 516 | loadConstant(cUnit, rIdx, elems - 1); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 517 | // Generate the copy loop. Going backwards for convenience |
| 518 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
| 519 | // Copy next element |
| 520 | loadBaseIndexed(cUnit, rSrc, rIdx, rVal, 2, kWord); |
| 521 | storeBaseIndexed(cUnit, rDst, rIdx, rVal, 2, kWord); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 522 | oatFreeTemp(cUnit, rVal); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 523 | opDecAndBranch(cUnit, kCondGe, rIdx, target); |
| 524 | if (cUnit->instructionSet == kX86) { |
| 525 | // Restore the target pointer |
| 526 | opRegRegImm(cUnit, kOpAdd, rRET0, rDst, -Array::DataOffset(component_size).Int32Value()); |
| 527 | } |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 528 | } else if (!info->isRange) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 529 | // TUNING: interleave |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 530 | for (int i = 0; i < elems; i++) { |
| 531 | RegLocation rlArg = loadValue(cUnit, info->args[i], kCoreReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 532 | storeBaseDisp(cUnit, rRET0, |
| 533 | Array::DataOffset(component_size).Int32Value() + |
| 534 | i * 4, rlArg.lowReg, kWord); |
| 535 | // If the loadValue caused a temp to be allocated, free it |
| 536 | if (oatIsTemp(cUnit, rlArg.lowReg)) { |
| 537 | oatFreeTemp(cUnit, rlArg.lowReg); |
| 538 | } |
| 539 | } |
| 540 | } |
buzbee | e5f0122 | 2012-06-14 15:19:35 -0700 | [diff] [blame] | 541 | if (info->result.location != kLocInvalid) { |
| 542 | storeValue(cUnit, info->result, oatGetReturn(cUnit, false /* not fp */)); |
| 543 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 544 | } |
| 545 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 546 | void genSput(CompilationUnit* cUnit, uint32_t fieldIdx, RegLocation rlSrc, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 547 | bool isLongOrDouble, bool isObject) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 548 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 549 | int fieldOffset; |
| 550 | int ssbIndex; |
| 551 | bool isVolatile; |
| 552 | bool isReferrersClass; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 553 | |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 554 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, *cUnit->dex_file, |
| 555 | cUnit->code_item, cUnit->method_idx, cUnit->access_flags); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 556 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 557 | bool fastPath = |
| 558 | cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, &mUnit, |
| 559 | fieldOffset, ssbIndex, |
| 560 | isReferrersClass, isVolatile, |
| 561 | true); |
| 562 | if (fastPath && !SLOW_FIELD_PATH) { |
| 563 | DCHECK_GE(fieldOffset, 0); |
| 564 | int rBase; |
| 565 | if (isReferrersClass) { |
| 566 | // Fast path, static storage base is this method's class |
| 567 | RegLocation rlMethod = loadCurrMethod(cUnit); |
| 568 | rBase = oatAllocTemp(cUnit); |
| 569 | loadWordDisp(cUnit, rlMethod.lowReg, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 570 | AbstractMethod::DeclaringClassOffset().Int32Value(), rBase); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 571 | if (oatIsTemp(cUnit, rlMethod.lowReg)) { |
| 572 | oatFreeTemp(cUnit, rlMethod.lowReg); |
| 573 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 574 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 575 | // Medium path, static storage base in a different class which |
| 576 | // requires checks that the other class is initialized. |
| 577 | DCHECK_GE(ssbIndex, 0); |
| 578 | // May do runtime call so everything to home locations. |
| 579 | oatFlushAllRegs(cUnit); |
| 580 | // Using fixed register to sync with possible call to runtime |
| 581 | // support. |
| 582 | int rMethod = rARG1; |
| 583 | oatLockTemp(cUnit, rMethod); |
| 584 | loadCurrMethodDirect(cUnit, rMethod); |
| 585 | rBase = rARG0; |
| 586 | oatLockTemp(cUnit, rBase); |
| 587 | loadWordDisp(cUnit, rMethod, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 588 | AbstractMethod::DexCacheInitializedStaticStorageOffset().Int32Value(), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 589 | rBase); |
| 590 | loadWordDisp(cUnit, rBase, |
| 591 | Array::DataOffset(sizeof(Object*)).Int32Value() + |
| 592 | sizeof(int32_t*) * ssbIndex, rBase); |
| 593 | // rBase now points at appropriate static storage base (Class*) |
| 594 | // or NULL if not initialized. Check for NULL and call helper if NULL. |
| 595 | // TUNING: fast path should fall through |
| 596 | LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rBase, 0, NULL); |
| 597 | loadConstant(cUnit, rARG0, ssbIndex); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 598 | callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssbIndex, true); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 599 | if (cUnit->instructionSet == kMips) { |
| 600 | // For Arm, rRET0 = rARG0 = rBASE, for Mips, we need to copy |
| 601 | opRegCopy(cUnit, rBase, rRET0); |
| 602 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 603 | LIR* skipTarget = newLIR0(cUnit, kPseudoTargetLabel); |
| 604 | branchOver->target = (LIR*)skipTarget; |
| 605 | oatFreeTemp(cUnit, rMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 606 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 607 | // rBase now holds static storage base |
| 608 | if (isLongOrDouble) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 609 | rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg); |
| 610 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 611 | rlSrc = loadValue(cUnit, rlSrc, kAnyReg); |
| 612 | } |
| 613 | //FIXME: need to generalize the barrier call |
| 614 | if (isVolatile) { |
| 615 | oatGenMemBarrier(cUnit, kST); |
| 616 | } |
| 617 | if (isLongOrDouble) { |
| 618 | storeBaseDispWide(cUnit, rBase, fieldOffset, rlSrc.lowReg, |
| 619 | rlSrc.highReg); |
| 620 | } else { |
| 621 | storeWordDisp(cUnit, rBase, fieldOffset, rlSrc.lowReg); |
| 622 | } |
| 623 | if (isVolatile) { |
| 624 | oatGenMemBarrier(cUnit, kSY); |
| 625 | } |
| 626 | if (isObject) { |
| 627 | markGCCard(cUnit, rlSrc.lowReg, rBase); |
| 628 | } |
| 629 | oatFreeTemp(cUnit, rBase); |
| 630 | } else { |
| 631 | oatFlushAllRegs(cUnit); // Everything to home locations |
| 632 | int setterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pSet64Static) : |
| 633 | (isObject ? ENTRYPOINT_OFFSET(pSetObjStatic) |
| 634 | : ENTRYPOINT_OFFSET(pSet32Static)); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 635 | callRuntimeHelperImmRegLocation(cUnit, setterOffset, fieldIdx, rlSrc, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 636 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 637 | } |
| 638 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 639 | void genSget(CompilationUnit* cUnit, uint32_t fieldIdx, RegLocation rlDest, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 640 | bool isLongOrDouble, bool isObject) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 641 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 642 | int fieldOffset; |
| 643 | int ssbIndex; |
| 644 | bool isVolatile; |
| 645 | bool isReferrersClass; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 646 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 647 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 648 | *cUnit->dex_file, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 649 | cUnit->code_item, cUnit->method_idx, |
| 650 | cUnit->access_flags); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 651 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 652 | bool fastPath = |
| 653 | cUnit->compiler->ComputeStaticFieldInfo(fieldIdx, &mUnit, |
| 654 | fieldOffset, ssbIndex, |
| 655 | isReferrersClass, isVolatile, |
| 656 | false); |
| 657 | if (fastPath && !SLOW_FIELD_PATH) { |
| 658 | DCHECK_GE(fieldOffset, 0); |
| 659 | int rBase; |
| 660 | if (isReferrersClass) { |
| 661 | // Fast path, static storage base is this method's class |
| 662 | RegLocation rlMethod = loadCurrMethod(cUnit); |
| 663 | rBase = oatAllocTemp(cUnit); |
| 664 | loadWordDisp(cUnit, rlMethod.lowReg, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 665 | AbstractMethod::DeclaringClassOffset().Int32Value(), rBase); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 666 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 667 | // Medium path, static storage base in a different class which |
| 668 | // requires checks that the other class is initialized |
| 669 | DCHECK_GE(ssbIndex, 0); |
| 670 | // May do runtime call so everything to home locations. |
| 671 | oatFlushAllRegs(cUnit); |
| 672 | // Using fixed register to sync with possible call to runtime |
| 673 | // support |
| 674 | int rMethod = rARG1; |
| 675 | oatLockTemp(cUnit, rMethod); |
| 676 | loadCurrMethodDirect(cUnit, rMethod); |
| 677 | rBase = rARG0; |
| 678 | oatLockTemp(cUnit, rBase); |
| 679 | loadWordDisp(cUnit, rMethod, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 680 | AbstractMethod::DexCacheInitializedStaticStorageOffset().Int32Value(), |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 681 | rBase); |
| 682 | loadWordDisp(cUnit, rBase, |
| 683 | Array::DataOffset(sizeof(Object*)).Int32Value() + |
| 684 | sizeof(int32_t*) * ssbIndex, rBase); |
| 685 | // rBase now points at appropriate static storage base (Class*) |
| 686 | // or NULL if not initialized. Check for NULL and call helper if NULL. |
| 687 | // TUNING: fast path should fall through |
| 688 | LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rBase, 0, NULL); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 689 | callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeStaticStorage), ssbIndex, true); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 690 | if (cUnit->instructionSet == kMips) { |
| 691 | // For Arm, rRET0 = rARG0 = rBASE, for Mips, we need to copy |
| 692 | opRegCopy(cUnit, rBase, rRET0); |
| 693 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 694 | LIR* skipTarget = newLIR0(cUnit, kPseudoTargetLabel); |
| 695 | branchOver->target = (LIR*)skipTarget; |
| 696 | oatFreeTemp(cUnit, rMethod); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 697 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 698 | // rBase now holds static storage base |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 699 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kAnyReg, true); |
| 700 | if (isVolatile) { |
| 701 | oatGenMemBarrier(cUnit, kSY); |
| 702 | } |
| 703 | if (isLongOrDouble) { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 704 | loadBaseDispWide(cUnit, rBase, fieldOffset, rlResult.lowReg, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 705 | rlResult.highReg, INVALID_SREG); |
| 706 | } else { |
| 707 | loadWordDisp(cUnit, rBase, fieldOffset, rlResult.lowReg); |
| 708 | } |
| 709 | oatFreeTemp(cUnit, rBase); |
| 710 | if (isLongOrDouble) { |
| 711 | storeValueWide(cUnit, rlDest, rlResult); |
| 712 | } else { |
| 713 | storeValue(cUnit, rlDest, rlResult); |
| 714 | } |
| 715 | } else { |
| 716 | oatFlushAllRegs(cUnit); // Everything to home locations |
| 717 | int getterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pGet64Static) : |
| 718 | (isObject ? ENTRYPOINT_OFFSET(pGetObjStatic) |
| 719 | : ENTRYPOINT_OFFSET(pGet32Static)); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 720 | callRuntimeHelperImm(cUnit, getterOffset, fieldIdx, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 721 | if (isLongOrDouble) { |
| 722 | RegLocation rlResult = oatGetReturnWide(cUnit, rlDest.fp); |
| 723 | storeValueWide(cUnit, rlDest, rlResult); |
| 724 | } else { |
| 725 | RegLocation rlResult = oatGetReturn(cUnit, rlDest.fp); |
| 726 | storeValue(cUnit, rlDest, rlResult); |
| 727 | } |
| 728 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | |
| 732 | // Debugging routine - if null target, branch to DebugMe |
| 733 | void genShowTarget(CompilationUnit* cUnit) |
| 734 | { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 735 | DCHECK_NE(cUnit->instructionSet, kX86) << "unimplemented genShowTarget"; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 736 | LIR* branchOver = opCmpImmBranch(cUnit, kCondNe, rINVOKE_TGT, 0, NULL); |
| 737 | loadWordDisp(cUnit, rSELF, ENTRYPOINT_OFFSET(pDebugMe), rINVOKE_TGT); |
| 738 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
| 739 | branchOver->target = (LIR*)target; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 740 | } |
| 741 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 742 | void handleSuspendLaunchpads(CompilationUnit *cUnit) |
| 743 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 744 | LIR** suspendLabel = (LIR **)cUnit->suspendLaunchpads.elemList; |
| 745 | int numElems = cUnit->suspendLaunchpads.numUsed; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 746 | int helperOffset = ENTRYPOINT_OFFSET(pTestSuspendFromCode); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 747 | for (int i = 0; i < numElems; i++) { |
| 748 | oatResetRegPool(cUnit); |
| 749 | oatResetDefTracking(cUnit); |
| 750 | LIR* lab = suspendLabel[i]; |
| 751 | LIR* resumeLab = (LIR*)lab->operands[0]; |
| 752 | cUnit->currentDalvikOffset = lab->operands[1]; |
| 753 | oatAppendLIR(cUnit, lab); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 754 | int rTgt = callHelperSetup(cUnit, helperOffset); |
| 755 | callHelper(cUnit, rTgt, helperOffset, true /* markSafepointPC */); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 756 | opUnconditionalBranch(cUnit, resumeLab); |
| 757 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 758 | } |
| 759 | |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 760 | void handleIntrinsicLaunchpads(CompilationUnit *cUnit) |
| 761 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 762 | LIR** intrinsicLabel = (LIR **)cUnit->intrinsicLaunchpads.elemList; |
| 763 | int numElems = cUnit->intrinsicLaunchpads.numUsed; |
| 764 | for (int i = 0; i < numElems; i++) { |
| 765 | oatResetRegPool(cUnit); |
| 766 | oatResetDefTracking(cUnit); |
| 767 | LIR* lab = intrinsicLabel[i]; |
buzbee | 3b3dbdd | 2012-06-13 13:39:34 -0700 | [diff] [blame] | 768 | CallInfo* info = (CallInfo*)lab->operands[0]; |
buzbee | 15bf980 | 2012-06-12 17:49:27 -0700 | [diff] [blame] | 769 | cUnit->currentDalvikOffset = info->offset; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 770 | oatAppendLIR(cUnit, lab); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 771 | // NOTE: genInvoke handles markSafepointPC |
buzbee | 15bf980 | 2012-06-12 17:49:27 -0700 | [diff] [blame] | 772 | genInvoke(cUnit, info); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 773 | LIR* resumeLab = (LIR*)lab->operands[2]; |
| 774 | if (resumeLab != NULL) { |
| 775 | opUnconditionalBranch(cUnit, resumeLab); |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 776 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 777 | } |
buzbee | fc9e6fa | 2012-03-23 15:14:29 -0700 | [diff] [blame] | 778 | } |
| 779 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 780 | void handleThrowLaunchpads(CompilationUnit *cUnit) |
| 781 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 782 | LIR** throwLabel = (LIR **)cUnit->throwLaunchpads.elemList; |
| 783 | int numElems = cUnit->throwLaunchpads.numUsed; |
| 784 | for (int i = 0; i < numElems; i++) { |
| 785 | oatResetRegPool(cUnit); |
| 786 | oatResetDefTracking(cUnit); |
| 787 | LIR* lab = throwLabel[i]; |
| 788 | cUnit->currentDalvikOffset = lab->operands[1]; |
| 789 | oatAppendLIR(cUnit, lab); |
| 790 | int funcOffset = 0; |
| 791 | int v1 = lab->operands[2]; |
| 792 | int v2 = lab->operands[3]; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 793 | bool targetX86 = (cUnit->instructionSet == kX86); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 794 | switch (lab->operands[0]) { |
| 795 | case kThrowNullPointer: |
| 796 | funcOffset = ENTRYPOINT_OFFSET(pThrowNullPointerFromCode); |
| 797 | break; |
| 798 | case kThrowArrayBounds: |
jeffhao | 44335e1 | 2012-06-18 13:48:25 -0700 | [diff] [blame] | 799 | // Move v1 (array index) to rARG0 and v2 (array length) to rARG1 |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 800 | if (v2 != rARG0) { |
| 801 | opRegCopy(cUnit, rARG0, v1); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 802 | if (targetX86) { |
| 803 | // x86 leaves the array pointer in v2, so load the array length that the handler expects |
| 804 | opRegMem(cUnit, kOpMov, rARG1, v2, Array::LengthOffset().Int32Value()); |
| 805 | } else { |
| 806 | opRegCopy(cUnit, rARG1, v2); |
| 807 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 808 | } else { |
| 809 | if (v1 == rARG1) { |
jeffhao | 44335e1 | 2012-06-18 13:48:25 -0700 | [diff] [blame] | 810 | // Swap v1 and v2, using rARG2 as a temp |
| 811 | opRegCopy(cUnit, rARG2, v1); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 812 | if (targetX86) { |
| 813 | // x86 leaves the array pointer in v2; load the array length that the handler expects |
| 814 | opRegMem(cUnit, kOpMov, rARG1, v2, Array::LengthOffset().Int32Value()); |
| 815 | } else { |
| 816 | opRegCopy(cUnit, rARG1, v2); |
| 817 | } |
jeffhao | 44335e1 | 2012-06-18 13:48:25 -0700 | [diff] [blame] | 818 | opRegCopy(cUnit, rARG0, rARG2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 819 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 820 | if (targetX86) { |
| 821 | // x86 leaves the array pointer in v2; load the array length that the handler expects |
| 822 | opRegMem(cUnit, kOpMov, rARG1, v2, Array::LengthOffset().Int32Value()); |
| 823 | } else { |
| 824 | opRegCopy(cUnit, rARG1, v2); |
| 825 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 826 | opRegCopy(cUnit, rARG0, v1); |
| 827 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 828 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 829 | funcOffset = ENTRYPOINT_OFFSET(pThrowArrayBoundsFromCode); |
| 830 | break; |
| 831 | case kThrowDivZero: |
| 832 | funcOffset = ENTRYPOINT_OFFSET(pThrowDivZeroFromCode); |
| 833 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 834 | case kThrowNoSuchMethod: |
| 835 | opRegCopy(cUnit, rARG0, v1); |
| 836 | funcOffset = |
| 837 | ENTRYPOINT_OFFSET(pThrowNoSuchMethodFromCode); |
| 838 | break; |
| 839 | case kThrowStackOverflow: |
| 840 | funcOffset = ENTRYPOINT_OFFSET(pThrowStackOverflowFromCode); |
| 841 | // Restore stack alignment |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 842 | if (targetX86) { |
| 843 | opRegImm(cUnit, kOpAdd, rSP, cUnit->frameSize); |
| 844 | } else { |
| 845 | opRegImm(cUnit, kOpAdd, rSP, (cUnit->numCoreSpills + cUnit->numFPSpills) * 4); |
| 846 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 847 | break; |
| 848 | default: |
| 849 | LOG(FATAL) << "Unexpected throw kind: " << lab->operands[0]; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 850 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 851 | oatClobberCalleeSave(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 852 | int rTgt = callHelperSetup(cUnit, funcOffset); |
| 853 | callHelper(cUnit, rTgt, funcOffset, true /* markSafepointPC */); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 854 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | /* Needed by the Assembler */ |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 858 | void oatSetupResourceMasks(CompilationUnit* cUnit, LIR* lir) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 859 | { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 860 | setupResourceMasks(cUnit, lir); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 861 | } |
| 862 | |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 863 | bool fastInstance(CompilationUnit* cUnit, uint32_t fieldIdx, |
| 864 | int& fieldOffset, bool& isVolatile, bool isPut) |
| 865 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 866 | OatCompilationUnit mUnit(cUnit->class_loader, cUnit->class_linker, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 867 | *cUnit->dex_file, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 868 | cUnit->code_item, cUnit->method_idx, |
| 869 | cUnit->access_flags); |
| 870 | return cUnit->compiler->ComputeInstanceFieldInfo(fieldIdx, &mUnit, |
| 871 | fieldOffset, isVolatile, isPut); |
buzbee | 16da88c | 2012-03-20 10:38:17 -0700 | [diff] [blame] | 872 | } |
| 873 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 874 | void genIGet(CompilationUnit* cUnit, uint32_t fieldIdx, int optFlags, OpSize size, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 875 | RegLocation rlDest, RegLocation rlObj, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 876 | bool isLongOrDouble, bool isObject) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 877 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 878 | int fieldOffset; |
| 879 | bool isVolatile; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 880 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 881 | bool fastPath = fastInstance(cUnit, fieldIdx, fieldOffset, isVolatile, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 882 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 883 | if (fastPath && !SLOW_FIELD_PATH) { |
| 884 | RegLocation rlResult; |
| 885 | RegisterClass regClass = oatRegClassBySize(size); |
| 886 | DCHECK_GE(fieldOffset, 0); |
| 887 | rlObj = loadValue(cUnit, rlObj, kCoreReg); |
| 888 | if (isLongOrDouble) { |
| 889 | DCHECK(rlDest.wide); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 890 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 891 | if (cUnit->instructionSet == kX86) { |
| 892 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 893 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags); |
| 894 | loadBaseDispWide(cUnit, rlObj.lowReg, fieldOffset, rlResult.lowReg, |
| 895 | rlResult.highReg, rlObj.sRegLow); |
| 896 | if (isVolatile) { |
| 897 | oatGenMemBarrier(cUnit, kSY); |
| 898 | } |
| 899 | } else { |
| 900 | int regPtr = oatAllocTemp(cUnit); |
| 901 | opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset); |
| 902 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 903 | loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg); |
| 904 | if (isVolatile) { |
| 905 | oatGenMemBarrier(cUnit, kSY); |
| 906 | } |
| 907 | oatFreeTemp(cUnit, regPtr); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 908 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 909 | storeValueWide(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 910 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 911 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 912 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags); |
| 913 | loadBaseDisp(cUnit, rlObj.lowReg, fieldOffset, rlResult.lowReg, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 914 | kWord, rlObj.sRegLow); |
| 915 | if (isVolatile) { |
| 916 | oatGenMemBarrier(cUnit, kSY); |
| 917 | } |
| 918 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 919 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 920 | } else { |
| 921 | int getterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pGet64Instance) : |
| 922 | (isObject ? ENTRYPOINT_OFFSET(pGetObjInstance) |
| 923 | : ENTRYPOINT_OFFSET(pGet32Instance)); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 924 | callRuntimeHelperImmRegLocation(cUnit, getterOffset, fieldIdx, rlObj, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 925 | if (isLongOrDouble) { |
| 926 | RegLocation rlResult = oatGetReturnWide(cUnit, rlDest.fp); |
| 927 | storeValueWide(cUnit, rlDest, rlResult); |
| 928 | } else { |
| 929 | RegLocation rlResult = oatGetReturn(cUnit, rlDest.fp); |
| 930 | storeValue(cUnit, rlDest, rlResult); |
| 931 | } |
| 932 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 933 | } |
| 934 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 935 | void genIPut(CompilationUnit* cUnit, uint32_t fieldIdx, int optFlags, OpSize size, |
| 936 | RegLocation rlSrc, RegLocation rlObj, bool isLongOrDouble, bool isObject) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 937 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 938 | int fieldOffset; |
| 939 | bool isVolatile; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 940 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 941 | bool fastPath = fastInstance(cUnit, fieldIdx, fieldOffset, isVolatile, |
| 942 | true); |
| 943 | if (fastPath && !SLOW_FIELD_PATH) { |
| 944 | RegisterClass regClass = oatRegClassBySize(size); |
| 945 | DCHECK_GE(fieldOffset, 0); |
| 946 | rlObj = loadValue(cUnit, rlObj, kCoreReg); |
| 947 | if (isLongOrDouble) { |
| 948 | int regPtr; |
| 949 | rlSrc = loadValueWide(cUnit, rlSrc, kAnyReg); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 950 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 951 | regPtr = oatAllocTemp(cUnit); |
| 952 | opRegRegImm(cUnit, kOpAdd, regPtr, rlObj.lowReg, fieldOffset); |
| 953 | if (isVolatile) { |
| 954 | oatGenMemBarrier(cUnit, kST); |
| 955 | } |
jeffhao | 41005dd | 2012-05-09 17:58:52 -0700 | [diff] [blame] | 956 | storeBaseDispWide(cUnit, regPtr, 0, rlSrc.lowReg, rlSrc.highReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 957 | if (isVolatile) { |
| 958 | oatGenMemBarrier(cUnit, kSY); |
| 959 | } |
| 960 | oatFreeTemp(cUnit, regPtr); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 961 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 962 | rlSrc = loadValue(cUnit, rlSrc, regClass); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 963 | genNullCheck(cUnit, rlObj.sRegLow, rlObj.lowReg, optFlags); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 964 | if (isVolatile) { |
| 965 | oatGenMemBarrier(cUnit, kST); |
| 966 | } |
| 967 | storeBaseDisp(cUnit, rlObj.lowReg, fieldOffset, rlSrc.lowReg, kWord); |
| 968 | if (isVolatile) { |
| 969 | oatGenMemBarrier(cUnit, kSY); |
| 970 | } |
| 971 | if (isObject) { |
| 972 | markGCCard(cUnit, rlSrc.lowReg, rlObj.lowReg); |
| 973 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 974 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 975 | } else { |
| 976 | int setterOffset = isLongOrDouble ? ENTRYPOINT_OFFSET(pSet64Instance) : |
| 977 | (isObject ? ENTRYPOINT_OFFSET(pSetObjInstance) |
| 978 | : ENTRYPOINT_OFFSET(pSet32Instance)); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 979 | callRuntimeHelperImmRegLocationRegLocation(cUnit, setterOffset, fieldIdx, rlObj, rlSrc, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 980 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 981 | } |
| 982 | |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 983 | void genConstClass(CompilationUnit* cUnit, uint32_t type_idx, |
| 984 | RegLocation rlDest) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 985 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 986 | RegLocation rlMethod = loadCurrMethod(cUnit); |
| 987 | int resReg = oatAllocTemp(cUnit); |
| 988 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 989 | if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 990 | *cUnit->dex_file, |
| 991 | type_idx)) { |
| 992 | // Call out to helper which resolves type and verifies access. |
| 993 | // Resolved type returned in rRET0. |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 994 | callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccessFromCode), |
| 995 | type_idx, rlMethod.lowReg, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 996 | RegLocation rlResult = oatGetReturn(cUnit, false); |
| 997 | storeValue(cUnit, rlDest, rlResult); |
| 998 | } else { |
| 999 | // We're don't need access checks, load type from dex cache |
| 1000 | int32_t dex_cache_offset = |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 1001 | AbstractMethod::DexCacheResolvedTypesOffset().Int32Value(); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1002 | loadWordDisp(cUnit, rlMethod.lowReg, dex_cache_offset, resReg); |
| 1003 | int32_t offset_of_type = |
| 1004 | Array::DataOffset(sizeof(Class*)).Int32Value() + (sizeof(Class*) |
| 1005 | * type_idx); |
| 1006 | loadWordDisp(cUnit, resReg, offset_of_type, rlResult.lowReg); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1007 | if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache(*cUnit->dex_file, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1008 | type_idx) || SLOW_TYPE_PATH) { |
| 1009 | // Slow path, at runtime test if type is null and if so initialize |
| 1010 | oatFlushAllRegs(cUnit); |
| 1011 | LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, rlResult.lowReg, 0, NULL); |
| 1012 | // Resolved, store and hop over following code |
| 1013 | storeValue(cUnit, rlDest, rlResult); |
| 1014 | /* |
| 1015 | * Because we have stores of the target value on two paths, |
| 1016 | * clobber temp tracking for the destination using the ssa name |
| 1017 | */ |
| 1018 | oatClobberSReg(cUnit, rlDest.sRegLow); |
| 1019 | LIR* branch2 = opUnconditionalBranch(cUnit,0); |
| 1020 | // TUNING: move slow path to end & remove unconditional branch |
| 1021 | LIR* target1 = newLIR0(cUnit, kPseudoTargetLabel); |
| 1022 | // Call out to helper, which will return resolved type in rARG0 |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1023 | callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeFromCode), type_idx, |
| 1024 | rlMethod.lowReg, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1025 | RegLocation rlResult = oatGetReturn(cUnit, false); |
| 1026 | storeValue(cUnit, rlDest, rlResult); |
| 1027 | /* |
| 1028 | * Because we have stores of the target value on two paths, |
| 1029 | * clobber temp tracking for the destination using the ssa name |
| 1030 | */ |
| 1031 | oatClobberSReg(cUnit, rlDest.sRegLow); |
| 1032 | // Rejoin code paths |
| 1033 | LIR* target2 = newLIR0(cUnit, kPseudoTargetLabel); |
| 1034 | branch1->target = (LIR*)target1; |
| 1035 | branch2->target = (LIR*)target2; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1036 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1037 | // Fast path, we're done - just store result |
| 1038 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1039 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1040 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1041 | } |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1042 | |
buzbee | 6969d50 | 2012-06-15 16:40:31 -0700 | [diff] [blame] | 1043 | void genConstString(CompilationUnit* cUnit, uint32_t string_idx, |
| 1044 | RegLocation rlDest) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1045 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1046 | /* NOTE: Most strings should be available at compile time */ |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1047 | int32_t offset_of_string = Array::DataOffset(sizeof(String*)).Int32Value() + |
| 1048 | (sizeof(String*) * string_idx); |
| 1049 | if (!cUnit->compiler->CanAssumeStringIsPresentInDexCache( |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1050 | *cUnit->dex_file, string_idx) || SLOW_STRING_PATH) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1051 | // slow path, resolve string if not in dex cache |
| 1052 | oatFlushAllRegs(cUnit); |
| 1053 | oatLockCallTemps(cUnit); // Using explicit registers |
| 1054 | loadCurrMethodDirect(cUnit, rARG2); |
| 1055 | loadWordDisp(cUnit, rARG2, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 1056 | AbstractMethod::DexCacheStringsOffset().Int32Value(), rARG0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1057 | // Might call out to helper, which will return resolved string in rRET0 |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1058 | int rTgt = callHelperSetup(cUnit, ENTRYPOINT_OFFSET(pResolveStringFromCode)); |
jeffhao | fa147e2 | 2012-10-12 17:03:32 -0700 | [diff] [blame] | 1059 | loadWordDisp(cUnit, rARG0, offset_of_string, rRET0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1060 | loadConstant(cUnit, rARG1, string_idx); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1061 | if (cUnit->instructionSet == kThumb2) { |
| 1062 | opRegImm(cUnit, kOpCmp, rRET0, 0); // Is resolved? |
| 1063 | genBarrier(cUnit); |
| 1064 | // For testing, always force through helper |
| 1065 | if (!EXERCISE_SLOWEST_STRING_PATH) { |
| 1066 | opIT(cUnit, kArmCondEq, "T"); |
| 1067 | } |
| 1068 | opRegCopy(cUnit, rARG0, rARG2); // .eq |
| 1069 | LIR* callInst = opReg(cUnit, kOpBlx, rTgt); // .eq, helper(Method*, string_idx) |
| 1070 | markSafepointPC(cUnit, callInst); |
| 1071 | oatFreeTemp(cUnit, rTgt); |
| 1072 | } else if (cUnit->instructionSet == kMips) { |
| 1073 | LIR* branch = opCmpImmBranch(cUnit, kCondNe, rRET0, 0, NULL); |
| 1074 | opRegCopy(cUnit, rARG0, rARG2); // .eq |
| 1075 | LIR* callInst = opReg(cUnit, kOpBlx, rTgt); |
| 1076 | markSafepointPC(cUnit, callInst); |
| 1077 | oatFreeTemp(cUnit, rTgt); |
| 1078 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
| 1079 | branch->target = target; |
| 1080 | } else { |
| 1081 | DCHECK_EQ(cUnit->instructionSet, kX86); |
| 1082 | callRuntimeHelperRegReg(cUnit, ENTRYPOINT_OFFSET(pResolveStringFromCode), rARG2, rARG1, true); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1083 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1084 | genBarrier(cUnit); |
| 1085 | storeValue(cUnit, rlDest, oatGetReturn(cUnit, false)); |
| 1086 | } else { |
| 1087 | RegLocation rlMethod = loadCurrMethod(cUnit); |
| 1088 | int resReg = oatAllocTemp(cUnit); |
| 1089 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1090 | loadWordDisp(cUnit, rlMethod.lowReg, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 1091 | AbstractMethod::DexCacheStringsOffset().Int32Value(), resReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1092 | loadWordDisp(cUnit, resReg, offset_of_string, rlResult.lowReg); |
| 1093 | storeValue(cUnit, rlDest, rlResult); |
| 1094 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /* |
| 1098 | * Let helper function take care of everything. Will |
| 1099 | * call Class::NewInstanceFromCode(type_idx, method); |
| 1100 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1101 | void genNewInstance(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlDest) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1102 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1103 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1104 | // alloc will always check for resolution, do we also need to verify |
| 1105 | // access because the verifier was unable to? |
| 1106 | int funcOffset; |
| 1107 | if (cUnit->compiler->CanAccessInstantiableTypeWithoutChecks( |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1108 | cUnit->method_idx, *cUnit->dex_file, type_idx)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1109 | funcOffset = ENTRYPOINT_OFFSET(pAllocObjectFromCode); |
| 1110 | } else { |
| 1111 | funcOffset = ENTRYPOINT_OFFSET(pAllocObjectFromCodeWithAccessCheck); |
| 1112 | } |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1113 | callRuntimeHelperImmMethod(cUnit, funcOffset, type_idx, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1114 | RegLocation rlResult = oatGetReturn(cUnit, false); |
| 1115 | storeValue(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1116 | } |
| 1117 | |
Ian Rogers | 474b6da | 2012-09-25 00:20:38 -0700 | [diff] [blame] | 1118 | void genMoveException(CompilationUnit* cUnit, RegLocation rlDest) |
| 1119 | { |
| 1120 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 1121 | int funcOffset = ENTRYPOINT_OFFSET(pGetAndClearException); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1122 | if (cUnit->instructionSet == kX86) { |
| 1123 | // Runtime helper will load argument for x86. |
| 1124 | callRuntimeHelperReg(cUnit, funcOffset, rARG0, false); |
| 1125 | } else { |
| 1126 | callRuntimeHelperReg(cUnit, funcOffset, rSELF, false); |
| 1127 | } |
Ian Rogers | 474b6da | 2012-09-25 00:20:38 -0700 | [diff] [blame] | 1128 | RegLocation rlResult = oatGetReturn(cUnit, false); |
| 1129 | storeValue(cUnit, rlDest, rlResult); |
| 1130 | } |
| 1131 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1132 | void genThrow(CompilationUnit* cUnit, RegLocation rlSrc) |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1133 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1134 | oatFlushAllRegs(cUnit); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1135 | callRuntimeHelperRegLocation(cUnit, ENTRYPOINT_OFFSET(pDeliverException), rlSrc, true); |
Ian Rogers | ab2b55d | 2012-03-18 00:06:11 -0700 | [diff] [blame] | 1136 | } |
| 1137 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1138 | void genInstanceof(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlDest, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1139 | RegLocation rlSrc) |
| 1140 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1141 | oatFlushAllRegs(cUnit); |
| 1142 | // May generate a call - use explicit registers |
| 1143 | oatLockCallTemps(cUnit); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1144 | loadCurrMethodDirect(cUnit, rARG1); // rARG1 <= current Method* |
| 1145 | int classReg = rARG2; // rARG2 will hold the Class* |
| 1146 | if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1147 | *cUnit->dex_file, |
| 1148 | type_idx)) { |
| 1149 | // Check we have access to type_idx and if not throw IllegalAccessError, |
| 1150 | // returns Class* in rARG0 |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1151 | callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccessFromCode), |
| 1152 | type_idx, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1153 | opRegCopy(cUnit, classReg, rRET0); // Align usage with fast path |
| 1154 | loadValueDirectFixed(cUnit, rlSrc, rARG0); // rARG0 <= ref |
| 1155 | } else { |
| 1156 | // Load dex cache entry into classReg (rARG2) |
| 1157 | loadValueDirectFixed(cUnit, rlSrc, rARG0); // rARG0 <= ref |
| 1158 | loadWordDisp(cUnit, rARG1, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 1159 | AbstractMethod::DexCacheResolvedTypesOffset().Int32Value(), classReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1160 | int32_t offset_of_type = |
| 1161 | Array::DataOffset(sizeof(Class*)).Int32Value() + (sizeof(Class*) |
| 1162 | * type_idx); |
| 1163 | loadWordDisp(cUnit, classReg, offset_of_type, classReg); |
| 1164 | if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache( |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1165 | *cUnit->dex_file, type_idx)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1166 | // Need to test presence of type in dex cache at runtime |
| 1167 | LIR* hopBranch = opCmpImmBranch(cUnit, kCondNe, classReg, 0, NULL); |
| 1168 | // Not resolved |
| 1169 | // Call out to helper, which will return resolved type in rRET0 |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1170 | callRuntimeHelperImm(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeFromCode), type_idx, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1171 | opRegCopy(cUnit, rARG2, rRET0); // Align usage with fast path |
| 1172 | loadValueDirectFixed(cUnit, rlSrc, rARG0); /* reload Ref */ |
| 1173 | // Rejoin code paths |
| 1174 | LIR* hopTarget = newLIR0(cUnit, kPseudoTargetLabel); |
| 1175 | hopBranch->target = (LIR*)hopTarget; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1176 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1177 | } |
| 1178 | /* rARG0 is ref, rARG2 is class. If ref==null, use directly as bool result */ |
jeffhao | 4eb68ed | 2012-10-17 16:41:07 -0700 | [diff] [blame] | 1179 | RegLocation rlResult = oatGetReturn(cUnit, false); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1180 | if (cUnit->instructionSet == kMips) { |
| 1181 | loadConstant(cUnit, rlResult.lowReg, 0); // store false result for if branch is taken |
| 1182 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1183 | LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, rARG0, 0, NULL); |
| 1184 | /* load object->klass_ */ |
| 1185 | DCHECK_EQ(Object::ClassOffset().Int32Value(), 0); |
| 1186 | loadWordDisp(cUnit, rARG0, Object::ClassOffset().Int32Value(), rARG1); |
| 1187 | /* rARG0 is ref, rARG1 is ref->klass_, rARG2 is class */ |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1188 | LIR* callInst; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1189 | LIR* branchover = NULL; |
| 1190 | if (cUnit->instructionSet == kThumb2) { |
| 1191 | /* Uses conditional nullification */ |
| 1192 | int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pInstanceofNonTrivialFromCode)); |
| 1193 | opRegReg(cUnit, kOpCmp, rARG1, rARG2); // Same? |
| 1194 | opIT(cUnit, kArmCondEq, "EE"); // if-convert the test |
| 1195 | loadConstant(cUnit, rARG0, 1); // .eq case - load true |
| 1196 | opRegCopy(cUnit, rARG0, rARG2); // .ne case - arg0 <= class |
| 1197 | callInst = opReg(cUnit, kOpBlx, rTgt); // .ne case: helper(class, ref->class) |
| 1198 | oatFreeTemp(cUnit, rTgt); |
| 1199 | } else { |
| 1200 | /* Uses branchovers */ |
| 1201 | loadConstant(cUnit, rlResult.lowReg, 1); // assume true |
| 1202 | branchover = opCmpBranch(cUnit, kCondEq, rARG1, rARG2, NULL); |
| 1203 | if (cUnit->instructionSet != kX86) { |
| 1204 | int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pInstanceofNonTrivialFromCode)); |
| 1205 | opRegCopy(cUnit, rARG0, rARG2); // .ne case - arg0 <= class |
| 1206 | callInst = opReg(cUnit, kOpBlx, rTgt); // .ne case: helper(class, ref->class) |
| 1207 | oatFreeTemp(cUnit, rTgt); |
| 1208 | } else { |
| 1209 | opRegCopy(cUnit, rARG0, rARG2); |
| 1210 | callInst = opThreadMem(cUnit, kOpBlx, ENTRYPOINT_OFFSET(pInstanceofNonTrivialFromCode)); |
| 1211 | } |
| 1212 | } |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1213 | markSafepointPC(cUnit, callInst); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1214 | oatClobberCalleeSave(cUnit); |
| 1215 | /* branch targets here */ |
| 1216 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1217 | storeValue(cUnit, rlDest, rlResult); |
| 1218 | branch1->target = target; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1219 | if (cUnit->instructionSet != kThumb2) { |
| 1220 | branchover->target = target; |
| 1221 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1222 | } |
| 1223 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1224 | void genCheckCast(CompilationUnit* cUnit, uint32_t type_idx, RegLocation rlSrc) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1225 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1226 | oatFlushAllRegs(cUnit); |
| 1227 | // May generate a call - use explicit registers |
| 1228 | oatLockCallTemps(cUnit); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1229 | loadCurrMethodDirect(cUnit, rARG1); // rARG1 <= current Method* |
| 1230 | int classReg = rARG2; // rARG2 will hold the Class* |
| 1231 | if (!cUnit->compiler->CanAccessTypeWithoutChecks(cUnit->method_idx, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1232 | *cUnit->dex_file, |
| 1233 | type_idx)) { |
| 1234 | // Check we have access to type_idx and if not throw IllegalAccessError, |
| 1235 | // returns Class* in rRET0 |
| 1236 | // InitializeTypeAndVerifyAccess(idx, method) |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1237 | callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeAndVerifyAccessFromCode), |
| 1238 | type_idx, rARG1, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1239 | opRegCopy(cUnit, classReg, rRET0); // Align usage with fast path |
| 1240 | } else { |
| 1241 | // Load dex cache entry into classReg (rARG2) |
| 1242 | loadWordDisp(cUnit, rARG1, |
Mathieu Chartier | 66f1925 | 2012-09-18 08:57:04 -0700 | [diff] [blame] | 1243 | AbstractMethod::DexCacheResolvedTypesOffset().Int32Value(), classReg); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1244 | int32_t offset_of_type = |
| 1245 | Array::DataOffset(sizeof(Class*)).Int32Value() + |
| 1246 | (sizeof(Class*) * type_idx); |
| 1247 | loadWordDisp(cUnit, classReg, offset_of_type, classReg); |
| 1248 | if (!cUnit->compiler->CanAssumeTypeIsPresentInDexCache( |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 1249 | *cUnit->dex_file, type_idx)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1250 | // Need to test presence of type in dex cache at runtime |
| 1251 | LIR* hopBranch = opCmpImmBranch(cUnit, kCondNe, classReg, 0, NULL); |
| 1252 | // Not resolved |
| 1253 | // Call out to helper, which will return resolved type in rARG0 |
| 1254 | // InitializeTypeFromCode(idx, method) |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1255 | callRuntimeHelperImmReg(cUnit, ENTRYPOINT_OFFSET(pInitializeTypeFromCode), type_idx, rARG1, |
| 1256 | true); |
jeffhao | 30a3317 | 2012-10-22 18:16:22 -0700 | [diff] [blame] | 1257 | opRegCopy(cUnit, classReg, rRET0); // Align usage with fast path |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1258 | // Rejoin code paths |
| 1259 | LIR* hopTarget = newLIR0(cUnit, kPseudoTargetLabel); |
| 1260 | hopBranch->target = (LIR*)hopTarget; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1261 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1262 | } |
| 1263 | // At this point, classReg (rARG2) has class |
| 1264 | loadValueDirectFixed(cUnit, rlSrc, rARG0); // rARG0 <= ref |
| 1265 | /* Null is OK - continue */ |
| 1266 | LIR* branch1 = opCmpImmBranch(cUnit, kCondEq, rARG0, 0, NULL); |
| 1267 | /* load object->klass_ */ |
| 1268 | DCHECK_EQ(Object::ClassOffset().Int32Value(), 0); |
| 1269 | loadWordDisp(cUnit, rARG0, Object::ClassOffset().Int32Value(), rARG1); |
| 1270 | /* rARG1 now contains object->klass_ */ |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1271 | LIR* branch2; |
| 1272 | if (cUnit->instructionSet == kThumb2) { |
| 1273 | int rTgt = loadHelper(cUnit, ENTRYPOINT_OFFSET(pCheckCastFromCode)); |
| 1274 | opRegReg(cUnit, kOpCmp, rARG1, classReg); |
| 1275 | branch2 = opCondBranch(cUnit, kCondEq, NULL); /* If eq, trivial yes */ |
| 1276 | opRegCopy(cUnit, rARG0, rARG1); |
| 1277 | opRegCopy(cUnit, rARG1, rARG2); |
| 1278 | oatClobberCalleeSave(cUnit); |
| 1279 | LIR* callInst = opReg(cUnit, kOpBlx, rTgt); |
| 1280 | markSafepointPC(cUnit, callInst); |
| 1281 | oatFreeTemp(cUnit, rTgt); |
| 1282 | } else { |
| 1283 | branch2 = opCmpBranch(cUnit, kCondEq, rARG1, classReg, NULL); |
| 1284 | callRuntimeHelperRegReg(cUnit, ENTRYPOINT_OFFSET(pCheckCastFromCode), rARG1, rARG2, true); |
| 1285 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1286 | /* branch target here */ |
| 1287 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
| 1288 | branch1->target = target; |
| 1289 | branch2->target = target; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1290 | } |
| 1291 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1292 | /* |
| 1293 | * Generate array store |
| 1294 | * |
| 1295 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1296 | void genArrayObjPut(CompilationUnit* cUnit, int optFlags, RegLocation rlArray, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1297 | RegLocation rlIndex, RegLocation rlSrc, int scale) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1298 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1299 | int lenOffset = Array::LengthOffset().Int32Value(); |
| 1300 | int dataOffset = Array::DataOffset(sizeof(Object*)).Int32Value(); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1301 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1302 | oatFlushAllRegs(cUnit); // Use explicit registers |
| 1303 | oatLockCallTemps(cUnit); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1304 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1305 | int rValue = rARG0; // Register holding value |
| 1306 | int rArrayClass = rARG1; // Register holding array's Class |
| 1307 | int rArray = rARG2; // Register holding array |
| 1308 | int rIndex = rARG3; // Register holding index into array |
Ian Rogers | d36c52e | 2012-04-09 16:29:25 -0700 | [diff] [blame] | 1309 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1310 | loadValueDirectFixed(cUnit, rlArray, rArray); // Grab array |
| 1311 | loadValueDirectFixed(cUnit, rlSrc, rValue); // Grab value |
| 1312 | loadValueDirectFixed(cUnit, rlIndex, rIndex); // Grab index |
Ian Rogers | d36c52e | 2012-04-09 16:29:25 -0700 | [diff] [blame] | 1313 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1314 | genNullCheck(cUnit, rlArray.sRegLow, rArray, optFlags); // NPE? |
Ian Rogers | d36c52e | 2012-04-09 16:29:25 -0700 | [diff] [blame] | 1315 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1316 | // Store of null? |
| 1317 | LIR* null_value_check = opCmpImmBranch(cUnit, kCondEq, rValue, 0, NULL); |
Ian Rogers | d36c52e | 2012-04-09 16:29:25 -0700 | [diff] [blame] | 1318 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1319 | // Get the array's class. |
| 1320 | loadWordDisp(cUnit, rArray, Object::ClassOffset().Int32Value(), rArrayClass); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1321 | callRuntimeHelperRegReg(cUnit, ENTRYPOINT_OFFSET(pCanPutArrayElementFromCode), rValue, |
| 1322 | rArrayClass, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1323 | // Redo loadValues in case they didn't survive the call. |
| 1324 | loadValueDirectFixed(cUnit, rlArray, rArray); // Reload array |
| 1325 | loadValueDirectFixed(cUnit, rlIndex, rIndex); // Reload index |
| 1326 | loadValueDirectFixed(cUnit, rlSrc, rValue); // Reload value |
| 1327 | rArrayClass = INVALID_REG; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1328 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1329 | // Branch here if value to be stored == null |
| 1330 | LIR* target = newLIR0(cUnit, kPseudoTargetLabel); |
| 1331 | null_value_check->target = target; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1332 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1333 | if (cUnit->instructionSet == kX86) { |
| 1334 | // make an extra temp available for card mark below |
| 1335 | oatFreeTemp(cUnit, rARG1); |
| 1336 | if (!(optFlags & MIR_IGNORE_RANGE_CHECK)) { |
| 1337 | /* if (rlIndex >= [rlArray + lenOffset]) goto kThrowArrayBounds */ |
| 1338 | genRegMemCheck(cUnit, kCondUge, rIndex, rArray, lenOffset, kThrowArrayBounds); |
| 1339 | } |
| 1340 | storeBaseIndexedDisp(cUnit, rArray, rIndex, scale, |
| 1341 | dataOffset, rValue, INVALID_REG, kWord, INVALID_SREG); |
| 1342 | } else { |
| 1343 | bool needsRangeCheck = (!(optFlags & MIR_IGNORE_RANGE_CHECK)); |
| 1344 | int regLen = INVALID_REG; |
| 1345 | if (needsRangeCheck) { |
| 1346 | regLen = rARG1; |
| 1347 | loadWordDisp(cUnit, rArray, lenOffset, regLen); // Get len |
| 1348 | } |
| 1349 | /* rPtr -> array data */ |
| 1350 | int rPtr = oatAllocTemp(cUnit); |
| 1351 | opRegRegImm(cUnit, kOpAdd, rPtr, rArray, dataOffset); |
| 1352 | if (needsRangeCheck) { |
| 1353 | genRegRegCheck(cUnit, kCondCs, rIndex, regLen, kThrowArrayBounds); |
| 1354 | } |
| 1355 | storeBaseIndexed(cUnit, rPtr, rIndex, rValue, scale, kWord); |
| 1356 | oatFreeTemp(cUnit, rPtr); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1357 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1358 | oatFreeTemp(cUnit, rIndex); |
| 1359 | markGCCard(cUnit, rValue, rArray); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | /* |
| 1363 | * Generate array load |
| 1364 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1365 | void genArrayGet(CompilationUnit* cUnit, int optFlags, OpSize size, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1366 | RegLocation rlArray, RegLocation rlIndex, |
| 1367 | RegLocation rlDest, int scale) |
| 1368 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1369 | RegisterClass regClass = oatRegClassBySize(size); |
| 1370 | int lenOffset = Array::LengthOffset().Int32Value(); |
| 1371 | int dataOffset; |
| 1372 | RegLocation rlResult; |
| 1373 | rlArray = loadValue(cUnit, rlArray, kCoreReg); |
| 1374 | rlIndex = loadValue(cUnit, rlIndex, kCoreReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1375 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1376 | if (size == kLong || size == kDouble) { |
| 1377 | dataOffset = Array::DataOffset(sizeof(int64_t)).Int32Value(); |
| 1378 | } else { |
| 1379 | dataOffset = Array::DataOffset(sizeof(int32_t)).Int32Value(); |
| 1380 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1381 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1382 | /* null object? */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1383 | genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, optFlags); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1384 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1385 | if (cUnit->instructionSet == kX86) { |
| 1386 | if (!(optFlags & MIR_IGNORE_RANGE_CHECK)) { |
| 1387 | /* if (rlIndex >= [rlArray + lenOffset]) goto kThrowArrayBounds */ |
| 1388 | genRegMemCheck(cUnit, kCondUge, rlIndex.lowReg, rlArray.lowReg, |
| 1389 | lenOffset, kThrowArrayBounds); |
| 1390 | } |
| 1391 | if ((size == kLong) || (size == kDouble)) { |
| 1392 | int regAddr = oatAllocTemp(cUnit); |
| 1393 | opLea(cUnit, regAddr, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset); |
| 1394 | oatFreeTemp(cUnit, rlArray.lowReg); |
| 1395 | oatFreeTemp(cUnit, rlIndex.lowReg); |
| 1396 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 1397 | loadBaseIndexedDisp(cUnit, regAddr, INVALID_REG, 0, 0, rlResult.lowReg, |
| 1398 | rlResult.highReg, size, INVALID_SREG); |
| 1399 | storeValueWide(cUnit, rlDest, rlResult); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1400 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1401 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1402 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1403 | loadBaseIndexedDisp(cUnit, rlArray.lowReg, rlIndex.lowReg, scale, |
| 1404 | dataOffset, rlResult.lowReg, INVALID_REG, size, |
| 1405 | INVALID_SREG); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1406 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1407 | storeValue(cUnit, rlDest, rlResult); |
| 1408 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1409 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1410 | int regPtr = oatAllocTemp(cUnit); |
| 1411 | bool needsRangeCheck = (!(optFlags & MIR_IGNORE_RANGE_CHECK)); |
| 1412 | int regLen = INVALID_REG; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1413 | if (needsRangeCheck) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1414 | regLen = oatAllocTemp(cUnit); |
| 1415 | /* Get len */ |
| 1416 | loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1417 | } |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1418 | /* regPtr -> array data */ |
| 1419 | opRegRegImm(cUnit, kOpAdd, regPtr, rlArray.lowReg, dataOffset); |
| 1420 | oatFreeTemp(cUnit, rlArray.lowReg); |
| 1421 | if ((size == kLong) || (size == kDouble)) { |
| 1422 | if (scale) { |
| 1423 | int rNewIndex = oatAllocTemp(cUnit); |
| 1424 | opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale); |
| 1425 | opRegReg(cUnit, kOpAdd, regPtr, rNewIndex); |
| 1426 | oatFreeTemp(cUnit, rNewIndex); |
| 1427 | } else { |
| 1428 | opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg); |
| 1429 | } |
| 1430 | oatFreeTemp(cUnit, rlIndex.lowReg); |
| 1431 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1432 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1433 | if (needsRangeCheck) { |
| 1434 | // TODO: change kCondCS to a more meaningful name, is the sense of |
| 1435 | // carry-set/clear flipped? |
| 1436 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds); |
| 1437 | oatFreeTemp(cUnit, regLen); |
| 1438 | } |
| 1439 | loadPair(cUnit, regPtr, rlResult.lowReg, rlResult.highReg); |
| 1440 | |
| 1441 | oatFreeTemp(cUnit, regPtr); |
| 1442 | storeValueWide(cUnit, rlDest, rlResult); |
| 1443 | } else { |
| 1444 | rlResult = oatEvalLoc(cUnit, rlDest, regClass, true); |
| 1445 | |
| 1446 | if (needsRangeCheck) { |
| 1447 | // TODO: change kCondCS to a more meaningful name, is the sense of |
| 1448 | // carry-set/clear flipped? |
| 1449 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds); |
| 1450 | oatFreeTemp(cUnit, regLen); |
| 1451 | } |
| 1452 | loadBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlResult.lowReg, scale, size); |
| 1453 | |
| 1454 | oatFreeTemp(cUnit, regPtr); |
| 1455 | storeValue(cUnit, rlDest, rlResult); |
| 1456 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1457 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
| 1460 | /* |
| 1461 | * Generate array store |
| 1462 | * |
| 1463 | */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1464 | void genArrayPut(CompilationUnit* cUnit, int optFlags, OpSize size, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1465 | RegLocation rlArray, RegLocation rlIndex, |
| 1466 | RegLocation rlSrc, int scale) |
| 1467 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1468 | RegisterClass regClass = oatRegClassBySize(size); |
| 1469 | int lenOffset = Array::LengthOffset().Int32Value(); |
| 1470 | int dataOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1471 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1472 | if (size == kLong || size == kDouble) { |
| 1473 | dataOffset = Array::DataOffset(sizeof(int64_t)).Int32Value(); |
| 1474 | } else { |
| 1475 | dataOffset = Array::DataOffset(sizeof(int32_t)).Int32Value(); |
| 1476 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1477 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1478 | rlArray = loadValue(cUnit, rlArray, kCoreReg); |
| 1479 | rlIndex = loadValue(cUnit, rlIndex, kCoreReg); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1480 | int regPtr = INVALID_REG; |
| 1481 | if (cUnit->instructionSet != kX86) { |
| 1482 | if (oatIsTemp(cUnit, rlArray.lowReg)) { |
| 1483 | oatClobber(cUnit, rlArray.lowReg); |
| 1484 | regPtr = rlArray.lowReg; |
| 1485 | } else { |
| 1486 | regPtr = oatAllocTemp(cUnit); |
| 1487 | opRegCopy(cUnit, regPtr, rlArray.lowReg); |
| 1488 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1489 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1490 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1491 | /* null object? */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1492 | genNullCheck(cUnit, rlArray.sRegLow, rlArray.lowReg, optFlags); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1493 | |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1494 | if (cUnit->instructionSet == kX86) { |
| 1495 | if (!(optFlags & MIR_IGNORE_RANGE_CHECK)) { |
| 1496 | /* if (rlIndex >= [rlArray + lenOffset]) goto kThrowArrayBounds */ |
| 1497 | genRegMemCheck(cUnit, kCondUge, rlIndex.lowReg, rlArray.lowReg, lenOffset, kThrowArrayBounds); |
| 1498 | } |
| 1499 | if ((size == kLong) || (size == kDouble)) { |
| 1500 | rlSrc = loadValueWide(cUnit, rlSrc, regClass); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1501 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1502 | rlSrc = loadValue(cUnit, rlSrc, regClass); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1503 | } |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1504 | // If the src reg can't be byte accessed, move it to a temp first. |
| 1505 | if ((size == kSignedByte || size == kUnsignedByte) && rlSrc.lowReg >= 4) { |
| 1506 | int temp = oatAllocTemp(cUnit); |
| 1507 | opRegCopy(cUnit, temp, rlSrc.lowReg); |
| 1508 | storeBaseIndexedDisp(cUnit, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset, temp, |
| 1509 | INVALID_REG, size, INVALID_SREG); |
| 1510 | } else { |
| 1511 | storeBaseIndexedDisp(cUnit, rlArray.lowReg, rlIndex.lowReg, scale, dataOffset, rlSrc.lowReg, |
| 1512 | rlSrc.highReg, size, INVALID_SREG); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1513 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1514 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1515 | bool needsRangeCheck = (!(optFlags & MIR_IGNORE_RANGE_CHECK)); |
| 1516 | int regLen = INVALID_REG; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1517 | if (needsRangeCheck) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1518 | regLen = oatAllocTemp(cUnit); |
| 1519 | //NOTE: max live temps(4) here. |
| 1520 | /* Get len */ |
| 1521 | loadWordDisp(cUnit, rlArray.lowReg, lenOffset, regLen); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1522 | } |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1523 | /* regPtr -> array data */ |
| 1524 | opRegImm(cUnit, kOpAdd, regPtr, dataOffset); |
| 1525 | /* at this point, regPtr points to array, 2 live temps */ |
| 1526 | if ((size == kLong) || (size == kDouble)) { |
| 1527 | //TUNING: specific wide routine that can handle fp regs |
| 1528 | if (scale) { |
| 1529 | int rNewIndex = oatAllocTemp(cUnit); |
| 1530 | opRegRegImm(cUnit, kOpLsl, rNewIndex, rlIndex.lowReg, scale); |
| 1531 | opRegReg(cUnit, kOpAdd, regPtr, rNewIndex); |
| 1532 | oatFreeTemp(cUnit, rNewIndex); |
| 1533 | } else { |
| 1534 | opRegReg(cUnit, kOpAdd, regPtr, rlIndex.lowReg); |
| 1535 | } |
| 1536 | rlSrc = loadValueWide(cUnit, rlSrc, regClass); |
| 1537 | |
| 1538 | if (needsRangeCheck) { |
| 1539 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds); |
| 1540 | oatFreeTemp(cUnit, regLen); |
| 1541 | } |
| 1542 | |
| 1543 | storeBaseDispWide(cUnit, regPtr, 0, rlSrc.lowReg, rlSrc.highReg); |
| 1544 | |
| 1545 | oatFreeTemp(cUnit, regPtr); |
| 1546 | } else { |
| 1547 | rlSrc = loadValue(cUnit, rlSrc, regClass); |
| 1548 | if (needsRangeCheck) { |
| 1549 | genRegRegCheck(cUnit, kCondCs, rlIndex.lowReg, regLen, kThrowArrayBounds); |
| 1550 | oatFreeTemp(cUnit, regLen); |
| 1551 | } |
| 1552 | storeBaseIndexed(cUnit, regPtr, rlIndex.lowReg, rlSrc.lowReg, |
| 1553 | scale, size); |
| 1554 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1555 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1556 | } |
| 1557 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1558 | void genLong3Addr(CompilationUnit* cUnit, OpKind firstOp, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1559 | OpKind secondOp, RegLocation rlDest, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1560 | RegLocation rlSrc1, RegLocation rlSrc2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1561 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1562 | RegLocation rlResult; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1563 | if (cUnit->instructionSet == kThumb2) { |
| 1564 | /* |
| 1565 | * NOTE: This is the one place in the code in which we might have |
| 1566 | * as many as six live temporary registers. There are 5 in the normal |
| 1567 | * set for Arm. Until we have spill capabilities, temporarily add |
| 1568 | * lr to the temp set. It is safe to do this locally, but note that |
| 1569 | * lr is used explicitly elsewhere in the code generator and cannot |
| 1570 | * normally be used as a general temp register. |
| 1571 | */ |
| 1572 | oatMarkTemp(cUnit, rLR); // Add lr to the temp pool |
| 1573 | oatFreeTemp(cUnit, rLR); // and make it available |
| 1574 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1575 | rlSrc1 = loadValueWide(cUnit, rlSrc1, kCoreReg); |
| 1576 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg); |
| 1577 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1578 | // The longs may overlap - use intermediate temp if so |
| 1579 | if (rlResult.lowReg == rlSrc1.highReg) { |
| 1580 | int tReg = oatAllocTemp(cUnit); |
| 1581 | opRegCopy(cUnit, tReg, rlSrc1.highReg); |
| 1582 | opRegRegReg(cUnit, firstOp, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg); |
| 1583 | opRegRegReg(cUnit, secondOp, rlResult.highReg, tReg, rlSrc2.highReg); |
| 1584 | oatFreeTemp(cUnit, tReg); |
| 1585 | } else { |
| 1586 | opRegRegReg(cUnit, firstOp, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg); |
| 1587 | opRegRegReg(cUnit, secondOp, rlResult.highReg, rlSrc1.highReg, |
| 1588 | rlSrc2.highReg); |
| 1589 | } |
| 1590 | /* |
| 1591 | * NOTE: If rlDest refers to a frame variable in a large frame, the |
| 1592 | * following storeValueWide might need to allocate a temp register. |
| 1593 | * To further work around the lack of a spill capability, explicitly |
| 1594 | * free any temps from rlSrc1 & rlSrc2 that aren't still live in rlResult. |
| 1595 | * Remove when spill is functional. |
| 1596 | */ |
| 1597 | freeRegLocTemps(cUnit, rlResult, rlSrc1); |
| 1598 | freeRegLocTemps(cUnit, rlResult, rlSrc2); |
| 1599 | storeValueWide(cUnit, rlDest, rlResult); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1600 | if (cUnit->instructionSet == kThumb2) { |
| 1601 | oatClobber(cUnit, rLR); |
| 1602 | oatUnmarkTemp(cUnit, rLR); // Remove lr from the temp pool |
| 1603 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1604 | } |
| 1605 | |
| 1606 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1607 | bool genShiftOpLong(CompilationUnit* cUnit, Instruction::Code opcode, RegLocation rlDest, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1608 | RegLocation rlSrc1, RegLocation rlShift) |
| 1609 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1610 | int funcOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1611 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1612 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1613 | case Instruction::SHL_LONG: |
| 1614 | case Instruction::SHL_LONG_2ADDR: |
| 1615 | funcOffset = ENTRYPOINT_OFFSET(pShlLong); |
| 1616 | break; |
| 1617 | case Instruction::SHR_LONG: |
| 1618 | case Instruction::SHR_LONG_2ADDR: |
| 1619 | funcOffset = ENTRYPOINT_OFFSET(pShrLong); |
| 1620 | break; |
| 1621 | case Instruction::USHR_LONG: |
| 1622 | case Instruction::USHR_LONG_2ADDR: |
| 1623 | funcOffset = ENTRYPOINT_OFFSET(pUshrLong); |
| 1624 | break; |
| 1625 | default: |
| 1626 | LOG(FATAL) << "Unexpected case"; |
| 1627 | return true; |
| 1628 | } |
| 1629 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 1630 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlShift, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1631 | RegLocation rlResult = oatGetReturnWide(cUnit, false); |
| 1632 | storeValueWide(cUnit, rlDest, rlResult); |
| 1633 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1637 | bool genArithOpInt(CompilationUnit* cUnit, Instruction::Code opcode, RegLocation rlDest, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1638 | RegLocation rlSrc1, RegLocation rlSrc2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1639 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1640 | OpKind op = kOpBkpt; |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1641 | bool isDivRem = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1642 | bool checkZero = false; |
| 1643 | bool unary = false; |
| 1644 | RegLocation rlResult; |
| 1645 | bool shiftOp = false; |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1646 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1647 | case Instruction::NEG_INT: |
| 1648 | op = kOpNeg; |
| 1649 | unary = true; |
| 1650 | break; |
| 1651 | case Instruction::NOT_INT: |
| 1652 | op = kOpMvn; |
| 1653 | unary = true; |
| 1654 | break; |
| 1655 | case Instruction::ADD_INT: |
| 1656 | case Instruction::ADD_INT_2ADDR: |
| 1657 | op = kOpAdd; |
| 1658 | break; |
| 1659 | case Instruction::SUB_INT: |
| 1660 | case Instruction::SUB_INT_2ADDR: |
| 1661 | op = kOpSub; |
| 1662 | break; |
| 1663 | case Instruction::MUL_INT: |
| 1664 | case Instruction::MUL_INT_2ADDR: |
| 1665 | op = kOpMul; |
| 1666 | break; |
| 1667 | case Instruction::DIV_INT: |
| 1668 | case Instruction::DIV_INT_2ADDR: |
| 1669 | checkZero = true; |
| 1670 | op = kOpDiv; |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1671 | isDivRem = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1672 | break; |
| 1673 | /* NOTE: returns in rARG1 */ |
| 1674 | case Instruction::REM_INT: |
| 1675 | case Instruction::REM_INT_2ADDR: |
| 1676 | checkZero = true; |
| 1677 | op = kOpRem; |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1678 | isDivRem = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1679 | break; |
| 1680 | case Instruction::AND_INT: |
| 1681 | case Instruction::AND_INT_2ADDR: |
| 1682 | op = kOpAnd; |
| 1683 | break; |
| 1684 | case Instruction::OR_INT: |
| 1685 | case Instruction::OR_INT_2ADDR: |
| 1686 | op = kOpOr; |
| 1687 | break; |
| 1688 | case Instruction::XOR_INT: |
| 1689 | case Instruction::XOR_INT_2ADDR: |
| 1690 | op = kOpXor; |
| 1691 | break; |
| 1692 | case Instruction::SHL_INT: |
| 1693 | case Instruction::SHL_INT_2ADDR: |
| 1694 | shiftOp = true; |
| 1695 | op = kOpLsl; |
| 1696 | break; |
| 1697 | case Instruction::SHR_INT: |
| 1698 | case Instruction::SHR_INT_2ADDR: |
| 1699 | shiftOp = true; |
| 1700 | op = kOpAsr; |
| 1701 | break; |
| 1702 | case Instruction::USHR_INT: |
| 1703 | case Instruction::USHR_INT_2ADDR: |
| 1704 | shiftOp = true; |
| 1705 | op = kOpLsr; |
| 1706 | break; |
| 1707 | default: |
| 1708 | LOG(FATAL) << "Invalid word arith op: " << |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1709 | (int)opcode; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1710 | } |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1711 | if (!isDivRem) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1712 | if (unary) { |
| 1713 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 1714 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1715 | opRegReg(cUnit, op, rlResult.lowReg, rlSrc1.lowReg); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1716 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1717 | if (shiftOp) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1718 | int tReg = INVALID_REG; |
| 1719 | if (cUnit->instructionSet == kX86) { |
| 1720 | // X86 doesn't require masking and must use ECX |
| 1721 | tReg = rCOUNT; // rCX |
| 1722 | loadValueDirectFixed(cUnit, rlSrc2, tReg); |
| 1723 | } else { |
| 1724 | rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg); |
| 1725 | tReg = oatAllocTemp(cUnit); |
| 1726 | opRegRegImm(cUnit, kOpAnd, tReg, rlSrc2.lowReg, 31); |
| 1727 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1728 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 1729 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1730 | opRegRegReg(cUnit, op, rlResult.lowReg, rlSrc1.lowReg, tReg); |
| 1731 | oatFreeTemp(cUnit, tReg); |
| 1732 | } else { |
| 1733 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 1734 | rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg); |
| 1735 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1736 | opRegRegReg(cUnit, op, rlResult.lowReg, rlSrc1.lowReg, rlSrc2.lowReg); |
| 1737 | } |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1738 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1739 | storeValue(cUnit, rlDest, rlResult); |
| 1740 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1741 | if (cUnit->instructionSet == kMips) { |
| 1742 | rlSrc1 = loadValue(cUnit, rlSrc1, kCoreReg); |
| 1743 | rlSrc2 = loadValue(cUnit, rlSrc2, kCoreReg); |
| 1744 | if (checkZero) { |
| 1745 | genImmedCheck(cUnit, kCondEq, rlSrc2.lowReg, 0, kThrowDivZero); |
| 1746 | } |
| 1747 | rlResult = genDivRem(cUnit, rlDest, rlSrc1.lowReg, rlSrc2.lowReg, op == kOpDiv); |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1748 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1749 | int funcOffset = ENTRYPOINT_OFFSET(pIdivmod); |
| 1750 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
| 1751 | loadValueDirectFixed(cUnit, rlSrc2, rARG1); |
| 1752 | int rTgt = callHelperSetup(cUnit, funcOffset); |
| 1753 | loadValueDirectFixed(cUnit, rlSrc1, rARG0); |
| 1754 | if (checkZero) { |
| 1755 | genImmedCheck(cUnit, kCondEq, rARG1, 0, kThrowDivZero); |
| 1756 | } |
| 1757 | // NOTE: callout here is not a safepoint |
| 1758 | callHelper(cUnit, rTgt, funcOffset, false /* not a safepoint */ ); |
| 1759 | if (op == kOpDiv) |
| 1760 | rlResult = oatGetReturn(cUnit, false); |
| 1761 | else |
| 1762 | rlResult = oatGetReturnAlt(cUnit); |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1763 | } |
jeffhao | 4eb68ed | 2012-10-17 16:41:07 -0700 | [diff] [blame] | 1764 | storeValue(cUnit, rlDest, rlResult); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1765 | } |
| 1766 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /* |
| 1770 | * The following are the first-level codegen routines that analyze the format |
| 1771 | * of each bytecode then either dispatch special purpose codegen routines |
| 1772 | * or produce corresponding Thumb instructions directly. |
| 1773 | */ |
| 1774 | |
| 1775 | bool isPowerOfTwo(int x) |
| 1776 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1777 | return (x & (x - 1)) == 0; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | // Returns true if no more than two bits are set in 'x'. |
| 1781 | bool isPopCountLE2(unsigned int x) |
| 1782 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1783 | x &= x - 1; |
| 1784 | return (x & (x - 1)) == 0; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | // Returns the index of the lowest set bit in 'x'. |
| 1788 | int lowestSetBit(unsigned int x) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1789 | int bit_posn = 0; |
| 1790 | while ((x & 0xf) == 0) { |
| 1791 | bit_posn += 4; |
| 1792 | x >>= 4; |
| 1793 | } |
| 1794 | while ((x & 1) == 0) { |
| 1795 | bit_posn++; |
| 1796 | x >>= 1; |
| 1797 | } |
| 1798 | return bit_posn; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | // Returns true if it added instructions to 'cUnit' to divide 'rlSrc' by 'lit' |
| 1802 | // and store the result in 'rlDest'. |
Elliott Hughes | adb8c67 | 2012-03-06 16:49:32 -0800 | [diff] [blame] | 1803 | bool handleEasyDivide(CompilationUnit* cUnit, Instruction::Code dalvikOpcode, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1804 | RegLocation rlSrc, RegLocation rlDest, int lit) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1805 | { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1806 | if (lit < 2) |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1807 | return false; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1808 | // No divide instruction for Arm, so check for more special cases |
| 1809 | if ((cUnit->instructionSet == kThumb2) && !isPowerOfTwo(lit)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1810 | return smallLiteralDivide(cUnit, dalvikOpcode, rlSrc, rlDest, lit); |
| 1811 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1812 | int k = lowestSetBit(lit); |
| 1813 | if (k >= 30) { |
| 1814 | // Avoid special cases. |
| 1815 | return false; |
| 1816 | } |
| 1817 | bool div = (dalvikOpcode == Instruction::DIV_INT_LIT8 || |
| 1818 | dalvikOpcode == Instruction::DIV_INT_LIT16); |
| 1819 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 1820 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1821 | if (div) { |
| 1822 | int tReg = oatAllocTemp(cUnit); |
| 1823 | if (lit == 2) { |
| 1824 | // Division by 2 is by far the most common division by constant. |
| 1825 | opRegRegImm(cUnit, kOpLsr, tReg, rlSrc.lowReg, 32 - k); |
| 1826 | opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg); |
| 1827 | opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1828 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1829 | opRegRegImm(cUnit, kOpAsr, tReg, rlSrc.lowReg, 31); |
| 1830 | opRegRegImm(cUnit, kOpLsr, tReg, tReg, 32 - k); |
| 1831 | opRegRegReg(cUnit, kOpAdd, tReg, tReg, rlSrc.lowReg); |
| 1832 | opRegRegImm(cUnit, kOpAsr, rlResult.lowReg, tReg, k); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1833 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1834 | } else { |
| 1835 | int tReg1 = oatAllocTemp(cUnit); |
| 1836 | int tReg2 = oatAllocTemp(cUnit); |
| 1837 | if (lit == 2) { |
| 1838 | opRegRegImm(cUnit, kOpLsr, tReg1, rlSrc.lowReg, 32 - k); |
| 1839 | opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg); |
| 1840 | opRegRegImm(cUnit, kOpAnd, tReg2, tReg2, lit -1); |
| 1841 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1); |
| 1842 | } else { |
| 1843 | opRegRegImm(cUnit, kOpAsr, tReg1, rlSrc.lowReg, 31); |
| 1844 | opRegRegImm(cUnit, kOpLsr, tReg1, tReg1, 32 - k); |
| 1845 | opRegRegReg(cUnit, kOpAdd, tReg2, tReg1, rlSrc.lowReg); |
| 1846 | opRegRegImm(cUnit, kOpAnd, tReg2, tReg2, lit - 1); |
| 1847 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg2, tReg1); |
| 1848 | } |
| 1849 | } |
| 1850 | storeValue(cUnit, rlDest, rlResult); |
| 1851 | return true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1852 | } |
| 1853 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1854 | // Returns true if it added instructions to 'cUnit' to multiply 'rlSrc' by 'lit' |
| 1855 | // and store the result in 'rlDest'. |
| 1856 | bool handleEasyMultiply(CompilationUnit* cUnit, RegLocation rlSrc, |
| 1857 | RegLocation rlDest, int lit) |
| 1858 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1859 | // Can we simplify this multiplication? |
| 1860 | bool powerOfTwo = false; |
| 1861 | bool popCountLE2 = false; |
| 1862 | bool powerOfTwoMinusOne = false; |
| 1863 | if (lit < 2) { |
| 1864 | // Avoid special cases. |
| 1865 | return false; |
| 1866 | } else if (isPowerOfTwo(lit)) { |
| 1867 | powerOfTwo = true; |
| 1868 | } else if (isPopCountLE2(lit)) { |
| 1869 | popCountLE2 = true; |
| 1870 | } else if (isPowerOfTwo(lit + 1)) { |
| 1871 | powerOfTwoMinusOne = true; |
| 1872 | } else { |
| 1873 | return false; |
| 1874 | } |
| 1875 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 1876 | RegLocation rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1877 | if (powerOfTwo) { |
| 1878 | // Shift. |
| 1879 | opRegRegImm(cUnit, kOpLsl, rlResult.lowReg, rlSrc.lowReg, |
| 1880 | lowestSetBit(lit)); |
| 1881 | } else if (popCountLE2) { |
| 1882 | // Shift and add and shift. |
| 1883 | int firstBit = lowestSetBit(lit); |
| 1884 | int secondBit = lowestSetBit(lit ^ (1 << firstBit)); |
| 1885 | genMultiplyByTwoBitMultiplier(cUnit, rlSrc, rlResult, lit, |
| 1886 | firstBit, secondBit); |
| 1887 | } else { |
| 1888 | // Reverse subtract: (src << (shift + 1)) - src. |
| 1889 | DCHECK(powerOfTwoMinusOne); |
| 1890 | // TUNING: rsb dst, src, src lsl#lowestSetBit(lit + 1) |
| 1891 | int tReg = oatAllocTemp(cUnit); |
| 1892 | opRegRegImm(cUnit, kOpLsl, tReg, rlSrc.lowReg, lowestSetBit(lit + 1)); |
| 1893 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg, rlSrc.lowReg); |
| 1894 | } |
| 1895 | storeValue(cUnit, rlDest, rlResult); |
| 1896 | return true; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1897 | } |
| 1898 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1899 | bool genArithOpIntLit(CompilationUnit* cUnit, Instruction::Code opcode, |
| 1900 | RegLocation rlDest, RegLocation rlSrc, int lit) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1901 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1902 | RegLocation rlResult; |
| 1903 | OpKind op = (OpKind)0; /* Make gcc happy */ |
| 1904 | int shiftOp = false; |
| 1905 | bool isDiv = false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1906 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1907 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1908 | case Instruction::RSUB_INT_LIT8: |
| 1909 | case Instruction::RSUB_INT: { |
| 1910 | int tReg; |
| 1911 | //TUNING: add support for use of Arm rsub op |
| 1912 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 1913 | tReg = oatAllocTemp(cUnit); |
| 1914 | loadConstant(cUnit, tReg, lit); |
| 1915 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 1916 | opRegRegReg(cUnit, kOpSub, rlResult.lowReg, tReg, rlSrc.lowReg); |
| 1917 | storeValue(cUnit, rlDest, rlResult); |
| 1918 | return false; |
| 1919 | break; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1920 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1921 | |
| 1922 | case Instruction::ADD_INT_LIT8: |
| 1923 | case Instruction::ADD_INT_LIT16: |
| 1924 | op = kOpAdd; |
| 1925 | break; |
| 1926 | case Instruction::MUL_INT_LIT8: |
| 1927 | case Instruction::MUL_INT_LIT16: { |
| 1928 | if (handleEasyMultiply(cUnit, rlSrc, rlDest, lit)) { |
| 1929 | return false; |
| 1930 | } |
| 1931 | op = kOpMul; |
| 1932 | break; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 1933 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1934 | case Instruction::AND_INT_LIT8: |
| 1935 | case Instruction::AND_INT_LIT16: |
| 1936 | op = kOpAnd; |
| 1937 | break; |
| 1938 | case Instruction::OR_INT_LIT8: |
| 1939 | case Instruction::OR_INT_LIT16: |
| 1940 | op = kOpOr; |
| 1941 | break; |
| 1942 | case Instruction::XOR_INT_LIT8: |
| 1943 | case Instruction::XOR_INT_LIT16: |
| 1944 | op = kOpXor; |
| 1945 | break; |
| 1946 | case Instruction::SHL_INT_LIT8: |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 1947 | case Instruction::SHL_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1948 | lit &= 31; |
| 1949 | shiftOp = true; |
| 1950 | op = kOpLsl; |
| 1951 | break; |
| 1952 | case Instruction::SHR_INT_LIT8: |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 1953 | case Instruction::SHR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1954 | lit &= 31; |
| 1955 | shiftOp = true; |
| 1956 | op = kOpAsr; |
| 1957 | break; |
| 1958 | case Instruction::USHR_INT_LIT8: |
buzbee | 2a83e8f | 2012-07-13 16:42:30 -0700 | [diff] [blame] | 1959 | case Instruction::USHR_INT: |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1960 | lit &= 31; |
| 1961 | shiftOp = true; |
| 1962 | op = kOpLsr; |
| 1963 | break; |
| 1964 | |
| 1965 | case Instruction::DIV_INT_LIT8: |
| 1966 | case Instruction::DIV_INT_LIT16: |
| 1967 | case Instruction::REM_INT_LIT8: |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1968 | case Instruction::REM_INT_LIT16: { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1969 | if (lit == 0) { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1970 | genImmedCheck(cUnit, kCondAl, 0, 0, kThrowDivZero); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1971 | return false; |
| 1972 | } |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1973 | if (handleEasyDivide(cUnit, opcode, rlSrc, rlDest, lit)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1974 | return false; |
| 1975 | } |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 1976 | if ((opcode == Instruction::DIV_INT_LIT8) || |
| 1977 | (opcode == Instruction::DIV_INT_LIT16)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1978 | isDiv = true; |
| 1979 | } else { |
| 1980 | isDiv = false; |
| 1981 | } |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1982 | if (cUnit->instructionSet == kMips) { |
| 1983 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 1984 | rlResult = genDivRemLit(cUnit, rlDest, rlSrc.lowReg, lit, isDiv); |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1985 | } else { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 1986 | oatFlushAllRegs(cUnit); /* Everything to home location */ |
| 1987 | loadValueDirectFixed(cUnit, rlSrc, rARG0); |
| 1988 | oatClobber(cUnit, rARG0); |
| 1989 | int funcOffset = ENTRYPOINT_OFFSET(pIdivmod); |
| 1990 | callRuntimeHelperRegImm(cUnit, funcOffset, rARG0, lit, false); |
| 1991 | if (isDiv) |
| 1992 | rlResult = oatGetReturn(cUnit, false); |
| 1993 | else |
| 1994 | rlResult = oatGetReturnAlt(cUnit); |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1995 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 1996 | storeValue(cUnit, rlDest, rlResult); |
| 1997 | return false; |
| 1998 | break; |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 1999 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2000 | default: |
| 2001 | return true; |
| 2002 | } |
| 2003 | rlSrc = loadValue(cUnit, rlSrc, kCoreReg); |
| 2004 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 2005 | // Avoid shifts by literal 0 - no support in Thumb. Change to copy |
| 2006 | if (shiftOp && (lit == 0)) { |
| 2007 | opRegCopy(cUnit, rlResult.lowReg, rlSrc.lowReg); |
| 2008 | } else { |
| 2009 | opRegRegImm(cUnit, op, rlResult.lowReg, rlSrc.lowReg, lit); |
| 2010 | } |
| 2011 | storeValue(cUnit, rlDest, rlResult); |
| 2012 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2013 | } |
| 2014 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2015 | bool genArithOpLong(CompilationUnit* cUnit, Instruction::Code opcode, RegLocation rlDest, |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2016 | RegLocation rlSrc1, RegLocation rlSrc2) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2017 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2018 | RegLocation rlResult; |
| 2019 | OpKind firstOp = kOpBkpt; |
| 2020 | OpKind secondOp = kOpBkpt; |
| 2021 | bool callOut = false; |
| 2022 | bool checkZero = false; |
| 2023 | int funcOffset; |
| 2024 | int retReg = rRET0; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2025 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2026 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2027 | case Instruction::NOT_LONG: |
| 2028 | rlSrc2 = loadValueWide(cUnit, rlSrc2, kCoreReg); |
| 2029 | rlResult = oatEvalLoc(cUnit, rlDest, kCoreReg, true); |
| 2030 | // Check for destructive overlap |
| 2031 | if (rlResult.lowReg == rlSrc2.highReg) { |
| 2032 | int tReg = oatAllocTemp(cUnit); |
| 2033 | opRegCopy(cUnit, tReg, rlSrc2.highReg); |
| 2034 | opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg); |
| 2035 | opRegReg(cUnit, kOpMvn, rlResult.highReg, tReg); |
| 2036 | oatFreeTemp(cUnit, tReg); |
| 2037 | } else { |
| 2038 | opRegReg(cUnit, kOpMvn, rlResult.lowReg, rlSrc2.lowReg); |
| 2039 | opRegReg(cUnit, kOpMvn, rlResult.highReg, rlSrc2.highReg); |
| 2040 | } |
| 2041 | storeValueWide(cUnit, rlDest, rlResult); |
| 2042 | return false; |
| 2043 | break; |
| 2044 | case Instruction::ADD_LONG: |
| 2045 | case Instruction::ADD_LONG_2ADDR: |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2046 | if (cUnit->instructionSet != kThumb2) { |
| 2047 | return genAddLong(cUnit, rlDest, rlSrc1, rlSrc2); |
| 2048 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2049 | firstOp = kOpAdd; |
| 2050 | secondOp = kOpAdc; |
| 2051 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2052 | case Instruction::SUB_LONG: |
| 2053 | case Instruction::SUB_LONG_2ADDR: |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2054 | if (cUnit->instructionSet != kThumb2) { |
| 2055 | return genSubLong(cUnit, rlDest, rlSrc1, rlSrc2); |
| 2056 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2057 | firstOp = kOpSub; |
| 2058 | secondOp = kOpSbc; |
| 2059 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2060 | case Instruction::MUL_LONG: |
| 2061 | case Instruction::MUL_LONG_2ADDR: |
| 2062 | callOut = true; |
| 2063 | retReg = rRET0; |
| 2064 | funcOffset = ENTRYPOINT_OFFSET(pLmul); |
| 2065 | break; |
| 2066 | case Instruction::DIV_LONG: |
| 2067 | case Instruction::DIV_LONG_2ADDR: |
| 2068 | callOut = true; |
| 2069 | checkZero = true; |
| 2070 | retReg = rRET0; |
jeffhao | 644d531 | 2012-05-03 19:04:49 -0700 | [diff] [blame] | 2071 | funcOffset = ENTRYPOINT_OFFSET(pLdiv); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2072 | break; |
| 2073 | case Instruction::REM_LONG: |
| 2074 | case Instruction::REM_LONG_2ADDR: |
| 2075 | callOut = true; |
| 2076 | checkZero = true; |
jeffhao | 644d531 | 2012-05-03 19:04:49 -0700 | [diff] [blame] | 2077 | funcOffset = ENTRYPOINT_OFFSET(pLdivmod); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2078 | /* NOTE - for Arm, result is in rARG2/rARG3 instead of rRET0/rRET1 */ |
| 2079 | retReg = (cUnit->instructionSet == kThumb2) ? rARG2 : rRET0; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2080 | break; |
| 2081 | case Instruction::AND_LONG_2ADDR: |
| 2082 | case Instruction::AND_LONG: |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2083 | if (cUnit->instructionSet == kX86) { |
| 2084 | return genAndLong(cUnit, rlDest, rlSrc1, rlSrc2); |
| 2085 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2086 | firstOp = kOpAnd; |
| 2087 | secondOp = kOpAnd; |
| 2088 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2089 | case Instruction::OR_LONG: |
| 2090 | case Instruction::OR_LONG_2ADDR: |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2091 | if (cUnit->instructionSet == kX86) { |
| 2092 | return genOrLong(cUnit, rlDest, rlSrc1, rlSrc2); |
| 2093 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2094 | firstOp = kOpOr; |
| 2095 | secondOp = kOpOr; |
| 2096 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2097 | case Instruction::XOR_LONG: |
| 2098 | case Instruction::XOR_LONG_2ADDR: |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2099 | if (cUnit->instructionSet == kX86) { |
| 2100 | return genXorLong(cUnit, rlDest, rlSrc1, rlSrc2); |
| 2101 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2102 | firstOp = kOpXor; |
| 2103 | secondOp = kOpXor; |
| 2104 | break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2105 | case Instruction::NEG_LONG: { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2106 | return genNegLong(cUnit, rlDest, rlSrc2); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2107 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2108 | default: |
| 2109 | LOG(FATAL) << "Invalid long arith op"; |
| 2110 | } |
| 2111 | if (!callOut) { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2112 | genLong3Addr(cUnit, firstOp, secondOp, rlDest, rlSrc1, rlSrc2); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2113 | } else { |
| 2114 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
| 2115 | if (checkZero) { |
| 2116 | loadValueDirectWideFixed(cUnit, rlSrc2, rARG2, rARG3); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2117 | int rTgt = callHelperSetup(cUnit, funcOffset); |
| 2118 | genDivZeroCheck(cUnit, rARG2, rARG3); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2119 | loadValueDirectWideFixed(cUnit, rlSrc1, rARG0, rARG1); |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 2120 | // NOTE: callout here is not a safepoint |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2121 | callHelper(cUnit, rTgt, funcOffset, false /* not safepoint */); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2122 | } else { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2123 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 2124 | rlSrc1, rlSrc2, false); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2125 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2126 | // Adjust return regs in to handle case of rem returning rARG2/rARG3 |
| 2127 | if (retReg == rRET0) |
| 2128 | rlResult = oatGetReturnWide(cUnit, false); |
| 2129 | else |
| 2130 | rlResult = oatGetReturnWideAlt(cUnit); |
| 2131 | storeValueWide(cUnit, rlDest, rlResult); |
| 2132 | } |
| 2133 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2134 | } |
| 2135 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2136 | bool genConversionCall(CompilationUnit* cUnit, int funcOffset, |
| 2137 | RegLocation rlDest, RegLocation rlSrc) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2138 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2139 | /* |
| 2140 | * Don't optimize the register usage since it calls out to support |
| 2141 | * functions |
| 2142 | */ |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2143 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2144 | if (rlSrc.wide) { |
jeffhao | 30a3317 | 2012-10-22 18:16:22 -0700 | [diff] [blame] | 2145 | loadValueDirectWideFixed(cUnit, rlSrc, rlSrc.fp ? rFARG0 : rARG0, rlSrc.fp ? rFARG1 : rARG1); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2146 | } else { |
jeffhao | 30a3317 | 2012-10-22 18:16:22 -0700 | [diff] [blame] | 2147 | loadValueDirectFixed(cUnit, rlSrc, rlSrc.fp ? rFARG0 : rARG0); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2148 | } |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 2149 | callRuntimeHelperRegLocation(cUnit, funcOffset, rlSrc, false); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2150 | if (rlDest.wide) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2151 | RegLocation rlResult; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2152 | rlResult = oatGetReturnWide(cUnit, rlDest.fp); |
| 2153 | storeValueWide(cUnit, rlDest, rlResult); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2154 | } else { |
| 2155 | RegLocation rlResult; |
| 2156 | rlResult = oatGetReturn(cUnit, rlDest.fp); |
| 2157 | storeValue(cUnit, rlDest, rlResult); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2158 | } |
| 2159 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | void genNegFloat(CompilationUnit* cUnit, RegLocation rlDest, RegLocation rlSrc); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2163 | bool genArithOpFloatPortable(CompilationUnit* cUnit, Instruction::Code opcode, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2164 | RegLocation rlDest, RegLocation rlSrc1, |
| 2165 | RegLocation rlSrc2) |
| 2166 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2167 | RegLocation rlResult; |
| 2168 | int funcOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2169 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2170 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2171 | case Instruction::ADD_FLOAT_2ADDR: |
| 2172 | case Instruction::ADD_FLOAT: |
| 2173 | funcOffset = ENTRYPOINT_OFFSET(pFadd); |
| 2174 | break; |
| 2175 | case Instruction::SUB_FLOAT_2ADDR: |
| 2176 | case Instruction::SUB_FLOAT: |
| 2177 | funcOffset = ENTRYPOINT_OFFSET(pFsub); |
| 2178 | break; |
| 2179 | case Instruction::DIV_FLOAT_2ADDR: |
| 2180 | case Instruction::DIV_FLOAT: |
| 2181 | funcOffset = ENTRYPOINT_OFFSET(pFdiv); |
| 2182 | break; |
| 2183 | case Instruction::MUL_FLOAT_2ADDR: |
| 2184 | case Instruction::MUL_FLOAT: |
| 2185 | funcOffset = ENTRYPOINT_OFFSET(pFmul); |
| 2186 | break; |
| 2187 | case Instruction::REM_FLOAT_2ADDR: |
| 2188 | case Instruction::REM_FLOAT: |
| 2189 | funcOffset = ENTRYPOINT_OFFSET(pFmodf); |
| 2190 | break; |
| 2191 | case Instruction::NEG_FLOAT: { |
| 2192 | genNegFloat(cUnit, rlDest, rlSrc1); |
| 2193 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2194 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2195 | default: |
| 2196 | return true; |
| 2197 | } |
| 2198 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 2199 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlSrc2, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2200 | rlResult = oatGetReturn(cUnit, true); |
| 2201 | storeValue(cUnit, rlDest, rlResult); |
| 2202 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2203 | } |
| 2204 | |
| 2205 | void genNegDouble(CompilationUnit* cUnit, RegLocation rlDst, RegLocation rlSrc); |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2206 | bool genArithOpDoublePortable(CompilationUnit* cUnit, Instruction::Code opcode, |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2207 | RegLocation rlDest, RegLocation rlSrc1, |
| 2208 | RegLocation rlSrc2) |
| 2209 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2210 | RegLocation rlResult; |
| 2211 | int funcOffset; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2212 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2213 | switch (opcode) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2214 | case Instruction::ADD_DOUBLE_2ADDR: |
| 2215 | case Instruction::ADD_DOUBLE: |
| 2216 | funcOffset = ENTRYPOINT_OFFSET(pDadd); |
| 2217 | break; |
| 2218 | case Instruction::SUB_DOUBLE_2ADDR: |
| 2219 | case Instruction::SUB_DOUBLE: |
| 2220 | funcOffset = ENTRYPOINT_OFFSET(pDsub); |
| 2221 | break; |
| 2222 | case Instruction::DIV_DOUBLE_2ADDR: |
| 2223 | case Instruction::DIV_DOUBLE: |
| 2224 | funcOffset = ENTRYPOINT_OFFSET(pDdiv); |
| 2225 | break; |
| 2226 | case Instruction::MUL_DOUBLE_2ADDR: |
| 2227 | case Instruction::MUL_DOUBLE: |
| 2228 | funcOffset = ENTRYPOINT_OFFSET(pDmul); |
| 2229 | break; |
| 2230 | case Instruction::REM_DOUBLE_2ADDR: |
| 2231 | case Instruction::REM_DOUBLE: |
| 2232 | funcOffset = ENTRYPOINT_OFFSET(pFmod); |
| 2233 | break; |
| 2234 | case Instruction::NEG_DOUBLE: { |
| 2235 | genNegDouble(cUnit, rlDest, rlSrc1); |
| 2236 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2237 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2238 | default: |
| 2239 | return true; |
| 2240 | } |
| 2241 | oatFlushAllRegs(cUnit); /* Send everything to home location */ |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 2242 | callRuntimeHelperRegLocationRegLocation(cUnit, funcOffset, rlSrc1, rlSrc2, false); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2243 | rlResult = oatGetReturnWide(cUnit, true); |
| 2244 | storeValueWide(cUnit, rlDest, rlResult); |
| 2245 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2246 | } |
| 2247 | |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2248 | bool genConversionPortable(CompilationUnit* cUnit, Instruction::Code opcode, |
| 2249 | RegLocation rlDest, RegLocation rlSrc) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2250 | { |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2251 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2252 | switch (opcode) { |
| 2253 | case Instruction::INT_TO_FLOAT: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2254 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pI2f), |
| 2255 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2256 | case Instruction::FLOAT_TO_INT: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2257 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pF2iz), |
| 2258 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2259 | case Instruction::DOUBLE_TO_FLOAT: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2260 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pD2f), |
| 2261 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2262 | case Instruction::FLOAT_TO_DOUBLE: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2263 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pF2d), |
| 2264 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2265 | case Instruction::INT_TO_DOUBLE: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2266 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pI2d), |
| 2267 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2268 | case Instruction::DOUBLE_TO_INT: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2269 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pD2iz), |
| 2270 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2271 | case Instruction::FLOAT_TO_LONG: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2272 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pF2l), |
| 2273 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2274 | case Instruction::LONG_TO_FLOAT: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2275 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pL2f), |
| 2276 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2277 | case Instruction::DOUBLE_TO_LONG: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2278 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pD2l), |
| 2279 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2280 | case Instruction::LONG_TO_DOUBLE: |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2281 | return genConversionCall(cUnit, ENTRYPOINT_OFFSET(pL2d), |
| 2282 | rlDest, rlSrc); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2283 | default: |
| 2284 | return true; |
| 2285 | } |
| 2286 | return false; |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2287 | } |
| 2288 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2289 | /* Check if we need to check for pending suspend request */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2290 | void genSuspendTest(CompilationUnit* cUnit, int optFlags) |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2291 | { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2292 | if (NO_SUSPEND || (optFlags & MIR_IGNORE_SUSPEND_CHECK)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2293 | return; |
| 2294 | } |
| 2295 | oatFlushAllRegs(cUnit); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2296 | LIR* branch = opTestSuspend(cUnit, NULL); |
| 2297 | LIR* retLab = newLIR0(cUnit, kPseudoTargetLabel); |
| 2298 | LIR* target = rawLIR(cUnit, cUnit->currentDalvikOffset, kPseudoSuspendTarget, |
| 2299 | (intptr_t)retLab, cUnit->currentDalvikOffset); |
| 2300 | branch->target = (LIR*)target; |
| 2301 | oatInsertGrowableList(cUnit, &cUnit->suspendLaunchpads, (intptr_t)target); |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2302 | } |
| 2303 | |
buzbee | fead293 | 2012-03-30 14:02:01 -0700 | [diff] [blame] | 2304 | /* Check if we need to check for pending suspend request */ |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2305 | void genSuspendTestAndBranch(CompilationUnit* cUnit, int optFlags, LIR* target) |
buzbee | fead293 | 2012-03-30 14:02:01 -0700 | [diff] [blame] | 2306 | { |
buzbee | 408ad16 | 2012-06-06 16:45:18 -0700 | [diff] [blame] | 2307 | if (NO_SUSPEND || (optFlags & MIR_IGNORE_SUSPEND_CHECK)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 2308 | opUnconditionalBranch(cUnit, target); |
| 2309 | return; |
| 2310 | } |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame^] | 2311 | opTestSuspend(cUnit, target); |
| 2312 | LIR* launchPad = rawLIR(cUnit, cUnit->currentDalvikOffset, kPseudoSuspendTarget, (intptr_t)target, |
| 2313 | cUnit->currentDalvikOffset); |
| 2314 | oatFlushAllRegs(cUnit); |
| 2315 | opUnconditionalBranch(cUnit, launchPad); |
| 2316 | oatInsertGrowableList(cUnit, &cUnit->suspendLaunchpads, (intptr_t)launchPad); |
buzbee | fead293 | 2012-03-30 14:02:01 -0700 | [diff] [blame] | 2317 | } |
| 2318 | |
buzbee | 31a4a6f | 2012-02-28 15:36:15 -0800 | [diff] [blame] | 2319 | } // namespace art |