blob: ab011fc0b2e0d40cd5d423fd21613f187cbe11f1 [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 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800401 * Dummy up a RegLocation for the incoming StackReference<mirror::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);
buzbeef2c3e562014-05-29 12:37:25 -0700410 StoreValue(rl_method, rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700411 // If Method* has been promoted, explicitly flush
412 if (rl_method.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700413 StoreRefDisp(TargetPtrReg(kSp), 0, rl_src.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700414 }
415
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700416 if (mir_graph_->GetNumOfInVRs() == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700417 return;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800418 }
419
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700420 int start_vreg = mir_graph_->GetFirstInVR();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700421 /*
422 * Copy incoming arguments to their proper home locations.
423 * NOTE: an older version of dx had an issue in which
424 * it would reuse static method argument registers.
425 * This could result in the same Dalvik virtual register
426 * being promoted to both core and fp regs. To account for this,
427 * we only copy to the corresponding promoted physical register
428 * if it matches the type of the SSA name for the incoming
429 * argument. It is also possible that long and double arguments
430 * end up half-promoted. In those cases, we must flush the promoted
431 * half to memory as well.
432 */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100433 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600434 RegLocation* t_loc = nullptr;
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000435 EnsureInitializedArgMappingToPhysicalReg();
Serguei Katkov717a3e42014-11-13 17:19:42 +0600436 for (uint32_t i = 0; i < mir_graph_->GetNumOfInVRs(); i += t_loc->wide ? 2 : 1) {
437 // get reg corresponding to input
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000438 RegStorage reg = in_to_reg_storage_mapping_.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600439 t_loc = &ArgLocs[i];
440
441 // If the wide input appeared as single, flush it and go
442 // as it comes from memory.
443 if (t_loc->wide && reg.Valid() && !reg.Is64Bit()) {
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000444 // The memory already holds the half. Don't do anything.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600445 reg = RegStorage::InvalidReg();
446 }
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800447
buzbee2700f7e2014-03-07 09:46:20 -0800448 if (reg.Valid()) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600449 // If arriving in register.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700450
Serguei Katkov717a3e42014-11-13 17:19:42 +0600451 // We have already updated the arg location with promoted info
452 // so we can be based on it.
453 if (t_loc->location == kLocPhysReg) {
454 // Just copy it.
455 if (t_loc->wide) {
456 OpRegCopyWide(t_loc->reg, reg);
457 } else {
458 OpRegCopy(t_loc->reg, reg);
459 }
460 } else {
461 // Needs flush.
462 int offset = SRegOffset(start_vreg + i);
463 if (t_loc->ref) {
464 StoreRefDisp(TargetPtrReg(kSp), offset, reg, kNotVolatile);
465 } else {
466 StoreBaseDisp(TargetPtrReg(kSp), offset, reg, t_loc->wide ? k64 : k32, kNotVolatile);
buzbeed0a03b82013-09-14 08:21:05 -0700467 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700468 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700469 } else {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600470 // If arriving in frame & promoted.
471 if (t_loc->location == kLocPhysReg) {
472 int offset = SRegOffset(start_vreg + i);
473 if (t_loc->ref) {
474 LoadRefDisp(TargetPtrReg(kSp), offset, t_loc->reg, kNotVolatile);
475 } else {
476 LoadBaseDisp(TargetPtrReg(kSp), offset, t_loc->reg, t_loc->wide ? k64 : k32,
477 kNotVolatile);
478 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700479 }
480 }
481 }
482}
483
Andreas Gampeccc60262014-07-04 18:02:38 -0700484static void CommonCallCodeLoadThisIntoArg1(const CallInfo* info, Mir2Lir* cg) {
485 RegLocation rl_arg = info->args[0];
486 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1, kRef));
487}
488
489static void CommonCallCodeLoadClassIntoArg0(const CallInfo* info, Mir2Lir* cg) {
490 cg->GenNullCheck(cg->TargetReg(kArg1, kRef), info->opt_flags);
491 // get this->klass_ [use kArg1, set kArg0]
492 cg->LoadRefDisp(cg->TargetReg(kArg1, kRef), mirror::Object::ClassOffset().Int32Value(),
493 cg->TargetReg(kArg0, kRef),
494 kNotVolatile);
495 cg->MarkPossibleNullPointerException(info->opt_flags);
496}
497
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700498static bool CommonCallCodeLoadCodePointerIntoInvokeTgt(const RegStorage* alt_from,
Andreas Gampeccc60262014-07-04 18:02:38 -0700499 const CompilationUnit* cu, Mir2Lir* cg) {
500 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Mathieu Chartier2d721012014-11-10 11:08:06 -0800501 int32_t offset = mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset(
502 InstructionSetPointerSize(cu->instruction_set)).Int32Value();
Andreas Gampeccc60262014-07-04 18:02:38 -0700503 // Get the compiled code address [use *alt_from or kArg0, set kInvokeTgt]
Mathieu Chartier2d721012014-11-10 11:08:06 -0800504 cg->LoadWordDisp(alt_from == nullptr ? cg->TargetReg(kArg0, kRef) : *alt_from, offset,
Andreas Gampeccc60262014-07-04 18:02:38 -0700505 cg->TargetPtrReg(kInvokeTgt));
506 return true;
507 }
508 return false;
509}
510
Brian Carlstrom7940e442013-07-12 13:46:57 -0700511/*
512 * Bit of a hack here - in the absence of a real scheduling pass,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700513 * emit the next instruction in a virtual invoke sequence.
514 * We can use kLr as a temp prior to target address loading
515 * Note also that we'll load the first argument ("this") into
Serguei Katkov717a3e42014-11-13 17:19:42 +0600516 * kArg1 here rather than the standard GenDalvikArgs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700517 */
518static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
519 int state, const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700520 uint32_t method_idx, uintptr_t, uintptr_t,
521 InvokeType) {
522 UNUSED(target_method);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700523 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
524 /*
525 * This is the fast path in which the target virtual method is
526 * fully resolved at compile time.
527 */
528 switch (state) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700529 case 0:
530 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Brian Carlstrom7940e442013-07-12 13:46:57 -0700531 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700532 case 1:
533 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
534 // Includes a null-check.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700535 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700536 case 2: {
537 // Get this->klass_.embedded_vtable[method_idx] [usr kArg0, set kArg0]
538 int32_t offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
539 method_idx * sizeof(mirror::Class::VTableEntry);
540 // Load target method from embedded vtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700541 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700542 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700543 }
544 case 3:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700545 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(nullptr, cu, cg)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700546 break; // kInvokeTgt := kArg0->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700547 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700548 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
549 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700550 default:
551 return -1;
552 }
553 return state + 1;
554}
555
556/*
Jeff Hao88474b42013-10-23 16:24:40 -0700557 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
558 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
559 * 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 +0600560 * argument ("this") into kArg1 here rather than the standard GenDalvikArgs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700561 */
562static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
563 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700564 uint32_t method_idx, uintptr_t, uintptr_t, InvokeType) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700565 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700566
Jeff Hao88474b42013-10-23 16:24:40 -0700567 switch (state) {
568 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700569 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Andreas Gampeccc60262014-07-04 18:02:38 -0700570 cg->LoadConstant(cg->TargetReg(kHiddenArg, kNotWide), target_method.dex_method_index);
Mark Mendelld3703d82014-06-09 15:10:50 -0400571 if (cu->instruction_set == kX86) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700572 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg, kNotWide), cg->TargetReg(kHiddenArg, kNotWide));
Jeff Hao88474b42013-10-23 16:24:40 -0700573 }
574 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700575 case 1:
576 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Jeff Hao88474b42013-10-23 16:24:40 -0700577 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700578 case 2:
579 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
580 // Includes a null-check.
Jeff Hao88474b42013-10-23 16:24:40 -0700581 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700582 case 3: { // Get target method [use kInvokeTgt, set kArg0]
583 int32_t offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
584 (method_idx % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
585 // Load target method from embedded imtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700586 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Jeff Hao88474b42013-10-23 16:24:40 -0700587 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700588 }
589 case 4:
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700590 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(nullptr, cu, cg)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700591 break; // kInvokeTgt := kArg0->entrypoint
Jeff Hao88474b42013-10-23 16:24:40 -0700592 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700593 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
594 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700595 default:
596 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700597 }
598 return state + 1;
599}
600
Andreas Gampeccc60262014-07-04 18:02:38 -0700601static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info,
Andreas Gampe98430592014-07-27 19:44:50 -0700602 QuickEntrypointEnum trampoline, int state,
Andreas Gampeccc60262014-07-04 18:02:38 -0700603 const MethodReference& target_method, uint32_t method_idx) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700604 UNUSED(info, method_idx);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700605 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Andreas Gampe98430592014-07-27 19:44:50 -0700606
Brian Carlstrom7940e442013-07-12 13:46:57 -0700607 /*
608 * This handles the case in which the base method is not fully
609 * resolved at compile time, we bail to a runtime helper.
610 */
611 if (state == 0) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700612 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700613 // Load trampoline target
Andreas Gampe98430592014-07-27 19:44:50 -0700614 int32_t disp;
615 if (cu->target64) {
616 disp = GetThreadOffset<8>(trampoline).Int32Value();
617 } else {
618 disp = GetThreadOffset<4>(trampoline).Int32Value();
619 }
620 cg->LoadWordDisp(cg->TargetPtrReg(kSelf), disp, cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700621 }
622 // Load kArg0 with method index
623 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampeccc60262014-07-04 18:02:38 -0700624 cg->LoadConstant(cg->TargetReg(kArg0, kNotWide), target_method.dex_method_index);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700625 return 1;
626 }
627 return -1;
628}
629
630static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
631 int state,
632 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700633 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700634 return NextInvokeInsnSP(cu, info, kQuickInvokeStaticTrampolineWithAccessCheck, state,
635 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700636}
637
638static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
639 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700640 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700641 return NextInvokeInsnSP(cu, info, kQuickInvokeDirectTrampolineWithAccessCheck, state,
642 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700643}
644
645static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
646 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700647 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700648 return NextInvokeInsnSP(cu, info, kQuickInvokeSuperTrampolineWithAccessCheck, state,
649 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700650}
651
652static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
653 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700654 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700655 return NextInvokeInsnSP(cu, info, kQuickInvokeVirtualTrampolineWithAccessCheck, state,
656 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700657}
658
659static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
660 CallInfo* info, int state,
661 const MethodReference& target_method,
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700662 uint32_t, uintptr_t, uintptr_t, InvokeType) {
Andreas Gampe98430592014-07-27 19:44:50 -0700663 return NextInvokeInsnSP(cu, info, kQuickInvokeInterfaceTrampolineWithAccessCheck, state,
664 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700665}
666
Dave Allison69dfe512014-07-11 17:11:58 +0000667// Default implementation of implicit null pointer check.
668// Overridden by arch specific as necessary.
669void Mir2Lir::GenImplicitNullCheck(RegStorage reg, int opt_flags) {
670 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
671 return;
672 }
673 RegStorage tmp = AllocTemp();
674 Load32Disp(reg, 0, tmp);
675 MarkPossibleNullPointerException(opt_flags);
676 FreeTemp(tmp);
677}
678
Serguei Katkov717a3e42014-11-13 17:19:42 +0600679/**
680 * @brief Used to flush promoted registers if they are used as argument
681 * in an invocation.
682 * @param info the infromation about arguments for invocation.
683 * @param start the first argument we should start to look from.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700684 */
Serguei Katkov717a3e42014-11-13 17:19:42 +0600685void Mir2Lir::GenDalvikArgsFlushPromoted(CallInfo* info, int start) {
686 if (cu_->disable_opt & (1 << kPromoteRegs)) {
687 // This make sense only if promotion is enabled.
688 return;
689 }
690 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700691 // Scan the rest of the args - if in phys_reg flush to memory
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000692 for (size_t next_arg = start; next_arg < info->num_arg_words;) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700693 RegLocation loc = info->args[next_arg];
694 if (loc.wide) {
695 loc = UpdateLocWide(loc);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600696 if (loc.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700697 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700698 }
699 next_arg += 2;
700 } else {
701 loc = UpdateLoc(loc);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600702 if (loc.location == kLocPhysReg) {
703 if (loc.ref) {
704 StoreRefDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, kNotVolatile);
705 } else {
706 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k32,
707 kNotVolatile);
708 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700709 }
710 next_arg++;
711 }
712 }
Serguei Katkov717a3e42014-11-13 17:19:42 +0600713}
Brian Carlstrom7940e442013-07-12 13:46:57 -0700714
Serguei Katkov717a3e42014-11-13 17:19:42 +0600715/**
716 * @brief Used to optimize the copying of VRs which are arguments of invocation.
717 * Please note that you should flush promoted registers first if you copy.
718 * If implementation does copying it may skip several of the first VRs but must copy
719 * till the end. Implementation must return the number of skipped VRs
720 * (it might be all VRs).
721 * @see GenDalvikArgsFlushPromoted
722 * @param info the information about arguments for invocation.
723 * @param first the first argument we should start to look from.
724 * @param count the number of remaining arguments we can handle.
725 * @return the number of arguments which we did not handle. Unhandled arguments
726 * must be attached to the first one.
727 */
728int Mir2Lir::GenDalvikArgsBulkCopy(CallInfo* info, int first, int count) {
729 // call is pretty expensive, let's use it if count is big.
730 if (count > 16) {
731 GenDalvikArgsFlushPromoted(info, first);
732 int start_offset = SRegOffset(info->args[first].s_reg_low);
733 int outs_offset = StackVisitor::GetOutVROffset(first, cu_->instruction_set);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800734
Andreas Gampeccc60262014-07-04 18:02:38 -0700735 OpRegRegImm(kOpAdd, TargetReg(kArg0, kRef), TargetPtrReg(kSp), outs_offset);
736 OpRegRegImm(kOpAdd, TargetReg(kArg1, kRef), TargetPtrReg(kSp), start_offset);
Andreas Gampe98430592014-07-27 19:44:50 -0700737 CallRuntimeHelperRegRegImm(kQuickMemcpy, TargetReg(kArg0, kRef), TargetReg(kArg1, kRef),
Serguei Katkov717a3e42014-11-13 17:19:42 +0600738 count * 4, false);
739 count = 0;
740 }
741 return count;
742}
743
744int Mir2Lir::GenDalvikArgs(CallInfo* info, int call_state,
745 LIR** pcrLabel, NextCallInsn next_call_insn,
746 const MethodReference& target_method,
747 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
748 InvokeType type, bool skip_this) {
749 // If no arguments, just return.
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000750 if (info->num_arg_words == 0u)
Serguei Katkov717a3e42014-11-13 17:19:42 +0600751 return call_state;
752
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000753 const size_t start_index = skip_this ? 1 : 0;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600754
755 // Get architecture dependent mapping between output VRs and physical registers
756 // basing on shorty of method to call.
757 InToRegStorageMapping in_to_reg_storage_mapping(arena_);
758 {
759 const char* target_shorty = mir_graph_->GetShortyFromMethodReference(target_method);
760 ShortyIterator shorty_iterator(target_shorty, type == kStatic);
761 in_to_reg_storage_mapping.Initialize(&shorty_iterator, GetResetedInToRegStorageMapper());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700762 }
763
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000764 size_t stack_map_start = std::max(in_to_reg_storage_mapping.GetEndMappedIn(), start_index);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600765 if ((stack_map_start < info->num_arg_words) && info->args[stack_map_start].high_word) {
766 // It is possible that the last mapped reg is 32 bit while arg is 64-bit.
767 // It will be handled together with low part mapped to register.
768 stack_map_start++;
769 }
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000770 size_t regs_left_to_pass_via_stack = info->num_arg_words - stack_map_start;
Serguei Katkov717a3e42014-11-13 17:19:42 +0600771
772 // If it is a range case we can try to copy remaining VRs (not mapped to physical registers)
773 // using more optimal algorithm.
774 if (info->is_range && regs_left_to_pass_via_stack > 1) {
775 regs_left_to_pass_via_stack = GenDalvikArgsBulkCopy(info, stack_map_start,
776 regs_left_to_pass_via_stack);
777 }
778
779 // Now handle any remaining VRs mapped to stack.
780 if (in_to_reg_storage_mapping.HasArgumentsOnStack()) {
781 // Two temps but do not use kArg1, it might be this which we can skip.
782 // Separate single and wide - it can give some advantage.
783 RegStorage regRef = TargetReg(kArg3, kRef);
784 RegStorage regSingle = TargetReg(kArg3, kNotWide);
785 RegStorage regWide = TargetReg(kArg2, kWide);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000786 for (size_t i = start_index; i < stack_map_start + regs_left_to_pass_via_stack; i++) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600787 RegLocation rl_arg = info->args[i];
788 rl_arg = UpdateRawLoc(rl_arg);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000789 RegStorage reg = in_to_reg_storage_mapping.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600790 if (!reg.Valid()) {
791 int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
792 {
793 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
794 if (rl_arg.wide) {
795 if (rl_arg.location == kLocPhysReg) {
796 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k64, kNotVolatile);
797 } else {
798 LoadValueDirectWideFixed(rl_arg, regWide);
799 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regWide, k64, kNotVolatile);
800 }
801 } else {
802 if (rl_arg.location == kLocPhysReg) {
803 if (rl_arg.ref) {
804 StoreRefDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, kNotVolatile);
805 } else {
806 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k32, kNotVolatile);
807 }
808 } else {
809 if (rl_arg.ref) {
810 LoadValueDirectFixed(rl_arg, regRef);
811 StoreRefDisp(TargetPtrReg(kSp), out_offset, regRef, kNotVolatile);
812 } else {
813 LoadValueDirectFixed(rl_arg, regSingle);
814 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regSingle, k32, kNotVolatile);
815 }
816 }
817 }
818 }
819 call_state = next_call_insn(cu_, info, call_state, target_method,
820 vtable_idx, direct_code, direct_method, type);
821 }
822 if (rl_arg.wide) {
823 i++;
824 }
825 }
826 }
827
828 // Finish with VRs mapped to physical registers.
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000829 for (size_t i = start_index; i < stack_map_start; i++) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600830 RegLocation rl_arg = info->args[i];
831 rl_arg = UpdateRawLoc(rl_arg);
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000832 RegStorage reg = in_to_reg_storage_mapping.GetReg(i);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600833 if (reg.Valid()) {
834 if (rl_arg.wide) {
835 // if reg is not 64-bit (it is half of 64-bit) then handle it separately.
836 if (!reg.Is64Bit()) {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600837 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
838 if (rl_arg.location == kLocPhysReg) {
839 int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000840 // Dump it to memory.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600841 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k64, kNotVolatile);
842 LoadBaseDisp(TargetPtrReg(kSp), out_offset, reg, k32, kNotVolatile);
843 } else {
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000844 int high_offset = StackVisitor::GetOutVROffset(i + 1, cu_->instruction_set);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600845 // First, use target reg for high part.
846 LoadBaseDisp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low + 1), reg, k32,
847 kNotVolatile);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000848 StoreBaseDisp(TargetPtrReg(kSp), high_offset, reg, k32, kNotVolatile);
849 // Now, use target reg for low part.
Serguei Katkov717a3e42014-11-13 17:19:42 +0600850 LoadBaseDisp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low), reg, k32, kNotVolatile);
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000851 int low_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
852 // And store it to the expected memory location.
853 StoreBaseDisp(TargetPtrReg(kSp), low_offset, reg, k32, kNotVolatile);
Serguei Katkov717a3e42014-11-13 17:19:42 +0600854 }
855 } else {
856 LoadValueDirectWideFixed(rl_arg, reg);
857 }
858 } else {
859 LoadValueDirectFixed(rl_arg, reg);
860 }
861 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
862 direct_code, direct_method, type);
863 }
864 if (rl_arg.wide) {
865 i++;
866 }
867 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700868
869 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
870 direct_code, direct_method, type);
871 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +0000872 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700873 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700874 } else {
875 *pcrLabel = nullptr;
Dave Allison69dfe512014-07-11 17:11:58 +0000876 GenImplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700877 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700878 }
879 return call_state;
880}
881
Vladimir Marko6ce3eba2015-02-16 13:05:59 +0000882void Mir2Lir::EnsureInitializedArgMappingToPhysicalReg() {
Serguei Katkov717a3e42014-11-13 17:19:42 +0600883 if (!in_to_reg_storage_mapping_.IsInitialized()) {
884 ShortyIterator shorty_iterator(cu_->shorty, cu_->invoke_type == kStatic);
885 in_to_reg_storage_mapping_.Initialize(&shorty_iterator, GetResetedInToRegStorageMapper());
886 }
Serguei Katkov717a3e42014-11-13 17:19:42 +0600887}
888
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700889RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700890 RegLocation res;
891 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -0700892 // If result is unused, return a sink target based on type of invoke target.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800893 res = GetReturn(
894 ShortyToRegClass(mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700895 } else {
896 res = info->result;
897 }
898 return res;
899}
900
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700901RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700902 RegLocation res;
903 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -0700904 // If result is unused, return a sink target based on type of invoke target.
Mathieu Chartiere5f13e52015-02-24 09:37:21 -0800905 res = GetReturnWide(ShortyToRegClass(
906 mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700907 } else {
908 res = info->result;
909 }
910 return res;
911}
912
Mathieu Chartiercd48f2d2014-09-09 13:51:09 -0700913bool Mir2Lir::GenInlinedReferenceGetReferent(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +0100914 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
915 // TODO: add Mips and Mips64 implementations.
Fred Shih4ee7a662014-07-11 09:59:27 -0700916 return false;
917 }
918
Fred Shih4ee7a662014-07-11 09:59:27 -0700919 bool use_direct_type_ptr;
920 uintptr_t direct_type_ptr;
Fred Shihe7f82e22014-08-06 10:46:37 -0700921 ClassReference ref;
922 if (!cu_->compiler_driver->CanEmbedReferenceTypeInCode(&ref,
923 &use_direct_type_ptr, &direct_type_ptr)) {
924 return false;
925 }
926
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700927 RegStorage reg_class = TargetReg(kArg1, kRef);
928 Clobber(reg_class);
929 LockTemp(reg_class);
Fred Shih4ee7a662014-07-11 09:59:27 -0700930 if (use_direct_type_ptr) {
931 LoadConstant(reg_class, direct_type_ptr);
Alex Lighteb76e112014-07-29 15:22:40 -0700932 } else {
Fred Shihe7f82e22014-08-06 10:46:37 -0700933 uint16_t type_idx = ref.first->GetClassDef(ref.second).class_idx_;
934 LoadClassType(*ref.first, type_idx, kArg1);
Fred Shih4ee7a662014-07-11 09:59:27 -0700935 }
Fred Shih4ee7a662014-07-11 09:59:27 -0700936
Fred Shihe7f82e22014-08-06 10:46:37 -0700937 uint32_t slow_path_flag_offset = cu_->compiler_driver->GetReferenceSlowFlagOffset();
938 uint32_t disable_flag_offset = cu_->compiler_driver->GetReferenceDisableFlagOffset();
Fred Shih4ee7a662014-07-11 09:59:27 -0700939 CHECK(slow_path_flag_offset && disable_flag_offset &&
940 (slow_path_flag_offset != disable_flag_offset));
941
942 // intrinsic logic start.
943 RegLocation rl_obj = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -0700944 rl_obj = LoadValue(rl_obj, kRefReg);
Fred Shih4ee7a662014-07-11 09:59:27 -0700945
946 RegStorage reg_slow_path = AllocTemp();
947 RegStorage reg_disabled = AllocTemp();
Andreas Gampef6815702015-01-20 09:53:48 -0800948 LoadBaseDisp(reg_class, slow_path_flag_offset, reg_slow_path, kSignedByte, kNotVolatile);
949 LoadBaseDisp(reg_class, disable_flag_offset, reg_disabled, kSignedByte, kNotVolatile);
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700950 FreeTemp(reg_class);
951 LIR* or_inst = OpRegRegReg(kOpOr, reg_slow_path, reg_slow_path, reg_disabled);
Fred Shih4ee7a662014-07-11 09:59:27 -0700952 FreeTemp(reg_disabled);
953
954 // if slow path, jump to JNI path target
Andreas Gampe30ab8a82014-07-17 00:12:32 -0700955 LIR* slow_path_branch;
956 if (or_inst->u.m.def_mask->HasBit(ResourceMask::kCCode)) {
957 // Generate conditional branch only, as the OR set a condition state (we are interested in a 'Z' flag).
958 slow_path_branch = OpCondBranch(kCondNe, nullptr);
959 } else {
960 // Generate compare and branch.
961 slow_path_branch = OpCmpImmBranch(kCondNe, reg_slow_path, 0, nullptr);
962 }
Fred Shih4ee7a662014-07-11 09:59:27 -0700963 FreeTemp(reg_slow_path);
964
965 // slow path not enabled, simply load the referent of the reference object
966 RegLocation rl_dest = InlineTarget(info);
967 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
968 GenNullCheck(rl_obj.reg, info->opt_flags);
969 LoadRefDisp(rl_obj.reg, mirror::Reference::ReferentOffset().Int32Value(), rl_result.reg,
970 kNotVolatile);
971 MarkPossibleNullPointerException(info->opt_flags);
972 StoreValue(rl_dest, rl_result);
973
974 LIR* intrinsic_finish = NewLIR0(kPseudoTargetLabel);
975 AddIntrinsicSlowPath(info, slow_path_branch, intrinsic_finish);
Serguei Katkov9863daf2014-09-04 15:21:32 +0700976 ClobberCallerSave(); // We must clobber everything because slow path will return here
Fred Shih4ee7a662014-07-11 09:59:27 -0700977 return true;
978}
979
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700980bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Jeff Hao848f70a2014-01-15 13:49:50 -0800981 // Location of char array data
Brian Carlstrom7940e442013-07-12 13:46:57 -0700982 int value_offset = mirror::String::ValueOffset().Int32Value();
983 // Location of count
984 int count_offset = mirror::String::CountOffset().Int32Value();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700985
986 RegLocation rl_obj = info->args[0];
987 RegLocation rl_idx = info->args[1];
buzbeea0cd2d72014-06-01 09:33:49 -0700988 rl_obj = LoadValue(rl_obj, kRefReg);
Andreas Gampe98430592014-07-27 19:44:50 -0700989 rl_idx = LoadValue(rl_idx, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -0800990 RegStorage reg_max;
991 GenNullCheck(rl_obj.reg, info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700992 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +0000993 LIR* range_check_branch = nullptr;
Andreas Gampe98430592014-07-27 19:44:50 -0700994 if (range_check) {
995 reg_max = AllocTemp();
996 Load32Disp(rl_obj.reg, count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -0800997 MarkPossibleNullPointerException(info->opt_flags);
Jeff Hao848f70a2014-01-15 13:49:50 -0800998 // Set up a slow path to allow retry in case of bounds violation
Andreas Gampe98430592014-07-27 19:44:50 -0700999 OpRegReg(kOpCmp, rl_idx.reg, reg_max);
1000 FreeTemp(reg_max);
1001 range_check_branch = OpCondBranch(kCondUge, nullptr);
1002 }
Jeff Hao848f70a2014-01-15 13:49:50 -08001003 RegStorage reg_ptr = AllocTempRef();
1004 OpRegRegImm(kOpAdd, reg_ptr, rl_obj.reg, value_offset);
buzbee2700f7e2014-03-07 09:46:20 -08001005 FreeTemp(rl_obj.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001006 RegLocation rl_dest = InlineTarget(info);
1007 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Jeff Hao848f70a2014-01-15 13:49:50 -08001008 LoadBaseIndexed(reg_ptr, rl_idx.reg, rl_result.reg, 1, kUnsignedHalf);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001009 FreeTemp(reg_ptr);
1010 StoreValue(rl_dest, rl_result);
1011 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001012 DCHECK(range_check_branch != nullptr);
1013 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001014 AddIntrinsicSlowPath(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001015 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001016 return true;
1017}
1018
Jeff Hao848f70a2014-01-15 13:49:50 -08001019bool Mir2Lir::GenInlinedStringGetCharsNoCheck(CallInfo* info) {
1020 if (cu_->instruction_set == kMips) {
1021 // TODO - add Mips implementation
1022 return false;
1023 }
1024 size_t char_component_size = Primitive::ComponentSize(Primitive::kPrimChar);
1025 // Location of data in char array buffer
1026 int data_offset = mirror::Array::DataOffset(char_component_size).Int32Value();
1027 // Location of char array data in string
1028 int value_offset = mirror::String::ValueOffset().Int32Value();
1029
1030 RegLocation rl_obj = info->args[0];
1031 RegLocation rl_start = info->args[1];
1032 RegLocation rl_end = info->args[2];
1033 RegLocation rl_buffer = info->args[3];
1034 RegLocation rl_index = info->args[4];
1035
1036 ClobberCallerSave();
1037 LockCallTemps(); // Using fixed registers
1038 RegStorage reg_dst_ptr = TargetReg(kArg0, kRef);
1039 RegStorage reg_src_ptr = TargetReg(kArg1, kRef);
1040 RegStorage reg_length = TargetReg(kArg2, kNotWide);
1041 RegStorage reg_tmp = TargetReg(kArg3, kNotWide);
1042 RegStorage reg_tmp_ptr = RegStorage(RegStorage::k64BitSolo, reg_tmp.GetRawBits() & RegStorage::kRegTypeMask);
1043
1044 LoadValueDirectFixed(rl_buffer, reg_dst_ptr);
1045 OpRegImm(kOpAdd, reg_dst_ptr, data_offset);
1046 LoadValueDirectFixed(rl_index, reg_tmp);
1047 OpRegRegImm(kOpLsl, reg_tmp, reg_tmp, 1);
1048 OpRegReg(kOpAdd, reg_dst_ptr, cu_->instruction_set == kArm64 ? reg_tmp_ptr : reg_tmp);
1049
1050 LoadValueDirectFixed(rl_start, reg_tmp);
1051 LoadValueDirectFixed(rl_end, reg_length);
1052 OpRegReg(kOpSub, reg_length, reg_tmp);
1053 OpRegRegImm(kOpLsl, reg_length, reg_length, 1);
1054 LoadValueDirectFixed(rl_obj, reg_src_ptr);
1055
1056 OpRegImm(kOpAdd, reg_src_ptr, value_offset);
1057 OpRegRegImm(kOpLsl, reg_tmp, reg_tmp, 1);
1058 OpRegReg(kOpAdd, reg_src_ptr, cu_->instruction_set == kArm64 ? reg_tmp_ptr : reg_tmp);
1059
1060 RegStorage r_tgt;
1061 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
1062 r_tgt = LoadHelper(kQuickMemcpy);
1063 } else {
1064 r_tgt = RegStorage::InvalidReg();
1065 }
1066 // NOTE: not a safepoint
1067 CallHelper(r_tgt, kQuickMemcpy, false, true);
1068
1069 return true;
1070}
1071
Brian Carlstrom7940e442013-07-12 13:46:57 -07001072// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001073bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001074 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1075 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001076 return false;
1077 }
1078 // dst = src.length();
1079 RegLocation rl_obj = info->args[0];
buzbeea0cd2d72014-06-01 09:33:49 -07001080 rl_obj = LoadValue(rl_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001081 RegLocation rl_dest = InlineTarget(info);
1082 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001083 GenNullCheck(rl_obj.reg, info->opt_flags);
buzbee695d13a2014-04-19 13:32:20 -07001084 Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg);
Dave Allisonb373e092014-02-20 16:06:36 -08001085 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001086 if (is_empty) {
1087 // dst = (dst == 0);
1088 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001089 RegStorage t_reg = AllocTemp();
1090 OpRegReg(kOpNeg, t_reg, rl_result.reg);
1091 OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001092 } else if (cu_->instruction_set == kArm64) {
1093 OpRegImm(kOpSub, rl_result.reg, 1);
1094 OpRegRegImm(kOpLsr, rl_result.reg, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001095 } else {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001096 DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64);
buzbee2700f7e2014-03-07 09:46:20 -08001097 OpRegImm(kOpSub, rl_result.reg, 1);
1098 OpRegImm(kOpLsr, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001099 }
1100 }
1101 StoreValue(rl_dest, rl_result);
1102 return true;
1103}
1104
Jeff Hao848f70a2014-01-15 13:49:50 -08001105bool Mir2Lir::GenInlinedStringFactoryNewStringFromBytes(CallInfo* info) {
1106 if (cu_->instruction_set == kMips) {
1107 // TODO - add Mips implementation
1108 return false;
1109 }
1110 RegLocation rl_data = info->args[0];
1111 RegLocation rl_high = info->args[1];
1112 RegLocation rl_offset = info->args[2];
1113 RegLocation rl_count = info->args[3];
1114 rl_data = LoadValue(rl_data, kRefReg);
1115 LIR* data_null_check_branch = OpCmpImmBranch(kCondEq, rl_data.reg, 0, nullptr);
1116 AddIntrinsicSlowPath(info, data_null_check_branch);
1117 CallRuntimeHelperRegLocationRegLocationRegLocationRegLocation(
1118 kQuickAllocStringFromBytes, rl_data, rl_high, rl_offset, rl_count, true);
1119 RegLocation rl_return = GetReturn(kRefReg);
1120 RegLocation rl_dest = InlineTarget(info);
1121 StoreValue(rl_dest, rl_return);
1122 return true;
1123}
1124
1125bool Mir2Lir::GenInlinedStringFactoryNewStringFromChars(CallInfo* info) {
1126 if (cu_->instruction_set == kMips) {
1127 // TODO - add Mips implementation
1128 return false;
1129 }
1130 RegLocation rl_offset = info->args[0];
1131 RegLocation rl_count = info->args[1];
1132 RegLocation rl_data = info->args[2];
1133 CallRuntimeHelperRegLocationRegLocationRegLocation(
1134 kQuickAllocStringFromChars, rl_offset, rl_count, rl_data, true);
1135 RegLocation rl_return = GetReturn(kRefReg);
1136 RegLocation rl_dest = InlineTarget(info);
1137 StoreValue(rl_dest, rl_return);
1138 return true;
1139}
1140
1141bool Mir2Lir::GenInlinedStringFactoryNewStringFromString(CallInfo* info) {
1142 if (cu_->instruction_set == kMips) {
1143 // TODO - add Mips implementation
1144 return false;
1145 }
1146 RegLocation rl_string = info->args[0];
1147 rl_string = LoadValue(rl_string, kRefReg);
1148 LIR* string_null_check_branch = OpCmpImmBranch(kCondEq, rl_string.reg, 0, nullptr);
1149 AddIntrinsicSlowPath(info, string_null_check_branch);
1150 CallRuntimeHelperRegLocation(kQuickAllocStringFromString, rl_string, true);
1151 RegLocation rl_return = GetReturn(kRefReg);
1152 RegLocation rl_dest = InlineTarget(info);
1153 StoreValue(rl_dest, rl_return);
1154 return true;
1155}
1156
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001157bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001158 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1159 // TODO: add Mips and Mips64 implementations.
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001160 return false;
1161 }
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001162 RegLocation rl_dest = IsWide(size) ? InlineTargetWide(info) : InlineTarget(info); // result reg
1163 if (rl_dest.s_reg_low == INVALID_SREG) {
1164 // Result is unused, the code is dead. Inlining successful, no code generated.
1165 return true;
1166 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001167 RegLocation rl_src_i = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -07001168 RegLocation rl_i = IsWide(size) ? LoadValueWide(rl_src_i, kCoreReg) : LoadValue(rl_src_i, kCoreReg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001169 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Fred Shih37f05ef2014-07-16 18:38:08 -07001170 if (IsWide(size)) {
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001171 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Serban Constantinescu169489b2014-06-11 16:43:35 +01001172 OpRegReg(kOpRev, rl_result.reg, rl_i.reg);
1173 StoreValueWide(rl_dest, rl_result);
1174 return true;
1175 }
buzbee2700f7e2014-03-07 09:46:20 -08001176 RegStorage r_i_low = rl_i.reg.GetLow();
1177 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001178 // 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 +00001179 r_i_low = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -08001180 OpRegCopy(r_i_low, rl_i.reg);
Vladimir Markof246af22013-11-27 12:30:15 +00001181 }
buzbee2700f7e2014-03-07 09:46:20 -08001182 OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh());
1183 OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low);
1184 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001185 FreeTemp(r_i_low);
1186 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001187 StoreValueWide(rl_dest, rl_result);
1188 } else {
buzbee695d13a2014-04-19 13:32:20 -07001189 DCHECK(size == k32 || size == kSignedHalf);
1190 OpKind op = (size == k32) ? kOpRev : kOpRevsh;
buzbee2700f7e2014-03-07 09:46:20 -08001191 OpRegReg(op, rl_result.reg, rl_i.reg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001192 StoreValue(rl_dest, rl_result);
1193 }
1194 return true;
1195}
1196
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001197bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001198 RegLocation rl_dest = InlineTarget(info);
1199 if (rl_dest.s_reg_low == INVALID_SREG) {
1200 // Result is unused, the code is dead. Inlining successful, no code generated.
1201 return true;
1202 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001203 RegLocation rl_src = info->args[0];
1204 rl_src = LoadValue(rl_src, kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001205 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001206 RegStorage sign_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001207 // abs(x) = y<=x>>31, (x+y)^y.
buzbee2700f7e2014-03-07 09:46:20 -08001208 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31);
1209 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1210 OpRegReg(kOpXor, rl_result.reg, sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001211 StoreValue(rl_dest, rl_result);
1212 return true;
1213}
1214
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001215bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001216 RegLocation rl_dest = InlineTargetWide(info);
1217 if (rl_dest.s_reg_low == INVALID_SREG) {
1218 // Result is unused, the code is dead. Inlining successful, no code generated.
1219 return true;
1220 }
Vladimir Markob9823312014-03-20 17:38:43 +00001221 RegLocation rl_src = info->args[0];
1222 rl_src = LoadValueWide(rl_src, kCoreReg);
Vladimir Markob9823312014-03-20 17:38:43 +00001223 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1224
1225 // If on x86 or if we would clobber a register needed later, just copy the source first.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001226 if (cu_->instruction_set != kX86_64 &&
1227 (cu_->instruction_set == kX86 ||
1228 rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001229 OpRegCopyWide(rl_result.reg, rl_src.reg);
1230 if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() &&
1231 rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() &&
1232 rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() &&
Vladimir Markob9823312014-03-20 17:38:43 +00001233 rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) {
1234 // Reuse source registers to avoid running out of temps.
buzbee2700f7e2014-03-07 09:46:20 -08001235 FreeTemp(rl_src.reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001236 }
1237 rl_src = rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001238 }
Vladimir Markob9823312014-03-20 17:38:43 +00001239
1240 // abs(x) = y<=x>>31, (x+y)^y.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001241 RegStorage sign_reg;
1242 if (cu_->instruction_set == kX86_64) {
1243 sign_reg = AllocTempWide();
1244 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 63);
1245 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1246 OpRegReg(kOpXor, rl_result.reg, sign_reg);
1247 } else {
1248 sign_reg = AllocTemp();
1249 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31);
1250 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg);
1251 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg);
1252 OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg);
1253 OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg);
1254 }
buzbee082833c2014-05-17 23:16:26 -07001255 FreeTemp(sign_reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001256 StoreValueWide(rl_dest, rl_result);
1257 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001258}
1259
Serban Constantinescu23abec92014-07-02 16:13:38 +01001260bool Mir2Lir::GenInlinedReverseBits(CallInfo* info, OpSize size) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001261 // Currently implemented only for ARM64.
1262 UNUSED(info, size);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001263 return false;
1264}
1265
1266bool Mir2Lir::GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001267 // Currently implemented only for ARM64.
1268 UNUSED(info, is_min, is_double);
Serban Constantinescu23abec92014-07-02 16:13:38 +01001269 return false;
1270}
1271
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001272bool Mir2Lir::GenInlinedCeil(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001273 UNUSED(info);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001274 return false;
1275}
1276
1277bool Mir2Lir::GenInlinedFloor(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001278 UNUSED(info);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001279 return false;
1280}
1281
1282bool Mir2Lir::GenInlinedRint(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001283 UNUSED(info);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001284 return false;
1285}
1286
1287bool Mir2Lir::GenInlinedRound(CallInfo* info, bool is_double) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001288 UNUSED(info, is_double);
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001289 return false;
1290}
1291
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001292bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001293 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1294 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001295 return false;
1296 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001297 RegLocation rl_dest = InlineTarget(info);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001298 if (rl_dest.s_reg_low == INVALID_SREG) {
1299 // Result is unused, the code is dead. Inlining successful, no code generated.
1300 return true;
1301 }
1302 RegLocation rl_src = info->args[0];
Brian Carlstrom7940e442013-07-12 13:46:57 -07001303 StoreValue(rl_dest, rl_src);
1304 return true;
1305}
1306
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001307bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001308 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1309 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001310 return false;
1311 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001312 RegLocation rl_dest = InlineTargetWide(info);
Chao-ying Fuff87d7b2015-01-19 15:51:57 -08001313 if (rl_dest.s_reg_low == INVALID_SREG) {
1314 // Result is unused, the code is dead. Inlining successful, no code generated.
1315 return true;
1316 }
1317 RegLocation rl_src = info->args[0];
Brian Carlstrom7940e442013-07-12 13:46:57 -07001318 StoreValueWide(rl_dest, rl_src);
1319 return true;
1320}
1321
DaniilSokolov70c4f062014-06-24 17:34:00 -07001322bool Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001323 UNUSED(info);
DaniilSokolov70c4f062014-06-24 17:34:00 -07001324 return false;
1325}
1326
1327
Brian Carlstrom7940e442013-07-12 13:46:57 -07001328/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001329 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001330 * otherwise bails to standard library code.
1331 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001332bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001333 RegLocation rl_obj = info->args[0];
1334 RegLocation rl_char = info->args[1];
1335 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1336 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1337 return false;
1338 }
1339
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001340 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001341 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001342 RegStorage reg_ptr = TargetReg(kArg0, kRef);
1343 RegStorage reg_char = TargetReg(kArg1, kNotWide);
1344 RegStorage reg_start = TargetReg(kArg2, kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001345
Brian Carlstrom7940e442013-07-12 13:46:57 -07001346 LoadValueDirectFixed(rl_obj, reg_ptr);
1347 LoadValueDirectFixed(rl_char, reg_char);
1348 if (zero_based) {
1349 LoadConstant(reg_start, 0);
1350 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001351 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001352 LoadValueDirectFixed(rl_start, reg_start);
1353 }
Andreas Gampe98430592014-07-27 19:44:50 -07001354 RegStorage r_tgt = LoadHelper(kQuickIndexOf);
Dave Allisonf9439142014-03-27 15:10:22 -07001355 GenExplicitNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001356 LIR* high_code_point_branch =
1357 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001358 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001359 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001360 if (!rl_char.is_const) {
1361 // Add the slow path for code points beyond 0xFFFF.
1362 DCHECK(high_code_point_branch != nullptr);
1363 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1364 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001365 AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt);
Serguei Katkov9863daf2014-09-04 15:21:32 +07001366 ClobberCallerSave(); // We must clobber everything because slow path will return here
Vladimir Marko3bc86152014-03-13 14:11:28 +00001367 } else {
1368 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1369 DCHECK(high_code_point_branch == nullptr);
1370 }
buzbeea0cd2d72014-06-01 09:33:49 -07001371 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001372 RegLocation rl_dest = InlineTarget(info);
1373 StoreValue(rl_dest, rl_return);
1374 return true;
1375}
1376
1377/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001378bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001379 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1380 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001381 return false;
1382 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001383 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001384 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001385 RegStorage reg_this = TargetReg(kArg0, kRef);
1386 RegStorage reg_cmp = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001387
1388 RegLocation rl_this = info->args[0];
1389 RegLocation rl_cmp = info->args[1];
1390 LoadValueDirectFixed(rl_this, reg_this);
1391 LoadValueDirectFixed(rl_cmp, reg_cmp);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001392 RegStorage r_tgt;
1393 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Andreas Gampe98430592014-07-27 19:44:50 -07001394 r_tgt = LoadHelper(kQuickStringCompareTo);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001395 } else {
1396 r_tgt = RegStorage::InvalidReg();
1397 }
Dave Allisonf9439142014-03-27 15:10:22 -07001398 GenExplicitNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001399 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001400 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001401 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
Mingyao Yang3a74d152014-04-21 15:39:44 -07001402 AddIntrinsicSlowPath(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001403 // NOTE: not a safepoint
Andreas Gampe98430592014-07-27 19:44:50 -07001404 CallHelper(r_tgt, kQuickStringCompareTo, false, true);
buzbeea0cd2d72014-06-01 09:33:49 -07001405 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001406 RegLocation rl_dest = InlineTarget(info);
1407 StoreValue(rl_dest, rl_return);
1408 return true;
1409}
1410
1411bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1412 RegLocation rl_dest = InlineTarget(info);
Andreas Gampe7a949612014-07-08 11:03:59 -07001413
1414 // Early exit if the result is unused.
1415 if (rl_dest.orig_sreg < 0) {
1416 return true;
1417 }
1418
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001419 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001420
Andreas Gamped500b532015-01-16 22:09:55 -08001421 if (Is64BitInstructionSet(cu_->instruction_set)) {
1422 LoadRefDisp(TargetPtrReg(kSelf), Thread::PeerOffset<8>().Int32Value(), rl_result.reg,
1423 kNotVolatile);
1424 } else {
1425 Load32Disp(TargetPtrReg(kSelf), Thread::PeerOffset<4>().Int32Value(), rl_result.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001426 }
Andreas Gamped500b532015-01-16 22:09:55 -08001427
Brian Carlstrom7940e442013-07-12 13:46:57 -07001428 StoreValue(rl_dest, rl_result);
1429 return true;
1430}
1431
1432bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
Vladimir Markofac10702015-04-22 11:51:52 +01001433 bool is_long, bool is_object, bool is_volatile) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001434 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1435 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001436 return false;
1437 }
1438 // Unused - RegLocation rl_src_unsafe = info->args[0];
1439 RegLocation rl_src_obj = info->args[1]; // Object
1440 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001441 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001442 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001443
buzbeea0cd2d72014-06-01 09:33:49 -07001444 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001445 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
Vladimir Markofac10702015-04-22 11:51:52 +01001446 RegLocation rl_result = EvalLoc(rl_dest, is_object ? kRefReg : kCoreReg, true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001447 if (is_long) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001448 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1449 || cu_->instruction_set == kArm64) {
1450 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001451 } else {
1452 RegStorage rl_temp_offset = AllocTemp();
1453 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001454 LoadBaseDisp(rl_temp_offset, 0, rl_result.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001455 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001456 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001457 } else {
Matteo Franchin255e0142014-07-04 13:50:41 +01001458 if (rl_result.ref) {
1459 LoadRefIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0);
1460 } else {
1461 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32);
1462 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001463 }
1464
1465 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001466 GenMemBarrier(kLoadAny);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001467 }
1468
1469 if (is_long) {
1470 StoreValueWide(rl_dest, rl_result);
1471 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001472 StoreValue(rl_dest, rl_result);
1473 }
1474 return true;
1475}
1476
1477bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1478 bool is_object, bool is_volatile, bool is_ordered) {
Maja Gagic6ea651f2015-02-24 16:55:04 +01001479 if (cu_->instruction_set == kMips || cu_->instruction_set == kMips64) {
1480 // TODO: add Mips and Mips64 implementations.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001481 return false;
1482 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001483 // Unused - RegLocation rl_src_unsafe = info->args[0];
1484 RegLocation rl_src_obj = info->args[1]; // Object
1485 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001486 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001487 RegLocation rl_src_value = info->args[4]; // value to store
1488 if (is_volatile || is_ordered) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001489 GenMemBarrier(kAnyStore);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001490 }
buzbeea0cd2d72014-06-01 09:33:49 -07001491 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001492 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1493 RegLocation rl_value;
1494 if (is_long) {
1495 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001496 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1497 || cu_->instruction_set == kArm64) {
1498 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001499 } else {
1500 RegStorage rl_temp_offset = AllocTemp();
1501 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001502 StoreBaseDisp(rl_temp_offset, 0, rl_value.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001503 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001504 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001505 } else {
Vladimir Markofac10702015-04-22 11:51:52 +01001506 rl_value = LoadValue(rl_src_value, is_object ? kRefReg : kCoreReg);
Matteo Franchin255e0142014-07-04 13:50:41 +01001507 if (rl_value.ref) {
1508 StoreRefIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0);
1509 } else {
1510 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32);
1511 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001512 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001513
1514 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
buzbee091cc402014-03-31 10:14:40 -07001515 FreeTemp(rl_offset.reg);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001516
Brian Carlstrom7940e442013-07-12 13:46:57 -07001517 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001518 // Prevent reordering with a subsequent volatile load.
1519 // May also be needed to address store atomicity issues.
1520 GenMemBarrier(kAnyAny);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001521 }
1522 if (is_object) {
Vladimir Marko743b98c2014-11-24 19:45:41 +00001523 MarkGCCard(0, rl_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001524 }
1525 return true;
1526}
1527
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001528void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001529 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Vladimir Marko87b7c522015-04-08 10:01:01 +01001530 if (mir_graph_->GetMethodLoweringInfo(info->mir).IsIntrinsic()) {
1531 const DexFile* dex_file = info->method_ref.dex_file;
1532 auto* inliner = cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(dex_file);
1533 if (inliner->GenIntrinsic(this, info)) {
1534 return;
1535 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001536 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001537 GenInvokeNoInline(info);
1538}
1539
1540void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001541 int call_state = 0;
1542 LIR* null_ck;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001543 LIR** p_null_ck = nullptr;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001544 NextCallInsn next_call_insn;
1545 FlushAllRegs(); /* Everything to home location */
1546 // Explicit register usage
1547 LockCallTemps();
1548
Vladimir Markof096aad2014-01-23 15:51:58 +00001549 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
Jeff Hao848f70a2014-01-15 13:49:50 -08001550 MethodReference target_method = method_info.GetTargetMethod();
Vladimir Markof096aad2014-01-23 15:51:58 +00001551 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
1552 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
Vladimir Markof4da6752014-08-01 19:04:18 +01001553 info->type = method_info.GetSharpType();
Jeff Hao848f70a2014-01-15 13:49:50 -08001554 bool is_string_init = false;
1555 if (method_info.IsSpecial()) {
1556 DexFileMethodInliner* inliner = cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(
1557 target_method.dex_file);
1558 if (inliner->IsStringInitMethodIndex(target_method.dex_method_index)) {
1559 is_string_init = true;
1560 size_t pointer_size = GetInstructionSetPointerSize(cu_->instruction_set);
1561 info->string_init_offset = inliner->GetOffsetForStringInit(target_method.dex_method_index,
1562 pointer_size);
1563 info->type = kStatic;
1564 }
1565 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001566 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001567 bool skip_this;
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001568
Brian Carlstrom7940e442013-07-12 13:46:57 -07001569 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001570 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001571 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001572 } else if (info->type == kDirect) {
1573 if (fast_path) {
1574 p_null_ck = &null_ck;
1575 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001576 next_call_insn = fast_path ? GetNextSDCallInsn() : NextDirectCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001577 skip_this = false;
1578 } else if (info->type == kStatic) {
Vladimir Markof4da6752014-08-01 19:04:18 +01001579 next_call_insn = fast_path ? GetNextSDCallInsn() : NextStaticCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001580 skip_this = false;
1581 } else if (info->type == kSuper) {
1582 DCHECK(!fast_path); // Fast path is a direct call.
1583 next_call_insn = NextSuperCallInsnSP;
1584 skip_this = false;
1585 } else {
1586 DCHECK_EQ(info->type, kVirtual);
1587 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1588 skip_this = fast_path;
1589 }
Serguei Katkov717a3e42014-11-13 17:19:42 +06001590 call_state = GenDalvikArgs(info, call_state, p_null_ck,
1591 next_call_insn, target_method, method_info.VTableIndex(),
1592 method_info.DirectCode(), method_info.DirectMethod(),
1593 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001594 // Finish up any of the call sequence not interleaved in arg loading
1595 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001596 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
Mathieu Chartiere5f13e52015-02-24 09:37:21 -08001597 method_info.DirectCode(), method_info.DirectMethod(),
1598 original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001599 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001600 LIR* call_insn = GenCallInsn(method_info);
Vladimir Markof4da6752014-08-01 19:04:18 +01001601 MarkSafepointPC(call_insn);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001602
Vladimir Markobfe400b2014-12-19 19:27:26 +00001603 FreeCallTemps();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001604 if (info->result.location != kLocInvalid) {
1605 // We have a following MOVE_RESULT - do it now.
Jeff Hao848f70a2014-01-15 13:49:50 -08001606 RegisterClass reg_class = is_string_init ? kRefReg :
Vladimir Markofac10702015-04-22 11:51:52 +01001607 ShortyToRegClass(mir_graph_->GetShortyFromMethodReference(info->method_ref)[0]);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001608 if (info->result.wide) {
Vladimir Markofac10702015-04-22 11:51:52 +01001609 RegLocation ret_loc = GetReturnWide(reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001610 StoreValueWide(info->result, ret_loc);
1611 } else {
Vladimir Markofac10702015-04-22 11:51:52 +01001612 RegLocation ret_loc = GetReturn(reg_class);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001613 StoreValue(info->result, ret_loc);
1614 }
1615 }
1616}
1617
Brian Carlstrom7940e442013-07-12 13:46:57 -07001618} // namespace art