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