blob: 2b1c5e83867cab5e29645b12c0e07423bc3b0933 [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
28// TODO: rework this when c++11 support allows.
29static const RegStorage core_regs_arr[] =
buzbeeb01bf152014-05-13 15:59:07 -070030 {rs_w0, rs_w1, rs_w2, rs_w3, rs_w4, rs_w5, rs_w6, rs_w7,
31 rs_w8, rs_w9, rs_w10, rs_w11, rs_w12, rs_w13, rs_w14, rs_w15,
32 rs_w16, rs_w17, rs_w18, rs_w19, rs_w20, rs_w21, rs_w22, rs_w23,
33 rs_w24, rs_w25, rs_w26, rs_w27, rs_w28, rs_w29, rs_w30, rs_w31,
34 rs_wzr};
35static const RegStorage core64_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010036 {rs_x0, rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7,
37 rs_x8, rs_x9, rs_x10, rs_x11, rs_x12, rs_x13, rs_x14, rs_x15,
38 rs_x16, rs_x17, rs_x18, rs_x19, rs_x20, rs_x21, rs_x22, rs_x23,
Matteo Franchinbc6d1972014-05-13 12:33:28 +010039 rs_x24, rs_x25, rs_x26, rs_x27, rs_x28, rs_x29, rs_x30, rs_x31,
40 rs_xzr};
Matteo Franchin43ec8732014-03-31 15:00:14 +010041static const RegStorage sp_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010042 {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7,
43 rs_f8, rs_f9, rs_f10, rs_f11, rs_f12, rs_f13, rs_f14, rs_f15,
44 rs_f16, rs_f17, rs_f18, rs_f19, rs_f20, rs_f21, rs_f22, rs_f23,
45 rs_f24, rs_f25, rs_f26, rs_f27, rs_f28, rs_f29, rs_f30, rs_f31};
Matteo Franchin43ec8732014-03-31 15:00:14 +010046static const RegStorage dp_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010047 {rs_d0, rs_d1, rs_d2, rs_d3, rs_d4, rs_d5, rs_d6, rs_d7,
Zheng Xuc8304302014-05-15 17:21:01 +010048 rs_d8, rs_d9, rs_d10, rs_d11, rs_d12, rs_d13, rs_d14, rs_d15,
49 rs_d16, rs_d17, rs_d18, rs_d19, rs_d20, rs_d21, rs_d22, rs_d23,
50 rs_d24, rs_d25, rs_d26, rs_d27, rs_d28, rs_d29, rs_d30, rs_d31};
Matteo Franchin43ec8732014-03-31 15:00:14 +010051static const RegStorage reserved_regs_arr[] =
buzbeeb01bf152014-05-13 15:59:07 -070052 {rs_rA32_SUSPEND, rs_rA32_SELF, rs_rA32_SP, rs_rA32_LR, rs_wzr};
53static const RegStorage reserved64_regs_arr[] =
Matteo Franchinbc6d1972014-05-13 12:33:28 +010054 {rs_rA64_SUSPEND, rs_rA64_SELF, rs_rA64_SP, rs_rA64_LR, rs_xzr};
55// TUNING: Are there too many temp registers and too less promote target?
Zheng Xuc8304302014-05-15 17:21:01 +010056// This definition need to be matched with runtime.cc, quick entry assembly and JNI compiler
57// Note: we are not able to call to C function directly if it un-match C ABI.
58// Currently, rs_rA64_SELF is not a callee save register which does not match C ABI.
Matteo Franchine45fb9e2014-05-06 10:10:30 +010059static const RegStorage core_temps_arr[] =
buzbeeb01bf152014-05-13 15:59:07 -070060 {rs_w0, rs_w1, rs_w2, rs_w3, rs_w4, rs_w5, rs_w6, rs_w7,
61 rs_w8, rs_w9, rs_w10, rs_w11, rs_w12, rs_w13, rs_w14, rs_w15, rs_w16,
62 rs_w17};
63static const RegStorage core64_temps_arr[] =
Zheng Xuc8304302014-05-15 17:21:01 +010064 {rs_x0, rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7,
65 rs_x8, rs_x9, rs_x10, rs_x11, rs_x12, rs_x13, rs_x14, rs_x15, rs_x16,
66 rs_x17};
Matteo Franchin43ec8732014-03-31 15:00:14 +010067static const RegStorage sp_temps_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010068 {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7,
Zheng Xuc8304302014-05-15 17:21:01 +010069 rs_f16, rs_f17, rs_f18, rs_f19, rs_f20, rs_f21, rs_f22, rs_f23,
70 rs_f24, rs_f25, rs_f26, rs_f27, rs_f28, rs_f29, rs_f30, rs_f31};
Matteo Franchin43ec8732014-03-31 15:00:14 +010071static const RegStorage dp_temps_arr[] =
Zheng Xuc8304302014-05-15 17:21:01 +010072 {rs_d0, rs_d1, rs_d2, rs_d3, rs_d4, rs_d5, rs_d6, rs_d7,
73 rs_d16, rs_d17, rs_d18, rs_d19, rs_d20, rs_d21, rs_d22, rs_d23,
74 rs_d24, rs_d25, rs_d26, rs_d27, rs_d28, rs_d29, rs_d30, rs_d31};
Matteo Franchin43ec8732014-03-31 15:00:14 +010075
76static const std::vector<RegStorage> core_regs(core_regs_arr,
Matteo Franchine45fb9e2014-05-06 10:10:30 +010077 core_regs_arr + arraysize(core_regs_arr));
buzbeeb01bf152014-05-13 15:59:07 -070078static const std::vector<RegStorage> core64_regs(core64_regs_arr,
79 core64_regs_arr + arraysize(core64_regs_arr));
Matteo Franchin43ec8732014-03-31 15:00:14 +010080static const std::vector<RegStorage> sp_regs(sp_regs_arr,
Matteo Franchine45fb9e2014-05-06 10:10:30 +010081 sp_regs_arr + arraysize(sp_regs_arr));
Matteo Franchin43ec8732014-03-31 15:00:14 +010082static const std::vector<RegStorage> dp_regs(dp_regs_arr,
Matteo Franchine45fb9e2014-05-06 10:10:30 +010083 dp_regs_arr + arraysize(dp_regs_arr));
Matteo Franchin43ec8732014-03-31 15:00:14 +010084static const std::vector<RegStorage> reserved_regs(reserved_regs_arr,
Matteo Franchine45fb9e2014-05-06 10:10:30 +010085 reserved_regs_arr + arraysize(reserved_regs_arr));
buzbeeb01bf152014-05-13 15:59:07 -070086static const std::vector<RegStorage> reserved64_regs(reserved64_regs_arr,
87 reserved64_regs_arr + arraysize(reserved64_regs_arr));
Matteo Franchin43ec8732014-03-31 15:00:14 +010088static const std::vector<RegStorage> core_temps(core_temps_arr,
Matteo Franchine45fb9e2014-05-06 10:10:30 +010089 core_temps_arr + arraysize(core_temps_arr));
buzbeeb01bf152014-05-13 15:59:07 -070090static const std::vector<RegStorage> core64_temps(core64_temps_arr,
91 core64_temps_arr + arraysize(core64_temps_arr));
Matteo Franchine45fb9e2014-05-06 10:10:30 +010092static const std::vector<RegStorage> sp_temps(sp_temps_arr, sp_temps_arr + arraysize(sp_temps_arr));
93static const std::vector<RegStorage> dp_temps(dp_temps_arr, dp_temps_arr + arraysize(dp_temps_arr));
Matteo Franchin43ec8732014-03-31 15:00:14 +010094
95RegLocation Arm64Mir2Lir::LocCReturn() {
96 return arm_loc_c_return;
97}
98
99RegLocation Arm64Mir2Lir::LocCReturnWide() {
100 return arm_loc_c_return_wide;
101}
102
103RegLocation Arm64Mir2Lir::LocCReturnFloat() {
104 return arm_loc_c_return_float;
105}
106
107RegLocation Arm64Mir2Lir::LocCReturnDouble() {
108 return arm_loc_c_return_double;
109}
110
111// Return a target-dependent special register.
112RegStorage Arm64Mir2Lir::TargetReg(SpecialTargetRegister reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100113 // TODO(Arm64): this function doesn't work for hard-float ABI.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100114 RegStorage res_reg = RegStorage::InvalidReg();
115 switch (reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100116 case kSelf: res_reg = rs_rA64_SELF; break;
117 case kSuspend: res_reg = rs_rA64_SUSPEND; break;
118 case kLr: res_reg = rs_rA64_LR; break;
119 case kPc: res_reg = RegStorage::InvalidReg(); break;
120 case kSp: res_reg = rs_rA64_SP; break;
121 case kArg0: res_reg = rs_x0; break;
122 case kArg1: res_reg = rs_x1; break;
123 case kArg2: res_reg = rs_x2; break;
124 case kArg3: res_reg = rs_x3; break;
125 case kFArg0: res_reg = rs_f0; break;
126 case kFArg1: res_reg = rs_f1; break;
127 case kFArg2: res_reg = rs_f2; break;
128 case kFArg3: res_reg = rs_f3; break;
129 case kRet0: res_reg = rs_x0; break;
130 case kRet1: res_reg = rs_x0; break;
131 case kInvokeTgt: res_reg = rs_rA64_LR; break;
132 case kHiddenArg: res_reg = rs_x12; break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100133 case kHiddenFpArg: res_reg = RegStorage::InvalidReg(); break;
134 case kCount: res_reg = RegStorage::InvalidReg(); break;
135 }
136 return res_reg;
137}
138
139RegStorage Arm64Mir2Lir::GetArgMappingToPhysicalReg(int arg_num) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100140 return RegStorage::InvalidReg();
Matteo Franchin43ec8732014-03-31 15:00:14 +0100141}
142
143/*
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100144 * Decode the register id. This routine makes assumptions on the encoding made by RegStorage.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100145 */
146uint64_t Arm64Mir2Lir::GetRegMaskCommon(RegStorage reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100147 // TODO(Arm64): this function depends too much on the internal RegStorage encoding. Refactor.
148
149 int reg_raw = reg.GetRawBits();
150 // Check if the shape mask is zero (i.e. invalid).
151 if (UNLIKELY(reg == rs_wzr || reg == rs_xzr)) {
152 // The zero register is not a true register. It is just an immediate zero.
153 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100154 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100155
156 return UINT64_C(1) << (reg_raw & RegStorage::kRegTypeMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100157}
158
159uint64_t Arm64Mir2Lir::GetPCUseDefEncoding() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100160 LOG(FATAL) << "Unexpected call to GetPCUseDefEncoding for Arm64";
161 return 0ULL;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100162}
163
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100164// Arm64 specific setup. TODO: inline?:
Matteo Franchin43ec8732014-03-31 15:00:14 +0100165void Arm64Mir2Lir::SetupTargetResourceMasks(LIR* lir, uint64_t flags) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100166 DCHECK_EQ(cu_->instruction_set, kArm64);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100167 DCHECK(!lir->flags.use_def_invalid);
168
Matteo Franchin43ec8732014-03-31 15:00:14 +0100169 // These flags are somewhat uncommon - bypass if we can.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100170 if ((flags & (REG_DEF_SP | REG_USE_SP | REG_DEF_LR)) != 0) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100171 if (flags & REG_DEF_SP) {
172 lir->u.m.def_mask |= ENCODE_ARM_REG_SP;
173 }
174
175 if (flags & REG_USE_SP) {
176 lir->u.m.use_mask |= ENCODE_ARM_REG_SP;
177 }
178
Matteo Franchin43ec8732014-03-31 15:00:14 +0100179 if (flags & REG_DEF_LR) {
180 lir->u.m.def_mask |= ENCODE_ARM_REG_LR;
181 }
182 }
183}
184
185ArmConditionCode Arm64Mir2Lir::ArmConditionEncoding(ConditionCode ccode) {
186 ArmConditionCode res;
187 switch (ccode) {
188 case kCondEq: res = kArmCondEq; break;
189 case kCondNe: res = kArmCondNe; break;
190 case kCondCs: res = kArmCondCs; break;
191 case kCondCc: res = kArmCondCc; break;
192 case kCondUlt: res = kArmCondCc; break;
193 case kCondUge: res = kArmCondCs; break;
194 case kCondMi: res = kArmCondMi; break;
195 case kCondPl: res = kArmCondPl; break;
196 case kCondVs: res = kArmCondVs; break;
197 case kCondVc: res = kArmCondVc; break;
198 case kCondHi: res = kArmCondHi; break;
199 case kCondLs: res = kArmCondLs; break;
200 case kCondGe: res = kArmCondGe; break;
201 case kCondLt: res = kArmCondLt; break;
202 case kCondGt: res = kArmCondGt; break;
203 case kCondLe: res = kArmCondLe; break;
204 case kCondAl: res = kArmCondAl; break;
205 case kCondNv: res = kArmCondNv; break;
206 default:
207 LOG(FATAL) << "Bad condition code " << ccode;
208 res = static_cast<ArmConditionCode>(0); // Quiet gcc
209 }
210 return res;
211}
212
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100213static const char *shift_names[4] = {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100214 "lsl",
215 "lsr",
216 "asr",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100217 "ror"
218};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100219
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100220static const char* extend_names[8] = {
221 "uxtb",
222 "uxth",
223 "uxtw",
224 "uxtx",
225 "sxtb",
226 "sxth",
227 "sxtw",
228 "sxtx",
229};
230
231/* Decode and print a register extension (e.g. ", uxtb #1") */
232static void DecodeRegExtendOrShift(int operand, char *buf, size_t buf_size) {
233 if ((operand & (1 << 6)) == 0) {
234 const char *shift_name = shift_names[(operand >> 7) & 0x3];
235 int amount = operand & 0x3f;
236 snprintf(buf, buf_size, ", %s #%d", shift_name, amount);
237 } else {
238 const char *extend_name = extend_names[(operand >> 3) & 0x7];
239 int amount = operand & 0x7;
240 if (amount == 0) {
241 snprintf(buf, buf_size, ", %s", extend_name);
242 } else {
243 snprintf(buf, buf_size, ", %s #%d", extend_name, amount);
244 }
245 }
246}
247
248#define BIT_MASK(w) ((UINT64_C(1) << (w)) - UINT64_C(1))
249
250static uint64_t RotateRight(uint64_t value, unsigned rotate, unsigned width) {
251 DCHECK_LE(width, 64U);
252 rotate &= 63;
253 value = value & BIT_MASK(width);
254 return ((value & BIT_MASK(rotate)) << (width - rotate)) | (value >> rotate);
255}
256
257static uint64_t RepeatBitsAcrossReg(bool is_wide, uint64_t value, unsigned width) {
258 unsigned i;
259 unsigned reg_size = (is_wide) ? 64 : 32;
260 uint64_t result = value & BIT_MASK(width);
261 DCHECK_NE(width, reg_size);
262 for (i = width; i < reg_size; i *= 2) {
263 result |= (result << i);
264 }
265 DCHECK_EQ(i, reg_size);
266 return result;
267}
268
269/**
270 * @brief Decode an immediate in the form required by logical instructions.
271 *
272 * @param is_wide Whether @p value encodes a 64-bit (as opposed to 32-bit) immediate.
273 * @param value The encoded logical immediates that is to be decoded.
274 * @return The decoded logical immediate.
275 * @note This is the inverse of Arm64Mir2Lir::EncodeLogicalImmediate().
276 */
277uint64_t Arm64Mir2Lir::DecodeLogicalImmediate(bool is_wide, int value) {
278 unsigned n = (value >> 12) & 0x01;
279 unsigned imm_r = (value >> 6) & 0x3f;
280 unsigned imm_s = (value >> 0) & 0x3f;
281
282 // An integer is constructed from the n, imm_s and imm_r bits according to
283 // the following table:
284 //
285 // N imms immr size S R
286 // 1 ssssss rrrrrr 64 UInt(ssssss) UInt(rrrrrr)
287 // 0 0sssss xrrrrr 32 UInt(sssss) UInt(rrrrr)
288 // 0 10ssss xxrrrr 16 UInt(ssss) UInt(rrrr)
289 // 0 110sss xxxrrr 8 UInt(sss) UInt(rrr)
290 // 0 1110ss xxxxrr 4 UInt(ss) UInt(rr)
291 // 0 11110s xxxxxr 2 UInt(s) UInt(r)
292 // (s bits must not be all set)
293 //
294 // A pattern is constructed of size bits, where the least significant S+1
295 // bits are set. The pattern is rotated right by R, and repeated across a
296 // 32 or 64-bit value, depending on destination register width.
297
298 if (n == 1) {
299 DCHECK_NE(imm_s, 0x3fU);
300 uint64_t bits = BIT_MASK(imm_s + 1);
301 return RotateRight(bits, imm_r, 64);
302 } else {
303 DCHECK_NE((imm_s >> 1), 0x1fU);
304 for (unsigned width = 0x20; width >= 0x2; width >>= 1) {
305 if ((imm_s & width) == 0) {
306 unsigned mask = (unsigned)(width - 1);
307 DCHECK_NE((imm_s & mask), mask);
308 uint64_t bits = BIT_MASK((imm_s & mask) + 1);
309 return RepeatBitsAcrossReg(is_wide, RotateRight(bits, imm_r & mask, width), width);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100310 }
311 }
312 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100313 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100314}
315
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100316/**
317 * @brief Decode an 8-bit single point number encoded with EncodeImmSingle().
318 */
319static float DecodeImmSingle(uint8_t small_float) {
320 int mantissa = (small_float & 0x0f) + 0x10;
321 int sign = ((small_float & 0x80) == 0) ? 1 : -1;
322 float signed_mantissa = static_cast<float>(sign*mantissa);
323 int exponent = (((small_float >> 4) & 0x7) + 4) & 0x7;
324 return signed_mantissa*static_cast<float>(1 << exponent)*0.0078125f;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100325}
326
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100327static const char* cc_names[] = {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
328 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100329/*
330 * Interpret a format string and build a string no longer than size
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100331 * See format key in assemble_arm64.cc.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100332 */
333std::string Arm64Mir2Lir::BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) {
334 std::string buf;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100335 const char* fmt_end = &fmt[strlen(fmt)];
336 char tbuf[256];
337 const char* name;
338 char nc;
339 while (fmt < fmt_end) {
340 int operand;
341 if (*fmt == '!') {
342 fmt++;
343 DCHECK_LT(fmt, fmt_end);
344 nc = *fmt++;
345 if (nc == '!') {
346 strcpy(tbuf, "!");
347 } else {
348 DCHECK_LT(fmt, fmt_end);
349 DCHECK_LT(static_cast<unsigned>(nc-'0'), 4U);
350 operand = lir->operands[nc-'0'];
351 switch (*fmt++) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100352 case 'e': {
353 // Omit ", uxtw #0" in strings like "add w0, w1, w3, uxtw #0" and
354 // ", uxtx #0" in strings like "add x0, x1, x3, uxtx #0"
355 int omittable = ((IS_WIDE(lir->opcode)) ? EncodeExtend(kA64Uxtw, 0) :
356 EncodeExtend(kA64Uxtw, 0));
357 if (LIKELY(operand == omittable)) {
358 strcpy(tbuf, "");
359 } else {
360 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
361 }
362 }
363 break;
364 case 'o':
365 // Omit ", lsl #0"
366 if (LIKELY(operand == EncodeShift(kA64Lsl, 0))) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100367 strcpy(tbuf, "");
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100368 } else {
369 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100370 }
371 break;
372 case 'B':
373 switch (operand) {
374 case kSY:
375 name = "sy";
376 break;
377 case kST:
378 name = "st";
379 break;
380 case kISH:
381 name = "ish";
382 break;
383 case kISHST:
384 name = "ishst";
385 break;
386 case kNSH:
387 name = "nsh";
388 break;
389 case kNSHST:
390 name = "shst";
391 break;
392 default:
393 name = "DecodeError2";
394 break;
395 }
396 strcpy(tbuf, name);
397 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100398 case 's':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100399 snprintf(tbuf, arraysize(tbuf), "s%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100400 break;
401 case 'S':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100402 snprintf(tbuf, arraysize(tbuf), "d%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100403 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100404 case 'f':
405 snprintf(tbuf, arraysize(tbuf), "%c%d", (IS_FWIDE(lir->opcode)) ? 'd' : 's',
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100406 operand & RegStorage::kRegNumMask);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100407 break;
408 case 'l': {
409 bool is_wide = IS_WIDE(lir->opcode);
410 uint64_t imm = DecodeLogicalImmediate(is_wide, operand);
411 snprintf(tbuf, arraysize(tbuf), "%" PRId64 " (%#" PRIx64 ")", imm, imm);
412 }
413 break;
414 case 'I':
415 snprintf(tbuf, arraysize(tbuf), "%f", DecodeImmSingle(operand));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100416 break;
417 case 'M':
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100418 if (LIKELY(operand == 0))
419 strcpy(tbuf, "");
420 else
421 snprintf(tbuf, arraysize(tbuf), ", lsl #%d", 16*operand);
422 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100423 case 'd':
424 snprintf(tbuf, arraysize(tbuf), "%d", operand);
425 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100426 case 'w':
427 if (LIKELY(operand != rwzr))
428 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
429 else
430 strcpy(tbuf, "wzr");
431 break;
432 case 'W':
433 if (LIKELY(operand != rwsp))
434 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
435 else
436 strcpy(tbuf, "wsp");
437 break;
438 case 'x':
439 if (LIKELY(operand != rxzr))
440 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
441 else
442 strcpy(tbuf, "xzr");
443 break;
444 case 'X':
445 if (LIKELY(operand != rsp))
446 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
447 else
448 strcpy(tbuf, "sp");
449 break;
450 case 'D':
451 snprintf(tbuf, arraysize(tbuf), "%d", operand*((IS_WIDE(lir->opcode)) ? 8 : 4));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100452 break;
453 case 'E':
454 snprintf(tbuf, arraysize(tbuf), "%d", operand*4);
455 break;
456 case 'F':
457 snprintf(tbuf, arraysize(tbuf), "%d", operand*2);
458 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100459 case 'G':
460 if (LIKELY(operand == 0))
461 strcpy(tbuf, "");
462 else
463 strcpy(tbuf, (IS_WIDE(lir->opcode)) ? ", lsl #3" : ", lsl #2");
464 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100465 case 'c':
466 strcpy(tbuf, cc_names[operand]);
467 break;
468 case 't':
469 snprintf(tbuf, arraysize(tbuf), "0x%08" PRIxPTR " (L%p)",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100470 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + (operand << 2),
Matteo Franchin43ec8732014-03-31 15:00:14 +0100471 lir->target);
472 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100473 case 'r': {
474 bool is_wide = IS_WIDE(lir->opcode);
475 if (LIKELY(operand != rwzr && operand != rxzr)) {
476 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
477 operand & RegStorage::kRegNumMask);
478 } else {
479 strcpy(tbuf, (is_wide) ? "xzr" : "wzr");
480 }
481 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100482 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100483 case 'R': {
484 bool is_wide = IS_WIDE(lir->opcode);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100485 if (LIKELY(operand != rwsp && operand != rsp)) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100486 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
487 operand & RegStorage::kRegNumMask);
488 } else {
489 strcpy(tbuf, (is_wide) ? "sp" : "wsp");
490 }
491 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100492 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100493 case 'p':
494 snprintf(tbuf, arraysize(tbuf), ".+%d (addr %#" PRIxPTR ")", 4*operand,
495 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + 4*operand);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100496 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100497 case 'T':
498 if (LIKELY(operand == 0))
499 strcpy(tbuf, "");
500 else if (operand == 1)
501 strcpy(tbuf, ", lsl #12");
502 else
503 strcpy(tbuf, ", DecodeError3");
Matteo Franchin43ec8732014-03-31 15:00:14 +0100504 break;
505 default:
506 strcpy(tbuf, "DecodeError1");
507 break;
508 }
509 buf += tbuf;
510 }
511 } else {
512 buf += *fmt++;
513 }
514 }
515 return buf;
516}
517
518void Arm64Mir2Lir::DumpResourceMask(LIR* arm_lir, uint64_t mask, const char* prefix) {
519 char buf[256];
520 buf[0] = 0;
521
522 if (mask == ENCODE_ALL) {
523 strcpy(buf, "all");
524 } else {
525 char num[8];
526 int i;
527
528 for (i = 0; i < kArmRegEnd; i++) {
529 if (mask & (1ULL << i)) {
530 snprintf(num, arraysize(num), "%d ", i);
531 strcat(buf, num);
532 }
533 }
534
535 if (mask & ENCODE_CCODE) {
536 strcat(buf, "cc ");
537 }
538 if (mask & ENCODE_FP_STATUS) {
539 strcat(buf, "fpcc ");
540 }
541
542 /* Memory bits */
543 if (arm_lir && (mask & ENCODE_DALVIK_REG)) {
544 snprintf(buf + strlen(buf), arraysize(buf) - strlen(buf), "dr%d%s",
545 DECODE_ALIAS_INFO_REG(arm_lir->flags.alias_info),
546 DECODE_ALIAS_INFO_WIDE(arm_lir->flags.alias_info) ? "(+1)" : "");
547 }
548 if (mask & ENCODE_LITERAL) {
549 strcat(buf, "lit ");
550 }
551
552 if (mask & ENCODE_HEAP_REF) {
553 strcat(buf, "heap ");
554 }
555 if (mask & ENCODE_MUST_NOT_ALIAS) {
556 strcat(buf, "noalias ");
557 }
558 }
559 if (buf[0]) {
560 LOG(INFO) << prefix << ": " << buf;
561 }
562}
563
564bool Arm64Mir2Lir::IsUnconditionalBranch(LIR* lir) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100565 return (lir->opcode == kA64B1t);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100566}
567
Vladimir Marko674744e2014-04-24 15:18:26 +0100568bool Arm64Mir2Lir::SupportsVolatileLoadStore(OpSize size) {
569 return true;
570}
571
572RegisterClass Arm64Mir2Lir::RegClassForFieldLoadStore(OpSize size, bool is_volatile) {
573 if (UNLIKELY(is_volatile)) {
574 // On arm64, fp register load/store is atomic only for single bytes.
575 if (size != kSignedByte && size != kUnsignedByte) {
576 return kCoreReg;
577 }
578 }
579 return RegClassBySize(size);
580}
581
Matteo Franchin43ec8732014-03-31 15:00:14 +0100582Arm64Mir2Lir::Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena)
583 : Mir2Lir(cu, mir_graph, arena) {
584 // Sanity check - make sure encoding map lines up.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100585 for (int i = 0; i < kA64Last; i++) {
586 if (UNWIDE(Arm64Mir2Lir::EncodingMap[i].opcode) != i) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100587 LOG(FATAL) << "Encoding order for " << Arm64Mir2Lir::EncodingMap[i].name
588 << " is wrong: expecting " << i << ", seeing "
589 << static_cast<int>(Arm64Mir2Lir::EncodingMap[i].opcode);
590 }
591 }
592}
593
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100594Mir2Lir* Arm64CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
595 ArenaAllocator* const arena) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100596 return new Arm64Mir2Lir(cu, mir_graph, arena);
597}
598
Matteo Franchin43ec8732014-03-31 15:00:14 +0100599void Arm64Mir2Lir::CompilerInitializeRegAlloc() {
buzbeeb01bf152014-05-13 15:59:07 -0700600 reg_pool_ = new (arena_) RegisterPool(this, arena_, core_regs, core64_regs, sp_regs, dp_regs,
601 reserved_regs, reserved64_regs, core_temps, core64_temps,
602 sp_temps, dp_temps);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100603
604 // Target-specific adjustments.
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100605 // Alias single precision float registers to corresponding double registers.
606 GrowableArray<RegisterInfo*>::Iterator fp_it(&reg_pool_->sp_regs_);
607 for (RegisterInfo* info = fp_it.Next(); info != nullptr; info = fp_it.Next()) {
608 int fp_reg_num = info->GetReg().GetRegNum();
609 RegStorage dp_reg = RegStorage::Solo64(RegStorage::kFloatingPoint | fp_reg_num);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100610 RegisterInfo* dp_reg_info = GetRegInfo(dp_reg);
611 // Double precision register's master storage should refer to itself.
612 DCHECK_EQ(dp_reg_info, dp_reg_info->Master());
613 // Redirect single precision's master storage to master.
614 info->SetMaster(dp_reg_info);
615 // Singles should show a single 32-bit mask bit, at first referring to the low half.
616 DCHECK_EQ(info->StorageMask(), 0x1U);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100617 }
618
619 // TODO: re-enable this when we can safely save r4 over the suspension code path.
620 bool no_suspend = NO_SUSPEND; // || !Runtime::Current()->ExplicitSuspendChecks();
621 if (no_suspend) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100622 GetRegInfo(rs_rA64_SUSPEND)->MarkFree();
Matteo Franchin43ec8732014-03-31 15:00:14 +0100623 }
624
625 // Don't start allocating temps at r0/s0/d0 or you may clobber return regs in early-exit methods.
626 // TODO: adjust when we roll to hard float calling convention.
627 reg_pool_->next_core_reg_ = 2;
628 reg_pool_->next_sp_reg_ = 0;
629 reg_pool_->next_dp_reg_ = 0;
630}
631
Matteo Franchin43ec8732014-03-31 15:00:14 +0100632/*
633 * TUNING: is true leaf? Can't just use METHOD_IS_LEAF to determine as some
634 * instructions might call out to C/assembly helper functions. Until
635 * machinery is in place, always spill lr.
636 */
637
638void Arm64Mir2Lir::AdjustSpillMask() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100639 core_spill_mask_ |= (1 << rs_rA64_LR.GetRegNum());
Matteo Franchin43ec8732014-03-31 15:00:14 +0100640 num_core_spills_++;
641}
642
643/*
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100644 * Mark a callee-save fp register as promoted.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100645 */
646void Arm64Mir2Lir::MarkPreservedSingle(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100647 DCHECK(reg.IsFloat());
648 int adjusted_reg_num = reg.GetRegNum() - A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100649 // Ensure fp_vmap_table is large enough
650 int table_size = fp_vmap_table_.size();
651 for (int i = table_size; i < (adjusted_reg_num + 1); i++) {
652 fp_vmap_table_.push_back(INVALID_VREG);
653 }
654 // Add the current mapping
655 fp_vmap_table_[adjusted_reg_num] = v_reg;
656 // Size of fp_vmap_table is high-water mark, use to set mask
657 num_fp_spills_ = fp_vmap_table_.size();
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100658 fp_spill_mask_ = ((1 << num_fp_spills_) - 1) << A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100659}
660
661void Arm64Mir2Lir::MarkPreservedDouble(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100662 DCHECK(reg.IsDouble());
663 MarkPreservedSingle(v_reg, reg);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100664}
665
666/* Clobber all regs that might be used by an external C call */
667void Arm64Mir2Lir::ClobberCallerSave() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100668 Clobber(rs_x0);
669 Clobber(rs_x1);
670 Clobber(rs_x2);
671 Clobber(rs_x3);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100672 Clobber(rs_x4);
673 Clobber(rs_x5);
674 Clobber(rs_x6);
675 Clobber(rs_x7);
676 Clobber(rs_x8);
677 Clobber(rs_x9);
678 Clobber(rs_x10);
679 Clobber(rs_x11);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100680 Clobber(rs_x12);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100681 Clobber(rs_x13);
682 Clobber(rs_x14);
683 Clobber(rs_x15);
684 Clobber(rs_x16);
685 Clobber(rs_x17);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100686 Clobber(rs_x30);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100687
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100688 Clobber(rs_f0);
689 Clobber(rs_f1);
690 Clobber(rs_f2);
691 Clobber(rs_f3);
692 Clobber(rs_f4);
693 Clobber(rs_f5);
694 Clobber(rs_f6);
695 Clobber(rs_f7);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100696 Clobber(rs_f16);
697 Clobber(rs_f17);
698 Clobber(rs_f18);
699 Clobber(rs_f19);
700 Clobber(rs_f20);
701 Clobber(rs_f21);
702 Clobber(rs_f22);
703 Clobber(rs_f23);
704 Clobber(rs_f24);
705 Clobber(rs_f25);
706 Clobber(rs_f26);
707 Clobber(rs_f27);
708 Clobber(rs_f28);
709 Clobber(rs_f29);
710 Clobber(rs_f30);
711 Clobber(rs_f31);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100712}
713
714RegLocation Arm64Mir2Lir::GetReturnWideAlt() {
715 RegLocation res = LocCReturnWide();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100716 res.reg.SetReg(rx2);
717 res.reg.SetHighReg(rx3);
718 Clobber(rs_x2);
719 Clobber(rs_x3);
720 MarkInUse(rs_x2);
721 MarkInUse(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100722 MarkWide(res.reg);
723 return res;
724}
725
726RegLocation Arm64Mir2Lir::GetReturnAlt() {
727 RegLocation res = LocCReturn();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100728 res.reg.SetReg(rx1);
729 Clobber(rs_x1);
730 MarkInUse(rs_x1);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100731 return res;
732}
733
734/* To be used when explicitly managing register use */
735void Arm64Mir2Lir::LockCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100736 LockTemp(rs_x0);
737 LockTemp(rs_x1);
738 LockTemp(rs_x2);
739 LockTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100740}
741
742/* To be used when explicitly managing register use */
743void Arm64Mir2Lir::FreeCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100744 FreeTemp(rs_x0);
745 FreeTemp(rs_x1);
746 FreeTemp(rs_x2);
747 FreeTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100748}
749
Andreas Gampe2f244e92014-05-08 03:35:25 -0700750RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<4> offset) {
751 UNIMPLEMENTED(FATAL) << "Should not be called.";
752 return RegStorage::InvalidReg();
753}
754
755RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<8> offset) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100756 // TODO(Arm64): use LoadWordDisp instead.
757 // e.g. LoadWordDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR);
758 LoadBaseDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR, k64);
759 return rs_rA64_LR;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100760}
761
762LIR* Arm64Mir2Lir::CheckSuspendUsingLoad() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100763 RegStorage tmp = rs_x0;
Andreas Gampe2f244e92014-05-08 03:35:25 -0700764 LoadWordDisp(rs_rA64_SELF, Thread::ThreadSuspendTriggerOffset<8>().Int32Value(), tmp);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100765 LIR* load2 = LoadWordDisp(tmp, 0, tmp);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100766 return load2;
767}
768
769uint64_t Arm64Mir2Lir::GetTargetInstFlags(int opcode) {
770 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100771 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].flags;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100772}
773
774const char* Arm64Mir2Lir::GetTargetInstName(int opcode) {
775 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100776 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].name;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100777}
778
779const char* Arm64Mir2Lir::GetTargetInstFmt(int opcode) {
780 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100781 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].fmt;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100782}
783
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100784// TODO(Arm64): reuse info in QuickArgumentVisitor?
785static RegStorage GetArgPhysicalReg(RegLocation* loc, int* num_gpr_used, int* num_fpr_used,
786 OpSize* op_size) {
787 if (loc->fp) {
788 int n = *num_fpr_used;
789 if (n < 8) {
790 *num_fpr_used = n + 1;
791 RegStorage::RegStorageKind reg_kind;
792 if (loc->wide) {
793 *op_size = kDouble;
794 reg_kind = RegStorage::k64BitSolo;
795 } else {
796 *op_size = kSingle;
797 reg_kind = RegStorage::k32BitSolo;
798 }
799 return RegStorage(RegStorage::kValid | reg_kind | RegStorage::kFloatingPoint | n);
800 }
801 } else {
802 int n = *num_gpr_used;
803 if (n < 7) {
804 *num_gpr_used = n + 1;
805 if (loc->wide) {
806 *op_size = k64;
807 return RegStorage::Solo64(n);
808 } else {
809 *op_size = k32;
810 return RegStorage::Solo32(n);
811 }
812 }
813 }
814
815 return RegStorage::InvalidReg();
816}
817
818/*
819 * If there are any ins passed in registers that have not been promoted
820 * to a callee-save register, flush them to the frame. Perform initial
821 * assignment of promoted arguments.
822 *
823 * ArgLocs is an array of location records describing the incoming arguments
824 * with one location record per word of argument.
825 */
826void Arm64Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
827 int num_gpr_used = 1;
828 int num_fpr_used = 0;
829
830 /*
831 * Dummy up a RegLocation for the incoming Method*
832 * It will attempt to keep kArg0 live (or copy it to home location
833 * if promoted).
834 */
835 RegLocation rl_src = rl_method;
836 rl_src.location = kLocPhysReg;
837 rl_src.reg = TargetReg(kArg0);
838 rl_src.home = false;
839 MarkLive(rl_src);
840
Zheng Xuc8304302014-05-15 17:21:01 +0100841 // rl_method might be 32-bit, but ArtMethod* on stack is 64-bit, so always flush it.
842 StoreWordDisp(TargetReg(kSp), 0, TargetReg(kArg0));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100843
Zheng Xuc8304302014-05-15 17:21:01 +0100844 // If Method* has been promoted, load it,
845 // otherwise, rl_method is the 32-bit value on [sp], and has already been loaded.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100846 if (rl_method.location == kLocPhysReg) {
Zheng Xuc8304302014-05-15 17:21:01 +0100847 StoreValue(rl_method, rl_src);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100848 }
849
850 if (cu_->num_ins == 0) {
851 return;
852 }
853
854 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
855 for (int i = 0; i < cu_->num_ins; i++) {
856 PromotionMap* v_map = &promotion_map_[start_vreg + i];
857 RegLocation* t_loc = &ArgLocs[i];
858 OpSize op_size;
859 RegStorage reg = GetArgPhysicalReg(t_loc, &num_gpr_used, &num_fpr_used, &op_size);
860
861 if (reg.Valid()) {
862 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
863 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
864 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
865 OpRegCopy(RegStorage::Solo32(v_map->FpReg), reg);
866 } else {
867 StoreBaseDisp(TargetReg(kSp), SRegOffset(start_vreg + i), reg, op_size);
868 if (reg.Is64Bit()) {
869 if (SRegOffset(start_vreg + i) + 4 != SRegOffset(start_vreg + i + 1)) {
870 LOG(FATAL) << "64 bit value stored in non-consecutive 4 bytes slots";
871 }
872 i += 1;
873 }
874 }
875 } else {
876 // If arriving in frame & promoted
877 if (v_map->core_location == kLocPhysReg) {
878 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i),
879 RegStorage::Solo32(v_map->core_reg));
880 }
881 if (v_map->fp_location == kLocPhysReg) {
882 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg));
883 }
884 }
885 }
886}
887
888int Arm64Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
889 NextCallInsn next_call_insn,
890 const MethodReference& target_method,
891 uint32_t vtable_idx, uintptr_t direct_code,
892 uintptr_t direct_method, InvokeType type, bool skip_this) {
893 int last_arg_reg = TargetReg(kArg3).GetReg();
894 int next_reg = TargetReg(kArg1).GetReg();
895 int next_arg = 0;
896 if (skip_this) {
897 next_reg++;
898 next_arg++;
899 }
900 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
901 RegLocation rl_arg = info->args[next_arg++];
902 rl_arg = UpdateRawLoc(rl_arg);
903 if (rl_arg.wide && (next_reg <= TargetReg(kArg2).GetReg())) {
904 RegStorage r_tmp(RegStorage::k64BitPair, next_reg, next_reg + 1);
905 LoadValueDirectWideFixed(rl_arg, r_tmp);
906 next_reg++;
907 next_arg++;
908 } else {
909 if (rl_arg.wide) {
910 rl_arg = NarrowRegLoc(rl_arg);
911 rl_arg.is_const = false;
912 }
913 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(next_reg));
914 }
915 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
916 direct_code, direct_method, type);
917 }
918 return call_state;
919}
920
Matteo Franchin43ec8732014-03-31 15:00:14 +0100921} // namespace art