blob: 1f114cf336d0f9e15763effa27c4fa12177198fc [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 {
Andreas Gampeccc60262014-07-04 18:02:38 -0700151 RegStorage r_tmp = TargetReg(cu_->instruction_set == kMips ? kArg2 : kArg1, 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 Chartier3d21bdf2015-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 Chartier3d21bdf2015-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 Chartier3d21bdf2015-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 Chartier3d21bdf2015-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,
524 int state, const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700525 uint32_t method_idx, uintptr_t, uintptr_t,
526 InvokeType) {
527 UNUSED(target_method);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700528 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
529 /*
530 * This is the fast path in which the target virtual method is
531 * fully resolved at compile time.
532 */
533 switch (state) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700534 case 0:
535 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Brian Carlstrom7940e442013-07-12 13:46:57 -0700536 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700537 case 1:
538 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
539 // Includes a null-check.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700540 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700541 case 2: {
542 // Get this->klass_.embedded_vtable[method_idx] [usr kArg0, set kArg0]
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -0700543 const size_t pointer_size = InstructionSetPointerSize(
544 cu->compiler_driver->GetInstructionSet());
545 int32_t offset = mirror::Class::EmbeddedVTableEntryOffset(
546 method_idx, pointer_size).Uint32Value();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700547 // Load target method from embedded vtable to kArg0 [use kArg0, set kArg0]
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -0700548 cg->LoadWordDisp(cg->TargetPtrReg(kArg0), offset, cg->TargetPtrReg(kArg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700549 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700550 }
551 case 3:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700552 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(nullptr, cu, cg)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700553 break; // kInvokeTgt := kArg0->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700554 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700555 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
556 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700557 default:
558 return -1;
559 }
560 return state + 1;
561}
562
563/*
Jeff Hao88474b42013-10-23 16:24:40 -0700564 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
565 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
566 * 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 +0600567 * argument ("this") into kArg1 here rather than the standard GenDalvikArgs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700568 */
569static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
570 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700571 uint32_t method_idx, uintptr_t, uintptr_t, InvokeType) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700572 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700573
Jeff Hao88474b42013-10-23 16:24:40 -0700574 switch (state) {
575 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700576 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Andreas Gampeccc60262014-07-04 18:02:38 -0700577 cg->LoadConstant(cg->TargetReg(kHiddenArg, kNotWide), target_method.dex_method_index);
Mark Mendelld3703d82014-06-09 15:10:50 -0400578 if (cu->instruction_set == kX86) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700579 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg, kNotWide), cg->TargetReg(kHiddenArg, kNotWide));
Jeff Hao88474b42013-10-23 16:24:40 -0700580 }
581 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700582 case 1:
583 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Jeff Hao88474b42013-10-23 16:24:40 -0700584 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700585 case 2:
586 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
587 // Includes a null-check.
Jeff Hao88474b42013-10-23 16:24:40 -0700588 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700589 case 3: { // Get target method [use kInvokeTgt, set kArg0]
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -0700590 const size_t pointer_size = InstructionSetPointerSize(
591 cu->compiler_driver->GetInstructionSet());
592 int32_t offset = mirror::Class::EmbeddedImTableEntryOffset(
593 method_idx % mirror::Class::kImtSize, pointer_size).Uint32Value();
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700594 // Load target method from embedded imtable to kArg0 [use kArg0, set kArg0]
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -0700595 cg->LoadWordDisp(cg->TargetPtrReg(kArg0), offset, cg->TargetPtrReg(kArg0));
Jeff Hao88474b42013-10-23 16:24:40 -0700596 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700597 }
598 case 4:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700599 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(nullptr, cu, cg)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700600 break; // kInvokeTgt := kArg0->entrypoint
Jeff Hao88474b42013-10-23 16:24:40 -0700601 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700602 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
603 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700604 default:
605 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700606 }
607 return state + 1;
608}
609
Andreas Gampeccc60262014-07-04 18:02:38 -0700610static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info,
Andreas Gampe98430592014-07-27 19:44:50 -0700611 QuickEntrypointEnum trampoline, int state,
Andreas Gampeccc60262014-07-04 18:02:38 -0700612 const MethodReference& target_method, uint32_t method_idx) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700613 UNUSED(info, method_idx);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700614 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Andreas Gampe98430592014-07-27 19:44:50 -0700615
Brian Carlstrom7940e442013-07-12 13:46:57 -0700616 /*
617 * This handles the case in which the base method is not fully
618 * resolved at compile time, we bail to a runtime helper.
619 */
620 if (state == 0) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700621 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700622 // Load trampoline target
Andreas Gampe98430592014-07-27 19:44:50 -0700623 int32_t disp;
624 if (cu->target64) {
625 disp = GetThreadOffset<8>(trampoline).Int32Value();
626 } else {
627 disp = GetThreadOffset<4>(trampoline).Int32Value();
628 }
629 cg->LoadWordDisp(cg->TargetPtrReg(kSelf), disp, cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700630 }
631 // Load kArg0 with method index
632 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampeccc60262014-07-04 18:02:38 -0700633 cg->LoadConstant(cg->TargetReg(kArg0, kNotWide), target_method.dex_method_index);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700634 return 1;
635 }
636 return -1;
637}
638
639static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
640 int state,
641 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700642 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700643 return NextInvokeInsnSP(cu, info, kQuickInvokeStaticTrampolineWithAccessCheck, state,
644 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700645}
646
647static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
648 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700649 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700650 return NextInvokeInsnSP(cu, info, kQuickInvokeDirectTrampolineWithAccessCheck, state,
651 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700652}
653
654static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
655 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700656 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700657 return NextInvokeInsnSP(cu, info, kQuickInvokeSuperTrampolineWithAccessCheck, state,
658 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700659}
660
661static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
662 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700663 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700664 return NextInvokeInsnSP(cu, info, kQuickInvokeVirtualTrampolineWithAccessCheck, state,
665 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700666}
667
668static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
669 CallInfo* info, int state,
670 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700671 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700672 return NextInvokeInsnSP(cu, info, kQuickInvokeInterfaceTrampolineWithAccessCheck, state,
673 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700674}
675
Dave Allison69dfe512014-07-11 17:11:58 +0000676// Default implementation of implicit null pointer check.
677// Overridden by arch specific as necessary.
678void Mir2Lir::GenImplicitNullCheck(RegStorage reg, int opt_flags) {
679 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
680 return;
681 }
682 RegStorage tmp = AllocTemp();
683 Load32Disp(reg, 0, tmp);
684 MarkPossibleNullPointerException(opt_flags);
685 FreeTemp(tmp);
686}
687
Serguei Katkov717a3e42014-11-13 17:19:42 +0600688/**
689 * @brief Used to flush promoted registers if they are used as argument
690 * in an invocation.
691 * @param info the infromation about arguments for invocation.
692 * @param start the first argument we should start to look from.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700693 */
Serguei Katkov717a3e42014-11-13 17:19:42 +0600694void Mir2Lir::GenDalvikArgsFlushPromoted(CallInfo* info, int start) {
695 if (cu_->disable_opt & (1 << kPromoteRegs)) {
696 // This make sense only if promotion is enabled.
697 return;
698 }
699 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700700 // Scan the rest of the args - if in phys_reg flush to memory
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000701 for (size_t next_arg = start; next_arg < info->num_arg_words;) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700702 RegLocation loc = info->args[next_arg];
703 if (loc.wide) {
704 loc = UpdateLocWide(loc);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600705 if (loc.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700706 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700707 }
708 next_arg += 2;
709 } else {
710 loc = UpdateLoc(loc);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600711 if (loc.location == kLocPhysReg) {
712 if (loc.ref) {
713 StoreRefDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, kNotVolatile);
714 } else {
715 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k32,
716 kNotVolatile);
717 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700718 }
719 next_arg++;
720 }
721 }
Serguei Katkov717a3e42014-11-13 17:19:42 +0600722}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700723
Serguei Katkov717a3e42014-11-13 17:19:42 +0600724/**
725 * @brief Used to optimize the copying of VRs which are arguments of invocation.
726 * Please note that you should flush promoted registers first if you copy.
727 * If implementation does copying it may skip several of the first VRs but must copy
728 * till the end. Implementation must return the number of skipped VRs
729 * (it might be all VRs).
730 * @see GenDalvikArgsFlushPromoted
731 * @param info the information about arguments for invocation.
732 * @param first the first argument we should start to look from.
733 * @param count the number of remaining arguments we can handle.
734 * @return the number of arguments which we did not handle. Unhandled arguments
735 * must be attached to the first one.
736 */
737int Mir2Lir::GenDalvikArgsBulkCopy(CallInfo* info, int first, int count) {
738 // call is pretty expensive, let's use it if count is big.
739 if (count > 16) {
740 GenDalvikArgsFlushPromoted(info, first);
741 int start_offset = SRegOffset(info->args[first].s_reg_low);
742 int outs_offset = StackVisitor::GetOutVROffset(first, cu_->instruction_set);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800743
Andreas Gampeccc60262014-07-04 18:02:38 -0700744 OpRegRegImm(kOpAdd, TargetReg(kArg0, kRef), TargetPtrReg(kSp), outs_offset);
745 OpRegRegImm(kOpAdd, TargetReg(kArg1, kRef), TargetPtrReg(kSp), start_offset);
Andreas Gampe98430592014-07-27 19:44:50 -0700746 CallRuntimeHelperRegRegImm(kQuickMemcpy, TargetReg(kArg0, kRef), TargetReg(kArg1, kRef),
Serguei Katkov717a3e42014-11-13 17:19:42 +0600747 count * 4, false);
748 count = 0;
749 }
750 return count;
751}
752
753int Mir2Lir::GenDalvikArgs(CallInfo* info, int call_state,
754 LIR** pcrLabel, NextCallInsn next_call_insn,
755 const MethodReference& target_method,
756 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
757 InvokeType type, bool skip_this) {
758 // If no arguments, just return.
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000759 if (info->num_arg_words == 0u)
Serguei Katkov717a3e42014-11-13 17:19:42 +0600760 return call_state;
761
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000762 const size_t start_index = skip_this ? 1 : 0;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600763
764 // Get architecture dependent mapping between output VRs and physical registers
765 // basing on shorty of method to call.
766 InToRegStorageMapping in_to_reg_storage_mapping(arena_);
767 {
768 const char* target_shorty = mir_graph_->GetShortyFromMethodReference(target_method);
769 ShortyIterator shorty_iterator(target_shorty, type == kStatic);
770 in_to_reg_storage_mapping.Initialize(&shorty_iterator, GetResetedInToRegStorageMapper());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700771 }
772
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000773 size_t stack_map_start = std::max(in_to_reg_storage_mapping.GetEndMappedIn(), start_index);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600774 if ((stack_map_start < info->num_arg_words) && info->args[stack_map_start].high_word) {
775 // It is possible that the last mapped reg is 32 bit while arg is 64-bit.
776 // It will be handled together with low part mapped to register.
777 stack_map_start++;
778 }
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000779 size_t regs_left_to_pass_via_stack = info->num_arg_words - stack_map_start;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600780
781 // If it is a range case we can try to copy remaining VRs (not mapped to physical registers)
782 // using more optimal algorithm.
783 if (info->is_range && regs_left_to_pass_via_stack > 1) {
784 regs_left_to_pass_via_stack = GenDalvikArgsBulkCopy(info, stack_map_start,
785 regs_left_to_pass_via_stack);
786 }
787
788 // Now handle any remaining VRs mapped to stack.
789 if (in_to_reg_storage_mapping.HasArgumentsOnStack()) {
790 // Two temps but do not use kArg1, it might be this which we can skip.
791 // Separate single and wide - it can give some advantage.
792 RegStorage regRef = TargetReg(kArg3, kRef);
793 RegStorage regSingle = TargetReg(kArg3, kNotWide);
794 RegStorage regWide = TargetReg(kArg2, kWide);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000795 for (size_t i = start_index; i < stack_map_start + regs_left_to_pass_via_stack; i++) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600796 RegLocation rl_arg = info->args[i];
797 rl_arg = UpdateRawLoc(rl_arg);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000798 RegStorage reg = in_to_reg_storage_mapping.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600799 if (!reg.Valid()) {
800 int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
801 {
802 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
803 if (rl_arg.wide) {
804 if (rl_arg.location == kLocPhysReg) {
805 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k64, kNotVolatile);
806 } else {
807 LoadValueDirectWideFixed(rl_arg, regWide);
808 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regWide, k64, kNotVolatile);
809 }
810 } else {
811 if (rl_arg.location == kLocPhysReg) {
812 if (rl_arg.ref) {
813 StoreRefDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, kNotVolatile);
814 } else {
815 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k32, kNotVolatile);
816 }
817 } else {
818 if (rl_arg.ref) {
819 LoadValueDirectFixed(rl_arg, regRef);
820 StoreRefDisp(TargetPtrReg(kSp), out_offset, regRef, kNotVolatile);
821 } else {
822 LoadValueDirectFixed(rl_arg, regSingle);
823 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regSingle, k32, kNotVolatile);
824 }
825 }
826 }
827 }
828 call_state = next_call_insn(cu_, info, call_state, target_method,
829 vtable_idx, direct_code, direct_method, type);
830 }
831 if (rl_arg.wide) {
832 i++;
833 }
834 }
835 }
836
837 // Finish with VRs mapped to physical registers.
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000838 for (size_t i = start_index; i < stack_map_start; i++) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600839 RegLocation rl_arg = info->args[i];
840 rl_arg = UpdateRawLoc(rl_arg);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000841 RegStorage reg = in_to_reg_storage_mapping.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600842 if (reg.Valid()) {
843 if (rl_arg.wide) {
844 // if reg is not 64-bit (it is half of 64-bit) then handle it separately.
845 if (!reg.Is64Bit()) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600846 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
847 if (rl_arg.location == kLocPhysReg) {
848 int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000849 // Dump it to memory.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600850 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k64, kNotVolatile);
851 LoadBaseDisp(TargetPtrReg(kSp), out_offset, reg, k32, kNotVolatile);
852 } else {
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000853 int high_offset = StackVisitor::GetOutVROffset(i + 1, cu_->instruction_set);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600854 // First, use target reg for high part.
855 LoadBaseDisp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low + 1), reg, k32,
856 kNotVolatile);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000857 StoreBaseDisp(TargetPtrReg(kSp), high_offset, reg, k32, kNotVolatile);
858 // Now, use target reg for low part.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600859 LoadBaseDisp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low), reg, k32, kNotVolatile);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000860 int low_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
861 // And store it to the expected memory location.
862 StoreBaseDisp(TargetPtrReg(kSp), low_offset, reg, k32, kNotVolatile);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600863 }
864 } else {
865 LoadValueDirectWideFixed(rl_arg, reg);
866 }
867 } else {
868 LoadValueDirectFixed(rl_arg, reg);
869 }
870 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
871 direct_code, direct_method, type);
872 }
873 if (rl_arg.wide) {
874 i++;
875 }
876 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700877
878 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
879 direct_code, direct_method, type);
880 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +0000881 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700882 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700883 } else {
884 *pcrLabel = nullptr;
Dave Allison69dfe512014-07-11 17:11:58 +0000885 GenImplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700886 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700887 }
888 return call_state;
889}
890
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000891void Mir2Lir::EnsureInitializedArgMappingToPhysicalReg() {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600892 if (!in_to_reg_storage_mapping_.IsInitialized()) {
893 ShortyIterator shorty_iterator(cu_->shorty, cu_->invoke_type == kStatic);
894 in_to_reg_storage_mapping_.Initialize(&shorty_iterator, GetResetedInToRegStorageMapper());
895 }
Serguei Katkov717a3e42014-11-13 17:19:42 +0600896}
897
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700898RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700899 RegLocation res;
900 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -0700901 // If result is unused, return a sink target based on type of invoke target.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800902 res = GetReturn(
903 ShortyToRegClass(mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700904 } else {
905 res = info->result;
906 }
907 return res;
908}
909
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700910RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700911 RegLocation res;
912 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -0700913 // If result is unused, return a sink target based on type of invoke target.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800914 res = GetReturnWide(ShortyToRegClass(
915 mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700916 } else {
917 res = info->result;
918 }
919 return res;
920}
921
Mathieu Chartiercd48f2d2014-09-09 13:51:09 -0700922bool Mir2Lir::GenInlinedReferenceGetReferent(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +0100923 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
924 // TODO: add Mips and Mips64 implementations.
Fred Shih4ee7a662014-07-11 09:59:27 -0700925 return false;
926 }
927
Fred Shih4ee7a662014-07-11 09:59:27 -0700928 bool use_direct_type_ptr;
929 uintptr_t direct_type_ptr;
Fred Shihe7f82e22014-08-06 10:46:37 -0700930 ClassReference ref;
931 if (!cu_->compiler_driver->CanEmbedReferenceTypeInCode(&ref,
932 &use_direct_type_ptr, &direct_type_ptr)) {
933 return false;
934 }
935
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700936 RegStorage reg_class = TargetReg(kArg1, kRef);
937 Clobber(reg_class);
938 LockTemp(reg_class);
Fred Shih4ee7a662014-07-11 09:59:27 -0700939 if (use_direct_type_ptr) {
940 LoadConstant(reg_class, direct_type_ptr);
Alex Lighteb76e112014-07-29 15:22:40 -0700941 } else {
Fred Shihe7f82e22014-08-06 10:46:37 -0700942 uint16_t type_idx = ref.first->GetClassDef(ref.second).class_idx_;
943 LoadClassType(*ref.first, type_idx, kArg1);
Fred Shih4ee7a662014-07-11 09:59:27 -0700944 }
Fred Shih4ee7a662014-07-11 09:59:27 -0700945
Fred Shihe7f82e22014-08-06 10:46:37 -0700946 uint32_t slow_path_flag_offset = cu_->compiler_driver->GetReferenceSlowFlagOffset();
947 uint32_t disable_flag_offset = cu_->compiler_driver->GetReferenceDisableFlagOffset();
Fred Shih4ee7a662014-07-11 09:59:27 -0700948 CHECK(slow_path_flag_offset && disable_flag_offset &&
949 (slow_path_flag_offset != disable_flag_offset));
950
951 // intrinsic logic start.
952 RegLocation rl_obj = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -0700953 rl_obj = LoadValue(rl_obj, kRefReg);
Fred Shih4ee7a662014-07-11 09:59:27 -0700954
955 RegStorage reg_slow_path = AllocTemp();
956 RegStorage reg_disabled = AllocTemp();
Andreas Gampef6815702015-01-20 09:53:48 -0800957 LoadBaseDisp(reg_class, slow_path_flag_offset, reg_slow_path, kSignedByte, kNotVolatile);
958 LoadBaseDisp(reg_class, disable_flag_offset, reg_disabled, kSignedByte, kNotVolatile);
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700959 FreeTemp(reg_class);
960 LIR* or_inst = OpRegRegReg(kOpOr, reg_slow_path, reg_slow_path, reg_disabled);
Fred Shih4ee7a662014-07-11 09:59:27 -0700961 FreeTemp(reg_disabled);
962
963 // if slow path, jump to JNI path target
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700964 LIR* slow_path_branch;
965 if (or_inst->u.m.def_mask->HasBit(ResourceMask::kCCode)) {
966 // Generate conditional branch only, as the OR set a condition state (we are interested in a 'Z' flag).
967 slow_path_branch = OpCondBranch(kCondNe, nullptr);
968 } else {
969 // Generate compare and branch.
970 slow_path_branch = OpCmpImmBranch(kCondNe, reg_slow_path, 0, nullptr);
971 }
Fred Shih4ee7a662014-07-11 09:59:27 -0700972 FreeTemp(reg_slow_path);
973
974 // slow path not enabled, simply load the referent of the reference object
975 RegLocation rl_dest = InlineTarget(info);
976 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
977 GenNullCheck(rl_obj.reg, info->opt_flags);
978 LoadRefDisp(rl_obj.reg, mirror::Reference::ReferentOffset().Int32Value(), rl_result.reg,
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -0700979 kNotVolatile);
Fred Shih4ee7a662014-07-11 09:59:27 -0700980 MarkPossibleNullPointerException(info->opt_flags);
981 StoreValue(rl_dest, rl_result);
982
983 LIR* intrinsic_finish = NewLIR0(kPseudoTargetLabel);
984 AddIntrinsicSlowPath(info, slow_path_branch, intrinsic_finish);
Serguei Katkov9863daf2014-09-04 15:21:32 +0700985 ClobberCallerSave(); // We must clobber everything because slow path will return here
Fred Shih4ee7a662014-07-11 09:59:27 -0700986 return true;
987}
988
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700989bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Jeff Hao848f70a2014-01-15 13:49:50 -0800990 // Location of char array data
Brian Carlstrom7940e442013-07-12 13:46:57 -0700991 int value_offset = mirror::String::ValueOffset().Int32Value();
992 // Location of count
993 int count_offset = mirror::String::CountOffset().Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700994
995 RegLocation rl_obj = info->args[0];
996 RegLocation rl_idx = info->args[1];
buzbeea0cd2d72014-06-01 09:33:49 -0700997 rl_obj = LoadValue(rl_obj, kRefReg);
Andreas Gampe98430592014-07-27 19:44:50 -0700998 rl_idx = LoadValue(rl_idx, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800999 RegStorage reg_max;
1000 GenNullCheck(rl_obj.reg, info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001001 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001002 LIR* range_check_branch = nullptr;
Andreas Gampe98430592014-07-27 19:44:50 -07001003 if (range_check) {
1004 reg_max = AllocTemp();
1005 Load32Disp(rl_obj.reg, count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -08001006 MarkPossibleNullPointerException(info->opt_flags);
Jeff Hao848f70a2014-01-15 13:49:50 -08001007 // Set up a slow path to allow retry in case of bounds violation
Andreas Gampe98430592014-07-27 19:44:50 -07001008 OpRegReg(kOpCmp, rl_idx.reg, reg_max);
1009 FreeTemp(reg_max);
1010 range_check_branch = OpCondBranch(kCondUge, nullptr);
1011 }
Jeff Hao848f70a2014-01-15 13:49:50 -08001012 RegStorage reg_ptr = AllocTempRef();
1013 OpRegRegImm(kOpAdd, reg_ptr, rl_obj.reg, value_offset);
buzbee2700f7e2014-03-07 09:46:20 -08001014 FreeTemp(rl_obj.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001015 RegLocation rl_dest = InlineTarget(info);
1016 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Jeff Hao848f70a2014-01-15 13:49:50 -08001017 LoadBaseIndexed(reg_ptr, rl_idx.reg, rl_result.reg, 1, kUnsignedHalf);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001018 FreeTemp(reg_ptr);
1019 StoreValue(rl_dest, rl_result);
1020 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001021 DCHECK(range_check_branch != nullptr);
1022 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001023 AddIntrinsicSlowPath(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001024 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001025 return true;
1026}
1027
Jeff Hao848f70a2014-01-15 13:49:50 -08001028bool Mir2Lir::GenInlinedStringGetCharsNoCheck(CallInfo* info) {
1029 if (cu_->instruction_set == kMips) {
1030 // TODO - add Mips implementation
1031 return false;
1032 }
1033 size_t char_component_size = Primitive::ComponentSize(Primitive::kPrimChar);
1034 // Location of data in char array buffer
1035 int data_offset = mirror::Array::DataOffset(char_component_size).Int32Value();
1036 // Location of char array data in string
1037 int value_offset = mirror::String::ValueOffset().Int32Value();
1038
1039 RegLocation rl_obj = info->args[0];
1040 RegLocation rl_start = info->args[1];
1041 RegLocation rl_end = info->args[2];
1042 RegLocation rl_buffer = info->args[3];
1043 RegLocation rl_index = info->args[4];
1044
1045 ClobberCallerSave();
1046 LockCallTemps(); // Using fixed registers
1047 RegStorage reg_dst_ptr = TargetReg(kArg0, kRef);
1048 RegStorage reg_src_ptr = TargetReg(kArg1, kRef);
1049 RegStorage reg_length = TargetReg(kArg2, kNotWide);
1050 RegStorage reg_tmp = TargetReg(kArg3, kNotWide);
1051 RegStorage reg_tmp_ptr = RegStorage(RegStorage::k64BitSolo, reg_tmp.GetRawBits() & RegStorage::kRegTypeMask);
1052
1053 LoadValueDirectFixed(rl_buffer, reg_dst_ptr);
1054 OpRegImm(kOpAdd, reg_dst_ptr, data_offset);
1055 LoadValueDirectFixed(rl_index, reg_tmp);
1056 OpRegRegImm(kOpLsl, reg_tmp, reg_tmp, 1);
1057 OpRegReg(kOpAdd, reg_dst_ptr, cu_->instruction_set == kArm64 ? reg_tmp_ptr : reg_tmp);
1058
1059 LoadValueDirectFixed(rl_start, reg_tmp);
1060 LoadValueDirectFixed(rl_end, reg_length);
1061 OpRegReg(kOpSub, reg_length, reg_tmp);
1062 OpRegRegImm(kOpLsl, reg_length, reg_length, 1);
1063 LoadValueDirectFixed(rl_obj, reg_src_ptr);
1064
1065 OpRegImm(kOpAdd, reg_src_ptr, value_offset);
1066 OpRegRegImm(kOpLsl, reg_tmp, reg_tmp, 1);
1067 OpRegReg(kOpAdd, reg_src_ptr, cu_->instruction_set == kArm64 ? reg_tmp_ptr : reg_tmp);
1068
1069 RegStorage r_tgt;
1070 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
1071 r_tgt = LoadHelper(kQuickMemcpy);
1072 } else {
1073 r_tgt = RegStorage::InvalidReg();
1074 }
1075 // NOTE: not a safepoint
1076 CallHelper(r_tgt, kQuickMemcpy, false, true);
1077
1078 return true;
1079}
1080
Brian Carlstrom7940e442013-07-12 13:46:57 -07001081// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001082bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001083 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1084 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001085 return false;
1086 }
1087 // dst = src.length();
1088 RegLocation rl_obj = info->args[0];
buzbeea0cd2d72014-06-01 09:33:49 -07001089 rl_obj = LoadValue(rl_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001090 RegLocation rl_dest = InlineTarget(info);
1091 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001092 GenNullCheck(rl_obj.reg, info->opt_flags);
buzbee695d13a2014-04-19 13:32:20 -07001093 Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg);
Dave Allisonb373e092014-02-20 16:06:36 -08001094 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001095 if (is_empty) {
1096 // dst = (dst == 0);
1097 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001098 RegStorage t_reg = AllocTemp();
1099 OpRegReg(kOpNeg, t_reg, rl_result.reg);
1100 OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001101 } else if (cu_->instruction_set == kArm64) {
1102 OpRegImm(kOpSub, rl_result.reg, 1);
1103 OpRegRegImm(kOpLsr, rl_result.reg, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001104 } else {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001105 DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64);
buzbee2700f7e2014-03-07 09:46:20 -08001106 OpRegImm(kOpSub, rl_result.reg, 1);
1107 OpRegImm(kOpLsr, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001108 }
1109 }
1110 StoreValue(rl_dest, rl_result);
1111 return true;
1112}
1113
Jeff Hao848f70a2014-01-15 13:49:50 -08001114bool Mir2Lir::GenInlinedStringFactoryNewStringFromBytes(CallInfo* info) {
1115 if (cu_->instruction_set == kMips) {
1116 // TODO - add Mips implementation
1117 return false;
1118 }
1119 RegLocation rl_data = info->args[0];
1120 RegLocation rl_high = info->args[1];
1121 RegLocation rl_offset = info->args[2];
1122 RegLocation rl_count = info->args[3];
1123 rl_data = LoadValue(rl_data, kRefReg);
1124 LIR* data_null_check_branch = OpCmpImmBranch(kCondEq, rl_data.reg, 0, nullptr);
1125 AddIntrinsicSlowPath(info, data_null_check_branch);
1126 CallRuntimeHelperRegLocationRegLocationRegLocationRegLocation(
1127 kQuickAllocStringFromBytes, rl_data, rl_high, rl_offset, rl_count, true);
1128 RegLocation rl_return = GetReturn(kRefReg);
1129 RegLocation rl_dest = InlineTarget(info);
1130 StoreValue(rl_dest, rl_return);
1131 return true;
1132}
1133
1134bool Mir2Lir::GenInlinedStringFactoryNewStringFromChars(CallInfo* info) {
1135 if (cu_->instruction_set == kMips) {
1136 // TODO - add Mips implementation
1137 return false;
1138 }
1139 RegLocation rl_offset = info->args[0];
1140 RegLocation rl_count = info->args[1];
1141 RegLocation rl_data = info->args[2];
1142 CallRuntimeHelperRegLocationRegLocationRegLocation(
1143 kQuickAllocStringFromChars, rl_offset, rl_count, rl_data, true);
1144 RegLocation rl_return = GetReturn(kRefReg);
1145 RegLocation rl_dest = InlineTarget(info);
1146 StoreValue(rl_dest, rl_return);
1147 return true;
1148}
1149
1150bool Mir2Lir::GenInlinedStringFactoryNewStringFromString(CallInfo* info) {
1151 if (cu_->instruction_set == kMips) {
1152 // TODO - add Mips implementation
1153 return false;
1154 }
1155 RegLocation rl_string = info->args[0];
1156 rl_string = LoadValue(rl_string, kRefReg);
1157 LIR* string_null_check_branch = OpCmpImmBranch(kCondEq, rl_string.reg, 0, nullptr);
1158 AddIntrinsicSlowPath(info, string_null_check_branch);
1159 CallRuntimeHelperRegLocation(kQuickAllocStringFromString, rl_string, true);
1160 RegLocation rl_return = GetReturn(kRefReg);
1161 RegLocation rl_dest = InlineTarget(info);
1162 StoreValue(rl_dest, rl_return);
1163 return true;
1164}
1165
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001166bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001167 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1168 // TODO: add Mips and Mips64 implementations.
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001169 return false;
1170 }
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001171 RegLocation rl_dest = IsWide(size) ? InlineTargetWide(info) : InlineTarget(info); // result reg
1172 if (rl_dest.s_reg_low == INVALID_SREG) {
1173 // Result is unused, the code is dead. Inlining successful, no code generated.
1174 return true;
1175 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001176 RegLocation rl_src_i = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -07001177 RegLocation rl_i = IsWide(size) ? LoadValueWide(rl_src_i, kCoreReg) : LoadValue(rl_src_i, kCoreReg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001178 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Fred Shih37f05ef2014-07-16 18:38:08 -07001179 if (IsWide(size)) {
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001180 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Serban Constantinescu169489b2014-06-11 16:43:35 +01001181 OpRegReg(kOpRev, rl_result.reg, rl_i.reg);
1182 StoreValueWide(rl_dest, rl_result);
1183 return true;
1184 }
buzbee2700f7e2014-03-07 09:46:20 -08001185 RegStorage r_i_low = rl_i.reg.GetLow();
1186 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001187 // 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 +00001188 r_i_low = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -08001189 OpRegCopy(r_i_low, rl_i.reg);
Vladimir Markof246af22013-11-27 12:30:15 +00001190 }
buzbee2700f7e2014-03-07 09:46:20 -08001191 OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh());
1192 OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low);
1193 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001194 FreeTemp(r_i_low);
1195 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001196 StoreValueWide(rl_dest, rl_result);
1197 } else {
buzbee695d13a2014-04-19 13:32:20 -07001198 DCHECK(size == k32 || size == kSignedHalf);
1199 OpKind op = (size == k32) ? kOpRev : kOpRevsh;
buzbee2700f7e2014-03-07 09:46:20 -08001200 OpRegReg(op, rl_result.reg, rl_i.reg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001201 StoreValue(rl_dest, rl_result);
1202 }
1203 return true;
1204}
1205
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001206bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001207 RegLocation rl_dest = InlineTarget(info);
1208 if (rl_dest.s_reg_low == INVALID_SREG) {
1209 // Result is unused, the code is dead. Inlining successful, no code generated.
1210 return true;
1211 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001212 RegLocation rl_src = info->args[0];
1213 rl_src = LoadValue(rl_src, kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001214 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001215 RegStorage sign_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001216 // abs(x) = y<=x>>31, (x+y)^y.
buzbee2700f7e2014-03-07 09:46:20 -08001217 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31);
1218 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1219 OpRegReg(kOpXor, rl_result.reg, sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001220 StoreValue(rl_dest, rl_result);
1221 return true;
1222}
1223
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001224bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001225 RegLocation rl_dest = InlineTargetWide(info);
1226 if (rl_dest.s_reg_low == INVALID_SREG) {
1227 // Result is unused, the code is dead. Inlining successful, no code generated.
1228 return true;
1229 }
Vladimir Markob9823312014-03-20 17:38:43 +00001230 RegLocation rl_src = info->args[0];
1231 rl_src = LoadValueWide(rl_src, kCoreReg);
Vladimir Markob9823312014-03-20 17:38:43 +00001232 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1233
1234 // If on x86 or if we would clobber a register needed later, just copy the source first.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001235 if (cu_->instruction_set != kX86_64 &&
1236 (cu_->instruction_set == kX86 ||
1237 rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001238 OpRegCopyWide(rl_result.reg, rl_src.reg);
1239 if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() &&
1240 rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() &&
1241 rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() &&
Vladimir Markob9823312014-03-20 17:38:43 +00001242 rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) {
1243 // Reuse source registers to avoid running out of temps.
buzbee2700f7e2014-03-07 09:46:20 -08001244 FreeTemp(rl_src.reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001245 }
1246 rl_src = rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001247 }
Vladimir Markob9823312014-03-20 17:38:43 +00001248
1249 // abs(x) = y<=x>>31, (x+y)^y.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001250 RegStorage sign_reg;
1251 if (cu_->instruction_set == kX86_64) {
1252 sign_reg = AllocTempWide();
1253 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 63);
1254 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1255 OpRegReg(kOpXor, rl_result.reg, sign_reg);
1256 } else {
1257 sign_reg = AllocTemp();
1258 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31);
1259 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg);
1260 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg);
1261 OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg);
1262 OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg);
1263 }
buzbee082833c2014-05-17 23:16:26 -07001264 FreeTemp(sign_reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001265 StoreValueWide(rl_dest, rl_result);
1266 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001267}
1268
Serban Constantinescu23abec92014-07-02 16:13:38 +01001269bool Mir2Lir::GenInlinedReverseBits(CallInfo* info, OpSize size) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001270 // Currently implemented only for ARM64.
1271 UNUSED(info, size);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001272 return false;
1273}
1274
1275bool Mir2Lir::GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001276 // Currently implemented only for ARM64.
1277 UNUSED(info, is_min, is_double);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001278 return false;
1279}
1280
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001281bool Mir2Lir::GenInlinedCeil(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001282 UNUSED(info);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001283 return false;
1284}
1285
1286bool Mir2Lir::GenInlinedFloor(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001287 UNUSED(info);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001288 return false;
1289}
1290
1291bool Mir2Lir::GenInlinedRint(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001292 UNUSED(info);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001293 return false;
1294}
1295
1296bool Mir2Lir::GenInlinedRound(CallInfo* info, bool is_double) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001297 UNUSED(info, is_double);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001298 return false;
1299}
1300
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001301bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001302 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1303 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001304 return false;
1305 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001306 RegLocation rl_dest = InlineTarget(info);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001307 if (rl_dest.s_reg_low == INVALID_SREG) {
1308 // Result is unused, the code is dead. Inlining successful, no code generated.
1309 return true;
1310 }
1311 RegLocation rl_src = info->args[0];
Brian Carlstrom7940e442013-07-12 13:46:57 -07001312 StoreValue(rl_dest, rl_src);
1313 return true;
1314}
1315
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001316bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001317 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1318 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001319 return false;
1320 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001321 RegLocation rl_dest = InlineTargetWide(info);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001322 if (rl_dest.s_reg_low == INVALID_SREG) {
1323 // Result is unused, the code is dead. Inlining successful, no code generated.
1324 return true;
1325 }
1326 RegLocation rl_src = info->args[0];
Brian Carlstrom7940e442013-07-12 13:46:57 -07001327 StoreValueWide(rl_dest, rl_src);
1328 return true;
1329}
1330
DaniilSokolov70c4f062014-06-24 17:34:00 -07001331bool Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001332 UNUSED(info);
DaniilSokolov70c4f062014-06-24 17:34:00 -07001333 return false;
1334}
1335
1336
Brian Carlstrom7940e442013-07-12 13:46:57 -07001337/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001338 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001339 * otherwise bails to standard library code.
1340 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001341bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001342 RegLocation rl_obj = info->args[0];
1343 RegLocation rl_char = info->args[1];
1344 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1345 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1346 return false;
1347 }
1348
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001349 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001350 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001351 RegStorage reg_ptr = TargetReg(kArg0, kRef);
1352 RegStorage reg_char = TargetReg(kArg1, kNotWide);
1353 RegStorage reg_start = TargetReg(kArg2, kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001354
Brian Carlstrom7940e442013-07-12 13:46:57 -07001355 LoadValueDirectFixed(rl_obj, reg_ptr);
1356 LoadValueDirectFixed(rl_char, reg_char);
1357 if (zero_based) {
1358 LoadConstant(reg_start, 0);
1359 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001360 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001361 LoadValueDirectFixed(rl_start, reg_start);
1362 }
Andreas Gampe98430592014-07-27 19:44:50 -07001363 RegStorage r_tgt = LoadHelper(kQuickIndexOf);
Dave Allisonf9439142014-03-27 15:10:22 -07001364 GenExplicitNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001365 LIR* high_code_point_branch =
1366 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001367 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001368 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001369 if (!rl_char.is_const) {
1370 // Add the slow path for code points beyond 0xFFFF.
1371 DCHECK(high_code_point_branch != nullptr);
1372 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1373 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001374 AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt);
Serguei Katkov9863daf2014-09-04 15:21:32 +07001375 ClobberCallerSave(); // We must clobber everything because slow path will return here
Vladimir Marko3bc86152014-03-13 14:11:28 +00001376 } else {
1377 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1378 DCHECK(high_code_point_branch == nullptr);
1379 }
buzbeea0cd2d72014-06-01 09:33:49 -07001380 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001381 RegLocation rl_dest = InlineTarget(info);
1382 StoreValue(rl_dest, rl_return);
1383 return true;
1384}
1385
1386/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001387bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001388 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1389 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001390 return false;
1391 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001392 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001393 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001394 RegStorage reg_this = TargetReg(kArg0, kRef);
1395 RegStorage reg_cmp = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001396
1397 RegLocation rl_this = info->args[0];
1398 RegLocation rl_cmp = info->args[1];
1399 LoadValueDirectFixed(rl_this, reg_this);
1400 LoadValueDirectFixed(rl_cmp, reg_cmp);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001401 RegStorage r_tgt;
1402 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Andreas Gampe98430592014-07-27 19:44:50 -07001403 r_tgt = LoadHelper(kQuickStringCompareTo);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001404 } else {
1405 r_tgt = RegStorage::InvalidReg();
1406 }
Dave Allisonf9439142014-03-27 15:10:22 -07001407 GenExplicitNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001408 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001409 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001410 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
Mingyao Yang3a74d152014-04-21 15:39:44 -07001411 AddIntrinsicSlowPath(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001412 // NOTE: not a safepoint
Andreas Gampe98430592014-07-27 19:44:50 -07001413 CallHelper(r_tgt, kQuickStringCompareTo, false, true);
buzbeea0cd2d72014-06-01 09:33:49 -07001414 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001415 RegLocation rl_dest = InlineTarget(info);
1416 StoreValue(rl_dest, rl_return);
1417 return true;
1418}
1419
1420bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1421 RegLocation rl_dest = InlineTarget(info);
Andreas Gampe7a949612014-07-08 11:03:59 -07001422
1423 // Early exit if the result is unused.
1424 if (rl_dest.orig_sreg < 0) {
1425 return true;
1426 }
1427
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001428 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001429
Mathieu Chartier3d21bdf2015-04-22 13:56:20 -07001430 if (cu_->target64) {
Andreas Gamped500b532015-01-16 22:09:55 -08001431 LoadRefDisp(TargetPtrReg(kSelf), Thread::PeerOffset<8>().Int32Value(), rl_result.reg,
1432 kNotVolatile);
1433 } else {
1434 Load32Disp(TargetPtrReg(kSelf), Thread::PeerOffset<4>().Int32Value(), rl_result.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001435 }
Andreas Gamped500b532015-01-16 22:09:55 -08001436
Brian Carlstrom7940e442013-07-12 13:46:57 -07001437 StoreValue(rl_dest, rl_result);
1438 return true;
1439}
1440
1441bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
Vladimir Markofac10702015-04-22 11:51:52 +01001442 bool is_long, bool is_object, bool is_volatile) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001443 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1444 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001445 return false;
1446 }
1447 // Unused - RegLocation rl_src_unsafe = info->args[0];
1448 RegLocation rl_src_obj = info->args[1]; // Object
1449 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001450 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001451 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001452
buzbeea0cd2d72014-06-01 09:33:49 -07001453 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001454 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
Vladimir Markofac10702015-04-22 11:51:52 +01001455 RegLocation rl_result = EvalLoc(rl_dest, is_object ? kRefReg : kCoreReg, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001456 if (is_long) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001457 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1458 || cu_->instruction_set == kArm64) {
1459 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001460 } else {
1461 RegStorage rl_temp_offset = AllocTemp();
1462 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001463 LoadBaseDisp(rl_temp_offset, 0, rl_result.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001464 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001465 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001466 } else {
Matteo Franchin255e0142014-07-04 13:50:41 +01001467 if (rl_result.ref) {
1468 LoadRefIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0);
1469 } else {
1470 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32);
1471 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001472 }
1473
1474 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001475 GenMemBarrier(kLoadAny);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001476 }
1477
1478 if (is_long) {
1479 StoreValueWide(rl_dest, rl_result);
1480 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001481 StoreValue(rl_dest, rl_result);
1482 }
1483 return true;
1484}
1485
1486bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1487 bool is_object, bool is_volatile, bool is_ordered) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001488 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1489 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001490 return false;
1491 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001492 // Unused - RegLocation rl_src_unsafe = info->args[0];
1493 RegLocation rl_src_obj = info->args[1]; // Object
1494 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001495 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001496 RegLocation rl_src_value = info->args[4]; // value to store
1497 if (is_volatile || is_ordered) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001498 GenMemBarrier(kAnyStore);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001499 }
buzbeea0cd2d72014-06-01 09:33:49 -07001500 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001501 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1502 RegLocation rl_value;
1503 if (is_long) {
1504 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001505 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1506 || cu_->instruction_set == kArm64) {
1507 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001508 } else {
1509 RegStorage rl_temp_offset = AllocTemp();
1510 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001511 StoreBaseDisp(rl_temp_offset, 0, rl_value.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001512 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001513 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001514 } else {
Vladimir Markofac10702015-04-22 11:51:52 +01001515 rl_value = LoadValue(rl_src_value, is_object ? kRefReg : kCoreReg);
Matteo Franchin255e0142014-07-04 13:50:41 +01001516 if (rl_value.ref) {
1517 StoreRefIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0);
1518 } else {
1519 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32);
1520 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001521 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001522
1523 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
buzbee091cc402014-03-31 10:14:40 -07001524 FreeTemp(rl_offset.reg);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001525
Brian Carlstrom7940e442013-07-12 13:46:57 -07001526 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001527 // Prevent reordering with a subsequent volatile load.
1528 // May also be needed to address store atomicity issues.
1529 GenMemBarrier(kAnyAny);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001530 }
1531 if (is_object) {
Vladimir Marko743b98c2014-11-24 19:45:41 +00001532 MarkGCCard(0, rl_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001533 }
1534 return true;
1535}
1536
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001537void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001538 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Vladimir Marko87b7c522015-04-08 10:01:01 +01001539 if (mir_graph_->GetMethodLoweringInfo(info->mir).IsIntrinsic()) {
1540 const DexFile* dex_file = info->method_ref.dex_file;
1541 auto* inliner = cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(dex_file);
1542 if (inliner->GenIntrinsic(this, info)) {
1543 return;
1544 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001545 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001546 GenInvokeNoInline(info);
1547}
1548
1549void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001550 int call_state = 0;
1551 LIR* null_ck;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001552 LIR** p_null_ck = nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001553 NextCallInsn next_call_insn;
1554 FlushAllRegs(); /* Everything to home location */
1555 // Explicit register usage
1556 LockCallTemps();
1557
Vladimir Markof096aad2014-01-23 15:51:58 +00001558 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
Jeff Hao848f70a2014-01-15 13:49:50 -08001559 MethodReference target_method = method_info.GetTargetMethod();
Vladimir Markof096aad2014-01-23 15:51:58 +00001560 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
1561 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
Vladimir Markof4da6752014-08-01 19:04:18 +01001562 info->type = method_info.GetSharpType();
Jeff Hao848f70a2014-01-15 13:49:50 -08001563 bool is_string_init = false;
1564 if (method_info.IsSpecial()) {
1565 DexFileMethodInliner* inliner = cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(
1566 target_method.dex_file);
1567 if (inliner->IsStringInitMethodIndex(target_method.dex_method_index)) {
1568 is_string_init = true;
1569 size_t pointer_size = GetInstructionSetPointerSize(cu_->instruction_set);
1570 info->string_init_offset = inliner->GetOffsetForStringInit(target_method.dex_method_index,
1571 pointer_size);
1572 info->type = kStatic;
1573 }
1574 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001575 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001576 bool skip_this;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001577
Brian Carlstrom7940e442013-07-12 13:46:57 -07001578 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001579 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001580 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001581 } else if (info->type == kDirect) {
1582 if (fast_path) {
1583 p_null_ck = &null_ck;
1584 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001585 next_call_insn = fast_path ? GetNextSDCallInsn() : NextDirectCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001586 skip_this = false;
1587 } else if (info->type == kStatic) {
Vladimir Markof4da6752014-08-01 19:04:18 +01001588 next_call_insn = fast_path ? GetNextSDCallInsn() : NextStaticCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001589 skip_this = false;
1590 } else if (info->type == kSuper) {
1591 DCHECK(!fast_path); // Fast path is a direct call.
1592 next_call_insn = NextSuperCallInsnSP;
1593 skip_this = false;
1594 } else {
1595 DCHECK_EQ(info->type, kVirtual);
1596 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1597 skip_this = fast_path;
1598 }
Serguei Katkov717a3e42014-11-13 17:19:42 +06001599 call_state = GenDalvikArgs(info, call_state, p_null_ck,
1600 next_call_insn, target_method, method_info.VTableIndex(),
1601 method_info.DirectCode(), method_info.DirectMethod(),
1602 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001603 // Finish up any of the call sequence not interleaved in arg loading
1604 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001605 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001606 method_info.DirectCode(), method_info.DirectMethod(),
1607 original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001608 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001609 LIR* call_insn = GenCallInsn(method_info);
Vladimir Markof4da6752014-08-01 19:04:18 +01001610 MarkSafepointPC(call_insn);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001611
Vladimir Markobfe400b2014-12-19 19:27:26 +00001612 FreeCallTemps();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001613 if (info->result.location != kLocInvalid) {
1614 // We have a following MOVE_RESULT - do it now.
Jeff Hao848f70a2014-01-15 13:49:50 -08001615 RegisterClass reg_class = is_string_init ? kRefReg :
Vladimir Markofac10702015-04-22 11:51:52 +01001616 ShortyToRegClass(mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001617 if (info->result.wide) {
Vladimir Markofac10702015-04-22 11:51:52 +01001618 RegLocation ret_loc = GetReturnWide(reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001619 StoreValueWide(info->result, ret_loc);
1620 } else {
Vladimir Markofac10702015-04-22 11:51:52 +01001621 RegLocation ret_loc = GetReturn(reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001622 StoreValue(info->result, ret_loc);
1623 }
1624 }
1625}
1626
Brian Carlstrom7940e442013-07-12 13:46:57 -07001627} // namespace art