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