blob: 367e07bb8182d91a763a08db253439472dad7ef7 [file] [log] [blame]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "dex/compiler_ir.h"
Vladimir Marko5c96e6b2013-11-14 15:34:17 +000018#include "dex/frontend.h"
19#include "dex/quick/dex_file_method_inliner.h"
20#include "dex/quick/dex_file_to_method_inliner_map.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070021#include "dex_file-inl.h"
Ian Rogers166db042013-07-26 12:05:57 -070022#include "entrypoints/quick/quick_entrypoints.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070023#include "invoke_type.h"
24#include "mirror/array.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070025#include "mirror/class-inl.h"
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070026#include "mirror/object_array-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070027#include "mirror/string.h"
28#include "mir_to_lir-inl.h"
Brian Carlstrom7940e442013-07-12 13:46:57 -070029#include "x86/codegen_x86.h"
30
31namespace art {
32
Dmitry Petrochenko37498b62014-05-05 20:33:38 +070033// Shortcuts to repeatedly used long types.
34typedef mirror::ObjectArray<mirror::Object> ObjArray;
35
Brian Carlstrom7940e442013-07-12 13:46:57 -070036/*
37 * This source files contains "gen" codegen routines that should
38 * be applicable to most targets. Only mid-level support utilities
39 * and "op" calls may be used here.
40 */
41
Mingyao Yang3a74d152014-04-21 15:39:44 -070042void Mir2Lir::AddIntrinsicSlowPath(CallInfo* info, LIR* branch, LIR* resume) {
43 class IntrinsicSlowPathPath : public Mir2Lir::LIRSlowPath {
Vladimir Marko3bc86152014-03-13 14:11:28 +000044 public:
Mingyao Yang3a74d152014-04-21 15:39:44 -070045 IntrinsicSlowPathPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr)
Vladimir Marko3bc86152014-03-13 14:11:28 +000046 : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) {
47 }
48
49 void Compile() {
50 m2l_->ResetRegPool();
51 m2l_->ResetDefTracking();
Mingyao Yang6ffcfa02014-04-25 11:06:00 -070052 GenerateTargetLabel(kPseudoIntrinsicRetry);
Vladimir Marko3bc86152014-03-13 14:11:28 +000053 // NOTE: GenInvokeNoInline() handles MarkSafepointPC.
54 m2l_->GenInvokeNoInline(info_);
55 if (cont_ != nullptr) {
56 m2l_->OpUnconditionalBranch(cont_);
57 }
58 }
59
60 private:
61 CallInfo* const info_;
62 };
63
Mingyao Yang3a74d152014-04-21 15:39:44 -070064 AddSlowPath(new (arena_) IntrinsicSlowPathPath(this, info, branch, resume));
Vladimir Marko3bc86152014-03-13 14:11:28 +000065}
66
Andreas Gampe2f244e92014-05-08 03:35:25 -070067// Macro to help instantiate.
68// TODO: This might be used to only instantiate <4> on pure 32b systems.
69#define INSTANTIATE(sig_part1, ...) \
70 template sig_part1(ThreadOffset<4>, __VA_ARGS__); \
71 template sig_part1(ThreadOffset<8>, __VA_ARGS__); \
72
73
Brian Carlstrom7940e442013-07-12 13:46:57 -070074/*
75 * To save scheduling time, helper calls are broken into two parts: generation of
Dave Allisond6ed6422014-04-09 23:36:15 +000076 * the helper target address, and the actual call to the helper. Because x86
77 * has a memory call operation, part 1 is a NOP for x86. For other targets,
78 * load arguments between the two parts.
Brian Carlstrom7940e442013-07-12 13:46:57 -070079 */
Andreas Gampe2f244e92014-05-08 03:35:25 -070080// template <size_t pointer_size>
Ian Rogersdd7624d2014-03-14 17:43:00 -070081RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<4> helper_offset) {
Andreas Gampe2f244e92014-05-08 03:35:25 -070082 // All CallRuntimeHelperXXX call this first. So make a central check here.
83 DCHECK_EQ(4U, GetInstructionSetPointerSize(cu_->instruction_set));
84
85 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
86 return RegStorage::InvalidReg();
87 } else {
88 return LoadHelper(helper_offset);
89 }
90}
91
92RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<8> helper_offset) {
93 // All CallRuntimeHelperXXX call this first. So make a central check here.
94 DCHECK_EQ(8U, GetInstructionSetPointerSize(cu_->instruction_set));
95
96 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
97 return RegStorage::InvalidReg();
98 } else {
99 return LoadHelper(helper_offset);
100 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700101}
102
103/* NOTE: if r_tgt is a temp, it will be freed following use */
Andreas Gampe2f244e92014-05-08 03:35:25 -0700104template <size_t pointer_size>
105LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<pointer_size> helper_offset,
106 bool safepoint_pc, bool use_link) {
Dave Allisond6ed6422014-04-09 23:36:15 +0000107 LIR* call_inst;
Brian Carlstrom60d7a652014-03-13 18:10:08 -0700108 OpKind op = use_link ? kOpBlx : kOpBx;
Dave Allisond6ed6422014-04-09 23:36:15 +0000109 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
110 call_inst = OpThreadMem(op, helper_offset);
111 } else {
112 call_inst = OpReg(op, r_tgt);
113 FreeTemp(r_tgt);
114 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700115 if (safepoint_pc) {
116 MarkSafepointPC(call_inst);
117 }
118 return call_inst;
119}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700120template LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<4> helper_offset,
121 bool safepoint_pc, bool use_link);
122template LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<8> helper_offset,
123 bool safepoint_pc, bool use_link);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700124
Andreas Gampe2f244e92014-05-08 03:35:25 -0700125template <size_t pointer_size>
126void Mir2Lir::CallRuntimeHelper(ThreadOffset<pointer_size> helper_offset, bool safepoint_pc) {
Mingyao Yang42894562014-04-07 12:42:16 -0700127 RegStorage r_tgt = CallHelperSetup(helper_offset);
128 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700129 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Mingyao Yang42894562014-04-07 12:42:16 -0700130}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700131INSTANTIATE(void Mir2Lir::CallRuntimeHelper, bool safepoint_pc)
Mingyao Yang42894562014-04-07 12:42:16 -0700132
Andreas Gampe2f244e92014-05-08 03:35:25 -0700133template <size_t pointer_size>
Andreas Gampeccc60262014-07-04 18:02:38 -0700134void Mir2Lir::CallRuntimeHelperImm(ThreadOffset<pointer_size> helper_offset, int arg0,
135 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800136 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700137 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000138 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700139 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700140}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700141INSTANTIATE(void Mir2Lir::CallRuntimeHelperImm, int arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700142
Andreas Gampe2f244e92014-05-08 03:35:25 -0700143template <size_t pointer_size>
144void Mir2Lir::CallRuntimeHelperReg(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700145 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800146 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700147 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000148 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700149 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700150}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700151INSTANTIATE(void Mir2Lir::CallRuntimeHelperReg, RegStorage arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700152
Andreas Gampe2f244e92014-05-08 03:35:25 -0700153template <size_t pointer_size>
154void Mir2Lir::CallRuntimeHelperRegLocation(ThreadOffset<pointer_size> helper_offset,
155 RegLocation arg0, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800156 RegStorage r_tgt = CallHelperSetup(helper_offset);
157 if (arg0.wide == 0) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700158 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, arg0));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700159 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700160 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700161 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000162 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700163 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700164}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700165INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocation, RegLocation arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700166
Andreas Gampe2f244e92014-05-08 03:35:25 -0700167template <size_t pointer_size>
168void Mir2Lir::CallRuntimeHelperImmImm(ThreadOffset<pointer_size> helper_offset, int arg0, int arg1,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700169 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800170 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700171 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
172 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000173 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700174 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700175}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700176INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmImm, int arg0, int arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700177
Andreas Gampe2f244e92014-05-08 03:35:25 -0700178template <size_t pointer_size>
179void Mir2Lir::CallRuntimeHelperImmRegLocation(ThreadOffset<pointer_size> helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700180 RegLocation arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800181 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700182 DCHECK(!arg1.fp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700183 if (arg1.wide == 0) {
Andreas Gampef9872f02014-07-01 19:00:09 -0700184 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700185 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700186 RegStorage r_tmp = TargetReg(cu_->instruction_set == kMips ? kArg2 : kArg1, kWide);
buzbee2700f7e2014-03-07 09:46:20 -0800187 LoadValueDirectWideFixed(arg1, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700188 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700189 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000190 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700191 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700192}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700193INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmRegLocation, int arg0, RegLocation arg1,
194 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700195
Andreas Gampe2f244e92014-05-08 03:35:25 -0700196template <size_t pointer_size>
197void Mir2Lir::CallRuntimeHelperRegLocationImm(ThreadOffset<pointer_size> helper_offset,
198 RegLocation arg0, int arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800199 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampef9872f02014-07-01 19:00:09 -0700200 DCHECK(!arg0.wide);
201 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
Andreas Gampeccc60262014-07-04 18:02:38 -0700202 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
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::CallRuntimeHelperRegLocationImm, RegLocation arg0, int 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::CallRuntimeHelperImmReg(ThreadOffset<pointer_size> helper_offset, int arg0,
211 RegStorage arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800212 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700213 OpRegCopy(TargetReg(kArg1, arg1.GetWideKind()), arg1);
214 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000215 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700216 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700217}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700218INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmReg, int arg0, RegStorage arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700219
Andreas Gampe2f244e92014-05-08 03:35:25 -0700220template <size_t pointer_size>
221void Mir2Lir::CallRuntimeHelperRegImm(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
222 int arg1, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800223 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700224 OpRegCopy(TargetReg(kArg0, arg0.GetWideKind()), arg0);
225 LoadConstant(TargetReg(kArg1, kNotWide), arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000226 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700227 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700228}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700229INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegImm, RegStorage arg0, int arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700230
Andreas Gampe2f244e92014-05-08 03:35:25 -0700231template <size_t pointer_size>
232void Mir2Lir::CallRuntimeHelperImmMethod(ThreadOffset<pointer_size> helper_offset, int arg0,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700233 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800234 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700235 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
236 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000237 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700238 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700239}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700240INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethod, int arg0, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700241
Andreas Gampe2f244e92014-05-08 03:35:25 -0700242template <size_t pointer_size>
243void Mir2Lir::CallRuntimeHelperRegMethod(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800244 bool safepoint_pc) {
245 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700246 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.GetWideKind()), arg0));
247 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
248 if (r_tmp.NotExactlyEquals(arg0)) {
249 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800250 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700251 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800252 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700253 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800254}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700255INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegMethod, RegStorage arg0, bool safepoint_pc)
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800256
Andreas Gampe2f244e92014-05-08 03:35:25 -0700257template <size_t pointer_size>
258void Mir2Lir::CallRuntimeHelperRegMethodRegLocation(ThreadOffset<pointer_size> helper_offset,
259 RegStorage arg0, RegLocation arg2,
260 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800261 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700262 DCHECK(!IsSameReg(TargetReg(kArg1, arg0.GetWideKind()), arg0));
263 RegStorage r_tmp = TargetReg(kArg0, arg0.GetWideKind());
264 if (r_tmp.NotExactlyEquals(arg0)) {
265 OpRegCopy(r_tmp, arg0);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800266 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700267 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700268 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800269 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700270 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800271}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700272INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegMethodRegLocation, RegStorage arg0, RegLocation arg2,
273 bool safepoint_pc)
Hiroshi Yamauchibb8f0ab2014-01-27 16:50:29 -0800274
Andreas Gampe2f244e92014-05-08 03:35:25 -0700275template <size_t pointer_size>
276void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(ThreadOffset<pointer_size> helper_offset,
Ian Rogersdd7624d2014-03-14 17:43:00 -0700277 RegLocation arg0, RegLocation arg1,
278 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800279 RegStorage r_tgt = CallHelperSetup(helper_offset);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700280 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700281 RegStorage arg0_reg = TargetReg((arg0.fp) ? kFArg0 : kArg0, arg0);
282
283 RegStorage arg1_reg;
284 if (arg1.fp == arg0.fp) {
285 arg1_reg = TargetReg((arg1.fp) ? kFArg1 : kArg1, arg1);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700286 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700287 arg1_reg = TargetReg((arg1.fp) ? kFArg0 : kArg0, arg1);
288 }
289
290 if (arg0.wide == 0) {
291 LoadValueDirectFixed(arg0, arg0_reg);
292 } else {
293 LoadValueDirectWideFixed(arg0, arg0_reg);
294 }
295
296 if (arg1.wide == 0) {
297 LoadValueDirectFixed(arg1, arg1_reg);
298 } else {
299 LoadValueDirectWideFixed(arg1, arg1_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700300 }
301 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700302 DCHECK(!cu_->target64);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700303 if (arg0.wide == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700304 LoadValueDirectFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700305 if (arg1.wide == 0) {
306 if (cu_->instruction_set == kMips) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700307 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700308 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700309 LoadValueDirectFixed(arg1, TargetReg(kArg1, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700310 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700311 } else {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700312 if (cu_->instruction_set == kMips) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700313 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700314 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700315 LoadValueDirectWideFixed(arg1, TargetReg(kArg1, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700316 }
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700317 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700318 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700319 LoadValueDirectWideFixed(arg0, TargetReg(arg0.fp ? kFArg0 : kArg0, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700320 if (arg1.wide == 0) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700321 LoadValueDirectFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kNotWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700322 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700323 LoadValueDirectWideFixed(arg1, TargetReg(arg1.fp ? kFArg2 : kArg2, kWide));
Andreas Gampe4b537a82014-06-30 22:24:53 -0700324 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700325 }
326 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000327 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700328 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700329}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700330INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationRegLocation, RegLocation arg0,
331 RegLocation arg1, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700332
Mingyao Yang80365d92014-04-18 12:10:58 -0700333void Mir2Lir::CopyToArgumentRegs(RegStorage arg0, RegStorage arg1) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700334 WideKind arg0_kind = arg0.GetWideKind();
335 WideKind arg1_kind = arg1.GetWideKind();
336 if (IsSameReg(arg1, TargetReg(kArg0, arg1_kind))) {
337 if (IsSameReg(arg0, TargetReg(kArg1, arg0_kind))) {
Mingyao Yang80365d92014-04-18 12:10:58 -0700338 // Swap kArg0 and kArg1 with kArg2 as temp.
Andreas Gampeccc60262014-07-04 18:02:38 -0700339 OpRegCopy(TargetReg(kArg2, arg1_kind), arg1);
340 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
341 OpRegCopy(TargetReg(kArg1, arg1_kind), TargetReg(kArg2, arg1_kind));
Mingyao Yang80365d92014-04-18 12:10:58 -0700342 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700343 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
344 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
Mingyao Yang80365d92014-04-18 12:10:58 -0700345 }
346 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700347 OpRegCopy(TargetReg(kArg0, arg0_kind), arg0);
348 OpRegCopy(TargetReg(kArg1, arg1_kind), arg1);
Mingyao Yang80365d92014-04-18 12:10:58 -0700349 }
350}
351
Andreas Gampe2f244e92014-05-08 03:35:25 -0700352template <size_t pointer_size>
353void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800354 RegStorage arg1, bool safepoint_pc) {
355 RegStorage r_tgt = CallHelperSetup(helper_offset);
Mingyao Yang80365d92014-04-18 12:10:58 -0700356 CopyToArgumentRegs(arg0, arg1);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000357 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700358 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700359}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700360INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegReg, RegStorage arg0, RegStorage arg1,
361 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700362
Andreas Gampe2f244e92014-05-08 03:35:25 -0700363template <size_t pointer_size>
364void Mir2Lir::CallRuntimeHelperRegRegImm(ThreadOffset<pointer_size> helper_offset, RegStorage arg0,
buzbee2700f7e2014-03-07 09:46:20 -0800365 RegStorage arg1, int arg2, bool safepoint_pc) {
366 RegStorage r_tgt = CallHelperSetup(helper_offset);
Mingyao Yang80365d92014-04-18 12:10:58 -0700367 CopyToArgumentRegs(arg0, arg1);
Andreas Gampeccc60262014-07-04 18:02:38 -0700368 LoadConstant(TargetReg(kArg2, kNotWide), arg2);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000369 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700370 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700371}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700372INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegRegImm, RegStorage arg0, RegStorage arg1, int arg2,
373 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700374
Andreas Gampe2f244e92014-05-08 03:35:25 -0700375template <size_t pointer_size>
376void Mir2Lir::CallRuntimeHelperImmMethodRegLocation(ThreadOffset<pointer_size> helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700377 int arg0, RegLocation arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800378 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700379 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Andreas Gampeccc60262014-07-04 18:02:38 -0700380 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
381 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000382 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700383 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700384}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700385INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethodRegLocation, int arg0, RegLocation arg2,
386 bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700387
Andreas Gampe2f244e92014-05-08 03:35:25 -0700388template <size_t pointer_size>
389void Mir2Lir::CallRuntimeHelperImmMethodImm(ThreadOffset<pointer_size> helper_offset, int arg0,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700390 int arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800391 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampeccc60262014-07-04 18:02:38 -0700392 LoadCurrMethodDirect(TargetReg(kArg1, kRef));
393 LoadConstant(TargetReg(kArg2, kNotWide), arg2);
394 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000395 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700396 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700397}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700398INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmMethodImm, int arg0, int arg2, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700399
Andreas Gampe2f244e92014-05-08 03:35:25 -0700400template <size_t pointer_size>
401void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset<pointer_size> helper_offset,
Brian Carlstrom7940e442013-07-12 13:46:57 -0700402 int arg0, RegLocation arg1,
403 RegLocation arg2, bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800404 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700405 DCHECK_EQ(static_cast<unsigned int>(arg1.wide), 0U); // The static_cast works around an
406 // instantiation bug in GCC.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700407 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700408 if (arg2.wide == 0) {
Andreas Gampe4b537a82014-06-30 22:24:53 -0700409 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700410 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700411 LoadValueDirectWideFixed(arg2, TargetReg(kArg2, kWide));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700412 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700413 LoadConstant(TargetReg(kArg0, kNotWide), arg0);
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000414 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700415 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700416}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700417INSTANTIATE(void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation, int arg0, RegLocation arg1,
418 RegLocation arg2, bool safepoint_pc)
Brian Carlstrom7940e442013-07-12 13:46:57 -0700419
Andreas Gampe2f244e92014-05-08 03:35:25 -0700420template <size_t pointer_size>
Andreas Gampeccc60262014-07-04 18:02:38 -0700421void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(
422 ThreadOffset<pointer_size> helper_offset,
423 RegLocation arg0,
424 RegLocation arg1,
425 RegLocation arg2,
426 bool safepoint_pc) {
buzbee2700f7e2014-03-07 09:46:20 -0800427 RegStorage r_tgt = CallHelperSetup(helper_offset);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700428 LoadValueDirectFixed(arg0, TargetReg(kArg0, arg0));
429 LoadValueDirectFixed(arg1, TargetReg(kArg1, arg1));
430 LoadValueDirectFixed(arg2, TargetReg(kArg2, arg2));
Vladimir Marko31c2aac2013-12-09 16:31:19 +0000431 ClobberCallerSave();
Andreas Gampe2f244e92014-05-08 03:35:25 -0700432 CallHelper<pointer_size>(r_tgt, helper_offset, safepoint_pc);
Ian Rogersa9a82542013-10-04 11:17:26 -0700433}
Andreas Gampe2f244e92014-05-08 03:35:25 -0700434INSTANTIATE(void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation, RegLocation arg0,
435 RegLocation arg1, RegLocation arg2, bool safepoint_pc)
Ian Rogersa9a82542013-10-04 11:17:26 -0700436
Brian Carlstrom7940e442013-07-12 13:46:57 -0700437/*
438 * If there are any ins passed in registers that have not been promoted
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100439 * to a callee-save register, flush them to the frame. Perform initial
Brian Carlstrom7940e442013-07-12 13:46:57 -0700440 * assignment of promoted arguments.
441 *
442 * ArgLocs is an array of location records describing the incoming arguments
443 * with one location record per word of argument.
444 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700445void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700446 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800447 * Dummy up a RegLocation for the incoming StackReference<mirror::ArtMethod>
Brian Carlstrom7940e442013-07-12 13:46:57 -0700448 * It will attempt to keep kArg0 live (or copy it to home location
449 * if promoted).
450 */
451 RegLocation rl_src = rl_method;
452 rl_src.location = kLocPhysReg;
Andreas Gampeccc60262014-07-04 18:02:38 -0700453 rl_src.reg = TargetReg(kArg0, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700454 rl_src.home = false;
buzbee091cc402014-03-31 10:14:40 -0700455 MarkLive(rl_src);
buzbeef2c3e562014-05-29 12:37:25 -0700456 StoreValue(rl_method, rl_src);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700457 // If Method* has been promoted, explicitly flush
458 if (rl_method.location == kLocPhysReg) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700459 StoreRefDisp(TargetPtrReg(kSp), 0, rl_src.reg, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700460 }
461
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800462 if (cu_->num_ins == 0) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700463 return;
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800464 }
465
Brian Carlstrom7940e442013-07-12 13:46:57 -0700466 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
467 /*
468 * Copy incoming arguments to their proper home locations.
469 * NOTE: an older version of dx had an issue in which
470 * it would reuse static method argument registers.
471 * This could result in the same Dalvik virtual register
472 * being promoted to both core and fp regs. To account for this,
473 * we only copy to the corresponding promoted physical register
474 * if it matches the type of the SSA name for the incoming
475 * argument. It is also possible that long and double arguments
476 * end up half-promoted. In those cases, we must flush the promoted
477 * half to memory as well.
478 */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100479 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700480 for (int i = 0; i < cu_->num_ins; i++) {
481 PromotionMap* v_map = &promotion_map_[start_vreg + i];
buzbee2700f7e2014-03-07 09:46:20 -0800482 RegStorage reg = GetArgMappingToPhysicalReg(i);
Razvan A Lupusoru3bc01742014-02-06 13:18:43 -0800483
buzbee2700f7e2014-03-07 09:46:20 -0800484 if (reg.Valid()) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700485 // If arriving in register
486 bool need_flush = true;
487 RegLocation* t_loc = &ArgLocs[i];
488 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
buzbee2700f7e2014-03-07 09:46:20 -0800489 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700490 need_flush = false;
491 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
buzbeeb5860fb2014-06-21 15:31:01 -0700492 OpRegCopy(RegStorage::Solo32(v_map->fp_reg), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700493 need_flush = false;
494 } else {
495 need_flush = true;
496 }
497
buzbeed0a03b82013-09-14 08:21:05 -0700498 // For wide args, force flush if not fully promoted
Brian Carlstrom7940e442013-07-12 13:46:57 -0700499 if (t_loc->wide) {
500 PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1);
buzbeed0a03b82013-09-14 08:21:05 -0700501 // Is only half promoted?
Brian Carlstrom7940e442013-07-12 13:46:57 -0700502 need_flush |= (p_map->core_location != v_map->core_location) ||
503 (p_map->fp_location != v_map->fp_location);
buzbeed0a03b82013-09-14 08:21:05 -0700504 if ((cu_->instruction_set == kThumb2) && t_loc->fp && !need_flush) {
505 /*
506 * In Arm, a double is represented as a pair of consecutive single float
507 * registers starting at an even number. It's possible that both Dalvik vRegs
508 * representing the incoming double were independently promoted as singles - but
509 * not in a form usable as a double. If so, we need to flush - even though the
510 * incoming arg appears fully in register. At this point in the code, both
511 * halves of the double are promoted. Make sure they are in a usable form.
512 */
513 int lowreg_index = start_vreg + i + (t_loc->high_word ? -1 : 0);
buzbeeb5860fb2014-06-21 15:31:01 -0700514 int low_reg = promotion_map_[lowreg_index].fp_reg;
515 int high_reg = promotion_map_[lowreg_index + 1].fp_reg;
buzbeed0a03b82013-09-14 08:21:05 -0700516 if (((low_reg & 0x1) != 0) || (high_reg != (low_reg + 1))) {
517 need_flush = true;
518 }
519 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700520 }
521 if (need_flush) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700522 Store32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700523 }
524 } else {
525 // If arriving in frame & promoted
526 if (v_map->core_location == kLocPhysReg) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700527 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i),
528 RegStorage::Solo32(v_map->core_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700529 }
530 if (v_map->fp_location == kLocPhysReg) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700531 Load32Disp(TargetPtrReg(kSp), SRegOffset(start_vreg + i),
532 RegStorage::Solo32(v_map->fp_reg));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700533 }
534 }
535 }
536}
537
Andreas Gampeccc60262014-07-04 18:02:38 -0700538static void CommonCallCodeLoadThisIntoArg1(const CallInfo* info, Mir2Lir* cg) {
539 RegLocation rl_arg = info->args[0];
540 cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1, kRef));
541}
542
543static void CommonCallCodeLoadClassIntoArg0(const CallInfo* info, Mir2Lir* cg) {
544 cg->GenNullCheck(cg->TargetReg(kArg1, kRef), info->opt_flags);
545 // get this->klass_ [use kArg1, set kArg0]
546 cg->LoadRefDisp(cg->TargetReg(kArg1, kRef), mirror::Object::ClassOffset().Int32Value(),
547 cg->TargetReg(kArg0, kRef),
548 kNotVolatile);
549 cg->MarkPossibleNullPointerException(info->opt_flags);
550}
551
552static bool CommonCallCodeLoadCodePointerIntoInvokeTgt(const CallInfo* info,
553 const RegStorage* alt_from,
554 const CompilationUnit* cu, Mir2Lir* cg) {
555 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
556 // Get the compiled code address [use *alt_from or kArg0, set kInvokeTgt]
557 cg->LoadWordDisp(alt_from == nullptr ? cg->TargetReg(kArg0, kRef) : *alt_from,
558 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(),
559 cg->TargetPtrReg(kInvokeTgt));
560 return true;
561 }
562 return false;
563}
564
Brian Carlstrom7940e442013-07-12 13:46:57 -0700565/*
566 * Bit of a hack here - in the absence of a real scheduling pass,
567 * emit the next instruction in static & direct invoke sequences.
568 */
569static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info,
570 int state, const MethodReference& target_method,
571 uint32_t unused,
572 uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700573 InvokeType type) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700574 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700575 if (direct_code != 0 && direct_method != 0) {
576 switch (state) {
577 case 0: // Get the current Method* [sets kArg0]
Ian Rogersff093b32014-04-30 19:04:27 -0700578 if (direct_code != static_cast<uintptr_t>(-1)) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700579 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700580 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
Ian Rogers83883d72013-10-21 21:07:24 -0700581 }
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700582 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Jeff Hao49161ce2014-03-12 11:05:25 -0700583 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700584 }
Ian Rogersff093b32014-04-30 19:04:27 -0700585 if (direct_method != static_cast<uintptr_t>(-1)) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700586 cg->LoadConstant(cg->TargetReg(kArg0, kRef), direct_method);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700587 } else {
Jeff Hao49161ce2014-03-12 11:05:25 -0700588 cg->LoadMethodAddress(target_method, type, kArg0);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700589 }
590 break;
591 default:
592 return -1;
593 }
594 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700595 RegStorage arg0_ref = cg->TargetReg(kArg0, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700596 switch (state) {
597 case 0: // Get the current Method* [sets kArg0]
598 // TUNING: we can save a reg copy if Method* has been promoted.
Andreas Gampe4b537a82014-06-30 22:24:53 -0700599 cg->LoadCurrMethodDirect(arg0_ref);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700600 break;
601 case 1: // Get method->dex_cache_resolved_methods_
Andreas Gampe4b537a82014-06-30 22:24:53 -0700602 cg->LoadRefDisp(arg0_ref,
buzbee695d13a2014-04-19 13:32:20 -0700603 mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700604 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000605 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700606 // Set up direct code if known.
607 if (direct_code != 0) {
Ian Rogersff093b32014-04-30 19:04:27 -0700608 if (direct_code != static_cast<uintptr_t>(-1)) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700609 cg->LoadConstant(cg->TargetPtrReg(kInvokeTgt), direct_code);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700610 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Ian Rogers83883d72013-10-21 21:07:24 -0700611 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Jeff Hao49161ce2014-03-12 11:05:25 -0700612 cg->LoadCodeAddress(target_method, type, kInvokeTgt);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700613 }
614 }
615 break;
616 case 2: // Grab target method*
617 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampe4b537a82014-06-30 22:24:53 -0700618 cg->LoadRefDisp(arg0_ref,
Dmitry Petrochenko37498b62014-05-05 20:33:38 +0700619 ObjArray::OffsetOfElement(target_method.dex_method_index).Int32Value(),
Andreas Gampe4b537a82014-06-30 22:24:53 -0700620 arg0_ref,
Andreas Gampe3c12c512014-06-24 18:46:29 +0000621 kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700622 break;
623 case 3: // Grab the code from the method*
Andreas Gampeccc60262014-07-04 18:02:38 -0700624 if (direct_code == 0) {
625 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, &arg0_ref, cu, cg)) {
626 break; // kInvokeTgt := arg0_ref->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700627 }
Andreas Gampeccc60262014-07-04 18:02:38 -0700628 } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700629 break;
630 }
631 // Intentional fallthrough for x86
632 default:
633 return -1;
634 }
635 }
636 return state + 1;
637}
638
639/*
640 * Bit of a hack here - in the absence of a real scheduling pass,
641 * emit the next instruction in a virtual invoke sequence.
642 * We can use kLr as a temp prior to target address loading
643 * Note also that we'll load the first argument ("this") into
644 * kArg1 here rather than the standard LoadArgRegs.
645 */
646static int NextVCallInsn(CompilationUnit* cu, CallInfo* info,
647 int state, const MethodReference& target_method,
648 uint32_t method_idx, uintptr_t unused, uintptr_t unused2,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700649 InvokeType unused3) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700650 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
651 /*
652 * This is the fast path in which the target virtual method is
653 * fully resolved at compile time.
654 */
655 switch (state) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700656 case 0:
657 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Brian Carlstrom7940e442013-07-12 13:46:57 -0700658 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700659 case 1:
660 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
661 // Includes a null-check.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700662 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700663 case 2: {
664 // Get this->klass_.embedded_vtable[method_idx] [usr kArg0, set kArg0]
665 int32_t offset = mirror::Class::EmbeddedVTableOffset().Uint32Value() +
666 method_idx * sizeof(mirror::Class::VTableEntry);
667 // Load target method from embedded vtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700668 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700669 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700670 }
671 case 3:
Andreas Gampeccc60262014-07-04 18:02:38 -0700672 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, nullptr, cu, cg)) {
673 break; // kInvokeTgt := kArg0->entrypoint
Brian Carlstrom7940e442013-07-12 13:46:57 -0700674 }
675 // Intentional fallthrough for X86
676 default:
677 return -1;
678 }
679 return state + 1;
680}
681
682/*
Jeff Hao88474b42013-10-23 16:24:40 -0700683 * Emit the next instruction in an invoke interface sequence. This will do a lookup in the
684 * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if
685 * more than one interface method map to the same index. Note also that we'll load the first
686 * argument ("this") into kArg1 here rather than the standard LoadArgRegs.
Brian Carlstrom7940e442013-07-12 13:46:57 -0700687 */
688static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state,
689 const MethodReference& target_method,
Jeff Hao88474b42013-10-23 16:24:40 -0700690 uint32_t method_idx, uintptr_t unused,
691 uintptr_t direct_method, InvokeType unused2) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700692 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
Brian Carlstrom7940e442013-07-12 13:46:57 -0700693
Jeff Hao88474b42013-10-23 16:24:40 -0700694 switch (state) {
695 case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)]
Jeff Hao88474b42013-10-23 16:24:40 -0700696 CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds());
Andreas Gampeccc60262014-07-04 18:02:38 -0700697 cg->LoadConstant(cg->TargetReg(kHiddenArg, kNotWide), target_method.dex_method_index);
Mark Mendelld3703d82014-06-09 15:10:50 -0400698 if (cu->instruction_set == kX86) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700699 cg->OpRegCopy(cg->TargetReg(kHiddenFpArg, kNotWide), cg->TargetReg(kHiddenArg, kNotWide));
Jeff Hao88474b42013-10-23 16:24:40 -0700700 }
701 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700702 case 1:
703 CommonCallCodeLoadThisIntoArg1(info, cg); // kArg1 := this
Jeff Hao88474b42013-10-23 16:24:40 -0700704 break;
Andreas Gampeccc60262014-07-04 18:02:38 -0700705 case 2:
706 CommonCallCodeLoadClassIntoArg0(info, cg); // kArg0 := kArg1->class
707 // Includes a null-check.
Jeff Hao88474b42013-10-23 16:24:40 -0700708 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700709 case 3: { // Get target method [use kInvokeTgt, set kArg0]
710 int32_t offset = mirror::Class::EmbeddedImTableOffset().Uint32Value() +
711 (method_idx % mirror::Class::kImtSize) * sizeof(mirror::Class::ImTableEntry);
712 // Load target method from embedded imtable to kArg0 [use kArg0, set kArg0]
Andreas Gampeccc60262014-07-04 18:02:38 -0700713 cg->LoadRefDisp(cg->TargetReg(kArg0, kRef), offset, cg->TargetReg(kArg0, kRef), kNotVolatile);
Jeff Hao88474b42013-10-23 16:24:40 -0700714 break;
Mingyao Yang98d1cc82014-05-15 17:02:16 -0700715 }
716 case 4:
Andreas Gampeccc60262014-07-04 18:02:38 -0700717 if (CommonCallCodeLoadCodePointerIntoInvokeTgt(info, nullptr, cu, cg)) {
718 break; // kInvokeTgt := kArg0->entrypoint
Jeff Hao88474b42013-10-23 16:24:40 -0700719 }
720 // Intentional fallthrough for X86
Brian Carlstrom7940e442013-07-12 13:46:57 -0700721 default:
722 return -1;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700723 }
724 return state + 1;
725}
726
Andreas Gampe2f244e92014-05-08 03:35:25 -0700727template <size_t pointer_size>
Andreas Gampeccc60262014-07-04 18:02:38 -0700728static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info,
729 ThreadOffset<pointer_size> trampoline, int state,
730 const MethodReference& target_method, uint32_t method_idx) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700731 Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get());
732 /*
733 * This handles the case in which the base method is not fully
734 * resolved at compile time, we bail to a runtime helper.
735 */
736 if (state == 0) {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +0700737 if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700738 // Load trampoline target
Andreas Gampeccc60262014-07-04 18:02:38 -0700739 cg->LoadWordDisp(cg->TargetPtrReg(kSelf), trampoline.Int32Value(),
740 cg->TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700741 }
742 // Load kArg0 with method index
743 CHECK_EQ(cu->dex_file, target_method.dex_file);
Andreas Gampeccc60262014-07-04 18:02:38 -0700744 cg->LoadConstant(cg->TargetReg(kArg0, kNotWide), target_method.dex_method_index);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700745 return 1;
746 }
747 return -1;
748}
749
750static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info,
751 int state,
752 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000753 uint32_t unused, uintptr_t unused2,
754 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700755 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700756 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeStaticTrampolineWithAccessCheck);
757 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
758 } else {
759 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeStaticTrampolineWithAccessCheck);
760 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
761 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700762}
763
764static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
765 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000766 uint32_t unused, uintptr_t unused2,
767 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700768 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700769 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeDirectTrampolineWithAccessCheck);
770 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
771 } else {
772 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeDirectTrampolineWithAccessCheck);
773 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
774 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700775}
776
777static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
778 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000779 uint32_t unused, uintptr_t unused2,
780 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700781 if (cu->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -0700782 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8, pInvokeSuperTrampolineWithAccessCheck);
783 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
784 } else {
785 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeSuperTrampolineWithAccessCheck);
786 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
787 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700788}
789
790static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state,
791 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000792 uint32_t unused, uintptr_t unused2,
793 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700794 if (cu->target64) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700795 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8,
796 pInvokeVirtualTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700797 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
798 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700799 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4,
800 pInvokeVirtualTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700801 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
802 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700803}
804
805static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu,
806 CallInfo* info, int state,
807 const MethodReference& target_method,
Vladimir Markof096aad2014-01-23 15:51:58 +0000808 uint32_t unused, uintptr_t unused2,
809 uintptr_t unused3, InvokeType unused4) {
buzbee33ae5582014-06-12 14:56:32 -0700810 if (cu->target64) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700811 ThreadOffset<8> trampoline = QUICK_ENTRYPOINT_OFFSET(8,
812 pInvokeInterfaceTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700813 return NextInvokeInsnSP<8>(cu, info, trampoline, state, target_method, 0);
814 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700815 ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4,
816 pInvokeInterfaceTrampolineWithAccessCheck);
Andreas Gampe2f244e92014-05-08 03:35:25 -0700817 return NextInvokeInsnSP<4>(cu, info, trampoline, state, target_method, 0);
818 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700819}
820
821int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
822 NextCallInsn next_call_insn,
823 const MethodReference& target_method,
824 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700825 uintptr_t direct_method, InvokeType type, bool skip_this) {
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700826 int last_arg_reg = 3 - 1;
Andreas Gampeccc60262014-07-04 18:02:38 -0700827 int arg_regs[3] = {TargetReg(kArg1, kNotWide).GetReg(), TargetReg(kArg2, kNotWide).GetReg(),
828 TargetReg(kArg3, kNotWide).GetReg()};
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700829
830 int next_reg = 0;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700831 int next_arg = 0;
832 if (skip_this) {
833 next_reg++;
834 next_arg++;
835 }
836 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
837 RegLocation rl_arg = info->args[next_arg++];
838 rl_arg = UpdateRawLoc(rl_arg);
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700839 if (rl_arg.wide && (next_reg <= last_arg_reg - 1)) {
840 RegStorage r_tmp(RegStorage::k64BitPair, arg_regs[next_reg], arg_regs[next_reg + 1]);
buzbee2700f7e2014-03-07 09:46:20 -0800841 LoadValueDirectWideFixed(rl_arg, r_tmp);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700842 next_reg++;
843 next_arg++;
844 } else {
845 if (rl_arg.wide) {
buzbee2700f7e2014-03-07 09:46:20 -0800846 rl_arg = NarrowRegLoc(rl_arg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700847 rl_arg.is_const = false;
848 }
Dmitry Petrochenko26ee07a2014-05-13 12:58:19 +0700849 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(arg_regs[next_reg]));
Brian Carlstrom7940e442013-07-12 13:46:57 -0700850 }
851 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
852 direct_code, direct_method, type);
853 }
854 return call_state;
855}
856
857/*
858 * Load up to 5 arguments, the first three of which will be in
859 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
860 * and as part of the load sequence, it must be replaced with
861 * the target method pointer. Note, this may also be called
862 * for "range" variants if the number of arguments is 5 or fewer.
863 */
864int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info,
865 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
866 const MethodReference& target_method,
867 uint32_t vtable_idx, uintptr_t direct_code,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700868 uintptr_t direct_method, InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700869 RegLocation rl_arg;
870
871 /* If no arguments, just return */
872 if (info->num_arg_words == 0)
873 return call_state;
874
875 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
876 direct_code, direct_method, type);
877
878 DCHECK_LE(info->num_arg_words, 5);
879 if (info->num_arg_words > 3) {
880 int32_t next_use = 3;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700881 // Detect special case of wide arg spanning arg3/arg4
Brian Carlstrom7940e442013-07-12 13:46:57 -0700882 RegLocation rl_use0 = info->args[0];
883 RegLocation rl_use1 = info->args[1];
884 RegLocation rl_use2 = info->args[2];
buzbee2700f7e2014-03-07 09:46:20 -0800885 if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) && rl_use2.wide) {
886 RegStorage reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700887 // Wide spans, we need the 2nd half of uses[2].
888 rl_arg = UpdateLocWide(rl_use2);
889 if (rl_arg.location == kLocPhysReg) {
buzbee85089dd2014-05-25 15:10:52 -0700890 if (rl_arg.reg.IsPair()) {
891 reg = rl_arg.reg.GetHigh();
892 } else {
893 RegisterInfo* info = GetRegInfo(rl_arg.reg);
894 info = info->FindMatchingView(RegisterInfo::kHighSingleStorageMask);
895 if (info == nullptr) {
896 // NOTE: For hard float convention we won't split arguments across reg/mem.
897 UNIMPLEMENTED(FATAL) << "Needs hard float api.";
898 }
899 reg = info->GetReg();
900 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700901 } else {
902 // kArg2 & rArg3 can safely be used here
Andreas Gampeccc60262014-07-04 18:02:38 -0700903 reg = TargetReg(kArg3, kNotWide);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100904 {
905 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700906 Load32Disp(TargetPtrReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100907 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700908 call_state = next_call_insn(cu_, info, call_state, target_method,
909 vtable_idx, direct_code, direct_method, type);
910 }
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100911 {
912 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -0700913 Store32Disp(TargetPtrReg(kSp), (next_use + 1) * 4, reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100914 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700915 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
916 direct_code, direct_method, type);
917 next_use++;
918 }
919 // Loop through the rest
920 while (next_use < info->num_arg_words) {
buzbee091cc402014-03-31 10:14:40 -0700921 RegStorage arg_reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700922 rl_arg = info->args[next_use];
923 rl_arg = UpdateRawLoc(rl_arg);
924 if (rl_arg.location == kLocPhysReg) {
buzbee091cc402014-03-31 10:14:40 -0700925 arg_reg = rl_arg.reg;
Brian Carlstrom7940e442013-07-12 13:46:57 -0700926 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -0700927 arg_reg = TargetReg(kArg2, rl_arg.wide ? kWide : kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700928 if (rl_arg.wide) {
buzbee091cc402014-03-31 10:14:40 -0700929 LoadValueDirectWideFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700930 } else {
buzbee091cc402014-03-31 10:14:40 -0700931 LoadValueDirectFixed(rl_arg, arg_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -0700932 }
933 call_state = next_call_insn(cu_, info, call_state, target_method,
934 vtable_idx, direct_code, direct_method, type);
935 }
936 int outs_offset = (next_use + 1) * 4;
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100937 {
938 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
939 if (rl_arg.wide) {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700940 StoreBaseDisp(TargetPtrReg(kSp), outs_offset, arg_reg, k64, kNotVolatile);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100941 next_use += 2;
942 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -0700943 Store32Disp(TargetPtrReg(kSp), outs_offset, arg_reg);
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100944 next_use++;
945 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700946 }
947 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
948 direct_code, direct_method, type);
949 }
950 }
951
952 call_state = LoadArgRegs(info, call_state, next_call_insn,
953 target_method, vtable_idx, direct_code, direct_method,
954 type, skip_this);
955
956 if (pcrLabel) {
Andreas Gampe5655e842014-06-17 16:36:07 -0700957 if (cu_->compiler_driver->GetCompilerOptions().GetExplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -0700958 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -0700959 } else {
960 *pcrLabel = nullptr;
961 // In lieu of generating a check for kArg1 being null, we need to
962 // perform a load when doing implicit checks.
Dave Allison3d14eb62014-07-10 01:54:57 +0000963 RegStorage tmp = AllocTemp();
Andreas Gampeccc60262014-07-04 18:02:38 -0700964 Load32Disp(TargetReg(kArg1, kRef), 0, tmp);
Dave Allison3d14eb62014-07-10 01:54:57 +0000965 MarkPossibleNullPointerException(info->opt_flags);
966 FreeTemp(tmp);
Dave Allisonf9439142014-03-27 15:10:22 -0700967 }
Brian Carlstrom7940e442013-07-12 13:46:57 -0700968 }
969 return call_state;
970}
971
972/*
973 * May have 0+ arguments (also used for jumbo). Note that
974 * source virtual registers may be in physical registers, so may
975 * need to be flushed to home location before copying. This
976 * applies to arg3 and above (see below).
977 *
978 * Two general strategies:
979 * If < 20 arguments
980 * Pass args 3-18 using vldm/vstm block copy
981 * Pass arg0, arg1 & arg2 in kArg1-kArg3
982 * If 20+ arguments
983 * Pass args arg19+ using memcpy block copy
984 * Pass arg0, arg1 & arg2 in kArg1-kArg3
985 *
986 */
987int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state,
988 LIR** pcrLabel, NextCallInsn next_call_insn,
989 const MethodReference& target_method,
990 uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method,
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700991 InvokeType type, bool skip_this) {
Brian Carlstrom7940e442013-07-12 13:46:57 -0700992 // If we can treat it as non-range (Jumbo ops will use range form)
993 if (info->num_arg_words <= 5)
994 return GenDalvikArgsNoRange(info, call_state, pcrLabel,
995 next_call_insn, target_method, vtable_idx,
996 direct_code, direct_method, type, skip_this);
997 /*
998 * First load the non-register arguments. Both forms expect all
999 * of the source arguments to be in their home frame location, so
1000 * scan the s_reg names and flush any that have been promoted to
1001 * frame backing storage.
1002 */
1003 // Scan the rest of the args - if in phys_reg flush to memory
1004 for (int next_arg = 0; next_arg < info->num_arg_words;) {
1005 RegLocation loc = info->args[next_arg];
1006 if (loc.wide) {
1007 loc = UpdateLocWide(loc);
1008 if ((next_arg >= 2) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001009 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001010 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001011 }
1012 next_arg += 2;
1013 } else {
1014 loc = UpdateLoc(loc);
1015 if ((next_arg >= 3) && (loc.location == kLocPhysReg)) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001016 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Chao-ying Fua77ee512014-07-01 17:43:41 -07001017 Store32Disp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001018 }
1019 next_arg++;
1020 }
1021 }
1022
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001023 // Logic below assumes that Method pointer is at offset zero from SP.
1024 DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0);
1025
1026 // The first 3 arguments are passed via registers.
1027 // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either
1028 // get size of uintptr_t or size of object reference according to model being used.
1029 int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001030 int start_offset = SRegOffset(info->args[3].s_reg_low);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001031 int regs_left_to_pass_via_stack = info->num_arg_words - 3;
1032 DCHECK_GT(regs_left_to_pass_via_stack, 0);
1033
1034 if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) {
1035 // Use vldm/vstm pair using kArg3 as a temp
1036 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1037 direct_code, direct_method, type);
Andreas Gampeccc60262014-07-04 18:02:38 -07001038 OpRegRegImm(kOpAdd, TargetReg(kArg3, kRef), TargetPtrReg(kSp), start_offset);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001039 LIR* ld = nullptr;
1040 {
1041 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Andreas Gampeccc60262014-07-04 18:02:38 -07001042 ld = OpVldm(TargetReg(kArg3, kRef), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001043 }
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001044 // TUNING: loosen barrier
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001045 ld->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001046 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1047 direct_code, direct_method, type);
Andreas Gampeccc60262014-07-04 18:02:38 -07001048 OpRegRegImm(kOpAdd, TargetReg(kArg3, kRef), TargetPtrReg(kSp), 4 /* Method* */ + (3 * 4));
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001049 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1050 direct_code, direct_method, type);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001051 LIR* st = nullptr;
1052 {
1053 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Andreas Gampeccc60262014-07-04 18:02:38 -07001054 st = OpVstm(TargetReg(kArg3, kRef), regs_left_to_pass_via_stack);
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001055 }
1056 st->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001057 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1058 direct_code, direct_method, type);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001059 } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) {
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001060 int current_src_offset = start_offset;
1061 int current_dest_offset = outs_offset;
1062
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001063 // Only davik regs are accessed in this loop; no next_call_insn() calls.
1064 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001065 while (regs_left_to_pass_via_stack > 0) {
1066 // This is based on the knowledge that the stack itself is 16-byte aligned.
1067 bool src_is_16b_aligned = (current_src_offset & 0xF) == 0;
1068 bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0;
1069 size_t bytes_to_move;
1070
1071 /*
1072 * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a
1073 * a 128-bit move because we won't get the chance to try to aligned. If there are more than
1074 * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned.
1075 * We do this because we could potentially do a smaller move to align.
1076 */
1077 if (regs_left_to_pass_via_stack == 4 ||
1078 (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) {
1079 // Moving 128-bits via xmm register.
1080 bytes_to_move = sizeof(uint32_t) * 4;
1081
1082 // Allocate a free xmm temp. Since we are working through the calling sequence,
Mark Mendelle87f9b52014-04-30 14:13:18 -04001083 // we expect to have an xmm temporary available. AllocTempDouble will abort if
1084 // there are no free registers.
buzbee2700f7e2014-03-07 09:46:20 -08001085 RegStorage temp = AllocTempDouble();
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001086
1087 LIR* ld1 = nullptr;
1088 LIR* ld2 = nullptr;
1089 LIR* st1 = nullptr;
1090 LIR* st2 = nullptr;
1091
1092 /*
1093 * The logic is similar for both loads and stores. If we have 16-byte alignment,
1094 * do an aligned move. If we have 8-byte alignment, then do the move in two
1095 * parts. This approach prevents possible cache line splits. Finally, fall back
1096 * to doing an unaligned move. In most cases we likely won't split the cache
1097 * line but we cannot prove it and thus take a conservative approach.
1098 */
1099 bool src_is_8b_aligned = (current_src_offset & 0x7) == 0;
1100 bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0;
1101
1102 if (src_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001103 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001104 } else if (src_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001105 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovLo128FP);
1106 ld2 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001107 kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001108 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001109 ld1 = OpMovRegMem(temp, TargetPtrReg(kSp), current_src_offset, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001110 }
1111
1112 if (dest_is_16b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001113 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovA128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001114 } else if (dest_is_8b_aligned) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001115 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovLo128FP);
1116 st2 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset + (bytes_to_move >> 1),
buzbee2700f7e2014-03-07 09:46:20 -08001117 temp, kMovHi128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001118 } else {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001119 st1 = OpMovMemReg(TargetPtrReg(kSp), current_dest_offset, temp, kMovU128FP);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001120 }
1121
1122 // TODO If we could keep track of aliasing information for memory accesses that are wider
1123 // than 64-bit, we wouldn't need to set up a barrier.
1124 if (ld1 != nullptr) {
1125 if (ld2 != nullptr) {
1126 // For 64-bit load we can actually set up the aliasing information.
1127 AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001128 AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true,
1129 true);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001130 } else {
1131 // Set barrier for 128-bit load.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001132 ld1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001133 }
1134 }
1135 if (st1 != nullptr) {
1136 if (st2 != nullptr) {
1137 // For 64-bit store we can actually set up the aliasing information.
1138 AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true);
Andreas Gampeccc60262014-07-04 18:02:38 -07001139 AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false,
1140 true);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001141 } else {
1142 // Set barrier for 128-bit store.
Vladimir Marko8dea81c2014-06-06 14:50:36 +01001143 st1->u.m.def_mask = &kEncodeAll;
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001144 }
1145 }
1146
1147 // Free the temporary used for the data movement.
buzbee091cc402014-03-31 10:14:40 -07001148 FreeTemp(temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001149 } else {
1150 // Moving 32-bits via general purpose register.
1151 bytes_to_move = sizeof(uint32_t);
1152
1153 // Instead of allocating a new temp, simply reuse one of the registers being used
1154 // for argument passing.
Andreas Gampeccc60262014-07-04 18:02:38 -07001155 RegStorage temp = TargetReg(kArg3, kNotWide);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001156
1157 // Now load the argument VR and store to the outs.
Chao-ying Fua77ee512014-07-01 17:43:41 -07001158 Load32Disp(TargetPtrReg(kSp), current_src_offset, temp);
1159 Store32Disp(TargetPtrReg(kSp), current_dest_offset, temp);
Razvan A Lupusoru2c498d12014-01-29 16:02:57 -08001160 }
1161
1162 current_src_offset += bytes_to_move;
1163 current_dest_offset += bytes_to_move;
1164 regs_left_to_pass_via_stack -= (bytes_to_move >> 2);
1165 }
1166 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001167 // Generate memcpy
Andreas Gampeccc60262014-07-04 18:02:38 -07001168 OpRegRegImm(kOpAdd, TargetReg(kArg0, kRef), TargetPtrReg(kSp), outs_offset);
1169 OpRegRegImm(kOpAdd, TargetReg(kArg1, kRef), TargetPtrReg(kSp), start_offset);
buzbee33ae5582014-06-12 14:56:32 -07001170 if (cu_->target64) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001171 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(8, pMemcpy), TargetReg(kArg0, kRef),
1172 TargetReg(kArg1, kRef), (info->num_arg_words - 3) * 4, false);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001173 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -07001174 CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(4, pMemcpy), TargetReg(kArg0, kRef),
1175 TargetReg(kArg1, kRef), (info->num_arg_words - 3) * 4, false);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001176 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001177 }
1178
1179 call_state = LoadArgRegs(info, call_state, next_call_insn,
1180 target_method, vtable_idx, direct_code, direct_method,
1181 type, skip_this);
1182
1183 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1184 direct_code, direct_method, type);
1185 if (pcrLabel) {
Andreas Gampe5655e842014-06-17 16:36:07 -07001186 if (cu_->compiler_driver->GetCompilerOptions().GetExplicitNullChecks()) {
Andreas Gampeccc60262014-07-04 18:02:38 -07001187 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
Dave Allisonf9439142014-03-27 15:10:22 -07001188 } else {
1189 *pcrLabel = nullptr;
1190 // In lieu of generating a check for kArg1 being null, we need to
1191 // perform a load when doing implicit checks.
Dave Allison3d14eb62014-07-10 01:54:57 +00001192 RegStorage tmp = AllocTemp();
Andreas Gampeccc60262014-07-04 18:02:38 -07001193 Load32Disp(TargetReg(kArg1, kRef), 0, tmp);
Dave Allison3d14eb62014-07-10 01:54:57 +00001194 MarkPossibleNullPointerException(info->opt_flags);
1195 FreeTemp(tmp);
Dave Allisonf9439142014-03-27 15:10:22 -07001196 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001197 }
1198 return call_state;
1199}
1200
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001201RegLocation Mir2Lir::InlineTarget(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001202 RegLocation res;
1203 if (info->result.location == kLocInvalid) {
buzbeea0cd2d72014-06-01 09:33:49 -07001204 res = GetReturn(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001205 } else {
1206 res = info->result;
1207 }
1208 return res;
1209}
1210
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001211RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001212 RegLocation res;
1213 if (info->result.location == kLocInvalid) {
buzbeea0cd2d72014-06-01 09:33:49 -07001214 res = GetReturnWide(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001215 } else {
1216 res = info->result;
1217 }
1218 return res;
1219}
1220
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001221bool Mir2Lir::GenInlinedCharAt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001222 if (cu_->instruction_set == kMips) {
1223 // TODO - add Mips implementation
1224 return false;
1225 }
1226 // Location of reference to data array
1227 int value_offset = mirror::String::ValueOffset().Int32Value();
1228 // Location of count
1229 int count_offset = mirror::String::CountOffset().Int32Value();
1230 // Starting offset within data array
1231 int offset_offset = mirror::String::OffsetOffset().Int32Value();
1232 // Start of char data with array_
1233 int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value();
1234
1235 RegLocation rl_obj = info->args[0];
1236 RegLocation rl_idx = info->args[1];
buzbeea0cd2d72014-06-01 09:33:49 -07001237 rl_obj = LoadValue(rl_obj, kRefReg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001238 // X86 wants to avoid putting a constant index into a register.
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001239 if (!((cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64)&& rl_idx.is_const)) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001240 rl_idx = LoadValue(rl_idx, kCoreReg);
1241 }
buzbee2700f7e2014-03-07 09:46:20 -08001242 RegStorage reg_max;
1243 GenNullCheck(rl_obj.reg, info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001244 bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK));
Vladimir Marko3bc86152014-03-13 14:11:28 +00001245 LIR* range_check_branch = nullptr;
buzbee2700f7e2014-03-07 09:46:20 -08001246 RegStorage reg_off;
1247 RegStorage reg_ptr;
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001248 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001249 reg_off = AllocTemp();
buzbeea0cd2d72014-06-01 09:33:49 -07001250 reg_ptr = AllocTempRef();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001251 if (range_check) {
1252 reg_max = AllocTemp();
buzbee695d13a2014-04-19 13:32:20 -07001253 Load32Disp(rl_obj.reg, count_offset, reg_max);
Dave Allisonb373e092014-02-20 16:06:36 -08001254 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001255 }
buzbee695d13a2014-04-19 13:32:20 -07001256 Load32Disp(rl_obj.reg, offset_offset, reg_off);
Dave Allisonb373e092014-02-20 16:06:36 -08001257 MarkPossibleNullPointerException(info->opt_flags);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001258 LoadRefDisp(rl_obj.reg, value_offset, reg_ptr, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001259 if (range_check) {
Mingyao Yang3a74d152014-04-21 15:39:44 -07001260 // Set up a slow path to allow retry in case of bounds violation */
buzbee2700f7e2014-03-07 09:46:20 -08001261 OpRegReg(kOpCmp, rl_idx.reg, reg_max);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001262 FreeTemp(reg_max);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001263 range_check_branch = OpCondBranch(kCondUge, nullptr);
Brian Carlstrom6f485c62013-07-18 15:35:35 -07001264 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001265 OpRegImm(kOpAdd, reg_ptr, data_offset);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001266 } else {
1267 if (range_check) {
Mark Mendell2b724cb2014-02-06 05:24:20 -08001268 // On x86, we can compare to memory directly
Brian Carlstrom7940e442013-07-12 13:46:57 -07001269 // Set up a launch pad to allow retry in case of bounds violation */
Mark Mendell2b724cb2014-02-06 05:24:20 -08001270 if (rl_idx.is_const) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001271 range_check_branch = OpCmpMemImmBranch(
buzbee2700f7e2014-03-07 09:46:20 -08001272 kCondUlt, RegStorage::InvalidReg(), rl_obj.reg, count_offset,
Dave Allison3d14eb62014-07-10 01:54:57 +00001273 mir_graph_->ConstantValue(rl_idx.orig_sreg), nullptr);
1274 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001275 OpRegMem(kOpCmp, rl_idx.reg, rl_obj.reg, count_offset);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001276 range_check_branch = OpCondBranch(kCondUge, nullptr);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001277 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001278 }
1279 reg_off = AllocTemp();
buzbeea0cd2d72014-06-01 09:33:49 -07001280 reg_ptr = AllocTempRef();
buzbee695d13a2014-04-19 13:32:20 -07001281 Load32Disp(rl_obj.reg, offset_offset, reg_off);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001282 LoadRefDisp(rl_obj.reg, value_offset, reg_ptr, kNotVolatile);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001283 }
Mark Mendell2b724cb2014-02-06 05:24:20 -08001284 if (rl_idx.is_const) {
1285 OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg));
1286 } else {
buzbee2700f7e2014-03-07 09:46:20 -08001287 OpRegReg(kOpAdd, reg_off, rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001288 }
buzbee2700f7e2014-03-07 09:46:20 -08001289 FreeTemp(rl_obj.reg);
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001290 if (rl_idx.location == kLocPhysReg) {
buzbee2700f7e2014-03-07 09:46:20 -08001291 FreeTemp(rl_idx.reg);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001292 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001293 RegLocation rl_dest = InlineTarget(info);
1294 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001295 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
buzbee2700f7e2014-03-07 09:46:20 -08001296 LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg, 1, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001297 } else {
Vladimir Marko3bf7c602014-05-07 14:55:43 +01001298 LoadBaseIndexedDisp(reg_ptr, reg_off, 1, data_offset, rl_result.reg, kUnsignedHalf);
Mark Mendell2b724cb2014-02-06 05:24:20 -08001299 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001300 FreeTemp(reg_off);
1301 FreeTemp(reg_ptr);
1302 StoreValue(rl_dest, rl_result);
1303 if (range_check) {
Vladimir Marko3bc86152014-03-13 14:11:28 +00001304 DCHECK(range_check_branch != nullptr);
1305 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001306 AddIntrinsicSlowPath(info, range_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001307 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001308 return true;
1309}
1310
1311// Generates an inlined String.is_empty or String.length.
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001312bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001313 if (cu_->instruction_set == kMips) {
1314 // TODO - add Mips implementation
1315 return false;
1316 }
1317 // dst = src.length();
1318 RegLocation rl_obj = info->args[0];
buzbeea0cd2d72014-06-01 09:33:49 -07001319 rl_obj = LoadValue(rl_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001320 RegLocation rl_dest = InlineTarget(info);
1321 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001322 GenNullCheck(rl_obj.reg, info->opt_flags);
buzbee695d13a2014-04-19 13:32:20 -07001323 Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg);
Dave Allisonb373e092014-02-20 16:06:36 -08001324 MarkPossibleNullPointerException(info->opt_flags);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001325 if (is_empty) {
1326 // dst = (dst == 0);
1327 if (cu_->instruction_set == kThumb2) {
buzbee2700f7e2014-03-07 09:46:20 -08001328 RegStorage t_reg = AllocTemp();
1329 OpRegReg(kOpNeg, t_reg, rl_result.reg);
1330 OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001331 } else if (cu_->instruction_set == kArm64) {
1332 OpRegImm(kOpSub, rl_result.reg, 1);
1333 OpRegRegImm(kOpLsr, rl_result.reg, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001334 } else {
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001335 DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64);
buzbee2700f7e2014-03-07 09:46:20 -08001336 OpRegImm(kOpSub, rl_result.reg, 1);
1337 OpRegImm(kOpLsr, rl_result.reg, 31);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001338 }
1339 }
1340 StoreValue(rl_dest, rl_result);
1341 return true;
1342}
1343
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001344bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001345 if (cu_->instruction_set == kMips || cu_->instruction_set == kArm64) {
1346 // TODO - add Mips implementation; Enable Arm64.
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001347 return false;
1348 }
1349 RegLocation rl_src_i = info->args[0];
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001350 RegLocation rl_i = (size == k64) ? LoadValueWide(rl_src_i, kCoreReg) : LoadValue(rl_src_i, kCoreReg);
buzbee695d13a2014-04-19 13:32:20 -07001351 RegLocation rl_dest = (size == k64) ? InlineTargetWide(info) : InlineTarget(info); // result reg
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001352 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee695d13a2014-04-19 13:32:20 -07001353 if (size == k64) {
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001354 if (cu_->instruction_set == kArm64 || cu_->instruction_set == kX86_64) {
Serban Constantinescu169489b2014-06-11 16:43:35 +01001355 OpRegReg(kOpRev, rl_result.reg, rl_i.reg);
1356 StoreValueWide(rl_dest, rl_result);
1357 return true;
1358 }
buzbee2700f7e2014-03-07 09:46:20 -08001359 RegStorage r_i_low = rl_i.reg.GetLow();
1360 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Bill Buzbee00e1ec62014-02-27 23:44:13 +00001361 // 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 +00001362 r_i_low = AllocTemp();
buzbee2700f7e2014-03-07 09:46:20 -08001363 OpRegCopy(r_i_low, rl_i.reg);
Vladimir Markof246af22013-11-27 12:30:15 +00001364 }
buzbee2700f7e2014-03-07 09:46:20 -08001365 OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh());
1366 OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low);
1367 if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) {
Vladimir Markof246af22013-11-27 12:30:15 +00001368 FreeTemp(r_i_low);
1369 }
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001370 StoreValueWide(rl_dest, rl_result);
1371 } else {
buzbee695d13a2014-04-19 13:32:20 -07001372 DCHECK(size == k32 || size == kSignedHalf);
1373 OpKind op = (size == k32) ? kOpRev : kOpRevsh;
buzbee2700f7e2014-03-07 09:46:20 -08001374 OpRegReg(op, rl_result.reg, rl_i.reg);
Vladimir Marko6bdf1ff2013-10-29 17:40:46 +00001375 StoreValue(rl_dest, rl_result);
1376 }
1377 return true;
1378}
1379
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001380bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001381 if (cu_->instruction_set == kMips) {
1382 // TODO - add Mips implementation
1383 return false;
1384 }
1385 RegLocation rl_src = info->args[0];
1386 rl_src = LoadValue(rl_src, kCoreReg);
1387 RegLocation rl_dest = InlineTarget(info);
1388 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001389 RegStorage sign_reg = AllocTemp();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001390 // abs(x) = y<=x>>31, (x+y)^y.
buzbee2700f7e2014-03-07 09:46:20 -08001391 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31);
1392 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1393 OpRegReg(kOpXor, rl_result.reg, sign_reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001394 StoreValue(rl_dest, rl_result);
1395 return true;
1396}
1397
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001398bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001399 if (cu_->instruction_set == kMips) {
1400 // TODO - add Mips implementation
1401 return false;
1402 }
Vladimir Markob9823312014-03-20 17:38:43 +00001403 RegLocation rl_src = info->args[0];
1404 rl_src = LoadValueWide(rl_src, kCoreReg);
1405 RegLocation rl_dest = InlineTargetWide(info);
1406 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
1407
1408 // If on x86 or if we would clobber a register needed later, just copy the source first.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001409 if (cu_->instruction_set != kX86_64 &&
1410 (cu_->instruction_set == kX86 ||
1411 rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg())) {
buzbee2700f7e2014-03-07 09:46:20 -08001412 OpRegCopyWide(rl_result.reg, rl_src.reg);
1413 if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() &&
1414 rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() &&
1415 rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() &&
Vladimir Markob9823312014-03-20 17:38:43 +00001416 rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) {
1417 // Reuse source registers to avoid running out of temps.
buzbee2700f7e2014-03-07 09:46:20 -08001418 FreeTemp(rl_src.reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001419 }
1420 rl_src = rl_result;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001421 }
Vladimir Markob9823312014-03-20 17:38:43 +00001422
1423 // abs(x) = y<=x>>31, (x+y)^y.
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001424 RegStorage sign_reg;
1425 if (cu_->instruction_set == kX86_64) {
1426 sign_reg = AllocTempWide();
1427 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 63);
1428 OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg);
1429 OpRegReg(kOpXor, rl_result.reg, sign_reg);
1430 } else {
1431 sign_reg = AllocTemp();
1432 OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31);
1433 OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg);
1434 OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg);
1435 OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg);
1436 OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg);
1437 }
buzbee082833c2014-05-17 23:16:26 -07001438 FreeTemp(sign_reg);
Vladimir Markob9823312014-03-20 17:38:43 +00001439 StoreValueWide(rl_dest, rl_result);
1440 return true;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001441}
1442
Yixin Shoudbb17e32014-02-07 05:09:30 -08001443bool Mir2Lir::GenInlinedAbsFloat(CallInfo* info) {
1444 if (cu_->instruction_set == kMips) {
1445 // TODO - add Mips implementation
1446 return false;
1447 }
1448 RegLocation rl_src = info->args[0];
1449 rl_src = LoadValue(rl_src, kCoreReg);
1450 RegLocation rl_dest = InlineTarget(info);
1451 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
buzbee2700f7e2014-03-07 09:46:20 -08001452 OpRegRegImm(kOpAnd, rl_result.reg, rl_src.reg, 0x7fffffff);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001453 StoreValue(rl_dest, rl_result);
1454 return true;
1455}
1456
Serban Constantinescu23abec92014-07-02 16:13:38 +01001457bool Mir2Lir::GenInlinedReverseBits(CallInfo* info, OpSize size) {
1458 // Currently implemented only for ARM64
1459 return false;
1460}
1461
1462bool Mir2Lir::GenInlinedMinMaxFP(CallInfo* info, bool is_min, bool is_double) {
1463 // Currently implemented only for ARM64
1464 return false;
1465}
1466
Yixin Shoudbb17e32014-02-07 05:09:30 -08001467bool Mir2Lir::GenInlinedAbsDouble(CallInfo* info) {
1468 if (cu_->instruction_set == kMips) {
1469 // TODO - add Mips implementation
1470 return false;
1471 }
1472 RegLocation rl_src = info->args[0];
1473 rl_src = LoadValueWide(rl_src, kCoreReg);
1474 RegLocation rl_dest = InlineTargetWide(info);
1475 RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true);
Serban Constantinescu169489b2014-06-11 16:43:35 +01001476
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001477 OpRegCopyWide(rl_result.reg, rl_src.reg);
1478 OpRegImm(kOpAnd, rl_result.reg.GetHigh(), 0x7fffffff);
Yixin Shoudbb17e32014-02-07 05:09:30 -08001479 StoreValueWide(rl_dest, rl_result);
1480 return true;
1481}
1482
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001483bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001484 if (cu_->instruction_set == kMips) {
1485 // TODO - add Mips implementation
1486 return false;
1487 }
1488 RegLocation rl_src = info->args[0];
1489 RegLocation rl_dest = InlineTarget(info);
1490 StoreValue(rl_dest, rl_src);
1491 return true;
1492}
1493
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001494bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001495 if (cu_->instruction_set == kMips) {
1496 // TODO - add Mips implementation
1497 return false;
1498 }
1499 RegLocation rl_src = info->args[0];
1500 RegLocation rl_dest = InlineTargetWide(info);
1501 StoreValueWide(rl_dest, rl_src);
1502 return true;
1503}
1504
DaniilSokolov70c4f062014-06-24 17:34:00 -07001505bool Mir2Lir::GenInlinedArrayCopyCharArray(CallInfo* info) {
1506 return false;
1507}
1508
1509
Brian Carlstrom7940e442013-07-12 13:46:57 -07001510/*
Vladimir Marko3bc86152014-03-13 14:11:28 +00001511 * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF,
Brian Carlstrom7940e442013-07-12 13:46:57 -07001512 * otherwise bails to standard library code.
1513 */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001514bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001515 if (cu_->instruction_set == kMips) {
1516 // TODO - add Mips implementation
1517 return false;
1518 }
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001519 if (cu_->instruction_set == kX86_64) {
1520 // TODO - add kX86_64 implementation
1521 return false;
1522 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001523 RegLocation rl_obj = info->args[0];
1524 RegLocation rl_char = info->args[1];
1525 if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) {
1526 // Code point beyond 0xFFFF. Punt to the real String.indexOf().
1527 return false;
1528 }
1529
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001530 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001531 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001532 RegStorage reg_ptr = TargetReg(kArg0, kRef);
1533 RegStorage reg_char = TargetReg(kArg1, kNotWide);
1534 RegStorage reg_start = TargetReg(kArg2, kNotWide);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001535
Brian Carlstrom7940e442013-07-12 13:46:57 -07001536 LoadValueDirectFixed(rl_obj, reg_ptr);
1537 LoadValueDirectFixed(rl_char, reg_char);
1538 if (zero_based) {
1539 LoadConstant(reg_start, 0);
1540 } else {
buzbeea44d4f52014-03-05 11:26:39 -08001541 RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf.
Brian Carlstrom7940e442013-07-12 13:46:57 -07001542 LoadValueDirectFixed(rl_start, reg_start);
1543 }
buzbee33ae5582014-06-12 14:56:32 -07001544 RegStorage r_tgt = cu_->target64 ?
Andreas Gampe2f244e92014-05-08 03:35:25 -07001545 LoadHelper(QUICK_ENTRYPOINT_OFFSET(8, pIndexOf)) :
1546 LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pIndexOf));
Dave Allisonf9439142014-03-27 15:10:22 -07001547 GenExplicitNullCheck(reg_ptr, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001548 LIR* high_code_point_branch =
1549 rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001550 // NOTE: not a safepoint
Mark Mendell4028a6c2014-02-19 20:06:20 -08001551 OpReg(kOpBlx, r_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001552 if (!rl_char.is_const) {
1553 // Add the slow path for code points beyond 0xFFFF.
1554 DCHECK(high_code_point_branch != nullptr);
1555 LIR* resume_tgt = NewLIR0(kPseudoTargetLabel);
1556 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Mingyao Yang3a74d152014-04-21 15:39:44 -07001557 AddIntrinsicSlowPath(info, high_code_point_branch, resume_tgt);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001558 } else {
1559 DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0);
1560 DCHECK(high_code_point_branch == nullptr);
1561 }
buzbeea0cd2d72014-06-01 09:33:49 -07001562 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001563 RegLocation rl_dest = InlineTarget(info);
1564 StoreValue(rl_dest, rl_return);
1565 return true;
1566}
1567
1568/* Fast string.compareTo(Ljava/lang/string;)I. */
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001569bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001570 if (cu_->instruction_set == kMips) {
1571 // TODO - add Mips implementation
1572 return false;
1573 }
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001574 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001575 LockCallTemps(); // Using fixed registers
Andreas Gampeccc60262014-07-04 18:02:38 -07001576 RegStorage reg_this = TargetReg(kArg0, kRef);
1577 RegStorage reg_cmp = TargetReg(kArg1, kRef);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001578
1579 RegLocation rl_this = info->args[0];
1580 RegLocation rl_cmp = info->args[1];
1581 LoadValueDirectFixed(rl_this, reg_this);
1582 LoadValueDirectFixed(rl_cmp, reg_cmp);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001583 RegStorage r_tgt;
1584 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
buzbee33ae5582014-06-12 14:56:32 -07001585 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001586 r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(8, pStringCompareTo));
1587 } else {
1588 r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo));
1589 }
1590 } else {
1591 r_tgt = RegStorage::InvalidReg();
1592 }
Dave Allisonf9439142014-03-27 15:10:22 -07001593 GenExplicitNullCheck(reg_this, info->opt_flags);
Vladimir Marko3bc86152014-03-13 14:11:28 +00001594 info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked.
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001595 // TUNING: check if rl_cmp.s_reg_low is already null checked
Vladimir Marko3bc86152014-03-13 14:11:28 +00001596 LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr);
Mingyao Yang3a74d152014-04-21 15:39:44 -07001597 AddIntrinsicSlowPath(info, cmp_null_check_branch);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001598 // NOTE: not a safepoint
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001599 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001600 OpReg(kOpBlx, r_tgt);
1601 } else {
buzbee33ae5582014-06-12 14:56:32 -07001602 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001603 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(8, pStringCompareTo));
1604 } else {
1605 OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo));
1606 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001607 }
buzbeea0cd2d72014-06-01 09:33:49 -07001608 RegLocation rl_return = GetReturn(kCoreReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001609 RegLocation rl_dest = InlineTarget(info);
1610 StoreValue(rl_dest, rl_return);
1611 return true;
1612}
1613
1614bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) {
1615 RegLocation rl_dest = InlineTarget(info);
Andreas Gampe7a949612014-07-08 11:03:59 -07001616
1617 // Early exit if the result is unused.
1618 if (rl_dest.orig_sreg < 0) {
1619 return true;
1620 }
1621
nikolay serdjukc5e4ce12014-06-10 17:07:10 +07001622 RegLocation rl_result = EvalLoc(rl_dest, kRefReg, true);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001623
1624 switch (cu_->instruction_set) {
1625 case kArm:
1626 // Fall-through.
1627 case kThumb2:
1628 // Fall-through.
1629 case kMips:
Chao-ying Fua77ee512014-07-01 17:43:41 -07001630 Load32Disp(TargetPtrReg(kSelf), Thread::PeerOffset<4>().Int32Value(), rl_result.reg);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001631 break;
1632
1633 case kArm64:
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001634 LoadRefDisp(TargetPtrReg(kSelf), Thread::PeerOffset<8>().Int32Value(), rl_result.reg,
1635 kNotVolatile);
Andreas Gampe2f244e92014-05-08 03:35:25 -07001636 break;
1637
1638 case kX86:
1639 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg,
1640 Thread::PeerOffset<4>());
1641 break;
1642
1643 case kX86_64:
1644 reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg,
1645 Thread::PeerOffset<8>());
1646 break;
1647
1648 default:
1649 LOG(FATAL) << "Unexpected isa " << cu_->instruction_set;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001650 }
1651 StoreValue(rl_dest, rl_result);
1652 return true;
1653}
1654
1655bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info,
1656 bool is_long, bool is_volatile) {
1657 if (cu_->instruction_set == kMips) {
1658 // TODO - add Mips implementation
1659 return false;
1660 }
1661 // Unused - RegLocation rl_src_unsafe = info->args[0];
1662 RegLocation rl_src_obj = info->args[1]; // Object
1663 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001664 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Mark Mendell55d0eac2014-02-06 11:02:52 -08001665 RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001666
buzbeea0cd2d72014-06-01 09:33:49 -07001667 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001668 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001669 RegLocation rl_result = EvalLoc(rl_dest, LocToRegClass(rl_dest), true);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001670 if (is_long) {
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001671 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1672 || cu_->instruction_set == kArm64) {
1673 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001674 } else {
1675 RegStorage rl_temp_offset = AllocTemp();
1676 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001677 LoadBaseDisp(rl_temp_offset, 0, rl_result.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001678 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001679 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001680 } else {
Matteo Franchin255e0142014-07-04 13:50:41 +01001681 if (rl_result.ref) {
1682 LoadRefIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0);
1683 } else {
1684 LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32);
1685 }
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001686 }
1687
1688 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001689 GenMemBarrier(kLoadAny);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001690 }
1691
1692 if (is_long) {
1693 StoreValueWide(rl_dest, rl_result);
1694 } else {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001695 StoreValue(rl_dest, rl_result);
1696 }
1697 return true;
1698}
1699
1700bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long,
1701 bool is_object, bool is_volatile, bool is_ordered) {
1702 if (cu_->instruction_set == kMips) {
1703 // TODO - add Mips implementation
1704 return false;
1705 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001706 // Unused - RegLocation rl_src_unsafe = info->args[0];
1707 RegLocation rl_src_obj = info->args[1]; // Object
1708 RegLocation rl_src_offset = info->args[2]; // long low
buzbee2700f7e2014-03-07 09:46:20 -08001709 rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3]
Brian Carlstrom7940e442013-07-12 13:46:57 -07001710 RegLocation rl_src_value = info->args[4]; // value to store
1711 if (is_volatile || is_ordered) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001712 GenMemBarrier(kAnyStore);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001713 }
buzbeea0cd2d72014-06-01 09:33:49 -07001714 RegLocation rl_object = LoadValue(rl_src_obj, kRefReg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001715 RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg);
1716 RegLocation rl_value;
1717 if (is_long) {
1718 rl_value = LoadValueWide(rl_src_value, kCoreReg);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001719 if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64
1720 || cu_->instruction_set == kArm64) {
1721 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k64);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001722 } else {
1723 RegStorage rl_temp_offset = AllocTemp();
1724 OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001725 StoreBaseDisp(rl_temp_offset, 0, rl_value.reg, k64, kNotVolatile);
buzbee091cc402014-03-31 10:14:40 -07001726 FreeTemp(rl_temp_offset);
Mathieu Chartier7c95cef2014-04-02 17:09:17 -07001727 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001728 } else {
buzbeea0cd2d72014-06-01 09:33:49 -07001729 rl_value = LoadValue(rl_src_value);
Matteo Franchin255e0142014-07-04 13:50:41 +01001730 if (rl_value.ref) {
1731 StoreRefIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0);
1732 } else {
1733 StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32);
1734 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001735 }
Mark Mendelldf8ee2e2014-01-27 16:37:47 -08001736
1737 // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard.
buzbee091cc402014-03-31 10:14:40 -07001738 FreeTemp(rl_offset.reg);
Razvan A Lupusoru99ad7232014-02-25 17:41:08 -08001739
Brian Carlstrom7940e442013-07-12 13:46:57 -07001740 if (is_volatile) {
Hans Boehm48f5c472014-06-27 14:50:10 -07001741 // Prevent reordering with a subsequent volatile load.
1742 // May also be needed to address store atomicity issues.
1743 GenMemBarrier(kAnyAny);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001744 }
1745 if (is_object) {
buzbee2700f7e2014-03-07 09:46:20 -08001746 MarkGCCard(rl_value.reg, rl_object.reg);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001747 }
1748 return true;
1749}
1750
Brian Carlstrom2ce745c2013-07-17 17:44:30 -07001751void Mir2Lir::GenInvoke(CallInfo* info) {
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001752 if ((info->opt_flags & MIR_INLINED) != 0) {
1753 // Already inlined but we may still need the null check.
1754 if (info->type != kStatic &&
1755 ((cu_->disable_opt & (1 << kNullCheckElimination)) != 0 ||
1756 (info->opt_flags & MIR_IGNORE_NULL_CHECK) == 0)) {
buzbeea0cd2d72014-06-01 09:33:49 -07001757 RegLocation rl_obj = LoadValue(info->args[0], kRefReg);
Mingyao Yange643a172014-04-08 11:02:52 -07001758 GenNullCheck(rl_obj.reg);
Vladimir Marko9820b7c2014-01-02 16:40:37 +00001759 }
1760 return;
1761 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001762 DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr);
Serban Constantinescu63fe93d2014-06-30 17:10:28 +01001763 if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file)
1764 ->GenIntrinsic(this, info)) {
1765 return;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001766 }
Vladimir Marko3bc86152014-03-13 14:11:28 +00001767 GenInvokeNoInline(info);
1768}
1769
Andreas Gampe2f244e92014-05-08 03:35:25 -07001770template <size_t pointer_size>
1771static LIR* GenInvokeNoInlineCall(Mir2Lir* mir_to_lir, InvokeType type) {
1772 ThreadOffset<pointer_size> trampoline(-1);
1773 switch (type) {
1774 case kInterface:
1775 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeInterfaceTrampolineWithAccessCheck);
1776 break;
1777 case kDirect:
1778 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeDirectTrampolineWithAccessCheck);
1779 break;
1780 case kStatic:
1781 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeStaticTrampolineWithAccessCheck);
1782 break;
1783 case kSuper:
1784 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeSuperTrampolineWithAccessCheck);
1785 break;
1786 case kVirtual:
1787 trampoline = QUICK_ENTRYPOINT_OFFSET(pointer_size, pInvokeVirtualTrampolineWithAccessCheck);
1788 break;
1789 default:
1790 LOG(FATAL) << "Unexpected invoke type";
1791 }
1792 return mir_to_lir->OpThreadMem(kOpBlx, trampoline);
1793}
1794
Vladimir Marko3bc86152014-03-13 14:11:28 +00001795void Mir2Lir::GenInvokeNoInline(CallInfo* info) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001796 int call_state = 0;
1797 LIR* null_ck;
1798 LIR** p_null_ck = NULL;
1799 NextCallInsn next_call_insn;
1800 FlushAllRegs(); /* Everything to home location */
1801 // Explicit register usage
1802 LockCallTemps();
1803
Vladimir Markof096aad2014-01-23 15:51:58 +00001804 const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir);
1805 cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags());
Mark Mendelle87f9b52014-04-30 14:13:18 -04001806 BeginInvoke(info);
Vladimir Markof096aad2014-01-23 15:51:58 +00001807 InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType());
1808 info->type = static_cast<InvokeType>(method_info.GetSharpType());
1809 bool fast_path = method_info.FastPath();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001810 bool skip_this;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001811 if (info->type == kInterface) {
Brian Carlstrom7940e442013-07-12 13:46:57 -07001812 next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck;
Jeff Hao88474b42013-10-23 16:24:40 -07001813 skip_this = fast_path;
Brian Carlstrom7940e442013-07-12 13:46:57 -07001814 } else if (info->type == kDirect) {
1815 if (fast_path) {
1816 p_null_ck = &null_ck;
1817 }
1818 next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP;
1819 skip_this = false;
1820 } else if (info->type == kStatic) {
1821 next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP;
1822 skip_this = false;
1823 } else if (info->type == kSuper) {
1824 DCHECK(!fast_path); // Fast path is a direct call.
1825 next_call_insn = NextSuperCallInsnSP;
1826 skip_this = false;
1827 } else {
1828 DCHECK_EQ(info->type, kVirtual);
1829 next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP;
1830 skip_this = fast_path;
1831 }
Vladimir Markof096aad2014-01-23 15:51:58 +00001832 MethodReference target_method = method_info.GetTargetMethod();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001833 if (!info->is_range) {
1834 call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001835 next_call_insn, target_method, method_info.VTableIndex(),
1836 method_info.DirectCode(), method_info.DirectMethod(),
Brian Carlstrom7940e442013-07-12 13:46:57 -07001837 original_type, skip_this);
1838 } else {
1839 call_state = GenDalvikArgsRange(info, call_state, p_null_ck,
Vladimir Markof096aad2014-01-23 15:51:58 +00001840 next_call_insn, target_method, method_info.VTableIndex(),
1841 method_info.DirectCode(), method_info.DirectMethod(),
1842 original_type, skip_this);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001843 }
1844 // Finish up any of the call sequence not interleaved in arg loading
1845 while (call_state >= 0) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001846 call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(),
1847 method_info.DirectCode(), method_info.DirectMethod(), original_type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001848 }
1849 LIR* call_inst;
Dmitry Petrochenko6a58cb12014-04-02 17:27:59 +07001850 if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) {
Chao-ying Fua77ee512014-07-01 17:43:41 -07001851 call_inst = OpReg(kOpBlx, TargetPtrReg(kInvokeTgt));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001852 } else {
Jeff Hao88474b42013-10-23 16:24:40 -07001853 if (fast_path) {
Vladimir Markof096aad2014-01-23 15:51:58 +00001854 if (method_info.DirectCode() == static_cast<uintptr_t>(-1)) {
Mark Mendell55d0eac2014-02-06 11:02:52 -08001855 // We can have the linker fixup a call relative.
1856 call_inst =
Jeff Hao49161ce2014-03-12 11:05:25 -07001857 reinterpret_cast<X86Mir2Lir*>(this)->CallWithLinkerFixup(target_method, info->type);
Mark Mendell55d0eac2014-02-06 11:02:52 -08001858 } else {
Andreas Gampeccc60262014-07-04 18:02:38 -07001859 call_inst = OpMem(kOpBlx, TargetReg(kArg0, kRef),
Mark Mendell55d0eac2014-02-06 11:02:52 -08001860 mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value());
1861 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001862 } else {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001863 // TODO: Extract?
buzbee33ae5582014-06-12 14:56:32 -07001864 if (cu_->target64) {
Andreas Gampe2f244e92014-05-08 03:35:25 -07001865 call_inst = GenInvokeNoInlineCall<8>(this, info->type);
1866 } else {
Andreas Gampe3ec5da22014-05-12 18:43:28 -07001867 call_inst = GenInvokeNoInlineCall<4>(this, info->type);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001868 }
Brian Carlstrom7940e442013-07-12 13:46:57 -07001869 }
1870 }
Mark Mendelle87f9b52014-04-30 14:13:18 -04001871 EndInvoke(info);
Brian Carlstrom7940e442013-07-12 13:46:57 -07001872 MarkSafepointPC(call_inst);
1873
Vladimir Marko31c2aac2013-12-09 16:31:19 +00001874 ClobberCallerSave();
Brian Carlstrom7940e442013-07-12 13:46:57 -07001875 if (info->result.location != kLocInvalid) {
1876 // We have a following MOVE_RESULT - do it now.
1877 if (info->result.wide) {
buzbeea0cd2d72014-06-01 09:33:49 -07001878 RegLocation ret_loc = GetReturnWide(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001879 StoreValueWide(info->result, ret_loc);
1880 } else {
buzbeea0cd2d72014-06-01 09:33:49 -07001881 RegLocation ret_loc = GetReturn(LocToRegClass(info->result));
Brian Carlstrom7940e442013-07-12 13:46:57 -07001882 StoreValue(info->result, ret_loc);
1883 }
1884 }
1885}
1886
1887} // namespace art