blob: fdb3d83c0b20611305075e4939794519d19fbfdd [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
17#include "dex/compiler_ir.h"
Vladimir Marko5c96e6b2013-11-14 15:34:17 +000018#include "dex/frontend.h"
19#include "dex/quick/dex_file_method_inliner.h"
20#include "dex/quick/dex_file_to_method_inliner_map.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include "dex_file-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070022#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023#include "invoke_type.h"
24#include "mirror/array.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070025#include "mirror/class-inl.h"
Fred Shih4ee7a662014-07-11 09:59:27 -070026#include "mirror/dex_cache.h"
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070027#include "mirror/object_array-inl.h"
Fred Shih4ee7a662014-07-11 09:59:27 -070028#include "mirror/reference-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "mirror/string.h"
30#include "mir_to_lir-inl.h"
Fred Shih4ee7a662014-07-11 09:59:27 -070031#include "scoped_thread_state_change.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070032#include "x86/codegen_x86.h"
33
34namespace art {
35
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070036// Shortcuts to repeatedly used long types.
37typedef mirror::ObjectArray<mirror::Object> ObjArray;
38
Brian Carlstrom7940e442013-07-12 13:46:57 -070039/*
40 * This source files contains "gen" codegen routines that should
41 * be applicable to most targets. Only mid-level support utilities
42 * and "op" calls may be used here.
43 */
44
Mingyao Yang3a74d152014-04-21 15:39:44 -070045void Mir2Lir::AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume) {
46 class IntrinsicSlowPathPath : public Mir2Lir::LIRSlowPath {
Vladimir Marko3bc86152014-03-13 14:11:28 +000047 public:
Mingyao Yang3a74d152014-04-21 15:39:44 -070048 IntrinsicSlowPathPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr)
Vladimir Marko3bc86152014-03-13 14:11:28 +000049 : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) {
50 }
51
52 void Compile() {
53 m2l_->ResetRegPool();
54 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -070055 GenerateTargetLabel(kPseudoIntrinsicRetry);
Vladimir Marko3bc86152014-03-13 14:11:28 +000056 // NOTE: GenInvokeNoInline() handles MarkSafepointPC.
57 m2l_->GenInvokeNoInline(info_);
58 if (cont_ != nullptr) {
59 m2l_->OpUnconditionalBranch(cont_);
60 }
61 }
62
63 private:
64 CallInfo* const info_;
65 };
66
Mingyao Yang3a74d152014-04-21 15:39:44 -070067 AddSlowPath(new (arena_) IntrinsicSlowPathPath(this, info, branch, resume));
Vladimir Marko3bc86152014-03-13 14:11:28 +000068}
69
Andreas Gampe2f244e92014-05-08 03:35:25 -070070// Macro to help instantiate.
71// TODO: This might be used to only instantiate <4> on pure 32b systems.
72#define INSTANTIATE(sig_part1, ...) \
73 template sig_part1(ThreadOffset<4>, __VA_ARGS__); \
74 template sig_part1(ThreadOffset<8>, __VA_ARGS__); \
75
76
Brian Carlstrom7940e442013-07-12 13:46:57 -070077/*
78 * To save scheduling time, helper calls are broken into two parts: generation of
Dave Allisond6ed6422014-04-09 23:36:15 +000079 * the helper target address, and the actual call to the helper. Because x86
80 * has a memory call operation, part 1 is a NOP for x86. For other targets,
81 * load arguments between the two parts.
Brian Carlstrom7940e442013-07-12 13:46:57 -070082 */
Andreas Gampe2f244e92014-05-08 03:35:25 -070083// template <size_t pointer_size>
Ian Rogersdd7624d2014-03-14 17:43:00 -070084RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<4> helper_offset) {
Andreas Gampe2f244e92014-05-08 03:35:25 -070085 // All CallRuntimeHelperXXX call this first. So make a central check here.
86 DCHECK_EQ(4U, GetInstructionSetPointerSize(cu_->instruction_set));
87
88 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
89 return RegStorage::InvalidReg();
90 } else {
91 return LoadHelper(helper_offset);
92 }
93}
94
95RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<8> helper_offset) {
96 // All CallRuntimeHelperXXX call this first. So make a central check here.
97 DCHECK_EQ(8U, GetInstructionSetPointerSize(cu_->instruction_set));
98
99 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
100 return RegStorage::InvalidReg();
101 } else {
102 return LoadHelper(helper_offset);
103 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700104}
105
106/* NOTE: if r_tgt is a temp, it will be freed following use */
Andreas Gampe2f244e92014-05-08 03:35:25 -0700107template <size_t pointer_size>
108LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<pointer_size> helper_offset,
109 bool safepoint_pc, bool use_link) {
Dave Allisond6ed6422014-04-09 23:36:15 +0000110 LIR* call_inst;
Brian Carlstrom60d7a652014-03-13 18:10:08 -0700111 OpKind op = use_link ? kOpBlx : kOpBx;
Dave Allisond6ed6422014-04-09 23:36:15 +0000112 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
113 call_inst = OpThreadMem(op, helper_offset);
114 } else {
115 call_inst = OpReg(op, r_tgt);
116 FreeTemp(r_tgt);
117 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700118 if (safepoint_pc) {
119 MarkSafepointPC(call_inst);
120 }
121 return call_inst;
122}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700123template LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<4> helper_offset,
124 bool safepoint_pc, bool use_link);
125template LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<8> helper_offset,
126 bool safepoint_pc, bool use_link);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700127
Andreas Gampe2f244e92014-05-08 03:35:25 -0700128template <size_t pointer_size>
129void Mir2Lir::CallRuntimeHelper(ThreadOffset<pointer_size> helper_offset, bool safepoint_pc) {
Mingyao Yang42894562014-04-07 12:42:16 -0700130 RegStorage r_tgt = CallHelperSetup(helper_offset);
131 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700132 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Mingyao Yang42894562014-04-07 12:42:16 -0700133}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700134INSTANTIATE(void Mir2Lir::CallRuntimeHelper, bool safepoint_pc)
Mingyao Yang42894562014-04-07 12:42:16 -0700135
Andreas Gampe2f244e92014-05-08 03:35:25 -0700136template <size_t pointer_size>
Andreas Gampeccc60262014-07-04 18:02:38 -0700137void Mir2Lir::CallRuntimeHelperImm(ThreadOffset<pointer_size> helper_offset, int arg0,
138 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800139 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700140 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000141 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700142 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700143}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700144INSTANTIATE(void Mir2Lir::CallRuntimeHelperImm, int arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700145
Andreas Gampe2f244e92014-05-08 03:35:25 -0700146template <size_t pointer_size>
147void Mir2Lir::CallRuntimeHelperReg(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700148 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800149 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700150 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000151 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700152 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700153}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700154INSTANTIATE(void Mir2Lir::CallRuntimeHelperReg, RegStorage arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700155
Andreas Gampe2f244e92014-05-08 03:35:25 -0700156template <size_t pointer_size>
157void Mir2Lir::CallRuntimeHelperRegLocation(ThreadOffset<pointer_size> helper_offset,
158 RegLocation arg0, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800159 RegStorage r_tgt = CallHelperSetup(helper_offset);
160 if (arg0.wide == 0) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700161 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, arg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700162 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700163 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700164 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000165 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700166 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700167}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700168INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocation, RegLocation arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700169
Andreas Gampe2f244e92014-05-08 03:35:25 -0700170template <size_t pointer_size>
171void Mir2Lir::CallRuntimeHelperImmImm(ThreadOffset<pointer_size> helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700172 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800173 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700174 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
175 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000176 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700177 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700178}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700179INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmImm, int arg0, int arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700180
Andreas Gampe2f244e92014-05-08 03:35:25 -0700181template <size_t pointer_size>
182void Mir2Lir::CallRuntimeHelperImmRegLocation(ThreadOffset<pointer_size> helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700183 RegLocation arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800184 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700185 DCHECK(!arg1.fp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700186 if (arg1.wide == 0) {
Andreas Gampef9872f02014-07-01 19:00:09 -0700187 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700188 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700189 RegStorage r_tmp = TargetReg(cu_->instruction_set == kMips ? kArg2 : kArg1, kWide);
buzbee2700f7e2014-03-07 09:46:20 -0800190 LoadValueDirectWideFixed(arg1, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700191 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700192 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000193 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700194 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700195}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700196INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmRegLocation, int arg0, RegLocation arg1,
197 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700198
Andreas Gampe2f244e92014-05-08 03:35:25 -0700199template <size_t pointer_size>
200void Mir2Lir::CallRuntimeHelperRegLocationImm(ThreadOffset<pointer_size> helper_offset,
201 RegLocation arg0, int arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800202 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampef9872f02014-07-01 19:00:09 -0700203 DCHECK(!arg0.wide);
204 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
Andreas Gampeccc60262014-07-04 18:02:38 -0700205 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000206 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700207 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700208}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700209INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationImm, RegLocation arg0, int arg1,
210 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700211
Andreas Gampe2f244e92014-05-08 03:35:25 -0700212template <size_t pointer_size>
213void Mir2Lir::CallRuntimeHelperImmReg(ThreadOffset<pointer_size> helper_offset, int arg0,
214 RegStorage arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800215 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700216 OpRegCopy(TargetReg(kArg1, arg1.GetWideKind()), arg1);
217 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000218 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700219 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700220}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700221INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmReg, int arg0, RegStorage arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700222
Andreas Gampe2f244e92014-05-08 03:35:25 -0700223template <size_t pointer_size>
224void Mir2Lir::CallRuntimeHelperRegImm(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
225 int arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800226 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700227 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
228 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000229 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700230 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700231}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700232INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegImm, RegStorage arg0, int arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700233
Andreas Gampe2f244e92014-05-08 03:35:25 -0700234template <size_t pointer_size>
235void Mir2Lir::CallRuntimeHelperImmMethod(ThreadOffset<pointer_size> helper_offset, int arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700236 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800237 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700238 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
239 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000240 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700241 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700242}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700243INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethod, int arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700244
Andreas Gampe2f244e92014-05-08 03:35:25 -0700245template <size_t pointer_size>
246void Mir2Lir::CallRuntimeHelperRegMethod(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800247 bool safepoint_pc) {
248 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700249 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.GetWideKind()), arg0));
250 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
251 if (r_tmp.NotExactlyEquals(arg0)) {
252 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800253 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700254 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800255 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700256 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800257}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700258INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegMethod, RegStorage arg0, bool safepoint_pc)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800259
Andreas Gampe2f244e92014-05-08 03:35:25 -0700260template <size_t pointer_size>
261void Mir2Lir::CallRuntimeHelperRegMethodRegLocation(ThreadOffset<pointer_size> helper_offset,
262 RegStorage arg0, RegLocation arg2,
263 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800264 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700265 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.GetWideKind()), arg0));
266 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
267 if (r_tmp.NotExactlyEquals(arg0)) {
268 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800269 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700270 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700271 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800272 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700273 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800274}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700275INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegMethodRegLocation, RegStorage arg0, RegLocation arg2,
276 bool safepoint_pc)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800277
Andreas Gampe2f244e92014-05-08 03:35:25 -0700278template <size_t pointer_size>
279void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(ThreadOffset<pointer_size> helper_offset,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700280 RegLocation arg0, RegLocation arg1,
281 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800282 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700283 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700284 RegStorage arg0_reg = TargetReg((arg0.fp) ? kFArg0 : kArg0, arg0);
285
286 RegStorage arg1_reg;
287 if (arg1.fp == arg0.fp) {
288 arg1_reg = TargetReg((arg1.fp) ? kFArg1 : kArg1, arg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700289 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700290 arg1_reg = TargetReg((arg1.fp) ? kFArg0 : kArg0, arg1);
291 }
292
293 if (arg0.wide == 0) {
294 LoadValueDirectFixed(arg0, arg0_reg);
295 } else {
296 LoadValueDirectWideFixed(arg0, arg0_reg);
297 }
298
299 if (arg1.wide == 0) {
300 LoadValueDirectFixed(arg1, arg1_reg);
301 } else {
302 LoadValueDirectWideFixed(arg1, arg1_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700303 }
304 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700305 DCHECK(!cu_->target64);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700306 if (arg0.wide == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700307 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700308 if (arg1.wide == 0) {
309 if (cu_->instruction_set == kMips) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700310 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700311 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700312 LoadValueDirectFixed(arg1, TargetReg(kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700313 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700314 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700315 if (cu_->instruction_set == kMips) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700316 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700317 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700318 LoadValueDirectWideFixed(arg1, TargetReg(kArg1, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700319 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700320 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700321 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700322 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700323 if (arg1.wide == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700324 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700325 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700326 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700327 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700328 }
329 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000330 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700331 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700332}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700333INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationRegLocation, RegLocation arg0,
334 RegLocation arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700335
Mingyao Yang80365d92014-04-18 12:10:58 -0700336void Mir2Lir::CopyToArgumentRegs(RegStorage arg0, RegStorage arg1) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700337 WideKind arg0_kind = arg0.GetWideKind();
338 WideKind arg1_kind = arg1.GetWideKind();
339 if (IsSameReg(arg1, TargetReg(kArg0, arg1_kind))) {
340 if (IsSameReg(arg0, TargetReg(kArg1, arg0_kind))) {
Mingyao Yang80365d92014-04-18 12:10:58 -0700341 // Swap kArg0 and kArg1 with kArg2 as temp.
Andreas Gampeccc60262014-07-04 18:02:38 -0700342 OpRegCopy(TargetReg(kArg2, arg1_kind), arg1);
343 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
344 OpRegCopy(TargetReg(kArg1, arg1_kind), TargetReg(kArg2, arg1_kind));
Mingyao Yang80365d92014-04-18 12:10:58 -0700345 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700346 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
347 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
Mingyao Yang80365d92014-04-18 12:10:58 -0700348 }
349 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700350 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
351 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
Mingyao Yang80365d92014-04-18 12:10:58 -0700352 }
353}
354
Andreas Gampe2f244e92014-05-08 03:35:25 -0700355template <size_t pointer_size>
356void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800357 RegStorage arg1, bool safepoint_pc) {
358 RegStorage r_tgt = CallHelperSetup(helper_offset);
Mingyao Yang80365d92014-04-18 12:10:58 -0700359 CopyToArgumentRegs(arg0, arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000360 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700361 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700362}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700363INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegReg, RegStorage arg0, RegStorage arg1,
364 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700365
Andreas Gampe2f244e92014-05-08 03:35:25 -0700366template <size_t pointer_size>
367void Mir2Lir::CallRuntimeHelperRegRegImm(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800368 RegStorage arg1, int arg2, bool safepoint_pc) {
369 RegStorage r_tgt = CallHelperSetup(helper_offset);
Mingyao Yang80365d92014-04-18 12:10:58 -0700370 CopyToArgumentRegs(arg0, arg1);
Andreas Gampeccc60262014-07-04 18:02:38 -0700371 LoadConstant(TargetReg(kArg2, kNotWide), arg2);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000372 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700373 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700374}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700375INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegRegImm, RegStorage arg0, RegStorage arg1, int arg2,
376 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700377
Andreas Gampe2f244e92014-05-08 03:35:25 -0700378template <size_t pointer_size>
379void Mir2Lir::CallRuntimeHelperImmMethodRegLocation(ThreadOffset<pointer_size> helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700380 int arg0, RegLocation arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800381 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700382 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Andreas Gampeccc60262014-07-04 18:02:38 -0700383 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
384 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000385 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700386 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700387}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700388INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethodRegLocation, int arg0, RegLocation arg2,
389 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700390
Andreas Gampe2f244e92014-05-08 03:35:25 -0700391template <size_t pointer_size>
392void Mir2Lir::CallRuntimeHelperImmMethodImm(ThreadOffset<pointer_size> helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700393 int arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800394 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700395 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
396 LoadConstant(TargetReg(kArg2, kNotWide), arg2);
397 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000398 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700399 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700400}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700401INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethodImm, int arg0, int arg2, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700402
Andreas Gampe2f244e92014-05-08 03:35:25 -0700403template <size_t pointer_size>
404void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset<pointer_size> helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700405 int arg0, RegLocation arg1,
406 RegLocation arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800407 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700408 DCHECK_EQ(static_cast<unsigned int>(arg1.wide), 0U); // The static_cast works around an
409 // instantiation bug in GCC.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700410 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700411 if (arg2.wide == 0) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700412 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700413 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700414 LoadValueDirectWideFixed(arg2, TargetReg(kArg2, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700415 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700416 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000417 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700418 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700419}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700420INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation, int arg0, RegLocation arg1,
421 RegLocation arg2, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700422
Andreas Gampe2f244e92014-05-08 03:35:25 -0700423template <size_t pointer_size>
Andreas Gampeccc60262014-07-04 18:02:38 -0700424void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(
425 ThreadOffset<pointer_size> helper_offset,
426 RegLocation arg0,
427 RegLocation arg1,
428 RegLocation arg2,
429 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800430 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700431 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
432 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
433 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000434 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700435 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Ian Rogersa9a82542013-10-04 11:17:26 -0700436}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700437INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation, RegLocation arg0,
438 RegLocation arg1, RegLocation arg2, bool safepoint_pc)
Ian Rogersa9a82542013-10-04 11:17:26 -0700439
Brian Carlstrom7940e442013-07-12 13:46:57 -0700440/*
441 * If there are any ins passed in registers that have not been promoted
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100442 * to a callee-save register, flush them to the frame. Perform initial
Brian Carlstrom7940e442013-07-12 13:46:57 -0700443 * assignment of promoted arguments.
444 *
445 * ArgLocs is an array of location records describing the incoming arguments
446 * with one location record per word of argument.
447 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700448void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700449 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800450 * Dummy up a RegLocation for the incoming StackReference<mirror::ArtMethod>
Brian Carlstrom7940e442013-07-12 13:46:57 -0700451 * It will attempt to keep kArg0 live (or copy it to home location
452 * if promoted).
453 */
454 RegLocation rl_src = rl_method;
455 rl_src.location = kLocPhysReg;
Andreas Gampeccc60262014-07-04 18:02:38 -0700456 rl_src.reg = TargetReg(kArg0, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700457 rl_src.home = false;
buzbee091cc402014-03-31 10:14:40 -0700458 MarkLive(rl_src);
buzbeef2c3e562014-05-29 12:37:25 -0700459 StoreValue(rl_method, rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700460 // If Method* has been promoted, explicitly flush
461 if (rl_method.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700462 StoreRefDisp(TargetPtrReg(kSp), 0, rl_src.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700463 }
464
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800465 if (cu_->num_ins == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700466 return;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800467 }
468
Brian Carlstrom7940e442013-07-12 13:46:57 -0700469 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
470 /*
471 * Copy incoming arguments to their proper home locations.
472 * NOTE: an older version of dx had an issue in which
473 * it would reuse static method argument registers.
474 * This could result in the same Dalvik virtual register
475 * being promoted to both core and fp regs. To account for this,
476 * we only copy to the corresponding promoted physical register
477 * if it matches the type of the SSA name for the incoming
478 * argument. It is also possible that long and double arguments
479 * end up half-promoted. In those cases, we must flush the promoted
480 * half to memory as well.
481 */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100482 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700483 for (int i = 0; i < cu_->num_ins; i++) {
484 PromotionMap* v_map = &promotion_map_[start_vreg + i];
buzbee2700f7e2014-03-07 09:46:20 -0800485 RegStorage reg = GetArgMappingToPhysicalReg(i);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800486
buzbee2700f7e2014-03-07 09:46:20 -0800487 if (reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700488 // If arriving in register
489 bool need_flush = true;
490 RegLocation* t_loc = &ArgLocs[i];
491 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
buzbee2700f7e2014-03-07 09:46:20 -0800492 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700493 need_flush = false;
494 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
buzbeeb5860fb2014-06-21 15:31:01 -0700495 OpRegCopy(RegStorage::Solo32(v_map->fp_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700496 need_flush = false;
497 } else {
498 need_flush = true;
499 }
500
buzbeed0a03b82013-09-14 08:21:05 -0700501 // For wide args, force flush if not fully promoted
Brian Carlstrom7940e442013-07-12 13:46:57 -0700502 if (t_loc->wide) {
503 PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1);
buzbeed0a03b82013-09-14 08:21:05 -0700504 // Is only half promoted?
Brian Carlstrom7940e442013-07-12 13:46:57 -0700505 need_flush |= (p_map->core_location != v_map->core_location) ||
506 (p_map->fp_location != v_map->fp_location);
buzbeed0a03b82013-09-14 08:21:05 -0700507 if ((cu_->instruction_set == kThumb2) && t_loc->fp && !need_flush) {
508 /*
509 * In Arm, a double is represented as a pair of consecutive single float
510 * registers starting at an even number. It's possible that both Dalvik vRegs
511 * representing the incoming double were independently promoted as singles - but
512 * not in a form usable as a double. If so, we need to flush - even though the
513 * incoming arg appears fully in register. At this point in the code, both
514 * halves of the double are promoted. Make sure they are in a usable form.
515 */
516 int lowreg_index = start_vreg + i + (t_loc->high_word ? -1 : 0);
buzbeeb5860fb2014-06-21 15:31:01 -0700517 int low_reg = promotion_map_[lowreg_index].fp_reg;
518 int high_reg = promotion_map_[lowreg_index + 1].fp_reg;
buzbeed0a03b82013-09-14 08:21:05 -0700519 if (((low_reg & 0x1) != 0) || (high_reg != (low_reg + 1))) {
520 need_flush = true;
521 }
522 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700523 }
524 if (need_flush) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700525 Store32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700526 }
527 } else {
528 // If arriving in frame & promoted
529 if (v_map->core_location == kLocPhysReg) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700530 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i),
531 RegStorage::Solo32(v_map->core_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700532 }
533 if (v_map->fp_location == kLocPhysReg) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700534 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i),
535 RegStorage::Solo32(v_map->fp_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700536 }
537 }
538 }
539}
540
Andreas Gampeccc60262014-07-04 18:02:38 -0700541static void CommonCallCodeLoadThisIntoArg1(const CallInfo* info, Mir2Lir* cg) {
542 RegLocation rl_arg = info->args[0];
543 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1, kRef));
544}
545
546static void CommonCallCodeLoadClassIntoArg0(const CallInfo* info, Mir2Lir* cg) {
547 cg->GenNullCheck(cg->TargetReg(kArg1, kRef), info->opt_flags);
548 // get this->klass_ [use kArg1, set kArg0]
549 cg->LoadRefDisp(cg->TargetReg(kArg1, kRef), mirror::Object::ClassOffset().Int32Value(),
550 cg->TargetReg(kArg0, kRef),
551 kNotVolatile);
552 cg->MarkPossibleNullPointerException(info->opt_flags);
553}
554
555static bool CommonCallCodeLoadCodePointerIntoInvokeTgt(const CallInfo* info,
556 const RegStorage* alt_from,
557 const CompilationUnit* cu, Mir2Lir* cg) {
558 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
559 // Get the compiled code address [use *alt_from or kArg0, set kInvokeTgt]
560 cg->LoadWordDisp(alt_from == nullptr ? cg->TargetReg(kArg0, kRef) : *alt_from,
561 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
562 cg->TargetPtrReg(kInvokeTgt));
563 return true;
564 }
565 return false;
566}
567
Brian Carlstrom7940e442013-07-12 13:46:57 -0700568/*
569 * Bit of a hack here - in the absence of a real scheduling pass,
570 * emit the next instruction in static & direct invoke sequences.
571 */
572static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
573 int state, const MethodReference& target_method,
574 uint32_t unused,
575 uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700576 InvokeType type) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700577 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700578 if (direct_code != 0 && direct_method != 0) {
579 switch (state) {
580 case 0: // Get the current Method* [sets kArg0]
Ian Rogersff093b32014-04-30 19:04:27 -0700581 if (direct_code != static_cast<uintptr_t>(-1)) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700582 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700583 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
Ian Rogers83883d72013-10-21 21:07:24 -0700584 }
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700585 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Jeff Hao49161ce2014-03-12 11:05:25 -0700586 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700587 }
Ian Rogersff093b32014-04-30 19:04:27 -0700588 if (direct_method != static_cast<uintptr_t>(-1)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700589 cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700590 } else {
Jeff Hao49161ce2014-03-12 11:05:25 -0700591 cg->LoadMethodAddress(target_method, type, kArg0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700592 }
593 break;
594 default:
595 return -1;
596 }
597 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700598 RegStorage arg0_ref = cg->TargetReg(kArg0, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700599 switch (state) {
600 case 0: // Get the current Method* [sets kArg0]
601 // TUNING: we can save a reg copy if Method* has been promoted.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700602 cg->LoadCurrMethodDirect(arg0_ref);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700603 break;
604 case 1: // Get method->dex_cache_resolved_methods_
Andreas Gampe4b537a82014-06-30 22:24:53 -0700605 cg->LoadRefDisp(arg0_ref,
buzbee695d13a2014-04-19 13:32:20 -0700606 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700607 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000608 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700609 // Set up direct code if known.
610 if (direct_code != 0) {
Ian Rogersff093b32014-04-30 19:04:27 -0700611 if (direct_code != static_cast<uintptr_t>(-1)) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700612 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700613 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Ian Rogers83883d72013-10-21 21:07:24 -0700614 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Jeff Hao49161ce2014-03-12 11:05:25 -0700615 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700616 }
617 }
618 break;
619 case 2: // Grab target method*
620 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700621 cg->LoadRefDisp(arg0_ref,
Dmitry Petrochenko37498b62014-05-05 20:33:38 +0700622 ObjArray::OffsetOfElement(target_method.dex_method_index).Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700623 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000624 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700625 break;
626 case 3: // Grab the code from the method*
Andreas Gampeccc60262014-07-04 18:02:38 -0700627 if (direct_code == 0) {
628 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, &arg0_ref, cu, cg)) {
629 break; // kInvokeTgt := arg0_ref->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700630 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700631 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700632 break;
633 }
634 // Intentional fallthrough for x86
635 default:
636 return -1;
637 }
638 }
639 return state + 1;
640}
641
642/*
643 * Bit of a hack here - in the absence of a real scheduling pass,
644 * emit the next instruction in a virtual invoke sequence.
645 * We can use kLr as a temp prior to target address loading
646 * Note also that we'll load the first argument ("this") into
647 * kArg1 here rather than the standard LoadArgRegs.
648 */
649static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
650 int state, const MethodReference& target_method,
651 uint32_t method_idx, uintptr_t unused, uintptr_t unused2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700652 InvokeType unused3) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700653 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
654 /*
655 * This is the fast path in which the target virtual method is
656 * fully resolved at compile time.
657 */
658 switch (state) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700659 case 0:
660 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Brian Carlstrom7940e442013-07-12 13:46:57 -0700661 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700662 case 1:
663 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
664 // Includes a null-check.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700665 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700666 case 2: {
667 // Get this->klass_.embedded_vtable[method_idx] [usr kArg0, set kArg0]
668 int32_t offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
669 method_idx * sizeof(mirror::Class::VTableEntry);
670 // Load target method from embedded vtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700671 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700672 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700673 }
674 case 3:
Andreas Gampeccc60262014-07-04 18:02:38 -0700675 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, nullptr, cu, cg)) {
676 break; // kInvokeTgt := kArg0->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700677 }
678 // Intentional fallthrough for X86
679 default:
680 return -1;
681 }
682 return state + 1;
683}
684
685/*
Jeff Hao88474b42013-10-23 16:24:40 -0700686 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
687 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
688 * more than one interface method map to the same index. Note also that we'll load the first
689 * argument ("this") into kArg1 here rather than the standard LoadArgRegs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700690 */
691static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
692 const MethodReference& target_method,
Jeff Hao88474b42013-10-23 16:24:40 -0700693 uint32_t method_idx, uintptr_t unused,
694 uintptr_t direct_method, InvokeType unused2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700695 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700696
Jeff Hao88474b42013-10-23 16:24:40 -0700697 switch (state) {
698 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700699 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Andreas Gampeccc60262014-07-04 18:02:38 -0700700 cg->LoadConstant(cg->TargetReg(kHiddenArg, kNotWide), target_method.dex_method_index);
Mark Mendelld3703d82014-06-09 15:10:50 -0400701 if (cu->instruction_set == kX86) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700702 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg, kNotWide), cg->TargetReg(kHiddenArg, kNotWide));
Jeff Hao88474b42013-10-23 16:24:40 -0700703 }
704 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700705 case 1:
706 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Jeff Hao88474b42013-10-23 16:24:40 -0700707 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700708 case 2:
709 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
710 // Includes a null-check.
Jeff Hao88474b42013-10-23 16:24:40 -0700711 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700712 case 3: { // Get target method [use kInvokeTgt, set kArg0]
713 int32_t offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
714 (method_idx % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
715 // Load target method from embedded imtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700716 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Jeff Hao88474b42013-10-23 16:24:40 -0700717 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700718 }
719 case 4:
Andreas Gampeccc60262014-07-04 18:02:38 -0700720 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, nullptr, cu, cg)) {
721 break; // kInvokeTgt := kArg0->entrypoint
Jeff Hao88474b42013-10-23 16:24:40 -0700722 }
723 // Intentional fallthrough for X86
Brian Carlstrom7940e442013-07-12 13:46:57 -0700724 default:
725 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700726 }
727 return state + 1;
728}
729
Andreas Gampe2f244e92014-05-08 03:35:25 -0700730template <size_t pointer_size>
Andreas Gampeccc60262014-07-04 18:02:38 -0700731static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info,
732 ThreadOffset<pointer_size> trampoline, int state,
733 const MethodReference& target_method, uint32_t method_idx) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700734 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
735 /*
736 * This handles the case in which the base method is not fully
737 * resolved at compile time, we bail to a runtime helper.
738 */
739 if (state == 0) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700740 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700741 // Load trampoline target
Andreas Gampeccc60262014-07-04 18:02:38 -0700742 cg->LoadWordDisp(cg->TargetPtrReg(kSelf), trampoline.Int32Value(),
743 cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700744 }
745 // Load kArg0 with method index
746 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampeccc60262014-07-04 18:02:38 -0700747 cg->LoadConstant(cg->TargetReg(kArg0, kNotWide), target_method.dex_method_index);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700748 return 1;
749 }
750 return -1;
751}
752
753static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
754 int state,
755 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000756 uint32_t unused, uintptr_t unused2,
757 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700758 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700759 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeStaticTrampolineWithAccessCheck);
760 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
761 } else {
762 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeStaticTrampolineWithAccessCheck);
763 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
764 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700765}
766
767static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
768 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000769 uint32_t unused, uintptr_t unused2,
770 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700771 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700772 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeDirectTrampolineWithAccessCheck);
773 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
774 } else {
775 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeDirectTrampolineWithAccessCheck);
776 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
777 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700778}
779
780static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
781 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000782 uint32_t unused, uintptr_t unused2,
783 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700784 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700785 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeSuperTrampolineWithAccessCheck);
786 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
787 } else {
788 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeSuperTrampolineWithAccessCheck);
789 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
790 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700791}
792
793static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
794 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000795 uint32_t unused, uintptr_t unused2,
796 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700797 if (cu->target64) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700798 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8,
799 pInvokeVirtualTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700800 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
801 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700802 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4,
803 pInvokeVirtualTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700804 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
805 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700806}
807
808static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
809 CallInfo* info, int state,
810 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000811 uint32_t unused, uintptr_t unused2,
812 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700813 if (cu->target64) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700814 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8,
815 pInvokeInterfaceTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700816 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
817 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700818 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4,
819 pInvokeInterfaceTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700820 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
821 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700822}
823
824int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
825 NextCallInsn next_call_insn,
826 const MethodReference& target_method,
827 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700828 uintptr_t direct_method, InvokeType type, bool skip_this) {
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700829 int last_arg_reg = 3 - 1;
Andreas Gampeccc60262014-07-04 18:02:38 -0700830 int arg_regs[3] = {TargetReg(kArg1, kNotWide).GetReg(), TargetReg(kArg2, kNotWide).GetReg(),
831 TargetReg(kArg3, kNotWide).GetReg()};
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700832
833 int next_reg = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700834 int next_arg = 0;
835 if (skip_this) {
836 next_reg++;
837 next_arg++;
838 }
839 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
840 RegLocation rl_arg = info->args[next_arg++];
841 rl_arg = UpdateRawLoc(rl_arg);
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700842 if (rl_arg.wide && (next_reg <= last_arg_reg - 1)) {
843 RegStorage r_tmp(RegStorage::k64BitPair, arg_regs[next_reg], arg_regs[next_reg + 1]);
buzbee2700f7e2014-03-07 09:46:20 -0800844 LoadValueDirectWideFixed(rl_arg, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700845 next_reg++;
846 next_arg++;
847 } else {
848 if (rl_arg.wide) {
buzbee2700f7e2014-03-07 09:46:20 -0800849 rl_arg = NarrowRegLoc(rl_arg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700850 rl_arg.is_const = false;
851 }
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700852 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(arg_regs[next_reg]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700853 }
854 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
855 direct_code, direct_method, type);
856 }
857 return call_state;
858}
859
860/*
861 * Load up to 5 arguments, the first three of which will be in
862 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
863 * and as part of the load sequence, it must be replaced with
864 * the target method pointer. Note, this may also be called
865 * for "range" variants if the number of arguments is 5 or fewer.
866 */
867int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info,
868 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
869 const MethodReference& target_method,
870 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700871 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700872 RegLocation rl_arg;
873
874 /* If no arguments, just return */
875 if (info->num_arg_words == 0)
876 return call_state;
877
878 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
879 direct_code, direct_method, type);
880
881 DCHECK_LE(info->num_arg_words, 5);
882 if (info->num_arg_words > 3) {
883 int32_t next_use = 3;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700884 // Detect special case of wide arg spanning arg3/arg4
Brian Carlstrom7940e442013-07-12 13:46:57 -0700885 RegLocation rl_use0 = info->args[0];
886 RegLocation rl_use1 = info->args[1];
887 RegLocation rl_use2 = info->args[2];
buzbee2700f7e2014-03-07 09:46:20 -0800888 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) && rl_use2.wide) {
889 RegStorage reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700890 // Wide spans, we need the 2nd half of uses[2].
891 rl_arg = UpdateLocWide(rl_use2);
892 if (rl_arg.location == kLocPhysReg) {
buzbee85089dd2014-05-25 15:10:52 -0700893 if (rl_arg.reg.IsPair()) {
894 reg = rl_arg.reg.GetHigh();
895 } else {
896 RegisterInfo* info = GetRegInfo(rl_arg.reg);
897 info = info->FindMatchingView(RegisterInfo::kHighSingleStorageMask);
898 if (info == nullptr) {
899 // NOTE: For hard float convention we won't split arguments across reg/mem.
900 UNIMPLEMENTED(FATAL) << "Needs hard float api.";
901 }
902 reg = info->GetReg();
903 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700904 } else {
905 // kArg2 & rArg3 can safely be used here
Andreas Gampeccc60262014-07-04 18:02:38 -0700906 reg = TargetReg(kArg3, kNotWide);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100907 {
908 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700909 Load32Disp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100910 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700911 call_state = next_call_insn(cu_, info, call_state, target_method,
912 vtable_idx, direct_code, direct_method, type);
913 }
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100914 {
915 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700916 Store32Disp(TargetPtrReg(kSp), (next_use + 1) * 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100917 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700918 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
919 direct_code, direct_method, type);
920 next_use++;
921 }
922 // Loop through the rest
923 while (next_use < info->num_arg_words) {
buzbee091cc402014-03-31 10:14:40 -0700924 RegStorage arg_reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700925 rl_arg = info->args[next_use];
926 rl_arg = UpdateRawLoc(rl_arg);
927 if (rl_arg.location == kLocPhysReg) {
buzbee091cc402014-03-31 10:14:40 -0700928 arg_reg = rl_arg.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700929 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700930 arg_reg = TargetReg(kArg2, rl_arg.wide ? kWide : kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700931 if (rl_arg.wide) {
buzbee091cc402014-03-31 10:14:40 -0700932 LoadValueDirectWideFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700933 } else {
buzbee091cc402014-03-31 10:14:40 -0700934 LoadValueDirectFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700935 }
936 call_state = next_call_insn(cu_, info, call_state, target_method,
937 vtable_idx, direct_code, direct_method, type);
938 }
939 int outs_offset = (next_use + 1) * 4;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100940 {
941 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
942 if (rl_arg.wide) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700943 StoreBaseDisp(TargetPtrReg(kSp), outs_offset, arg_reg, k64, kNotVolatile);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100944 next_use += 2;
945 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700946 Store32Disp(TargetPtrReg(kSp), outs_offset, arg_reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100947 next_use++;
948 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700949 }
950 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
951 direct_code, direct_method, type);
952 }
953 }
954
955 call_state = LoadArgRegs(info, call_state, next_call_insn,
956 target_method, vtable_idx, direct_code, direct_method,
957 type, skip_this);
958
959 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +0000960 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700961 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700962 } else {
963 *pcrLabel = nullptr;
Dave Allison69dfe512014-07-11 17:11:58 +0000964 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) &&
965 (info->opt_flags & MIR_IGNORE_NULL_CHECK)) {
966 return call_state;
967 }
Dave Allisonf9439142014-03-27 15:10:22 -0700968 // In lieu of generating a check for kArg1 being null, we need to
969 // perform a load when doing implicit checks.
Dave Allison69dfe512014-07-11 17:11:58 +0000970 GenImplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700971 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700972 }
973 return call_state;
974}
975
Dave Allison69dfe512014-07-11 17:11:58 +0000976// Default implementation of implicit null pointer check.
977// Overridden by arch specific as necessary.
978void Mir2Lir::GenImplicitNullCheck(RegStorage reg, int opt_flags) {
979 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) && (opt_flags & MIR_IGNORE_NULL_CHECK)) {
980 return;
981 }
982 RegStorage tmp = AllocTemp();
983 Load32Disp(reg, 0, tmp);
984 MarkPossibleNullPointerException(opt_flags);
985 FreeTemp(tmp);
986}
987
988
Brian Carlstrom7940e442013-07-12 13:46:57 -0700989/*
990 * May have 0+ arguments (also used for jumbo). Note that
991 * source virtual registers may be in physical registers, so may
992 * need to be flushed to home location before copying. This
993 * applies to arg3 and above (see below).
994 *
995 * Two general strategies:
996 * If < 20 arguments
997 * Pass args 3-18 using vldm/vstm block copy
998 * Pass arg0, arg1 & arg2 in kArg1-kArg3
999 * If 20+ arguments
1000 * Pass args arg19+ using memcpy block copy
1001 * Pass arg0, arg1 & arg2 in kArg1-kArg3
1002 *
1003 */
1004int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state,
1005 LIR** pcrLabel, NextCallInsn next_call_insn,
1006 const MethodReference& target_method,
1007 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001008 InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001009 // If we can treat it as non-range (Jumbo ops will use range form)
1010 if (info->num_arg_words <= 5)
1011 return GenDalvikArgsNoRange(info, call_state, pcrLabel,
1012 next_call_insn, target_method, vtable_idx,
1013 direct_code, direct_method, type, skip_this);
1014 /*
1015 * First load the non-register arguments. Both forms expect all
1016 * of the source arguments to be in their home frame location, so
1017 * scan the s_reg names and flush any that have been promoted to
1018 * frame backing storage.
1019 */
1020 // Scan the rest of the args - if in phys_reg flush to memory
1021 for (int next_arg = 0; next_arg < info->num_arg_words;) {
1022 RegLocation loc = info->args[next_arg];
1023 if (loc.wide) {
1024 loc = UpdateLocWide(loc);
1025 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001026 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001027 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001028 }
1029 next_arg += 2;
1030 } else {
1031 loc = UpdateLoc(loc);
1032 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001033 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001034 Store32Disp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001035 }
1036 next_arg++;
1037 }
1038 }
1039
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001040 // Logic below assumes that Method pointer is at offset zero from SP.
1041 DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0);
1042
1043 // The first 3 arguments are passed via registers.
1044 // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either
1045 // get size of uintptr_t or size of object reference according to model being used.
1046 int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001047 int start_offset = SRegOffset(info->args[3].s_reg_low);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001048 int regs_left_to_pass_via_stack = info->num_arg_words - 3;
1049 DCHECK_GT(regs_left_to_pass_via_stack, 0);
1050
1051 if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) {
1052 // Use vldm/vstm pair using kArg3 as a temp
1053 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1054 direct_code, direct_method, type);
Andreas Gampeccc60262014-07-04 18:02:38 -07001055 OpRegRegImm(kOpAdd, TargetReg(kArg3, kRef), TargetPtrReg(kSp), start_offset);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001056 LIR* ld = nullptr;
1057 {
1058 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Andreas Gampeccc60262014-07-04 18:02:38 -07001059 ld = OpVldm(TargetReg(kArg3, kRef), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001060 }
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001061 // TUNING: loosen barrier
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001062 ld->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001063 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1064 direct_code, direct_method, type);
Andreas Gampeccc60262014-07-04 18:02:38 -07001065 OpRegRegImm(kOpAdd, TargetReg(kArg3, kRef), TargetPtrReg(kSp), 4 /* Method* */ + (3 * 4));
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001066 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1067 direct_code, direct_method, type);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001068 LIR* st = nullptr;
1069 {
1070 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Andreas Gampeccc60262014-07-04 18:02:38 -07001071 st = OpVstm(TargetReg(kArg3, kRef), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001072 }
1073 st->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001074 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1075 direct_code, direct_method, type);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001076 } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001077 int current_src_offset = start_offset;
1078 int current_dest_offset = outs_offset;
1079
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001080 // Only davik regs are accessed in this loop; no next_call_insn() calls.
1081 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001082 while (regs_left_to_pass_via_stack > 0) {
1083 // This is based on the knowledge that the stack itself is 16-byte aligned.
1084 bool src_is_16b_aligned = (current_src_offset & 0xF) == 0;
1085 bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0;
1086 size_t bytes_to_move;
1087
1088 /*
1089 * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a
1090 * a 128-bit move because we won't get the chance to try to aligned. If there are more than
1091 * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned.
1092 * We do this because we could potentially do a smaller move to align.
1093 */
1094 if (regs_left_to_pass_via_stack == 4 ||
1095 (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) {
1096 // Moving 128-bits via xmm register.
1097 bytes_to_move = sizeof(uint32_t) * 4;
1098
1099 // Allocate a free xmm temp. Since we are working through the calling sequence,
Mark Mendelle87f9b52014-04-30 14:13:18 -04001100 // we expect to have an xmm temporary available. AllocTempDouble will abort if
1101 // there are no free registers.
buzbee2700f7e2014-03-07 09:46:20 -08001102 RegStorage temp = AllocTempDouble();
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001103
1104 LIR* ld1 = nullptr;
1105 LIR* ld2 = nullptr;
1106 LIR* st1 = nullptr;
1107 LIR* st2 = nullptr;
1108
1109 /*
1110 * The logic is similar for both loads and stores. If we have 16-byte alignment,
1111 * do an aligned move. If we have 8-byte alignment, then do the move in two
1112 * parts. This approach prevents possible cache line splits. Finally, fall back
1113 * to doing an unaligned move. In most cases we likely won't split the cache
1114 * line but we cannot prove it and thus take a conservative approach.
1115 */
1116 bool src_is_8b_aligned = (current_src_offset & 0x7) == 0;
1117 bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0;
1118
1119 if (src_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001120 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001121 } else if (src_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001122 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovLo128FP);
1123 ld2 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001124 kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001125 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001126 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001127 }
1128
1129 if (dest_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001130 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001131 } else if (dest_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001132 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovLo128FP);
1133 st2 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001134 temp, kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001135 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001136 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001137 }
1138
1139 // TODO If we could keep track of aliasing information for memory accesses that are wider
1140 // than 64-bit, we wouldn't need to set up a barrier.
1141 if (ld1 != nullptr) {
1142 if (ld2 != nullptr) {
1143 // For 64-bit load we can actually set up the aliasing information.
1144 AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001145 AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true,
1146 true);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001147 } else {
1148 // Set barrier for 128-bit load.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001149 ld1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001150 }
1151 }
1152 if (st1 != nullptr) {
1153 if (st2 != nullptr) {
1154 // For 64-bit store we can actually set up the aliasing information.
1155 AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001156 AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false,
1157 true);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001158 } else {
1159 // Set barrier for 128-bit store.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001160 st1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001161 }
1162 }
1163
1164 // Free the temporary used for the data movement.
buzbee091cc402014-03-31 10:14:40 -07001165 FreeTemp(temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001166 } else {
1167 // Moving 32-bits via general purpose register.
1168 bytes_to_move = sizeof(uint32_t);
1169
1170 // Instead of allocating a new temp, simply reuse one of the registers being used
1171 // for argument passing.
Andreas Gampeccc60262014-07-04 18:02:38 -07001172 RegStorage temp = TargetReg(kArg3, kNotWide);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001173
1174 // Now load the argument VR and store to the outs.
Chao-ying Fua77ee512014-07-01 17:43:41 -07001175 Load32Disp(TargetPtrReg(kSp), current_src_offset, temp);
1176 Store32Disp(TargetPtrReg(kSp), current_dest_offset, temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001177 }
1178
1179 current_src_offset += bytes_to_move;
1180 current_dest_offset += bytes_to_move;
1181 regs_left_to_pass_via_stack -= (bytes_to_move >> 2);
1182 }
1183 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001184 // Generate memcpy
Andreas Gampeccc60262014-07-04 18:02:38 -07001185 OpRegRegImm(kOpAdd, TargetReg(kArg0, kRef), TargetPtrReg(kSp), outs_offset);
1186 OpRegRegImm(kOpAdd, TargetReg(kArg1, kRef), TargetPtrReg(kSp), start_offset);
buzbee33ae5582014-06-12 14:56:32 -07001187 if (cu_->target64) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001188 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(8, pMemcpy), TargetReg(kArg0, kRef),
1189 TargetReg(kArg1, kRef), (info->num_arg_words - 3) * 4, false);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001190 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -07001191 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(4, pMemcpy), TargetReg(kArg0, kRef),
1192 TargetReg(kArg1, kRef), (info->num_arg_words - 3) * 4, false);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001193 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001194 }
1195
1196 call_state = LoadArgRegs(info, call_state, next_call_insn,
1197 target_method, vtable_idx, direct_code, direct_method,
1198 type, skip_this);
1199
1200 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1201 direct_code, direct_method, type);
1202 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +00001203 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001204 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -07001205 } else {
1206 *pcrLabel = nullptr;
Dave Allison69dfe512014-07-11 17:11:58 +00001207 if (!(cu_->disable_opt & (1 << kNullCheckElimination)) &&
1208 (info->opt_flags & MIR_IGNORE_NULL_CHECK)) {
1209 return call_state;
1210 }
Dave Allisonf9439142014-03-27 15:10:22 -07001211 // In lieu of generating a check for kArg1 being null, we need to
1212 // perform a load when doing implicit checks.
Dave Allison69dfe512014-07-11 17:11:58 +00001213 GenImplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -07001214 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001215 }
1216 return call_state;
1217}
1218
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001219RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001220 RegLocation res;
1221 if (info->result.location == kLocInvalid) {
buzbeea0cd2d72014-06-01 09:33:49 -07001222 res = GetReturn(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001223 } else {
1224 res = info->result;
1225 }
1226 return res;
1227}
1228
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001229RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001230 RegLocation res;
1231 if (info->result.location == kLocInvalid) {
buzbeea0cd2d72014-06-01 09:33:49 -07001232 res = GetReturnWide(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001233 } else {
1234 res = info->result;
1235 }
1236 return res;
1237}
1238
Fred Shih4ee7a662014-07-11 09:59:27 -07001239bool Mir2Lir::GenInlinedGet(CallInfo* info) {
1240 if (cu_->instruction_set == kMips) {
1241 // TODO - add Mips implementation
1242 return false;
1243 }
1244
1245 // the refrence class is stored in the image dex file which might not be the same as the cu's
1246 // dex file. Query the reference class for the image dex file then reset to starting dex file
1247 // in after loading class type.
1248 uint16_t type_idx = 0;
1249 const DexFile* ref_dex_file = nullptr;
1250 {
1251 ScopedObjectAccess soa(Thread::Current());
1252 type_idx = mirror::Reference::GetJavaLangRefReference()->GetDexTypeIndex();
1253 ref_dex_file = mirror::Reference::GetJavaLangRefReference()->GetDexCache()->GetDexFile();
1254 }
1255 CHECK(LIKELY(ref_dex_file != nullptr));
1256
1257 // address is either static within the image file, or needs to be patched up after compilation.
1258 bool unused_type_initialized;
1259 bool use_direct_type_ptr;
1260 uintptr_t direct_type_ptr;
1261 bool is_finalizable;
1262 const DexFile* old_dex = cu_->dex_file;
1263 cu_->dex_file = ref_dex_file;
Andreas Gampe30ab8a82014-07-17 00:12:32 -07001264 RegStorage reg_class = TargetReg(kArg1, kRef);
1265 Clobber(reg_class);
1266 LockTemp(reg_class);
Fred Shih4ee7a662014-07-11 09:59:27 -07001267 if (!cu_->compiler_driver->CanEmbedTypeInCode(*ref_dex_file, type_idx, &unused_type_initialized,
1268 &use_direct_type_ptr, &direct_type_ptr,
1269 &is_finalizable) || is_finalizable) {
1270 cu_->dex_file = old_dex;
1271 // address is not known and post-compile patch is not possible, cannot insert intrinsic.
1272 return false;
1273 }
1274 if (use_direct_type_ptr) {
1275 LoadConstant(reg_class, direct_type_ptr);
1276 } else {
1277 LoadClassType(type_idx, kArg1);
1278 }
1279 cu_->dex_file = old_dex;
1280
1281 // get the offset for flags in reference class.
1282 uint32_t slow_path_flag_offset = 0;
1283 uint32_t disable_flag_offset = 0;
1284 {
1285 ScopedObjectAccess soa(Thread::Current());
1286 mirror::Class* reference_class = mirror::Reference::GetJavaLangRefReference();
1287 slow_path_flag_offset = reference_class->GetSlowPathFlagOffset().Uint32Value();
1288 disable_flag_offset = reference_class->GetDisableIntrinsicFlagOffset().Uint32Value();
1289 }
1290 CHECK(slow_path_flag_offset && disable_flag_offset &&
1291 (slow_path_flag_offset != disable_flag_offset));
1292
1293 // intrinsic logic start.
1294 RegLocation rl_obj = info->args[0];
1295 rl_obj = LoadValue(rl_obj);
1296
1297 RegStorage reg_slow_path = AllocTemp();
1298 RegStorage reg_disabled = AllocTemp();
1299 Load32Disp(reg_class, slow_path_flag_offset, reg_slow_path);
1300 Load32Disp(reg_class, disable_flag_offset, reg_disabled);
Andreas Gampe30ab8a82014-07-17 00:12:32 -07001301 FreeTemp(reg_class);
1302 LIR* or_inst = OpRegRegReg(kOpOr, reg_slow_path, reg_slow_path, reg_disabled);
Fred Shih4ee7a662014-07-11 09:59:27 -07001303 FreeTemp(reg_disabled);
1304
1305 // if slow path, jump to JNI path target
Andreas Gampe30ab8a82014-07-17 00:12:32 -07001306 LIR* slow_path_branch;
1307 if (or_inst->u.m.def_mask->HasBit(ResourceMask::kCCode)) {
1308 // Generate conditional branch only, as the OR set a condition state (we are interested in a 'Z' flag).
1309 slow_path_branch = OpCondBranch(kCondNe, nullptr);
1310 } else {
1311 // Generate compare and branch.
1312 slow_path_branch = OpCmpImmBranch(kCondNe, reg_slow_path, 0, nullptr);
1313 }
Fred Shih4ee7a662014-07-11 09:59:27 -07001314 FreeTemp(reg_slow_path);
1315
1316 // slow path not enabled, simply load the referent of the reference object
1317 RegLocation rl_dest = InlineTarget(info);
1318 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
1319 GenNullCheck(rl_obj.reg, info->opt_flags);
1320 LoadRefDisp(rl_obj.reg, mirror::Reference::ReferentOffset().Int32Value(), rl_result.reg,
1321 kNotVolatile);
1322 MarkPossibleNullPointerException(info->opt_flags);
1323 StoreValue(rl_dest, rl_result);
1324
1325 LIR* intrinsic_finish = NewLIR0(kPseudoTargetLabel);
1326 AddIntrinsicSlowPath(info, slow_path_branch, intrinsic_finish);
1327
1328 return true;
1329}
1330
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001331bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001332 if (cu_->instruction_set == kMips) {
1333 // TODO - add Mips implementation
1334 return false;
1335 }
1336 // Location of reference to data array
1337 int value_offset = mirror::String::ValueOffset().Int32Value();
1338 // Location of count
1339 int count_offset = mirror::String::CountOffset().Int32Value();
1340 // Starting offset within data array
1341 int offset_offset = mirror::String::OffsetOffset().Int32Value();
1342 // Start of char data with array_
1343 int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value();
1344
1345 RegLocation rl_obj = info->args[0];
1346 RegLocation rl_idx = info->args[1];
buzbeea0cd2d72014-06-01 09:33:49 -07001347 rl_obj = LoadValue(rl_obj, kRefReg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001348 // X86 wants to avoid putting a constant index into a register.
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001349 if (!((cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64)&& rl_idx.is_const)) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001350 rl_idx = LoadValue(rl_idx, kCoreReg);
1351 }
buzbee2700f7e2014-03-07 09:46:20 -08001352 RegStorage reg_max;
1353 GenNullCheck(rl_obj.reg, info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001354 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001355 LIR* range_check_branch = nullptr;
buzbee2700f7e2014-03-07 09:46:20 -08001356 RegStorage reg_off;
1357 RegStorage reg_ptr;
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001358 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001359 reg_off = AllocTemp();
buzbeea0cd2d72014-06-01 09:33:49 -07001360 reg_ptr = AllocTempRef();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001361 if (range_check) {
1362 reg_max = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -07001363 Load32Disp(rl_obj.reg, count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -08001364 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001365 }
buzbee695d13a2014-04-19 13:32:20 -07001366 Load32Disp(rl_obj.reg, offset_offset, reg_off);
Dave Allisonb373e092014-02-20 16:06:36 -08001367 MarkPossibleNullPointerException(info->opt_flags);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001368 LoadRefDisp(rl_obj.reg, value_offset, reg_ptr, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001369 if (range_check) {
Mingyao Yang3a74d152014-04-21 15:39:44 -07001370 // Set up a slow path to allow retry in case of bounds violation */
buzbee2700f7e2014-03-07 09:46:20 -08001371 OpRegReg(kOpCmp, rl_idx.reg, reg_max);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001372 FreeTemp(reg_max);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001373 range_check_branch = OpCondBranch(kCondUge, nullptr);
Brian Carlstrom6f485c62013-07-18 15:35:35 -07001374 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001375 OpRegImm(kOpAdd, reg_ptr, data_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001376 } else {
1377 if (range_check) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001378 // On x86, we can compare to memory directly
Brian Carlstrom7940e442013-07-12 13:46:57 -07001379 // Set up a launch pad to allow retry in case of bounds violation */
Mark Mendell2b724cb2014-02-06 05:24:20 -08001380 if (rl_idx.is_const) {
Dave Allison69dfe512014-07-11 17:11:58 +00001381 LIR* comparison;
Vladimir Marko3bc86152014-03-13 14:11:28 +00001382 range_check_branch = OpCmpMemImmBranch(
buzbee2700f7e2014-03-07 09:46:20 -08001383 kCondUlt, RegStorage::InvalidReg(), rl_obj.reg, count_offset,
Dave Allison69dfe512014-07-11 17:11:58 +00001384 mir_graph_->ConstantValue(rl_idx.orig_sreg), nullptr, &comparison);
1385 MarkPossibleNullPointerExceptionAfter(0, comparison);
1386 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001387 OpRegMem(kOpCmp, rl_idx.reg, rl_obj.reg, count_offset);
Dave Allison69dfe512014-07-11 17:11:58 +00001388 MarkPossibleNullPointerException(0);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001389 range_check_branch = OpCondBranch(kCondUge, nullptr);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001390 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001391 }
1392 reg_off = AllocTemp();
buzbeea0cd2d72014-06-01 09:33:49 -07001393 reg_ptr = AllocTempRef();
buzbee695d13a2014-04-19 13:32:20 -07001394 Load32Disp(rl_obj.reg, offset_offset, reg_off);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001395 LoadRefDisp(rl_obj.reg, value_offset, reg_ptr, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001396 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001397 if (rl_idx.is_const) {
1398 OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg));
1399 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001400 OpRegReg(kOpAdd, reg_off, rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001401 }
buzbee2700f7e2014-03-07 09:46:20 -08001402 FreeTemp(rl_obj.reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001403 if (rl_idx.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -08001404 FreeTemp(rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001405 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001406 RegLocation rl_dest = InlineTarget(info);
1407 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001408 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
buzbee2700f7e2014-03-07 09:46:20 -08001409 LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg, 1, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001410 } else {
Vladimir Marko3bf7c602014-05-07 14:55:43 +01001411 LoadBaseIndexedDisp(reg_ptr, reg_off, 1, data_offset, rl_result.reg, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001412 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001413 FreeTemp(reg_off);
1414 FreeTemp(reg_ptr);
1415 StoreValue(rl_dest, rl_result);
1416 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001417 DCHECK(range_check_branch != nullptr);
1418 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001419 AddIntrinsicSlowPath(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001420 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001421 return true;
1422}
1423
1424// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001425bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001426 if (cu_->instruction_set == kMips) {
1427 // TODO - add Mips implementation
1428 return false;
1429 }
1430 // dst = src.length();
1431 RegLocation rl_obj = info->args[0];
buzbeea0cd2d72014-06-01 09:33:49 -07001432 rl_obj = LoadValue(rl_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001433 RegLocation rl_dest = InlineTarget(info);
1434 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001435 GenNullCheck(rl_obj.reg, info->opt_flags);
buzbee695d13a2014-04-19 13:32:20 -07001436 Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg);
Dave Allisonb373e092014-02-20 16:06:36 -08001437 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001438 if (is_empty) {
1439 // dst = (dst == 0);
1440 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001441 RegStorage t_reg = AllocTemp();
1442 OpRegReg(kOpNeg, t_reg, rl_result.reg);
1443 OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001444 } else if (cu_->instruction_set == kArm64) {
1445 OpRegImm(kOpSub, rl_result.reg, 1);
1446 OpRegRegImm(kOpLsr, rl_result.reg, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001447 } else {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001448 DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64);
buzbee2700f7e2014-03-07 09:46:20 -08001449 OpRegImm(kOpSub, rl_result.reg, 1);
1450 OpRegImm(kOpLsr, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001451 }
1452 }
1453 StoreValue(rl_dest, rl_result);
1454 return true;
1455}
1456
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001457bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
Zheng Xua3fe7422014-07-09 14:03:15 +08001458 if (cu_->instruction_set == kMips) {
1459 // TODO - add Mips implementation.
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001460 return false;
1461 }
1462 RegLocation rl_src_i = info->args[0];
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001463 RegLocation rl_i = (size == k64) ? LoadValueWide(rl_src_i, kCoreReg) : LoadValue(rl_src_i, kCoreReg);
buzbee695d13a2014-04-19 13:32:20 -07001464 RegLocation rl_dest = (size == k64) ? InlineTargetWide(info) : InlineTarget(info); // result reg
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001465 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee695d13a2014-04-19 13:32:20 -07001466 if (size == k64) {
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001467 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Serban Constantinescu169489b2014-06-11 16:43:35 +01001468 OpRegReg(kOpRev, rl_result.reg, rl_i.reg);
1469 StoreValueWide(rl_dest, rl_result);
1470 return true;
1471 }
buzbee2700f7e2014-03-07 09:46:20 -08001472 RegStorage r_i_low = rl_i.reg.GetLow();
1473 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001474 // 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 +00001475 r_i_low = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -08001476 OpRegCopy(r_i_low, rl_i.reg);
Vladimir Markof246af22013-11-27 12:30:15 +00001477 }
buzbee2700f7e2014-03-07 09:46:20 -08001478 OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh());
1479 OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low);
1480 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001481 FreeTemp(r_i_low);
1482 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001483 StoreValueWide(rl_dest, rl_result);
1484 } else {
buzbee695d13a2014-04-19 13:32:20 -07001485 DCHECK(size == k32 || size == kSignedHalf);
1486 OpKind op = (size == k32) ? kOpRev : kOpRevsh;
buzbee2700f7e2014-03-07 09:46:20 -08001487 OpRegReg(op, rl_result.reg, rl_i.reg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001488 StoreValue(rl_dest, rl_result);
1489 }
1490 return true;
1491}
1492
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001493bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001494 if (cu_->instruction_set == kMips) {
1495 // TODO - add Mips implementation
1496 return false;
1497 }
1498 RegLocation rl_src = info->args[0];
1499 rl_src = LoadValue(rl_src, kCoreReg);
1500 RegLocation rl_dest = InlineTarget(info);
1501 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001502 RegStorage sign_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001503 // abs(x) = y<=x>>31, (x+y)^y.
buzbee2700f7e2014-03-07 09:46:20 -08001504 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31);
1505 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1506 OpRegReg(kOpXor, rl_result.reg, sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001507 StoreValue(rl_dest, rl_result);
1508 return true;
1509}
1510
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001511bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001512 if (cu_->instruction_set == kMips) {
1513 // TODO - add Mips implementation
1514 return false;
1515 }
Vladimir Markob9823312014-03-20 17:38:43 +00001516 RegLocation rl_src = info->args[0];
1517 rl_src = LoadValueWide(rl_src, kCoreReg);
1518 RegLocation rl_dest = InlineTargetWide(info);
1519 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1520
1521 // If on x86 or if we would clobber a register needed later, just copy the source first.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001522 if (cu_->instruction_set != kX86_64 &&
1523 (cu_->instruction_set == kX86 ||
1524 rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001525 OpRegCopyWide(rl_result.reg, rl_src.reg);
1526 if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() &&
1527 rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() &&
1528 rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() &&
Vladimir Markob9823312014-03-20 17:38:43 +00001529 rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) {
1530 // Reuse source registers to avoid running out of temps.
buzbee2700f7e2014-03-07 09:46:20 -08001531 FreeTemp(rl_src.reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001532 }
1533 rl_src = rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001534 }
Vladimir Markob9823312014-03-20 17:38:43 +00001535
1536 // abs(x) = y<=x>>31, (x+y)^y.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001537 RegStorage sign_reg;
1538 if (cu_->instruction_set == kX86_64) {
1539 sign_reg = AllocTempWide();
1540 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 63);
1541 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1542 OpRegReg(kOpXor, rl_result.reg, sign_reg);
1543 } else {
1544 sign_reg = AllocTemp();
1545 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31);
1546 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg);
1547 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg);
1548 OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg);
1549 OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg);
1550 }
buzbee082833c2014-05-17 23:16:26 -07001551 FreeTemp(sign_reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001552 StoreValueWide(rl_dest, rl_result);
1553 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001554}
1555
Yixin Shoudbb17e32014-02-07 05:09:30 -08001556bool Mir2Lir::GenInlinedAbsFloat(CallInfo* info) {
1557 if (cu_->instruction_set == kMips) {
1558 // TODO - add Mips implementation
1559 return false;
1560 }
1561 RegLocation rl_src = info->args[0];
1562 rl_src = LoadValue(rl_src, kCoreReg);
1563 RegLocation rl_dest = InlineTarget(info);
1564 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001565 OpRegRegImm(kOpAnd, rl_result.reg, rl_src.reg, 0x7fffffff);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001566 StoreValue(rl_dest, rl_result);
1567 return true;
1568}
1569
Serban Constantinescu23abec92014-07-02 16:13:38 +01001570bool Mir2Lir::GenInlinedReverseBits(CallInfo* info, OpSize size) {
1571 // Currently implemented only for ARM64
1572 return false;
1573}
1574
1575bool Mir2Lir::GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) {
1576 // Currently implemented only for ARM64
1577 return false;
1578}
1579
Yixin Shoudbb17e32014-02-07 05:09:30 -08001580bool Mir2Lir::GenInlinedAbsDouble(CallInfo* info) {
1581 if (cu_->instruction_set == kMips) {
1582 // TODO - add Mips implementation
1583 return false;
1584 }
1585 RegLocation rl_src = info->args[0];
1586 rl_src = LoadValueWide(rl_src, kCoreReg);
1587 RegLocation rl_dest = InlineTargetWide(info);
1588 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001589
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001590 OpRegCopyWide(rl_result.reg, rl_src.reg);
1591 OpRegImm(kOpAnd, rl_result.reg.GetHigh(), 0x7fffffff);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001592 StoreValueWide(rl_dest, rl_result);
1593 return true;
1594}
1595
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001596bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001597 if (cu_->instruction_set == kMips) {
1598 // TODO - add Mips implementation
1599 return false;
1600 }
1601 RegLocation rl_src = info->args[0];
1602 RegLocation rl_dest = InlineTarget(info);
1603 StoreValue(rl_dest, rl_src);
1604 return true;
1605}
1606
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001607bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001608 if (cu_->instruction_set == kMips) {
1609 // TODO - add Mips implementation
1610 return false;
1611 }
1612 RegLocation rl_src = info->args[0];
1613 RegLocation rl_dest = InlineTargetWide(info);
1614 StoreValueWide(rl_dest, rl_src);
1615 return true;
1616}
1617
DaniilSokolov70c4f062014-06-24 17:34:00 -07001618bool Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) {
1619 return false;
1620}
1621
1622
Brian Carlstrom7940e442013-07-12 13:46:57 -07001623/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001624 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001625 * otherwise bails to standard library code.
1626 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001627bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001628 if (cu_->instruction_set == kMips) {
1629 // TODO - add Mips implementation
1630 return false;
1631 }
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001632 if (cu_->instruction_set == kX86_64) {
1633 // TODO - add kX86_64 implementation
1634 return false;
1635 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001636 RegLocation rl_obj = info->args[0];
1637 RegLocation rl_char = info->args[1];
1638 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1639 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1640 return false;
1641 }
1642
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001643 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001644 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001645 RegStorage reg_ptr = TargetReg(kArg0, kRef);
1646 RegStorage reg_char = TargetReg(kArg1, kNotWide);
1647 RegStorage reg_start = TargetReg(kArg2, kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001648
Brian Carlstrom7940e442013-07-12 13:46:57 -07001649 LoadValueDirectFixed(rl_obj, reg_ptr);
1650 LoadValueDirectFixed(rl_char, reg_char);
1651 if (zero_based) {
1652 LoadConstant(reg_start, 0);
1653 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001654 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001655 LoadValueDirectFixed(rl_start, reg_start);
1656 }
buzbee33ae5582014-06-12 14:56:32 -07001657 RegStorage r_tgt = cu_->target64 ?
Andreas Gampe2f244e92014-05-08 03:35:25 -07001658 LoadHelper(QUICK_ENTRYPOINT_OFFSET(8, pIndexOf)) :
1659 LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pIndexOf));
Dave Allisonf9439142014-03-27 15:10:22 -07001660 GenExplicitNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001661 LIR* high_code_point_branch =
1662 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001663 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001664 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001665 if (!rl_char.is_const) {
1666 // Add the slow path for code points beyond 0xFFFF.
1667 DCHECK(high_code_point_branch != nullptr);
1668 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1669 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001670 AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001671 } else {
1672 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1673 DCHECK(high_code_point_branch == nullptr);
1674 }
buzbeea0cd2d72014-06-01 09:33:49 -07001675 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001676 RegLocation rl_dest = InlineTarget(info);
1677 StoreValue(rl_dest, rl_return);
1678 return true;
1679}
1680
1681/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001682bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001683 if (cu_->instruction_set == kMips) {
1684 // TODO - add Mips implementation
1685 return false;
1686 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001687 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001688 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001689 RegStorage reg_this = TargetReg(kArg0, kRef);
1690 RegStorage reg_cmp = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001691
1692 RegLocation rl_this = info->args[0];
1693 RegLocation rl_cmp = info->args[1];
1694 LoadValueDirectFixed(rl_this, reg_this);
1695 LoadValueDirectFixed(rl_cmp, reg_cmp);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001696 RegStorage r_tgt;
1697 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
buzbee33ae5582014-06-12 14:56:32 -07001698 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001699 r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(8, pStringCompareTo));
1700 } else {
1701 r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo));
1702 }
1703 } else {
1704 r_tgt = RegStorage::InvalidReg();
1705 }
Dave Allisonf9439142014-03-27 15:10:22 -07001706 GenExplicitNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001707 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001708 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001709 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
Mingyao Yang3a74d152014-04-21 15:39:44 -07001710 AddIntrinsicSlowPath(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001711 // NOTE: not a safepoint
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001712 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001713 OpReg(kOpBlx, r_tgt);
1714 } else {
buzbee33ae5582014-06-12 14:56:32 -07001715 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001716 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(8, pStringCompareTo));
1717 } else {
1718 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo));
1719 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001720 }
buzbeea0cd2d72014-06-01 09:33:49 -07001721 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001722 RegLocation rl_dest = InlineTarget(info);
1723 StoreValue(rl_dest, rl_return);
1724 return true;
1725}
1726
1727bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1728 RegLocation rl_dest = InlineTarget(info);
Andreas Gampe7a949612014-07-08 11:03:59 -07001729
1730 // Early exit if the result is unused.
1731 if (rl_dest.orig_sreg < 0) {
1732 return true;
1733 }
1734
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001735 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001736
1737 switch (cu_->instruction_set) {
1738 case kArm:
1739 // Fall-through.
1740 case kThumb2:
1741 // Fall-through.
1742 case kMips:
Chao-ying Fua77ee512014-07-01 17:43:41 -07001743 Load32Disp(TargetPtrReg(kSelf), Thread::PeerOffset<4>().Int32Value(), rl_result.reg);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001744 break;
1745
1746 case kArm64:
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001747 LoadRefDisp(TargetPtrReg(kSelf), Thread::PeerOffset<8>().Int32Value(), rl_result.reg,
1748 kNotVolatile);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001749 break;
1750
1751 case kX86:
1752 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg,
1753 Thread::PeerOffset<4>());
1754 break;
1755
1756 case kX86_64:
1757 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg,
1758 Thread::PeerOffset<8>());
1759 break;
1760
1761 default:
1762 LOG(FATAL) << "Unexpected isa " << cu_->instruction_set;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001763 }
1764 StoreValue(rl_dest, rl_result);
1765 return true;
1766}
1767
1768bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
1769 bool is_long, bool is_volatile) {
1770 if (cu_->instruction_set == kMips) {
1771 // TODO - add Mips implementation
1772 return false;
1773 }
1774 // Unused - RegLocation rl_src_unsafe = info->args[0];
1775 RegLocation rl_src_obj = info->args[1]; // Object
1776 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001777 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001778 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001779
buzbeea0cd2d72014-06-01 09:33:49 -07001780 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001781 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001782 RegLocation rl_result = EvalLoc(rl_dest, LocToRegClass(rl_dest), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001783 if (is_long) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001784 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1785 || cu_->instruction_set == kArm64) {
1786 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001787 } else {
1788 RegStorage rl_temp_offset = AllocTemp();
1789 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001790 LoadBaseDisp(rl_temp_offset, 0, rl_result.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001791 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001792 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001793 } else {
Matteo Franchin255e0142014-07-04 13:50:41 +01001794 if (rl_result.ref) {
1795 LoadRefIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0);
1796 } else {
1797 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32);
1798 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001799 }
1800
1801 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001802 GenMemBarrier(kLoadAny);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001803 }
1804
1805 if (is_long) {
1806 StoreValueWide(rl_dest, rl_result);
1807 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001808 StoreValue(rl_dest, rl_result);
1809 }
1810 return true;
1811}
1812
1813bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1814 bool is_object, bool is_volatile, bool is_ordered) {
1815 if (cu_->instruction_set == kMips) {
1816 // TODO - add Mips implementation
1817 return false;
1818 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001819 // Unused - RegLocation rl_src_unsafe = info->args[0];
1820 RegLocation rl_src_obj = info->args[1]; // Object
1821 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001822 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001823 RegLocation rl_src_value = info->args[4]; // value to store
1824 if (is_volatile || is_ordered) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001825 GenMemBarrier(kAnyStore);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001826 }
buzbeea0cd2d72014-06-01 09:33:49 -07001827 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001828 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1829 RegLocation rl_value;
1830 if (is_long) {
1831 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001832 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1833 || cu_->instruction_set == kArm64) {
1834 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001835 } else {
1836 RegStorage rl_temp_offset = AllocTemp();
1837 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001838 StoreBaseDisp(rl_temp_offset, 0, rl_value.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001839 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001840 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001841 } else {
buzbeea0cd2d72014-06-01 09:33:49 -07001842 rl_value = LoadValue(rl_src_value);
Matteo Franchin255e0142014-07-04 13:50:41 +01001843 if (rl_value.ref) {
1844 StoreRefIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0);
1845 } else {
1846 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32);
1847 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001848 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001849
1850 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
buzbee091cc402014-03-31 10:14:40 -07001851 FreeTemp(rl_offset.reg);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001852
Brian Carlstrom7940e442013-07-12 13:46:57 -07001853 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001854 // Prevent reordering with a subsequent volatile load.
1855 // May also be needed to address store atomicity issues.
1856 GenMemBarrier(kAnyAny);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001857 }
1858 if (is_object) {
buzbee2700f7e2014-03-07 09:46:20 -08001859 MarkGCCard(rl_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001860 }
1861 return true;
1862}
1863
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001864void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001865 if ((info->opt_flags & MIR_INLINED) != 0) {
1866 // Already inlined but we may still need the null check.
1867 if (info->type != kStatic &&
1868 ((cu_->disable_opt & (1 << kNullCheckElimination)) != 0 ||
1869 (info->opt_flags & MIR_IGNORE_NULL_CHECK) == 0)) {
buzbeea0cd2d72014-06-01 09:33:49 -07001870 RegLocation rl_obj = LoadValue(info->args[0], kRefReg);
Mingyao Yange643a172014-04-08 11:02:52 -07001871 GenNullCheck(rl_obj.reg);
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001872 }
1873 return;
1874 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001875 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001876 if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file)
1877 ->GenIntrinsic(this, info)) {
1878 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001879 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001880 GenInvokeNoInline(info);
1881}
1882
Andreas Gampe2f244e92014-05-08 03:35:25 -07001883template <size_t pointer_size>
1884static LIR* GenInvokeNoInlineCall(Mir2Lir* mir_to_lir, InvokeType type) {
1885 ThreadOffset<pointer_size> trampoline(-1);
1886 switch (type) {
1887 case kInterface:
1888 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeInterfaceTrampolineWithAccessCheck);
1889 break;
1890 case kDirect:
1891 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeDirectTrampolineWithAccessCheck);
1892 break;
1893 case kStatic:
1894 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeStaticTrampolineWithAccessCheck);
1895 break;
1896 case kSuper:
1897 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeSuperTrampolineWithAccessCheck);
1898 break;
1899 case kVirtual:
1900 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeVirtualTrampolineWithAccessCheck);
1901 break;
1902 default:
1903 LOG(FATAL) << "Unexpected invoke type";
1904 }
1905 return mir_to_lir->OpThreadMem(kOpBlx, trampoline);
1906}
1907
Vladimir Marko3bc86152014-03-13 14:11:28 +00001908void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001909 int call_state = 0;
1910 LIR* null_ck;
1911 LIR** p_null_ck = NULL;
1912 NextCallInsn next_call_insn;
1913 FlushAllRegs(); /* Everything to home location */
1914 // Explicit register usage
1915 LockCallTemps();
1916
Vladimir Markof096aad2014-01-23 15:51:58 +00001917 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
1918 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
Mark Mendelle87f9b52014-04-30 14:13:18 -04001919 BeginInvoke(info);
Vladimir Markof096aad2014-01-23 15:51:58 +00001920 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
1921 info->type = static_cast<InvokeType>(method_info.GetSharpType());
1922 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001923 bool skip_this;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001924 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001925 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001926 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001927 } else if (info->type == kDirect) {
1928 if (fast_path) {
1929 p_null_ck = &null_ck;
1930 }
1931 next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP;
1932 skip_this = false;
1933 } else if (info->type == kStatic) {
1934 next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP;
1935 skip_this = false;
1936 } else if (info->type == kSuper) {
1937 DCHECK(!fast_path); // Fast path is a direct call.
1938 next_call_insn = NextSuperCallInsnSP;
1939 skip_this = false;
1940 } else {
1941 DCHECK_EQ(info->type, kVirtual);
1942 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1943 skip_this = fast_path;
1944 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001945 MethodReference target_method = method_info.GetTargetMethod();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001946 if (!info->is_range) {
1947 call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001948 next_call_insn, target_method, method_info.VTableIndex(),
1949 method_info.DirectCode(), method_info.DirectMethod(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001950 original_type, skip_this);
1951 } else {
1952 call_state = GenDalvikArgsRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001953 next_call_insn, target_method, method_info.VTableIndex(),
1954 method_info.DirectCode(), method_info.DirectMethod(),
1955 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001956 }
1957 // Finish up any of the call sequence not interleaved in arg loading
1958 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001959 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
1960 method_info.DirectCode(), method_info.DirectMethod(), original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001961 }
1962 LIR* call_inst;
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001963 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001964 call_inst = OpReg(kOpBlx, TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001965 } else {
Jeff Hao88474b42013-10-23 16:24:40 -07001966 if (fast_path) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001967 if (method_info.DirectCode() == static_cast<uintptr_t>(-1)) {
Mark Mendell55d0eac2014-02-06 11:02:52 -08001968 // We can have the linker fixup a call relative.
1969 call_inst =
Jeff Hao49161ce2014-03-12 11:05:25 -07001970 reinterpret_cast<X86Mir2Lir*>(this)->CallWithLinkerFixup(target_method, info->type);
Mark Mendell55d0eac2014-02-06 11:02:52 -08001971 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -07001972 call_inst = OpMem(kOpBlx, TargetReg(kArg0, kRef),
Mark Mendell55d0eac2014-02-06 11:02:52 -08001973 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
1974 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001975 } else {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001976 // TODO: Extract?
buzbee33ae5582014-06-12 14:56:32 -07001977 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001978 call_inst = GenInvokeNoInlineCall<8>(this, info->type);
1979 } else {
Andreas Gampe3ec5da22014-05-12 18:43:28 -07001980 call_inst = GenInvokeNoInlineCall<4>(this, info->type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001981 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001982 }
1983 }
Mark Mendelle87f9b52014-04-30 14:13:18 -04001984 EndInvoke(info);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001985 MarkSafepointPC(call_inst);
1986
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001987 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001988 if (info->result.location != kLocInvalid) {
1989 // We have a following MOVE_RESULT - do it now.
1990 if (info->result.wide) {
buzbeea0cd2d72014-06-01 09:33:49 -07001991 RegLocation ret_loc = GetReturnWide(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001992 StoreValueWide(info->result, ret_loc);
1993 } else {
buzbeea0cd2d72014-06-01 09:33:49 -07001994 RegLocation ret_loc = GetReturn(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001995 StoreValue(info->result, ret_loc);
1996 }
1997 }
1998}
1999
2000} // namespace art