blob: 422d82ffa23070d7af9b1b42737288fdfadfda30 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
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
Andreas Gampe0b9203e2015-01-22 20:39:27 -080017#include "mir_to_lir-inl.h"
18
Vladimir Markof4da6752014-08-01 19:04:18 +010019#include "arm/codegen_arm.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070020#include "dex/compiler_ir.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080021#include "dex/dex_flags.h"
22#include "dex/mir_graph.h"
Vladimir Marko5c96e6b2013-11-14 15:34:17 +000023#include "dex/quick/dex_file_method_inliner.h"
24#include "dex/quick/dex_file_to_method_inliner_map.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070025#include "dex_file-inl.h"
Andreas Gampe0b9203e2015-01-22 20:39:27 -080026#include "driver/compiler_driver.h"
Vladimir Marko20f85592015-03-19 10:07:02 +000027#include "driver/compiler_options.h"
Ian Rogers166db042013-07-26 12:05:57 -070028#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "invoke_type.h"
30#include "mirror/array.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070031#include "mirror/class-inl.h"
Fred Shih4ee7a662014-07-11 09:59:27 -070032#include "mirror/dex_cache.h"
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070033#include "mirror/object_array-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070034#include "mirror/string.h"
Vladimir Markof4da6752014-08-01 19:04:18 +010035#include "scoped_thread_state_change.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070036
37namespace art {
38
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070039// Shortcuts to repeatedly used long types.
40typedef mirror::ObjectArray<mirror::Object> ObjArray;
41
Brian Carlstrom7940e442013-07-12 13:46:57 -070042/*
43 * This source files contains "gen" codegen routines that should
44 * be applicable to most targets. Only mid-level support utilities
45 * and "op" calls may be used here.
46 */
47
Mingyao Yang3a74d152014-04-21 15:39:44 -070048void Mir2Lir::AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume) {
49 class IntrinsicSlowPathPath : public Mir2Lir::LIRSlowPath {
Vladimir Marko3bc86152014-03-13 14:11:28 +000050 public:
Andreas Gampe277ccbd2014-11-03 21:36:10 -080051 IntrinsicSlowPathPath(Mir2Lir* m2l, CallInfo* info_in, LIR* branch_in, LIR* resume_in)
Vladimir Marko0b40ecf2015-03-20 12:08:03 +000052 : LIRSlowPath(m2l, branch_in, resume_in), info_(info_in) {
53 DCHECK_EQ(info_in->offset, current_dex_pc_);
Vladimir Marko3bc86152014-03-13 14:11:28 +000054 }
55
56 void Compile() {
57 m2l_->ResetRegPool();
58 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -070059 GenerateTargetLabel(kPseudoIntrinsicRetry);
Vladimir Marko3bc86152014-03-13 14:11:28 +000060 // NOTE: GenInvokeNoInline() handles MarkSafepointPC.
61 m2l_->GenInvokeNoInline(info_);
62 if (cont_ != nullptr) {
63 m2l_->OpUnconditionalBranch(cont_);
64 }
65 }
66
67 private:
68 CallInfo* const info_;
69 };
70
Mingyao Yang3a74d152014-04-21 15:39:44 -070071 AddSlowPath(new (arena_) IntrinsicSlowPathPath(this, info, branch, resume));
Vladimir Marko3bc86152014-03-13 14:11:28 +000072}
73
Brian Carlstrom7940e442013-07-12 13:46:57 -070074/*
75 * To save scheduling time, helper calls are broken into two parts: generation of
Dave Allisond6ed6422014-04-09 23:36:15 +000076 * the helper target address, and the actual call to the helper. Because x86
77 * has a memory call operation, part 1 is a NOP for x86. For other targets,
78 * load arguments between the two parts.
Brian Carlstrom7940e442013-07-12 13:46:57 -070079 */
Andreas Gampe2f244e92014-05-08 03:35:25 -070080// template <size_t pointer_size>
Andreas Gampe98430592014-07-27 19:44:50 -070081RegStorage Mir2Lir::CallHelperSetup(QuickEntrypointEnum trampoline) {
Andreas Gampe2f244e92014-05-08 03:35:25 -070082 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
83 return RegStorage::InvalidReg();
84 } else {
Andreas Gampe98430592014-07-27 19:44:50 -070085 return LoadHelper(trampoline);
Andreas Gampe2f244e92014-05-08 03:35:25 -070086 }
87}
88
Andreas Gampe98430592014-07-27 19:44:50 -070089LIR* Mir2Lir::CallHelper(RegStorage r_tgt, QuickEntrypointEnum trampoline, bool safepoint_pc,
90 bool use_link) {
91 LIR* call_inst = InvokeTrampoline(use_link ? kOpBlx : kOpBx, r_tgt, trampoline);
Andreas Gampe2f244e92014-05-08 03:35:25 -070092
Andreas Gampe98430592014-07-27 19:44:50 -070093 if (r_tgt.Valid()) {
Dave Allisond6ed6422014-04-09 23:36:15 +000094 FreeTemp(r_tgt);
95 }
Andreas Gampe98430592014-07-27 19:44:50 -070096
Brian Carlstrom7940e442013-07-12 13:46:57 -070097 if (safepoint_pc) {
98 MarkSafepointPC(call_inst);
99 }
100 return call_inst;
101}
102
Andreas Gampe98430592014-07-27 19:44:50 -0700103void Mir2Lir::CallRuntimeHelper(QuickEntrypointEnum trampoline, bool safepoint_pc) {
104 RegStorage r_tgt = CallHelperSetup(trampoline);
Mingyao Yang42894562014-04-07 12:42:16 -0700105 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700106 CallHelper(r_tgt, trampoline, safepoint_pc);
Mingyao Yang42894562014-04-07 12:42:16 -0700107}
108
Andreas Gampe98430592014-07-27 19:44:50 -0700109void Mir2Lir::CallRuntimeHelperImm(QuickEntrypointEnum trampoline, int arg0, bool safepoint_pc) {
110 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700111 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000112 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700113 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114}
115
Andreas Gampe98430592014-07-27 19:44:50 -0700116void Mir2Lir::CallRuntimeHelperReg(QuickEntrypointEnum trampoline, RegStorage arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700117 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700118 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700119 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000120 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700121 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700122}
123
Andreas Gampe98430592014-07-27 19:44:50 -0700124void Mir2Lir::CallRuntimeHelperRegLocation(QuickEntrypointEnum trampoline, RegLocation arg0,
125 bool safepoint_pc) {
126 RegStorage r_tgt = CallHelperSetup(trampoline);
buzbee2700f7e2014-03-07 09:46:20 -0800127 if (arg0.wide == 0) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700128 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, arg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700130 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700131 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000132 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700133 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700134}
135
Andreas Gampe98430592014-07-27 19:44:50 -0700136void Mir2Lir::CallRuntimeHelperImmImm(QuickEntrypointEnum trampoline, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700137 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700138 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700139 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
140 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000141 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700142 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700143}
144
Andreas Gampe98430592014-07-27 19:44:50 -0700145void Mir2Lir::CallRuntimeHelperImmRegLocation(QuickEntrypointEnum trampoline, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700146 RegLocation arg1, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700147 RegStorage r_tgt = CallHelperSetup(trampoline);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 if (arg1.wide == 0) {
Andreas Gampef9872f02014-07-01 19:00:09 -0700149 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700150 } else {
Calin Juravlee460d1d2015-09-29 04:52:17 +0100151 RegStorage r_tmp = TargetReg(kArg2, kWide);
buzbee2700f7e2014-03-07 09:46:20 -0800152 LoadValueDirectWideFixed(arg1, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700153 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700154 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000155 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700156 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700157}
158
Andreas Gampe98430592014-07-27 19:44:50 -0700159void Mir2Lir::CallRuntimeHelperRegLocationImm(QuickEntrypointEnum trampoline, RegLocation arg0,
160 int arg1, bool safepoint_pc) {
161 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampef9872f02014-07-01 19:00:09 -0700162 DCHECK(!arg0.wide);
163 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
Andreas Gampeccc60262014-07-04 18:02:38 -0700164 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000165 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700166 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700167}
168
Andreas Gampe98430592014-07-27 19:44:50 -0700169void Mir2Lir::CallRuntimeHelperImmReg(QuickEntrypointEnum trampoline, int arg0, RegStorage arg1,
170 bool safepoint_pc) {
171 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700172 OpRegCopy(TargetReg(kArg1, arg1.GetWideKind()), arg1);
173 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000174 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700175 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700176}
177
Andreas Gampe98430592014-07-27 19:44:50 -0700178void Mir2Lir::CallRuntimeHelperRegImm(QuickEntrypointEnum trampoline, RegStorage arg0, int arg1,
179 bool safepoint_pc) {
180 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700181 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
182 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000183 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700184 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700185}
186
Andreas Gampe98430592014-07-27 19:44:50 -0700187void Mir2Lir::CallRuntimeHelperImmMethod(QuickEntrypointEnum trampoline, int arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700188 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700189 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700190 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
191 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000192 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700193 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700194}
195
Andreas Gampe98430592014-07-27 19:44:50 -0700196void Mir2Lir::CallRuntimeHelperRegMethod(QuickEntrypointEnum trampoline, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800197 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700198 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700199 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.GetWideKind()), arg0));
200 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
201 if (r_tmp.NotExactlyEquals(arg0)) {
202 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800203 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700204 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800205 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700206 CallHelper(r_tgt, trampoline, safepoint_pc);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800207}
208
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800209void Mir2Lir::CallRuntimeHelperRegRegLocationMethod(QuickEntrypointEnum trampoline, RegStorage arg0,
210 RegLocation arg1, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700211 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800212 DCHECK(!IsSameReg(TargetReg(kArg2, arg0.GetWideKind()), arg0));
Andreas Gampeccc60262014-07-04 18:02:38 -0700213 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
214 if (r_tmp.NotExactlyEquals(arg0)) {
215 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800216 }
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800217 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
218 LoadCurrMethodDirect(TargetReg(kArg2, kRef));
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800219 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700220 CallHelper(r_tgt, trampoline, safepoint_pc);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800221}
222
Andreas Gampe98430592014-07-27 19:44:50 -0700223void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(QuickEntrypointEnum trampoline,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700224 RegLocation arg0, RegLocation arg1,
225 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700226 RegStorage r_tgt = CallHelperSetup(trampoline);
Maja Gagic6ea651f2015-02-24 16:55:04 +0100227 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kMips64 ||
228 cu_->instruction_set == kX86_64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700229 RegStorage arg0_reg = TargetReg((arg0.fp) ? kFArg0 : kArg0, arg0);
230
231 RegStorage arg1_reg;
232 if (arg1.fp == arg0.fp) {
233 arg1_reg = TargetReg((arg1.fp) ? kFArg1 : kArg1, arg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700234 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700235 arg1_reg = TargetReg((arg1.fp) ? kFArg0 : kArg0, arg1);
236 }
237
238 if (arg0.wide == 0) {
239 LoadValueDirectFixed(arg0, arg0_reg);
240 } else {
241 LoadValueDirectWideFixed(arg0, arg0_reg);
242 }
243
244 if (arg1.wide == 0) {
245 LoadValueDirectFixed(arg1, arg1_reg);
246 } else {
247 LoadValueDirectWideFixed(arg1, arg1_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700248 }
249 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700250 DCHECK(!cu_->target64);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700251 if (arg0.wide == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700252 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700253 if (arg1.wide == 0) {
Douglas Leungf58c11c2015-02-13 16:53:03 -0800254 // For Mips, when the 1st arg is integral, then remaining arg are passed in core reg.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700255 if (cu_->instruction_set == kMips) {
Douglas Leungf58c11c2015-02-13 16:53:03 -0800256 LoadValueDirectFixed(arg1, TargetReg((arg1.fp && arg0.fp) ? kFArg2 : kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700257 } else {
Zheng Xu5667fdb2014-10-23 18:29:55 +0800258 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg1 : kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700259 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700260 } else {
Douglas Leungf58c11c2015-02-13 16:53:03 -0800261 // For Mips, when the 1st arg is integral, then remaining arg are passed in core reg.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700262 if (cu_->instruction_set == kMips) {
Douglas Leungf58c11c2015-02-13 16:53:03 -0800263 LoadValueDirectWideFixed(arg1, TargetReg((arg1.fp && arg0.fp) ? kFArg2 : kArg2, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700264 } else {
Zheng Xu5667fdb2014-10-23 18:29:55 +0800265 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg1 : kArg1, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700266 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700267 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700268 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700269 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700270 if (arg1.wide == 0) {
Douglas Leungf58c11c2015-02-13 16:53:03 -0800271 // For Mips, when the 1st arg is integral, then remaining arg are passed in core reg.
272 if (cu_->instruction_set == kMips) {
273 LoadValueDirectFixed(arg1, TargetReg((arg1.fp && arg0.fp) ? kFArg2 : kArg2, kNotWide));
274 } else {
275 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kNotWide));
276 }
Andreas Gampe4b537a82014-06-30 22:24:53 -0700277 } else {
Douglas Leungf58c11c2015-02-13 16:53:03 -0800278 // For Mips, when the 1st arg is integral, then remaining arg are passed in core reg.
279 if (cu_->instruction_set == kMips) {
280 LoadValueDirectWideFixed(arg1, TargetReg((arg1.fp && arg0.fp) ? kFArg2 : kArg2, kWide));
281 } else {
282 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kWide));
283 }
Andreas Gampe4b537a82014-06-30 22:24:53 -0700284 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700285 }
286 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000287 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700288 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700289}
290
Mingyao Yang80365d92014-04-18 12:10:58 -0700291void Mir2Lir::CopyToArgumentRegs(RegStorage arg0, RegStorage arg1) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700292 WideKind arg0_kind = arg0.GetWideKind();
293 WideKind arg1_kind = arg1.GetWideKind();
294 if (IsSameReg(arg1, TargetReg(kArg0, arg1_kind))) {
295 if (IsSameReg(arg0, TargetReg(kArg1, arg0_kind))) {
Mingyao Yang80365d92014-04-18 12:10:58 -0700296 // Swap kArg0 and kArg1 with kArg2 as temp.
Andreas Gampeccc60262014-07-04 18:02:38 -0700297 OpRegCopy(TargetReg(kArg2, arg1_kind), arg1);
298 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
299 OpRegCopy(TargetReg(kArg1, arg1_kind), TargetReg(kArg2, arg1_kind));
Mingyao Yang80365d92014-04-18 12:10:58 -0700300 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700301 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
302 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
Mingyao Yang80365d92014-04-18 12:10:58 -0700303 }
304 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700305 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
306 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
Mingyao Yang80365d92014-04-18 12:10:58 -0700307 }
308}
309
Andreas Gampe98430592014-07-27 19:44:50 -0700310void Mir2Lir::CallRuntimeHelperRegReg(QuickEntrypointEnum trampoline, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800311 RegStorage arg1, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700312 RegStorage r_tgt = CallHelperSetup(trampoline);
Mingyao Yang80365d92014-04-18 12:10:58 -0700313 CopyToArgumentRegs(arg0, arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000314 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700315 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700316}
317
Andreas Gampe98430592014-07-27 19:44:50 -0700318void Mir2Lir::CallRuntimeHelperRegRegImm(QuickEntrypointEnum trampoline, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800319 RegStorage arg1, int arg2, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700320 RegStorage r_tgt = CallHelperSetup(trampoline);
Mingyao Yang80365d92014-04-18 12:10:58 -0700321 CopyToArgumentRegs(arg0, arg1);
Andreas Gampeccc60262014-07-04 18:02:38 -0700322 LoadConstant(TargetReg(kArg2, kNotWide), arg2);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000323 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700324 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700325}
326
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800327void Mir2Lir::CallRuntimeHelperImmRegLocationMethod(QuickEntrypointEnum trampoline, int arg0,
328 RegLocation arg1, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700329 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800330 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
331 LoadCurrMethodDirect(TargetReg(kArg2, kRef));
Andreas Gampeccc60262014-07-04 18:02:38 -0700332 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000333 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700334 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700335}
336
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800337void Mir2Lir::CallRuntimeHelperImmImmMethod(QuickEntrypointEnum trampoline, int arg0, int arg1,
Andreas Gampe98430592014-07-27 19:44:50 -0700338 bool safepoint_pc) {
339 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe1cc7dba2014-12-17 18:43:01 -0800340 LoadCurrMethodDirect(TargetReg(kArg2, kRef));
341 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Andreas Gampeccc60262014-07-04 18:02:38 -0700342 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000343 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700344 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700345}
346
Andreas Gampe98430592014-07-27 19:44:50 -0700347void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(QuickEntrypointEnum trampoline, int arg0,
348 RegLocation arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700349 RegLocation arg2, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700350 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700351 DCHECK_EQ(static_cast<unsigned int>(arg1.wide), 0U); // The static_cast works around an
352 // instantiation bug in GCC.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700353 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700354 if (arg2.wide == 0) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700355 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700356 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700357 LoadValueDirectWideFixed(arg2, TargetReg(kArg2, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700358 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700359 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000360 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700361 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700362}
363
Andreas Gampeccc60262014-07-04 18:02:38 -0700364void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(
Andreas Gampe98430592014-07-27 19:44:50 -0700365 QuickEntrypointEnum trampoline,
Andreas Gampeccc60262014-07-04 18:02:38 -0700366 RegLocation arg0,
367 RegLocation arg1,
368 RegLocation arg2,
369 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700370 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700371 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
372 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
373 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000374 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700375 CallHelper(r_tgt, trampoline, safepoint_pc);
Ian Rogersa9a82542013-10-04 11:17:26 -0700376}
377
Jeff Hao848f70a2014-01-15 13:49:50 -0800378void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocationRegLocation(
379 QuickEntrypointEnum trampoline, RegLocation arg0, RegLocation arg1, RegLocation arg2,
380 RegLocation arg3, bool safepoint_pc) {
381 RegStorage r_tgt = CallHelperSetup(trampoline);
382 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
383 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
384 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
385 LoadValueDirectFixed(arg3, TargetReg(kArg3, arg3));
386 ClobberCallerSave();
387 CallHelper(r_tgt, trampoline, safepoint_pc);
388}
389
Brian Carlstrom7940e442013-07-12 13:46:57 -0700390/*
391 * If there are any ins passed in registers that have not been promoted
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100392 * to a callee-save register, flush them to the frame. Perform initial
Brian Carlstrom7940e442013-07-12 13:46:57 -0700393 * assignment of promoted arguments.
394 *
395 * ArgLocs is an array of location records describing the incoming arguments
396 * with one location record per word of argument.
397 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800398// TODO: Support 64-bit argument registers.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700399void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700400 /*
Mathieu Chartiere401d142015-04-22 13:56:20 -0700401 * Dummy up a RegLocation for the incoming ArtMethod*
Brian Carlstrom7940e442013-07-12 13:46:57 -0700402 * It will attempt to keep kArg0 live (or copy it to home location
403 * if promoted).
404 */
405 RegLocation rl_src = rl_method;
406 rl_src.location = kLocPhysReg;
Andreas Gampeccc60262014-07-04 18:02:38 -0700407 rl_src.reg = TargetReg(kArg0, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700408 rl_src.home = false;
buzbee091cc402014-03-31 10:14:40 -0700409 MarkLive(rl_src);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700410 if (cu_->target64) {
411 DCHECK(rl_method.wide);
412 StoreValueWide(rl_method, rl_src);
413 } else {
414 StoreValue(rl_method, rl_src);
415 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700416 // If Method* has been promoted, explicitly flush
417 if (rl_method.location == kLocPhysReg) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700418 StoreBaseDisp(TargetPtrReg(kSp), 0, rl_src.reg, kWord, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700419 }
420
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700421 if (mir_graph_->GetNumOfInVRs() == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700422 return;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800423 }
424
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700425 int start_vreg = mir_graph_->GetFirstInVR();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700426 /*
427 * Copy incoming arguments to their proper home locations.
428 * NOTE: an older version of dx had an issue in which
429 * it would reuse static method argument registers.
430 * This could result in the same Dalvik virtual register
431 * being promoted to both core and fp regs. To account for this,
432 * we only copy to the corresponding promoted physical register
433 * if it matches the type of the SSA name for the incoming
434 * argument. It is also possible that long and double arguments
435 * end up half-promoted. In those cases, we must flush the promoted
436 * half to memory as well.
437 */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100438 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600439 RegLocation* t_loc = nullptr;
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000440 EnsureInitializedArgMappingToPhysicalReg();
Serguei Katkov717a3e42014-11-13 17:19:42 +0600441 for (uint32_t i = 0; i < mir_graph_->GetNumOfInVRs(); i += t_loc->wide ? 2 : 1) {
442 // get reg corresponding to input
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000443 RegStorage reg = in_to_reg_storage_mapping_.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600444 t_loc = &ArgLocs[i];
445
446 // If the wide input appeared as single, flush it and go
447 // as it comes from memory.
448 if (t_loc->wide && reg.Valid() && !reg.Is64Bit()) {
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000449 // The memory already holds the half. Don't do anything.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600450 reg = RegStorage::InvalidReg();
451 }
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800452
buzbee2700f7e2014-03-07 09:46:20 -0800453 if (reg.Valid()) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600454 // If arriving in register.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700455
Serguei Katkov717a3e42014-11-13 17:19:42 +0600456 // We have already updated the arg location with promoted info
457 // so we can be based on it.
458 if (t_loc->location == kLocPhysReg) {
459 // Just copy it.
460 if (t_loc->wide) {
461 OpRegCopyWide(t_loc->reg, reg);
462 } else {
463 OpRegCopy(t_loc->reg, reg);
464 }
465 } else {
466 // Needs flush.
467 int offset = SRegOffset(start_vreg + i);
468 if (t_loc->ref) {
469 StoreRefDisp(TargetPtrReg(kSp), offset, reg, kNotVolatile);
470 } else {
471 StoreBaseDisp(TargetPtrReg(kSp), offset, reg, t_loc->wide ? k64 : k32, kNotVolatile);
buzbeed0a03b82013-09-14 08:21:05 -0700472 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700473 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700474 } else {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600475 // If arriving in frame & promoted.
476 if (t_loc->location == kLocPhysReg) {
477 int offset = SRegOffset(start_vreg + i);
478 if (t_loc->ref) {
479 LoadRefDisp(TargetPtrReg(kSp), offset, t_loc->reg, kNotVolatile);
480 } else {
481 LoadBaseDisp(TargetPtrReg(kSp), offset, t_loc->reg, t_loc->wide ? k64 : k32,
482 kNotVolatile);
483 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700484 }
485 }
486 }
487}
488
Andreas Gampeccc60262014-07-04 18:02:38 -0700489static void CommonCallCodeLoadThisIntoArg1(const CallInfo* info, Mir2Lir* cg) {
490 RegLocation rl_arg = info->args[0];
491 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1, kRef));
492}
493
494static void CommonCallCodeLoadClassIntoArg0(const CallInfo* info, Mir2Lir* cg) {
495 cg->GenNullCheck(cg->TargetReg(kArg1, kRef), info->opt_flags);
496 // get this->klass_ [use kArg1, set kArg0]
497 cg->LoadRefDisp(cg->TargetReg(kArg1, kRef), mirror::Object::ClassOffset().Int32Value(),
498 cg->TargetReg(kArg0, kRef),
499 kNotVolatile);
500 cg->MarkPossibleNullPointerException(info->opt_flags);
501}
502
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700503static bool CommonCallCodeLoadCodePointerIntoInvokeTgt(const RegStorage* alt_from,
Andreas Gampeccc60262014-07-04 18:02:38 -0700504 const CompilationUnit* cu, Mir2Lir* cg) {
505 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700506 int32_t offset = ArtMethod::EntryPointFromQuickCompiledCodeOffset(
Mathieu Chartier2d721012014-11-10 11:08:06 -0800507 InstructionSetPointerSize(cu->instruction_set)).Int32Value();
Andreas Gampeccc60262014-07-04 18:02:38 -0700508 // Get the compiled code address [use *alt_from or kArg0, set kInvokeTgt]
Mathieu Chartier2d721012014-11-10 11:08:06 -0800509 cg->LoadWordDisp(alt_from == nullptr ? cg->TargetReg(kArg0, kRef) : *alt_from, offset,
Andreas Gampeccc60262014-07-04 18:02:38 -0700510 cg->TargetPtrReg(kInvokeTgt));
511 return true;
512 }
513 return false;
514}
515
Brian Carlstrom7940e442013-07-12 13:46:57 -0700516/*
517 * Bit of a hack here - in the absence of a real scheduling pass,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700518 * emit the next instruction in a virtual invoke sequence.
519 * We can use kLr as a temp prior to target address loading
520 * Note also that we'll load the first argument ("this") into
Serguei Katkov717a3e42014-11-13 17:19:42 +0600521 * kArg1 here rather than the standard GenDalvikArgs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700522 */
523static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100524 int state, const MethodReference& target_method ATTRIBUTE_UNUSED,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700525 uint32_t method_idx, uintptr_t, uintptr_t,
526 InvokeType) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700527 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
528 /*
529 * This is the fast path in which the target virtual method is
530 * fully resolved at compile time.
531 */
532 switch (state) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700533 case 0:
534 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Brian Carlstrom7940e442013-07-12 13:46:57 -0700535 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700536 case 1:
537 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
538 // Includes a null-check.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700539 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700540 case 2: {
541 // Get this->klass_.embedded_vtable[method_idx] [usr kArg0, set kArg0]
Mathieu Chartiere401d142015-04-22 13:56:20 -0700542 const size_t pointer_size = InstructionSetPointerSize(
543 cu->compiler_driver->GetInstructionSet());
544 int32_t offset = mirror::Class::EmbeddedVTableEntryOffset(
545 method_idx, pointer_size).Uint32Value();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700546 // Load target method from embedded vtable to kArg0 [use kArg0, set kArg0]
Mathieu Chartiere401d142015-04-22 13:56:20 -0700547 cg->LoadWordDisp(cg->TargetPtrReg(kArg0), offset, cg->TargetPtrReg(kArg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700548 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700549 }
550 case 3:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700551 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(nullptr, cu, cg)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700552 break; // kInvokeTgt := kArg0->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700553 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700554 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
555 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700556 default:
557 return -1;
558 }
559 return state + 1;
560}
561
562/*
Jeff Hao88474b42013-10-23 16:24:40 -0700563 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
564 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
565 * more than one interface method map to the same index. Note also that we'll load the first
Serguei Katkov717a3e42014-11-13 17:19:42 +0600566 * argument ("this") into kArg1 here rather than the standard GenDalvikArgs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700567 */
568static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
569 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700570 uint32_t method_idx, uintptr_t, uintptr_t, InvokeType) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700571 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700572
Jeff Hao88474b42013-10-23 16:24:40 -0700573 switch (state) {
574 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700575 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Andreas Gampeccc60262014-07-04 18:02:38 -0700576 cg->LoadConstant(cg->TargetReg(kHiddenArg, kNotWide), target_method.dex_method_index);
Mark Mendelld3703d82014-06-09 15:10:50 -0400577 if (cu->instruction_set == kX86) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700578 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg, kNotWide), cg->TargetReg(kHiddenArg, kNotWide));
Jeff Hao88474b42013-10-23 16:24:40 -0700579 }
580 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700581 case 1:
582 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Jeff Hao88474b42013-10-23 16:24:40 -0700583 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700584 case 2:
585 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
586 // Includes a null-check.
Jeff Hao88474b42013-10-23 16:24:40 -0700587 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700588 case 3: { // Get target method [use kInvokeTgt, set kArg0]
Mathieu Chartiere401d142015-04-22 13:56:20 -0700589 const size_t pointer_size = InstructionSetPointerSize(
590 cu->compiler_driver->GetInstructionSet());
591 int32_t offset = mirror::Class::EmbeddedImTableEntryOffset(
592 method_idx % mirror::Class::kImtSize, pointer_size).Uint32Value();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700593 // Load target method from embedded imtable to kArg0 [use kArg0, set kArg0]
Mathieu Chartiere401d142015-04-22 13:56:20 -0700594 cg->LoadWordDisp(cg->TargetPtrReg(kArg0), offset, cg->TargetPtrReg(kArg0));
Jeff Hao88474b42013-10-23 16:24:40 -0700595 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700596 }
597 case 4:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700598 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(nullptr, cu, cg)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700599 break; // kInvokeTgt := kArg0->entrypoint
Jeff Hao88474b42013-10-23 16:24:40 -0700600 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700601 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
602 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700603 default:
604 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700605 }
606 return state + 1;
607}
608
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100609static int NextInvokeInsnSP(CompilationUnit* cu,
610 CallInfo* info ATTRIBUTE_UNUSED,
611 QuickEntrypointEnum trampoline,
612 int state,
613 const MethodReference& target_method,
614 uint32_t method_idx ATTRIBUTE_UNUSED) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700615 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Andreas Gampe98430592014-07-27 19:44:50 -0700616
Brian Carlstrom7940e442013-07-12 13:46:57 -0700617 /*
618 * This handles the case in which the base method is not fully
619 * resolved at compile time, we bail to a runtime helper.
620 */
621 if (state == 0) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700622 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700623 // Load trampoline target
Andreas Gampe98430592014-07-27 19:44:50 -0700624 int32_t disp;
625 if (cu->target64) {
626 disp = GetThreadOffset<8>(trampoline).Int32Value();
627 } else {
628 disp = GetThreadOffset<4>(trampoline).Int32Value();
629 }
630 cg->LoadWordDisp(cg->TargetPtrReg(kSelf), disp, cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700631 }
632 // Load kArg0 with method index
633 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampeccc60262014-07-04 18:02:38 -0700634 cg->LoadConstant(cg->TargetReg(kArg0, kNotWide), target_method.dex_method_index);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700635 return 1;
636 }
637 return -1;
638}
639
640static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
641 int state,
642 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700643 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700644 return NextInvokeInsnSP(cu, info, kQuickInvokeStaticTrampolineWithAccessCheck, state,
645 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700646}
647
648static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
649 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700650 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700651 return NextInvokeInsnSP(cu, info, kQuickInvokeDirectTrampolineWithAccessCheck, state,
652 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700653}
654
655static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
656 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700657 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700658 return NextInvokeInsnSP(cu, info, kQuickInvokeSuperTrampolineWithAccessCheck, state,
659 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700660}
661
662static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
663 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700664 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700665 return NextInvokeInsnSP(cu, info, kQuickInvokeVirtualTrampolineWithAccessCheck, state,
666 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700667}
668
669static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
670 CallInfo* info, int state,
671 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700672 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700673 return NextInvokeInsnSP(cu, info, kQuickInvokeInterfaceTrampolineWithAccessCheck, state,
674 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700675}
676
Dave Allison69dfe512014-07-11 17:11:58 +0000677// Default implementation of implicit null pointer check.
678// Overridden by arch specific as necessary.
679void Mir2Lir::GenImplicitNullCheck(RegStorage reg, int opt_flags) {
680 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
681 return;
682 }
683 RegStorage tmp = AllocTemp();
684 Load32Disp(reg, 0, tmp);
685 MarkPossibleNullPointerException(opt_flags);
686 FreeTemp(tmp);
687}
688
Serguei Katkov717a3e42014-11-13 17:19:42 +0600689/**
690 * @brief Used to flush promoted registers if they are used as argument
691 * in an invocation.
692 * @param info the infromation about arguments for invocation.
693 * @param start the first argument we should start to look from.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700694 */
Serguei Katkov717a3e42014-11-13 17:19:42 +0600695void Mir2Lir::GenDalvikArgsFlushPromoted(CallInfo* info, int start) {
696 if (cu_->disable_opt & (1 << kPromoteRegs)) {
697 // This make sense only if promotion is enabled.
698 return;
699 }
700 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700701 // Scan the rest of the args - if in phys_reg flush to memory
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000702 for (size_t next_arg = start; next_arg < info->num_arg_words;) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700703 RegLocation loc = info->args[next_arg];
704 if (loc.wide) {
705 loc = UpdateLocWide(loc);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600706 if (loc.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700707 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700708 }
709 next_arg += 2;
710 } else {
711 loc = UpdateLoc(loc);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600712 if (loc.location == kLocPhysReg) {
713 if (loc.ref) {
714 StoreRefDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, kNotVolatile);
715 } else {
716 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k32,
717 kNotVolatile);
718 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700719 }
720 next_arg++;
721 }
722 }
Serguei Katkov717a3e42014-11-13 17:19:42 +0600723}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700724
Serguei Katkov717a3e42014-11-13 17:19:42 +0600725/**
726 * @brief Used to optimize the copying of VRs which are arguments of invocation.
727 * Please note that you should flush promoted registers first if you copy.
728 * If implementation does copying it may skip several of the first VRs but must copy
729 * till the end. Implementation must return the number of skipped VRs
730 * (it might be all VRs).
731 * @see GenDalvikArgsFlushPromoted
732 * @param info the information about arguments for invocation.
733 * @param first the first argument we should start to look from.
734 * @param count the number of remaining arguments we can handle.
735 * @return the number of arguments which we did not handle. Unhandled arguments
736 * must be attached to the first one.
737 */
738int Mir2Lir::GenDalvikArgsBulkCopy(CallInfo* info, int first, int count) {
739 // call is pretty expensive, let's use it if count is big.
740 if (count > 16) {
741 GenDalvikArgsFlushPromoted(info, first);
742 int start_offset = SRegOffset(info->args[first].s_reg_low);
743 int outs_offset = StackVisitor::GetOutVROffset(first, cu_->instruction_set);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800744
Andreas Gampeccc60262014-07-04 18:02:38 -0700745 OpRegRegImm(kOpAdd, TargetReg(kArg0, kRef), TargetPtrReg(kSp), outs_offset);
746 OpRegRegImm(kOpAdd, TargetReg(kArg1, kRef), TargetPtrReg(kSp), start_offset);
Andreas Gampe98430592014-07-27 19:44:50 -0700747 CallRuntimeHelperRegRegImm(kQuickMemcpy, TargetReg(kArg0, kRef), TargetReg(kArg1, kRef),
Serguei Katkov717a3e42014-11-13 17:19:42 +0600748 count * 4, false);
749 count = 0;
750 }
751 return count;
752}
753
754int Mir2Lir::GenDalvikArgs(CallInfo* info, int call_state,
755 LIR** pcrLabel, NextCallInsn next_call_insn,
756 const MethodReference& target_method,
757 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
758 InvokeType type, bool skip_this) {
759 // If no arguments, just return.
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000760 if (info->num_arg_words == 0u)
Serguei Katkov717a3e42014-11-13 17:19:42 +0600761 return call_state;
762
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000763 const size_t start_index = skip_this ? 1 : 0;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600764
765 // Get architecture dependent mapping between output VRs and physical registers
766 // basing on shorty of method to call.
767 InToRegStorageMapping in_to_reg_storage_mapping(arena_);
768 {
769 const char* target_shorty = mir_graph_->GetShortyFromMethodReference(target_method);
770 ShortyIterator shorty_iterator(target_shorty, type == kStatic);
771 in_to_reg_storage_mapping.Initialize(&shorty_iterator, GetResetedInToRegStorageMapper());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700772 }
773
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000774 size_t stack_map_start = std::max(in_to_reg_storage_mapping.GetEndMappedIn(), start_index);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600775 if ((stack_map_start < info->num_arg_words) && info->args[stack_map_start].high_word) {
776 // It is possible that the last mapped reg is 32 bit while arg is 64-bit.
777 // It will be handled together with low part mapped to register.
778 stack_map_start++;
779 }
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000780 size_t regs_left_to_pass_via_stack = info->num_arg_words - stack_map_start;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600781
782 // If it is a range case we can try to copy remaining VRs (not mapped to physical registers)
783 // using more optimal algorithm.
784 if (info->is_range && regs_left_to_pass_via_stack > 1) {
785 regs_left_to_pass_via_stack = GenDalvikArgsBulkCopy(info, stack_map_start,
786 regs_left_to_pass_via_stack);
787 }
788
789 // Now handle any remaining VRs mapped to stack.
790 if (in_to_reg_storage_mapping.HasArgumentsOnStack()) {
791 // Two temps but do not use kArg1, it might be this which we can skip.
792 // Separate single and wide - it can give some advantage.
793 RegStorage regRef = TargetReg(kArg3, kRef);
794 RegStorage regSingle = TargetReg(kArg3, kNotWide);
795 RegStorage regWide = TargetReg(kArg2, kWide);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000796 for (size_t i = start_index; i < stack_map_start + regs_left_to_pass_via_stack; i++) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600797 RegLocation rl_arg = info->args[i];
798 rl_arg = UpdateRawLoc(rl_arg);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000799 RegStorage reg = in_to_reg_storage_mapping.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600800 if (!reg.Valid()) {
801 int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
802 {
803 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
804 if (rl_arg.wide) {
805 if (rl_arg.location == kLocPhysReg) {
806 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k64, kNotVolatile);
807 } else {
808 LoadValueDirectWideFixed(rl_arg, regWide);
809 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regWide, k64, kNotVolatile);
810 }
811 } else {
812 if (rl_arg.location == kLocPhysReg) {
813 if (rl_arg.ref) {
814 StoreRefDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, kNotVolatile);
815 } else {
816 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k32, kNotVolatile);
817 }
818 } else {
819 if (rl_arg.ref) {
820 LoadValueDirectFixed(rl_arg, regRef);
821 StoreRefDisp(TargetPtrReg(kSp), out_offset, regRef, kNotVolatile);
822 } else {
823 LoadValueDirectFixed(rl_arg, regSingle);
824 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regSingle, k32, kNotVolatile);
825 }
826 }
827 }
828 }
829 call_state = next_call_insn(cu_, info, call_state, target_method,
830 vtable_idx, direct_code, direct_method, type);
831 }
832 if (rl_arg.wide) {
833 i++;
834 }
835 }
836 }
837
838 // Finish with VRs mapped to physical registers.
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000839 for (size_t i = start_index; i < stack_map_start; i++) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600840 RegLocation rl_arg = info->args[i];
841 rl_arg = UpdateRawLoc(rl_arg);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000842 RegStorage reg = in_to_reg_storage_mapping.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600843 if (reg.Valid()) {
844 if (rl_arg.wide) {
845 // if reg is not 64-bit (it is half of 64-bit) then handle it separately.
846 if (!reg.Is64Bit()) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600847 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
848 if (rl_arg.location == kLocPhysReg) {
849 int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000850 // Dump it to memory.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600851 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k64, kNotVolatile);
852 LoadBaseDisp(TargetPtrReg(kSp), out_offset, reg, k32, kNotVolatile);
853 } else {
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000854 int high_offset = StackVisitor::GetOutVROffset(i + 1, cu_->instruction_set);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600855 // First, use target reg for high part.
856 LoadBaseDisp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low + 1), reg, k32,
857 kNotVolatile);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000858 StoreBaseDisp(TargetPtrReg(kSp), high_offset, reg, k32, kNotVolatile);
859 // Now, use target reg for low part.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600860 LoadBaseDisp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low), reg, k32, kNotVolatile);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000861 int low_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
862 // And store it to the expected memory location.
863 StoreBaseDisp(TargetPtrReg(kSp), low_offset, reg, k32, kNotVolatile);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600864 }
865 } else {
866 LoadValueDirectWideFixed(rl_arg, reg);
867 }
868 } else {
869 LoadValueDirectFixed(rl_arg, reg);
870 }
871 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
872 direct_code, direct_method, type);
873 }
874 if (rl_arg.wide) {
875 i++;
876 }
877 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700878
879 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
880 direct_code, direct_method, type);
881 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +0000882 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700883 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700884 } else {
885 *pcrLabel = nullptr;
Dave Allison69dfe512014-07-11 17:11:58 +0000886 GenImplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700887 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700888 }
889 return call_state;
890}
891
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000892void Mir2Lir::EnsureInitializedArgMappingToPhysicalReg() {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600893 if (!in_to_reg_storage_mapping_.IsInitialized()) {
894 ShortyIterator shorty_iterator(cu_->shorty, cu_->invoke_type == kStatic);
895 in_to_reg_storage_mapping_.Initialize(&shorty_iterator, GetResetedInToRegStorageMapper());
896 }
Serguei Katkov717a3e42014-11-13 17:19:42 +0600897}
898
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700899RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700900 RegLocation res;
901 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -0700902 // If result is unused, return a sink target based on type of invoke target.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800903 res = GetReturn(
904 ShortyToRegClass(mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700905 } else {
906 res = info->result;
907 }
908 return res;
909}
910
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700911RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700912 RegLocation res;
913 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -0700914 // If result is unused, return a sink target based on type of invoke target.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800915 res = GetReturnWide(ShortyToRegClass(
916 mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700917 } else {
918 res = info->result;
919 }
920 return res;
921}
922
Mathieu Chartiercd48f2d2014-09-09 13:51:09 -0700923bool Mir2Lir::GenInlinedReferenceGetReferent(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +0100924 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
925 // TODO: add Mips and Mips64 implementations.
Fred Shih4ee7a662014-07-11 09:59:27 -0700926 return false;
927 }
928
Fred Shih4ee7a662014-07-11 09:59:27 -0700929 bool use_direct_type_ptr;
930 uintptr_t direct_type_ptr;
Fred Shihe7f82e22014-08-06 10:46:37 -0700931 ClassReference ref;
932 if (!cu_->compiler_driver->CanEmbedReferenceTypeInCode(&ref,
933 &use_direct_type_ptr, &direct_type_ptr)) {
934 return false;
935 }
936
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700937 RegStorage reg_class = TargetReg(kArg1, kRef);
938 Clobber(reg_class);
939 LockTemp(reg_class);
Fred Shih4ee7a662014-07-11 09:59:27 -0700940 if (use_direct_type_ptr) {
941 LoadConstant(reg_class, direct_type_ptr);
Alex Lighteb76e112014-07-29 15:22:40 -0700942 } else {
Fred Shihe7f82e22014-08-06 10:46:37 -0700943 uint16_t type_idx = ref.first->GetClassDef(ref.second).class_idx_;
944 LoadClassType(*ref.first, type_idx, kArg1);
Fred Shih4ee7a662014-07-11 09:59:27 -0700945 }
Fred Shih4ee7a662014-07-11 09:59:27 -0700946
Fred Shihe7f82e22014-08-06 10:46:37 -0700947 uint32_t slow_path_flag_offset = cu_->compiler_driver->GetReferenceSlowFlagOffset();
948 uint32_t disable_flag_offset = cu_->compiler_driver->GetReferenceDisableFlagOffset();
Fred Shih4ee7a662014-07-11 09:59:27 -0700949 CHECK(slow_path_flag_offset && disable_flag_offset &&
950 (slow_path_flag_offset != disable_flag_offset));
951
952 // intrinsic logic start.
953 RegLocation rl_obj = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -0700954 rl_obj = LoadValue(rl_obj, kRefReg);
Fred Shih4ee7a662014-07-11 09:59:27 -0700955
956 RegStorage reg_slow_path = AllocTemp();
957 RegStorage reg_disabled = AllocTemp();
Andreas Gampef6815702015-01-20 09:53:48 -0800958 LoadBaseDisp(reg_class, slow_path_flag_offset, reg_slow_path, kSignedByte, kNotVolatile);
959 LoadBaseDisp(reg_class, disable_flag_offset, reg_disabled, kSignedByte, kNotVolatile);
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700960 FreeTemp(reg_class);
961 LIR* or_inst = OpRegRegReg(kOpOr, reg_slow_path, reg_slow_path, reg_disabled);
Fred Shih4ee7a662014-07-11 09:59:27 -0700962 FreeTemp(reg_disabled);
963
964 // if slow path, jump to JNI path target
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700965 LIR* slow_path_branch;
966 if (or_inst->u.m.def_mask->HasBit(ResourceMask::kCCode)) {
967 // Generate conditional branch only, as the OR set a condition state (we are interested in a 'Z' flag).
968 slow_path_branch = OpCondBranch(kCondNe, nullptr);
969 } else {
970 // Generate compare and branch.
971 slow_path_branch = OpCmpImmBranch(kCondNe, reg_slow_path, 0, nullptr);
972 }
Fred Shih4ee7a662014-07-11 09:59:27 -0700973 FreeTemp(reg_slow_path);
974
975 // slow path not enabled, simply load the referent of the reference object
976 RegLocation rl_dest = InlineTarget(info);
977 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
978 GenNullCheck(rl_obj.reg, info->opt_flags);
979 LoadRefDisp(rl_obj.reg, mirror::Reference::ReferentOffset().Int32Value(), rl_result.reg,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700980 kNotVolatile);
Fred Shih4ee7a662014-07-11 09:59:27 -0700981 MarkPossibleNullPointerException(info->opt_flags);
982 StoreValue(rl_dest, rl_result);
983
984 LIR* intrinsic_finish = NewLIR0(kPseudoTargetLabel);
985 AddIntrinsicSlowPath(info, slow_path_branch, intrinsic_finish);
Serguei Katkov9863daf2014-09-04 15:21:32 +0700986 ClobberCallerSave(); // We must clobber everything because slow path will return here
Fred Shih4ee7a662014-07-11 09:59:27 -0700987 return true;
988}
989
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700990bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Jeff Hao848f70a2014-01-15 13:49:50 -0800991 // Location of char array data
Brian Carlstrom7940e442013-07-12 13:46:57 -0700992 int value_offset = mirror::String::ValueOffset().Int32Value();
993 // Location of count
994 int count_offset = mirror::String::CountOffset().Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700995
996 RegLocation rl_obj = info->args[0];
997 RegLocation rl_idx = info->args[1];
buzbeea0cd2d72014-06-01 09:33:49 -0700998 rl_obj = LoadValue(rl_obj, kRefReg);
Andreas Gampe98430592014-07-27 19:44:50 -0700999 rl_idx = LoadValue(rl_idx, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -08001000 RegStorage reg_max;
1001 GenNullCheck(rl_obj.reg, info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001002 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001003 LIR* range_check_branch = nullptr;
Andreas Gampe98430592014-07-27 19:44:50 -07001004 if (range_check) {
1005 reg_max = AllocTemp();
1006 Load32Disp(rl_obj.reg, count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -08001007 MarkPossibleNullPointerException(info->opt_flags);
Jeff Hao848f70a2014-01-15 13:49:50 -08001008 // Set up a slow path to allow retry in case of bounds violation
Andreas Gampe98430592014-07-27 19:44:50 -07001009 OpRegReg(kOpCmp, rl_idx.reg, reg_max);
1010 FreeTemp(reg_max);
1011 range_check_branch = OpCondBranch(kCondUge, nullptr);
1012 }
Jeff Hao848f70a2014-01-15 13:49:50 -08001013 RegStorage reg_ptr = AllocTempRef();
1014 OpRegRegImm(kOpAdd, reg_ptr, rl_obj.reg, value_offset);
buzbee2700f7e2014-03-07 09:46:20 -08001015 FreeTemp(rl_obj.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001016 RegLocation rl_dest = InlineTarget(info);
1017 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Jeff Hao848f70a2014-01-15 13:49:50 -08001018 LoadBaseIndexed(reg_ptr, rl_idx.reg, rl_result.reg, 1, kUnsignedHalf);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001019 FreeTemp(reg_ptr);
1020 StoreValue(rl_dest, rl_result);
1021 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001022 DCHECK(range_check_branch != nullptr);
1023 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001024 AddIntrinsicSlowPath(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001025 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001026 return true;
1027}
1028
Jeff Hao848f70a2014-01-15 13:49:50 -08001029bool Mir2Lir::GenInlinedStringGetCharsNoCheck(CallInfo* info) {
1030 if (cu_->instruction_set == kMips) {
1031 // TODO - add Mips implementation
1032 return false;
1033 }
1034 size_t char_component_size = Primitive::ComponentSize(Primitive::kPrimChar);
1035 // Location of data in char array buffer
1036 int data_offset = mirror::Array::DataOffset(char_component_size).Int32Value();
1037 // Location of char array data in string
1038 int value_offset = mirror::String::ValueOffset().Int32Value();
1039
1040 RegLocation rl_obj = info->args[0];
1041 RegLocation rl_start = info->args[1];
1042 RegLocation rl_end = info->args[2];
1043 RegLocation rl_buffer = info->args[3];
1044 RegLocation rl_index = info->args[4];
1045
1046 ClobberCallerSave();
1047 LockCallTemps(); // Using fixed registers
1048 RegStorage reg_dst_ptr = TargetReg(kArg0, kRef);
1049 RegStorage reg_src_ptr = TargetReg(kArg1, kRef);
1050 RegStorage reg_length = TargetReg(kArg2, kNotWide);
1051 RegStorage reg_tmp = TargetReg(kArg3, kNotWide);
1052 RegStorage reg_tmp_ptr = RegStorage(RegStorage::k64BitSolo, reg_tmp.GetRawBits() & RegStorage::kRegTypeMask);
1053
1054 LoadValueDirectFixed(rl_buffer, reg_dst_ptr);
1055 OpRegImm(kOpAdd, reg_dst_ptr, data_offset);
1056 LoadValueDirectFixed(rl_index, reg_tmp);
1057 OpRegRegImm(kOpLsl, reg_tmp, reg_tmp, 1);
1058 OpRegReg(kOpAdd, reg_dst_ptr, cu_->instruction_set == kArm64 ? reg_tmp_ptr : reg_tmp);
1059
1060 LoadValueDirectFixed(rl_start, reg_tmp);
1061 LoadValueDirectFixed(rl_end, reg_length);
1062 OpRegReg(kOpSub, reg_length, reg_tmp);
1063 OpRegRegImm(kOpLsl, reg_length, reg_length, 1);
1064 LoadValueDirectFixed(rl_obj, reg_src_ptr);
1065
1066 OpRegImm(kOpAdd, reg_src_ptr, value_offset);
1067 OpRegRegImm(kOpLsl, reg_tmp, reg_tmp, 1);
1068 OpRegReg(kOpAdd, reg_src_ptr, cu_->instruction_set == kArm64 ? reg_tmp_ptr : reg_tmp);
1069
1070 RegStorage r_tgt;
1071 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
1072 r_tgt = LoadHelper(kQuickMemcpy);
1073 } else {
1074 r_tgt = RegStorage::InvalidReg();
1075 }
1076 // NOTE: not a safepoint
1077 CallHelper(r_tgt, kQuickMemcpy, false, true);
1078
1079 return true;
1080}
1081
Brian Carlstrom7940e442013-07-12 13:46:57 -07001082// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001083bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001084 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1085 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001086 return false;
1087 }
1088 // dst = src.length();
1089 RegLocation rl_obj = info->args[0];
buzbeea0cd2d72014-06-01 09:33:49 -07001090 rl_obj = LoadValue(rl_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001091 RegLocation rl_dest = InlineTarget(info);
1092 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001093 GenNullCheck(rl_obj.reg, info->opt_flags);
buzbee695d13a2014-04-19 13:32:20 -07001094 Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg);
Dave Allisonb373e092014-02-20 16:06:36 -08001095 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001096 if (is_empty) {
1097 // dst = (dst == 0);
1098 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001099 RegStorage t_reg = AllocTemp();
1100 OpRegReg(kOpNeg, t_reg, rl_result.reg);
1101 OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001102 } else if (cu_->instruction_set == kArm64) {
1103 OpRegImm(kOpSub, rl_result.reg, 1);
1104 OpRegRegImm(kOpLsr, rl_result.reg, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001105 } else {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001106 DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64);
buzbee2700f7e2014-03-07 09:46:20 -08001107 OpRegImm(kOpSub, rl_result.reg, 1);
1108 OpRegImm(kOpLsr, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001109 }
1110 }
1111 StoreValue(rl_dest, rl_result);
1112 return true;
1113}
1114
Jeff Hao848f70a2014-01-15 13:49:50 -08001115bool Mir2Lir::GenInlinedStringFactoryNewStringFromBytes(CallInfo* info) {
1116 if (cu_->instruction_set == kMips) {
1117 // TODO - add Mips implementation
1118 return false;
1119 }
1120 RegLocation rl_data = info->args[0];
1121 RegLocation rl_high = info->args[1];
1122 RegLocation rl_offset = info->args[2];
1123 RegLocation rl_count = info->args[3];
1124 rl_data = LoadValue(rl_data, kRefReg);
1125 LIR* data_null_check_branch = OpCmpImmBranch(kCondEq, rl_data.reg, 0, nullptr);
1126 AddIntrinsicSlowPath(info, data_null_check_branch);
1127 CallRuntimeHelperRegLocationRegLocationRegLocationRegLocation(
1128 kQuickAllocStringFromBytes, rl_data, rl_high, rl_offset, rl_count, true);
1129 RegLocation rl_return = GetReturn(kRefReg);
1130 RegLocation rl_dest = InlineTarget(info);
1131 StoreValue(rl_dest, rl_return);
1132 return true;
1133}
1134
1135bool Mir2Lir::GenInlinedStringFactoryNewStringFromChars(CallInfo* info) {
1136 if (cu_->instruction_set == kMips) {
1137 // TODO - add Mips implementation
1138 return false;
1139 }
1140 RegLocation rl_offset = info->args[0];
1141 RegLocation rl_count = info->args[1];
1142 RegLocation rl_data = info->args[2];
1143 CallRuntimeHelperRegLocationRegLocationRegLocation(
1144 kQuickAllocStringFromChars, rl_offset, rl_count, rl_data, true);
1145 RegLocation rl_return = GetReturn(kRefReg);
1146 RegLocation rl_dest = InlineTarget(info);
1147 StoreValue(rl_dest, rl_return);
1148 return true;
1149}
1150
1151bool Mir2Lir::GenInlinedStringFactoryNewStringFromString(CallInfo* info) {
1152 if (cu_->instruction_set == kMips) {
1153 // TODO - add Mips implementation
1154 return false;
1155 }
1156 RegLocation rl_string = info->args[0];
1157 rl_string = LoadValue(rl_string, kRefReg);
1158 LIR* string_null_check_branch = OpCmpImmBranch(kCondEq, rl_string.reg, 0, nullptr);
1159 AddIntrinsicSlowPath(info, string_null_check_branch);
1160 CallRuntimeHelperRegLocation(kQuickAllocStringFromString, rl_string, true);
1161 RegLocation rl_return = GetReturn(kRefReg);
1162 RegLocation rl_dest = InlineTarget(info);
1163 StoreValue(rl_dest, rl_return);
1164 return true;
1165}
1166
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001167bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001168 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1169 // TODO: add Mips and Mips64 implementations.
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001170 return false;
1171 }
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001172 RegLocation rl_dest = IsWide(size) ? InlineTargetWide(info) : InlineTarget(info); // result reg
1173 if (rl_dest.s_reg_low == INVALID_SREG) {
1174 // Result is unused, the code is dead. Inlining successful, no code generated.
1175 return true;
1176 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001177 RegLocation rl_src_i = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -07001178 RegLocation rl_i = IsWide(size) ? LoadValueWide(rl_src_i, kCoreReg) : LoadValue(rl_src_i, kCoreReg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001179 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Fred Shih37f05ef2014-07-16 18:38:08 -07001180 if (IsWide(size)) {
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001181 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Serban Constantinescu169489b2014-06-11 16:43:35 +01001182 OpRegReg(kOpRev, rl_result.reg, rl_i.reg);
1183 StoreValueWide(rl_dest, rl_result);
1184 return true;
1185 }
buzbee2700f7e2014-03-07 09:46:20 -08001186 RegStorage r_i_low = rl_i.reg.GetLow();
1187 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001188 // First REV shall clobber rl_result.reg.GetReg(), save the value in a temp for the second REV.
Vladimir Markof246af22013-11-27 12:30:15 +00001189 r_i_low = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -08001190 OpRegCopy(r_i_low, rl_i.reg);
Vladimir Markof246af22013-11-27 12:30:15 +00001191 }
buzbee2700f7e2014-03-07 09:46:20 -08001192 OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh());
1193 OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low);
1194 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001195 FreeTemp(r_i_low);
1196 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001197 StoreValueWide(rl_dest, rl_result);
1198 } else {
buzbee695d13a2014-04-19 13:32:20 -07001199 DCHECK(size == k32 || size == kSignedHalf);
1200 OpKind op = (size == k32) ? kOpRev : kOpRevsh;
buzbee2700f7e2014-03-07 09:46:20 -08001201 OpRegReg(op, rl_result.reg, rl_i.reg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001202 StoreValue(rl_dest, rl_result);
1203 }
1204 return true;
1205}
1206
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001207bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001208 RegLocation rl_dest = InlineTarget(info);
1209 if (rl_dest.s_reg_low == INVALID_SREG) {
1210 // Result is unused, the code is dead. Inlining successful, no code generated.
1211 return true;
1212 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001213 RegLocation rl_src = info->args[0];
1214 rl_src = LoadValue(rl_src, kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001215 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001216 RegStorage sign_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001217 // abs(x) = y<=x>>31, (x+y)^y.
buzbee2700f7e2014-03-07 09:46:20 -08001218 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31);
1219 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1220 OpRegReg(kOpXor, rl_result.reg, sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001221 StoreValue(rl_dest, rl_result);
1222 return true;
1223}
1224
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001225bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001226 RegLocation rl_dest = InlineTargetWide(info);
1227 if (rl_dest.s_reg_low == INVALID_SREG) {
1228 // Result is unused, the code is dead. Inlining successful, no code generated.
1229 return true;
1230 }
Vladimir Markob9823312014-03-20 17:38:43 +00001231 RegLocation rl_src = info->args[0];
1232 rl_src = LoadValueWide(rl_src, kCoreReg);
Vladimir Markob9823312014-03-20 17:38:43 +00001233 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1234
1235 // If on x86 or if we would clobber a register needed later, just copy the source first.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001236 if (cu_->instruction_set != kX86_64 &&
1237 (cu_->instruction_set == kX86 ||
1238 rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001239 OpRegCopyWide(rl_result.reg, rl_src.reg);
1240 if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() &&
1241 rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() &&
1242 rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() &&
Vladimir Markob9823312014-03-20 17:38:43 +00001243 rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) {
1244 // Reuse source registers to avoid running out of temps.
buzbee2700f7e2014-03-07 09:46:20 -08001245 FreeTemp(rl_src.reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001246 }
1247 rl_src = rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001248 }
Vladimir Markob9823312014-03-20 17:38:43 +00001249
1250 // abs(x) = y<=x>>31, (x+y)^y.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001251 RegStorage sign_reg;
1252 if (cu_->instruction_set == kX86_64) {
1253 sign_reg = AllocTempWide();
1254 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 63);
1255 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1256 OpRegReg(kOpXor, rl_result.reg, sign_reg);
1257 } else {
1258 sign_reg = AllocTemp();
1259 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31);
1260 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg);
1261 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg);
1262 OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg);
1263 OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg);
1264 }
buzbee082833c2014-05-17 23:16:26 -07001265 FreeTemp(sign_reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001266 StoreValueWide(rl_dest, rl_result);
1267 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001268}
1269
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001270bool Mir2Lir::GenInlinedReverseBits(CallInfo* info ATTRIBUTE_UNUSED, OpSize size ATTRIBUTE_UNUSED) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001271 // Currently implemented only for ARM64.
Serban Constantinescu23abec92014-07-02 16:13:38 +01001272 return false;
1273}
1274
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001275bool Mir2Lir::GenInlinedMinMaxFP(CallInfo* info ATTRIBUTE_UNUSED,
1276 bool is_min ATTRIBUTE_UNUSED,
1277 bool is_double ATTRIBUTE_UNUSED) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001278 // Currently implemented only for ARM64.
Serban Constantinescu23abec92014-07-02 16:13:38 +01001279 return false;
1280}
1281
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001282bool Mir2Lir::GenInlinedCeil(CallInfo* info ATTRIBUTE_UNUSED) {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001283 return false;
1284}
1285
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001286bool Mir2Lir::GenInlinedFloor(CallInfo* info ATTRIBUTE_UNUSED) {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001287 return false;
1288}
1289
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001290bool Mir2Lir::GenInlinedRint(CallInfo* info ATTRIBUTE_UNUSED) {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001291 return false;
1292}
1293
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001294bool Mir2Lir::GenInlinedRound(CallInfo* info ATTRIBUTE_UNUSED, bool is_double ATTRIBUTE_UNUSED) {
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001295 return false;
1296}
1297
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001298bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001299 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1300 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001301 return false;
1302 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001303 RegLocation rl_dest = InlineTarget(info);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001304 if (rl_dest.s_reg_low == INVALID_SREG) {
1305 // Result is unused, the code is dead. Inlining successful, no code generated.
1306 return true;
1307 }
1308 RegLocation rl_src = info->args[0];
Brian Carlstrom7940e442013-07-12 13:46:57 -07001309 StoreValue(rl_dest, rl_src);
1310 return true;
1311}
1312
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001313bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001314 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1315 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001316 return false;
1317 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001318 RegLocation rl_dest = InlineTargetWide(info);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001319 if (rl_dest.s_reg_low == INVALID_SREG) {
1320 // Result is unused, the code is dead. Inlining successful, no code generated.
1321 return true;
1322 }
1323 RegLocation rl_src = info->args[0];
Brian Carlstrom7940e442013-07-12 13:46:57 -07001324 StoreValueWide(rl_dest, rl_src);
1325 return true;
1326}
1327
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001328bool Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info ATTRIBUTE_UNUSED) {
DaniilSokolov70c4f062014-06-24 17:34:00 -07001329 return false;
1330}
1331
1332
Brian Carlstrom7940e442013-07-12 13:46:57 -07001333/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001334 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001335 * otherwise bails to standard library code.
1336 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001337bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001338 RegLocation rl_obj = info->args[0];
1339 RegLocation rl_char = info->args[1];
1340 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1341 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1342 return false;
1343 }
1344
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001345 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001346 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001347 RegStorage reg_ptr = TargetReg(kArg0, kRef);
1348 RegStorage reg_char = TargetReg(kArg1, kNotWide);
1349 RegStorage reg_start = TargetReg(kArg2, kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001350
Brian Carlstrom7940e442013-07-12 13:46:57 -07001351 LoadValueDirectFixed(rl_obj, reg_ptr);
1352 LoadValueDirectFixed(rl_char, reg_char);
1353 if (zero_based) {
1354 LoadConstant(reg_start, 0);
1355 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001356 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001357 LoadValueDirectFixed(rl_start, reg_start);
1358 }
Andreas Gampe98430592014-07-27 19:44:50 -07001359 RegStorage r_tgt = LoadHelper(kQuickIndexOf);
Dave Allisonf9439142014-03-27 15:10:22 -07001360 GenExplicitNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001361 LIR* high_code_point_branch =
1362 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001363 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001364 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001365 if (!rl_char.is_const) {
1366 // Add the slow path for code points beyond 0xFFFF.
1367 DCHECK(high_code_point_branch != nullptr);
1368 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1369 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001370 AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt);
Serguei Katkov9863daf2014-09-04 15:21:32 +07001371 ClobberCallerSave(); // We must clobber everything because slow path will return here
Vladimir Marko3bc86152014-03-13 14:11:28 +00001372 } else {
1373 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1374 DCHECK(high_code_point_branch == nullptr);
1375 }
buzbeea0cd2d72014-06-01 09:33:49 -07001376 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001377 RegLocation rl_dest = InlineTarget(info);
1378 StoreValue(rl_dest, rl_return);
1379 return true;
1380}
1381
1382/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001383bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001384 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1385 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001386 return false;
1387 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001388 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001389 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001390 RegStorage reg_this = TargetReg(kArg0, kRef);
1391 RegStorage reg_cmp = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001392
1393 RegLocation rl_this = info->args[0];
1394 RegLocation rl_cmp = info->args[1];
1395 LoadValueDirectFixed(rl_this, reg_this);
1396 LoadValueDirectFixed(rl_cmp, reg_cmp);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001397 RegStorage r_tgt;
1398 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Andreas Gampe98430592014-07-27 19:44:50 -07001399 r_tgt = LoadHelper(kQuickStringCompareTo);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001400 } else {
1401 r_tgt = RegStorage::InvalidReg();
1402 }
Dave Allisonf9439142014-03-27 15:10:22 -07001403 GenExplicitNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001404 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001405 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001406 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
Mingyao Yang3a74d152014-04-21 15:39:44 -07001407 AddIntrinsicSlowPath(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001408 // NOTE: not a safepoint
Andreas Gampe98430592014-07-27 19:44:50 -07001409 CallHelper(r_tgt, kQuickStringCompareTo, false, true);
buzbeea0cd2d72014-06-01 09:33:49 -07001410 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001411 RegLocation rl_dest = InlineTarget(info);
1412 StoreValue(rl_dest, rl_return);
1413 return true;
1414}
1415
1416bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1417 RegLocation rl_dest = InlineTarget(info);
Andreas Gampe7a949612014-07-08 11:03:59 -07001418
1419 // Early exit if the result is unused.
1420 if (rl_dest.orig_sreg < 0) {
1421 return true;
1422 }
1423
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001424 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001425
Mathieu Chartiere401d142015-04-22 13:56:20 -07001426 if (cu_->target64) {
Andreas Gamped500b532015-01-16 22:09:55 -08001427 LoadRefDisp(TargetPtrReg(kSelf), Thread::PeerOffset<8>().Int32Value(), rl_result.reg,
1428 kNotVolatile);
1429 } else {
1430 Load32Disp(TargetPtrReg(kSelf), Thread::PeerOffset<4>().Int32Value(), rl_result.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001431 }
Andreas Gamped500b532015-01-16 22:09:55 -08001432
Brian Carlstrom7940e442013-07-12 13:46:57 -07001433 StoreValue(rl_dest, rl_result);
1434 return true;
1435}
1436
1437bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
Vladimir Markofac10702015-04-22 11:51:52 +01001438 bool is_long, bool is_object, bool is_volatile) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001439 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1440 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001441 return false;
1442 }
1443 // Unused - RegLocation rl_src_unsafe = info->args[0];
1444 RegLocation rl_src_obj = info->args[1]; // Object
1445 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001446 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001447 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001448
buzbeea0cd2d72014-06-01 09:33:49 -07001449 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001450 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
Vladimir Markofac10702015-04-22 11:51:52 +01001451 RegLocation rl_result = EvalLoc(rl_dest, is_object ? kRefReg : kCoreReg, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001452 if (is_long) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001453 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1454 || cu_->instruction_set == kArm64) {
1455 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001456 } else {
1457 RegStorage rl_temp_offset = AllocTemp();
1458 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001459 LoadBaseDisp(rl_temp_offset, 0, rl_result.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001460 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001461 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001462 } else {
Matteo Franchin255e0142014-07-04 13:50:41 +01001463 if (rl_result.ref) {
1464 LoadRefIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0);
1465 } else {
1466 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32);
1467 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001468 }
1469
1470 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001471 GenMemBarrier(kLoadAny);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001472 }
1473
1474 if (is_long) {
1475 StoreValueWide(rl_dest, rl_result);
1476 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001477 StoreValue(rl_dest, rl_result);
1478 }
1479 return true;
1480}
1481
1482bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1483 bool is_object, bool is_volatile, bool is_ordered) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001484 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1485 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001486 return false;
1487 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001488 // Unused - RegLocation rl_src_unsafe = info->args[0];
1489 RegLocation rl_src_obj = info->args[1]; // Object
1490 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001491 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001492 RegLocation rl_src_value = info->args[4]; // value to store
1493 if (is_volatile || is_ordered) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001494 GenMemBarrier(kAnyStore);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001495 }
buzbeea0cd2d72014-06-01 09:33:49 -07001496 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001497 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1498 RegLocation rl_value;
1499 if (is_long) {
1500 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001501 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1502 || cu_->instruction_set == kArm64) {
1503 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001504 } else {
1505 RegStorage rl_temp_offset = AllocTemp();
1506 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001507 StoreBaseDisp(rl_temp_offset, 0, rl_value.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001508 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001509 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001510 } else {
Vladimir Markofac10702015-04-22 11:51:52 +01001511 rl_value = LoadValue(rl_src_value, is_object ? kRefReg : kCoreReg);
Matteo Franchin255e0142014-07-04 13:50:41 +01001512 if (rl_value.ref) {
1513 StoreRefIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0);
1514 } else {
1515 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32);
1516 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001517 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001518
1519 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
buzbee091cc402014-03-31 10:14:40 -07001520 FreeTemp(rl_offset.reg);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001521
Brian Carlstrom7940e442013-07-12 13:46:57 -07001522 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001523 // Prevent reordering with a subsequent volatile load.
1524 // May also be needed to address store atomicity issues.
1525 GenMemBarrier(kAnyAny);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001526 }
1527 if (is_object) {
Vladimir Marko743b98c2014-11-24 19:45:41 +00001528 MarkGCCard(0, rl_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001529 }
1530 return true;
1531}
1532
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001533void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001534 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Vladimir Marko87b7c522015-04-08 10:01:01 +01001535 if (mir_graph_->GetMethodLoweringInfo(info->mir).IsIntrinsic()) {
1536 const DexFile* dex_file = info->method_ref.dex_file;
1537 auto* inliner = cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(dex_file);
1538 if (inliner->GenIntrinsic(this, info)) {
1539 return;
1540 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001541 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001542 GenInvokeNoInline(info);
1543}
1544
1545void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001546 int call_state = 0;
1547 LIR* null_ck;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001548 LIR** p_null_ck = nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001549 NextCallInsn next_call_insn;
1550 FlushAllRegs(); /* Everything to home location */
1551 // Explicit register usage
1552 LockCallTemps();
1553
Vladimir Markof096aad2014-01-23 15:51:58 +00001554 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
Jeff Hao848f70a2014-01-15 13:49:50 -08001555 MethodReference target_method = method_info.GetTargetMethod();
Vladimir Markof096aad2014-01-23 15:51:58 +00001556 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
1557 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
Vladimir Markof4da6752014-08-01 19:04:18 +01001558 info->type = method_info.GetSharpType();
Jeff Hao848f70a2014-01-15 13:49:50 -08001559 bool is_string_init = false;
1560 if (method_info.IsSpecial()) {
1561 DexFileMethodInliner* inliner = cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(
1562 target_method.dex_file);
1563 if (inliner->IsStringInitMethodIndex(target_method.dex_method_index)) {
1564 is_string_init = true;
1565 size_t pointer_size = GetInstructionSetPointerSize(cu_->instruction_set);
1566 info->string_init_offset = inliner->GetOffsetForStringInit(target_method.dex_method_index,
1567 pointer_size);
1568 info->type = kStatic;
1569 }
1570 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001571 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001572 bool skip_this;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001573
Brian Carlstrom7940e442013-07-12 13:46:57 -07001574 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001575 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001576 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001577 } else if (info->type == kDirect) {
1578 if (fast_path) {
1579 p_null_ck = &null_ck;
1580 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001581 next_call_insn = fast_path ? GetNextSDCallInsn() : NextDirectCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001582 skip_this = false;
1583 } else if (info->type == kStatic) {
Vladimir Markof4da6752014-08-01 19:04:18 +01001584 next_call_insn = fast_path ? GetNextSDCallInsn() : NextStaticCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001585 skip_this = false;
1586 } else if (info->type == kSuper) {
1587 DCHECK(!fast_path); // Fast path is a direct call.
1588 next_call_insn = NextSuperCallInsnSP;
1589 skip_this = false;
1590 } else {
1591 DCHECK_EQ(info->type, kVirtual);
1592 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1593 skip_this = fast_path;
1594 }
Serguei Katkov717a3e42014-11-13 17:19:42 +06001595 call_state = GenDalvikArgs(info, call_state, p_null_ck,
1596 next_call_insn, target_method, method_info.VTableIndex(),
1597 method_info.DirectCode(), method_info.DirectMethod(),
1598 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001599 // Finish up any of the call sequence not interleaved in arg loading
1600 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001601 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001602 method_info.DirectCode(), method_info.DirectMethod(),
1603 original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001604 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001605 LIR* call_insn = GenCallInsn(method_info);
Vladimir Markof4da6752014-08-01 19:04:18 +01001606 MarkSafepointPC(call_insn);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001607
Vladimir Markobfe400b2014-12-19 19:27:26 +00001608 FreeCallTemps();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001609 if (info->result.location != kLocInvalid) {
1610 // We have a following MOVE_RESULT - do it now.
Jeff Hao848f70a2014-01-15 13:49:50 -08001611 RegisterClass reg_class = is_string_init ? kRefReg :
Vladimir Markofac10702015-04-22 11:51:52 +01001612 ShortyToRegClass(mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001613 if (info->result.wide) {
Vladimir Markofac10702015-04-22 11:51:52 +01001614 RegLocation ret_loc = GetReturnWide(reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001615 StoreValueWide(info->result, ret_loc);
1616 } else {
Vladimir Markofac10702015-04-22 11:51:52 +01001617 RegLocation ret_loc = GetReturn(reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001618 StoreValue(info->result, ret_loc);
1619 }
1620 }
1621}
1622
Brian Carlstrom7940e442013-07-12 13:46:57 -07001623} // namespace art