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