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