blob: ce9528632e000ea9c24165fe5c742db6d3173970 [file] [log] [blame]
Matteo Franchin43ec8732014-03-31 15:00:14 +01001/*
2 * Copyright (C) 2011 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 "codegen_arm64.h"
18
19#include <inttypes.h>
20
21#include <string>
22
23#include "dex/compiler_internals.h"
24#include "dex/quick/mir_to_lir-inl.h"
25
26namespace art {
27
Vladimir Marko089142c2014-06-05 10:57:05 +010028static constexpr RegStorage core_regs_arr[] =
buzbeeb01bf152014-05-13 15:59:07 -070029 {rs_w0, rs_w1, rs_w2, rs_w3, rs_w4, rs_w5, rs_w6, rs_w7,
30 rs_w8, rs_w9, rs_w10, rs_w11, rs_w12, rs_w13, rs_w14, rs_w15,
31 rs_w16, rs_w17, rs_w18, rs_w19, rs_w20, rs_w21, rs_w22, rs_w23,
32 rs_w24, rs_w25, rs_w26, rs_w27, rs_w28, rs_w29, rs_w30, rs_w31,
33 rs_wzr};
Vladimir Marko089142c2014-06-05 10:57:05 +010034static constexpr RegStorage core64_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010035 {rs_x0, rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7,
36 rs_x8, rs_x9, rs_x10, rs_x11, rs_x12, rs_x13, rs_x14, rs_x15,
37 rs_x16, rs_x17, rs_x18, rs_x19, rs_x20, rs_x21, rs_x22, rs_x23,
Matteo Franchinbc6d1972014-05-13 12:33:28 +010038 rs_x24, rs_x25, rs_x26, rs_x27, rs_x28, rs_x29, rs_x30, rs_x31,
39 rs_xzr};
Vladimir Marko089142c2014-06-05 10:57:05 +010040static constexpr RegStorage sp_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010041 {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7,
42 rs_f8, rs_f9, rs_f10, rs_f11, rs_f12, rs_f13, rs_f14, rs_f15,
43 rs_f16, rs_f17, rs_f18, rs_f19, rs_f20, rs_f21, rs_f22, rs_f23,
44 rs_f24, rs_f25, rs_f26, rs_f27, rs_f28, rs_f29, rs_f30, rs_f31};
Vladimir Marko089142c2014-06-05 10:57:05 +010045static constexpr RegStorage dp_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010046 {rs_d0, rs_d1, rs_d2, rs_d3, rs_d4, rs_d5, rs_d6, rs_d7,
Zheng Xuc8304302014-05-15 17:21:01 +010047 rs_d8, rs_d9, rs_d10, rs_d11, rs_d12, rs_d13, rs_d14, rs_d15,
48 rs_d16, rs_d17, rs_d18, rs_d19, rs_d20, rs_d21, rs_d22, rs_d23,
49 rs_d24, rs_d25, rs_d26, rs_d27, rs_d28, rs_d29, rs_d30, rs_d31};
Vladimir Marko089142c2014-06-05 10:57:05 +010050static constexpr RegStorage reserved_regs_arr[] =
buzbeeb01bf152014-05-13 15:59:07 -070051 {rs_rA32_SUSPEND, rs_rA32_SELF, rs_rA32_SP, rs_rA32_LR, rs_wzr};
Vladimir Marko089142c2014-06-05 10:57:05 +010052static constexpr RegStorage reserved64_regs_arr[] =
Matteo Franchinbc6d1972014-05-13 12:33:28 +010053 {rs_rA64_SUSPEND, rs_rA64_SELF, rs_rA64_SP, rs_rA64_LR, rs_xzr};
54// TUNING: Are there too many temp registers and too less promote target?
Zheng Xuc8304302014-05-15 17:21:01 +010055// This definition need to be matched with runtime.cc, quick entry assembly and JNI compiler
56// Note: we are not able to call to C function directly if it un-match C ABI.
57// Currently, rs_rA64_SELF is not a callee save register which does not match C ABI.
Vladimir Marko089142c2014-06-05 10:57:05 +010058static constexpr RegStorage core_temps_arr[] =
buzbeeb01bf152014-05-13 15:59:07 -070059 {rs_w0, rs_w1, rs_w2, rs_w3, rs_w4, rs_w5, rs_w6, rs_w7,
60 rs_w8, rs_w9, rs_w10, rs_w11, rs_w12, rs_w13, rs_w14, rs_w15, rs_w16,
61 rs_w17};
Vladimir Marko089142c2014-06-05 10:57:05 +010062static constexpr RegStorage core64_temps_arr[] =
Zheng Xuc8304302014-05-15 17:21:01 +010063 {rs_x0, rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7,
64 rs_x8, rs_x9, rs_x10, rs_x11, rs_x12, rs_x13, rs_x14, rs_x15, rs_x16,
65 rs_x17};
Vladimir Marko089142c2014-06-05 10:57:05 +010066static constexpr RegStorage sp_temps_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010067 {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7,
Zheng Xuc8304302014-05-15 17:21:01 +010068 rs_f16, rs_f17, rs_f18, rs_f19, rs_f20, rs_f21, rs_f22, rs_f23,
69 rs_f24, rs_f25, rs_f26, rs_f27, rs_f28, rs_f29, rs_f30, rs_f31};
Vladimir Marko089142c2014-06-05 10:57:05 +010070static constexpr RegStorage dp_temps_arr[] =
Zheng Xuc8304302014-05-15 17:21:01 +010071 {rs_d0, rs_d1, rs_d2, rs_d3, rs_d4, rs_d5, rs_d6, rs_d7,
72 rs_d16, rs_d17, rs_d18, rs_d19, rs_d20, rs_d21, rs_d22, rs_d23,
73 rs_d24, rs_d25, rs_d26, rs_d27, rs_d28, rs_d29, rs_d30, rs_d31};
Matteo Franchin43ec8732014-03-31 15:00:14 +010074
Vladimir Marko089142c2014-06-05 10:57:05 +010075static constexpr ArrayRef<const RegStorage> core_regs(core_regs_arr);
76static constexpr ArrayRef<const RegStorage> core64_regs(core64_regs_arr);
77static constexpr ArrayRef<const RegStorage> sp_regs(sp_regs_arr);
78static constexpr ArrayRef<const RegStorage> dp_regs(dp_regs_arr);
79static constexpr ArrayRef<const RegStorage> reserved_regs(reserved_regs_arr);
80static constexpr ArrayRef<const RegStorage> reserved64_regs(reserved64_regs_arr);
81static constexpr ArrayRef<const RegStorage> core_temps(core_temps_arr);
82static constexpr ArrayRef<const RegStorage> core64_temps(core64_temps_arr);
83static constexpr ArrayRef<const RegStorage> sp_temps(sp_temps_arr);
84static constexpr ArrayRef<const RegStorage> dp_temps(dp_temps_arr);
Matteo Franchin43ec8732014-03-31 15:00:14 +010085
86RegLocation Arm64Mir2Lir::LocCReturn() {
87 return arm_loc_c_return;
88}
89
buzbeea0cd2d72014-06-01 09:33:49 -070090RegLocation Arm64Mir2Lir::LocCReturnRef() {
91 return arm_loc_c_return;
92}
93
Matteo Franchin43ec8732014-03-31 15:00:14 +010094RegLocation Arm64Mir2Lir::LocCReturnWide() {
95 return arm_loc_c_return_wide;
96}
97
98RegLocation Arm64Mir2Lir::LocCReturnFloat() {
99 return arm_loc_c_return_float;
100}
101
102RegLocation Arm64Mir2Lir::LocCReturnDouble() {
103 return arm_loc_c_return_double;
104}
105
106// Return a target-dependent special register.
107RegStorage Arm64Mir2Lir::TargetReg(SpecialTargetRegister reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100108 // TODO(Arm64): this function doesn't work for hard-float ABI.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100109 RegStorage res_reg = RegStorage::InvalidReg();
110 switch (reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100111 case kSelf: res_reg = rs_rA64_SELF; break;
112 case kSuspend: res_reg = rs_rA64_SUSPEND; break;
113 case kLr: res_reg = rs_rA64_LR; break;
114 case kPc: res_reg = RegStorage::InvalidReg(); break;
115 case kSp: res_reg = rs_rA64_SP; break;
116 case kArg0: res_reg = rs_x0; break;
117 case kArg1: res_reg = rs_x1; break;
118 case kArg2: res_reg = rs_x2; break;
119 case kArg3: res_reg = rs_x3; break;
120 case kFArg0: res_reg = rs_f0; break;
121 case kFArg1: res_reg = rs_f1; break;
122 case kFArg2: res_reg = rs_f2; break;
123 case kFArg3: res_reg = rs_f3; break;
124 case kRet0: res_reg = rs_x0; break;
125 case kRet1: res_reg = rs_x0; break;
126 case kInvokeTgt: res_reg = rs_rA64_LR; break;
127 case kHiddenArg: res_reg = rs_x12; break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100128 case kHiddenFpArg: res_reg = RegStorage::InvalidReg(); break;
129 case kCount: res_reg = RegStorage::InvalidReg(); break;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700130 default: res_reg = RegStorage::InvalidReg();
Matteo Franchin43ec8732014-03-31 15:00:14 +0100131 }
132 return res_reg;
133}
134
135RegStorage Arm64Mir2Lir::GetArgMappingToPhysicalReg(int arg_num) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100136 return RegStorage::InvalidReg();
Matteo Franchin43ec8732014-03-31 15:00:14 +0100137}
138
139/*
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100140 * Decode the register id. This routine makes assumptions on the encoding made by RegStorage.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100141 */
142uint64_t Arm64Mir2Lir::GetRegMaskCommon(RegStorage reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100143 // TODO(Arm64): this function depends too much on the internal RegStorage encoding. Refactor.
144
145 int reg_raw = reg.GetRawBits();
146 // Check if the shape mask is zero (i.e. invalid).
147 if (UNLIKELY(reg == rs_wzr || reg == rs_xzr)) {
148 // The zero register is not a true register. It is just an immediate zero.
149 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100150 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100151
152 return UINT64_C(1) << (reg_raw & RegStorage::kRegTypeMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100153}
154
155uint64_t Arm64Mir2Lir::GetPCUseDefEncoding() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100156 LOG(FATAL) << "Unexpected call to GetPCUseDefEncoding for Arm64";
157 return 0ULL;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100158}
159
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100160// Arm64 specific setup. TODO: inline?:
Matteo Franchin43ec8732014-03-31 15:00:14 +0100161void Arm64Mir2Lir::SetupTargetResourceMasks(LIR* lir, uint64_t flags) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100162 DCHECK_EQ(cu_->instruction_set, kArm64);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100163 DCHECK(!lir->flags.use_def_invalid);
164
Matteo Franchin43ec8732014-03-31 15:00:14 +0100165 // These flags are somewhat uncommon - bypass if we can.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100166 if ((flags & (REG_DEF_SP | REG_USE_SP | REG_DEF_LR)) != 0) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100167 if (flags & REG_DEF_SP) {
168 lir->u.m.def_mask |= ENCODE_ARM_REG_SP;
169 }
170
171 if (flags & REG_USE_SP) {
172 lir->u.m.use_mask |= ENCODE_ARM_REG_SP;
173 }
174
Matteo Franchin43ec8732014-03-31 15:00:14 +0100175 if (flags & REG_DEF_LR) {
176 lir->u.m.def_mask |= ENCODE_ARM_REG_LR;
177 }
178 }
179}
180
181ArmConditionCode Arm64Mir2Lir::ArmConditionEncoding(ConditionCode ccode) {
182 ArmConditionCode res;
183 switch (ccode) {
184 case kCondEq: res = kArmCondEq; break;
185 case kCondNe: res = kArmCondNe; break;
186 case kCondCs: res = kArmCondCs; break;
187 case kCondCc: res = kArmCondCc; break;
188 case kCondUlt: res = kArmCondCc; break;
189 case kCondUge: res = kArmCondCs; break;
190 case kCondMi: res = kArmCondMi; break;
191 case kCondPl: res = kArmCondPl; break;
192 case kCondVs: res = kArmCondVs; break;
193 case kCondVc: res = kArmCondVc; break;
194 case kCondHi: res = kArmCondHi; break;
195 case kCondLs: res = kArmCondLs; break;
196 case kCondGe: res = kArmCondGe; break;
197 case kCondLt: res = kArmCondLt; break;
198 case kCondGt: res = kArmCondGt; break;
199 case kCondLe: res = kArmCondLe; break;
200 case kCondAl: res = kArmCondAl; break;
201 case kCondNv: res = kArmCondNv; break;
202 default:
203 LOG(FATAL) << "Bad condition code " << ccode;
204 res = static_cast<ArmConditionCode>(0); // Quiet gcc
205 }
206 return res;
207}
208
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100209static const char *shift_names[4] = {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100210 "lsl",
211 "lsr",
212 "asr",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100213 "ror"
214};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100215
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100216static const char* extend_names[8] = {
217 "uxtb",
218 "uxth",
219 "uxtw",
220 "uxtx",
221 "sxtb",
222 "sxth",
223 "sxtw",
224 "sxtx",
225};
226
227/* Decode and print a register extension (e.g. ", uxtb #1") */
228static void DecodeRegExtendOrShift(int operand, char *buf, size_t buf_size) {
229 if ((operand & (1 << 6)) == 0) {
230 const char *shift_name = shift_names[(operand >> 7) & 0x3];
231 int amount = operand & 0x3f;
232 snprintf(buf, buf_size, ", %s #%d", shift_name, amount);
233 } else {
234 const char *extend_name = extend_names[(operand >> 3) & 0x7];
235 int amount = operand & 0x7;
236 if (amount == 0) {
237 snprintf(buf, buf_size, ", %s", extend_name);
238 } else {
239 snprintf(buf, buf_size, ", %s #%d", extend_name, amount);
240 }
241 }
242}
243
244#define BIT_MASK(w) ((UINT64_C(1) << (w)) - UINT64_C(1))
245
246static uint64_t RotateRight(uint64_t value, unsigned rotate, unsigned width) {
247 DCHECK_LE(width, 64U);
248 rotate &= 63;
249 value = value & BIT_MASK(width);
250 return ((value & BIT_MASK(rotate)) << (width - rotate)) | (value >> rotate);
251}
252
253static uint64_t RepeatBitsAcrossReg(bool is_wide, uint64_t value, unsigned width) {
254 unsigned i;
255 unsigned reg_size = (is_wide) ? 64 : 32;
256 uint64_t result = value & BIT_MASK(width);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100257 for (i = width; i < reg_size; i *= 2) {
258 result |= (result << i);
259 }
260 DCHECK_EQ(i, reg_size);
261 return result;
262}
263
264/**
265 * @brief Decode an immediate in the form required by logical instructions.
266 *
267 * @param is_wide Whether @p value encodes a 64-bit (as opposed to 32-bit) immediate.
268 * @param value The encoded logical immediates that is to be decoded.
269 * @return The decoded logical immediate.
270 * @note This is the inverse of Arm64Mir2Lir::EncodeLogicalImmediate().
271 */
272uint64_t Arm64Mir2Lir::DecodeLogicalImmediate(bool is_wide, int value) {
273 unsigned n = (value >> 12) & 0x01;
274 unsigned imm_r = (value >> 6) & 0x3f;
275 unsigned imm_s = (value >> 0) & 0x3f;
276
277 // An integer is constructed from the n, imm_s and imm_r bits according to
278 // the following table:
279 //
280 // N imms immr size S R
281 // 1 ssssss rrrrrr 64 UInt(ssssss) UInt(rrrrrr)
282 // 0 0sssss xrrrrr 32 UInt(sssss) UInt(rrrrr)
283 // 0 10ssss xxrrrr 16 UInt(ssss) UInt(rrrr)
284 // 0 110sss xxxrrr 8 UInt(sss) UInt(rrr)
285 // 0 1110ss xxxxrr 4 UInt(ss) UInt(rr)
286 // 0 11110s xxxxxr 2 UInt(s) UInt(r)
287 // (s bits must not be all set)
288 //
289 // A pattern is constructed of size bits, where the least significant S+1
290 // bits are set. The pattern is rotated right by R, and repeated across a
291 // 32 or 64-bit value, depending on destination register width.
292
293 if (n == 1) {
294 DCHECK_NE(imm_s, 0x3fU);
295 uint64_t bits = BIT_MASK(imm_s + 1);
296 return RotateRight(bits, imm_r, 64);
297 } else {
298 DCHECK_NE((imm_s >> 1), 0x1fU);
299 for (unsigned width = 0x20; width >= 0x2; width >>= 1) {
300 if ((imm_s & width) == 0) {
301 unsigned mask = (unsigned)(width - 1);
302 DCHECK_NE((imm_s & mask), mask);
303 uint64_t bits = BIT_MASK((imm_s & mask) + 1);
304 return RepeatBitsAcrossReg(is_wide, RotateRight(bits, imm_r & mask, width), width);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100305 }
306 }
307 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100308 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100309}
310
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100311/**
312 * @brief Decode an 8-bit single point number encoded with EncodeImmSingle().
313 */
314static float DecodeImmSingle(uint8_t small_float) {
315 int mantissa = (small_float & 0x0f) + 0x10;
316 int sign = ((small_float & 0x80) == 0) ? 1 : -1;
317 float signed_mantissa = static_cast<float>(sign*mantissa);
318 int exponent = (((small_float >> 4) & 0x7) + 4) & 0x7;
319 return signed_mantissa*static_cast<float>(1 << exponent)*0.0078125f;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100320}
321
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100322static const char* cc_names[] = {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
323 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100324/*
325 * Interpret a format string and build a string no longer than size
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100326 * See format key in assemble_arm64.cc.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100327 */
328std::string Arm64Mir2Lir::BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) {
329 std::string buf;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100330 const char* fmt_end = &fmt[strlen(fmt)];
331 char tbuf[256];
332 const char* name;
333 char nc;
334 while (fmt < fmt_end) {
335 int operand;
336 if (*fmt == '!') {
337 fmt++;
338 DCHECK_LT(fmt, fmt_end);
339 nc = *fmt++;
340 if (nc == '!') {
341 strcpy(tbuf, "!");
342 } else {
343 DCHECK_LT(fmt, fmt_end);
344 DCHECK_LT(static_cast<unsigned>(nc-'0'), 4U);
345 operand = lir->operands[nc-'0'];
346 switch (*fmt++) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100347 case 'e': {
348 // Omit ", uxtw #0" in strings like "add w0, w1, w3, uxtw #0" and
349 // ", uxtx #0" in strings like "add x0, x1, x3, uxtx #0"
350 int omittable = ((IS_WIDE(lir->opcode)) ? EncodeExtend(kA64Uxtw, 0) :
351 EncodeExtend(kA64Uxtw, 0));
352 if (LIKELY(operand == omittable)) {
353 strcpy(tbuf, "");
354 } else {
355 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
356 }
357 }
358 break;
359 case 'o':
360 // Omit ", lsl #0"
361 if (LIKELY(operand == EncodeShift(kA64Lsl, 0))) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100362 strcpy(tbuf, "");
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100363 } else {
364 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100365 }
366 break;
367 case 'B':
368 switch (operand) {
369 case kSY:
370 name = "sy";
371 break;
372 case kST:
373 name = "st";
374 break;
375 case kISH:
376 name = "ish";
377 break;
378 case kISHST:
379 name = "ishst";
380 break;
381 case kNSH:
382 name = "nsh";
383 break;
384 case kNSHST:
385 name = "shst";
386 break;
387 default:
388 name = "DecodeError2";
389 break;
390 }
391 strcpy(tbuf, name);
392 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100393 case 's':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100394 snprintf(tbuf, arraysize(tbuf), "s%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100395 break;
396 case 'S':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100397 snprintf(tbuf, arraysize(tbuf), "d%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100398 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100399 case 'f':
400 snprintf(tbuf, arraysize(tbuf), "%c%d", (IS_FWIDE(lir->opcode)) ? 'd' : 's',
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100401 operand & RegStorage::kRegNumMask);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100402 break;
403 case 'l': {
404 bool is_wide = IS_WIDE(lir->opcode);
405 uint64_t imm = DecodeLogicalImmediate(is_wide, operand);
406 snprintf(tbuf, arraysize(tbuf), "%" PRId64 " (%#" PRIx64 ")", imm, imm);
407 }
408 break;
409 case 'I':
410 snprintf(tbuf, arraysize(tbuf), "%f", DecodeImmSingle(operand));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100411 break;
412 case 'M':
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100413 if (LIKELY(operand == 0))
414 strcpy(tbuf, "");
415 else
416 snprintf(tbuf, arraysize(tbuf), ", lsl #%d", 16*operand);
417 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100418 case 'd':
419 snprintf(tbuf, arraysize(tbuf), "%d", operand);
420 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100421 case 'w':
422 if (LIKELY(operand != rwzr))
423 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
424 else
425 strcpy(tbuf, "wzr");
426 break;
427 case 'W':
428 if (LIKELY(operand != rwsp))
429 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
430 else
431 strcpy(tbuf, "wsp");
432 break;
433 case 'x':
434 if (LIKELY(operand != rxzr))
435 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
436 else
437 strcpy(tbuf, "xzr");
438 break;
439 case 'X':
440 if (LIKELY(operand != rsp))
441 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
442 else
443 strcpy(tbuf, "sp");
444 break;
445 case 'D':
446 snprintf(tbuf, arraysize(tbuf), "%d", operand*((IS_WIDE(lir->opcode)) ? 8 : 4));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100447 break;
448 case 'E':
449 snprintf(tbuf, arraysize(tbuf), "%d", operand*4);
450 break;
451 case 'F':
452 snprintf(tbuf, arraysize(tbuf), "%d", operand*2);
453 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100454 case 'G':
455 if (LIKELY(operand == 0))
456 strcpy(tbuf, "");
457 else
458 strcpy(tbuf, (IS_WIDE(lir->opcode)) ? ", lsl #3" : ", lsl #2");
459 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100460 case 'c':
461 strcpy(tbuf, cc_names[operand]);
462 break;
463 case 't':
464 snprintf(tbuf, arraysize(tbuf), "0x%08" PRIxPTR " (L%p)",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100465 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + (operand << 2),
Matteo Franchin43ec8732014-03-31 15:00:14 +0100466 lir->target);
467 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100468 case 'r': {
469 bool is_wide = IS_WIDE(lir->opcode);
470 if (LIKELY(operand != rwzr && operand != rxzr)) {
471 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
472 operand & RegStorage::kRegNumMask);
473 } else {
474 strcpy(tbuf, (is_wide) ? "xzr" : "wzr");
475 }
476 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100477 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100478 case 'R': {
479 bool is_wide = IS_WIDE(lir->opcode);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100480 if (LIKELY(operand != rwsp && operand != rsp)) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100481 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
482 operand & RegStorage::kRegNumMask);
483 } else {
484 strcpy(tbuf, (is_wide) ? "sp" : "wsp");
485 }
486 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100487 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100488 case 'p':
489 snprintf(tbuf, arraysize(tbuf), ".+%d (addr %#" PRIxPTR ")", 4*operand,
490 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + 4*operand);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100491 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100492 case 'T':
493 if (LIKELY(operand == 0))
494 strcpy(tbuf, "");
495 else if (operand == 1)
496 strcpy(tbuf, ", lsl #12");
497 else
498 strcpy(tbuf, ", DecodeError3");
Matteo Franchin43ec8732014-03-31 15:00:14 +0100499 break;
500 default:
501 strcpy(tbuf, "DecodeError1");
502 break;
503 }
504 buf += tbuf;
505 }
506 } else {
507 buf += *fmt++;
508 }
509 }
510 return buf;
511}
512
513void Arm64Mir2Lir::DumpResourceMask(LIR* arm_lir, uint64_t mask, const char* prefix) {
514 char buf[256];
515 buf[0] = 0;
516
517 if (mask == ENCODE_ALL) {
518 strcpy(buf, "all");
519 } else {
520 char num[8];
521 int i;
522
523 for (i = 0; i < kArmRegEnd; i++) {
524 if (mask & (1ULL << i)) {
525 snprintf(num, arraysize(num), "%d ", i);
526 strcat(buf, num);
527 }
528 }
529
530 if (mask & ENCODE_CCODE) {
531 strcat(buf, "cc ");
532 }
533 if (mask & ENCODE_FP_STATUS) {
534 strcat(buf, "fpcc ");
535 }
536
537 /* Memory bits */
538 if (arm_lir && (mask & ENCODE_DALVIK_REG)) {
539 snprintf(buf + strlen(buf), arraysize(buf) - strlen(buf), "dr%d%s",
540 DECODE_ALIAS_INFO_REG(arm_lir->flags.alias_info),
541 DECODE_ALIAS_INFO_WIDE(arm_lir->flags.alias_info) ? "(+1)" : "");
542 }
543 if (mask & ENCODE_LITERAL) {
544 strcat(buf, "lit ");
545 }
546
547 if (mask & ENCODE_HEAP_REF) {
548 strcat(buf, "heap ");
549 }
550 if (mask & ENCODE_MUST_NOT_ALIAS) {
551 strcat(buf, "noalias ");
552 }
553 }
554 if (buf[0]) {
555 LOG(INFO) << prefix << ": " << buf;
556 }
557}
558
559bool Arm64Mir2Lir::IsUnconditionalBranch(LIR* lir) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100560 return (lir->opcode == kA64B1t);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100561}
562
Vladimir Marko674744e2014-04-24 15:18:26 +0100563bool Arm64Mir2Lir::SupportsVolatileLoadStore(OpSize size) {
564 return true;
565}
566
567RegisterClass Arm64Mir2Lir::RegClassForFieldLoadStore(OpSize size, bool is_volatile) {
568 if (UNLIKELY(is_volatile)) {
569 // On arm64, fp register load/store is atomic only for single bytes.
570 if (size != kSignedByte && size != kUnsignedByte) {
buzbeea0cd2d72014-06-01 09:33:49 -0700571 return (size == kReference) ? kRefReg : kCoreReg;
Vladimir Marko674744e2014-04-24 15:18:26 +0100572 }
573 }
574 return RegClassBySize(size);
575}
576
Matteo Franchin43ec8732014-03-31 15:00:14 +0100577Arm64Mir2Lir::Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena)
578 : Mir2Lir(cu, mir_graph, arena) {
579 // Sanity check - make sure encoding map lines up.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100580 for (int i = 0; i < kA64Last; i++) {
581 if (UNWIDE(Arm64Mir2Lir::EncodingMap[i].opcode) != i) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100582 LOG(FATAL) << "Encoding order for " << Arm64Mir2Lir::EncodingMap[i].name
583 << " is wrong: expecting " << i << ", seeing "
584 << static_cast<int>(Arm64Mir2Lir::EncodingMap[i].opcode);
585 }
586 }
587}
588
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100589Mir2Lir* Arm64CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
590 ArenaAllocator* const arena) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100591 return new Arm64Mir2Lir(cu, mir_graph, arena);
592}
593
Matteo Franchin43ec8732014-03-31 15:00:14 +0100594void Arm64Mir2Lir::CompilerInitializeRegAlloc() {
buzbeeb01bf152014-05-13 15:59:07 -0700595 reg_pool_ = new (arena_) RegisterPool(this, arena_, core_regs, core64_regs, sp_regs, dp_regs,
596 reserved_regs, reserved64_regs, core_temps, core64_temps,
597 sp_temps, dp_temps);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100598
599 // Target-specific adjustments.
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100600 // Alias single precision float registers to corresponding double registers.
601 GrowableArray<RegisterInfo*>::Iterator fp_it(&reg_pool_->sp_regs_);
602 for (RegisterInfo* info = fp_it.Next(); info != nullptr; info = fp_it.Next()) {
603 int fp_reg_num = info->GetReg().GetRegNum();
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100604 RegStorage dp_reg = RegStorage::FloatSolo64(fp_reg_num);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100605 RegisterInfo* dp_reg_info = GetRegInfo(dp_reg);
606 // Double precision register's master storage should refer to itself.
607 DCHECK_EQ(dp_reg_info, dp_reg_info->Master());
608 // Redirect single precision's master storage to master.
609 info->SetMaster(dp_reg_info);
610 // Singles should show a single 32-bit mask bit, at first referring to the low half.
611 DCHECK_EQ(info->StorageMask(), 0x1U);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100612 }
613
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100614 // Alias 32bit W registers to corresponding 64bit X registers.
615 GrowableArray<RegisterInfo*>::Iterator w_it(&reg_pool_->core_regs_);
616 for (RegisterInfo* info = w_it.Next(); info != nullptr; info = w_it.Next()) {
617 int x_reg_num = info->GetReg().GetRegNum();
618 RegStorage x_reg = RegStorage::Solo64(x_reg_num);
619 RegisterInfo* x_reg_info = GetRegInfo(x_reg);
620 // 64bit X register's master storage should refer to itself.
621 DCHECK_EQ(x_reg_info, x_reg_info->Master());
622 // Redirect 32bit W master storage to 64bit X.
623 info->SetMaster(x_reg_info);
624 // 32bit W should show a single 32-bit mask bit, at first referring to the low half.
625 DCHECK_EQ(info->StorageMask(), 0x1U);
626 }
627
Matteo Franchin43ec8732014-03-31 15:00:14 +0100628 // Don't start allocating temps at r0/s0/d0 or you may clobber return regs in early-exit methods.
629 // TODO: adjust when we roll to hard float calling convention.
630 reg_pool_->next_core_reg_ = 2;
631 reg_pool_->next_sp_reg_ = 0;
632 reg_pool_->next_dp_reg_ = 0;
633}
634
Matteo Franchin43ec8732014-03-31 15:00:14 +0100635/*
636 * TUNING: is true leaf? Can't just use METHOD_IS_LEAF to determine as some
637 * instructions might call out to C/assembly helper functions. Until
638 * machinery is in place, always spill lr.
639 */
640
641void Arm64Mir2Lir::AdjustSpillMask() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100642 core_spill_mask_ |= (1 << rs_rA64_LR.GetRegNum());
Matteo Franchin43ec8732014-03-31 15:00:14 +0100643 num_core_spills_++;
644}
645
646/*
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100647 * Mark a callee-save fp register as promoted.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100648 */
649void Arm64Mir2Lir::MarkPreservedSingle(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100650 DCHECK(reg.IsFloat());
651 int adjusted_reg_num = reg.GetRegNum() - A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100652 // Ensure fp_vmap_table is large enough
653 int table_size = fp_vmap_table_.size();
654 for (int i = table_size; i < (adjusted_reg_num + 1); i++) {
655 fp_vmap_table_.push_back(INVALID_VREG);
656 }
657 // Add the current mapping
658 fp_vmap_table_[adjusted_reg_num] = v_reg;
659 // Size of fp_vmap_table is high-water mark, use to set mask
660 num_fp_spills_ = fp_vmap_table_.size();
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100661 fp_spill_mask_ = ((1 << num_fp_spills_) - 1) << A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100662}
663
664void Arm64Mir2Lir::MarkPreservedDouble(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100665 DCHECK(reg.IsDouble());
666 MarkPreservedSingle(v_reg, reg);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100667}
668
669/* Clobber all regs that might be used by an external C call */
670void Arm64Mir2Lir::ClobberCallerSave() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100671 Clobber(rs_x0);
672 Clobber(rs_x1);
673 Clobber(rs_x2);
674 Clobber(rs_x3);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100675 Clobber(rs_x4);
676 Clobber(rs_x5);
677 Clobber(rs_x6);
678 Clobber(rs_x7);
679 Clobber(rs_x8);
680 Clobber(rs_x9);
681 Clobber(rs_x10);
682 Clobber(rs_x11);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100683 Clobber(rs_x12);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100684 Clobber(rs_x13);
685 Clobber(rs_x14);
686 Clobber(rs_x15);
687 Clobber(rs_x16);
688 Clobber(rs_x17);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100689 Clobber(rs_x30);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100690
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100691 Clobber(rs_f0);
692 Clobber(rs_f1);
693 Clobber(rs_f2);
694 Clobber(rs_f3);
695 Clobber(rs_f4);
696 Clobber(rs_f5);
697 Clobber(rs_f6);
698 Clobber(rs_f7);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100699 Clobber(rs_f16);
700 Clobber(rs_f17);
701 Clobber(rs_f18);
702 Clobber(rs_f19);
703 Clobber(rs_f20);
704 Clobber(rs_f21);
705 Clobber(rs_f22);
706 Clobber(rs_f23);
707 Clobber(rs_f24);
708 Clobber(rs_f25);
709 Clobber(rs_f26);
710 Clobber(rs_f27);
711 Clobber(rs_f28);
712 Clobber(rs_f29);
713 Clobber(rs_f30);
714 Clobber(rs_f31);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100715}
716
717RegLocation Arm64Mir2Lir::GetReturnWideAlt() {
718 RegLocation res = LocCReturnWide();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100719 res.reg.SetReg(rx2);
720 res.reg.SetHighReg(rx3);
721 Clobber(rs_x2);
722 Clobber(rs_x3);
723 MarkInUse(rs_x2);
724 MarkInUse(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100725 MarkWide(res.reg);
726 return res;
727}
728
729RegLocation Arm64Mir2Lir::GetReturnAlt() {
730 RegLocation res = LocCReturn();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100731 res.reg.SetReg(rx1);
732 Clobber(rs_x1);
733 MarkInUse(rs_x1);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100734 return res;
735}
736
737/* To be used when explicitly managing register use */
738void Arm64Mir2Lir::LockCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100739 LockTemp(rs_x0);
740 LockTemp(rs_x1);
741 LockTemp(rs_x2);
742 LockTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100743}
744
745/* To be used when explicitly managing register use */
746void Arm64Mir2Lir::FreeCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100747 FreeTemp(rs_x0);
748 FreeTemp(rs_x1);
749 FreeTemp(rs_x2);
750 FreeTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100751}
752
Andreas Gampe2f244e92014-05-08 03:35:25 -0700753RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<4> offset) {
754 UNIMPLEMENTED(FATAL) << "Should not be called.";
755 return RegStorage::InvalidReg();
756}
757
758RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<8> offset) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100759 // TODO(Arm64): use LoadWordDisp instead.
760 // e.g. LoadWordDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR);
761 LoadBaseDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR, k64);
762 return rs_rA64_LR;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100763}
764
765LIR* Arm64Mir2Lir::CheckSuspendUsingLoad() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100766 RegStorage tmp = rs_x0;
Andreas Gampe2f244e92014-05-08 03:35:25 -0700767 LoadWordDisp(rs_rA64_SELF, Thread::ThreadSuspendTriggerOffset<8>().Int32Value(), tmp);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100768 LIR* load2 = LoadWordDisp(tmp, 0, tmp);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100769 return load2;
770}
771
772uint64_t Arm64Mir2Lir::GetTargetInstFlags(int opcode) {
773 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100774 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].flags;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100775}
776
777const char* Arm64Mir2Lir::GetTargetInstName(int opcode) {
778 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100779 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].name;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100780}
781
782const char* Arm64Mir2Lir::GetTargetInstFmt(int opcode) {
783 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100784 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].fmt;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100785}
786
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100787// TODO(Arm64): reuse info in QuickArgumentVisitor?
788static RegStorage GetArgPhysicalReg(RegLocation* loc, int* num_gpr_used, int* num_fpr_used,
789 OpSize* op_size) {
790 if (loc->fp) {
791 int n = *num_fpr_used;
792 if (n < 8) {
793 *num_fpr_used = n + 1;
794 RegStorage::RegStorageKind reg_kind;
795 if (loc->wide) {
796 *op_size = kDouble;
797 reg_kind = RegStorage::k64BitSolo;
798 } else {
799 *op_size = kSingle;
800 reg_kind = RegStorage::k32BitSolo;
801 }
802 return RegStorage(RegStorage::kValid | reg_kind | RegStorage::kFloatingPoint | n);
803 }
804 } else {
805 int n = *num_gpr_used;
806 if (n < 7) {
807 *num_gpr_used = n + 1;
808 if (loc->wide) {
809 *op_size = k64;
810 return RegStorage::Solo64(n);
811 } else {
812 *op_size = k32;
813 return RegStorage::Solo32(n);
814 }
815 }
816 }
817
818 return RegStorage::InvalidReg();
819}
820
821/*
822 * If there are any ins passed in registers that have not been promoted
823 * to a callee-save register, flush them to the frame. Perform initial
824 * assignment of promoted arguments.
825 *
826 * ArgLocs is an array of location records describing the incoming arguments
827 * with one location record per word of argument.
828 */
829void Arm64Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
830 int num_gpr_used = 1;
831 int num_fpr_used = 0;
832
833 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800834 * Dummy up a RegLocation for the incoming StackReference<mirror::ArtMethod>
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100835 * It will attempt to keep kArg0 live (or copy it to home location
836 * if promoted).
837 */
838 RegLocation rl_src = rl_method;
839 rl_src.location = kLocPhysReg;
840 rl_src.reg = TargetReg(kArg0);
841 rl_src.home = false;
842 MarkLive(rl_src);
Zheng Xu511c8a62014-06-03 16:22:23 +0800843 StoreValue(rl_method, rl_src);
844 // If Method* has been promoted, explicitly flush
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100845 if (rl_method.location == kLocPhysReg) {
Zheng Xu511c8a62014-06-03 16:22:23 +0800846 StoreRefDisp(TargetReg(kSp), 0, TargetReg(kArg0));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100847 }
848
849 if (cu_->num_ins == 0) {
850 return;
851 }
852
853 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
854 for (int i = 0; i < cu_->num_ins; i++) {
855 PromotionMap* v_map = &promotion_map_[start_vreg + i];
856 RegLocation* t_loc = &ArgLocs[i];
857 OpSize op_size;
858 RegStorage reg = GetArgPhysicalReg(t_loc, &num_gpr_used, &num_fpr_used, &op_size);
859
860 if (reg.Valid()) {
861 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
862 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
863 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
864 OpRegCopy(RegStorage::Solo32(v_map->FpReg), reg);
865 } else {
866 StoreBaseDisp(TargetReg(kSp), SRegOffset(start_vreg + i), reg, op_size);
867 if (reg.Is64Bit()) {
868 if (SRegOffset(start_vreg + i) + 4 != SRegOffset(start_vreg + i + 1)) {
869 LOG(FATAL) << "64 bit value stored in non-consecutive 4 bytes slots";
870 }
871 i += 1;
872 }
873 }
874 } else {
875 // If arriving in frame & promoted
876 if (v_map->core_location == kLocPhysReg) {
877 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i),
878 RegStorage::Solo32(v_map->core_reg));
879 }
880 if (v_map->fp_location == kLocPhysReg) {
881 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg));
882 }
883 }
884 }
885}
886
887int Arm64Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
888 NextCallInsn next_call_insn,
889 const MethodReference& target_method,
890 uint32_t vtable_idx, uintptr_t direct_code,
891 uintptr_t direct_method, InvokeType type, bool skip_this) {
892 int last_arg_reg = TargetReg(kArg3).GetReg();
893 int next_reg = TargetReg(kArg1).GetReg();
894 int next_arg = 0;
895 if (skip_this) {
896 next_reg++;
897 next_arg++;
898 }
899 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
900 RegLocation rl_arg = info->args[next_arg++];
901 rl_arg = UpdateRawLoc(rl_arg);
902 if (rl_arg.wide && (next_reg <= TargetReg(kArg2).GetReg())) {
Zheng Xu511c8a62014-06-03 16:22:23 +0800903 LoadValueDirectWideFixed(rl_arg, RegStorage::Solo64(next_reg));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100904 next_arg++;
905 } else {
906 if (rl_arg.wide) {
907 rl_arg = NarrowRegLoc(rl_arg);
908 rl_arg.is_const = false;
909 }
910 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(next_reg));
911 }
912 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
913 direct_code, direct_method, type);
914 }
915 return call_state;
916}
917
Matteo Franchin43ec8732014-03-31 15:00:14 +0100918} // namespace art