Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [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 | |
| 17 | #include "dex/compiler_ir.h" |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 18 | #include "dex/frontend.h" |
| 19 | #include "dex/quick/dex_file_method_inliner.h" |
| 20 | #include "dex/quick/dex_file_to_method_inliner_map.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include "dex_file-inl.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | #include "invoke_type.h" |
| 24 | #include "mirror/array.h" |
| 25 | #include "mirror/string.h" |
| 26 | #include "mir_to_lir-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | #include "x86/codegen_x86.h" |
| 28 | |
| 29 | namespace art { |
| 30 | |
| 31 | /* |
| 32 | * This source files contains "gen" codegen routines that should |
| 33 | * be applicable to most targets. Only mid-level support utilities |
| 34 | * and "op" calls may be used here. |
| 35 | */ |
| 36 | |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 37 | void Mir2Lir::AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume) { |
| 38 | class IntrinsicSlowPathPath : public Mir2Lir::LIRSlowPath { |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 39 | public: |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 40 | IntrinsicSlowPathPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr) |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 41 | : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) { |
| 42 | } |
| 43 | |
| 44 | void Compile() { |
| 45 | m2l_->ResetRegPool(); |
| 46 | m2l_->ResetDefTracking(); |
Mingyao Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 47 | GenerateTargetLabel(kPseudoIntrinsicRetry); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 48 | // NOTE: GenInvokeNoInline() handles MarkSafepointPC. |
| 49 | m2l_->GenInvokeNoInline(info_); |
| 50 | if (cont_ != nullptr) { |
| 51 | m2l_->OpUnconditionalBranch(cont_); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | CallInfo* const info_; |
| 57 | }; |
| 58 | |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 59 | AddSlowPath(new (arena_) IntrinsicSlowPathPath(this, info, branch, resume)); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 62 | /* |
| 63 | * To save scheduling time, helper calls are broken into two parts: generation of |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 64 | * the helper target address, and the actual call to the helper. Because x86 |
| 65 | * has a memory call operation, part 1 is a NOP for x86. For other targets, |
| 66 | * load arguments between the two parts. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 67 | */ |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 68 | RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<4> helper_offset) { |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 69 | return (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) ? RegStorage::InvalidReg() : LoadHelper(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* NOTE: if r_tgt is a temp, it will be freed following use */ |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 73 | LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<4> helper_offset, bool safepoint_pc, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 74 | bool use_link) { |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 75 | LIR* call_inst; |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame] | 76 | OpKind op = use_link ? kOpBlx : kOpBx; |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 77 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
| 78 | call_inst = OpThreadMem(op, helper_offset); |
| 79 | } else { |
| 80 | call_inst = OpReg(op, r_tgt); |
| 81 | FreeTemp(r_tgt); |
| 82 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 83 | if (safepoint_pc) { |
| 84 | MarkSafepointPC(call_inst); |
| 85 | } |
| 86 | return call_inst; |
| 87 | } |
| 88 | |
Mingyao Yang | 4289456 | 2014-04-07 12:42:16 -0700 | [diff] [blame] | 89 | void Mir2Lir::CallRuntimeHelper(ThreadOffset<4> helper_offset, bool safepoint_pc) { |
| 90 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 91 | ClobberCallerSave(); |
| 92 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 93 | } |
| 94 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 95 | void Mir2Lir::CallRuntimeHelperImm(ThreadOffset<4> helper_offset, int arg0, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 96 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 97 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 98 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 99 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 100 | } |
| 101 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 102 | void Mir2Lir::CallRuntimeHelperReg(ThreadOffset<4> helper_offset, RegStorage arg0, |
| 103 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 104 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 105 | OpRegCopy(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 106 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 107 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 108 | } |
| 109 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 110 | void Mir2Lir::CallRuntimeHelperRegLocation(ThreadOffset<4> helper_offset, RegLocation arg0, |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 111 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 112 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 113 | if (arg0.wide == 0) { |
| 114 | LoadValueDirectFixed(arg0, TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 115 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 116 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg0), TargetReg(kArg1)); |
| 117 | LoadValueDirectWideFixed(arg0, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 118 | } |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 119 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 120 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 121 | } |
| 122 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 123 | void Mir2Lir::CallRuntimeHelperImmImm(ThreadOffset<4> helper_offset, int arg0, int arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 124 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 125 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 126 | LoadConstant(TargetReg(kArg0), arg0); |
| 127 | LoadConstant(TargetReg(kArg1), arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 128 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 129 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 130 | } |
| 131 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 132 | void Mir2Lir::CallRuntimeHelperImmRegLocation(ThreadOffset<4> helper_offset, int arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 133 | RegLocation arg1, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 134 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 135 | if (arg1.wide == 0) { |
| 136 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 137 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 138 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg1), TargetReg(kArg2)); |
| 139 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 140 | } |
| 141 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 142 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 143 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 144 | } |
| 145 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 146 | void Mir2Lir::CallRuntimeHelperRegLocationImm(ThreadOffset<4> helper_offset, RegLocation arg0, |
| 147 | int arg1, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 148 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 149 | LoadValueDirectFixed(arg0, TargetReg(kArg0)); |
| 150 | LoadConstant(TargetReg(kArg1), arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 151 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 152 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 153 | } |
| 154 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 155 | void Mir2Lir::CallRuntimeHelperImmReg(ThreadOffset<4> helper_offset, int arg0, RegStorage arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 156 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 157 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 158 | OpRegCopy(TargetReg(kArg1), arg1); |
| 159 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 160 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 161 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 162 | } |
| 163 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 164 | void Mir2Lir::CallRuntimeHelperRegImm(ThreadOffset<4> helper_offset, RegStorage arg0, int arg1, |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 165 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 166 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 167 | OpRegCopy(TargetReg(kArg0), arg0); |
| 168 | LoadConstant(TargetReg(kArg1), arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 169 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 170 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 171 | } |
| 172 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 173 | void Mir2Lir::CallRuntimeHelperImmMethod(ThreadOffset<4> helper_offset, int arg0, |
| 174 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 175 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 176 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 177 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 178 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 179 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 180 | } |
| 181 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 182 | void Mir2Lir::CallRuntimeHelperRegMethod(ThreadOffset<4> helper_offset, RegStorage arg0, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 183 | bool safepoint_pc) { |
| 184 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 185 | DCHECK_NE(TargetReg(kArg1).GetReg(), arg0.GetReg()); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 186 | if (TargetReg(kArg0) != arg0) { |
| 187 | OpRegCopy(TargetReg(kArg0), arg0); |
| 188 | } |
| 189 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 190 | ClobberCallerSave(); |
| 191 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 192 | } |
| 193 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 194 | void Mir2Lir::CallRuntimeHelperRegMethodRegLocation(ThreadOffset<4> helper_offset, RegStorage arg0, |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 195 | RegLocation arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 196 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 197 | DCHECK_NE(TargetReg(kArg1).GetReg(), arg0.GetReg()); |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 198 | if (TargetReg(kArg0) != arg0) { |
| 199 | OpRegCopy(TargetReg(kArg0), arg0); |
| 200 | } |
| 201 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 202 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
| 203 | ClobberCallerSave(); |
| 204 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 205 | } |
| 206 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 207 | void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(ThreadOffset<4> helper_offset, |
| 208 | RegLocation arg0, RegLocation arg1, |
| 209 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 210 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 211 | if (arg0.wide == 0) { |
| 212 | LoadValueDirectFixed(arg0, arg0.fp ? TargetReg(kFArg0) : TargetReg(kArg0)); |
| 213 | if (arg1.wide == 0) { |
| 214 | if (cu_->instruction_set == kMips) { |
| 215 | LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg1)); |
| 216 | } else { |
| 217 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 218 | } |
| 219 | } else { |
| 220 | if (cu_->instruction_set == kMips) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 221 | RegStorage r_tmp; |
| 222 | if (arg1.fp) { |
| 223 | r_tmp = RegStorage::MakeRegPair(TargetReg(kFArg2), TargetReg(kFArg3)); |
| 224 | } else { |
| 225 | r_tmp = RegStorage::MakeRegPair(TargetReg(kArg1), TargetReg(kArg2)); |
| 226 | } |
| 227 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 228 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 229 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg1), TargetReg(kArg2)); |
| 230 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 231 | } |
| 232 | } |
| 233 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 234 | RegStorage r_tmp; |
| 235 | if (arg0.fp) { |
| 236 | r_tmp = RegStorage::MakeRegPair(TargetReg(kFArg0), TargetReg(kFArg1)); |
| 237 | } else { |
| 238 | r_tmp = RegStorage::MakeRegPair(TargetReg(kArg0), TargetReg(kArg1)); |
| 239 | } |
| 240 | LoadValueDirectWideFixed(arg0, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 241 | if (arg1.wide == 0) { |
| 242 | LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg2)); |
| 243 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 244 | RegStorage r_tmp; |
| 245 | if (arg1.fp) { |
| 246 | r_tmp = RegStorage::MakeRegPair(TargetReg(kFArg2), TargetReg(kFArg3)); |
| 247 | } else { |
| 248 | r_tmp = RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3)); |
| 249 | } |
| 250 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 251 | } |
| 252 | } |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 253 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 254 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 255 | } |
| 256 | |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 257 | void Mir2Lir::CopyToArgumentRegs(RegStorage arg0, RegStorage arg1) { |
| 258 | if (arg1.GetReg() == TargetReg(kArg0).GetReg()) { |
| 259 | if (arg0.GetReg() == TargetReg(kArg1).GetReg()) { |
| 260 | // Swap kArg0 and kArg1 with kArg2 as temp. |
| 261 | OpRegCopy(TargetReg(kArg2), arg1); |
| 262 | OpRegCopy(TargetReg(kArg0), arg0); |
| 263 | OpRegCopy(TargetReg(kArg1), TargetReg(kArg2)); |
| 264 | } else { |
| 265 | OpRegCopy(TargetReg(kArg1), arg1); |
| 266 | OpRegCopy(TargetReg(kArg0), arg0); |
| 267 | } |
| 268 | } else { |
| 269 | OpRegCopy(TargetReg(kArg0), arg0); |
| 270 | OpRegCopy(TargetReg(kArg1), arg1); |
| 271 | } |
| 272 | } |
| 273 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 274 | void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset<4> helper_offset, RegStorage arg0, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 275 | RegStorage arg1, bool safepoint_pc) { |
| 276 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 277 | CopyToArgumentRegs(arg0, arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 278 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 279 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 280 | } |
| 281 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 282 | void Mir2Lir::CallRuntimeHelperRegRegImm(ThreadOffset<4> helper_offset, RegStorage arg0, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 283 | RegStorage arg1, int arg2, bool safepoint_pc) { |
| 284 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Mingyao Yang | 80365d9 | 2014-04-18 12:10:58 -0700 | [diff] [blame] | 285 | CopyToArgumentRegs(arg0, arg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 286 | LoadConstant(TargetReg(kArg2), arg2); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 287 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 288 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 289 | } |
| 290 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 291 | void Mir2Lir::CallRuntimeHelperImmMethodRegLocation(ThreadOffset<4> helper_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 292 | int arg0, RegLocation arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 293 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 294 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
| 295 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 296 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 297 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 298 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 299 | } |
| 300 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 301 | void Mir2Lir::CallRuntimeHelperImmMethodImm(ThreadOffset<4> helper_offset, int arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 302 | int arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 303 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 304 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 305 | LoadConstant(TargetReg(kArg2), arg2); |
| 306 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 307 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 308 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 309 | } |
| 310 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 311 | void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset<4> helper_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 312 | int arg0, RegLocation arg1, |
| 313 | RegLocation arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 314 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 315 | DCHECK_EQ(arg1.wide, 0U); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 316 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 317 | if (arg2.wide == 0) { |
| 318 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
| 319 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 320 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3)); |
| 321 | LoadValueDirectWideFixed(arg2, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 322 | } |
| 323 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 324 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 325 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 326 | } |
| 327 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 328 | void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(ThreadOffset<4> helper_offset, |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 329 | RegLocation arg0, RegLocation arg1, |
| 330 | RegLocation arg2, |
| 331 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 332 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 333 | DCHECK_EQ(arg0.wide, 0U); |
| 334 | LoadValueDirectFixed(arg0, TargetReg(kArg0)); |
| 335 | DCHECK_EQ(arg1.wide, 0U); |
| 336 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 337 | DCHECK_EQ(arg1.wide, 0U); |
| 338 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 339 | ClobberCallerSave(); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 340 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 341 | } |
| 342 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 343 | /* |
| 344 | * If there are any ins passed in registers that have not been promoted |
| 345 | * to a callee-save register, flush them to the frame. Perform intial |
| 346 | * assignment of promoted arguments. |
| 347 | * |
| 348 | * ArgLocs is an array of location records describing the incoming arguments |
| 349 | * with one location record per word of argument. |
| 350 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 351 | void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 352 | /* |
| 353 | * Dummy up a RegLocation for the incoming Method* |
| 354 | * It will attempt to keep kArg0 live (or copy it to home location |
| 355 | * if promoted). |
| 356 | */ |
| 357 | RegLocation rl_src = rl_method; |
| 358 | rl_src.location = kLocPhysReg; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 359 | rl_src.reg = TargetReg(kArg0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 360 | rl_src.home = false; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 361 | MarkLive(rl_src); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 362 | if (rl_method.wide) { |
| 363 | StoreValueWide(rl_method, rl_src); |
| 364 | } else { |
| 365 | StoreValue(rl_method, rl_src); |
| 366 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 367 | // If Method* has been promoted, explicitly flush |
| 368 | if (rl_method.location == kLocPhysReg) { |
| 369 | StoreWordDisp(TargetReg(kSp), 0, TargetReg(kArg0)); |
| 370 | } |
| 371 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 372 | if (cu_->num_ins == 0) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 373 | return; |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 376 | int start_vreg = cu_->num_dalvik_registers - cu_->num_ins; |
| 377 | /* |
| 378 | * Copy incoming arguments to their proper home locations. |
| 379 | * NOTE: an older version of dx had an issue in which |
| 380 | * it would reuse static method argument registers. |
| 381 | * This could result in the same Dalvik virtual register |
| 382 | * being promoted to both core and fp regs. To account for this, |
| 383 | * we only copy to the corresponding promoted physical register |
| 384 | * if it matches the type of the SSA name for the incoming |
| 385 | * argument. It is also possible that long and double arguments |
| 386 | * end up half-promoted. In those cases, we must flush the promoted |
| 387 | * half to memory as well. |
| 388 | */ |
| 389 | for (int i = 0; i < cu_->num_ins; i++) { |
| 390 | PromotionMap* v_map = &promotion_map_[start_vreg + i]; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 391 | RegStorage reg = GetArgMappingToPhysicalReg(i); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 392 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 393 | if (reg.Valid()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 394 | // If arriving in register |
| 395 | bool need_flush = true; |
| 396 | RegLocation* t_loc = &ArgLocs[i]; |
| 397 | if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 398 | OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 399 | need_flush = false; |
| 400 | } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 401 | OpRegCopy(RegStorage::Solo32(v_map->FpReg), reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 402 | need_flush = false; |
| 403 | } else { |
| 404 | need_flush = true; |
| 405 | } |
| 406 | |
buzbee | d0a03b8 | 2013-09-14 08:21:05 -0700 | [diff] [blame] | 407 | // For wide args, force flush if not fully promoted |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 408 | if (t_loc->wide) { |
| 409 | PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1); |
buzbee | d0a03b8 | 2013-09-14 08:21:05 -0700 | [diff] [blame] | 410 | // Is only half promoted? |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 411 | need_flush |= (p_map->core_location != v_map->core_location) || |
| 412 | (p_map->fp_location != v_map->fp_location); |
buzbee | d0a03b8 | 2013-09-14 08:21:05 -0700 | [diff] [blame] | 413 | if ((cu_->instruction_set == kThumb2) && t_loc->fp && !need_flush) { |
| 414 | /* |
| 415 | * In Arm, a double is represented as a pair of consecutive single float |
| 416 | * registers starting at an even number. It's possible that both Dalvik vRegs |
| 417 | * representing the incoming double were independently promoted as singles - but |
| 418 | * not in a form usable as a double. If so, we need to flush - even though the |
| 419 | * incoming arg appears fully in register. At this point in the code, both |
| 420 | * halves of the double are promoted. Make sure they are in a usable form. |
| 421 | */ |
| 422 | int lowreg_index = start_vreg + i + (t_loc->high_word ? -1 : 0); |
| 423 | int low_reg = promotion_map_[lowreg_index].FpReg; |
| 424 | int high_reg = promotion_map_[lowreg_index + 1].FpReg; |
| 425 | if (((low_reg & 0x1) != 0) || (high_reg != (low_reg + 1))) { |
| 426 | need_flush = true; |
| 427 | } |
| 428 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 429 | } |
| 430 | if (need_flush) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 431 | Store32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 432 | } |
| 433 | } else { |
| 434 | // If arriving in frame & promoted |
| 435 | if (v_map->core_location == kLocPhysReg) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 436 | Load32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->core_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 437 | } |
| 438 | if (v_map->fp_location == kLocPhysReg) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 439 | Load32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | /* |
| 446 | * Bit of a hack here - in the absence of a real scheduling pass, |
| 447 | * emit the next instruction in static & direct invoke sequences. |
| 448 | */ |
| 449 | static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info, |
| 450 | int state, const MethodReference& target_method, |
| 451 | uint32_t unused, |
| 452 | uintptr_t direct_code, uintptr_t direct_method, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 453 | InvokeType type) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 454 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 455 | if (direct_code != 0 && direct_method != 0) { |
| 456 | switch (state) { |
| 457 | case 0: // Get the current Method* [sets kArg0] |
Ian Rogers | ff093b3 | 2014-04-30 19:04:27 -0700 | [diff] [blame] | 458 | if (direct_code != static_cast<uintptr_t>(-1)) { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 459 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Ian Rogers | 83883d7 | 2013-10-21 21:07:24 -0700 | [diff] [blame] | 460 | cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code); |
| 461 | } |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 462 | } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 463 | cg->LoadCodeAddress(target_method, type, kInvokeTgt); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 464 | } |
Ian Rogers | ff093b3 | 2014-04-30 19:04:27 -0700 | [diff] [blame] | 465 | if (direct_method != static_cast<uintptr_t>(-1)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 466 | cg->LoadConstant(cg->TargetReg(kArg0), direct_method); |
| 467 | } else { |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 468 | cg->LoadMethodAddress(target_method, type, kArg0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 469 | } |
| 470 | break; |
| 471 | default: |
| 472 | return -1; |
| 473 | } |
| 474 | } else { |
| 475 | switch (state) { |
| 476 | case 0: // Get the current Method* [sets kArg0] |
| 477 | // TUNING: we can save a reg copy if Method* has been promoted. |
| 478 | cg->LoadCurrMethodDirect(cg->TargetReg(kArg0)); |
| 479 | break; |
| 480 | case 1: // Get method->dex_cache_resolved_methods_ |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 481 | cg->LoadRefDisp(cg->TargetReg(kArg0), |
| 482 | mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(), |
| 483 | cg->TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 484 | // Set up direct code if known. |
| 485 | if (direct_code != 0) { |
Ian Rogers | ff093b3 | 2014-04-30 19:04:27 -0700 | [diff] [blame] | 486 | if (direct_code != static_cast<uintptr_t>(-1)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 487 | cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 488 | } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Ian Rogers | 83883d7 | 2013-10-21 21:07:24 -0700 | [diff] [blame] | 489 | CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds()); |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 490 | cg->LoadCodeAddress(target_method, type, kInvokeTgt); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 491 | } |
| 492 | } |
| 493 | break; |
| 494 | case 2: // Grab target method* |
| 495 | CHECK_EQ(cu->dex_file, target_method.dex_file); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 496 | cg->LoadRefDisp(cg->TargetReg(kArg0), |
| 497 | mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + |
| 498 | (target_method.dex_method_index * 4), cg->TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 499 | break; |
| 500 | case 3: // Grab the code from the method* |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 501 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 502 | if (direct_code == 0) { |
| 503 | cg->LoadWordDisp(cg->TargetReg(kArg0), |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 504 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 505 | cg->TargetReg(kInvokeTgt)); |
| 506 | } |
| 507 | break; |
| 508 | } |
| 509 | // Intentional fallthrough for x86 |
| 510 | default: |
| 511 | return -1; |
| 512 | } |
| 513 | } |
| 514 | return state + 1; |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | * Bit of a hack here - in the absence of a real scheduling pass, |
| 519 | * emit the next instruction in a virtual invoke sequence. |
| 520 | * We can use kLr as a temp prior to target address loading |
| 521 | * Note also that we'll load the first argument ("this") into |
| 522 | * kArg1 here rather than the standard LoadArgRegs. |
| 523 | */ |
| 524 | static int NextVCallInsn(CompilationUnit* cu, CallInfo* info, |
| 525 | int state, const MethodReference& target_method, |
| 526 | uint32_t method_idx, uintptr_t unused, uintptr_t unused2, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 527 | InvokeType unused3) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 528 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
| 529 | /* |
| 530 | * This is the fast path in which the target virtual method is |
| 531 | * fully resolved at compile time. |
| 532 | */ |
| 533 | switch (state) { |
| 534 | case 0: { // Get "this" [set kArg1] |
| 535 | RegLocation rl_arg = info->args[0]; |
| 536 | cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1)); |
| 537 | break; |
| 538 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 539 | case 1: // Is "this" null? [use kArg1] |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 540 | cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 541 | // get this->klass_ [use kArg1, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 542 | cg->LoadRefDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), |
| 543 | cg->TargetReg(kInvokeTgt)); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 544 | cg->MarkPossibleNullPointerException(info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 545 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 546 | case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 547 | cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), mirror::Class::VTableOffset().Int32Value(), |
| 548 | cg->TargetReg(kInvokeTgt)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 549 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 550 | case 3: // Get target method [use kInvokeTgt, set kArg0] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 551 | cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), (method_idx * 4) + |
| 552 | mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(), |
| 553 | cg->TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 554 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 555 | case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt] |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 556 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 557 | cg->LoadWordDisp(cg->TargetReg(kArg0), |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 558 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 559 | cg->TargetReg(kInvokeTgt)); |
| 560 | break; |
| 561 | } |
| 562 | // Intentional fallthrough for X86 |
| 563 | default: |
| 564 | return -1; |
| 565 | } |
| 566 | return state + 1; |
| 567 | } |
| 568 | |
| 569 | /* |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 570 | * Emit the next instruction in an invoke interface sequence. This will do a lookup in the |
| 571 | * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if |
| 572 | * more than one interface method map to the same index. Note also that we'll load the first |
| 573 | * argument ("this") into kArg1 here rather than the standard LoadArgRegs. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 574 | */ |
| 575 | static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state, |
| 576 | const MethodReference& target_method, |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 577 | uint32_t method_idx, uintptr_t unused, |
| 578 | uintptr_t direct_method, InvokeType unused2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 579 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 580 | |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 581 | switch (state) { |
| 582 | case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)] |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 583 | CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds()); |
| 584 | cg->LoadConstant(cg->TargetReg(kHiddenArg), target_method.dex_method_index); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 585 | if (cu->instruction_set == kX86 || cu->instruction_set == kX86_64) { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 586 | cg->OpRegCopy(cg->TargetReg(kHiddenFpArg), cg->TargetReg(kHiddenArg)); |
| 587 | } |
| 588 | break; |
| 589 | case 1: { // Get "this" [set kArg1] |
| 590 | RegLocation rl_arg = info->args[0]; |
| 591 | cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1)); |
| 592 | break; |
| 593 | } |
| 594 | case 2: // Is "this" null? [use kArg1] |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 595 | cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags); |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 596 | // Get this->klass_ [use kArg1, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 597 | cg->LoadRefDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), |
| 598 | cg->TargetReg(kInvokeTgt)); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 599 | cg->MarkPossibleNullPointerException(info->opt_flags); |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 600 | break; |
| 601 | case 3: // Get this->klass_->imtable [use kInvokeTgt, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 602 | // NOTE: native pointer. |
| 603 | cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), mirror::Class::ImTableOffset().Int32Value(), |
| 604 | cg->TargetReg(kInvokeTgt)); |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 605 | break; |
| 606 | case 4: // Get target method [use kInvokeTgt, set kArg0] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 607 | // NOTE: native pointer. |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 608 | cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), ((method_idx % ClassLinker::kImtSize) * 4) + |
| 609 | mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 610 | cg->TargetReg(kArg0)); |
| 611 | break; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 612 | case 5: // Get the compiled code address [use kArg0, set kInvokeTgt] |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 613 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 614 | cg->LoadWordDisp(cg->TargetReg(kArg0), |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 615 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(), |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 616 | cg->TargetReg(kInvokeTgt)); |
| 617 | break; |
| 618 | } |
| 619 | // Intentional fallthrough for X86 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 620 | default: |
| 621 | return -1; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 622 | } |
| 623 | return state + 1; |
| 624 | } |
| 625 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 626 | static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, ThreadOffset<4> trampoline, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 627 | int state, const MethodReference& target_method, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 628 | uint32_t method_idx) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 629 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
| 630 | /* |
| 631 | * This handles the case in which the base method is not fully |
| 632 | * resolved at compile time, we bail to a runtime helper. |
| 633 | */ |
| 634 | if (state == 0) { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 635 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 636 | // Load trampoline target |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 637 | cg->LoadWordDisp(cg->TargetReg(kSelf), trampoline.Int32Value(), cg->TargetReg(kInvokeTgt)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 638 | } |
| 639 | // Load kArg0 with method index |
| 640 | CHECK_EQ(cu->dex_file, target_method.dex_file); |
| 641 | cg->LoadConstant(cg->TargetReg(kArg0), target_method.dex_method_index); |
| 642 | return 1; |
| 643 | } |
| 644 | return -1; |
| 645 | } |
| 646 | |
| 647 | static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info, |
| 648 | int state, |
| 649 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 650 | uint32_t unused, uintptr_t unused2, |
| 651 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 652 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeStaticTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 653 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 654 | } |
| 655 | |
| 656 | static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, |
| 657 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 658 | uint32_t unused, uintptr_t unused2, |
| 659 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 660 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeDirectTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 661 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 662 | } |
| 663 | |
| 664 | static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, |
| 665 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 666 | uint32_t unused, uintptr_t unused2, |
| 667 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 668 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeSuperTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 669 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 670 | } |
| 671 | |
| 672 | static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, |
| 673 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 674 | uint32_t unused, uintptr_t unused2, |
| 675 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 676 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeVirtualTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 677 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 678 | } |
| 679 | |
| 680 | static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu, |
| 681 | CallInfo* info, int state, |
| 682 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 683 | uint32_t unused, uintptr_t unused2, |
| 684 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 685 | ThreadOffset<4> trampoline = |
| 686 | QUICK_ENTRYPOINT_OFFSET(4, pInvokeInterfaceTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 687 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 688 | } |
| 689 | |
| 690 | int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state, |
| 691 | NextCallInsn next_call_insn, |
| 692 | const MethodReference& target_method, |
| 693 | uint32_t vtable_idx, uintptr_t direct_code, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 694 | uintptr_t direct_method, InvokeType type, bool skip_this) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 695 | int last_arg_reg = TargetReg(kArg3).GetReg(); |
| 696 | int next_reg = TargetReg(kArg1).GetReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 697 | int next_arg = 0; |
| 698 | if (skip_this) { |
| 699 | next_reg++; |
| 700 | next_arg++; |
| 701 | } |
| 702 | for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) { |
| 703 | RegLocation rl_arg = info->args[next_arg++]; |
| 704 | rl_arg = UpdateRawLoc(rl_arg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 705 | if (rl_arg.wide && (next_reg <= TargetReg(kArg2).GetReg())) { |
| 706 | RegStorage r_tmp(RegStorage::k64BitPair, next_reg, next_reg + 1); |
| 707 | LoadValueDirectWideFixed(rl_arg, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 708 | next_reg++; |
| 709 | next_arg++; |
| 710 | } else { |
| 711 | if (rl_arg.wide) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 712 | rl_arg = NarrowRegLoc(rl_arg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 713 | rl_arg.is_const = false; |
| 714 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 715 | LoadValueDirectFixed(rl_arg, RegStorage::Solo32(next_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 716 | } |
| 717 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 718 | direct_code, direct_method, type); |
| 719 | } |
| 720 | return call_state; |
| 721 | } |
| 722 | |
| 723 | /* |
| 724 | * Load up to 5 arguments, the first three of which will be in |
| 725 | * kArg1 .. kArg3. On entry kArg0 contains the current method pointer, |
| 726 | * and as part of the load sequence, it must be replaced with |
| 727 | * the target method pointer. Note, this may also be called |
| 728 | * for "range" variants if the number of arguments is 5 or fewer. |
| 729 | */ |
| 730 | int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, |
| 731 | int call_state, LIR** pcrLabel, NextCallInsn next_call_insn, |
| 732 | const MethodReference& target_method, |
| 733 | uint32_t vtable_idx, uintptr_t direct_code, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 734 | uintptr_t direct_method, InvokeType type, bool skip_this) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 735 | RegLocation rl_arg; |
| 736 | |
| 737 | /* If no arguments, just return */ |
| 738 | if (info->num_arg_words == 0) |
| 739 | return call_state; |
| 740 | |
| 741 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 742 | direct_code, direct_method, type); |
| 743 | |
| 744 | DCHECK_LE(info->num_arg_words, 5); |
| 745 | if (info->num_arg_words > 3) { |
| 746 | int32_t next_use = 3; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 747 | // Detect special case of wide arg spanning arg3/arg4 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 748 | RegLocation rl_use0 = info->args[0]; |
| 749 | RegLocation rl_use1 = info->args[1]; |
| 750 | RegLocation rl_use2 = info->args[2]; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 751 | if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) && rl_use2.wide) { |
| 752 | RegStorage reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 753 | // Wide spans, we need the 2nd half of uses[2]. |
| 754 | rl_arg = UpdateLocWide(rl_use2); |
| 755 | if (rl_arg.location == kLocPhysReg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 756 | // NOTE: not correct for 64-bit core regs, but this needs rewriting for hard-float. |
| 757 | reg = rl_arg.reg.IsPair() ? rl_arg.reg.GetHigh() : rl_arg.reg.DoubleToHighSingle(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 758 | } else { |
| 759 | // kArg2 & rArg3 can safely be used here |
| 760 | reg = TargetReg(kArg3); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 761 | Load32Disp(TargetReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 762 | call_state = next_call_insn(cu_, info, call_state, target_method, |
| 763 | vtable_idx, direct_code, direct_method, type); |
| 764 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 765 | Store32Disp(TargetReg(kSp), (next_use + 1) * 4, reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 766 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 767 | direct_code, direct_method, type); |
| 768 | next_use++; |
| 769 | } |
| 770 | // Loop through the rest |
| 771 | while (next_use < info->num_arg_words) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 772 | RegStorage arg_reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 773 | rl_arg = info->args[next_use]; |
| 774 | rl_arg = UpdateRawLoc(rl_arg); |
| 775 | if (rl_arg.location == kLocPhysReg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 776 | arg_reg = rl_arg.reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 777 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 778 | arg_reg = rl_arg.wide ? RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3)) : |
| 779 | TargetReg(kArg2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 780 | if (rl_arg.wide) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 781 | LoadValueDirectWideFixed(rl_arg, arg_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 782 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 783 | LoadValueDirectFixed(rl_arg, arg_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 784 | } |
| 785 | call_state = next_call_insn(cu_, info, call_state, target_method, |
| 786 | vtable_idx, direct_code, direct_method, type); |
| 787 | } |
| 788 | int outs_offset = (next_use + 1) * 4; |
| 789 | if (rl_arg.wide) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 790 | StoreBaseDispWide(TargetReg(kSp), outs_offset, arg_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 791 | next_use += 2; |
| 792 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 793 | Store32Disp(TargetReg(kSp), outs_offset, arg_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 794 | next_use++; |
| 795 | } |
| 796 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 797 | direct_code, direct_method, type); |
| 798 | } |
| 799 | } |
| 800 | |
| 801 | call_state = LoadArgRegs(info, call_state, next_call_insn, |
| 802 | target_method, vtable_idx, direct_code, direct_method, |
| 803 | type, skip_this); |
| 804 | |
| 805 | if (pcrLabel) { |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 806 | if (Runtime::Current()->ExplicitNullChecks()) { |
| 807 | *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1), info->opt_flags); |
| 808 | } else { |
| 809 | *pcrLabel = nullptr; |
| 810 | // In lieu of generating a check for kArg1 being null, we need to |
| 811 | // perform a load when doing implicit checks. |
| 812 | RegStorage tmp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 813 | Load32Disp(TargetReg(kArg1), 0, tmp); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 814 | MarkPossibleNullPointerException(info->opt_flags); |
| 815 | FreeTemp(tmp); |
| 816 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 817 | } |
| 818 | return call_state; |
| 819 | } |
| 820 | |
| 821 | /* |
| 822 | * May have 0+ arguments (also used for jumbo). Note that |
| 823 | * source virtual registers may be in physical registers, so may |
| 824 | * need to be flushed to home location before copying. This |
| 825 | * applies to arg3 and above (see below). |
| 826 | * |
| 827 | * Two general strategies: |
| 828 | * If < 20 arguments |
| 829 | * Pass args 3-18 using vldm/vstm block copy |
| 830 | * Pass arg0, arg1 & arg2 in kArg1-kArg3 |
| 831 | * If 20+ arguments |
| 832 | * Pass args arg19+ using memcpy block copy |
| 833 | * Pass arg0, arg1 & arg2 in kArg1-kArg3 |
| 834 | * |
| 835 | */ |
| 836 | int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state, |
| 837 | LIR** pcrLabel, NextCallInsn next_call_insn, |
| 838 | const MethodReference& target_method, |
| 839 | uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 840 | InvokeType type, bool skip_this) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 841 | // If we can treat it as non-range (Jumbo ops will use range form) |
| 842 | if (info->num_arg_words <= 5) |
| 843 | return GenDalvikArgsNoRange(info, call_state, pcrLabel, |
| 844 | next_call_insn, target_method, vtable_idx, |
| 845 | direct_code, direct_method, type, skip_this); |
| 846 | /* |
| 847 | * First load the non-register arguments. Both forms expect all |
| 848 | * of the source arguments to be in their home frame location, so |
| 849 | * scan the s_reg names and flush any that have been promoted to |
| 850 | * frame backing storage. |
| 851 | */ |
| 852 | // Scan the rest of the args - if in phys_reg flush to memory |
| 853 | for (int next_arg = 0; next_arg < info->num_arg_words;) { |
| 854 | RegLocation loc = info->args[next_arg]; |
| 855 | if (loc.wide) { |
| 856 | loc = UpdateLocWide(loc); |
| 857 | if ((next_arg >= 2) && (loc.location == kLocPhysReg)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 858 | StoreBaseDispWide(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 859 | } |
| 860 | next_arg += 2; |
| 861 | } else { |
| 862 | loc = UpdateLoc(loc); |
| 863 | if ((next_arg >= 3) && (loc.location == kLocPhysReg)) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 864 | Store32Disp(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 865 | } |
| 866 | next_arg++; |
| 867 | } |
| 868 | } |
| 869 | |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 870 | // Logic below assumes that Method pointer is at offset zero from SP. |
| 871 | DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0); |
| 872 | |
| 873 | // The first 3 arguments are passed via registers. |
| 874 | // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either |
| 875 | // get size of uintptr_t or size of object reference according to model being used. |
| 876 | int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 877 | int start_offset = SRegOffset(info->args[3].s_reg_low); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 878 | int regs_left_to_pass_via_stack = info->num_arg_words - 3; |
| 879 | DCHECK_GT(regs_left_to_pass_via_stack, 0); |
| 880 | |
| 881 | if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) { |
| 882 | // Use vldm/vstm pair using kArg3 as a temp |
| 883 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 884 | direct_code, direct_method, type); |
| 885 | OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), start_offset); |
| 886 | LIR* ld = OpVldm(TargetReg(kArg3), regs_left_to_pass_via_stack); |
| 887 | // TUNING: loosen barrier |
| 888 | ld->u.m.def_mask = ENCODE_ALL; |
| 889 | SetMemRefType(ld, true /* is_load */, kDalvikReg); |
| 890 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 891 | direct_code, direct_method, type); |
| 892 | OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), 4 /* Method* */ + (3 * 4)); |
| 893 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 894 | direct_code, direct_method, type); |
| 895 | LIR* st = OpVstm(TargetReg(kArg3), regs_left_to_pass_via_stack); |
| 896 | SetMemRefType(st, false /* is_load */, kDalvikReg); |
| 897 | st->u.m.def_mask = ENCODE_ALL; |
| 898 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 899 | direct_code, direct_method, type); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 900 | } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 901 | int current_src_offset = start_offset; |
| 902 | int current_dest_offset = outs_offset; |
| 903 | |
| 904 | while (regs_left_to_pass_via_stack > 0) { |
| 905 | // This is based on the knowledge that the stack itself is 16-byte aligned. |
| 906 | bool src_is_16b_aligned = (current_src_offset & 0xF) == 0; |
| 907 | bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0; |
| 908 | size_t bytes_to_move; |
| 909 | |
| 910 | /* |
| 911 | * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a |
| 912 | * a 128-bit move because we won't get the chance to try to aligned. If there are more than |
| 913 | * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned. |
| 914 | * We do this because we could potentially do a smaller move to align. |
| 915 | */ |
| 916 | if (regs_left_to_pass_via_stack == 4 || |
| 917 | (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) { |
| 918 | // Moving 128-bits via xmm register. |
| 919 | bytes_to_move = sizeof(uint32_t) * 4; |
| 920 | |
| 921 | // Allocate a free xmm temp. Since we are working through the calling sequence, |
| 922 | // we expect to have an xmm temporary available. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 923 | RegStorage temp = AllocTempDouble(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 924 | DCHECK(temp.Valid()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 925 | |
| 926 | LIR* ld1 = nullptr; |
| 927 | LIR* ld2 = nullptr; |
| 928 | LIR* st1 = nullptr; |
| 929 | LIR* st2 = nullptr; |
| 930 | |
| 931 | /* |
| 932 | * The logic is similar for both loads and stores. If we have 16-byte alignment, |
| 933 | * do an aligned move. If we have 8-byte alignment, then do the move in two |
| 934 | * parts. This approach prevents possible cache line splits. Finally, fall back |
| 935 | * to doing an unaligned move. In most cases we likely won't split the cache |
| 936 | * line but we cannot prove it and thus take a conservative approach. |
| 937 | */ |
| 938 | bool src_is_8b_aligned = (current_src_offset & 0x7) == 0; |
| 939 | bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0; |
| 940 | |
| 941 | if (src_is_16b_aligned) { |
| 942 | ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovA128FP); |
| 943 | } else if (src_is_8b_aligned) { |
| 944 | ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovLo128FP); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 945 | ld2 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset + (bytes_to_move >> 1), |
| 946 | kMovHi128FP); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 947 | } else { |
| 948 | ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovU128FP); |
| 949 | } |
| 950 | |
| 951 | if (dest_is_16b_aligned) { |
| 952 | st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovA128FP); |
| 953 | } else if (dest_is_8b_aligned) { |
| 954 | st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovLo128FP); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 955 | st2 = OpMovMemReg(TargetReg(kSp), current_dest_offset + (bytes_to_move >> 1), |
| 956 | temp, kMovHi128FP); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 957 | } else { |
| 958 | st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovU128FP); |
| 959 | } |
| 960 | |
| 961 | // TODO If we could keep track of aliasing information for memory accesses that are wider |
| 962 | // than 64-bit, we wouldn't need to set up a barrier. |
| 963 | if (ld1 != nullptr) { |
| 964 | if (ld2 != nullptr) { |
| 965 | // For 64-bit load we can actually set up the aliasing information. |
| 966 | AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true); |
| 967 | AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true, true); |
| 968 | } else { |
| 969 | // Set barrier for 128-bit load. |
| 970 | SetMemRefType(ld1, true /* is_load */, kDalvikReg); |
| 971 | ld1->u.m.def_mask = ENCODE_ALL; |
| 972 | } |
| 973 | } |
| 974 | if (st1 != nullptr) { |
| 975 | if (st2 != nullptr) { |
| 976 | // For 64-bit store we can actually set up the aliasing information. |
| 977 | AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true); |
| 978 | AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false, true); |
| 979 | } else { |
| 980 | // Set barrier for 128-bit store. |
| 981 | SetMemRefType(st1, false /* is_load */, kDalvikReg); |
| 982 | st1->u.m.def_mask = ENCODE_ALL; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | // Free the temporary used for the data movement. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 987 | FreeTemp(temp); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 988 | } else { |
| 989 | // Moving 32-bits via general purpose register. |
| 990 | bytes_to_move = sizeof(uint32_t); |
| 991 | |
| 992 | // Instead of allocating a new temp, simply reuse one of the registers being used |
| 993 | // for argument passing. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 994 | RegStorage temp = TargetReg(kArg3); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 995 | |
| 996 | // Now load the argument VR and store to the outs. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 997 | Load32Disp(TargetReg(kSp), current_src_offset, temp); |
| 998 | Store32Disp(TargetReg(kSp), current_dest_offset, temp); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | current_src_offset += bytes_to_move; |
| 1002 | current_dest_offset += bytes_to_move; |
| 1003 | regs_left_to_pass_via_stack -= (bytes_to_move >> 2); |
| 1004 | } |
| 1005 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1006 | // Generate memcpy |
| 1007 | OpRegRegImm(kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset); |
| 1008 | OpRegRegImm(kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1009 | CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(4, pMemcpy), TargetReg(kArg0), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1010 | TargetReg(kArg1), (info->num_arg_words - 3) * 4, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1011 | } |
| 1012 | |
| 1013 | call_state = LoadArgRegs(info, call_state, next_call_insn, |
| 1014 | target_method, vtable_idx, direct_code, direct_method, |
| 1015 | type, skip_this); |
| 1016 | |
| 1017 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 1018 | direct_code, direct_method, type); |
| 1019 | if (pcrLabel) { |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1020 | if (Runtime::Current()->ExplicitNullChecks()) { |
| 1021 | *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1), info->opt_flags); |
| 1022 | } else { |
| 1023 | *pcrLabel = nullptr; |
| 1024 | // In lieu of generating a check for kArg1 being null, we need to |
| 1025 | // perform a load when doing implicit checks. |
| 1026 | RegStorage tmp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1027 | Load32Disp(TargetReg(kArg1), 0, tmp); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1028 | MarkPossibleNullPointerException(info->opt_flags); |
| 1029 | FreeTemp(tmp); |
| 1030 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1031 | } |
| 1032 | return call_state; |
| 1033 | } |
| 1034 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1035 | RegLocation Mir2Lir::InlineTarget(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1036 | RegLocation res; |
| 1037 | if (info->result.location == kLocInvalid) { |
| 1038 | res = GetReturn(false); |
| 1039 | } else { |
| 1040 | res = info->result; |
| 1041 | } |
| 1042 | return res; |
| 1043 | } |
| 1044 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1045 | RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1046 | RegLocation res; |
| 1047 | if (info->result.location == kLocInvalid) { |
| 1048 | res = GetReturnWide(false); |
| 1049 | } else { |
| 1050 | res = info->result; |
| 1051 | } |
| 1052 | return res; |
| 1053 | } |
| 1054 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1055 | bool Mir2Lir::GenInlinedCharAt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1056 | if (cu_->instruction_set == kMips) { |
| 1057 | // TODO - add Mips implementation |
| 1058 | return false; |
| 1059 | } |
| 1060 | // Location of reference to data array |
| 1061 | int value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1062 | // Location of count |
| 1063 | int count_offset = mirror::String::CountOffset().Int32Value(); |
| 1064 | // Starting offset within data array |
| 1065 | int offset_offset = mirror::String::OffsetOffset().Int32Value(); |
| 1066 | // Start of char data with array_ |
| 1067 | int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value(); |
| 1068 | |
| 1069 | RegLocation rl_obj = info->args[0]; |
| 1070 | RegLocation rl_idx = info->args[1]; |
| 1071 | rl_obj = LoadValue(rl_obj, kCoreReg); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1072 | // X86 wants to avoid putting a constant index into a register. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1073 | if (!((cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64)&& rl_idx.is_const)) { |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1074 | rl_idx = LoadValue(rl_idx, kCoreReg); |
| 1075 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1076 | RegStorage reg_max; |
| 1077 | GenNullCheck(rl_obj.reg, info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1078 | bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK)); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1079 | LIR* range_check_branch = nullptr; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1080 | RegStorage reg_off; |
| 1081 | RegStorage reg_ptr; |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1082 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1083 | reg_off = AllocTemp(); |
| 1084 | reg_ptr = AllocTemp(); |
| 1085 | if (range_check) { |
| 1086 | reg_max = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1087 | Load32Disp(rl_obj.reg, count_offset, reg_max); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 1088 | MarkPossibleNullPointerException(info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1089 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1090 | Load32Disp(rl_obj.reg, offset_offset, reg_off); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 1091 | MarkPossibleNullPointerException(info->opt_flags); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1092 | Load32Disp(rl_obj.reg, value_offset, reg_ptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1093 | if (range_check) { |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1094 | // Set up a slow path to allow retry in case of bounds violation */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1095 | OpRegReg(kOpCmp, rl_idx.reg, reg_max); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1096 | FreeTemp(reg_max); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1097 | range_check_branch = OpCondBranch(kCondUge, nullptr); |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 1098 | } |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1099 | OpRegImm(kOpAdd, reg_ptr, data_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1100 | } else { |
| 1101 | if (range_check) { |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1102 | // On x86, we can compare to memory directly |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1103 | // Set up a launch pad to allow retry in case of bounds violation */ |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1104 | if (rl_idx.is_const) { |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1105 | range_check_branch = OpCmpMemImmBranch( |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1106 | kCondUlt, RegStorage::InvalidReg(), rl_obj.reg, count_offset, |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1107 | mir_graph_->ConstantValue(rl_idx.orig_sreg), nullptr); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1108 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1109 | OpRegMem(kOpCmp, rl_idx.reg, rl_obj.reg, count_offset); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1110 | range_check_branch = OpCondBranch(kCondUge, nullptr); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1111 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1112 | } |
| 1113 | reg_off = AllocTemp(); |
| 1114 | reg_ptr = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1115 | Load32Disp(rl_obj.reg, offset_offset, reg_off); |
| 1116 | Load32Disp(rl_obj.reg, value_offset, reg_ptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1117 | } |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1118 | if (rl_idx.is_const) { |
| 1119 | OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg)); |
| 1120 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1121 | OpRegReg(kOpAdd, reg_off, rl_idx.reg); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1122 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1123 | FreeTemp(rl_obj.reg); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 1124 | if (rl_idx.location == kLocPhysReg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1125 | FreeTemp(rl_idx.reg); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1126 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1127 | RegLocation rl_dest = InlineTarget(info); |
| 1128 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1129 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1130 | LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg, 1, kUnsignedHalf); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1131 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 1132 | LoadBaseIndexedDisp(reg_ptr, reg_off, 1, data_offset, rl_result.reg, kUnsignedHalf, |
| 1133 | INVALID_SREG); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1134 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1135 | FreeTemp(reg_off); |
| 1136 | FreeTemp(reg_ptr); |
| 1137 | StoreValue(rl_dest, rl_result); |
| 1138 | if (range_check) { |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1139 | DCHECK(range_check_branch != nullptr); |
| 1140 | info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked. |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1141 | AddIntrinsicSlowPath(info, range_check_branch); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1142 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1143 | return true; |
| 1144 | } |
| 1145 | |
| 1146 | // Generates an inlined String.is_empty or String.length. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1147 | bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1148 | if (cu_->instruction_set == kMips) { |
| 1149 | // TODO - add Mips implementation |
| 1150 | return false; |
| 1151 | } |
| 1152 | // dst = src.length(); |
| 1153 | RegLocation rl_obj = info->args[0]; |
| 1154 | rl_obj = LoadValue(rl_obj, kCoreReg); |
| 1155 | RegLocation rl_dest = InlineTarget(info); |
| 1156 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1157 | GenNullCheck(rl_obj.reg, info->opt_flags); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1158 | Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 1159 | MarkPossibleNullPointerException(info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1160 | if (is_empty) { |
| 1161 | // dst = (dst == 0); |
| 1162 | if (cu_->instruction_set == kThumb2) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1163 | RegStorage t_reg = AllocTemp(); |
| 1164 | OpRegReg(kOpNeg, t_reg, rl_result.reg); |
| 1165 | OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1166 | } else { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1167 | DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1168 | OpRegImm(kOpSub, rl_result.reg, 1); |
| 1169 | OpRegImm(kOpLsr, rl_result.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | StoreValue(rl_dest, rl_result); |
| 1173 | return true; |
| 1174 | } |
| 1175 | |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1176 | bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) { |
| 1177 | if (cu_->instruction_set == kMips) { |
| 1178 | // TODO - add Mips implementation |
| 1179 | return false; |
| 1180 | } |
| 1181 | RegLocation rl_src_i = info->args[0]; |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1182 | RegLocation rl_dest = (size == k64) ? InlineTargetWide(info) : InlineTarget(info); // result reg |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1183 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1184 | if (size == k64) { |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1185 | RegLocation rl_i = LoadValueWide(rl_src_i, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1186 | RegStorage r_i_low = rl_i.reg.GetLow(); |
| 1187 | if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 1188 | // First REV shall clobber rl_result.reg.GetReg(), save the value in a temp for the second REV. |
Vladimir Marko | f246af2 | 2013-11-27 12:30:15 +0000 | [diff] [blame] | 1189 | r_i_low = AllocTemp(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1190 | OpRegCopy(r_i_low, rl_i.reg); |
Vladimir Marko | f246af2 | 2013-11-27 12:30:15 +0000 | [diff] [blame] | 1191 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1192 | OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh()); |
| 1193 | OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low); |
| 1194 | if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) { |
Vladimir Marko | f246af2 | 2013-11-27 12:30:15 +0000 | [diff] [blame] | 1195 | FreeTemp(r_i_low); |
| 1196 | } |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1197 | StoreValueWide(rl_dest, rl_result); |
| 1198 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1199 | DCHECK(size == k32 || size == kSignedHalf); |
| 1200 | OpKind op = (size == k32) ? kOpRev : kOpRevsh; |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1201 | RegLocation rl_i = LoadValue(rl_src_i, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1202 | OpRegReg(op, rl_result.reg, rl_i.reg); |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1203 | StoreValue(rl_dest, rl_result); |
| 1204 | } |
| 1205 | return true; |
| 1206 | } |
| 1207 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1208 | bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1209 | if (cu_->instruction_set == kMips) { |
| 1210 | // TODO - add Mips implementation |
| 1211 | return false; |
| 1212 | } |
| 1213 | RegLocation rl_src = info->args[0]; |
| 1214 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1215 | RegLocation rl_dest = InlineTarget(info); |
| 1216 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1217 | RegStorage sign_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1218 | // abs(x) = y<=x>>31, (x+y)^y. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1219 | OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31); |
| 1220 | OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg); |
| 1221 | OpRegReg(kOpXor, rl_result.reg, sign_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1222 | StoreValue(rl_dest, rl_result); |
| 1223 | return true; |
| 1224 | } |
| 1225 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1226 | bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1227 | if (cu_->instruction_set == kMips) { |
| 1228 | // TODO - add Mips implementation |
| 1229 | return false; |
| 1230 | } |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1231 | RegLocation rl_src = info->args[0]; |
| 1232 | rl_src = LoadValueWide(rl_src, kCoreReg); |
| 1233 | RegLocation rl_dest = InlineTargetWide(info); |
| 1234 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1235 | |
| 1236 | // If on x86 or if we would clobber a register needed later, just copy the source first. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1237 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64 || rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg()) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1238 | OpRegCopyWide(rl_result.reg, rl_src.reg); |
| 1239 | if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() && |
| 1240 | rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() && |
| 1241 | rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() && |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1242 | rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) { |
| 1243 | // Reuse source registers to avoid running out of temps. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1244 | FreeTemp(rl_src.reg); |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1245 | } |
| 1246 | rl_src = rl_result; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1247 | } |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1248 | |
| 1249 | // abs(x) = y<=x>>31, (x+y)^y. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1250 | RegStorage sign_reg = AllocTemp(); |
| 1251 | OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31); |
| 1252 | OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg); |
| 1253 | OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg); |
| 1254 | OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg); |
| 1255 | OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg); |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1256 | StoreValueWide(rl_dest, rl_result); |
| 1257 | return true; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1258 | } |
| 1259 | |
Yixin Shou | dbb17e3 | 2014-02-07 05:09:30 -0800 | [diff] [blame] | 1260 | bool Mir2Lir::GenInlinedAbsFloat(CallInfo* info) { |
| 1261 | if (cu_->instruction_set == kMips) { |
| 1262 | // TODO - add Mips implementation |
| 1263 | return false; |
| 1264 | } |
| 1265 | RegLocation rl_src = info->args[0]; |
| 1266 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1267 | RegLocation rl_dest = InlineTarget(info); |
| 1268 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1269 | OpRegRegImm(kOpAnd, rl_result.reg, rl_src.reg, 0x7fffffff); |
Yixin Shou | dbb17e3 | 2014-02-07 05:09:30 -0800 | [diff] [blame] | 1270 | StoreValue(rl_dest, rl_result); |
| 1271 | return true; |
| 1272 | } |
| 1273 | |
| 1274 | bool Mir2Lir::GenInlinedAbsDouble(CallInfo* info) { |
| 1275 | if (cu_->instruction_set == kMips) { |
| 1276 | // TODO - add Mips implementation |
| 1277 | return false; |
| 1278 | } |
| 1279 | RegLocation rl_src = info->args[0]; |
| 1280 | rl_src = LoadValueWide(rl_src, kCoreReg); |
| 1281 | RegLocation rl_dest = InlineTargetWide(info); |
| 1282 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1283 | OpRegCopyWide(rl_result.reg, rl_src.reg); |
| 1284 | OpRegImm(kOpAnd, rl_result.reg.GetHigh(), 0x7fffffff); |
Yixin Shou | dbb17e3 | 2014-02-07 05:09:30 -0800 | [diff] [blame] | 1285 | StoreValueWide(rl_dest, rl_result); |
| 1286 | return true; |
| 1287 | } |
| 1288 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1289 | bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1290 | if (cu_->instruction_set == kMips) { |
| 1291 | // TODO - add Mips implementation |
| 1292 | return false; |
| 1293 | } |
| 1294 | RegLocation rl_src = info->args[0]; |
| 1295 | RegLocation rl_dest = InlineTarget(info); |
| 1296 | StoreValue(rl_dest, rl_src); |
| 1297 | return true; |
| 1298 | } |
| 1299 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1300 | bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1301 | if (cu_->instruction_set == kMips) { |
| 1302 | // TODO - add Mips implementation |
| 1303 | return false; |
| 1304 | } |
| 1305 | RegLocation rl_src = info->args[0]; |
| 1306 | RegLocation rl_dest = InlineTargetWide(info); |
| 1307 | StoreValueWide(rl_dest, rl_src); |
| 1308 | return true; |
| 1309 | } |
| 1310 | |
| 1311 | /* |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1312 | * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1313 | * otherwise bails to standard library code. |
| 1314 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1315 | bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1316 | if (cu_->instruction_set == kMips) { |
| 1317 | // TODO - add Mips implementation |
| 1318 | return false; |
| 1319 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1320 | RegLocation rl_obj = info->args[0]; |
| 1321 | RegLocation rl_char = info->args[1]; |
| 1322 | if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) { |
| 1323 | // Code point beyond 0xFFFF. Punt to the real String.indexOf(). |
| 1324 | return false; |
| 1325 | } |
| 1326 | |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1327 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1328 | LockCallTemps(); // Using fixed registers |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1329 | RegStorage reg_ptr = TargetReg(kArg0); |
| 1330 | RegStorage reg_char = TargetReg(kArg1); |
| 1331 | RegStorage reg_start = TargetReg(kArg2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1332 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1333 | LoadValueDirectFixed(rl_obj, reg_ptr); |
| 1334 | LoadValueDirectFixed(rl_char, reg_char); |
| 1335 | if (zero_based) { |
| 1336 | LoadConstant(reg_start, 0); |
| 1337 | } else { |
buzbee | a44d4f5 | 2014-03-05 11:26:39 -0800 | [diff] [blame] | 1338 | RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1339 | LoadValueDirectFixed(rl_start, reg_start); |
| 1340 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1341 | RegStorage r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pIndexOf)); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1342 | GenExplicitNullCheck(reg_ptr, info->opt_flags); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1343 | LIR* high_code_point_branch = |
| 1344 | rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1345 | // NOTE: not a safepoint |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1346 | OpReg(kOpBlx, r_tgt); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1347 | if (!rl_char.is_const) { |
| 1348 | // Add the slow path for code points beyond 0xFFFF. |
| 1349 | DCHECK(high_code_point_branch != nullptr); |
| 1350 | LIR* resume_tgt = NewLIR0(kPseudoTargetLabel); |
| 1351 | info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1352 | AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1353 | } else { |
| 1354 | DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0); |
| 1355 | DCHECK(high_code_point_branch == nullptr); |
| 1356 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1357 | RegLocation rl_return = GetReturn(false); |
| 1358 | RegLocation rl_dest = InlineTarget(info); |
| 1359 | StoreValue(rl_dest, rl_return); |
| 1360 | return true; |
| 1361 | } |
| 1362 | |
| 1363 | /* Fast string.compareTo(Ljava/lang/string;)I. */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1364 | bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1365 | if (cu_->instruction_set == kMips) { |
| 1366 | // TODO - add Mips implementation |
| 1367 | return false; |
| 1368 | } |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1369 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1370 | LockCallTemps(); // Using fixed registers |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1371 | RegStorage reg_this = TargetReg(kArg0); |
| 1372 | RegStorage reg_cmp = TargetReg(kArg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1373 | |
| 1374 | RegLocation rl_this = info->args[0]; |
| 1375 | RegLocation rl_cmp = info->args[1]; |
| 1376 | LoadValueDirectFixed(rl_this, reg_this); |
| 1377 | LoadValueDirectFixed(rl_cmp, reg_cmp); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1378 | RegStorage r_tgt = (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) ? |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1379 | LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo)) : RegStorage::InvalidReg(); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1380 | GenExplicitNullCheck(reg_this, info->opt_flags); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1381 | info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1382 | // TUNING: check if rl_cmp.s_reg_low is already null checked |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1383 | LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr); |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1384 | AddIntrinsicSlowPath(info, cmp_null_check_branch); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1385 | // NOTE: not a safepoint |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1386 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1387 | OpReg(kOpBlx, r_tgt); |
| 1388 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1389 | OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1390 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1391 | RegLocation rl_return = GetReturn(false); |
| 1392 | RegLocation rl_dest = InlineTarget(info); |
| 1393 | StoreValue(rl_dest, rl_return); |
| 1394 | return true; |
| 1395 | } |
| 1396 | |
| 1397 | bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) { |
| 1398 | RegLocation rl_dest = InlineTarget(info); |
| 1399 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1400 | ThreadOffset<4> offset = Thread::PeerOffset<4>(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1401 | if (cu_->instruction_set == kThumb2 || cu_->instruction_set == kMips) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1402 | Load32Disp(TargetReg(kSelf), offset.Int32Value(), rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1403 | } else { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1404 | CHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 1405 | reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg, offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1406 | } |
| 1407 | StoreValue(rl_dest, rl_result); |
| 1408 | return true; |
| 1409 | } |
| 1410 | |
| 1411 | bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info, |
| 1412 | bool is_long, bool is_volatile) { |
| 1413 | if (cu_->instruction_set == kMips) { |
| 1414 | // TODO - add Mips implementation |
| 1415 | return false; |
| 1416 | } |
| 1417 | // Unused - RegLocation rl_src_unsafe = info->args[0]; |
| 1418 | RegLocation rl_src_obj = info->args[1]; // Object |
| 1419 | RegLocation rl_src_offset = info->args[2]; // long low |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1420 | rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3] |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1421 | RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1422 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1423 | RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg); |
| 1424 | RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg); |
| 1425 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1426 | if (is_long) { |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1427 | if (cu_->instruction_set == kX86) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 1428 | LoadBaseIndexedDisp(rl_object.reg, rl_offset.reg, 0, 0, rl_result.reg, k64, INVALID_SREG); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1429 | } else { |
| 1430 | RegStorage rl_temp_offset = AllocTemp(); |
| 1431 | OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg); |
| 1432 | LoadBaseDispWide(rl_temp_offset, 0, rl_result.reg, INVALID_SREG); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 1433 | FreeTemp(rl_temp_offset); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1434 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1435 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1436 | LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | if (is_volatile) { |
| 1440 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 1441 | // In this case, either a load or store may follow so we issue both barriers. |
| 1442 | GenMemBarrier(kLoadLoad); |
| 1443 | GenMemBarrier(kLoadStore); |
| 1444 | } |
| 1445 | |
| 1446 | if (is_long) { |
| 1447 | StoreValueWide(rl_dest, rl_result); |
| 1448 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1449 | StoreValue(rl_dest, rl_result); |
| 1450 | } |
| 1451 | return true; |
| 1452 | } |
| 1453 | |
| 1454 | bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long, |
| 1455 | bool is_object, bool is_volatile, bool is_ordered) { |
| 1456 | if (cu_->instruction_set == kMips) { |
| 1457 | // TODO - add Mips implementation |
| 1458 | return false; |
| 1459 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1460 | // Unused - RegLocation rl_src_unsafe = info->args[0]; |
| 1461 | RegLocation rl_src_obj = info->args[1]; // Object |
| 1462 | RegLocation rl_src_offset = info->args[2]; // long low |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1463 | rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3] |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1464 | RegLocation rl_src_value = info->args[4]; // value to store |
| 1465 | if (is_volatile || is_ordered) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1466 | // There might have been a store before this volatile one so insert StoreStore barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1467 | GenMemBarrier(kStoreStore); |
| 1468 | } |
| 1469 | RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg); |
| 1470 | RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg); |
| 1471 | RegLocation rl_value; |
| 1472 | if (is_long) { |
| 1473 | rl_value = LoadValueWide(rl_src_value, kCoreReg); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1474 | if (cu_->instruction_set == kX86) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 1475 | StoreBaseIndexedDisp(rl_object.reg, rl_offset.reg, 0, 0, rl_value.reg, k64, INVALID_SREG); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1476 | } else { |
| 1477 | RegStorage rl_temp_offset = AllocTemp(); |
| 1478 | OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg); |
| 1479 | StoreBaseDispWide(rl_temp_offset, 0, rl_value.reg); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 1480 | FreeTemp(rl_temp_offset); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1481 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1482 | } else { |
| 1483 | rl_value = LoadValue(rl_src_value, kCoreReg); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1484 | StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1485 | } |
Mark Mendell | df8ee2e | 2014-01-27 16:37:47 -0800 | [diff] [blame] | 1486 | |
| 1487 | // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame^] | 1488 | FreeTemp(rl_offset.reg); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1489 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1490 | if (is_volatile) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1491 | // A load might follow the volatile store so insert a StoreLoad barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1492 | GenMemBarrier(kStoreLoad); |
| 1493 | } |
| 1494 | if (is_object) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1495 | MarkGCCard(rl_value.reg, rl_object.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1496 | } |
| 1497 | return true; |
| 1498 | } |
| 1499 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1500 | void Mir2Lir::GenInvoke(CallInfo* info) { |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 1501 | if ((info->opt_flags & MIR_INLINED) != 0) { |
| 1502 | // Already inlined but we may still need the null check. |
| 1503 | if (info->type != kStatic && |
| 1504 | ((cu_->disable_opt & (1 << kNullCheckElimination)) != 0 || |
| 1505 | (info->opt_flags & MIR_IGNORE_NULL_CHECK) == 0)) { |
| 1506 | RegLocation rl_obj = LoadValue(info->args[0], kCoreReg); |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1507 | GenNullCheck(rl_obj.reg); |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 1508 | } |
| 1509 | return; |
| 1510 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1511 | DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr); |
| 1512 | if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file) |
| 1513 | ->GenIntrinsic(this, info)) { |
| 1514 | return; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1515 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1516 | GenInvokeNoInline(info); |
| 1517 | } |
| 1518 | |
| 1519 | void Mir2Lir::GenInvokeNoInline(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1520 | int call_state = 0; |
| 1521 | LIR* null_ck; |
| 1522 | LIR** p_null_ck = NULL; |
| 1523 | NextCallInsn next_call_insn; |
| 1524 | FlushAllRegs(); /* Everything to home location */ |
| 1525 | // Explicit register usage |
| 1526 | LockCallTemps(); |
| 1527 | |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1528 | const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir); |
| 1529 | cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags()); |
| 1530 | InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType()); |
| 1531 | info->type = static_cast<InvokeType>(method_info.GetSharpType()); |
| 1532 | bool fast_path = method_info.FastPath(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1533 | bool skip_this; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1534 | if (info->type == kInterface) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1535 | next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 1536 | skip_this = fast_path; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1537 | } else if (info->type == kDirect) { |
| 1538 | if (fast_path) { |
| 1539 | p_null_ck = &null_ck; |
| 1540 | } |
| 1541 | next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP; |
| 1542 | skip_this = false; |
| 1543 | } else if (info->type == kStatic) { |
| 1544 | next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP; |
| 1545 | skip_this = false; |
| 1546 | } else if (info->type == kSuper) { |
| 1547 | DCHECK(!fast_path); // Fast path is a direct call. |
| 1548 | next_call_insn = NextSuperCallInsnSP; |
| 1549 | skip_this = false; |
| 1550 | } else { |
| 1551 | DCHECK_EQ(info->type, kVirtual); |
| 1552 | next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP; |
| 1553 | skip_this = fast_path; |
| 1554 | } |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1555 | MethodReference target_method = method_info.GetTargetMethod(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1556 | if (!info->is_range) { |
| 1557 | call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1558 | next_call_insn, target_method, method_info.VTableIndex(), |
| 1559 | method_info.DirectCode(), method_info.DirectMethod(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1560 | original_type, skip_this); |
| 1561 | } else { |
| 1562 | call_state = GenDalvikArgsRange(info, call_state, p_null_ck, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1563 | next_call_insn, target_method, method_info.VTableIndex(), |
| 1564 | method_info.DirectCode(), method_info.DirectMethod(), |
| 1565 | original_type, skip_this); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1566 | } |
| 1567 | // Finish up any of the call sequence not interleaved in arg loading |
| 1568 | while (call_state >= 0) { |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1569 | call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(), |
| 1570 | method_info.DirectCode(), method_info.DirectMethod(), original_type); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1571 | } |
| 1572 | LIR* call_inst; |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1573 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1574 | call_inst = OpReg(kOpBlx, TargetReg(kInvokeTgt)); |
| 1575 | } else { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 1576 | if (fast_path) { |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1577 | if (method_info.DirectCode() == static_cast<uintptr_t>(-1)) { |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1578 | // We can have the linker fixup a call relative. |
| 1579 | call_inst = |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 1580 | reinterpret_cast<X86Mir2Lir*>(this)->CallWithLinkerFixup(target_method, info->type); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1581 | } else { |
| 1582 | call_inst = OpMem(kOpBlx, TargetReg(kArg0), |
| 1583 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value()); |
| 1584 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1585 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1586 | ThreadOffset<4> trampoline(-1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1587 | switch (info->type) { |
| 1588 | case kInterface: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1589 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeInterfaceTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1590 | break; |
| 1591 | case kDirect: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1592 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeDirectTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1593 | break; |
| 1594 | case kStatic: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1595 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeStaticTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | case kSuper: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1598 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeSuperTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1599 | break; |
| 1600 | case kVirtual: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1601 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeVirtualTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1602 | break; |
| 1603 | default: |
| 1604 | LOG(FATAL) << "Unexpected invoke type"; |
| 1605 | } |
| 1606 | call_inst = OpThreadMem(kOpBlx, trampoline); |
| 1607 | } |
| 1608 | } |
| 1609 | MarkSafepointPC(call_inst); |
| 1610 | |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1611 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1612 | if (info->result.location != kLocInvalid) { |
| 1613 | // We have a following MOVE_RESULT - do it now. |
| 1614 | if (info->result.wide) { |
| 1615 | RegLocation ret_loc = GetReturnWide(info->result.fp); |
| 1616 | StoreValueWide(info->result, ret_loc); |
| 1617 | } else { |
| 1618 | RegLocation ret_loc = GetReturn(info->result.fp); |
| 1619 | StoreValue(info->result, ret_loc); |
| 1620 | } |
| 1621 | } |
| 1622 | } |
| 1623 | |
| 1624 | } // namespace art |