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