blob: 6c0dfe80a6a4335af42b7cb1cc1286d6adaa8507 [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"
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070025#include "mirror/object_array-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070026#include "mirror/string.h"
27#include "mir_to_lir-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070028#include "x86/codegen_x86.h"
29
30namespace art {
31
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070032// Shortcuts to repeatedly used long types.
33typedef mirror::ObjectArray<mirror::Object> ObjArray;
34
Brian Carlstrom7940e442013-07-12 13:46:57 -070035/*
36 * This source files contains "gen" codegen routines that should
37 * be applicable to most targets. Only mid-level support utilities
38 * and "op" calls may be used here.
39 */
40
Mingyao Yang3a74d152014-04-21 15:39:44 -070041void Mir2Lir::AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume) {
42 class IntrinsicSlowPathPath : public Mir2Lir::LIRSlowPath {
Vladimir Marko3bc86152014-03-13 14:11:28 +000043 public:
Mingyao Yang3a74d152014-04-21 15:39:44 -070044 IntrinsicSlowPathPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr)
Vladimir Marko3bc86152014-03-13 14:11:28 +000045 : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) {
46 }
47
48 void Compile() {
49 m2l_->ResetRegPool();
50 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -070051 GenerateTargetLabel(kPseudoIntrinsicRetry);
Vladimir Marko3bc86152014-03-13 14:11:28 +000052 // NOTE: GenInvokeNoInline() handles MarkSafepointPC.
53 m2l_->GenInvokeNoInline(info_);
54 if (cont_ != nullptr) {
55 m2l_->OpUnconditionalBranch(cont_);
56 }
57 }
58
59 private:
60 CallInfo* const info_;
61 };
62
Mingyao Yang3a74d152014-04-21 15:39:44 -070063 AddSlowPath(new (arena_) IntrinsicSlowPathPath(this, info, branch, resume));
Vladimir Marko3bc86152014-03-13 14:11:28 +000064}
65
Andreas Gampe2f244e92014-05-08 03:35:25 -070066// Macro to help instantiate.
67// TODO: This might be used to only instantiate <4> on pure 32b systems.
68#define INSTANTIATE(sig_part1, ...) \
69 template sig_part1(ThreadOffset<4>, __VA_ARGS__); \
70 template sig_part1(ThreadOffset<8>, __VA_ARGS__); \
71
72
Brian Carlstrom7940e442013-07-12 13:46:57 -070073/*
74 * To save scheduling time, helper calls are broken into two parts: generation of
Dave Allisond6ed6422014-04-09 23:36:15 +000075 * the helper target address, and the actual call to the helper. Because x86
76 * has a memory call operation, part 1 is a NOP for x86. For other targets,
77 * load arguments between the two parts.
Brian Carlstrom7940e442013-07-12 13:46:57 -070078 */
Andreas Gampe2f244e92014-05-08 03:35:25 -070079// template <size_t pointer_size>
Ian Rogersdd7624d2014-03-14 17:43:00 -070080RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<4> helper_offset) {
Andreas Gampe2f244e92014-05-08 03:35:25 -070081 // All CallRuntimeHelperXXX call this first. So make a central check here.
82 DCHECK_EQ(4U, GetInstructionSetPointerSize(cu_->instruction_set));
83
84 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
85 return RegStorage::InvalidReg();
86 } else {
87 return LoadHelper(helper_offset);
88 }
89}
90
91RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<8> helper_offset) {
92 // All CallRuntimeHelperXXX call this first. So make a central check here.
93 DCHECK_EQ(8U, GetInstructionSetPointerSize(cu_->instruction_set));
94
95 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
96 return RegStorage::InvalidReg();
97 } else {
98 return LoadHelper(helper_offset);
99 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700100}
101
102/* NOTE: if r_tgt is a temp, it will be freed following use */
Andreas Gampe2f244e92014-05-08 03:35:25 -0700103template <size_t pointer_size>
104LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<pointer_size> helper_offset,
105 bool safepoint_pc, bool use_link) {
Dave Allisond6ed6422014-04-09 23:36:15 +0000106 LIR* call_inst;
Brian Carlstrom60d7a652014-03-13 18:10:08 -0700107 OpKind op = use_link ? kOpBlx : kOpBx;
Dave Allisond6ed6422014-04-09 23:36:15 +0000108 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
109 call_inst = OpThreadMem(op, helper_offset);
110 } else {
111 call_inst = OpReg(op, r_tgt);
112 FreeTemp(r_tgt);
113 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700114 if (safepoint_pc) {
115 MarkSafepointPC(call_inst);
116 }
117 return call_inst;
118}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700119template LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<4> helper_offset,
120 bool safepoint_pc, bool use_link);
121template LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<8> helper_offset,
122 bool safepoint_pc, bool use_link);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700123
Andreas Gampe2f244e92014-05-08 03:35:25 -0700124template <size_t pointer_size>
125void Mir2Lir::CallRuntimeHelper(ThreadOffset<pointer_size> helper_offset, bool safepoint_pc) {
Mingyao Yang42894562014-04-07 12:42:16 -0700126 RegStorage r_tgt = CallHelperSetup(helper_offset);
127 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700128 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Mingyao Yang42894562014-04-07 12:42:16 -0700129}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700130INSTANTIATE(void Mir2Lir::CallRuntimeHelper, bool safepoint_pc)
Mingyao Yang42894562014-04-07 12:42:16 -0700131
Andreas Gampe2f244e92014-05-08 03:35:25 -0700132template <size_t pointer_size>
133void Mir2Lir::CallRuntimeHelperImm(ThreadOffset<pointer_size> helper_offset, int arg0, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800134 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700135 LoadConstant(TargetReg(kArg0, false), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000136 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700137 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700138}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700139INSTANTIATE(void Mir2Lir::CallRuntimeHelperImm, int arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140
Andreas Gampe2f244e92014-05-08 03:35:25 -0700141template <size_t pointer_size>
142void Mir2Lir::CallRuntimeHelperReg(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700143 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800144 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700145 OpRegCopy(TargetReg(kArg0, arg0.Is64Bit()), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000146 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700147 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700148}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700149INSTANTIATE(void Mir2Lir::CallRuntimeHelperReg, RegStorage arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700150
Andreas Gampe2f244e92014-05-08 03:35:25 -0700151template <size_t pointer_size>
152void Mir2Lir::CallRuntimeHelperRegLocation(ThreadOffset<pointer_size> helper_offset,
153 RegLocation arg0, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800154 RegStorage r_tgt = CallHelperSetup(helper_offset);
155 if (arg0.wide == 0) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700156 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, arg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700157 } else {
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700158 RegStorage r_tmp;
buzbee33ae5582014-06-12 14:56:32 -0700159 if (cu_->target64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700160 r_tmp = TargetReg(kArg0, true);
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700161 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700162 r_tmp = TargetReg(arg0.fp ? kFArg0 : kArg0, arg0.fp ? kFArg1 : kArg1);
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700163 }
buzbee2700f7e2014-03-07 09:46:20 -0800164 LoadValueDirectWideFixed(arg0, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700165 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000166 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700167 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700168}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700169INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocation, RegLocation arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700170
Andreas Gampe2f244e92014-05-08 03:35:25 -0700171template <size_t pointer_size>
172void Mir2Lir::CallRuntimeHelperImmImm(ThreadOffset<pointer_size> helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700173 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800174 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700175 LoadConstant(TargetReg(kArg0, false), arg0);
176 LoadConstant(TargetReg(kArg1, false), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000177 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700178 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700179}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700180INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmImm, int arg0, int arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700181
Andreas Gampe2f244e92014-05-08 03:35:25 -0700182template <size_t pointer_size>
183void Mir2Lir::CallRuntimeHelperImmRegLocation(ThreadOffset<pointer_size> helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700184 RegLocation arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800185 RegStorage r_tgt = CallHelperSetup(helper_offset);
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 {
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700189 RegStorage r_tmp;
buzbee33ae5582014-06-12 14:56:32 -0700190 if (cu_->target64) {
Andreas Gampef9872f02014-07-01 19:00:09 -0700191 r_tmp = TargetReg(kArg1, true);
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700192 } else {
Douglas Leung2db3e262014-06-25 16:02:55 -0700193 if (cu_->instruction_set == kMips) {
194 // skip kArg1 for stack alignment.
Chao-ying Fua77ee512014-07-01 17:43:41 -0700195 r_tmp = TargetReg(kArg2, kArg3);
Douglas Leung2db3e262014-06-25 16:02:55 -0700196 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700197 r_tmp = TargetReg(kArg1, kArg2);
Douglas Leung2db3e262014-06-25 16:02:55 -0700198 }
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700199 }
buzbee2700f7e2014-03-07 09:46:20 -0800200 LoadValueDirectWideFixed(arg1, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700201 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700202 LoadConstant(TargetReg(kArg0, false), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000203 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700204 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700205}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700206INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmRegLocation, int arg0, RegLocation arg1,
207 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700208
Andreas Gampe2f244e92014-05-08 03:35:25 -0700209template <size_t pointer_size>
210void Mir2Lir::CallRuntimeHelperRegLocationImm(ThreadOffset<pointer_size> helper_offset,
211 RegLocation arg0, int arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800212 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampef9872f02014-07-01 19:00:09 -0700213 DCHECK(!arg0.wide);
214 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700215 LoadConstant(TargetReg(kArg1, false), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000216 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700217 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700218}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700219INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationImm, RegLocation arg0, int arg1,
220 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700221
Andreas Gampe2f244e92014-05-08 03:35:25 -0700222template <size_t pointer_size>
223void Mir2Lir::CallRuntimeHelperImmReg(ThreadOffset<pointer_size> helper_offset, int arg0,
224 RegStorage arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800225 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700226 OpRegCopy(TargetReg(kArg1, arg1.Is64Bit()), arg1);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700227 LoadConstant(TargetReg(kArg0, false), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000228 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700229 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700230}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700231INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmReg, int arg0, RegStorage arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700232
Andreas Gampe2f244e92014-05-08 03:35:25 -0700233template <size_t pointer_size>
234void Mir2Lir::CallRuntimeHelperRegImm(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
235 int arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800236 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700237 OpRegCopy(TargetReg(kArg0, arg0.Is64Bit()), arg0);
238 LoadConstant(TargetReg(kArg1, false), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000239 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700240 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700241}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700242INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegImm, RegStorage arg0, int arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700243
Andreas Gampe2f244e92014-05-08 03:35:25 -0700244template <size_t pointer_size>
245void Mir2Lir::CallRuntimeHelperImmMethod(ThreadOffset<pointer_size> helper_offset, int arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700246 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800247 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700248 LoadCurrMethodDirect(TargetRefReg(kArg1));
249 LoadConstant(TargetReg(kArg0, false), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000250 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700251 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700252}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700253INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethod, int arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700254
Andreas Gampe2f244e92014-05-08 03:35:25 -0700255template <size_t pointer_size>
256void Mir2Lir::CallRuntimeHelperRegMethod(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800257 bool safepoint_pc) {
258 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700259 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.Is64Bit()), arg0));
buzbeeb5860fb2014-06-21 15:31:01 -0700260 if (TargetReg(kArg0, arg0.Is64Bit()).NotExactlyEquals(arg0)) {
261 OpRegCopy(TargetReg(kArg0, arg0.Is64Bit()), arg0);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800262 }
buzbeeb5860fb2014-06-21 15:31:01 -0700263 LoadCurrMethodDirect(TargetRefReg(kArg1));
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800264 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700265 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800266}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700267INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegMethod, RegStorage arg0, bool safepoint_pc)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800268
Andreas Gampe2f244e92014-05-08 03:35:25 -0700269template <size_t pointer_size>
270void Mir2Lir::CallRuntimeHelperRegMethodRegLocation(ThreadOffset<pointer_size> helper_offset,
271 RegStorage arg0, RegLocation arg2,
272 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800273 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700274 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.Is64Bit()), arg0));
buzbeeb5860fb2014-06-21 15:31:01 -0700275 if (TargetReg(kArg0, arg0.Is64Bit()).NotExactlyEquals(arg0)) {
276 OpRegCopy(TargetReg(kArg0, arg0.Is64Bit()), arg0);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800277 }
buzbeeb5860fb2014-06-21 15:31:01 -0700278 LoadCurrMethodDirect(TargetRefReg(kArg1));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700279 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800280 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700281 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800282}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700283INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegMethodRegLocation, RegStorage arg0, RegLocation arg2,
284 bool safepoint_pc)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800285
Andreas Gampe2f244e92014-05-08 03:35:25 -0700286template <size_t pointer_size>
287void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(ThreadOffset<pointer_size> helper_offset,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700288 RegLocation arg0, RegLocation arg1,
289 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800290 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700291 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700292 RegStorage arg0_reg = TargetReg((arg0.fp) ? kFArg0 : kArg0, arg0);
293
294 RegStorage arg1_reg;
295 if (arg1.fp == arg0.fp) {
296 arg1_reg = TargetReg((arg1.fp) ? kFArg1 : kArg1, arg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700297 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700298 arg1_reg = TargetReg((arg1.fp) ? kFArg0 : kArg0, arg1);
299 }
300
301 if (arg0.wide == 0) {
302 LoadValueDirectFixed(arg0, arg0_reg);
303 } else {
304 LoadValueDirectWideFixed(arg0, arg0_reg);
305 }
306
307 if (arg1.wide == 0) {
308 LoadValueDirectFixed(arg1, arg1_reg);
309 } else {
310 LoadValueDirectWideFixed(arg1, arg1_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700311 }
312 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700313 DCHECK(!cu_->target64);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700314 if (arg0.wide == 0) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700315 LoadValueDirectFixed(arg0, arg0.fp ? TargetReg(kFArg0, false) : TargetReg(kArg0, false));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700316 if (arg1.wide == 0) {
317 if (cu_->instruction_set == kMips) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700318 LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2, false) : TargetReg(kArg1, false));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700319 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700320 LoadValueDirectFixed(arg1, TargetReg(kArg1, false));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700321 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700322 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700323 if (cu_->instruction_set == kMips) {
324 RegStorage r_tmp;
325 if (arg1.fp) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700326 r_tmp = TargetReg(kFArg2, kFArg3);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700327 } else {
328 // skip kArg1 for stack alignment.
Chao-ying Fua77ee512014-07-01 17:43:41 -0700329 r_tmp = TargetReg(kArg2, kArg3);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700330 }
331 LoadValueDirectWideFixed(arg1, r_tmp);
332 } else {
333 RegStorage r_tmp;
Chao-ying Fua77ee512014-07-01 17:43:41 -0700334 r_tmp = TargetReg(kArg1, kArg2);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700335 LoadValueDirectWideFixed(arg1, r_tmp);
336 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700337 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700338 } else {
buzbee2700f7e2014-03-07 09:46:20 -0800339 RegStorage r_tmp;
Andreas Gampe4b537a82014-06-30 22:24:53 -0700340 if (arg0.fp) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700341 r_tmp = TargetReg(kFArg0, kFArg1);
buzbee2700f7e2014-03-07 09:46:20 -0800342 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700343 r_tmp = TargetReg(kArg0, kArg1);
buzbee2700f7e2014-03-07 09:46:20 -0800344 }
Andreas Gampe4b537a82014-06-30 22:24:53 -0700345 LoadValueDirectWideFixed(arg0, r_tmp);
346 if (arg1.wide == 0) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700347 LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2, false) : TargetReg(kArg2, false));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700348 } else {
349 RegStorage r_tmp;
350 if (arg1.fp) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700351 r_tmp = TargetReg(kFArg2, kFArg3);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700352 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700353 r_tmp = TargetReg(kArg2, kArg3);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700354 }
355 LoadValueDirectWideFixed(arg1, r_tmp);
356 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700357 }
358 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000359 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700360 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700361}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700362INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationRegLocation, RegLocation arg0,
363 RegLocation arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700364
Mingyao Yang80365d92014-04-18 12:10:58 -0700365void Mir2Lir::CopyToArgumentRegs(RegStorage arg0, RegStorage arg1) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700366 if (IsSameReg(arg1, TargetReg(kArg0, arg1.Is64Bit()))) {
367 if (IsSameReg(arg0, TargetReg(kArg1, arg0.Is64Bit()))) {
Mingyao Yang80365d92014-04-18 12:10:58 -0700368 // Swap kArg0 and kArg1 with kArg2 as temp.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700369 OpRegCopy(TargetReg(kArg2, arg1.Is64Bit()), arg1);
370 OpRegCopy(TargetReg(kArg0, arg0.Is64Bit()), arg0);
371 OpRegCopy(TargetReg(kArg1, arg1.Is64Bit()), TargetReg(kArg2, arg1.Is64Bit()));
Mingyao Yang80365d92014-04-18 12:10:58 -0700372 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700373 OpRegCopy(TargetReg(kArg1, arg1.Is64Bit()), arg1);
374 OpRegCopy(TargetReg(kArg0, arg0.Is64Bit()), arg0);
Mingyao Yang80365d92014-04-18 12:10:58 -0700375 }
376 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700377 OpRegCopy(TargetReg(kArg0, arg0.Is64Bit()), arg0);
378 OpRegCopy(TargetReg(kArg1, arg1.Is64Bit()), arg1);
Mingyao Yang80365d92014-04-18 12:10:58 -0700379 }
380}
381
Andreas Gampe2f244e92014-05-08 03:35:25 -0700382template <size_t pointer_size>
383void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800384 RegStorage arg1, bool safepoint_pc) {
385 RegStorage r_tgt = CallHelperSetup(helper_offset);
Mingyao Yang80365d92014-04-18 12:10:58 -0700386 CopyToArgumentRegs(arg0, arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000387 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700388 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700389}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700390INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegReg, RegStorage arg0, RegStorage arg1,
391 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700392
Andreas Gampe2f244e92014-05-08 03:35:25 -0700393template <size_t pointer_size>
394void Mir2Lir::CallRuntimeHelperRegRegImm(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800395 RegStorage arg1, int arg2, bool safepoint_pc) {
396 RegStorage r_tgt = CallHelperSetup(helper_offset);
Mingyao Yang80365d92014-04-18 12:10:58 -0700397 CopyToArgumentRegs(arg0, arg1);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700398 LoadConstant(TargetReg(kArg2, false), arg2);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000399 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700400 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700401}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700402INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegRegImm, RegStorage arg0, RegStorage arg1, int arg2,
403 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700404
Andreas Gampe2f244e92014-05-08 03:35:25 -0700405template <size_t pointer_size>
406void Mir2Lir::CallRuntimeHelperImmMethodRegLocation(ThreadOffset<pointer_size> helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700407 int arg0, RegLocation arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800408 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700409 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Chao-ying Fua77ee512014-07-01 17:43:41 -0700410 LoadCurrMethodDirect(TargetRefReg(kArg1));
411 LoadConstant(TargetReg(kArg0, false), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000412 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700413 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700414}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700415INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethodRegLocation, int arg0, RegLocation arg2,
416 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700417
Andreas Gampe2f244e92014-05-08 03:35:25 -0700418template <size_t pointer_size>
419void Mir2Lir::CallRuntimeHelperImmMethodImm(ThreadOffset<pointer_size> helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700420 int arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800421 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700422 LoadCurrMethodDirect(TargetRefReg(kArg1));
423 LoadConstant(TargetReg(kArg2, false), arg2);
424 LoadConstant(TargetReg(kArg0, false), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000425 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700426 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700427}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700428INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethodImm, int arg0, int arg2, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700429
Andreas Gampe2f244e92014-05-08 03:35:25 -0700430template <size_t pointer_size>
431void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset<pointer_size> helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700432 int arg0, RegLocation arg1,
433 RegLocation arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800434 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700435 DCHECK_EQ(static_cast<unsigned int>(arg1.wide), 0U); // The static_cast works around an
436 // instantiation bug in GCC.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700437 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700438 if (arg2.wide == 0) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700439 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700440 } else {
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700441 RegStorage r_tmp;
buzbee33ae5582014-06-12 14:56:32 -0700442 if (cu_->target64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700443 r_tmp = TargetReg(kArg2, true);
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700444 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700445 r_tmp = TargetReg(kArg2, kArg3);
Chao-ying Fu7e399fd2014-06-10 18:11:11 -0700446 }
buzbee2700f7e2014-03-07 09:46:20 -0800447 LoadValueDirectWideFixed(arg2, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700448 }
Chao-ying Fua77ee512014-07-01 17:43:41 -0700449 LoadConstant(TargetReg(kArg0, false), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000450 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700451 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700452}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700453INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation, int arg0, RegLocation arg1,
454 RegLocation arg2, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700455
Andreas Gampe2f244e92014-05-08 03:35:25 -0700456template <size_t pointer_size>
457void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(ThreadOffset<pointer_size> helper_offset,
Ian Rogersa9a82542013-10-04 11:17:26 -0700458 RegLocation arg0, RegLocation arg1,
459 RegLocation arg2,
460 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800461 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700462 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
463 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
464 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000465 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700466 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Ian Rogersa9a82542013-10-04 11:17:26 -0700467}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700468INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation, RegLocation arg0,
469 RegLocation arg1, RegLocation arg2, bool safepoint_pc)
Ian Rogersa9a82542013-10-04 11:17:26 -0700470
Brian Carlstrom7940e442013-07-12 13:46:57 -0700471/*
472 * If there are any ins passed in registers that have not been promoted
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100473 * to a callee-save register, flush them to the frame. Perform initial
Brian Carlstrom7940e442013-07-12 13:46:57 -0700474 * assignment of promoted arguments.
475 *
476 * ArgLocs is an array of location records describing the incoming arguments
477 * with one location record per word of argument.
478 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700479void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700480 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800481 * Dummy up a RegLocation for the incoming StackReference<mirror::ArtMethod>
Brian Carlstrom7940e442013-07-12 13:46:57 -0700482 * It will attempt to keep kArg0 live (or copy it to home location
483 * if promoted).
484 */
485 RegLocation rl_src = rl_method;
486 rl_src.location = kLocPhysReg;
Andreas Gampe4b537a82014-06-30 22:24:53 -0700487 rl_src.reg = TargetRefReg(kArg0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700488 rl_src.home = false;
buzbee091cc402014-03-31 10:14:40 -0700489 MarkLive(rl_src);
buzbeef2c3e562014-05-29 12:37:25 -0700490 StoreValue(rl_method, rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700491 // If Method* has been promoted, explicitly flush
492 if (rl_method.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700493 StoreRefDisp(TargetPtrReg(kSp), 0, rl_src.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700494 }
495
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800496 if (cu_->num_ins == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700497 return;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800498 }
499
Brian Carlstrom7940e442013-07-12 13:46:57 -0700500 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
501 /*
502 * Copy incoming arguments to their proper home locations.
503 * NOTE: an older version of dx had an issue in which
504 * it would reuse static method argument registers.
505 * This could result in the same Dalvik virtual register
506 * being promoted to both core and fp regs. To account for this,
507 * we only copy to the corresponding promoted physical register
508 * if it matches the type of the SSA name for the incoming
509 * argument. It is also possible that long and double arguments
510 * end up half-promoted. In those cases, we must flush the promoted
511 * half to memory as well.
512 */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100513 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700514 for (int i = 0; i < cu_->num_ins; i++) {
515 PromotionMap* v_map = &promotion_map_[start_vreg + i];
buzbee2700f7e2014-03-07 09:46:20 -0800516 RegStorage reg = GetArgMappingToPhysicalReg(i);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800517
buzbee2700f7e2014-03-07 09:46:20 -0800518 if (reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700519 // If arriving in register
520 bool need_flush = true;
521 RegLocation* t_loc = &ArgLocs[i];
522 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
buzbee2700f7e2014-03-07 09:46:20 -0800523 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700524 need_flush = false;
525 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
buzbeeb5860fb2014-06-21 15:31:01 -0700526 OpRegCopy(RegStorage::Solo32(v_map->fp_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700527 need_flush = false;
528 } else {
529 need_flush = true;
530 }
531
buzbeed0a03b82013-09-14 08:21:05 -0700532 // For wide args, force flush if not fully promoted
Brian Carlstrom7940e442013-07-12 13:46:57 -0700533 if (t_loc->wide) {
534 PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1);
buzbeed0a03b82013-09-14 08:21:05 -0700535 // Is only half promoted?
Brian Carlstrom7940e442013-07-12 13:46:57 -0700536 need_flush |= (p_map->core_location != v_map->core_location) ||
537 (p_map->fp_location != v_map->fp_location);
buzbeed0a03b82013-09-14 08:21:05 -0700538 if ((cu_->instruction_set == kThumb2) && t_loc->fp && !need_flush) {
539 /*
540 * In Arm, a double is represented as a pair of consecutive single float
541 * registers starting at an even number. It's possible that both Dalvik vRegs
542 * representing the incoming double were independently promoted as singles - but
543 * not in a form usable as a double. If so, we need to flush - even though the
544 * incoming arg appears fully in register. At this point in the code, both
545 * halves of the double are promoted. Make sure they are in a usable form.
546 */
547 int lowreg_index = start_vreg + i + (t_loc->high_word ? -1 : 0);
buzbeeb5860fb2014-06-21 15:31:01 -0700548 int low_reg = promotion_map_[lowreg_index].fp_reg;
549 int high_reg = promotion_map_[lowreg_index + 1].fp_reg;
buzbeed0a03b82013-09-14 08:21:05 -0700550 if (((low_reg & 0x1) != 0) || (high_reg != (low_reg + 1))) {
551 need_flush = true;
552 }
553 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700554 }
555 if (need_flush) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700556 Store32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700557 }
558 } else {
559 // If arriving in frame & promoted
560 if (v_map->core_location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700561 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->core_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700562 }
563 if (v_map->fp_location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700564 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->fp_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700565 }
566 }
567 }
568}
569
570/*
571 * Bit of a hack here - in the absence of a real scheduling pass,
572 * emit the next instruction in static & direct invoke sequences.
573 */
574static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
575 int state, const MethodReference& target_method,
576 uint32_t unused,
577 uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700578 InvokeType type) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700579 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700580 if (direct_code != 0 && direct_method != 0) {
581 switch (state) {
582 case 0: // Get the current Method* [sets kArg0]
Ian Rogersff093b32014-04-30 19:04:27 -0700583 if (direct_code != static_cast<uintptr_t>(-1)) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700584 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700585 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
Ian Rogers83883d72013-10-21 21:07:24 -0700586 }
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700587 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Jeff Hao49161ce2014-03-12 11:05:25 -0700588 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700589 }
Ian Rogersff093b32014-04-30 19:04:27 -0700590 if (direct_method != static_cast<uintptr_t>(-1)) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700591 cg->LoadConstant(cg->TargetRefReg(kArg0), direct_method);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700592 } else {
Jeff Hao49161ce2014-03-12 11:05:25 -0700593 cg->LoadMethodAddress(target_method, type, kArg0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700594 }
595 break;
596 default:
597 return -1;
598 }
599 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700600 RegStorage arg0_ref = cg->TargetRefReg(kArg0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700601 switch (state) {
602 case 0: // Get the current Method* [sets kArg0]
603 // TUNING: we can save a reg copy if Method* has been promoted.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700604 cg->LoadCurrMethodDirect(arg0_ref);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700605 break;
606 case 1: // Get method->dex_cache_resolved_methods_
Andreas Gampe4b537a82014-06-30 22:24:53 -0700607 cg->LoadRefDisp(arg0_ref,
buzbee695d13a2014-04-19 13:32:20 -0700608 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700609 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000610 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700611 // Set up direct code if known.
612 if (direct_code != 0) {
Ian Rogersff093b32014-04-30 19:04:27 -0700613 if (direct_code != static_cast<uintptr_t>(-1)) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700614 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700615 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Ian Rogers83883d72013-10-21 21:07:24 -0700616 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Jeff Hao49161ce2014-03-12 11:05:25 -0700617 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700618 }
619 }
620 break;
621 case 2: // Grab target method*
622 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700623 cg->LoadRefDisp(arg0_ref,
Dmitry Petrochenko37498b62014-05-05 20:33:38 +0700624 ObjArray::OffsetOfElement(target_method.dex_method_index).Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700625 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000626 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700627 break;
628 case 3: // Grab the code from the method*
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700629 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700630 if (direct_code == 0) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700631 cg->LoadWordDisp(arg0_ref,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800632 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Chao-ying Fua77ee512014-07-01 17:43:41 -0700633 cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700634 }
635 break;
636 }
637 // Intentional fallthrough for x86
638 default:
639 return -1;
640 }
641 }
642 return state + 1;
643}
644
645/*
646 * Bit of a hack here - in the absence of a real scheduling pass,
647 * emit the next instruction in a virtual invoke sequence.
648 * We can use kLr as a temp prior to target address loading
649 * Note also that we'll load the first argument ("this") into
650 * kArg1 here rather than the standard LoadArgRegs.
651 */
652static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
653 int state, const MethodReference& target_method,
654 uint32_t method_idx, uintptr_t unused, uintptr_t unused2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700655 InvokeType unused3) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700656 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
657 /*
658 * This is the fast path in which the target virtual method is
659 * fully resolved at compile time.
660 */
661 switch (state) {
662 case 0: { // Get "this" [set kArg1]
663 RegLocation rl_arg = info->args[0];
Andreas Gampe4b537a82014-06-30 22:24:53 -0700664 cg->LoadValueDirectFixed(rl_arg, cg->TargetRefReg(kArg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700665 break;
666 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700667 case 1: // Is "this" null? [use kArg1]
Andreas Gampe4b537a82014-06-30 22:24:53 -0700668 cg->GenNullCheck(cg->TargetRefReg(kArg1), info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700669 // get this->klass_ [use kArg1, set kInvokeTgt]
Andreas Gampe4b537a82014-06-30 22:24:53 -0700670 cg->LoadRefDisp(cg->TargetRefReg(kArg1), mirror::Object::ClassOffset().Int32Value(),
Chao-ying Fua77ee512014-07-01 17:43:41 -0700671 cg->TargetPtrReg(kInvokeTgt),
Andreas Gampe3c12c512014-06-24 18:46:29 +0000672 kNotVolatile);
Dave Allisonb373e092014-02-20 16:06:36 -0800673 cg->MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700674 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700675 case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt]
Chao-ying Fua77ee512014-07-01 17:43:41 -0700676 cg->LoadRefDisp(cg->TargetPtrReg(kInvokeTgt), mirror::Class::VTableOffset().Int32Value(),
677 cg->TargetPtrReg(kInvokeTgt),
Andreas Gampe3c12c512014-06-24 18:46:29 +0000678 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700679 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700680 case 3: // Get target method [use kInvokeTgt, set kArg0]
Chao-ying Fua77ee512014-07-01 17:43:41 -0700681 cg->LoadRefDisp(cg->TargetPtrReg(kInvokeTgt),
Dmitry Petrochenko37498b62014-05-05 20:33:38 +0700682 ObjArray::OffsetOfElement(method_idx).Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700683 cg->TargetRefReg(kArg0),
Andreas Gampe3c12c512014-06-24 18:46:29 +0000684 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700685 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700686 case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt]
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700687 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700688 cg->LoadWordDisp(cg->TargetRefReg(kArg0),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800689 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Chao-ying Fua77ee512014-07-01 17:43:41 -0700690 cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700691 break;
692 }
693 // Intentional fallthrough for X86
694 default:
695 return -1;
696 }
697 return state + 1;
698}
699
700/*
Jeff Hao88474b42013-10-23 16:24:40 -0700701 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
702 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
703 * more than one interface method map to the same index. Note also that we'll load the first
704 * argument ("this") into kArg1 here rather than the standard LoadArgRegs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700705 */
706static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
707 const MethodReference& target_method,
Jeff Hao88474b42013-10-23 16:24:40 -0700708 uint32_t method_idx, uintptr_t unused,
709 uintptr_t direct_method, InvokeType unused2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700710 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700711
Jeff Hao88474b42013-10-23 16:24:40 -0700712 switch (state) {
713 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700714 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Chao-ying Fua77ee512014-07-01 17:43:41 -0700715 cg->LoadConstant(cg->TargetReg(kHiddenArg, false), target_method.dex_method_index);
Mark Mendelld3703d82014-06-09 15:10:50 -0400716 if (cu->instruction_set == kX86) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700717 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg, false), cg->TargetReg(kHiddenArg, false));
Jeff Hao88474b42013-10-23 16:24:40 -0700718 }
719 break;
720 case 1: { // Get "this" [set kArg1]
721 RegLocation rl_arg = info->args[0];
Andreas Gampe4b537a82014-06-30 22:24:53 -0700722 cg->LoadValueDirectFixed(rl_arg, cg->TargetRefReg(kArg1));
Jeff Hao88474b42013-10-23 16:24:40 -0700723 break;
724 }
725 case 2: // Is "this" null? [use kArg1]
Andreas Gampe4b537a82014-06-30 22:24:53 -0700726 cg->GenNullCheck(cg->TargetRefReg(kArg1), info->opt_flags);
Jeff Hao88474b42013-10-23 16:24:40 -0700727 // Get this->klass_ [use kArg1, set kInvokeTgt]
Andreas Gampe4b537a82014-06-30 22:24:53 -0700728 cg->LoadRefDisp(cg->TargetRefReg(kArg1), mirror::Object::ClassOffset().Int32Value(),
Chao-ying Fua77ee512014-07-01 17:43:41 -0700729 cg->TargetPtrReg(kInvokeTgt),
Andreas Gampe3c12c512014-06-24 18:46:29 +0000730 kNotVolatile);
Dave Allisonb373e092014-02-20 16:06:36 -0800731 cg->MarkPossibleNullPointerException(info->opt_flags);
Jeff Hao88474b42013-10-23 16:24:40 -0700732 break;
733 case 3: // Get this->klass_->imtable [use kInvokeTgt, set kInvokeTgt]
buzbee695d13a2014-04-19 13:32:20 -0700734 // NOTE: native pointer.
Chao-ying Fua77ee512014-07-01 17:43:41 -0700735 cg->LoadRefDisp(cg->TargetPtrReg(kInvokeTgt), mirror::Class::ImTableOffset().Int32Value(),
736 cg->TargetPtrReg(kInvokeTgt),
Andreas Gampe3c12c512014-06-24 18:46:29 +0000737 kNotVolatile);
Jeff Hao88474b42013-10-23 16:24:40 -0700738 break;
739 case 4: // Get target method [use kInvokeTgt, set kArg0]
buzbee695d13a2014-04-19 13:32:20 -0700740 // NOTE: native pointer.
Chao-ying Fua77ee512014-07-01 17:43:41 -0700741 cg->LoadRefDisp(cg->TargetPtrReg(kInvokeTgt),
Dmitry Petrochenko37498b62014-05-05 20:33:38 +0700742 ObjArray::OffsetOfElement(method_idx % ClassLinker::kImtSize).Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700743 cg->TargetRefReg(kArg0),
Andreas Gampe3c12c512014-06-24 18:46:29 +0000744 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700745 break;
Jeff Hao88474b42013-10-23 16:24:40 -0700746 case 5: // Get the compiled code address [use kArg0, set kInvokeTgt]
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700747 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700748 cg->LoadWordDisp(cg->TargetRefReg(kArg0),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800749 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
Chao-ying Fua77ee512014-07-01 17:43:41 -0700750 cg->TargetPtrReg(kInvokeTgt));
Jeff Hao88474b42013-10-23 16:24:40 -0700751 break;
752 }
753 // Intentional fallthrough for X86
Brian Carlstrom7940e442013-07-12 13:46:57 -0700754 default:
755 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700756 }
757 return state + 1;
758}
759
Andreas Gampe2f244e92014-05-08 03:35:25 -0700760template <size_t pointer_size>
761static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, ThreadOffset<pointer_size> trampoline,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700762 int state, const MethodReference& target_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700763 uint32_t method_idx) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700764 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
765 /*
766 * This handles the case in which the base method is not fully
767 * resolved at compile time, we bail to a runtime helper.
768 */
769 if (state == 0) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700770 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700771 // Load trampoline target
Chao-ying Fua77ee512014-07-01 17:43:41 -0700772 cg->LoadWordDisp(cg->TargetPtrReg(kSelf), trampoline.Int32Value(), cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700773 }
774 // Load kArg0 with method index
775 CHECK_EQ(cu->dex_file, target_method.dex_file);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700776 cg->LoadConstant(cg->TargetReg(kArg0, false), target_method.dex_method_index);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700777 return 1;
778 }
779 return -1;
780}
781
782static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
783 int state,
784 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000785 uint32_t unused, uintptr_t unused2,
786 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700787 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700788 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeStaticTrampolineWithAccessCheck);
789 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
790 } else {
791 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeStaticTrampolineWithAccessCheck);
792 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
793 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700794}
795
796static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
797 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000798 uint32_t unused, uintptr_t unused2,
799 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700800 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700801 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeDirectTrampolineWithAccessCheck);
802 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
803 } else {
804 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeDirectTrampolineWithAccessCheck);
805 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
806 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700807}
808
809static int NextSuperCallInsnSP(CompilationUnit* cu, 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 Gampe2f244e92014-05-08 03:35:25 -0700814 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeSuperTrampolineWithAccessCheck);
815 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
816 } else {
817 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeSuperTrampolineWithAccessCheck);
818 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
819 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700820}
821
822static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
823 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000824 uint32_t unused, uintptr_t unused2,
825 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700826 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700827 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeVirtualTrampolineWithAccessCheck);
828 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
829 } else {
830 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeVirtualTrampolineWithAccessCheck);
831 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
832 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700833}
834
835static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
836 CallInfo* info, int state,
837 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000838 uint32_t unused, uintptr_t unused2,
839 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700840 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700841 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeInterfaceTrampolineWithAccessCheck);
842 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
843 } else {
844 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeInterfaceTrampolineWithAccessCheck);
845 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
846 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700847}
848
849int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
850 NextCallInsn next_call_insn,
851 const MethodReference& target_method,
852 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700853 uintptr_t direct_method, InvokeType type, bool skip_this) {
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700854 int last_arg_reg = 3 - 1;
Chao-ying Fua77ee512014-07-01 17:43:41 -0700855 int arg_regs[3] = {TargetReg(kArg1, false).GetReg(), TargetReg(kArg2, false).GetReg(), TargetReg(kArg3, false).GetReg()};
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700856
857 int next_reg = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700858 int next_arg = 0;
859 if (skip_this) {
860 next_reg++;
861 next_arg++;
862 }
863 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
864 RegLocation rl_arg = info->args[next_arg++];
865 rl_arg = UpdateRawLoc(rl_arg);
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700866 if (rl_arg.wide && (next_reg <= last_arg_reg - 1)) {
867 RegStorage r_tmp(RegStorage::k64BitPair, arg_regs[next_reg], arg_regs[next_reg + 1]);
buzbee2700f7e2014-03-07 09:46:20 -0800868 LoadValueDirectWideFixed(rl_arg, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700869 next_reg++;
870 next_arg++;
871 } else {
872 if (rl_arg.wide) {
buzbee2700f7e2014-03-07 09:46:20 -0800873 rl_arg = NarrowRegLoc(rl_arg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700874 rl_arg.is_const = false;
875 }
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700876 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(arg_regs[next_reg]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700877 }
878 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
879 direct_code, direct_method, type);
880 }
881 return call_state;
882}
883
884/*
885 * Load up to 5 arguments, the first three of which will be in
886 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
887 * and as part of the load sequence, it must be replaced with
888 * the target method pointer. Note, this may also be called
889 * for "range" variants if the number of arguments is 5 or fewer.
890 */
891int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info,
892 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
893 const MethodReference& target_method,
894 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700895 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700896 RegLocation rl_arg;
897
898 /* If no arguments, just return */
899 if (info->num_arg_words == 0)
900 return call_state;
901
902 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
903 direct_code, direct_method, type);
904
905 DCHECK_LE(info->num_arg_words, 5);
906 if (info->num_arg_words > 3) {
907 int32_t next_use = 3;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700908 // Detect special case of wide arg spanning arg3/arg4
Brian Carlstrom7940e442013-07-12 13:46:57 -0700909 RegLocation rl_use0 = info->args[0];
910 RegLocation rl_use1 = info->args[1];
911 RegLocation rl_use2 = info->args[2];
buzbee2700f7e2014-03-07 09:46:20 -0800912 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) && rl_use2.wide) {
913 RegStorage reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700914 // Wide spans, we need the 2nd half of uses[2].
915 rl_arg = UpdateLocWide(rl_use2);
916 if (rl_arg.location == kLocPhysReg) {
buzbee85089dd2014-05-25 15:10:52 -0700917 if (rl_arg.reg.IsPair()) {
918 reg = rl_arg.reg.GetHigh();
919 } else {
920 RegisterInfo* info = GetRegInfo(rl_arg.reg);
921 info = info->FindMatchingView(RegisterInfo::kHighSingleStorageMask);
922 if (info == nullptr) {
923 // NOTE: For hard float convention we won't split arguments across reg/mem.
924 UNIMPLEMENTED(FATAL) << "Needs hard float api.";
925 }
926 reg = info->GetReg();
927 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700928 } else {
929 // kArg2 & rArg3 can safely be used here
Chao-ying Fua77ee512014-07-01 17:43:41 -0700930 reg = TargetReg(kArg3, false);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100931 {
932 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700933 Load32Disp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100934 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700935 call_state = next_call_insn(cu_, info, call_state, target_method,
936 vtable_idx, direct_code, direct_method, type);
937 }
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100938 {
939 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700940 Store32Disp(TargetPtrReg(kSp), (next_use + 1) * 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100941 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700942 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
943 direct_code, direct_method, type);
944 next_use++;
945 }
946 // Loop through the rest
947 while (next_use < info->num_arg_words) {
buzbee091cc402014-03-31 10:14:40 -0700948 RegStorage arg_reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700949 rl_arg = info->args[next_use];
950 rl_arg = UpdateRawLoc(rl_arg);
951 if (rl_arg.location == kLocPhysReg) {
buzbee091cc402014-03-31 10:14:40 -0700952 arg_reg = rl_arg.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700953 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700954 arg_reg = rl_arg.wide ? TargetReg(kArg2, kArg3) : TargetReg(kArg2, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700955 if (rl_arg.wide) {
buzbee091cc402014-03-31 10:14:40 -0700956 LoadValueDirectWideFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700957 } else {
buzbee091cc402014-03-31 10:14:40 -0700958 LoadValueDirectFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700959 }
960 call_state = next_call_insn(cu_, info, call_state, target_method,
961 vtable_idx, direct_code, direct_method, type);
962 }
963 int outs_offset = (next_use + 1) * 4;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100964 {
965 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
966 if (rl_arg.wide) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700967 StoreBaseDisp(TargetPtrReg(kSp), outs_offset, arg_reg, k64, kNotVolatile);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100968 next_use += 2;
969 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700970 Store32Disp(TargetPtrReg(kSp), outs_offset, arg_reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100971 next_use++;
972 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700973 }
974 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
975 direct_code, direct_method, type);
976 }
977 }
978
979 call_state = LoadArgRegs(info, call_state, next_call_insn,
980 target_method, vtable_idx, direct_code, direct_method,
981 type, skip_this);
982
983 if (pcrLabel) {
Andreas Gampe5655e842014-06-17 16:36:07 -0700984 if (cu_->compiler_driver->GetCompilerOptions().GetExplicitNullChecks()) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700985 *pcrLabel = GenExplicitNullCheck(TargetRefReg(kArg1), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700986 } else {
987 *pcrLabel = nullptr;
988 // In lieu of generating a check for kArg1 being null, we need to
989 // perform a load when doing implicit checks.
Dave Allison3d14eb62014-07-10 01:54:57 +0000990 RegStorage tmp = AllocTemp();
991 Load32Disp(TargetRefReg(kArg1), 0, tmp);
992 MarkPossibleNullPointerException(info->opt_flags);
993 FreeTemp(tmp);
Dave Allisonf9439142014-03-27 15:10:22 -0700994 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700995 }
996 return call_state;
997}
998
999/*
1000 * May have 0+ arguments (also used for jumbo). Note that
1001 * source virtual registers may be in physical registers, so may
1002 * need to be flushed to home location before copying. This
1003 * applies to arg3 and above (see below).
1004 *
1005 * Two general strategies:
1006 * If < 20 arguments
1007 * Pass args 3-18 using vldm/vstm block copy
1008 * Pass arg0, arg1 & arg2 in kArg1-kArg3
1009 * If 20+ arguments
1010 * Pass args arg19+ using memcpy block copy
1011 * Pass arg0, arg1 & arg2 in kArg1-kArg3
1012 *
1013 */
1014int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state,
1015 LIR** pcrLabel, NextCallInsn next_call_insn,
1016 const MethodReference& target_method,
1017 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001018 InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001019 // If we can treat it as non-range (Jumbo ops will use range form)
1020 if (info->num_arg_words <= 5)
1021 return GenDalvikArgsNoRange(info, call_state, pcrLabel,
1022 next_call_insn, target_method, vtable_idx,
1023 direct_code, direct_method, type, skip_this);
1024 /*
1025 * First load the non-register arguments. Both forms expect all
1026 * of the source arguments to be in their home frame location, so
1027 * scan the s_reg names and flush any that have been promoted to
1028 * frame backing storage.
1029 */
1030 // Scan the rest of the args - if in phys_reg flush to memory
1031 for (int next_arg = 0; next_arg < info->num_arg_words;) {
1032 RegLocation loc = info->args[next_arg];
1033 if (loc.wide) {
1034 loc = UpdateLocWide(loc);
1035 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001036 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001037 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001038 }
1039 next_arg += 2;
1040 } else {
1041 loc = UpdateLoc(loc);
1042 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001043 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001044 Store32Disp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001045 }
1046 next_arg++;
1047 }
1048 }
1049
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001050 // Logic below assumes that Method pointer is at offset zero from SP.
1051 DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0);
1052
1053 // The first 3 arguments are passed via registers.
1054 // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either
1055 // get size of uintptr_t or size of object reference according to model being used.
1056 int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001057 int start_offset = SRegOffset(info->args[3].s_reg_low);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001058 int regs_left_to_pass_via_stack = info->num_arg_words - 3;
1059 DCHECK_GT(regs_left_to_pass_via_stack, 0);
1060
1061 if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) {
1062 // Use vldm/vstm pair using kArg3 as a temp
1063 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1064 direct_code, direct_method, type);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001065 OpRegRegImm(kOpAdd, TargetRefReg(kArg3), TargetPtrReg(kSp), start_offset);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001066 LIR* ld = nullptr;
1067 {
1068 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001069 ld = OpVldm(TargetRefReg(kArg3), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001070 }
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001071 // TUNING: loosen barrier
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001072 ld->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001073 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1074 direct_code, direct_method, type);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001075 OpRegRegImm(kOpAdd, TargetRefReg(kArg3), TargetPtrReg(kSp), 4 /* Method* */ + (3 * 4));
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001076 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1077 direct_code, direct_method, type);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001078 LIR* st = nullptr;
1079 {
1080 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001081 st = OpVstm(TargetRefReg(kArg3), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001082 }
1083 st->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001084 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1085 direct_code, direct_method, type);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001086 } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001087 int current_src_offset = start_offset;
1088 int current_dest_offset = outs_offset;
1089
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001090 // Only davik regs are accessed in this loop; no next_call_insn() calls.
1091 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001092 while (regs_left_to_pass_via_stack > 0) {
1093 // This is based on the knowledge that the stack itself is 16-byte aligned.
1094 bool src_is_16b_aligned = (current_src_offset & 0xF) == 0;
1095 bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0;
1096 size_t bytes_to_move;
1097
1098 /*
1099 * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a
1100 * a 128-bit move because we won't get the chance to try to aligned. If there are more than
1101 * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned.
1102 * We do this because we could potentially do a smaller move to align.
1103 */
1104 if (regs_left_to_pass_via_stack == 4 ||
1105 (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) {
1106 // Moving 128-bits via xmm register.
1107 bytes_to_move = sizeof(uint32_t) * 4;
1108
1109 // Allocate a free xmm temp. Since we are working through the calling sequence,
Mark Mendelle87f9b52014-04-30 14:13:18 -04001110 // we expect to have an xmm temporary available. AllocTempDouble will abort if
1111 // there are no free registers.
buzbee2700f7e2014-03-07 09:46:20 -08001112 RegStorage temp = AllocTempDouble();
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001113
1114 LIR* ld1 = nullptr;
1115 LIR* ld2 = nullptr;
1116 LIR* st1 = nullptr;
1117 LIR* st2 = nullptr;
1118
1119 /*
1120 * The logic is similar for both loads and stores. If we have 16-byte alignment,
1121 * do an aligned move. If we have 8-byte alignment, then do the move in two
1122 * parts. This approach prevents possible cache line splits. Finally, fall back
1123 * to doing an unaligned move. In most cases we likely won't split the cache
1124 * line but we cannot prove it and thus take a conservative approach.
1125 */
1126 bool src_is_8b_aligned = (current_src_offset & 0x7) == 0;
1127 bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0;
1128
1129 if (src_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001130 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001131 } else if (src_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001132 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovLo128FP);
1133 ld2 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001134 kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001135 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001136 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001137 }
1138
1139 if (dest_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001140 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001141 } else if (dest_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001142 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovLo128FP);
1143 st2 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001144 temp, kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001145 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001146 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001147 }
1148
1149 // TODO If we could keep track of aliasing information for memory accesses that are wider
1150 // than 64-bit, we wouldn't need to set up a barrier.
1151 if (ld1 != nullptr) {
1152 if (ld2 != nullptr) {
1153 // For 64-bit load we can actually set up the aliasing information.
1154 AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true);
1155 AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true, true);
1156 } else {
1157 // Set barrier for 128-bit load.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001158 ld1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001159 }
1160 }
1161 if (st1 != nullptr) {
1162 if (st2 != nullptr) {
1163 // For 64-bit store we can actually set up the aliasing information.
1164 AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true);
1165 AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false, true);
1166 } else {
1167 // Set barrier for 128-bit store.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001168 st1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001169 }
1170 }
1171
1172 // Free the temporary used for the data movement.
buzbee091cc402014-03-31 10:14:40 -07001173 FreeTemp(temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001174 } else {
1175 // Moving 32-bits via general purpose register.
1176 bytes_to_move = sizeof(uint32_t);
1177
1178 // Instead of allocating a new temp, simply reuse one of the registers being used
1179 // for argument passing.
Chao-ying Fua77ee512014-07-01 17:43:41 -07001180 RegStorage temp = TargetReg(kArg3, false);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001181
1182 // Now load the argument VR and store to the outs.
Chao-ying Fua77ee512014-07-01 17:43:41 -07001183 Load32Disp(TargetPtrReg(kSp), current_src_offset, temp);
1184 Store32Disp(TargetPtrReg(kSp), current_dest_offset, temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001185 }
1186
1187 current_src_offset += bytes_to_move;
1188 current_dest_offset += bytes_to_move;
1189 regs_left_to_pass_via_stack -= (bytes_to_move >> 2);
1190 }
1191 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001192 // Generate memcpy
Chao-ying Fua77ee512014-07-01 17:43:41 -07001193 OpRegRegImm(kOpAdd, TargetRefReg(kArg0), TargetPtrReg(kSp), outs_offset);
1194 OpRegRegImm(kOpAdd, TargetRefReg(kArg1), TargetPtrReg(kSp), start_offset);
buzbee33ae5582014-06-12 14:56:32 -07001195 if (cu_->target64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001196 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(8, pMemcpy), TargetRefReg(kArg0),
1197 TargetRefReg(kArg1), (info->num_arg_words - 3) * 4, false);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001198 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001199 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(4, pMemcpy), TargetRefReg(kArg0),
1200 TargetRefReg(kArg1), (info->num_arg_words - 3) * 4, false);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001201 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001202 }
1203
1204 call_state = LoadArgRegs(info, call_state, next_call_insn,
1205 target_method, vtable_idx, direct_code, direct_method,
1206 type, skip_this);
1207
1208 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1209 direct_code, direct_method, type);
1210 if (pcrLabel) {
Andreas Gampe5655e842014-06-17 16:36:07 -07001211 if (cu_->compiler_driver->GetCompilerOptions().GetExplicitNullChecks()) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001212 *pcrLabel = GenExplicitNullCheck(TargetRefReg(kArg1), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -07001213 } else {
1214 *pcrLabel = nullptr;
1215 // In lieu of generating a check for kArg1 being null, we need to
1216 // perform a load when doing implicit checks.
Dave Allison3d14eb62014-07-10 01:54:57 +00001217 RegStorage tmp = AllocTemp();
1218 Load32Disp(TargetRefReg(kArg1), 0, tmp);
1219 MarkPossibleNullPointerException(info->opt_flags);
1220 FreeTemp(tmp);
Dave Allisonf9439142014-03-27 15:10:22 -07001221 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001222 }
1223 return call_state;
1224}
1225
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001226RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001227 RegLocation res;
1228 if (info->result.location == kLocInvalid) {
buzbeea0cd2d72014-06-01 09:33:49 -07001229 res = GetReturn(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001230 } else {
1231 res = info->result;
1232 }
1233 return res;
1234}
1235
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001236RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001237 RegLocation res;
1238 if (info->result.location == kLocInvalid) {
buzbeea0cd2d72014-06-01 09:33:49 -07001239 res = GetReturnWide(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001240 } else {
1241 res = info->result;
1242 }
1243 return res;
1244}
1245
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001246bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001247 if (cu_->instruction_set == kMips) {
1248 // TODO - add Mips implementation
1249 return false;
1250 }
1251 // Location of reference to data array
1252 int value_offset = mirror::String::ValueOffset().Int32Value();
1253 // Location of count
1254 int count_offset = mirror::String::CountOffset().Int32Value();
1255 // Starting offset within data array
1256 int offset_offset = mirror::String::OffsetOffset().Int32Value();
1257 // Start of char data with array_
1258 int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value();
1259
1260 RegLocation rl_obj = info->args[0];
1261 RegLocation rl_idx = info->args[1];
buzbeea0cd2d72014-06-01 09:33:49 -07001262 rl_obj = LoadValue(rl_obj, kRefReg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001263 // X86 wants to avoid putting a constant index into a register.
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001264 if (!((cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64)&& rl_idx.is_const)) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001265 rl_idx = LoadValue(rl_idx, kCoreReg);
1266 }
buzbee2700f7e2014-03-07 09:46:20 -08001267 RegStorage reg_max;
1268 GenNullCheck(rl_obj.reg, info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001269 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001270 LIR* range_check_branch = nullptr;
buzbee2700f7e2014-03-07 09:46:20 -08001271 RegStorage reg_off;
1272 RegStorage reg_ptr;
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001273 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001274 reg_off = AllocTemp();
buzbeea0cd2d72014-06-01 09:33:49 -07001275 reg_ptr = AllocTempRef();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001276 if (range_check) {
1277 reg_max = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -07001278 Load32Disp(rl_obj.reg, count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -08001279 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001280 }
buzbee695d13a2014-04-19 13:32:20 -07001281 Load32Disp(rl_obj.reg, offset_offset, reg_off);
Dave Allisonb373e092014-02-20 16:06:36 -08001282 MarkPossibleNullPointerException(info->opt_flags);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001283 LoadRefDisp(rl_obj.reg, value_offset, reg_ptr, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001284 if (range_check) {
Mingyao Yang3a74d152014-04-21 15:39:44 -07001285 // Set up a slow path to allow retry in case of bounds violation */
buzbee2700f7e2014-03-07 09:46:20 -08001286 OpRegReg(kOpCmp, rl_idx.reg, reg_max);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001287 FreeTemp(reg_max);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001288 range_check_branch = OpCondBranch(kCondUge, nullptr);
Brian Carlstrom6f485c62013-07-18 15:35:35 -07001289 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001290 OpRegImm(kOpAdd, reg_ptr, data_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001291 } else {
1292 if (range_check) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001293 // On x86, we can compare to memory directly
Brian Carlstrom7940e442013-07-12 13:46:57 -07001294 // Set up a launch pad to allow retry in case of bounds violation */
Mark Mendell2b724cb2014-02-06 05:24:20 -08001295 if (rl_idx.is_const) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001296 range_check_branch = OpCmpMemImmBranch(
buzbee2700f7e2014-03-07 09:46:20 -08001297 kCondUlt, RegStorage::InvalidReg(), rl_obj.reg, count_offset,
Dave Allison3d14eb62014-07-10 01:54:57 +00001298 mir_graph_->ConstantValue(rl_idx.orig_sreg), nullptr);
1299 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001300 OpRegMem(kOpCmp, rl_idx.reg, rl_obj.reg, count_offset);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001301 range_check_branch = OpCondBranch(kCondUge, nullptr);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001302 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001303 }
1304 reg_off = AllocTemp();
buzbeea0cd2d72014-06-01 09:33:49 -07001305 reg_ptr = AllocTempRef();
buzbee695d13a2014-04-19 13:32:20 -07001306 Load32Disp(rl_obj.reg, offset_offset, reg_off);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001307 LoadRefDisp(rl_obj.reg, value_offset, reg_ptr, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001308 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001309 if (rl_idx.is_const) {
1310 OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg));
1311 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001312 OpRegReg(kOpAdd, reg_off, rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001313 }
buzbee2700f7e2014-03-07 09:46:20 -08001314 FreeTemp(rl_obj.reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001315 if (rl_idx.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -08001316 FreeTemp(rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001317 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001318 RegLocation rl_dest = InlineTarget(info);
1319 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001320 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
buzbee2700f7e2014-03-07 09:46:20 -08001321 LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg, 1, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001322 } else {
Vladimir Marko3bf7c602014-05-07 14:55:43 +01001323 LoadBaseIndexedDisp(reg_ptr, reg_off, 1, data_offset, rl_result.reg, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001324 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001325 FreeTemp(reg_off);
1326 FreeTemp(reg_ptr);
1327 StoreValue(rl_dest, rl_result);
1328 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001329 DCHECK(range_check_branch != nullptr);
1330 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001331 AddIntrinsicSlowPath(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001332 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001333 return true;
1334}
1335
1336// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001337bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001338 if (cu_->instruction_set == kMips) {
1339 // TODO - add Mips implementation
1340 return false;
1341 }
1342 // dst = src.length();
1343 RegLocation rl_obj = info->args[0];
buzbeea0cd2d72014-06-01 09:33:49 -07001344 rl_obj = LoadValue(rl_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001345 RegLocation rl_dest = InlineTarget(info);
1346 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001347 GenNullCheck(rl_obj.reg, info->opt_flags);
buzbee695d13a2014-04-19 13:32:20 -07001348 Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg);
Dave Allisonb373e092014-02-20 16:06:36 -08001349 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001350 if (is_empty) {
1351 // dst = (dst == 0);
1352 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001353 RegStorage t_reg = AllocTemp();
1354 OpRegReg(kOpNeg, t_reg, rl_result.reg);
1355 OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001356 } else if (cu_->instruction_set == kArm64) {
1357 OpRegImm(kOpSub, rl_result.reg, 1);
1358 OpRegRegImm(kOpLsr, rl_result.reg, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001359 } else {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001360 DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64);
buzbee2700f7e2014-03-07 09:46:20 -08001361 OpRegImm(kOpSub, rl_result.reg, 1);
1362 OpRegImm(kOpLsr, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001363 }
1364 }
1365 StoreValue(rl_dest, rl_result);
1366 return true;
1367}
1368
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001369bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001370 if (cu_->instruction_set == kMips || cu_->instruction_set == kArm64) {
1371 // TODO - add Mips implementation; Enable Arm64.
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001372 return false;
1373 }
1374 RegLocation rl_src_i = info->args[0];
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001375 RegLocation rl_i = (size == k64) ? LoadValueWide(rl_src_i, kCoreReg) : LoadValue(rl_src_i, kCoreReg);
buzbee695d13a2014-04-19 13:32:20 -07001376 RegLocation rl_dest = (size == k64) ? InlineTargetWide(info) : InlineTarget(info); // result reg
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001377 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee695d13a2014-04-19 13:32:20 -07001378 if (size == k64) {
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001379 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Serban Constantinescu169489b2014-06-11 16:43:35 +01001380 OpRegReg(kOpRev, rl_result.reg, rl_i.reg);
1381 StoreValueWide(rl_dest, rl_result);
1382 return true;
1383 }
buzbee2700f7e2014-03-07 09:46:20 -08001384 RegStorage r_i_low = rl_i.reg.GetLow();
1385 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001386 // 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 +00001387 r_i_low = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -08001388 OpRegCopy(r_i_low, rl_i.reg);
Vladimir Markof246af22013-11-27 12:30:15 +00001389 }
buzbee2700f7e2014-03-07 09:46:20 -08001390 OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh());
1391 OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low);
1392 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001393 FreeTemp(r_i_low);
1394 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001395 StoreValueWide(rl_dest, rl_result);
1396 } else {
buzbee695d13a2014-04-19 13:32:20 -07001397 DCHECK(size == k32 || size == kSignedHalf);
1398 OpKind op = (size == k32) ? kOpRev : kOpRevsh;
buzbee2700f7e2014-03-07 09:46:20 -08001399 OpRegReg(op, rl_result.reg, rl_i.reg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001400 StoreValue(rl_dest, rl_result);
1401 }
1402 return true;
1403}
1404
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001405bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001406 if (cu_->instruction_set == kMips) {
1407 // TODO - add Mips implementation
1408 return false;
1409 }
1410 RegLocation rl_src = info->args[0];
1411 rl_src = LoadValue(rl_src, kCoreReg);
1412 RegLocation rl_dest = InlineTarget(info);
1413 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001414 RegStorage sign_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001415 // abs(x) = y<=x>>31, (x+y)^y.
buzbee2700f7e2014-03-07 09:46:20 -08001416 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31);
1417 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1418 OpRegReg(kOpXor, rl_result.reg, sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001419 StoreValue(rl_dest, rl_result);
1420 return true;
1421}
1422
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001423bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001424 if (cu_->instruction_set == kMips) {
1425 // TODO - add Mips implementation
1426 return false;
1427 }
Vladimir Markob9823312014-03-20 17:38:43 +00001428 RegLocation rl_src = info->args[0];
1429 rl_src = LoadValueWide(rl_src, kCoreReg);
1430 RegLocation rl_dest = InlineTargetWide(info);
1431 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1432
1433 // If on x86 or if we would clobber a register needed later, just copy the source first.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001434 if (cu_->instruction_set != kX86_64 &&
1435 (cu_->instruction_set == kX86 ||
1436 rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001437 OpRegCopyWide(rl_result.reg, rl_src.reg);
1438 if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() &&
1439 rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() &&
1440 rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() &&
Vladimir Markob9823312014-03-20 17:38:43 +00001441 rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) {
1442 // Reuse source registers to avoid running out of temps.
buzbee2700f7e2014-03-07 09:46:20 -08001443 FreeTemp(rl_src.reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001444 }
1445 rl_src = rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001446 }
Vladimir Markob9823312014-03-20 17:38:43 +00001447
1448 // abs(x) = y<=x>>31, (x+y)^y.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001449 RegStorage sign_reg;
1450 if (cu_->instruction_set == kX86_64) {
1451 sign_reg = AllocTempWide();
1452 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 63);
1453 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1454 OpRegReg(kOpXor, rl_result.reg, sign_reg);
1455 } else {
1456 sign_reg = AllocTemp();
1457 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31);
1458 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg);
1459 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg);
1460 OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg);
1461 OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg);
1462 }
buzbee082833c2014-05-17 23:16:26 -07001463 FreeTemp(sign_reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001464 StoreValueWide(rl_dest, rl_result);
1465 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001466}
1467
Yixin Shoudbb17e32014-02-07 05:09:30 -08001468bool Mir2Lir::GenInlinedAbsFloat(CallInfo* info) {
1469 if (cu_->instruction_set == kMips) {
1470 // TODO - add Mips implementation
1471 return false;
1472 }
1473 RegLocation rl_src = info->args[0];
1474 rl_src = LoadValue(rl_src, kCoreReg);
1475 RegLocation rl_dest = InlineTarget(info);
1476 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001477 OpRegRegImm(kOpAnd, rl_result.reg, rl_src.reg, 0x7fffffff);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001478 StoreValue(rl_dest, rl_result);
1479 return true;
1480}
1481
Serban Constantinescu23abec92014-07-02 16:13:38 +01001482bool Mir2Lir::GenInlinedReverseBits(CallInfo* info, OpSize size) {
1483 // Currently implemented only for ARM64
1484 return false;
1485}
1486
1487bool Mir2Lir::GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) {
1488 // Currently implemented only for ARM64
1489 return false;
1490}
1491
Yixin Shoudbb17e32014-02-07 05:09:30 -08001492bool Mir2Lir::GenInlinedAbsDouble(CallInfo* info) {
1493 if (cu_->instruction_set == kMips) {
1494 // TODO - add Mips implementation
1495 return false;
1496 }
1497 RegLocation rl_src = info->args[0];
1498 rl_src = LoadValueWide(rl_src, kCoreReg);
1499 RegLocation rl_dest = InlineTargetWide(info);
1500 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001501
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001502 OpRegCopyWide(rl_result.reg, rl_src.reg);
1503 OpRegImm(kOpAnd, rl_result.reg.GetHigh(), 0x7fffffff);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001504 StoreValueWide(rl_dest, rl_result);
1505 return true;
1506}
1507
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001508bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001509 if (cu_->instruction_set == kMips) {
1510 // TODO - add Mips implementation
1511 return false;
1512 }
1513 RegLocation rl_src = info->args[0];
1514 RegLocation rl_dest = InlineTarget(info);
1515 StoreValue(rl_dest, rl_src);
1516 return true;
1517}
1518
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001519bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001520 if (cu_->instruction_set == kMips) {
1521 // TODO - add Mips implementation
1522 return false;
1523 }
1524 RegLocation rl_src = info->args[0];
1525 RegLocation rl_dest = InlineTargetWide(info);
1526 StoreValueWide(rl_dest, rl_src);
1527 return true;
1528}
1529
DaniilSokolov70c4f062014-06-24 17:34:00 -07001530bool Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) {
1531 return false;
1532}
1533
1534
Brian Carlstrom7940e442013-07-12 13:46:57 -07001535/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001536 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001537 * otherwise bails to standard library code.
1538 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001539bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001540 if (cu_->instruction_set == kMips) {
1541 // TODO - add Mips implementation
1542 return false;
1543 }
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001544 if (cu_->instruction_set == kX86_64) {
1545 // TODO - add kX86_64 implementation
1546 return false;
1547 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001548 RegLocation rl_obj = info->args[0];
1549 RegLocation rl_char = info->args[1];
1550 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1551 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1552 return false;
1553 }
1554
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001555 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001556 LockCallTemps(); // Using fixed registers
Chao-ying Fua77ee512014-07-01 17:43:41 -07001557 RegStorage reg_ptr = TargetRefReg(kArg0);
1558 RegStorage reg_char = TargetReg(kArg1, false);
1559 RegStorage reg_start = TargetReg(kArg2, false);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001560
Brian Carlstrom7940e442013-07-12 13:46:57 -07001561 LoadValueDirectFixed(rl_obj, reg_ptr);
1562 LoadValueDirectFixed(rl_char, reg_char);
1563 if (zero_based) {
1564 LoadConstant(reg_start, 0);
1565 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001566 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001567 LoadValueDirectFixed(rl_start, reg_start);
1568 }
buzbee33ae5582014-06-12 14:56:32 -07001569 RegStorage r_tgt = cu_->target64 ?
Andreas Gampe2f244e92014-05-08 03:35:25 -07001570 LoadHelper(QUICK_ENTRYPOINT_OFFSET(8, pIndexOf)) :
1571 LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pIndexOf));
Dave Allisonf9439142014-03-27 15:10:22 -07001572 GenExplicitNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001573 LIR* high_code_point_branch =
1574 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001575 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001576 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001577 if (!rl_char.is_const) {
1578 // Add the slow path for code points beyond 0xFFFF.
1579 DCHECK(high_code_point_branch != nullptr);
1580 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1581 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001582 AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001583 } else {
1584 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1585 DCHECK(high_code_point_branch == nullptr);
1586 }
buzbeea0cd2d72014-06-01 09:33:49 -07001587 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001588 RegLocation rl_dest = InlineTarget(info);
1589 StoreValue(rl_dest, rl_return);
1590 return true;
1591}
1592
1593/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001594bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001595 if (cu_->instruction_set == kMips) {
1596 // TODO - add Mips implementation
1597 return false;
1598 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001599 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001600 LockCallTemps(); // Using fixed registers
Chao-ying Fua77ee512014-07-01 17:43:41 -07001601 RegStorage reg_this = TargetRefReg(kArg0);
1602 RegStorage reg_cmp = TargetRefReg(kArg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001603
1604 RegLocation rl_this = info->args[0];
1605 RegLocation rl_cmp = info->args[1];
1606 LoadValueDirectFixed(rl_this, reg_this);
1607 LoadValueDirectFixed(rl_cmp, reg_cmp);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001608 RegStorage r_tgt;
1609 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
buzbee33ae5582014-06-12 14:56:32 -07001610 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001611 r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(8, pStringCompareTo));
1612 } else {
1613 r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo));
1614 }
1615 } else {
1616 r_tgt = RegStorage::InvalidReg();
1617 }
Dave Allisonf9439142014-03-27 15:10:22 -07001618 GenExplicitNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001619 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001620 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001621 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
Mingyao Yang3a74d152014-04-21 15:39:44 -07001622 AddIntrinsicSlowPath(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001623 // NOTE: not a safepoint
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001624 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001625 OpReg(kOpBlx, r_tgt);
1626 } else {
buzbee33ae5582014-06-12 14:56:32 -07001627 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001628 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(8, pStringCompareTo));
1629 } else {
1630 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo));
1631 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001632 }
buzbeea0cd2d72014-06-01 09:33:49 -07001633 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001634 RegLocation rl_dest = InlineTarget(info);
1635 StoreValue(rl_dest, rl_return);
1636 return true;
1637}
1638
1639bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1640 RegLocation rl_dest = InlineTarget(info);
Andreas Gampe7a949612014-07-08 11:03:59 -07001641
1642 // Early exit if the result is unused.
1643 if (rl_dest.orig_sreg < 0) {
1644 return true;
1645 }
1646
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001647 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001648
1649 switch (cu_->instruction_set) {
1650 case kArm:
1651 // Fall-through.
1652 case kThumb2:
1653 // Fall-through.
1654 case kMips:
Chao-ying Fua77ee512014-07-01 17:43:41 -07001655 Load32Disp(TargetPtrReg(kSelf), Thread::PeerOffset<4>().Int32Value(), rl_result.reg);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001656 break;
1657
1658 case kArm64:
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001659 LoadRefDisp(TargetPtrReg(kSelf), Thread::PeerOffset<8>().Int32Value(), rl_result.reg,
1660 kNotVolatile);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001661 break;
1662
1663 case kX86:
1664 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg,
1665 Thread::PeerOffset<4>());
1666 break;
1667
1668 case kX86_64:
1669 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg,
1670 Thread::PeerOffset<8>());
1671 break;
1672
1673 default:
1674 LOG(FATAL) << "Unexpected isa " << cu_->instruction_set;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001675 }
1676 StoreValue(rl_dest, rl_result);
1677 return true;
1678}
1679
1680bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
1681 bool is_long, bool is_volatile) {
1682 if (cu_->instruction_set == kMips) {
1683 // TODO - add Mips implementation
1684 return false;
1685 }
1686 // Unused - RegLocation rl_src_unsafe = info->args[0];
1687 RegLocation rl_src_obj = info->args[1]; // Object
1688 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001689 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001690 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001691
buzbeea0cd2d72014-06-01 09:33:49 -07001692 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001693 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001694 RegLocation rl_result = EvalLoc(rl_dest, LocToRegClass(rl_dest), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001695 if (is_long) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001696 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1697 || cu_->instruction_set == kArm64) {
1698 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001699 } else {
1700 RegStorage rl_temp_offset = AllocTemp();
1701 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001702 LoadBaseDisp(rl_temp_offset, 0, rl_result.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001703 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001704 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001705 } else {
Matteo Franchin255e0142014-07-04 13:50:41 +01001706 if (rl_result.ref) {
1707 LoadRefIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0);
1708 } else {
1709 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32);
1710 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001711 }
1712
1713 if (is_volatile) {
1714 // Without context sensitive analysis, we must issue the most conservative barriers.
1715 // In this case, either a load or store may follow so we issue both barriers.
1716 GenMemBarrier(kLoadLoad);
1717 GenMemBarrier(kLoadStore);
1718 }
1719
1720 if (is_long) {
1721 StoreValueWide(rl_dest, rl_result);
1722 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001723 StoreValue(rl_dest, rl_result);
1724 }
1725 return true;
1726}
1727
1728bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1729 bool is_object, bool is_volatile, bool is_ordered) {
1730 if (cu_->instruction_set == kMips) {
1731 // TODO - add Mips implementation
1732 return false;
1733 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001734 // Unused - RegLocation rl_src_unsafe = info->args[0];
1735 RegLocation rl_src_obj = info->args[1]; // Object
1736 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001737 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001738 RegLocation rl_src_value = info->args[4]; // value to store
1739 if (is_volatile || is_ordered) {
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001740 // There might have been a store before this volatile one so insert StoreStore barrier.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001741 GenMemBarrier(kStoreStore);
1742 }
buzbeea0cd2d72014-06-01 09:33:49 -07001743 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001744 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1745 RegLocation rl_value;
1746 if (is_long) {
1747 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001748 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1749 || cu_->instruction_set == kArm64) {
1750 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001751 } else {
1752 RegStorage rl_temp_offset = AllocTemp();
1753 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001754 StoreBaseDisp(rl_temp_offset, 0, rl_value.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001755 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001756 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001757 } else {
buzbeea0cd2d72014-06-01 09:33:49 -07001758 rl_value = LoadValue(rl_src_value);
Matteo Franchin255e0142014-07-04 13:50:41 +01001759 if (rl_value.ref) {
1760 StoreRefIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0);
1761 } else {
1762 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32);
1763 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001764 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001765
1766 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
buzbee091cc402014-03-31 10:14:40 -07001767 FreeTemp(rl_offset.reg);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001768
Brian Carlstrom7940e442013-07-12 13:46:57 -07001769 if (is_volatile) {
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001770 // A load might follow the volatile store so insert a StoreLoad barrier.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001771 GenMemBarrier(kStoreLoad);
1772 }
1773 if (is_object) {
buzbee2700f7e2014-03-07 09:46:20 -08001774 MarkGCCard(rl_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001775 }
1776 return true;
1777}
1778
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001779void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001780 if ((info->opt_flags & MIR_INLINED) != 0) {
1781 // Already inlined but we may still need the null check.
1782 if (info->type != kStatic &&
1783 ((cu_->disable_opt & (1 << kNullCheckElimination)) != 0 ||
1784 (info->opt_flags & MIR_IGNORE_NULL_CHECK) == 0)) {
buzbeea0cd2d72014-06-01 09:33:49 -07001785 RegLocation rl_obj = LoadValue(info->args[0], kRefReg);
Mingyao Yange643a172014-04-08 11:02:52 -07001786 GenNullCheck(rl_obj.reg);
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001787 }
1788 return;
1789 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001790 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001791 if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file)
1792 ->GenIntrinsic(this, info)) {
1793 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001794 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001795 GenInvokeNoInline(info);
1796}
1797
Andreas Gampe2f244e92014-05-08 03:35:25 -07001798template <size_t pointer_size>
1799static LIR* GenInvokeNoInlineCall(Mir2Lir* mir_to_lir, InvokeType type) {
1800 ThreadOffset<pointer_size> trampoline(-1);
1801 switch (type) {
1802 case kInterface:
1803 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeInterfaceTrampolineWithAccessCheck);
1804 break;
1805 case kDirect:
1806 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeDirectTrampolineWithAccessCheck);
1807 break;
1808 case kStatic:
1809 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeStaticTrampolineWithAccessCheck);
1810 break;
1811 case kSuper:
1812 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeSuperTrampolineWithAccessCheck);
1813 break;
1814 case kVirtual:
1815 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeVirtualTrampolineWithAccessCheck);
1816 break;
1817 default:
1818 LOG(FATAL) << "Unexpected invoke type";
1819 }
1820 return mir_to_lir->OpThreadMem(kOpBlx, trampoline);
1821}
1822
Vladimir Marko3bc86152014-03-13 14:11:28 +00001823void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001824 int call_state = 0;
1825 LIR* null_ck;
1826 LIR** p_null_ck = NULL;
1827 NextCallInsn next_call_insn;
1828 FlushAllRegs(); /* Everything to home location */
1829 // Explicit register usage
1830 LockCallTemps();
1831
Vladimir Markof096aad2014-01-23 15:51:58 +00001832 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
1833 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
Mark Mendelle87f9b52014-04-30 14:13:18 -04001834 BeginInvoke(info);
Vladimir Markof096aad2014-01-23 15:51:58 +00001835 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
1836 info->type = static_cast<InvokeType>(method_info.GetSharpType());
1837 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001838 bool skip_this;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001839 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001840 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001841 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001842 } else if (info->type == kDirect) {
1843 if (fast_path) {
1844 p_null_ck = &null_ck;
1845 }
1846 next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP;
1847 skip_this = false;
1848 } else if (info->type == kStatic) {
1849 next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP;
1850 skip_this = false;
1851 } else if (info->type == kSuper) {
1852 DCHECK(!fast_path); // Fast path is a direct call.
1853 next_call_insn = NextSuperCallInsnSP;
1854 skip_this = false;
1855 } else {
1856 DCHECK_EQ(info->type, kVirtual);
1857 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1858 skip_this = fast_path;
1859 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001860 MethodReference target_method = method_info.GetTargetMethod();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001861 if (!info->is_range) {
1862 call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001863 next_call_insn, target_method, method_info.VTableIndex(),
1864 method_info.DirectCode(), method_info.DirectMethod(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001865 original_type, skip_this);
1866 } else {
1867 call_state = GenDalvikArgsRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001868 next_call_insn, target_method, method_info.VTableIndex(),
1869 method_info.DirectCode(), method_info.DirectMethod(),
1870 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001871 }
1872 // Finish up any of the call sequence not interleaved in arg loading
1873 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001874 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
1875 method_info.DirectCode(), method_info.DirectMethod(), original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001876 }
1877 LIR* call_inst;
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001878 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001879 call_inst = OpReg(kOpBlx, TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001880 } else {
Jeff Hao88474b42013-10-23 16:24:40 -07001881 if (fast_path) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001882 if (method_info.DirectCode() == static_cast<uintptr_t>(-1)) {
Mark Mendell55d0eac2014-02-06 11:02:52 -08001883 // We can have the linker fixup a call relative.
1884 call_inst =
Jeff Hao49161ce2014-03-12 11:05:25 -07001885 reinterpret_cast<X86Mir2Lir*>(this)->CallWithLinkerFixup(target_method, info->type);
Mark Mendell55d0eac2014-02-06 11:02:52 -08001886 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001887 call_inst = OpMem(kOpBlx, TargetRefReg(kArg0),
Mark Mendell55d0eac2014-02-06 11:02:52 -08001888 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
1889 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001890 } else {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001891 // TODO: Extract?
buzbee33ae5582014-06-12 14:56:32 -07001892 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001893 call_inst = GenInvokeNoInlineCall<8>(this, info->type);
1894 } else {
Andreas Gampe3ec5da22014-05-12 18:43:28 -07001895 call_inst = GenInvokeNoInlineCall<4>(this, info->type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001896 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001897 }
1898 }
Mark Mendelle87f9b52014-04-30 14:13:18 -04001899 EndInvoke(info);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001900 MarkSafepointPC(call_inst);
1901
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001902 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001903 if (info->result.location != kLocInvalid) {
1904 // We have a following MOVE_RESULT - do it now.
1905 if (info->result.wide) {
buzbeea0cd2d72014-06-01 09:33:49 -07001906 RegLocation ret_loc = GetReturnWide(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001907 StoreValueWide(info->result, ret_loc);
1908 } else {
buzbeea0cd2d72014-06-01 09:33:49 -07001909 RegLocation ret_loc = GetReturn(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001910 StoreValue(info->result, ret_loc);
1911 }
1912 }
1913}
1914
1915} // namespace art