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