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