blob: bc4d00b6cdbe7f441f3a98dc068dd4bbcdfea2c0 [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
Vladimir Markof4da6752014-08-01 19:04:18 +010017#include "arm/codegen_arm.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070018#include "dex/compiler_ir.h"
Vladimir Marko5c96e6b2013-11-14 15:34:17 +000019#include "dex/frontend.h"
20#include "dex/quick/dex_file_method_inliner.h"
21#include "dex/quick/dex_file_to_method_inliner_map.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070022#include "dex_file-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070023#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070024#include "invoke_type.h"
25#include "mirror/array.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070026#include "mirror/class-inl.h"
Fred Shih4ee7a662014-07-11 09:59:27 -070027#include "mirror/dex_cache.h"
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070028#include "mirror/object_array-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "mirror/string.h"
30#include "mir_to_lir-inl.h"
Vladimir Markof4da6752014-08-01 19:04:18 +010031#include "scoped_thread_state_change.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070032
33namespace art {
34
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070035// Shortcuts to repeatedly used long types.
36typedef mirror::ObjectArray<mirror::Object> ObjArray;
37
Brian Carlstrom7940e442013-07-12 13:46:57 -070038/*
39 * This source files contains "gen" codegen routines that should
40 * be applicable to most targets. Only mid-level support utilities
41 * and "op" calls may be used here.
42 */
43
Mingyao Yang3a74d152014-04-21 15:39:44 -070044void Mir2Lir::AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume) {
45 class IntrinsicSlowPathPath : public Mir2Lir::LIRSlowPath {
Vladimir Marko3bc86152014-03-13 14:11:28 +000046 public:
Mingyao Yang3a74d152014-04-21 15:39:44 -070047 IntrinsicSlowPathPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr)
Vladimir Marko3bc86152014-03-13 14:11:28 +000048 : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) {
49 }
50
51 void Compile() {
52 m2l_->ResetRegPool();
53 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -070054 GenerateTargetLabel(kPseudoIntrinsicRetry);
Vladimir Marko3bc86152014-03-13 14:11:28 +000055 // NOTE: GenInvokeNoInline() handles MarkSafepointPC.
56 m2l_->GenInvokeNoInline(info_);
57 if (cont_ != nullptr) {
58 m2l_->OpUnconditionalBranch(cont_);
59 }
60 }
61
62 private:
63 CallInfo* const info_;
64 };
65
Mingyao Yang3a74d152014-04-21 15:39:44 -070066 AddSlowPath(new (arena_) IntrinsicSlowPathPath(this, info, branch, resume));
Vladimir Marko3bc86152014-03-13 14:11:28 +000067}
68
Brian Carlstrom7940e442013-07-12 13:46:57 -070069/*
70 * To save scheduling time, helper calls are broken into two parts: generation of
Dave Allisond6ed6422014-04-09 23:36:15 +000071 * the helper target address, and the actual call to the helper. Because x86
72 * has a memory call operation, part 1 is a NOP for x86. For other targets,
73 * load arguments between the two parts.
Brian Carlstrom7940e442013-07-12 13:46:57 -070074 */
Andreas Gampe2f244e92014-05-08 03:35:25 -070075// template <size_t pointer_size>
Andreas Gampe98430592014-07-27 19:44:50 -070076RegStorage Mir2Lir::CallHelperSetup(QuickEntrypointEnum trampoline) {
Andreas Gampe2f244e92014-05-08 03:35:25 -070077 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
78 return RegStorage::InvalidReg();
79 } else {
Andreas Gampe98430592014-07-27 19:44:50 -070080 return LoadHelper(trampoline);
Andreas Gampe2f244e92014-05-08 03:35:25 -070081 }
82}
83
Andreas Gampe98430592014-07-27 19:44:50 -070084LIR* Mir2Lir::CallHelper(RegStorage r_tgt, QuickEntrypointEnum trampoline, bool safepoint_pc,
85 bool use_link) {
86 LIR* call_inst = InvokeTrampoline(use_link ? kOpBlx : kOpBx, r_tgt, trampoline);
Andreas Gampe2f244e92014-05-08 03:35:25 -070087
Andreas Gampe98430592014-07-27 19:44:50 -070088 if (r_tgt.Valid()) {
Dave Allisond6ed6422014-04-09 23:36:15 +000089 FreeTemp(r_tgt);
90 }
Andreas Gampe98430592014-07-27 19:44:50 -070091
Brian Carlstrom7940e442013-07-12 13:46:57 -070092 if (safepoint_pc) {
93 MarkSafepointPC(call_inst);
94 }
95 return call_inst;
96}
97
Andreas Gampe98430592014-07-27 19:44:50 -070098void Mir2Lir::CallRuntimeHelper(QuickEntrypointEnum trampoline, bool safepoint_pc) {
99 RegStorage r_tgt = CallHelperSetup(trampoline);
Mingyao Yang42894562014-04-07 12:42:16 -0700100 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700101 CallHelper(r_tgt, trampoline, safepoint_pc);
Mingyao Yang42894562014-04-07 12:42:16 -0700102}
103
Andreas Gampe98430592014-07-27 19:44:50 -0700104void Mir2Lir::CallRuntimeHelperImm(QuickEntrypointEnum trampoline, int arg0, bool safepoint_pc) {
105 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700106 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000107 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700108 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700109}
110
Andreas Gampe98430592014-07-27 19:44:50 -0700111void Mir2Lir::CallRuntimeHelperReg(QuickEntrypointEnum trampoline, RegStorage arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700112 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700113 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700114 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000115 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700116 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700117}
118
Andreas Gampe98430592014-07-27 19:44:50 -0700119void Mir2Lir::CallRuntimeHelperRegLocation(QuickEntrypointEnum trampoline, RegLocation arg0,
120 bool safepoint_pc) {
121 RegStorage r_tgt = CallHelperSetup(trampoline);
buzbee2700f7e2014-03-07 09:46:20 -0800122 if (arg0.wide == 0) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700123 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, arg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700125 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700126 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000127 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700128 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700129}
130
Andreas Gampe98430592014-07-27 19:44:50 -0700131void Mir2Lir::CallRuntimeHelperImmImm(QuickEntrypointEnum trampoline, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700132 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700133 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700134 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
135 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000136 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700137 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700138}
139
Andreas Gampe98430592014-07-27 19:44:50 -0700140void Mir2Lir::CallRuntimeHelperImmRegLocation(QuickEntrypointEnum trampoline, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700141 RegLocation arg1, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700142 RegStorage r_tgt = CallHelperSetup(trampoline);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700143 if (arg1.wide == 0) {
Andreas Gampef9872f02014-07-01 19:00:09 -0700144 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700145 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700146 RegStorage r_tmp = TargetReg(cu_->instruction_set == kMips ? kArg2 : kArg1, kWide);
buzbee2700f7e2014-03-07 09:46:20 -0800147 LoadValueDirectWideFixed(arg1, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700149 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000150 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700151 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700152}
153
Andreas Gampe98430592014-07-27 19:44:50 -0700154void Mir2Lir::CallRuntimeHelperRegLocationImm(QuickEntrypointEnum trampoline, RegLocation arg0,
155 int arg1, bool safepoint_pc) {
156 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampef9872f02014-07-01 19:00:09 -0700157 DCHECK(!arg0.wide);
158 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
Andreas Gampeccc60262014-07-04 18:02:38 -0700159 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000160 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700161 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162}
163
Andreas Gampe98430592014-07-27 19:44:50 -0700164void Mir2Lir::CallRuntimeHelperImmReg(QuickEntrypointEnum trampoline, int arg0, RegStorage arg1,
165 bool safepoint_pc) {
166 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700167 OpRegCopy(TargetReg(kArg1, arg1.GetWideKind()), arg1);
168 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000169 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700170 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700171}
172
Andreas Gampe98430592014-07-27 19:44:50 -0700173void Mir2Lir::CallRuntimeHelperRegImm(QuickEntrypointEnum trampoline, RegStorage arg0, int arg1,
174 bool safepoint_pc) {
175 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700176 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
177 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000178 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700179 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700180}
181
Andreas Gampe98430592014-07-27 19:44:50 -0700182void Mir2Lir::CallRuntimeHelperImmMethod(QuickEntrypointEnum trampoline, int arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700183 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700184 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700185 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
186 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000187 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700188 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700189}
190
Andreas Gampe98430592014-07-27 19:44:50 -0700191void Mir2Lir::CallRuntimeHelperRegMethod(QuickEntrypointEnum trampoline, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800192 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700193 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700194 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.GetWideKind()), arg0));
195 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
196 if (r_tmp.NotExactlyEquals(arg0)) {
197 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800198 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700199 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800200 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700201 CallHelper(r_tgt, trampoline, safepoint_pc);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800202}
203
Andreas Gampe98430592014-07-27 19:44:50 -0700204void Mir2Lir::CallRuntimeHelperRegMethodRegLocation(QuickEntrypointEnum trampoline, RegStorage arg0,
205 RegLocation arg2, bool safepoint_pc) {
206 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700207 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.GetWideKind()), arg0));
208 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
209 if (r_tmp.NotExactlyEquals(arg0)) {
210 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800211 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700212 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700213 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800214 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700215 CallHelper(r_tgt, trampoline, safepoint_pc);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800216}
217
Andreas Gampe98430592014-07-27 19:44:50 -0700218void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(QuickEntrypointEnum trampoline,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700219 RegLocation arg0, RegLocation arg1,
220 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700221 RegStorage r_tgt = CallHelperSetup(trampoline);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700222 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700223 RegStorage arg0_reg = TargetReg((arg0.fp) ? kFArg0 : kArg0, arg0);
224
225 RegStorage arg1_reg;
226 if (arg1.fp == arg0.fp) {
227 arg1_reg = TargetReg((arg1.fp) ? kFArg1 : kArg1, arg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700229 arg1_reg = TargetReg((arg1.fp) ? kFArg0 : kArg0, arg1);
230 }
231
232 if (arg0.wide == 0) {
233 LoadValueDirectFixed(arg0, arg0_reg);
234 } else {
235 LoadValueDirectWideFixed(arg0, arg0_reg);
236 }
237
238 if (arg1.wide == 0) {
239 LoadValueDirectFixed(arg1, arg1_reg);
240 } else {
241 LoadValueDirectWideFixed(arg1, arg1_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700242 }
243 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700244 DCHECK(!cu_->target64);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700245 if (arg0.wide == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700246 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700247 if (arg1.wide == 0) {
248 if (cu_->instruction_set == kMips) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700249 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700250 } else {
Zheng Xu5667fdb2014-10-23 18:29:55 +0800251 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg1 : kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700252 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700253 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700254 if (cu_->instruction_set == kMips) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700255 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700256 } else {
Zheng Xu5667fdb2014-10-23 18:29:55 +0800257 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg1 : kArg1, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700258 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700259 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700260 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700261 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700262 if (arg1.wide == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700263 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700264 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700265 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700266 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700267 }
268 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000269 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700270 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700271}
272
Mingyao Yang80365d92014-04-18 12:10:58 -0700273void Mir2Lir::CopyToArgumentRegs(RegStorage arg0, RegStorage arg1) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700274 WideKind arg0_kind = arg0.GetWideKind();
275 WideKind arg1_kind = arg1.GetWideKind();
276 if (IsSameReg(arg1, TargetReg(kArg0, arg1_kind))) {
277 if (IsSameReg(arg0, TargetReg(kArg1, arg0_kind))) {
Mingyao Yang80365d92014-04-18 12:10:58 -0700278 // Swap kArg0 and kArg1 with kArg2 as temp.
Andreas Gampeccc60262014-07-04 18:02:38 -0700279 OpRegCopy(TargetReg(kArg2, arg1_kind), arg1);
280 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
281 OpRegCopy(TargetReg(kArg1, arg1_kind), TargetReg(kArg2, arg1_kind));
Mingyao Yang80365d92014-04-18 12:10:58 -0700282 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700283 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
284 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
Mingyao Yang80365d92014-04-18 12:10:58 -0700285 }
286 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700287 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
288 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
Mingyao Yang80365d92014-04-18 12:10:58 -0700289 }
290}
291
Andreas Gampe98430592014-07-27 19:44:50 -0700292void Mir2Lir::CallRuntimeHelperRegReg(QuickEntrypointEnum trampoline, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800293 RegStorage arg1, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700294 RegStorage r_tgt = CallHelperSetup(trampoline);
Mingyao Yang80365d92014-04-18 12:10:58 -0700295 CopyToArgumentRegs(arg0, arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000296 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700297 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700298}
299
Andreas Gampe98430592014-07-27 19:44:50 -0700300void Mir2Lir::CallRuntimeHelperRegRegImm(QuickEntrypointEnum trampoline, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800301 RegStorage arg1, int arg2, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700302 RegStorage r_tgt = CallHelperSetup(trampoline);
Mingyao Yang80365d92014-04-18 12:10:58 -0700303 CopyToArgumentRegs(arg0, arg1);
Andreas Gampeccc60262014-07-04 18:02:38 -0700304 LoadConstant(TargetReg(kArg2, kNotWide), arg2);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000305 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700306 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700307}
308
Andreas Gampe98430592014-07-27 19:44:50 -0700309void Mir2Lir::CallRuntimeHelperImmMethodRegLocation(QuickEntrypointEnum trampoline, int arg0,
310 RegLocation arg2, bool safepoint_pc) {
311 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700312 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Andreas Gampeccc60262014-07-04 18:02:38 -0700313 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
314 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000315 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700316 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700317}
318
Andreas Gampe98430592014-07-27 19:44:50 -0700319void Mir2Lir::CallRuntimeHelperImmMethodImm(QuickEntrypointEnum trampoline, int arg0, int arg2,
320 bool safepoint_pc) {
321 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampeccc60262014-07-04 18:02:38 -0700322 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
323 LoadConstant(TargetReg(kArg2, kNotWide), arg2);
324 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000325 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700326 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700327}
328
Andreas Gampe98430592014-07-27 19:44:50 -0700329void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(QuickEntrypointEnum trampoline, int arg0,
330 RegLocation arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700331 RegLocation arg2, bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700332 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700333 DCHECK_EQ(static_cast<unsigned int>(arg1.wide), 0U); // The static_cast works around an
334 // instantiation bug in GCC.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700335 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700336 if (arg2.wide == 0) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700337 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700338 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700339 LoadValueDirectWideFixed(arg2, TargetReg(kArg2, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700340 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700341 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000342 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700343 CallHelper(r_tgt, trampoline, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700344}
345
Andreas Gampeccc60262014-07-04 18:02:38 -0700346void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(
Andreas Gampe98430592014-07-27 19:44:50 -0700347 QuickEntrypointEnum trampoline,
Andreas Gampeccc60262014-07-04 18:02:38 -0700348 RegLocation arg0,
349 RegLocation arg1,
350 RegLocation arg2,
351 bool safepoint_pc) {
Andreas Gampe98430592014-07-27 19:44:50 -0700352 RegStorage r_tgt = CallHelperSetup(trampoline);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700353 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
354 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
355 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000356 ClobberCallerSave();
Andreas Gampe98430592014-07-27 19:44:50 -0700357 CallHelper(r_tgt, trampoline, safepoint_pc);
Ian Rogersa9a82542013-10-04 11:17:26 -0700358}
359
Brian Carlstrom7940e442013-07-12 13:46:57 -0700360/*
361 * If there are any ins passed in registers that have not been promoted
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100362 * to a callee-save register, flush them to the frame. Perform initial
Brian Carlstrom7940e442013-07-12 13:46:57 -0700363 * assignment of promoted arguments.
364 *
365 * ArgLocs is an array of location records describing the incoming arguments
366 * with one location record per word of argument.
367 */
Zheng Xu5667fdb2014-10-23 18:29:55 +0800368// TODO: Support 64-bit argument registers.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700369void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700370 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800371 * Dummy up a RegLocation for the incoming StackReference<mirror::ArtMethod>
Brian Carlstrom7940e442013-07-12 13:46:57 -0700372 * It will attempt to keep kArg0 live (or copy it to home location
373 * if promoted).
374 */
375 RegLocation rl_src = rl_method;
376 rl_src.location = kLocPhysReg;
Andreas Gampeccc60262014-07-04 18:02:38 -0700377 rl_src.reg = TargetReg(kArg0, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700378 rl_src.home = false;
buzbee091cc402014-03-31 10:14:40 -0700379 MarkLive(rl_src);
buzbeef2c3e562014-05-29 12:37:25 -0700380 StoreValue(rl_method, rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700381 // If Method* has been promoted, explicitly flush
382 if (rl_method.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700383 StoreRefDisp(TargetPtrReg(kSp), 0, rl_src.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700384 }
385
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700386 if (mir_graph_->GetNumOfInVRs() == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700387 return;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800388 }
389
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700390 int start_vreg = mir_graph_->GetFirstInVR();
Brian Carlstrom7940e442013-07-12 13:46:57 -0700391 /*
392 * Copy incoming arguments to their proper home locations.
393 * NOTE: an older version of dx had an issue in which
394 * it would reuse static method argument registers.
395 * This could result in the same Dalvik virtual register
396 * being promoted to both core and fp regs. To account for this,
397 * we only copy to the corresponding promoted physical register
398 * if it matches the type of the SSA name for the incoming
399 * argument. It is also possible that long and double arguments
400 * end up half-promoted. In those cases, we must flush the promoted
401 * half to memory as well.
402 */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100403 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700404 for (uint32_t i = 0; i < mir_graph_->GetNumOfInVRs(); i++) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700405 PromotionMap* v_map = &promotion_map_[start_vreg + i];
buzbee2700f7e2014-03-07 09:46:20 -0800406 RegStorage reg = GetArgMappingToPhysicalReg(i);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800407
buzbee2700f7e2014-03-07 09:46:20 -0800408 if (reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700409 // If arriving in register
410 bool need_flush = true;
411 RegLocation* t_loc = &ArgLocs[i];
412 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
buzbee2700f7e2014-03-07 09:46:20 -0800413 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700414 need_flush = false;
415 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
buzbeeb5860fb2014-06-21 15:31:01 -0700416 OpRegCopy(RegStorage::Solo32(v_map->fp_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700417 need_flush = false;
418 } else {
419 need_flush = true;
420 }
421
buzbeed0a03b82013-09-14 08:21:05 -0700422 // For wide args, force flush if not fully promoted
Brian Carlstrom7940e442013-07-12 13:46:57 -0700423 if (t_loc->wide) {
424 PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1);
buzbeed0a03b82013-09-14 08:21:05 -0700425 // Is only half promoted?
Brian Carlstrom7940e442013-07-12 13:46:57 -0700426 need_flush |= (p_map->core_location != v_map->core_location) ||
427 (p_map->fp_location != v_map->fp_location);
buzbeed0a03b82013-09-14 08:21:05 -0700428 if ((cu_->instruction_set == kThumb2) && t_loc->fp && !need_flush) {
429 /*
430 * In Arm, a double is represented as a pair of consecutive single float
431 * registers starting at an even number. It's possible that both Dalvik vRegs
432 * representing the incoming double were independently promoted as singles - but
433 * not in a form usable as a double. If so, we need to flush - even though the
434 * incoming arg appears fully in register. At this point in the code, both
435 * halves of the double are promoted. Make sure they are in a usable form.
436 */
437 int lowreg_index = start_vreg + i + (t_loc->high_word ? -1 : 0);
buzbeeb5860fb2014-06-21 15:31:01 -0700438 int low_reg = promotion_map_[lowreg_index].fp_reg;
439 int high_reg = promotion_map_[lowreg_index + 1].fp_reg;
buzbeed0a03b82013-09-14 08:21:05 -0700440 if (((low_reg & 0x1) != 0) || (high_reg != (low_reg + 1))) {
441 need_flush = true;
442 }
443 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700444 }
445 if (need_flush) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700446 Store32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700447 }
448 } else {
449 // If arriving in frame & promoted
450 if (v_map->core_location == kLocPhysReg) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700451 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i),
452 RegStorage::Solo32(v_map->core_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700453 }
454 if (v_map->fp_location == kLocPhysReg) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700455 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i),
456 RegStorage::Solo32(v_map->fp_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700457 }
458 }
459 }
460}
461
Andreas Gampeccc60262014-07-04 18:02:38 -0700462static void CommonCallCodeLoadThisIntoArg1(const CallInfo* info, Mir2Lir* cg) {
463 RegLocation rl_arg = info->args[0];
464 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1, kRef));
465}
466
467static void CommonCallCodeLoadClassIntoArg0(const CallInfo* info, Mir2Lir* cg) {
468 cg->GenNullCheck(cg->TargetReg(kArg1, kRef), info->opt_flags);
469 // get this->klass_ [use kArg1, set kArg0]
470 cg->LoadRefDisp(cg->TargetReg(kArg1, kRef), mirror::Object::ClassOffset().Int32Value(),
471 cg->TargetReg(kArg0, kRef),
472 kNotVolatile);
473 cg->MarkPossibleNullPointerException(info->opt_flags);
474}
475
476static bool CommonCallCodeLoadCodePointerIntoInvokeTgt(const CallInfo* info,
477 const RegStorage* alt_from,
478 const CompilationUnit* cu, Mir2Lir* cg) {
479 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
480 // Get the compiled code address [use *alt_from or kArg0, set kInvokeTgt]
481 cg->LoadWordDisp(alt_from == nullptr ? cg->TargetReg(kArg0, kRef) : *alt_from,
482 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
483 cg->TargetPtrReg(kInvokeTgt));
484 return true;
485 }
486 return false;
487}
488
Brian Carlstrom7940e442013-07-12 13:46:57 -0700489/*
490 * Bit of a hack here - in the absence of a real scheduling pass,
491 * emit the next instruction in static & direct invoke sequences.
492 */
493static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
494 int state, const MethodReference& target_method,
495 uint32_t unused,
496 uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700497 InvokeType type) {
Vladimir Markof4da6752014-08-01 19:04:18 +0100498 DCHECK(cu->instruction_set != kX86 && cu->instruction_set != kX86_64 &&
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100499 cu->instruction_set != kThumb2 && cu->instruction_set != kArm &&
500 cu->instruction_set != kArm64);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700501 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700502 if (direct_code != 0 && direct_method != 0) {
503 switch (state) {
504 case 0: // Get the current Method* [sets kArg0]
Ian Rogersff093b32014-04-30 19:04:27 -0700505 if (direct_code != static_cast<uintptr_t>(-1)) {
Vladimir Markof4da6752014-08-01 19:04:18 +0100506 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
507 } else {
Jeff Hao49161ce2014-03-12 11:05:25 -0700508 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700509 }
Ian Rogersff093b32014-04-30 19:04:27 -0700510 if (direct_method != static_cast<uintptr_t>(-1)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700511 cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700512 } else {
Jeff Hao49161ce2014-03-12 11:05:25 -0700513 cg->LoadMethodAddress(target_method, type, kArg0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700514 }
515 break;
516 default:
517 return -1;
518 }
519 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700520 RegStorage arg0_ref = cg->TargetReg(kArg0, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700521 switch (state) {
522 case 0: // Get the current Method* [sets kArg0]
523 // TUNING: we can save a reg copy if Method* has been promoted.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700524 cg->LoadCurrMethodDirect(arg0_ref);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700525 break;
526 case 1: // Get method->dex_cache_resolved_methods_
Andreas Gampe4b537a82014-06-30 22:24:53 -0700527 cg->LoadRefDisp(arg0_ref,
buzbee695d13a2014-04-19 13:32:20 -0700528 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700529 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000530 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700531 // Set up direct code if known.
532 if (direct_code != 0) {
Ian Rogersff093b32014-04-30 19:04:27 -0700533 if (direct_code != static_cast<uintptr_t>(-1)) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700534 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
Vladimir Markof4da6752014-08-01 19:04:18 +0100535 } else {
Ian Rogers83883d72013-10-21 21:07:24 -0700536 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Jeff Hao49161ce2014-03-12 11:05:25 -0700537 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700538 }
539 }
540 break;
541 case 2: // Grab target method*
542 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700543 cg->LoadRefDisp(arg0_ref,
Dmitry Petrochenko37498b62014-05-05 20:33:38 +0700544 ObjArray::OffsetOfElement(target_method.dex_method_index).Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700545 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000546 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700547 break;
548 case 3: // Grab the code from the method*
Andreas Gampeccc60262014-07-04 18:02:38 -0700549 if (direct_code == 0) {
550 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, &arg0_ref, cu, cg)) {
551 break; // kInvokeTgt := arg0_ref->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700552 }
Vladimir Markof4da6752014-08-01 19:04:18 +0100553 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700554 break;
555 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700556 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
557 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700558 default:
559 return -1;
560 }
561 }
562 return state + 1;
563}
564
565/*
566 * Bit of a hack here - in the absence of a real scheduling pass,
567 * emit the next instruction in a virtual invoke sequence.
568 * We can use kLr as a temp prior to target address loading
569 * Note also that we'll load the first argument ("this") into
570 * kArg1 here rather than the standard LoadArgRegs.
571 */
572static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
573 int state, const MethodReference& target_method,
574 uint32_t method_idx, uintptr_t unused, uintptr_t unused2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700575 InvokeType unused3) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700576 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
577 /*
578 * This is the fast path in which the target virtual method is
579 * fully resolved at compile time.
580 */
581 switch (state) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700582 case 0:
583 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Brian Carlstrom7940e442013-07-12 13:46:57 -0700584 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700585 case 1:
586 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
587 // Includes a null-check.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700588 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700589 case 2: {
590 // Get this->klass_.embedded_vtable[method_idx] [usr kArg0, set kArg0]
591 int32_t offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
592 method_idx * sizeof(mirror::Class::VTableEntry);
593 // Load target method from embedded vtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700594 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700595 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700596 }
597 case 3:
Andreas Gampeccc60262014-07-04 18:02:38 -0700598 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, nullptr, cu, cg)) {
599 break; // kInvokeTgt := kArg0->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700600 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700601 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
602 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700603 default:
604 return -1;
605 }
606 return state + 1;
607}
608
609/*
Jeff Hao88474b42013-10-23 16:24:40 -0700610 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
611 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
612 * more than one interface method map to the same index. Note also that we'll load the first
613 * argument ("this") into kArg1 here rather than the standard LoadArgRegs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700614 */
615static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
616 const MethodReference& target_method,
Jeff Hao88474b42013-10-23 16:24:40 -0700617 uint32_t method_idx, uintptr_t unused,
618 uintptr_t direct_method, InvokeType unused2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700619 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700620
Jeff Hao88474b42013-10-23 16:24:40 -0700621 switch (state) {
622 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700623 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Andreas Gampeccc60262014-07-04 18:02:38 -0700624 cg->LoadConstant(cg->TargetReg(kHiddenArg, kNotWide), target_method.dex_method_index);
Mark Mendelld3703d82014-06-09 15:10:50 -0400625 if (cu->instruction_set == kX86) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700626 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg, kNotWide), cg->TargetReg(kHiddenArg, kNotWide));
Jeff Hao88474b42013-10-23 16:24:40 -0700627 }
628 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700629 case 1:
630 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Jeff Hao88474b42013-10-23 16:24:40 -0700631 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700632 case 2:
633 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
634 // Includes a null-check.
Jeff Hao88474b42013-10-23 16:24:40 -0700635 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700636 case 3: { // Get target method [use kInvokeTgt, set kArg0]
637 int32_t offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
638 (method_idx % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
639 // Load target method from embedded imtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700640 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Jeff Hao88474b42013-10-23 16:24:40 -0700641 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700642 }
643 case 4:
Andreas Gampeccc60262014-07-04 18:02:38 -0700644 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, nullptr, cu, cg)) {
645 break; // kInvokeTgt := kArg0->entrypoint
Jeff Hao88474b42013-10-23 16:24:40 -0700646 }
Ian Rogersfc787ec2014-10-09 21:56:44 -0700647 DCHECK(cu->instruction_set == kX86 || cu->instruction_set == kX86_64);
648 FALLTHROUGH_INTENDED;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700649 default:
650 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700651 }
652 return state + 1;
653}
654
Andreas Gampeccc60262014-07-04 18:02:38 -0700655static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info,
Andreas Gampe98430592014-07-27 19:44:50 -0700656 QuickEntrypointEnum trampoline, int state,
Andreas Gampeccc60262014-07-04 18:02:38 -0700657 const MethodReference& target_method, uint32_t method_idx) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700658 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Andreas Gampe98430592014-07-27 19:44:50 -0700659
660
Brian Carlstrom7940e442013-07-12 13:46:57 -0700661 /*
662 * This handles the case in which the base method is not fully
663 * resolved at compile time, we bail to a runtime helper.
664 */
665 if (state == 0) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700666 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700667 // Load trampoline target
Andreas Gampe98430592014-07-27 19:44:50 -0700668 int32_t disp;
669 if (cu->target64) {
670 disp = GetThreadOffset<8>(trampoline).Int32Value();
671 } else {
672 disp = GetThreadOffset<4>(trampoline).Int32Value();
673 }
674 cg->LoadWordDisp(cg->TargetPtrReg(kSelf), disp, cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700675 }
676 // Load kArg0 with method index
677 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampeccc60262014-07-04 18:02:38 -0700678 cg->LoadConstant(cg->TargetReg(kArg0, kNotWide), target_method.dex_method_index);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700679 return 1;
680 }
681 return -1;
682}
683
684static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
685 int state,
686 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000687 uint32_t unused, uintptr_t unused2,
688 uintptr_t unused3, InvokeType unused4) {
Andreas Gampe98430592014-07-27 19:44:50 -0700689 return NextInvokeInsnSP(cu, info, kQuickInvokeStaticTrampolineWithAccessCheck, state,
690 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700691}
692
693static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
694 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000695 uint32_t unused, uintptr_t unused2,
696 uintptr_t unused3, InvokeType unused4) {
Andreas Gampe98430592014-07-27 19:44:50 -0700697 return NextInvokeInsnSP(cu, info, kQuickInvokeDirectTrampolineWithAccessCheck, state,
698 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700699}
700
701static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
702 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000703 uint32_t unused, uintptr_t unused2,
704 uintptr_t unused3, InvokeType unused4) {
Andreas Gampe98430592014-07-27 19:44:50 -0700705 return NextInvokeInsnSP(cu, info, kQuickInvokeSuperTrampolineWithAccessCheck, state,
706 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700707}
708
709static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
710 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000711 uint32_t unused, uintptr_t unused2,
712 uintptr_t unused3, InvokeType unused4) {
Andreas Gampe98430592014-07-27 19:44:50 -0700713 return NextInvokeInsnSP(cu, info, kQuickInvokeVirtualTrampolineWithAccessCheck, state,
714 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700715}
716
717static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
718 CallInfo* info, int state,
719 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000720 uint32_t unused, uintptr_t unused2,
721 uintptr_t unused3, InvokeType unused4) {
Andreas Gampe98430592014-07-27 19:44:50 -0700722 return NextInvokeInsnSP(cu, info, kQuickInvokeInterfaceTrampolineWithAccessCheck, state,
723 target_method, 0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700724}
725
726int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
727 NextCallInsn next_call_insn,
728 const MethodReference& target_method,
729 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700730 uintptr_t direct_method, InvokeType type, bool skip_this) {
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700731 int last_arg_reg = 3 - 1;
Andreas Gampeccc60262014-07-04 18:02:38 -0700732 int arg_regs[3] = {TargetReg(kArg1, kNotWide).GetReg(), TargetReg(kArg2, kNotWide).GetReg(),
733 TargetReg(kArg3, kNotWide).GetReg()};
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700734
735 int next_reg = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700736 int next_arg = 0;
737 if (skip_this) {
738 next_reg++;
739 next_arg++;
740 }
741 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
742 RegLocation rl_arg = info->args[next_arg++];
743 rl_arg = UpdateRawLoc(rl_arg);
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700744 if (rl_arg.wide && (next_reg <= last_arg_reg - 1)) {
745 RegStorage r_tmp(RegStorage::k64BitPair, arg_regs[next_reg], arg_regs[next_reg + 1]);
buzbee2700f7e2014-03-07 09:46:20 -0800746 LoadValueDirectWideFixed(rl_arg, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700747 next_reg++;
748 next_arg++;
749 } else {
750 if (rl_arg.wide) {
buzbee2700f7e2014-03-07 09:46:20 -0800751 rl_arg = NarrowRegLoc(rl_arg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700752 rl_arg.is_const = false;
753 }
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700754 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(arg_regs[next_reg]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700755 }
756 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
757 direct_code, direct_method, type);
758 }
759 return call_state;
760}
761
762/*
763 * Load up to 5 arguments, the first three of which will be in
764 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
765 * and as part of the load sequence, it must be replaced with
766 * the target method pointer. Note, this may also be called
767 * for "range" variants if the number of arguments is 5 or fewer.
768 */
769int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info,
770 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
771 const MethodReference& target_method,
772 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700773 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700774 RegLocation rl_arg;
775
776 /* If no arguments, just return */
777 if (info->num_arg_words == 0)
778 return call_state;
779
780 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
781 direct_code, direct_method, type);
782
783 DCHECK_LE(info->num_arg_words, 5);
784 if (info->num_arg_words > 3) {
785 int32_t next_use = 3;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700786 // Detect special case of wide arg spanning arg3/arg4
Brian Carlstrom7940e442013-07-12 13:46:57 -0700787 RegLocation rl_use0 = info->args[0];
788 RegLocation rl_use1 = info->args[1];
789 RegLocation rl_use2 = info->args[2];
buzbee2700f7e2014-03-07 09:46:20 -0800790 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) && rl_use2.wide) {
791 RegStorage reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700792 // Wide spans, we need the 2nd half of uses[2].
793 rl_arg = UpdateLocWide(rl_use2);
794 if (rl_arg.location == kLocPhysReg) {
buzbee85089dd2014-05-25 15:10:52 -0700795 if (rl_arg.reg.IsPair()) {
796 reg = rl_arg.reg.GetHigh();
797 } else {
798 RegisterInfo* info = GetRegInfo(rl_arg.reg);
799 info = info->FindMatchingView(RegisterInfo::kHighSingleStorageMask);
800 if (info == nullptr) {
801 // NOTE: For hard float convention we won't split arguments across reg/mem.
802 UNIMPLEMENTED(FATAL) << "Needs hard float api.";
803 }
804 reg = info->GetReg();
805 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700806 } else {
807 // kArg2 & rArg3 can safely be used here
Andreas Gampeccc60262014-07-04 18:02:38 -0700808 reg = TargetReg(kArg3, kNotWide);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100809 {
810 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700811 Load32Disp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100812 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700813 call_state = next_call_insn(cu_, info, call_state, target_method,
814 vtable_idx, direct_code, direct_method, type);
815 }
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100816 {
817 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700818 Store32Disp(TargetPtrReg(kSp), (next_use + 1) * 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100819 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700820 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
821 direct_code, direct_method, type);
822 next_use++;
823 }
824 // Loop through the rest
825 while (next_use < info->num_arg_words) {
buzbee091cc402014-03-31 10:14:40 -0700826 RegStorage arg_reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700827 rl_arg = info->args[next_use];
828 rl_arg = UpdateRawLoc(rl_arg);
829 if (rl_arg.location == kLocPhysReg) {
buzbee091cc402014-03-31 10:14:40 -0700830 arg_reg = rl_arg.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700831 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700832 arg_reg = TargetReg(kArg2, rl_arg.wide ? kWide : kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700833 if (rl_arg.wide) {
buzbee091cc402014-03-31 10:14:40 -0700834 LoadValueDirectWideFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700835 } else {
buzbee091cc402014-03-31 10:14:40 -0700836 LoadValueDirectFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700837 }
838 call_state = next_call_insn(cu_, info, call_state, target_method,
839 vtable_idx, direct_code, direct_method, type);
840 }
841 int outs_offset = (next_use + 1) * 4;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100842 {
843 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
844 if (rl_arg.wide) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700845 StoreBaseDisp(TargetPtrReg(kSp), outs_offset, arg_reg, k64, kNotVolatile);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100846 next_use += 2;
847 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700848 Store32Disp(TargetPtrReg(kSp), outs_offset, arg_reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100849 next_use++;
850 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700851 }
852 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
853 direct_code, direct_method, type);
854 }
855 }
856
857 call_state = LoadArgRegs(info, call_state, next_call_insn,
858 target_method, vtable_idx, direct_code, direct_method,
859 type, skip_this);
860
861 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +0000862 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700863 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700864 } else {
865 *pcrLabel = nullptr;
Dave Allison69dfe512014-07-11 17:11:58 +0000866 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) &&
867 (info->opt_flags & MIR_IGNORE_NULL_CHECK)) {
868 return call_state;
869 }
Dave Allisonf9439142014-03-27 15:10:22 -0700870 // In lieu of generating a check for kArg1 being null, we need to
871 // perform a load when doing implicit checks.
Dave Allison69dfe512014-07-11 17:11:58 +0000872 GenImplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700873 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700874 }
875 return call_state;
876}
877
Dave Allison69dfe512014-07-11 17:11:58 +0000878// Default implementation of implicit null pointer check.
879// Overridden by arch specific as necessary.
880void Mir2Lir::GenImplicitNullCheck(RegStorage reg, int opt_flags) {
881 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
882 return;
883 }
884 RegStorage tmp = AllocTemp();
885 Load32Disp(reg, 0, tmp);
886 MarkPossibleNullPointerException(opt_flags);
887 FreeTemp(tmp);
888}
889
890
Brian Carlstrom7940e442013-07-12 13:46:57 -0700891/*
892 * May have 0+ arguments (also used for jumbo). Note that
893 * source virtual registers may be in physical registers, so may
894 * need to be flushed to home location before copying. This
895 * applies to arg3 and above (see below).
896 *
897 * Two general strategies:
898 * If < 20 arguments
899 * Pass args 3-18 using vldm/vstm block copy
900 * Pass arg0, arg1 & arg2 in kArg1-kArg3
901 * If 20+ arguments
902 * Pass args arg19+ using memcpy block copy
903 * Pass arg0, arg1 & arg2 in kArg1-kArg3
904 *
905 */
906int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state,
907 LIR** pcrLabel, NextCallInsn next_call_insn,
908 const MethodReference& target_method,
909 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700910 InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700911 // If we can treat it as non-range (Jumbo ops will use range form)
912 if (info->num_arg_words <= 5)
913 return GenDalvikArgsNoRange(info, call_state, pcrLabel,
914 next_call_insn, target_method, vtable_idx,
915 direct_code, direct_method, type, skip_this);
916 /*
917 * First load the non-register arguments. Both forms expect all
918 * of the source arguments to be in their home frame location, so
919 * scan the s_reg names and flush any that have been promoted to
920 * frame backing storage.
921 */
922 // Scan the rest of the args - if in phys_reg flush to memory
923 for (int next_arg = 0; next_arg < info->num_arg_words;) {
924 RegLocation loc = info->args[next_arg];
925 if (loc.wide) {
926 loc = UpdateLocWide(loc);
927 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100928 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700929 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700930 }
931 next_arg += 2;
932 } else {
933 loc = UpdateLoc(loc);
934 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100935 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700936 Store32Disp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700937 }
938 next_arg++;
939 }
940 }
941
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800942 // The first 3 arguments are passed via registers.
943 // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either
944 // get size of uintptr_t or size of object reference according to model being used.
945 int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700946 int start_offset = SRegOffset(info->args[3].s_reg_low);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800947 int regs_left_to_pass_via_stack = info->num_arg_words - 3;
948 DCHECK_GT(regs_left_to_pass_via_stack, 0);
949
950 if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) {
951 // Use vldm/vstm pair using kArg3 as a temp
952 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
953 direct_code, direct_method, type);
Andreas Gampeccc60262014-07-04 18:02:38 -0700954 OpRegRegImm(kOpAdd, TargetReg(kArg3, kRef), TargetPtrReg(kSp), start_offset);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100955 LIR* ld = nullptr;
956 {
957 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Andreas Gampeccc60262014-07-04 18:02:38 -0700958 ld = OpVldm(TargetReg(kArg3, kRef), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100959 }
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800960 // TUNING: loosen barrier
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100961 ld->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800962 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
963 direct_code, direct_method, type);
Andreas Gampeccc60262014-07-04 18:02:38 -0700964 OpRegRegImm(kOpAdd, TargetReg(kArg3, kRef), TargetPtrReg(kSp), 4 /* Method* */ + (3 * 4));
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800965 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
966 direct_code, direct_method, type);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100967 LIR* st = nullptr;
968 {
969 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Andreas Gampeccc60262014-07-04 18:02:38 -0700970 st = OpVstm(TargetReg(kArg3, kRef), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100971 }
972 st->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800973 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
974 direct_code, direct_method, type);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700975 } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800976 int current_src_offset = start_offset;
977 int current_dest_offset = outs_offset;
978
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100979 // Only davik regs are accessed in this loop; no next_call_insn() calls.
980 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -0800981 while (regs_left_to_pass_via_stack > 0) {
982 // This is based on the knowledge that the stack itself is 16-byte aligned.
983 bool src_is_16b_aligned = (current_src_offset & 0xF) == 0;
984 bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0;
985 size_t bytes_to_move;
986
987 /*
988 * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a
989 * a 128-bit move because we won't get the chance to try to aligned. If there are more than
990 * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned.
991 * We do this because we could potentially do a smaller move to align.
992 */
993 if (regs_left_to_pass_via_stack == 4 ||
994 (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) {
995 // Moving 128-bits via xmm register.
996 bytes_to_move = sizeof(uint32_t) * 4;
997
998 // Allocate a free xmm temp. Since we are working through the calling sequence,
Mark Mendelle87f9b52014-04-30 14:13:18 -0400999 // we expect to have an xmm temporary available. AllocTempDouble will abort if
1000 // there are no free registers.
buzbee2700f7e2014-03-07 09:46:20 -08001001 RegStorage temp = AllocTempDouble();
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001002
1003 LIR* ld1 = nullptr;
1004 LIR* ld2 = nullptr;
1005 LIR* st1 = nullptr;
1006 LIR* st2 = nullptr;
1007
1008 /*
1009 * The logic is similar for both loads and stores. If we have 16-byte alignment,
1010 * do an aligned move. If we have 8-byte alignment, then do the move in two
1011 * parts. This approach prevents possible cache line splits. Finally, fall back
1012 * to doing an unaligned move. In most cases we likely won't split the cache
1013 * line but we cannot prove it and thus take a conservative approach.
1014 */
1015 bool src_is_8b_aligned = (current_src_offset & 0x7) == 0;
1016 bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0;
1017
1018 if (src_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001019 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001020 } else if (src_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001021 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovLo128FP);
1022 ld2 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001023 kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001024 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001025 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001026 }
1027
1028 if (dest_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001029 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001030 } else if (dest_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001031 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovLo128FP);
1032 st2 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001033 temp, kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001034 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001035 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001036 }
1037
1038 // TODO If we could keep track of aliasing information for memory accesses that are wider
1039 // than 64-bit, we wouldn't need to set up a barrier.
1040 if (ld1 != nullptr) {
1041 if (ld2 != nullptr) {
1042 // For 64-bit load we can actually set up the aliasing information.
1043 AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001044 AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true,
1045 true);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001046 } else {
1047 // Set barrier for 128-bit load.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001048 ld1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001049 }
1050 }
1051 if (st1 != nullptr) {
1052 if (st2 != nullptr) {
1053 // For 64-bit store we can actually set up the aliasing information.
1054 AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001055 AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false,
1056 true);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001057 } else {
1058 // Set barrier for 128-bit store.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001059 st1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001060 }
1061 }
1062
1063 // Free the temporary used for the data movement.
buzbee091cc402014-03-31 10:14:40 -07001064 FreeTemp(temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001065 } else {
1066 // Moving 32-bits via general purpose register.
1067 bytes_to_move = sizeof(uint32_t);
1068
1069 // Instead of allocating a new temp, simply reuse one of the registers being used
1070 // for argument passing.
Andreas Gampeccc60262014-07-04 18:02:38 -07001071 RegStorage temp = TargetReg(kArg3, kNotWide);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001072
1073 // Now load the argument VR and store to the outs.
Chao-ying Fua77ee512014-07-01 17:43:41 -07001074 Load32Disp(TargetPtrReg(kSp), current_src_offset, temp);
1075 Store32Disp(TargetPtrReg(kSp), current_dest_offset, temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001076 }
1077
1078 current_src_offset += bytes_to_move;
1079 current_dest_offset += bytes_to_move;
1080 regs_left_to_pass_via_stack -= (bytes_to_move >> 2);
1081 }
1082 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001083 // Generate memcpy
Andreas Gampeccc60262014-07-04 18:02:38 -07001084 OpRegRegImm(kOpAdd, TargetReg(kArg0, kRef), TargetPtrReg(kSp), outs_offset);
1085 OpRegRegImm(kOpAdd, TargetReg(kArg1, kRef), TargetPtrReg(kSp), start_offset);
Andreas Gampe98430592014-07-27 19:44:50 -07001086 CallRuntimeHelperRegRegImm(kQuickMemcpy, TargetReg(kArg0, kRef), TargetReg(kArg1, kRef),
1087 (info->num_arg_words - 3) * 4, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001088 }
1089
1090 call_state = LoadArgRegs(info, call_state, next_call_insn,
1091 target_method, vtable_idx, direct_code, direct_method,
1092 type, skip_this);
1093
1094 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1095 direct_code, direct_method, type);
1096 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +00001097 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001098 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -07001099 } else {
1100 *pcrLabel = nullptr;
Dave Allison69dfe512014-07-11 17:11:58 +00001101 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) &&
1102 (info->opt_flags & MIR_IGNORE_NULL_CHECK)) {
1103 return call_state;
1104 }
Dave Allisonf9439142014-03-27 15:10:22 -07001105 // In lieu of generating a check for kArg1 being null, we need to
1106 // perform a load when doing implicit checks.
Dave Allison69dfe512014-07-11 17:11:58 +00001107 GenImplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -07001108 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001109 }
1110 return call_state;
1111}
1112
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001113RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001114 RegLocation res;
1115 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -07001116 // If result is unused, return a sink target based on type of invoke target.
1117 res = GetReturn(ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001118 } else {
1119 res = info->result;
buzbee90a21f82014-09-07 11:37:51 -07001120 DCHECK_EQ(LocToRegClass(res),
1121 ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001122 }
1123 return res;
1124}
1125
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001126RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001127 RegLocation res;
1128 if (info->result.location == kLocInvalid) {
buzbee90a21f82014-09-07 11:37:51 -07001129 // If result is unused, return a sink target based on type of invoke target.
1130 res = GetReturnWide(ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001131 } else {
1132 res = info->result;
buzbee90a21f82014-09-07 11:37:51 -07001133 DCHECK_EQ(LocToRegClass(res),
1134 ShortyToRegClass(mir_graph_->GetShortyFromTargetIdx(info->index)[0]));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001135 }
1136 return res;
1137}
1138
Mathieu Chartiercd48f2d2014-09-09 13:51:09 -07001139bool Mir2Lir::GenInlinedReferenceGetReferent(CallInfo* info) {
Fred Shih4ee7a662014-07-11 09:59:27 -07001140 if (cu_->instruction_set == kMips) {
1141 // TODO - add Mips implementation
1142 return false;
1143 }
1144
Fred Shih4ee7a662014-07-11 09:59:27 -07001145 bool use_direct_type_ptr;
1146 uintptr_t direct_type_ptr;
Fred Shihe7f82e22014-08-06 10:46:37 -07001147 ClassReference ref;
1148 if (!cu_->compiler_driver->CanEmbedReferenceTypeInCode(&ref,
1149 &use_direct_type_ptr, &direct_type_ptr)) {
1150 return false;
1151 }
1152
Andreas Gampe30ab8a82014-07-17 00:12:32 -07001153 RegStorage reg_class = TargetReg(kArg1, kRef);
1154 Clobber(reg_class);
1155 LockTemp(reg_class);
Fred Shih4ee7a662014-07-11 09:59:27 -07001156 if (use_direct_type_ptr) {
1157 LoadConstant(reg_class, direct_type_ptr);
Alex Lighteb76e112014-07-29 15:22:40 -07001158 } else {
Fred Shihe7f82e22014-08-06 10:46:37 -07001159 uint16_t type_idx = ref.first->GetClassDef(ref.second).class_idx_;
1160 LoadClassType(*ref.first, type_idx, kArg1);
Fred Shih4ee7a662014-07-11 09:59:27 -07001161 }
Fred Shih4ee7a662014-07-11 09:59:27 -07001162
Fred Shihe7f82e22014-08-06 10:46:37 -07001163 uint32_t slow_path_flag_offset = cu_->compiler_driver->GetReferenceSlowFlagOffset();
1164 uint32_t disable_flag_offset = cu_->compiler_driver->GetReferenceDisableFlagOffset();
Fred Shih4ee7a662014-07-11 09:59:27 -07001165 CHECK(slow_path_flag_offset && disable_flag_offset &&
1166 (slow_path_flag_offset != disable_flag_offset));
1167
1168 // intrinsic logic start.
1169 RegLocation rl_obj = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -07001170 rl_obj = LoadValue(rl_obj, kRefReg);
Fred Shih4ee7a662014-07-11 09:59:27 -07001171
1172 RegStorage reg_slow_path = AllocTemp();
1173 RegStorage reg_disabled = AllocTemp();
Fred Shih37f05ef2014-07-16 18:38:08 -07001174 Load8Disp(reg_class, slow_path_flag_offset, reg_slow_path);
1175 Load8Disp(reg_class, disable_flag_offset, reg_disabled);
Andreas Gampe30ab8a82014-07-17 00:12:32 -07001176 FreeTemp(reg_class);
1177 LIR* or_inst = OpRegRegReg(kOpOr, reg_slow_path, reg_slow_path, reg_disabled);
Fred Shih4ee7a662014-07-11 09:59:27 -07001178 FreeTemp(reg_disabled);
1179
1180 // if slow path, jump to JNI path target
Andreas Gampe30ab8a82014-07-17 00:12:32 -07001181 LIR* slow_path_branch;
1182 if (or_inst->u.m.def_mask->HasBit(ResourceMask::kCCode)) {
1183 // Generate conditional branch only, as the OR set a condition state (we are interested in a 'Z' flag).
1184 slow_path_branch = OpCondBranch(kCondNe, nullptr);
1185 } else {
1186 // Generate compare and branch.
1187 slow_path_branch = OpCmpImmBranch(kCondNe, reg_slow_path, 0, nullptr);
1188 }
Fred Shih4ee7a662014-07-11 09:59:27 -07001189 FreeTemp(reg_slow_path);
1190
1191 // slow path not enabled, simply load the referent of the reference object
1192 RegLocation rl_dest = InlineTarget(info);
1193 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
1194 GenNullCheck(rl_obj.reg, info->opt_flags);
1195 LoadRefDisp(rl_obj.reg, mirror::Reference::ReferentOffset().Int32Value(), rl_result.reg,
1196 kNotVolatile);
1197 MarkPossibleNullPointerException(info->opt_flags);
1198 StoreValue(rl_dest, rl_result);
1199
1200 LIR* intrinsic_finish = NewLIR0(kPseudoTargetLabel);
1201 AddIntrinsicSlowPath(info, slow_path_branch, intrinsic_finish);
Serguei Katkov9863daf2014-09-04 15:21:32 +07001202 ClobberCallerSave(); // We must clobber everything because slow path will return here
Fred Shih4ee7a662014-07-11 09:59:27 -07001203 return true;
1204}
1205
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001206bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001207 if (cu_->instruction_set == kMips) {
1208 // TODO - add Mips implementation
1209 return false;
1210 }
1211 // Location of reference to data array
1212 int value_offset = mirror::String::ValueOffset().Int32Value();
1213 // Location of count
1214 int count_offset = mirror::String::CountOffset().Int32Value();
1215 // Starting offset within data array
1216 int offset_offset = mirror::String::OffsetOffset().Int32Value();
1217 // Start of char data with array_
1218 int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value();
1219
1220 RegLocation rl_obj = info->args[0];
1221 RegLocation rl_idx = info->args[1];
buzbeea0cd2d72014-06-01 09:33:49 -07001222 rl_obj = LoadValue(rl_obj, kRefReg);
Andreas Gampe98430592014-07-27 19:44:50 -07001223 rl_idx = LoadValue(rl_idx, kCoreReg);
buzbee2700f7e2014-03-07 09:46:20 -08001224 RegStorage reg_max;
1225 GenNullCheck(rl_obj.reg, info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001226 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001227 LIR* range_check_branch = nullptr;
buzbee2700f7e2014-03-07 09:46:20 -08001228 RegStorage reg_off;
1229 RegStorage reg_ptr;
Andreas Gampe98430592014-07-27 19:44:50 -07001230 reg_off = AllocTemp();
1231 reg_ptr = AllocTempRef();
1232 if (range_check) {
1233 reg_max = AllocTemp();
1234 Load32Disp(rl_obj.reg, count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -08001235 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001236 }
Andreas Gampe98430592014-07-27 19:44:50 -07001237 Load32Disp(rl_obj.reg, offset_offset, reg_off);
1238 MarkPossibleNullPointerException(info->opt_flags);
1239 LoadRefDisp(rl_obj.reg, value_offset, reg_ptr, kNotVolatile);
1240 if (range_check) {
1241 // Set up a slow path to allow retry in case of bounds violation */
1242 OpRegReg(kOpCmp, rl_idx.reg, reg_max);
1243 FreeTemp(reg_max);
1244 range_check_branch = OpCondBranch(kCondUge, nullptr);
1245 }
1246 OpRegImm(kOpAdd, reg_ptr, data_offset);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001247 if (rl_idx.is_const) {
1248 OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg));
1249 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001250 OpRegReg(kOpAdd, reg_off, rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001251 }
buzbee2700f7e2014-03-07 09:46:20 -08001252 FreeTemp(rl_obj.reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001253 if (rl_idx.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -08001254 FreeTemp(rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001255 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001256 RegLocation rl_dest = InlineTarget(info);
1257 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Andreas Gampe98430592014-07-27 19:44:50 -07001258 LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg, 1, kUnsignedHalf);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001259 FreeTemp(reg_off);
1260 FreeTemp(reg_ptr);
1261 StoreValue(rl_dest, rl_result);
1262 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001263 DCHECK(range_check_branch != nullptr);
1264 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001265 AddIntrinsicSlowPath(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001266 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001267 return true;
1268}
1269
1270// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001271bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001272 if (cu_->instruction_set == kMips) {
1273 // TODO - add Mips implementation
1274 return false;
1275 }
1276 // dst = src.length();
1277 RegLocation rl_obj = info->args[0];
buzbeea0cd2d72014-06-01 09:33:49 -07001278 rl_obj = LoadValue(rl_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001279 RegLocation rl_dest = InlineTarget(info);
1280 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001281 GenNullCheck(rl_obj.reg, info->opt_flags);
buzbee695d13a2014-04-19 13:32:20 -07001282 Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg);
Dave Allisonb373e092014-02-20 16:06:36 -08001283 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001284 if (is_empty) {
1285 // dst = (dst == 0);
1286 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001287 RegStorage t_reg = AllocTemp();
1288 OpRegReg(kOpNeg, t_reg, rl_result.reg);
1289 OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001290 } else if (cu_->instruction_set == kArm64) {
1291 OpRegImm(kOpSub, rl_result.reg, 1);
1292 OpRegRegImm(kOpLsr, rl_result.reg, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001293 } else {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001294 DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64);
buzbee2700f7e2014-03-07 09:46:20 -08001295 OpRegImm(kOpSub, rl_result.reg, 1);
1296 OpRegImm(kOpLsr, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001297 }
1298 }
1299 StoreValue(rl_dest, rl_result);
1300 return true;
1301}
1302
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001303bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
Zheng Xua3fe7422014-07-09 14:03:15 +08001304 if (cu_->instruction_set == kMips) {
1305 // TODO - add Mips implementation.
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001306 return false;
1307 }
1308 RegLocation rl_src_i = info->args[0];
Fred Shih37f05ef2014-07-16 18:38:08 -07001309 RegLocation rl_i = IsWide(size) ? LoadValueWide(rl_src_i, kCoreReg) : LoadValue(rl_src_i, kCoreReg);
1310 RegLocation rl_dest = IsWide(size) ? InlineTargetWide(info) : InlineTarget(info); // result reg
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001311 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Fred Shih37f05ef2014-07-16 18:38:08 -07001312 if (IsWide(size)) {
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001313 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Serban Constantinescu169489b2014-06-11 16:43:35 +01001314 OpRegReg(kOpRev, rl_result.reg, rl_i.reg);
1315 StoreValueWide(rl_dest, rl_result);
1316 return true;
1317 }
buzbee2700f7e2014-03-07 09:46:20 -08001318 RegStorage r_i_low = rl_i.reg.GetLow();
1319 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001320 // 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 +00001321 r_i_low = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -08001322 OpRegCopy(r_i_low, rl_i.reg);
Vladimir Markof246af22013-11-27 12:30:15 +00001323 }
buzbee2700f7e2014-03-07 09:46:20 -08001324 OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh());
1325 OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low);
1326 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001327 FreeTemp(r_i_low);
1328 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001329 StoreValueWide(rl_dest, rl_result);
1330 } else {
buzbee695d13a2014-04-19 13:32:20 -07001331 DCHECK(size == k32 || size == kSignedHalf);
1332 OpKind op = (size == k32) ? kOpRev : kOpRevsh;
buzbee2700f7e2014-03-07 09:46:20 -08001333 OpRegReg(op, rl_result.reg, rl_i.reg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001334 StoreValue(rl_dest, rl_result);
1335 }
1336 return true;
1337}
1338
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001339bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001340 if (cu_->instruction_set == kMips) {
1341 // TODO - add Mips implementation
1342 return false;
1343 }
1344 RegLocation rl_src = info->args[0];
1345 rl_src = LoadValue(rl_src, kCoreReg);
1346 RegLocation rl_dest = InlineTarget(info);
1347 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001348 RegStorage sign_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001349 // abs(x) = y<=x>>31, (x+y)^y.
buzbee2700f7e2014-03-07 09:46:20 -08001350 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31);
1351 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1352 OpRegReg(kOpXor, rl_result.reg, sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001353 StoreValue(rl_dest, rl_result);
1354 return true;
1355}
1356
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001357bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001358 if (cu_->instruction_set == kMips) {
1359 // TODO - add Mips implementation
1360 return false;
1361 }
Vladimir Markob9823312014-03-20 17:38:43 +00001362 RegLocation rl_src = info->args[0];
1363 rl_src = LoadValueWide(rl_src, kCoreReg);
1364 RegLocation rl_dest = InlineTargetWide(info);
1365 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1366
1367 // If on x86 or if we would clobber a register needed later, just copy the source first.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001368 if (cu_->instruction_set != kX86_64 &&
1369 (cu_->instruction_set == kX86 ||
1370 rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001371 OpRegCopyWide(rl_result.reg, rl_src.reg);
1372 if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() &&
1373 rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() &&
1374 rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() &&
Vladimir Markob9823312014-03-20 17:38:43 +00001375 rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) {
1376 // Reuse source registers to avoid running out of temps.
buzbee2700f7e2014-03-07 09:46:20 -08001377 FreeTemp(rl_src.reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001378 }
1379 rl_src = rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001380 }
Vladimir Markob9823312014-03-20 17:38:43 +00001381
1382 // abs(x) = y<=x>>31, (x+y)^y.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001383 RegStorage sign_reg;
1384 if (cu_->instruction_set == kX86_64) {
1385 sign_reg = AllocTempWide();
1386 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 63);
1387 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1388 OpRegReg(kOpXor, rl_result.reg, sign_reg);
1389 } else {
1390 sign_reg = AllocTemp();
1391 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31);
1392 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg);
1393 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg);
1394 OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg);
1395 OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg);
1396 }
buzbee082833c2014-05-17 23:16:26 -07001397 FreeTemp(sign_reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001398 StoreValueWide(rl_dest, rl_result);
1399 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001400}
1401
Serban Constantinescu23abec92014-07-02 16:13:38 +01001402bool Mir2Lir::GenInlinedReverseBits(CallInfo* info, OpSize size) {
1403 // Currently implemented only for ARM64
1404 return false;
1405}
1406
1407bool Mir2Lir::GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) {
1408 // Currently implemented only for ARM64
1409 return false;
1410}
1411
Serban Constantinescu2eba1fa2014-07-31 19:07:17 +01001412bool Mir2Lir::GenInlinedCeil(CallInfo* info) {
1413 return false;
1414}
1415
1416bool Mir2Lir::GenInlinedFloor(CallInfo* info) {
1417 return false;
1418}
1419
1420bool Mir2Lir::GenInlinedRint(CallInfo* info) {
1421 return false;
1422}
1423
1424bool Mir2Lir::GenInlinedRound(CallInfo* info, bool is_double) {
1425 return false;
1426}
1427
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001428bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001429 if (cu_->instruction_set == kMips) {
1430 // TODO - add Mips implementation
1431 return false;
1432 }
1433 RegLocation rl_src = info->args[0];
1434 RegLocation rl_dest = InlineTarget(info);
1435 StoreValue(rl_dest, rl_src);
1436 return true;
1437}
1438
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001439bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001440 if (cu_->instruction_set == kMips) {
1441 // TODO - add Mips implementation
1442 return false;
1443 }
1444 RegLocation rl_src = info->args[0];
1445 RegLocation rl_dest = InlineTargetWide(info);
1446 StoreValueWide(rl_dest, rl_src);
1447 return true;
1448}
1449
DaniilSokolov70c4f062014-06-24 17:34:00 -07001450bool Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) {
1451 return false;
1452}
1453
1454
Brian Carlstrom7940e442013-07-12 13:46:57 -07001455/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001456 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001457 * otherwise bails to standard library code.
1458 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001459bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001460 if (cu_->instruction_set == kMips) {
1461 // TODO - add Mips implementation
1462 return false;
1463 }
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001464 if (cu_->instruction_set == kX86_64) {
1465 // TODO - add kX86_64 implementation
1466 return false;
1467 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001468 RegLocation rl_obj = info->args[0];
1469 RegLocation rl_char = info->args[1];
1470 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1471 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1472 return false;
1473 }
1474
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001475 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001476 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001477 RegStorage reg_ptr = TargetReg(kArg0, kRef);
1478 RegStorage reg_char = TargetReg(kArg1, kNotWide);
1479 RegStorage reg_start = TargetReg(kArg2, kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001480
Brian Carlstrom7940e442013-07-12 13:46:57 -07001481 LoadValueDirectFixed(rl_obj, reg_ptr);
1482 LoadValueDirectFixed(rl_char, reg_char);
1483 if (zero_based) {
1484 LoadConstant(reg_start, 0);
1485 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001486 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001487 LoadValueDirectFixed(rl_start, reg_start);
1488 }
Andreas Gampe98430592014-07-27 19:44:50 -07001489 RegStorage r_tgt = LoadHelper(kQuickIndexOf);
Dave Allisonf9439142014-03-27 15:10:22 -07001490 GenExplicitNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001491 LIR* high_code_point_branch =
1492 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001493 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001494 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001495 if (!rl_char.is_const) {
1496 // Add the slow path for code points beyond 0xFFFF.
1497 DCHECK(high_code_point_branch != nullptr);
1498 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1499 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001500 AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt);
Serguei Katkov9863daf2014-09-04 15:21:32 +07001501 ClobberCallerSave(); // We must clobber everything because slow path will return here
Vladimir Marko3bc86152014-03-13 14:11:28 +00001502 } else {
1503 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1504 DCHECK(high_code_point_branch == nullptr);
1505 }
buzbeea0cd2d72014-06-01 09:33:49 -07001506 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001507 RegLocation rl_dest = InlineTarget(info);
1508 StoreValue(rl_dest, rl_return);
1509 return true;
1510}
1511
1512/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001513bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001514 if (cu_->instruction_set == kMips) {
1515 // TODO - add Mips implementation
1516 return false;
1517 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001518 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001519 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001520 RegStorage reg_this = TargetReg(kArg0, kRef);
1521 RegStorage reg_cmp = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001522
1523 RegLocation rl_this = info->args[0];
1524 RegLocation rl_cmp = info->args[1];
1525 LoadValueDirectFixed(rl_this, reg_this);
1526 LoadValueDirectFixed(rl_cmp, reg_cmp);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001527 RegStorage r_tgt;
1528 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Andreas Gampe98430592014-07-27 19:44:50 -07001529 r_tgt = LoadHelper(kQuickStringCompareTo);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001530 } else {
1531 r_tgt = RegStorage::InvalidReg();
1532 }
Dave Allisonf9439142014-03-27 15:10:22 -07001533 GenExplicitNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001534 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001535 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001536 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
Mingyao Yang3a74d152014-04-21 15:39:44 -07001537 AddIntrinsicSlowPath(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001538 // NOTE: not a safepoint
Andreas Gampe98430592014-07-27 19:44:50 -07001539 CallHelper(r_tgt, kQuickStringCompareTo, false, true);
buzbeea0cd2d72014-06-01 09:33:49 -07001540 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001541 RegLocation rl_dest = InlineTarget(info);
1542 StoreValue(rl_dest, rl_return);
1543 return true;
1544}
1545
1546bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1547 RegLocation rl_dest = InlineTarget(info);
Andreas Gampe7a949612014-07-08 11:03:59 -07001548
1549 // Early exit if the result is unused.
1550 if (rl_dest.orig_sreg < 0) {
1551 return true;
1552 }
1553
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001554 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001555
1556 switch (cu_->instruction_set) {
1557 case kArm:
1558 // Fall-through.
1559 case kThumb2:
1560 // Fall-through.
1561 case kMips:
Chao-ying Fua77ee512014-07-01 17:43:41 -07001562 Load32Disp(TargetPtrReg(kSelf), Thread::PeerOffset<4>().Int32Value(), rl_result.reg);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001563 break;
1564
1565 case kArm64:
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001566 LoadRefDisp(TargetPtrReg(kSelf), Thread::PeerOffset<8>().Int32Value(), rl_result.reg,
1567 kNotVolatile);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001568 break;
1569
Andreas Gampe2f244e92014-05-08 03:35:25 -07001570 default:
1571 LOG(FATAL) << "Unexpected isa " << cu_->instruction_set;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001572 }
1573 StoreValue(rl_dest, rl_result);
1574 return true;
1575}
1576
1577bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
1578 bool is_long, bool is_volatile) {
1579 if (cu_->instruction_set == kMips) {
1580 // TODO - add Mips implementation
1581 return false;
1582 }
1583 // Unused - RegLocation rl_src_unsafe = info->args[0];
1584 RegLocation rl_src_obj = info->args[1]; // Object
1585 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001586 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001587 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001588
buzbeea0cd2d72014-06-01 09:33:49 -07001589 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001590 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001591 RegLocation rl_result = EvalLoc(rl_dest, LocToRegClass(rl_dest), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001592 if (is_long) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001593 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1594 || cu_->instruction_set == kArm64) {
1595 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001596 } else {
1597 RegStorage rl_temp_offset = AllocTemp();
1598 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001599 LoadBaseDisp(rl_temp_offset, 0, rl_result.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001600 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001601 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001602 } else {
Matteo Franchin255e0142014-07-04 13:50:41 +01001603 if (rl_result.ref) {
1604 LoadRefIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0);
1605 } else {
1606 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32);
1607 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001608 }
1609
1610 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001611 GenMemBarrier(kLoadAny);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001612 }
1613
1614 if (is_long) {
1615 StoreValueWide(rl_dest, rl_result);
1616 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001617 StoreValue(rl_dest, rl_result);
1618 }
1619 return true;
1620}
1621
1622bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1623 bool is_object, bool is_volatile, bool is_ordered) {
1624 if (cu_->instruction_set == kMips) {
1625 // TODO - add Mips implementation
1626 return false;
1627 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001628 // Unused - RegLocation rl_src_unsafe = info->args[0];
1629 RegLocation rl_src_obj = info->args[1]; // Object
1630 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001631 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001632 RegLocation rl_src_value = info->args[4]; // value to store
1633 if (is_volatile || is_ordered) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001634 GenMemBarrier(kAnyStore);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001635 }
buzbeea0cd2d72014-06-01 09:33:49 -07001636 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001637 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1638 RegLocation rl_value;
1639 if (is_long) {
1640 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001641 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1642 || cu_->instruction_set == kArm64) {
1643 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001644 } else {
1645 RegStorage rl_temp_offset = AllocTemp();
1646 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001647 StoreBaseDisp(rl_temp_offset, 0, rl_value.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001648 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001649 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001650 } else {
buzbee7c02e912014-10-03 13:14:17 -07001651 rl_value = LoadValue(rl_src_value, LocToRegClass(rl_src_value));
Matteo Franchin255e0142014-07-04 13:50:41 +01001652 if (rl_value.ref) {
1653 StoreRefIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0);
1654 } else {
1655 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32);
1656 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001657 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001658
1659 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
buzbee091cc402014-03-31 10:14:40 -07001660 FreeTemp(rl_offset.reg);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001661
Brian Carlstrom7940e442013-07-12 13:46:57 -07001662 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001663 // Prevent reordering with a subsequent volatile load.
1664 // May also be needed to address store atomicity issues.
1665 GenMemBarrier(kAnyAny);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001666 }
1667 if (is_object) {
buzbee2700f7e2014-03-07 09:46:20 -08001668 MarkGCCard(rl_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001669 }
1670 return true;
1671}
1672
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001673void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001674 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001675 if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file)
1676 ->GenIntrinsic(this, info)) {
1677 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001678 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001679 GenInvokeNoInline(info);
1680}
1681
1682void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001683 int call_state = 0;
1684 LIR* null_ck;
1685 LIR** p_null_ck = NULL;
1686 NextCallInsn next_call_insn;
1687 FlushAllRegs(); /* Everything to home location */
1688 // Explicit register usage
1689 LockCallTemps();
1690
Vladimir Markof096aad2014-01-23 15:51:58 +00001691 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
1692 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
Mark Mendelle87f9b52014-04-30 14:13:18 -04001693 BeginInvoke(info);
Vladimir Markof096aad2014-01-23 15:51:58 +00001694 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
Vladimir Markof4da6752014-08-01 19:04:18 +01001695 info->type = method_info.GetSharpType();
Vladimir Markof096aad2014-01-23 15:51:58 +00001696 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001697 bool skip_this;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001698 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001699 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001700 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001701 } else if (info->type == kDirect) {
1702 if (fast_path) {
1703 p_null_ck = &null_ck;
1704 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001705 next_call_insn = fast_path ? GetNextSDCallInsn() : NextDirectCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001706 skip_this = false;
1707 } else if (info->type == kStatic) {
Vladimir Markof4da6752014-08-01 19:04:18 +01001708 next_call_insn = fast_path ? GetNextSDCallInsn() : NextStaticCallInsnSP;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001709 skip_this = false;
1710 } else if (info->type == kSuper) {
1711 DCHECK(!fast_path); // Fast path is a direct call.
1712 next_call_insn = NextSuperCallInsnSP;
1713 skip_this = false;
1714 } else {
1715 DCHECK_EQ(info->type, kVirtual);
1716 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1717 skip_this = fast_path;
1718 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001719 MethodReference target_method = method_info.GetTargetMethod();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001720 if (!info->is_range) {
1721 call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001722 next_call_insn, target_method, method_info.VTableIndex(),
1723 method_info.DirectCode(), method_info.DirectMethod(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001724 original_type, skip_this);
1725 } else {
1726 call_state = GenDalvikArgsRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001727 next_call_insn, target_method, method_info.VTableIndex(),
1728 method_info.DirectCode(), method_info.DirectMethod(),
1729 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001730 }
1731 // Finish up any of the call sequence not interleaved in arg loading
1732 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001733 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
1734 method_info.DirectCode(), method_info.DirectMethod(), original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001735 }
Vladimir Markof4da6752014-08-01 19:04:18 +01001736 LIR* call_insn = GenCallInsn(method_info);
Mark Mendelle87f9b52014-04-30 14:13:18 -04001737 EndInvoke(info);
Vladimir Markof4da6752014-08-01 19:04:18 +01001738 MarkSafepointPC(call_insn);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001739
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001740 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001741 if (info->result.location != kLocInvalid) {
1742 // We have a following MOVE_RESULT - do it now.
1743 if (info->result.wide) {
buzbeea0cd2d72014-06-01 09:33:49 -07001744 RegLocation ret_loc = GetReturnWide(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001745 StoreValueWide(info->result, ret_loc);
1746 } else {
buzbeea0cd2d72014-06-01 09:33:49 -07001747 RegLocation ret_loc = GetReturn(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001748 StoreValue(info->result, ret_loc);
1749 }
1750 }
1751}
1752
Vladimir Markof4da6752014-08-01 19:04:18 +01001753NextCallInsn Mir2Lir::GetNextSDCallInsn() {
1754 return NextSDCallInsn;
1755}
1756
1757LIR* Mir2Lir::GenCallInsn(const MirMethodLoweringInfo& method_info) {
1758 DCHECK(cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64 &&
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +01001759 cu_->instruction_set != kThumb2 && cu_->instruction_set != kArm &&
1760 cu_->instruction_set != kArm64);
Vladimir Markof4da6752014-08-01 19:04:18 +01001761 return OpReg(kOpBlx, TargetPtrReg(kInvokeTgt));
1762}
1763
Brian Carlstrom7940e442013-07-12 13:46:57 -07001764} // namespace art