blob: b287399900ffc69c343918b045931d62b84f6fce [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;
130 }
131 return res_reg;
132}
133
134RegStorage Arm64Mir2Lir::GetArgMappingToPhysicalReg(int arg_num) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100135 return RegStorage::InvalidReg();
Matteo Franchin43ec8732014-03-31 15:00:14 +0100136}
137
138/*
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100139 * Decode the register id. This routine makes assumptions on the encoding made by RegStorage.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100140 */
141uint64_t Arm64Mir2Lir::GetRegMaskCommon(RegStorage reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100142 // TODO(Arm64): this function depends too much on the internal RegStorage encoding. Refactor.
143
144 int reg_raw = reg.GetRawBits();
145 // Check if the shape mask is zero (i.e. invalid).
146 if (UNLIKELY(reg == rs_wzr || reg == rs_xzr)) {
147 // The zero register is not a true register. It is just an immediate zero.
148 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100149 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100150
151 return UINT64_C(1) << (reg_raw & RegStorage::kRegTypeMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100152}
153
154uint64_t Arm64Mir2Lir::GetPCUseDefEncoding() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100155 LOG(FATAL) << "Unexpected call to GetPCUseDefEncoding for Arm64";
156 return 0ULL;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100157}
158
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100159// Arm64 specific setup. TODO: inline?:
Matteo Franchin43ec8732014-03-31 15:00:14 +0100160void Arm64Mir2Lir::SetupTargetResourceMasks(LIR* lir, uint64_t flags) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100161 DCHECK_EQ(cu_->instruction_set, kArm64);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100162 DCHECK(!lir->flags.use_def_invalid);
163
Matteo Franchin43ec8732014-03-31 15:00:14 +0100164 // These flags are somewhat uncommon - bypass if we can.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100165 if ((flags & (REG_DEF_SP | REG_USE_SP | REG_DEF_LR)) != 0) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100166 if (flags & REG_DEF_SP) {
167 lir->u.m.def_mask |= ENCODE_ARM_REG_SP;
168 }
169
170 if (flags & REG_USE_SP) {
171 lir->u.m.use_mask |= ENCODE_ARM_REG_SP;
172 }
173
Matteo Franchin43ec8732014-03-31 15:00:14 +0100174 if (flags & REG_DEF_LR) {
175 lir->u.m.def_mask |= ENCODE_ARM_REG_LR;
176 }
177 }
178}
179
180ArmConditionCode Arm64Mir2Lir::ArmConditionEncoding(ConditionCode ccode) {
181 ArmConditionCode res;
182 switch (ccode) {
183 case kCondEq: res = kArmCondEq; break;
184 case kCondNe: res = kArmCondNe; break;
185 case kCondCs: res = kArmCondCs; break;
186 case kCondCc: res = kArmCondCc; break;
187 case kCondUlt: res = kArmCondCc; break;
188 case kCondUge: res = kArmCondCs; break;
189 case kCondMi: res = kArmCondMi; break;
190 case kCondPl: res = kArmCondPl; break;
191 case kCondVs: res = kArmCondVs; break;
192 case kCondVc: res = kArmCondVc; break;
193 case kCondHi: res = kArmCondHi; break;
194 case kCondLs: res = kArmCondLs; break;
195 case kCondGe: res = kArmCondGe; break;
196 case kCondLt: res = kArmCondLt; break;
197 case kCondGt: res = kArmCondGt; break;
198 case kCondLe: res = kArmCondLe; break;
199 case kCondAl: res = kArmCondAl; break;
200 case kCondNv: res = kArmCondNv; break;
201 default:
202 LOG(FATAL) << "Bad condition code " << ccode;
203 res = static_cast<ArmConditionCode>(0); // Quiet gcc
204 }
205 return res;
206}
207
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100208static const char *shift_names[4] = {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100209 "lsl",
210 "lsr",
211 "asr",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100212 "ror"
213};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100214
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100215static const char* extend_names[8] = {
216 "uxtb",
217 "uxth",
218 "uxtw",
219 "uxtx",
220 "sxtb",
221 "sxth",
222 "sxtw",
223 "sxtx",
224};
225
226/* Decode and print a register extension (e.g. ", uxtb #1") */
227static void DecodeRegExtendOrShift(int operand, char *buf, size_t buf_size) {
228 if ((operand & (1 << 6)) == 0) {
229 const char *shift_name = shift_names[(operand >> 7) & 0x3];
230 int amount = operand & 0x3f;
231 snprintf(buf, buf_size, ", %s #%d", shift_name, amount);
232 } else {
233 const char *extend_name = extend_names[(operand >> 3) & 0x7];
234 int amount = operand & 0x7;
235 if (amount == 0) {
236 snprintf(buf, buf_size, ", %s", extend_name);
237 } else {
238 snprintf(buf, buf_size, ", %s #%d", extend_name, amount);
239 }
240 }
241}
242
243#define BIT_MASK(w) ((UINT64_C(1) << (w)) - UINT64_C(1))
244
245static uint64_t RotateRight(uint64_t value, unsigned rotate, unsigned width) {
246 DCHECK_LE(width, 64U);
247 rotate &= 63;
248 value = value & BIT_MASK(width);
249 return ((value & BIT_MASK(rotate)) << (width - rotate)) | (value >> rotate);
250}
251
252static uint64_t RepeatBitsAcrossReg(bool is_wide, uint64_t value, unsigned width) {
253 unsigned i;
254 unsigned reg_size = (is_wide) ? 64 : 32;
255 uint64_t result = value & BIT_MASK(width);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100256 for (i = width; i < reg_size; i *= 2) {
257 result |= (result << i);
258 }
259 DCHECK_EQ(i, reg_size);
260 return result;
261}
262
263/**
264 * @brief Decode an immediate in the form required by logical instructions.
265 *
266 * @param is_wide Whether @p value encodes a 64-bit (as opposed to 32-bit) immediate.
267 * @param value The encoded logical immediates that is to be decoded.
268 * @return The decoded logical immediate.
269 * @note This is the inverse of Arm64Mir2Lir::EncodeLogicalImmediate().
270 */
271uint64_t Arm64Mir2Lir::DecodeLogicalImmediate(bool is_wide, int value) {
272 unsigned n = (value >> 12) & 0x01;
273 unsigned imm_r = (value >> 6) & 0x3f;
274 unsigned imm_s = (value >> 0) & 0x3f;
275
276 // An integer is constructed from the n, imm_s and imm_r bits according to
277 // the following table:
278 //
279 // N imms immr size S R
280 // 1 ssssss rrrrrr 64 UInt(ssssss) UInt(rrrrrr)
281 // 0 0sssss xrrrrr 32 UInt(sssss) UInt(rrrrr)
282 // 0 10ssss xxrrrr 16 UInt(ssss) UInt(rrrr)
283 // 0 110sss xxxrrr 8 UInt(sss) UInt(rrr)
284 // 0 1110ss xxxxrr 4 UInt(ss) UInt(rr)
285 // 0 11110s xxxxxr 2 UInt(s) UInt(r)
286 // (s bits must not be all set)
287 //
288 // A pattern is constructed of size bits, where the least significant S+1
289 // bits are set. The pattern is rotated right by R, and repeated across a
290 // 32 or 64-bit value, depending on destination register width.
291
292 if (n == 1) {
293 DCHECK_NE(imm_s, 0x3fU);
294 uint64_t bits = BIT_MASK(imm_s + 1);
295 return RotateRight(bits, imm_r, 64);
296 } else {
297 DCHECK_NE((imm_s >> 1), 0x1fU);
298 for (unsigned width = 0x20; width >= 0x2; width >>= 1) {
299 if ((imm_s & width) == 0) {
300 unsigned mask = (unsigned)(width - 1);
301 DCHECK_NE((imm_s & mask), mask);
302 uint64_t bits = BIT_MASK((imm_s & mask) + 1);
303 return RepeatBitsAcrossReg(is_wide, RotateRight(bits, imm_r & mask, width), width);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100304 }
305 }
306 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100307 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100308}
309
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100310/**
311 * @brief Decode an 8-bit single point number encoded with EncodeImmSingle().
312 */
313static float DecodeImmSingle(uint8_t small_float) {
314 int mantissa = (small_float & 0x0f) + 0x10;
315 int sign = ((small_float & 0x80) == 0) ? 1 : -1;
316 float signed_mantissa = static_cast<float>(sign*mantissa);
317 int exponent = (((small_float >> 4) & 0x7) + 4) & 0x7;
318 return signed_mantissa*static_cast<float>(1 << exponent)*0.0078125f;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100319}
320
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100321static const char* cc_names[] = {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
322 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100323/*
324 * Interpret a format string and build a string no longer than size
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100325 * See format key in assemble_arm64.cc.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100326 */
327std::string Arm64Mir2Lir::BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) {
328 std::string buf;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100329 const char* fmt_end = &fmt[strlen(fmt)];
330 char tbuf[256];
331 const char* name;
332 char nc;
333 while (fmt < fmt_end) {
334 int operand;
335 if (*fmt == '!') {
336 fmt++;
337 DCHECK_LT(fmt, fmt_end);
338 nc = *fmt++;
339 if (nc == '!') {
340 strcpy(tbuf, "!");
341 } else {
342 DCHECK_LT(fmt, fmt_end);
343 DCHECK_LT(static_cast<unsigned>(nc-'0'), 4U);
344 operand = lir->operands[nc-'0'];
345 switch (*fmt++) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100346 case 'e': {
347 // Omit ", uxtw #0" in strings like "add w0, w1, w3, uxtw #0" and
348 // ", uxtx #0" in strings like "add x0, x1, x3, uxtx #0"
349 int omittable = ((IS_WIDE(lir->opcode)) ? EncodeExtend(kA64Uxtw, 0) :
350 EncodeExtend(kA64Uxtw, 0));
351 if (LIKELY(operand == omittable)) {
352 strcpy(tbuf, "");
353 } else {
354 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
355 }
356 }
357 break;
358 case 'o':
359 // Omit ", lsl #0"
360 if (LIKELY(operand == EncodeShift(kA64Lsl, 0))) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100361 strcpy(tbuf, "");
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100362 } else {
363 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100364 }
365 break;
366 case 'B':
367 switch (operand) {
368 case kSY:
369 name = "sy";
370 break;
371 case kST:
372 name = "st";
373 break;
374 case kISH:
375 name = "ish";
376 break;
377 case kISHST:
378 name = "ishst";
379 break;
380 case kNSH:
381 name = "nsh";
382 break;
383 case kNSHST:
384 name = "shst";
385 break;
386 default:
387 name = "DecodeError2";
388 break;
389 }
390 strcpy(tbuf, name);
391 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100392 case 's':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100393 snprintf(tbuf, arraysize(tbuf), "s%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100394 break;
395 case 'S':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100396 snprintf(tbuf, arraysize(tbuf), "d%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100397 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100398 case 'f':
399 snprintf(tbuf, arraysize(tbuf), "%c%d", (IS_FWIDE(lir->opcode)) ? 'd' : 's',
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100400 operand & RegStorage::kRegNumMask);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100401 break;
402 case 'l': {
403 bool is_wide = IS_WIDE(lir->opcode);
404 uint64_t imm = DecodeLogicalImmediate(is_wide, operand);
405 snprintf(tbuf, arraysize(tbuf), "%" PRId64 " (%#" PRIx64 ")", imm, imm);
406 }
407 break;
408 case 'I':
409 snprintf(tbuf, arraysize(tbuf), "%f", DecodeImmSingle(operand));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100410 break;
411 case 'M':
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100412 if (LIKELY(operand == 0))
413 strcpy(tbuf, "");
414 else
415 snprintf(tbuf, arraysize(tbuf), ", lsl #%d", 16*operand);
416 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100417 case 'd':
418 snprintf(tbuf, arraysize(tbuf), "%d", operand);
419 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100420 case 'w':
421 if (LIKELY(operand != rwzr))
422 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
423 else
424 strcpy(tbuf, "wzr");
425 break;
426 case 'W':
427 if (LIKELY(operand != rwsp))
428 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
429 else
430 strcpy(tbuf, "wsp");
431 break;
432 case 'x':
433 if (LIKELY(operand != rxzr))
434 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
435 else
436 strcpy(tbuf, "xzr");
437 break;
438 case 'X':
439 if (LIKELY(operand != rsp))
440 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
441 else
442 strcpy(tbuf, "sp");
443 break;
444 case 'D':
445 snprintf(tbuf, arraysize(tbuf), "%d", operand*((IS_WIDE(lir->opcode)) ? 8 : 4));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100446 break;
447 case 'E':
448 snprintf(tbuf, arraysize(tbuf), "%d", operand*4);
449 break;
450 case 'F':
451 snprintf(tbuf, arraysize(tbuf), "%d", operand*2);
452 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100453 case 'G':
454 if (LIKELY(operand == 0))
455 strcpy(tbuf, "");
456 else
457 strcpy(tbuf, (IS_WIDE(lir->opcode)) ? ", lsl #3" : ", lsl #2");
458 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100459 case 'c':
460 strcpy(tbuf, cc_names[operand]);
461 break;
462 case 't':
463 snprintf(tbuf, arraysize(tbuf), "0x%08" PRIxPTR " (L%p)",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100464 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + (operand << 2),
Matteo Franchin43ec8732014-03-31 15:00:14 +0100465 lir->target);
466 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100467 case 'r': {
468 bool is_wide = IS_WIDE(lir->opcode);
469 if (LIKELY(operand != rwzr && operand != rxzr)) {
470 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
471 operand & RegStorage::kRegNumMask);
472 } else {
473 strcpy(tbuf, (is_wide) ? "xzr" : "wzr");
474 }
475 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100476 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100477 case 'R': {
478 bool is_wide = IS_WIDE(lir->opcode);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100479 if (LIKELY(operand != rwsp && operand != rsp)) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100480 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
481 operand & RegStorage::kRegNumMask);
482 } else {
483 strcpy(tbuf, (is_wide) ? "sp" : "wsp");
484 }
485 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100486 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100487 case 'p':
488 snprintf(tbuf, arraysize(tbuf), ".+%d (addr %#" PRIxPTR ")", 4*operand,
489 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + 4*operand);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100490 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100491 case 'T':
492 if (LIKELY(operand == 0))
493 strcpy(tbuf, "");
494 else if (operand == 1)
495 strcpy(tbuf, ", lsl #12");
496 else
497 strcpy(tbuf, ", DecodeError3");
Matteo Franchin43ec8732014-03-31 15:00:14 +0100498 break;
499 default:
500 strcpy(tbuf, "DecodeError1");
501 break;
502 }
503 buf += tbuf;
504 }
505 } else {
506 buf += *fmt++;
507 }
508 }
509 return buf;
510}
511
512void Arm64Mir2Lir::DumpResourceMask(LIR* arm_lir, uint64_t mask, const char* prefix) {
513 char buf[256];
514 buf[0] = 0;
515
516 if (mask == ENCODE_ALL) {
517 strcpy(buf, "all");
518 } else {
519 char num[8];
520 int i;
521
522 for (i = 0; i < kArmRegEnd; i++) {
523 if (mask & (1ULL << i)) {
524 snprintf(num, arraysize(num), "%d ", i);
525 strcat(buf, num);
526 }
527 }
528
529 if (mask & ENCODE_CCODE) {
530 strcat(buf, "cc ");
531 }
532 if (mask & ENCODE_FP_STATUS) {
533 strcat(buf, "fpcc ");
534 }
535
536 /* Memory bits */
537 if (arm_lir && (mask & ENCODE_DALVIK_REG)) {
538 snprintf(buf + strlen(buf), arraysize(buf) - strlen(buf), "dr%d%s",
539 DECODE_ALIAS_INFO_REG(arm_lir->flags.alias_info),
540 DECODE_ALIAS_INFO_WIDE(arm_lir->flags.alias_info) ? "(+1)" : "");
541 }
542 if (mask & ENCODE_LITERAL) {
543 strcat(buf, "lit ");
544 }
545
546 if (mask & ENCODE_HEAP_REF) {
547 strcat(buf, "heap ");
548 }
549 if (mask & ENCODE_MUST_NOT_ALIAS) {
550 strcat(buf, "noalias ");
551 }
552 }
553 if (buf[0]) {
554 LOG(INFO) << prefix << ": " << buf;
555 }
556}
557
558bool Arm64Mir2Lir::IsUnconditionalBranch(LIR* lir) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100559 return (lir->opcode == kA64B1t);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100560}
561
Vladimir Marko674744e2014-04-24 15:18:26 +0100562bool Arm64Mir2Lir::SupportsVolatileLoadStore(OpSize size) {
563 return true;
564}
565
566RegisterClass Arm64Mir2Lir::RegClassForFieldLoadStore(OpSize size, bool is_volatile) {
567 if (UNLIKELY(is_volatile)) {
568 // On arm64, fp register load/store is atomic only for single bytes.
569 if (size != kSignedByte && size != kUnsignedByte) {
buzbeea0cd2d72014-06-01 09:33:49 -0700570 return (size == kReference) ? kRefReg : kCoreReg;
Vladimir Marko674744e2014-04-24 15:18:26 +0100571 }
572 }
573 return RegClassBySize(size);
574}
575
Matteo Franchin43ec8732014-03-31 15:00:14 +0100576Arm64Mir2Lir::Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena)
577 : Mir2Lir(cu, mir_graph, arena) {
578 // Sanity check - make sure encoding map lines up.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100579 for (int i = 0; i < kA64Last; i++) {
580 if (UNWIDE(Arm64Mir2Lir::EncodingMap[i].opcode) != i) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100581 LOG(FATAL) << "Encoding order for " << Arm64Mir2Lir::EncodingMap[i].name
582 << " is wrong: expecting " << i << ", seeing "
583 << static_cast<int>(Arm64Mir2Lir::EncodingMap[i].opcode);
584 }
585 }
586}
587
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100588Mir2Lir* Arm64CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
589 ArenaAllocator* const arena) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100590 return new Arm64Mir2Lir(cu, mir_graph, arena);
591}
592
Matteo Franchin43ec8732014-03-31 15:00:14 +0100593void Arm64Mir2Lir::CompilerInitializeRegAlloc() {
buzbeeb01bf152014-05-13 15:59:07 -0700594 reg_pool_ = new (arena_) RegisterPool(this, arena_, core_regs, core64_regs, sp_regs, dp_regs,
595 reserved_regs, reserved64_regs, core_temps, core64_temps,
596 sp_temps, dp_temps);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100597
598 // Target-specific adjustments.
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100599 // Alias single precision float registers to corresponding double registers.
600 GrowableArray<RegisterInfo*>::Iterator fp_it(&reg_pool_->sp_regs_);
601 for (RegisterInfo* info = fp_it.Next(); info != nullptr; info = fp_it.Next()) {
602 int fp_reg_num = info->GetReg().GetRegNum();
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100603 RegStorage dp_reg = RegStorage::FloatSolo64(fp_reg_num);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100604 RegisterInfo* dp_reg_info = GetRegInfo(dp_reg);
605 // Double precision register's master storage should refer to itself.
606 DCHECK_EQ(dp_reg_info, dp_reg_info->Master());
607 // Redirect single precision's master storage to master.
608 info->SetMaster(dp_reg_info);
609 // Singles should show a single 32-bit mask bit, at first referring to the low half.
610 DCHECK_EQ(info->StorageMask(), 0x1U);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100611 }
612
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100613 // Alias 32bit W registers to corresponding 64bit X registers.
614 GrowableArray<RegisterInfo*>::Iterator w_it(&reg_pool_->core_regs_);
615 for (RegisterInfo* info = w_it.Next(); info != nullptr; info = w_it.Next()) {
616 int x_reg_num = info->GetReg().GetRegNum();
617 RegStorage x_reg = RegStorage::Solo64(x_reg_num);
618 RegisterInfo* x_reg_info = GetRegInfo(x_reg);
619 // 64bit X register's master storage should refer to itself.
620 DCHECK_EQ(x_reg_info, x_reg_info->Master());
621 // Redirect 32bit W master storage to 64bit X.
622 info->SetMaster(x_reg_info);
623 // 32bit W should show a single 32-bit mask bit, at first referring to the low half.
624 DCHECK_EQ(info->StorageMask(), 0x1U);
625 }
626
Matteo Franchin43ec8732014-03-31 15:00:14 +0100627 // Don't start allocating temps at r0/s0/d0 or you may clobber return regs in early-exit methods.
628 // TODO: adjust when we roll to hard float calling convention.
629 reg_pool_->next_core_reg_ = 2;
630 reg_pool_->next_sp_reg_ = 0;
631 reg_pool_->next_dp_reg_ = 0;
632}
633
Matteo Franchin43ec8732014-03-31 15:00:14 +0100634/*
635 * TUNING: is true leaf? Can't just use METHOD_IS_LEAF to determine as some
636 * instructions might call out to C/assembly helper functions. Until
637 * machinery is in place, always spill lr.
638 */
639
640void Arm64Mir2Lir::AdjustSpillMask() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100641 core_spill_mask_ |= (1 << rs_rA64_LR.GetRegNum());
Matteo Franchin43ec8732014-03-31 15:00:14 +0100642 num_core_spills_++;
643}
644
645/*
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100646 * Mark a callee-save fp register as promoted.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100647 */
648void Arm64Mir2Lir::MarkPreservedSingle(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100649 DCHECK(reg.IsFloat());
650 int adjusted_reg_num = reg.GetRegNum() - A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100651 // Ensure fp_vmap_table is large enough
652 int table_size = fp_vmap_table_.size();
653 for (int i = table_size; i < (adjusted_reg_num + 1); i++) {
654 fp_vmap_table_.push_back(INVALID_VREG);
655 }
656 // Add the current mapping
657 fp_vmap_table_[adjusted_reg_num] = v_reg;
658 // Size of fp_vmap_table is high-water mark, use to set mask
659 num_fp_spills_ = fp_vmap_table_.size();
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100660 fp_spill_mask_ = ((1 << num_fp_spills_) - 1) << A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100661}
662
663void Arm64Mir2Lir::MarkPreservedDouble(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100664 DCHECK(reg.IsDouble());
665 MarkPreservedSingle(v_reg, reg);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100666}
667
668/* Clobber all regs that might be used by an external C call */
669void Arm64Mir2Lir::ClobberCallerSave() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100670 Clobber(rs_x0);
671 Clobber(rs_x1);
672 Clobber(rs_x2);
673 Clobber(rs_x3);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100674 Clobber(rs_x4);
675 Clobber(rs_x5);
676 Clobber(rs_x6);
677 Clobber(rs_x7);
678 Clobber(rs_x8);
679 Clobber(rs_x9);
680 Clobber(rs_x10);
681 Clobber(rs_x11);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100682 Clobber(rs_x12);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100683 Clobber(rs_x13);
684 Clobber(rs_x14);
685 Clobber(rs_x15);
686 Clobber(rs_x16);
687 Clobber(rs_x17);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100688 Clobber(rs_x30);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100689
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100690 Clobber(rs_f0);
691 Clobber(rs_f1);
692 Clobber(rs_f2);
693 Clobber(rs_f3);
694 Clobber(rs_f4);
695 Clobber(rs_f5);
696 Clobber(rs_f6);
697 Clobber(rs_f7);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100698 Clobber(rs_f16);
699 Clobber(rs_f17);
700 Clobber(rs_f18);
701 Clobber(rs_f19);
702 Clobber(rs_f20);
703 Clobber(rs_f21);
704 Clobber(rs_f22);
705 Clobber(rs_f23);
706 Clobber(rs_f24);
707 Clobber(rs_f25);
708 Clobber(rs_f26);
709 Clobber(rs_f27);
710 Clobber(rs_f28);
711 Clobber(rs_f29);
712 Clobber(rs_f30);
713 Clobber(rs_f31);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100714}
715
716RegLocation Arm64Mir2Lir::GetReturnWideAlt() {
717 RegLocation res = LocCReturnWide();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100718 res.reg.SetReg(rx2);
719 res.reg.SetHighReg(rx3);
720 Clobber(rs_x2);
721 Clobber(rs_x3);
722 MarkInUse(rs_x2);
723 MarkInUse(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100724 MarkWide(res.reg);
725 return res;
726}
727
728RegLocation Arm64Mir2Lir::GetReturnAlt() {
729 RegLocation res = LocCReturn();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100730 res.reg.SetReg(rx1);
731 Clobber(rs_x1);
732 MarkInUse(rs_x1);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100733 return res;
734}
735
736/* To be used when explicitly managing register use */
737void Arm64Mir2Lir::LockCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100738 LockTemp(rs_x0);
739 LockTemp(rs_x1);
740 LockTemp(rs_x2);
741 LockTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100742}
743
744/* To be used when explicitly managing register use */
745void Arm64Mir2Lir::FreeCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100746 FreeTemp(rs_x0);
747 FreeTemp(rs_x1);
748 FreeTemp(rs_x2);
749 FreeTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100750}
751
Andreas Gampe2f244e92014-05-08 03:35:25 -0700752RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<4> offset) {
753 UNIMPLEMENTED(FATAL) << "Should not be called.";
754 return RegStorage::InvalidReg();
755}
756
757RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<8> offset) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100758 // TODO(Arm64): use LoadWordDisp instead.
759 // e.g. LoadWordDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR);
760 LoadBaseDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR, k64);
761 return rs_rA64_LR;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100762}
763
764LIR* Arm64Mir2Lir::CheckSuspendUsingLoad() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100765 RegStorage tmp = rs_x0;
Andreas Gampe2f244e92014-05-08 03:35:25 -0700766 LoadWordDisp(rs_rA64_SELF, Thread::ThreadSuspendTriggerOffset<8>().Int32Value(), tmp);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100767 LIR* load2 = LoadWordDisp(tmp, 0, tmp);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100768 return load2;
769}
770
771uint64_t Arm64Mir2Lir::GetTargetInstFlags(int opcode) {
772 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100773 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].flags;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100774}
775
776const char* Arm64Mir2Lir::GetTargetInstName(int opcode) {
777 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100778 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].name;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100779}
780
781const char* Arm64Mir2Lir::GetTargetInstFmt(int opcode) {
782 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100783 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].fmt;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100784}
785
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100786// TODO(Arm64): reuse info in QuickArgumentVisitor?
787static RegStorage GetArgPhysicalReg(RegLocation* loc, int* num_gpr_used, int* num_fpr_used,
788 OpSize* op_size) {
789 if (loc->fp) {
790 int n = *num_fpr_used;
791 if (n < 8) {
792 *num_fpr_used = n + 1;
793 RegStorage::RegStorageKind reg_kind;
794 if (loc->wide) {
795 *op_size = kDouble;
796 reg_kind = RegStorage::k64BitSolo;
797 } else {
798 *op_size = kSingle;
799 reg_kind = RegStorage::k32BitSolo;
800 }
801 return RegStorage(RegStorage::kValid | reg_kind | RegStorage::kFloatingPoint | n);
802 }
803 } else {
804 int n = *num_gpr_used;
805 if (n < 7) {
806 *num_gpr_used = n + 1;
807 if (loc->wide) {
808 *op_size = k64;
809 return RegStorage::Solo64(n);
810 } else {
811 *op_size = k32;
812 return RegStorage::Solo32(n);
813 }
814 }
815 }
816
817 return RegStorage::InvalidReg();
818}
819
820/*
821 * If there are any ins passed in registers that have not been promoted
822 * to a callee-save register, flush them to the frame. Perform initial
823 * assignment of promoted arguments.
824 *
825 * ArgLocs is an array of location records describing the incoming arguments
826 * with one location record per word of argument.
827 */
828void Arm64Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
829 int num_gpr_used = 1;
830 int num_fpr_used = 0;
831
832 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800833 * Dummy up a RegLocation for the incoming StackReference<mirror::ArtMethod>
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100834 * It will attempt to keep kArg0 live (or copy it to home location
835 * if promoted).
836 */
837 RegLocation rl_src = rl_method;
838 rl_src.location = kLocPhysReg;
839 rl_src.reg = TargetReg(kArg0);
840 rl_src.home = false;
841 MarkLive(rl_src);
Zheng Xu511c8a62014-06-03 16:22:23 +0800842 StoreValue(rl_method, rl_src);
843 // If Method* has been promoted, explicitly flush
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100844 if (rl_method.location == kLocPhysReg) {
Zheng Xu511c8a62014-06-03 16:22:23 +0800845 StoreRefDisp(TargetReg(kSp), 0, TargetReg(kArg0));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100846 }
847
848 if (cu_->num_ins == 0) {
849 return;
850 }
851
852 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
853 for (int i = 0; i < cu_->num_ins; i++) {
854 PromotionMap* v_map = &promotion_map_[start_vreg + i];
855 RegLocation* t_loc = &ArgLocs[i];
856 OpSize op_size;
857 RegStorage reg = GetArgPhysicalReg(t_loc, &num_gpr_used, &num_fpr_used, &op_size);
858
859 if (reg.Valid()) {
860 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
861 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
862 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
863 OpRegCopy(RegStorage::Solo32(v_map->FpReg), reg);
864 } else {
865 StoreBaseDisp(TargetReg(kSp), SRegOffset(start_vreg + i), reg, op_size);
866 if (reg.Is64Bit()) {
867 if (SRegOffset(start_vreg + i) + 4 != SRegOffset(start_vreg + i + 1)) {
868 LOG(FATAL) << "64 bit value stored in non-consecutive 4 bytes slots";
869 }
870 i += 1;
871 }
872 }
873 } else {
874 // If arriving in frame & promoted
875 if (v_map->core_location == kLocPhysReg) {
876 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i),
877 RegStorage::Solo32(v_map->core_reg));
878 }
879 if (v_map->fp_location == kLocPhysReg) {
880 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg));
881 }
882 }
883 }
884}
885
886int Arm64Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
887 NextCallInsn next_call_insn,
888 const MethodReference& target_method,
889 uint32_t vtable_idx, uintptr_t direct_code,
890 uintptr_t direct_method, InvokeType type, bool skip_this) {
891 int last_arg_reg = TargetReg(kArg3).GetReg();
892 int next_reg = TargetReg(kArg1).GetReg();
893 int next_arg = 0;
894 if (skip_this) {
895 next_reg++;
896 next_arg++;
897 }
898 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
899 RegLocation rl_arg = info->args[next_arg++];
900 rl_arg = UpdateRawLoc(rl_arg);
901 if (rl_arg.wide && (next_reg <= TargetReg(kArg2).GetReg())) {
Zheng Xu511c8a62014-06-03 16:22:23 +0800902 LoadValueDirectWideFixed(rl_arg, RegStorage::Solo64(next_reg));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100903 next_arg++;
904 } else {
905 if (rl_arg.wide) {
906 rl_arg = NarrowRegLoc(rl_arg);
907 rl_arg.is_const = false;
908 }
909 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(next_reg));
910 }
911 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
912 direct_code, direct_method, type);
913 }
914 return call_state;
915}
916
Matteo Franchin43ec8732014-03-31 15:00:14 +0100917} // namespace art