blob: 7539392b7982fb17ba6c868093d5f0a08abdf97e [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
buzbeea0cd2d72014-06-01 09:33:49 -070099RegLocation Arm64Mir2Lir::LocCReturnRef() {
100 return arm_loc_c_return;
101}
102
Matteo Franchin43ec8732014-03-31 15:00:14 +0100103RegLocation Arm64Mir2Lir::LocCReturnWide() {
104 return arm_loc_c_return_wide;
105}
106
107RegLocation Arm64Mir2Lir::LocCReturnFloat() {
108 return arm_loc_c_return_float;
109}
110
111RegLocation Arm64Mir2Lir::LocCReturnDouble() {
112 return arm_loc_c_return_double;
113}
114
115// Return a target-dependent special register.
116RegStorage Arm64Mir2Lir::TargetReg(SpecialTargetRegister reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100117 // TODO(Arm64): this function doesn't work for hard-float ABI.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100118 RegStorage res_reg = RegStorage::InvalidReg();
119 switch (reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100120 case kSelf: res_reg = rs_rA64_SELF; break;
121 case kSuspend: res_reg = rs_rA64_SUSPEND; break;
122 case kLr: res_reg = rs_rA64_LR; break;
123 case kPc: res_reg = RegStorage::InvalidReg(); break;
124 case kSp: res_reg = rs_rA64_SP; break;
125 case kArg0: res_reg = rs_x0; break;
126 case kArg1: res_reg = rs_x1; break;
127 case kArg2: res_reg = rs_x2; break;
128 case kArg3: res_reg = rs_x3; break;
129 case kFArg0: res_reg = rs_f0; break;
130 case kFArg1: res_reg = rs_f1; break;
131 case kFArg2: res_reg = rs_f2; break;
132 case kFArg3: res_reg = rs_f3; break;
133 case kRet0: res_reg = rs_x0; break;
134 case kRet1: res_reg = rs_x0; break;
135 case kInvokeTgt: res_reg = rs_rA64_LR; break;
136 case kHiddenArg: res_reg = rs_x12; break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100137 case kHiddenFpArg: res_reg = RegStorage::InvalidReg(); break;
138 case kCount: res_reg = RegStorage::InvalidReg(); break;
139 }
140 return res_reg;
141}
142
143RegStorage Arm64Mir2Lir::GetArgMappingToPhysicalReg(int arg_num) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100144 return RegStorage::InvalidReg();
Matteo Franchin43ec8732014-03-31 15:00:14 +0100145}
146
147/*
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100148 * Decode the register id. This routine makes assumptions on the encoding made by RegStorage.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100149 */
150uint64_t Arm64Mir2Lir::GetRegMaskCommon(RegStorage reg) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100151 // TODO(Arm64): this function depends too much on the internal RegStorage encoding. Refactor.
152
153 int reg_raw = reg.GetRawBits();
154 // Check if the shape mask is zero (i.e. invalid).
155 if (UNLIKELY(reg == rs_wzr || reg == rs_xzr)) {
156 // The zero register is not a true register. It is just an immediate zero.
157 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100158 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100159
160 return UINT64_C(1) << (reg_raw & RegStorage::kRegTypeMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100161}
162
163uint64_t Arm64Mir2Lir::GetPCUseDefEncoding() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100164 LOG(FATAL) << "Unexpected call to GetPCUseDefEncoding for Arm64";
165 return 0ULL;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100166}
167
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100168// Arm64 specific setup. TODO: inline?:
Matteo Franchin43ec8732014-03-31 15:00:14 +0100169void Arm64Mir2Lir::SetupTargetResourceMasks(LIR* lir, uint64_t flags) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100170 DCHECK_EQ(cu_->instruction_set, kArm64);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100171 DCHECK(!lir->flags.use_def_invalid);
172
Matteo Franchin43ec8732014-03-31 15:00:14 +0100173 // These flags are somewhat uncommon - bypass if we can.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100174 if ((flags & (REG_DEF_SP | REG_USE_SP | REG_DEF_LR)) != 0) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100175 if (flags & REG_DEF_SP) {
176 lir->u.m.def_mask |= ENCODE_ARM_REG_SP;
177 }
178
179 if (flags & REG_USE_SP) {
180 lir->u.m.use_mask |= ENCODE_ARM_REG_SP;
181 }
182
Matteo Franchin43ec8732014-03-31 15:00:14 +0100183 if (flags & REG_DEF_LR) {
184 lir->u.m.def_mask |= ENCODE_ARM_REG_LR;
185 }
186 }
187}
188
189ArmConditionCode Arm64Mir2Lir::ArmConditionEncoding(ConditionCode ccode) {
190 ArmConditionCode res;
191 switch (ccode) {
192 case kCondEq: res = kArmCondEq; break;
193 case kCondNe: res = kArmCondNe; break;
194 case kCondCs: res = kArmCondCs; break;
195 case kCondCc: res = kArmCondCc; break;
196 case kCondUlt: res = kArmCondCc; break;
197 case kCondUge: res = kArmCondCs; break;
198 case kCondMi: res = kArmCondMi; break;
199 case kCondPl: res = kArmCondPl; break;
200 case kCondVs: res = kArmCondVs; break;
201 case kCondVc: res = kArmCondVc; break;
202 case kCondHi: res = kArmCondHi; break;
203 case kCondLs: res = kArmCondLs; break;
204 case kCondGe: res = kArmCondGe; break;
205 case kCondLt: res = kArmCondLt; break;
206 case kCondGt: res = kArmCondGt; break;
207 case kCondLe: res = kArmCondLe; break;
208 case kCondAl: res = kArmCondAl; break;
209 case kCondNv: res = kArmCondNv; break;
210 default:
211 LOG(FATAL) << "Bad condition code " << ccode;
212 res = static_cast<ArmConditionCode>(0); // Quiet gcc
213 }
214 return res;
215}
216
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100217static const char *shift_names[4] = {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100218 "lsl",
219 "lsr",
220 "asr",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100221 "ror"
222};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100223
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100224static const char* extend_names[8] = {
225 "uxtb",
226 "uxth",
227 "uxtw",
228 "uxtx",
229 "sxtb",
230 "sxth",
231 "sxtw",
232 "sxtx",
233};
234
235/* Decode and print a register extension (e.g. ", uxtb #1") */
236static void DecodeRegExtendOrShift(int operand, char *buf, size_t buf_size) {
237 if ((operand & (1 << 6)) == 0) {
238 const char *shift_name = shift_names[(operand >> 7) & 0x3];
239 int amount = operand & 0x3f;
240 snprintf(buf, buf_size, ", %s #%d", shift_name, amount);
241 } else {
242 const char *extend_name = extend_names[(operand >> 3) & 0x7];
243 int amount = operand & 0x7;
244 if (amount == 0) {
245 snprintf(buf, buf_size, ", %s", extend_name);
246 } else {
247 snprintf(buf, buf_size, ", %s #%d", extend_name, amount);
248 }
249 }
250}
251
252#define BIT_MASK(w) ((UINT64_C(1) << (w)) - UINT64_C(1))
253
254static uint64_t RotateRight(uint64_t value, unsigned rotate, unsigned width) {
255 DCHECK_LE(width, 64U);
256 rotate &= 63;
257 value = value & BIT_MASK(width);
258 return ((value & BIT_MASK(rotate)) << (width - rotate)) | (value >> rotate);
259}
260
261static uint64_t RepeatBitsAcrossReg(bool is_wide, uint64_t value, unsigned width) {
262 unsigned i;
263 unsigned reg_size = (is_wide) ? 64 : 32;
264 uint64_t result = value & BIT_MASK(width);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100265 for (i = width; i < reg_size; i *= 2) {
266 result |= (result << i);
267 }
268 DCHECK_EQ(i, reg_size);
269 return result;
270}
271
272/**
273 * @brief Decode an immediate in the form required by logical instructions.
274 *
275 * @param is_wide Whether @p value encodes a 64-bit (as opposed to 32-bit) immediate.
276 * @param value The encoded logical immediates that is to be decoded.
277 * @return The decoded logical immediate.
278 * @note This is the inverse of Arm64Mir2Lir::EncodeLogicalImmediate().
279 */
280uint64_t Arm64Mir2Lir::DecodeLogicalImmediate(bool is_wide, int value) {
281 unsigned n = (value >> 12) & 0x01;
282 unsigned imm_r = (value >> 6) & 0x3f;
283 unsigned imm_s = (value >> 0) & 0x3f;
284
285 // An integer is constructed from the n, imm_s and imm_r bits according to
286 // the following table:
287 //
288 // N imms immr size S R
289 // 1 ssssss rrrrrr 64 UInt(ssssss) UInt(rrrrrr)
290 // 0 0sssss xrrrrr 32 UInt(sssss) UInt(rrrrr)
291 // 0 10ssss xxrrrr 16 UInt(ssss) UInt(rrrr)
292 // 0 110sss xxxrrr 8 UInt(sss) UInt(rrr)
293 // 0 1110ss xxxxrr 4 UInt(ss) UInt(rr)
294 // 0 11110s xxxxxr 2 UInt(s) UInt(r)
295 // (s bits must not be all set)
296 //
297 // A pattern is constructed of size bits, where the least significant S+1
298 // bits are set. The pattern is rotated right by R, and repeated across a
299 // 32 or 64-bit value, depending on destination register width.
300
301 if (n == 1) {
302 DCHECK_NE(imm_s, 0x3fU);
303 uint64_t bits = BIT_MASK(imm_s + 1);
304 return RotateRight(bits, imm_r, 64);
305 } else {
306 DCHECK_NE((imm_s >> 1), 0x1fU);
307 for (unsigned width = 0x20; width >= 0x2; width >>= 1) {
308 if ((imm_s & width) == 0) {
309 unsigned mask = (unsigned)(width - 1);
310 DCHECK_NE((imm_s & mask), mask);
311 uint64_t bits = BIT_MASK((imm_s & mask) + 1);
312 return RepeatBitsAcrossReg(is_wide, RotateRight(bits, imm_r & mask, width), width);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100313 }
314 }
315 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100316 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100317}
318
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100319/**
320 * @brief Decode an 8-bit single point number encoded with EncodeImmSingle().
321 */
322static float DecodeImmSingle(uint8_t small_float) {
323 int mantissa = (small_float & 0x0f) + 0x10;
324 int sign = ((small_float & 0x80) == 0) ? 1 : -1;
325 float signed_mantissa = static_cast<float>(sign*mantissa);
326 int exponent = (((small_float >> 4) & 0x7) + 4) & 0x7;
327 return signed_mantissa*static_cast<float>(1 << exponent)*0.0078125f;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100328}
329
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100330static const char* cc_names[] = {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
331 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100332/*
333 * Interpret a format string and build a string no longer than size
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100334 * See format key in assemble_arm64.cc.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100335 */
336std::string Arm64Mir2Lir::BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) {
337 std::string buf;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100338 const char* fmt_end = &fmt[strlen(fmt)];
339 char tbuf[256];
340 const char* name;
341 char nc;
342 while (fmt < fmt_end) {
343 int operand;
344 if (*fmt == '!') {
345 fmt++;
346 DCHECK_LT(fmt, fmt_end);
347 nc = *fmt++;
348 if (nc == '!') {
349 strcpy(tbuf, "!");
350 } else {
351 DCHECK_LT(fmt, fmt_end);
352 DCHECK_LT(static_cast<unsigned>(nc-'0'), 4U);
353 operand = lir->operands[nc-'0'];
354 switch (*fmt++) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100355 case 'e': {
356 // Omit ", uxtw #0" in strings like "add w0, w1, w3, uxtw #0" and
357 // ", uxtx #0" in strings like "add x0, x1, x3, uxtx #0"
358 int omittable = ((IS_WIDE(lir->opcode)) ? EncodeExtend(kA64Uxtw, 0) :
359 EncodeExtend(kA64Uxtw, 0));
360 if (LIKELY(operand == omittable)) {
361 strcpy(tbuf, "");
362 } else {
363 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
364 }
365 }
366 break;
367 case 'o':
368 // Omit ", lsl #0"
369 if (LIKELY(operand == EncodeShift(kA64Lsl, 0))) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100370 strcpy(tbuf, "");
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100371 } else {
372 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100373 }
374 break;
375 case 'B':
376 switch (operand) {
377 case kSY:
378 name = "sy";
379 break;
380 case kST:
381 name = "st";
382 break;
383 case kISH:
384 name = "ish";
385 break;
386 case kISHST:
387 name = "ishst";
388 break;
389 case kNSH:
390 name = "nsh";
391 break;
392 case kNSHST:
393 name = "shst";
394 break;
395 default:
396 name = "DecodeError2";
397 break;
398 }
399 strcpy(tbuf, name);
400 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100401 case 's':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100402 snprintf(tbuf, arraysize(tbuf), "s%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100403 break;
404 case 'S':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100405 snprintf(tbuf, arraysize(tbuf), "d%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100406 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100407 case 'f':
408 snprintf(tbuf, arraysize(tbuf), "%c%d", (IS_FWIDE(lir->opcode)) ? 'd' : 's',
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100409 operand & RegStorage::kRegNumMask);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100410 break;
411 case 'l': {
412 bool is_wide = IS_WIDE(lir->opcode);
413 uint64_t imm = DecodeLogicalImmediate(is_wide, operand);
414 snprintf(tbuf, arraysize(tbuf), "%" PRId64 " (%#" PRIx64 ")", imm, imm);
415 }
416 break;
417 case 'I':
418 snprintf(tbuf, arraysize(tbuf), "%f", DecodeImmSingle(operand));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100419 break;
420 case 'M':
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100421 if (LIKELY(operand == 0))
422 strcpy(tbuf, "");
423 else
424 snprintf(tbuf, arraysize(tbuf), ", lsl #%d", 16*operand);
425 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100426 case 'd':
427 snprintf(tbuf, arraysize(tbuf), "%d", operand);
428 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100429 case 'w':
430 if (LIKELY(operand != rwzr))
431 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
432 else
433 strcpy(tbuf, "wzr");
434 break;
435 case 'W':
436 if (LIKELY(operand != rwsp))
437 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
438 else
439 strcpy(tbuf, "wsp");
440 break;
441 case 'x':
442 if (LIKELY(operand != rxzr))
443 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
444 else
445 strcpy(tbuf, "xzr");
446 break;
447 case 'X':
448 if (LIKELY(operand != rsp))
449 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
450 else
451 strcpy(tbuf, "sp");
452 break;
453 case 'D':
454 snprintf(tbuf, arraysize(tbuf), "%d", operand*((IS_WIDE(lir->opcode)) ? 8 : 4));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100455 break;
456 case 'E':
457 snprintf(tbuf, arraysize(tbuf), "%d", operand*4);
458 break;
459 case 'F':
460 snprintf(tbuf, arraysize(tbuf), "%d", operand*2);
461 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100462 case 'G':
463 if (LIKELY(operand == 0))
464 strcpy(tbuf, "");
465 else
466 strcpy(tbuf, (IS_WIDE(lir->opcode)) ? ", lsl #3" : ", lsl #2");
467 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100468 case 'c':
469 strcpy(tbuf, cc_names[operand]);
470 break;
471 case 't':
472 snprintf(tbuf, arraysize(tbuf), "0x%08" PRIxPTR " (L%p)",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100473 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + (operand << 2),
Matteo Franchin43ec8732014-03-31 15:00:14 +0100474 lir->target);
475 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100476 case 'r': {
477 bool is_wide = IS_WIDE(lir->opcode);
478 if (LIKELY(operand != rwzr && operand != rxzr)) {
479 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
480 operand & RegStorage::kRegNumMask);
481 } else {
482 strcpy(tbuf, (is_wide) ? "xzr" : "wzr");
483 }
484 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100485 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100486 case 'R': {
487 bool is_wide = IS_WIDE(lir->opcode);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100488 if (LIKELY(operand != rwsp && operand != rsp)) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100489 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
490 operand & RegStorage::kRegNumMask);
491 } else {
492 strcpy(tbuf, (is_wide) ? "sp" : "wsp");
493 }
494 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100495 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100496 case 'p':
497 snprintf(tbuf, arraysize(tbuf), ".+%d (addr %#" PRIxPTR ")", 4*operand,
498 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + 4*operand);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100499 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100500 case 'T':
501 if (LIKELY(operand == 0))
502 strcpy(tbuf, "");
503 else if (operand == 1)
504 strcpy(tbuf, ", lsl #12");
505 else
506 strcpy(tbuf, ", DecodeError3");
Matteo Franchin43ec8732014-03-31 15:00:14 +0100507 break;
508 default:
509 strcpy(tbuf, "DecodeError1");
510 break;
511 }
512 buf += tbuf;
513 }
514 } else {
515 buf += *fmt++;
516 }
517 }
518 return buf;
519}
520
521void Arm64Mir2Lir::DumpResourceMask(LIR* arm_lir, uint64_t mask, const char* prefix) {
522 char buf[256];
523 buf[0] = 0;
524
525 if (mask == ENCODE_ALL) {
526 strcpy(buf, "all");
527 } else {
528 char num[8];
529 int i;
530
531 for (i = 0; i < kArmRegEnd; i++) {
532 if (mask & (1ULL << i)) {
533 snprintf(num, arraysize(num), "%d ", i);
534 strcat(buf, num);
535 }
536 }
537
538 if (mask & ENCODE_CCODE) {
539 strcat(buf, "cc ");
540 }
541 if (mask & ENCODE_FP_STATUS) {
542 strcat(buf, "fpcc ");
543 }
544
545 /* Memory bits */
546 if (arm_lir && (mask & ENCODE_DALVIK_REG)) {
547 snprintf(buf + strlen(buf), arraysize(buf) - strlen(buf), "dr%d%s",
548 DECODE_ALIAS_INFO_REG(arm_lir->flags.alias_info),
549 DECODE_ALIAS_INFO_WIDE(arm_lir->flags.alias_info) ? "(+1)" : "");
550 }
551 if (mask & ENCODE_LITERAL) {
552 strcat(buf, "lit ");
553 }
554
555 if (mask & ENCODE_HEAP_REF) {
556 strcat(buf, "heap ");
557 }
558 if (mask & ENCODE_MUST_NOT_ALIAS) {
559 strcat(buf, "noalias ");
560 }
561 }
562 if (buf[0]) {
563 LOG(INFO) << prefix << ": " << buf;
564 }
565}
566
567bool Arm64Mir2Lir::IsUnconditionalBranch(LIR* lir) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100568 return (lir->opcode == kA64B1t);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100569}
570
Vladimir Marko674744e2014-04-24 15:18:26 +0100571bool Arm64Mir2Lir::SupportsVolatileLoadStore(OpSize size) {
572 return true;
573}
574
575RegisterClass Arm64Mir2Lir::RegClassForFieldLoadStore(OpSize size, bool is_volatile) {
576 if (UNLIKELY(is_volatile)) {
577 // On arm64, fp register load/store is atomic only for single bytes.
578 if (size != kSignedByte && size != kUnsignedByte) {
buzbeea0cd2d72014-06-01 09:33:49 -0700579 return (size == kReference) ? kRefReg : kCoreReg;
Vladimir Marko674744e2014-04-24 15:18:26 +0100580 }
581 }
582 return RegClassBySize(size);
583}
584
Matteo Franchin43ec8732014-03-31 15:00:14 +0100585Arm64Mir2Lir::Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena)
586 : Mir2Lir(cu, mir_graph, arena) {
587 // Sanity check - make sure encoding map lines up.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100588 for (int i = 0; i < kA64Last; i++) {
589 if (UNWIDE(Arm64Mir2Lir::EncodingMap[i].opcode) != i) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100590 LOG(FATAL) << "Encoding order for " << Arm64Mir2Lir::EncodingMap[i].name
591 << " is wrong: expecting " << i << ", seeing "
592 << static_cast<int>(Arm64Mir2Lir::EncodingMap[i].opcode);
593 }
594 }
595}
596
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100597Mir2Lir* Arm64CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
598 ArenaAllocator* const arena) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100599 return new Arm64Mir2Lir(cu, mir_graph, arena);
600}
601
Matteo Franchin43ec8732014-03-31 15:00:14 +0100602void Arm64Mir2Lir::CompilerInitializeRegAlloc() {
buzbeeb01bf152014-05-13 15:59:07 -0700603 reg_pool_ = new (arena_) RegisterPool(this, arena_, core_regs, core64_regs, sp_regs, dp_regs,
604 reserved_regs, reserved64_regs, core_temps, core64_temps,
605 sp_temps, dp_temps);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100606
607 // Target-specific adjustments.
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100608 // Alias single precision float registers to corresponding double registers.
609 GrowableArray<RegisterInfo*>::Iterator fp_it(&reg_pool_->sp_regs_);
610 for (RegisterInfo* info = fp_it.Next(); info != nullptr; info = fp_it.Next()) {
611 int fp_reg_num = info->GetReg().GetRegNum();
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100612 RegStorage dp_reg = RegStorage::FloatSolo64(fp_reg_num);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100613 RegisterInfo* dp_reg_info = GetRegInfo(dp_reg);
614 // Double precision register's master storage should refer to itself.
615 DCHECK_EQ(dp_reg_info, dp_reg_info->Master());
616 // Redirect single precision's master storage to master.
617 info->SetMaster(dp_reg_info);
618 // Singles should show a single 32-bit mask bit, at first referring to the low half.
619 DCHECK_EQ(info->StorageMask(), 0x1U);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100620 }
621
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100622 // Alias 32bit W registers to corresponding 64bit X registers.
623 GrowableArray<RegisterInfo*>::Iterator w_it(&reg_pool_->core_regs_);
624 for (RegisterInfo* info = w_it.Next(); info != nullptr; info = w_it.Next()) {
625 int x_reg_num = info->GetReg().GetRegNum();
626 RegStorage x_reg = RegStorage::Solo64(x_reg_num);
627 RegisterInfo* x_reg_info = GetRegInfo(x_reg);
628 // 64bit X register's master storage should refer to itself.
629 DCHECK_EQ(x_reg_info, x_reg_info->Master());
630 // Redirect 32bit W master storage to 64bit X.
631 info->SetMaster(x_reg_info);
632 // 32bit W should show a single 32-bit mask bit, at first referring to the low half.
633 DCHECK_EQ(info->StorageMask(), 0x1U);
634 }
635
Matteo Franchin43ec8732014-03-31 15:00:14 +0100636 // Don't start allocating temps at r0/s0/d0 or you may clobber return regs in early-exit methods.
637 // TODO: adjust when we roll to hard float calling convention.
638 reg_pool_->next_core_reg_ = 2;
639 reg_pool_->next_sp_reg_ = 0;
640 reg_pool_->next_dp_reg_ = 0;
641}
642
Matteo Franchin43ec8732014-03-31 15:00:14 +0100643/*
644 * TUNING: is true leaf? Can't just use METHOD_IS_LEAF to determine as some
645 * instructions might call out to C/assembly helper functions. Until
646 * machinery is in place, always spill lr.
647 */
648
649void Arm64Mir2Lir::AdjustSpillMask() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100650 core_spill_mask_ |= (1 << rs_rA64_LR.GetRegNum());
Matteo Franchin43ec8732014-03-31 15:00:14 +0100651 num_core_spills_++;
652}
653
654/*
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100655 * Mark a callee-save fp register as promoted.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100656 */
657void Arm64Mir2Lir::MarkPreservedSingle(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100658 DCHECK(reg.IsFloat());
659 int adjusted_reg_num = reg.GetRegNum() - A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100660 // Ensure fp_vmap_table is large enough
661 int table_size = fp_vmap_table_.size();
662 for (int i = table_size; i < (adjusted_reg_num + 1); i++) {
663 fp_vmap_table_.push_back(INVALID_VREG);
664 }
665 // Add the current mapping
666 fp_vmap_table_[adjusted_reg_num] = v_reg;
667 // Size of fp_vmap_table is high-water mark, use to set mask
668 num_fp_spills_ = fp_vmap_table_.size();
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100669 fp_spill_mask_ = ((1 << num_fp_spills_) - 1) << A64_FP_CALLEE_SAVE_BASE;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100670}
671
672void Arm64Mir2Lir::MarkPreservedDouble(int v_reg, RegStorage reg) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100673 DCHECK(reg.IsDouble());
674 MarkPreservedSingle(v_reg, reg);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100675}
676
677/* Clobber all regs that might be used by an external C call */
678void Arm64Mir2Lir::ClobberCallerSave() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100679 Clobber(rs_x0);
680 Clobber(rs_x1);
681 Clobber(rs_x2);
682 Clobber(rs_x3);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100683 Clobber(rs_x4);
684 Clobber(rs_x5);
685 Clobber(rs_x6);
686 Clobber(rs_x7);
687 Clobber(rs_x8);
688 Clobber(rs_x9);
689 Clobber(rs_x10);
690 Clobber(rs_x11);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100691 Clobber(rs_x12);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100692 Clobber(rs_x13);
693 Clobber(rs_x14);
694 Clobber(rs_x15);
695 Clobber(rs_x16);
696 Clobber(rs_x17);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100697 Clobber(rs_x30);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100698
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100699 Clobber(rs_f0);
700 Clobber(rs_f1);
701 Clobber(rs_f2);
702 Clobber(rs_f3);
703 Clobber(rs_f4);
704 Clobber(rs_f5);
705 Clobber(rs_f6);
706 Clobber(rs_f7);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100707 Clobber(rs_f16);
708 Clobber(rs_f17);
709 Clobber(rs_f18);
710 Clobber(rs_f19);
711 Clobber(rs_f20);
712 Clobber(rs_f21);
713 Clobber(rs_f22);
714 Clobber(rs_f23);
715 Clobber(rs_f24);
716 Clobber(rs_f25);
717 Clobber(rs_f26);
718 Clobber(rs_f27);
719 Clobber(rs_f28);
720 Clobber(rs_f29);
721 Clobber(rs_f30);
722 Clobber(rs_f31);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100723}
724
725RegLocation Arm64Mir2Lir::GetReturnWideAlt() {
726 RegLocation res = LocCReturnWide();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100727 res.reg.SetReg(rx2);
728 res.reg.SetHighReg(rx3);
729 Clobber(rs_x2);
730 Clobber(rs_x3);
731 MarkInUse(rs_x2);
732 MarkInUse(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100733 MarkWide(res.reg);
734 return res;
735}
736
737RegLocation Arm64Mir2Lir::GetReturnAlt() {
738 RegLocation res = LocCReturn();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100739 res.reg.SetReg(rx1);
740 Clobber(rs_x1);
741 MarkInUse(rs_x1);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100742 return res;
743}
744
745/* To be used when explicitly managing register use */
746void Arm64Mir2Lir::LockCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100747 LockTemp(rs_x0);
748 LockTemp(rs_x1);
749 LockTemp(rs_x2);
750 LockTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100751}
752
753/* To be used when explicitly managing register use */
754void Arm64Mir2Lir::FreeCallTemps() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100755 FreeTemp(rs_x0);
756 FreeTemp(rs_x1);
757 FreeTemp(rs_x2);
758 FreeTemp(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100759}
760
Andreas Gampe2f244e92014-05-08 03:35:25 -0700761RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<4> offset) {
762 UNIMPLEMENTED(FATAL) << "Should not be called.";
763 return RegStorage::InvalidReg();
764}
765
766RegStorage Arm64Mir2Lir::LoadHelper(ThreadOffset<8> offset) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100767 // TODO(Arm64): use LoadWordDisp instead.
768 // e.g. LoadWordDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR);
769 LoadBaseDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR, k64);
770 return rs_rA64_LR;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100771}
772
773LIR* Arm64Mir2Lir::CheckSuspendUsingLoad() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100774 RegStorage tmp = rs_x0;
Andreas Gampe2f244e92014-05-08 03:35:25 -0700775 LoadWordDisp(rs_rA64_SELF, Thread::ThreadSuspendTriggerOffset<8>().Int32Value(), tmp);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100776 LIR* load2 = LoadWordDisp(tmp, 0, tmp);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100777 return load2;
778}
779
780uint64_t Arm64Mir2Lir::GetTargetInstFlags(int opcode) {
781 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100782 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].flags;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100783}
784
785const char* Arm64Mir2Lir::GetTargetInstName(int opcode) {
786 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100787 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].name;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100788}
789
790const char* Arm64Mir2Lir::GetTargetInstFmt(int opcode) {
791 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100792 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].fmt;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100793}
794
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100795// TODO(Arm64): reuse info in QuickArgumentVisitor?
796static RegStorage GetArgPhysicalReg(RegLocation* loc, int* num_gpr_used, int* num_fpr_used,
797 OpSize* op_size) {
798 if (loc->fp) {
799 int n = *num_fpr_used;
800 if (n < 8) {
801 *num_fpr_used = n + 1;
802 RegStorage::RegStorageKind reg_kind;
803 if (loc->wide) {
804 *op_size = kDouble;
805 reg_kind = RegStorage::k64BitSolo;
806 } else {
807 *op_size = kSingle;
808 reg_kind = RegStorage::k32BitSolo;
809 }
810 return RegStorage(RegStorage::kValid | reg_kind | RegStorage::kFloatingPoint | n);
811 }
812 } else {
813 int n = *num_gpr_used;
814 if (n < 7) {
815 *num_gpr_used = n + 1;
816 if (loc->wide) {
817 *op_size = k64;
818 return RegStorage::Solo64(n);
819 } else {
820 *op_size = k32;
821 return RegStorage::Solo32(n);
822 }
823 }
824 }
825
826 return RegStorage::InvalidReg();
827}
828
829/*
830 * If there are any ins passed in registers that have not been promoted
831 * to a callee-save register, flush them to the frame. Perform initial
832 * assignment of promoted arguments.
833 *
834 * ArgLocs is an array of location records describing the incoming arguments
835 * with one location record per word of argument.
836 */
837void Arm64Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
838 int num_gpr_used = 1;
839 int num_fpr_used = 0;
840
841 /*
842 * Dummy up a RegLocation for the incoming Method*
843 * It will attempt to keep kArg0 live (or copy it to home location
844 * if promoted).
845 */
846 RegLocation rl_src = rl_method;
847 rl_src.location = kLocPhysReg;
848 rl_src.reg = TargetReg(kArg0);
849 rl_src.home = false;
850 MarkLive(rl_src);
851
Zheng Xuc8304302014-05-15 17:21:01 +0100852 // rl_method might be 32-bit, but ArtMethod* on stack is 64-bit, so always flush it.
853 StoreWordDisp(TargetReg(kSp), 0, TargetReg(kArg0));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100854
Zheng Xuc8304302014-05-15 17:21:01 +0100855 // If Method* has been promoted, load it,
856 // otherwise, rl_method is the 32-bit value on [sp], and has already been loaded.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100857 if (rl_method.location == kLocPhysReg) {
Zheng Xuc8304302014-05-15 17:21:01 +0100858 StoreValue(rl_method, rl_src);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100859 }
860
861 if (cu_->num_ins == 0) {
862 return;
863 }
864
865 int start_vreg = cu_->num_dalvik_registers - cu_->num_ins;
866 for (int i = 0; i < cu_->num_ins; i++) {
867 PromotionMap* v_map = &promotion_map_[start_vreg + i];
868 RegLocation* t_loc = &ArgLocs[i];
869 OpSize op_size;
870 RegStorage reg = GetArgPhysicalReg(t_loc, &num_gpr_used, &num_fpr_used, &op_size);
871
872 if (reg.Valid()) {
873 if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
874 OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
875 } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
876 OpRegCopy(RegStorage::Solo32(v_map->FpReg), reg);
877 } else {
878 StoreBaseDisp(TargetReg(kSp), SRegOffset(start_vreg + i), reg, op_size);
879 if (reg.Is64Bit()) {
880 if (SRegOffset(start_vreg + i) + 4 != SRegOffset(start_vreg + i + 1)) {
881 LOG(FATAL) << "64 bit value stored in non-consecutive 4 bytes slots";
882 }
883 i += 1;
884 }
885 }
886 } else {
887 // If arriving in frame & promoted
888 if (v_map->core_location == kLocPhysReg) {
889 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i),
890 RegStorage::Solo32(v_map->core_reg));
891 }
892 if (v_map->fp_location == kLocPhysReg) {
893 LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg));
894 }
895 }
896 }
897}
898
899int Arm64Mir2Lir::LoadArgRegs(CallInfo* info, int call_state,
900 NextCallInsn next_call_insn,
901 const MethodReference& target_method,
902 uint32_t vtable_idx, uintptr_t direct_code,
903 uintptr_t direct_method, InvokeType type, bool skip_this) {
904 int last_arg_reg = TargetReg(kArg3).GetReg();
905 int next_reg = TargetReg(kArg1).GetReg();
906 int next_arg = 0;
907 if (skip_this) {
908 next_reg++;
909 next_arg++;
910 }
911 for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) {
912 RegLocation rl_arg = info->args[next_arg++];
913 rl_arg = UpdateRawLoc(rl_arg);
914 if (rl_arg.wide && (next_reg <= TargetReg(kArg2).GetReg())) {
915 RegStorage r_tmp(RegStorage::k64BitPair, next_reg, next_reg + 1);
916 LoadValueDirectWideFixed(rl_arg, r_tmp);
917 next_reg++;
918 next_arg++;
919 } else {
920 if (rl_arg.wide) {
921 rl_arg = NarrowRegLoc(rl_arg);
922 rl_arg.is_const = false;
923 }
924 LoadValueDirectFixed(rl_arg, RegStorage::Solo32(next_reg));
925 }
926 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
927 direct_code, direct_method, type);
928 }
929 return call_state;
930}
931
Matteo Franchin43ec8732014-03-31 15:00:14 +0100932} // namespace art