blob: ba47883d9e18965ed82e09b270465b09190913d0 [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
Andreas Gampe53c913b2014-08-12 23:19:23 -070023#include "backend_arm64.h"
Matteo Franchin43ec8732014-03-31 15:00:14 +010024#include "dex/compiler_internals.h"
25#include "dex/quick/mir_to_lir-inl.h"
buzbeeb5860fb2014-06-21 15:31:01 -070026#include "dex/reg_storage_eq.h"
Matteo Franchin43ec8732014-03-31 15:00:14 +010027
28namespace art {
29
Vladimir Marko089142c2014-06-05 10:57:05 +010030static constexpr RegStorage core_regs_arr[] =
buzbeeb01bf152014-05-13 15:59:07 -070031 {rs_w0, rs_w1, rs_w2, rs_w3, rs_w4, rs_w5, rs_w6, rs_w7,
32 rs_w8, rs_w9, rs_w10, rs_w11, rs_w12, rs_w13, rs_w14, rs_w15,
33 rs_w16, rs_w17, rs_w18, rs_w19, rs_w20, rs_w21, rs_w22, rs_w23,
34 rs_w24, rs_w25, rs_w26, rs_w27, rs_w28, rs_w29, rs_w30, rs_w31,
35 rs_wzr};
Vladimir Marko089142c2014-06-05 10:57:05 +010036static constexpr RegStorage core64_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010037 {rs_x0, rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7,
38 rs_x8, rs_x9, rs_x10, rs_x11, rs_x12, rs_x13, rs_x14, rs_x15,
39 rs_x16, rs_x17, rs_x18, rs_x19, rs_x20, rs_x21, rs_x22, rs_x23,
Matteo Franchinbc6d1972014-05-13 12:33:28 +010040 rs_x24, rs_x25, rs_x26, rs_x27, rs_x28, rs_x29, rs_x30, rs_x31,
41 rs_xzr};
Vladimir Marko089142c2014-06-05 10:57:05 +010042static constexpr RegStorage sp_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010043 {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7,
44 rs_f8, rs_f9, rs_f10, rs_f11, rs_f12, rs_f13, rs_f14, rs_f15,
45 rs_f16, rs_f17, rs_f18, rs_f19, rs_f20, rs_f21, rs_f22, rs_f23,
46 rs_f24, rs_f25, rs_f26, rs_f27, rs_f28, rs_f29, rs_f30, rs_f31};
Vladimir Marko089142c2014-06-05 10:57:05 +010047static constexpr RegStorage dp_regs_arr[] =
Matteo Franchine45fb9e2014-05-06 10:10:30 +010048 {rs_d0, rs_d1, rs_d2, rs_d3, rs_d4, rs_d5, rs_d6, rs_d7,
Zheng Xuc8304302014-05-15 17:21:01 +010049 rs_d8, rs_d9, rs_d10, rs_d11, rs_d12, rs_d13, rs_d14, rs_d15,
50 rs_d16, rs_d17, rs_d18, rs_d19, rs_d20, rs_d21, rs_d22, rs_d23,
51 rs_d24, rs_d25, rs_d26, rs_d27, rs_d28, rs_d29, rs_d30, rs_d31};
Zheng Xub551fdc2014-07-25 11:49:42 +080052// Note: we are not able to call to C function since rs_xSELF is a special register need to be
53// preserved but would be scratched by native functions follow aapcs64.
Vladimir Marko089142c2014-06-05 10:57:05 +010054static constexpr RegStorage reserved_regs_arr[] =
Zheng Xubaa7c882014-06-30 14:26:50 +080055 {rs_wSUSPEND, rs_wSELF, rs_wsp, rs_wLR, rs_wzr};
Vladimir Marko089142c2014-06-05 10:57:05 +010056static constexpr RegStorage reserved64_regs_arr[] =
Zheng Xubaa7c882014-06-30 14:26:50 +080057 {rs_xSUSPEND, rs_xSELF, rs_sp, rs_xLR, rs_xzr};
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() {
Matteo Franchin4163c532014-07-15 15:20:27 +010087 return a64_loc_c_return;
Matteo Franchin43ec8732014-03-31 15:00:14 +010088}
89
buzbeea0cd2d72014-06-01 09:33:49 -070090RegLocation Arm64Mir2Lir::LocCReturnRef() {
Matteo Franchin4163c532014-07-15 15:20:27 +010091 return a64_loc_c_return_ref;
buzbeea0cd2d72014-06-01 09:33:49 -070092}
93
Matteo Franchin43ec8732014-03-31 15:00:14 +010094RegLocation Arm64Mir2Lir::LocCReturnWide() {
Matteo Franchin4163c532014-07-15 15:20:27 +010095 return a64_loc_c_return_wide;
Matteo Franchin43ec8732014-03-31 15:00:14 +010096}
97
98RegLocation Arm64Mir2Lir::LocCReturnFloat() {
Matteo Franchin4163c532014-07-15 15:20:27 +010099 return a64_loc_c_return_float;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100100}
101
102RegLocation Arm64Mir2Lir::LocCReturnDouble() {
Matteo Franchin4163c532014-07-15 15:20:27 +0100103 return a64_loc_c_return_double;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100104}
105
106// Return a target-dependent special register.
107RegStorage Arm64Mir2Lir::TargetReg(SpecialTargetRegister reg) {
108 RegStorage res_reg = RegStorage::InvalidReg();
109 switch (reg) {
Matteo Franchined7a0f22014-06-10 19:23:45 +0100110 case kSelf: res_reg = rs_wSELF; break;
111 case kSuspend: res_reg = rs_wSUSPEND; break;
112 case kLr: res_reg = rs_wLR; break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100113 case kPc: res_reg = RegStorage::InvalidReg(); break;
Matteo Franchined7a0f22014-06-10 19:23:45 +0100114 case kSp: res_reg = rs_wsp; break;
115 case kArg0: res_reg = rs_w0; break;
116 case kArg1: res_reg = rs_w1; break;
117 case kArg2: res_reg = rs_w2; break;
118 case kArg3: res_reg = rs_w3; break;
119 case kArg4: res_reg = rs_w4; break;
120 case kArg5: res_reg = rs_w5; break;
121 case kArg6: res_reg = rs_w6; break;
122 case kArg7: res_reg = rs_w7; break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100123 case kFArg0: res_reg = rs_f0; break;
124 case kFArg1: res_reg = rs_f1; break;
125 case kFArg2: res_reg = rs_f2; break;
126 case kFArg3: res_reg = rs_f3; break;
buzbee33ae5582014-06-12 14:56:32 -0700127 case kFArg4: res_reg = rs_f4; break;
128 case kFArg5: res_reg = rs_f5; break;
129 case kFArg6: res_reg = rs_f6; break;
130 case kFArg7: res_reg = rs_f7; break;
Matteo Franchined7a0f22014-06-10 19:23:45 +0100131 case kRet0: res_reg = rs_w0; break;
132 case kRet1: res_reg = rs_w1; break;
133 case kInvokeTgt: res_reg = rs_wLR; break;
Zheng Xub551fdc2014-07-25 11:49:42 +0800134 case kHiddenArg: res_reg = rs_wIP1; break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100135 case kHiddenFpArg: res_reg = RegStorage::InvalidReg(); break;
136 case kCount: res_reg = RegStorage::InvalidReg(); break;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700137 default: res_reg = RegStorage::InvalidReg();
Matteo Franchin43ec8732014-03-31 15:00:14 +0100138 }
139 return res_reg;
140}
141
Matteo Franchin43ec8732014-03-31 15:00:14 +0100142/*
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100143 * Decode the register id. This routine makes assumptions on the encoding made by RegStorage.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100144 */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100145ResourceMask Arm64Mir2Lir::GetRegMaskCommon(const RegStorage& reg) const {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100146 // TODO(Arm64): this function depends too much on the internal RegStorage encoding. Refactor.
147
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100148 // Check if the shape mask is zero (i.e. invalid).
149 if (UNLIKELY(reg == rs_wzr || reg == rs_xzr)) {
150 // The zero register is not a true register. It is just an immediate zero.
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100151 return kEncodeNone;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100152 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100153
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100154 return ResourceMask::Bit(
155 // FP register starts at bit position 32.
Matteo Franchin4163c532014-07-15 15:20:27 +0100156 (reg.IsFloat() ? kA64FPReg0 : 0) + reg.GetRegNum());
Matteo Franchin43ec8732014-03-31 15:00:14 +0100157}
158
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100159ResourceMask Arm64Mir2Lir::GetPCUseDefEncoding() const {
Zheng Xu421efca2014-07-11 17:33:59 +0800160 // Note: On arm64, we are not able to set pc except branch instructions, which is regarded as a
161 // kind of barrier. All other instructions only use pc, which has no dependency between any
162 // of them. So it is fine to just return kEncodeNone here.
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100163 return kEncodeNone;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100164}
165
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100166// Arm64 specific setup. TODO: inline?:
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100167void Arm64Mir2Lir::SetupTargetResourceMasks(LIR* lir, uint64_t flags,
168 ResourceMask* use_mask, ResourceMask* def_mask) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100169 DCHECK_EQ(cu_->instruction_set, kArm64);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100170 DCHECK(!lir->flags.use_def_invalid);
171
Zheng Xu421efca2014-07-11 17:33:59 +0800172 // Note: REG_USE_PC is ignored, the reason is the same with what we do in GetPCUseDefEncoding().
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) {
Matteo Franchin4163c532014-07-15 15:20:27 +0100176 def_mask->SetBit(kA64RegSP);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100177 }
178
179 if (flags & REG_USE_SP) {
Matteo Franchin4163c532014-07-15 15:20:27 +0100180 use_mask->SetBit(kA64RegSP);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100181 }
182
Matteo Franchin43ec8732014-03-31 15:00:14 +0100183 if (flags & REG_DEF_LR) {
Matteo Franchin4163c532014-07-15 15:20:27 +0100184 def_mask->SetBit(kA64RegLR);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100185 }
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
buzbeef77e9772014-09-02 15:39:57 -0700252static uint64_t bit_mask(unsigned width) {
253 DCHECK_LE(width, 64U);
254 return (width == 64) ? static_cast<uint64_t>(-1) : ((UINT64_C(1) << (width)) - UINT64_C(1));
255}
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100256
257static uint64_t RotateRight(uint64_t value, unsigned rotate, unsigned width) {
258 DCHECK_LE(width, 64U);
259 rotate &= 63;
buzbeef77e9772014-09-02 15:39:57 -0700260 value = value & bit_mask(width);
261 return ((value & bit_mask(rotate)) << (width - rotate)) | (value >> rotate);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100262}
263
264static uint64_t RepeatBitsAcrossReg(bool is_wide, uint64_t value, unsigned width) {
265 unsigned i;
266 unsigned reg_size = (is_wide) ? 64 : 32;
buzbeef77e9772014-09-02 15:39:57 -0700267 uint64_t result = value & bit_mask(width);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100268 for (i = width; i < reg_size; i *= 2) {
269 result |= (result << i);
270 }
271 DCHECK_EQ(i, reg_size);
272 return result;
273}
274
275/**
276 * @brief Decode an immediate in the form required by logical instructions.
277 *
278 * @param is_wide Whether @p value encodes a 64-bit (as opposed to 32-bit) immediate.
279 * @param value The encoded logical immediates that is to be decoded.
280 * @return The decoded logical immediate.
281 * @note This is the inverse of Arm64Mir2Lir::EncodeLogicalImmediate().
282 */
283uint64_t Arm64Mir2Lir::DecodeLogicalImmediate(bool is_wide, int value) {
284 unsigned n = (value >> 12) & 0x01;
285 unsigned imm_r = (value >> 6) & 0x3f;
286 unsigned imm_s = (value >> 0) & 0x3f;
287
288 // An integer is constructed from the n, imm_s and imm_r bits according to
289 // the following table:
290 //
291 // N imms immr size S R
292 // 1 ssssss rrrrrr 64 UInt(ssssss) UInt(rrrrrr)
293 // 0 0sssss xrrrrr 32 UInt(sssss) UInt(rrrrr)
294 // 0 10ssss xxrrrr 16 UInt(ssss) UInt(rrrr)
295 // 0 110sss xxxrrr 8 UInt(sss) UInt(rrr)
296 // 0 1110ss xxxxrr 4 UInt(ss) UInt(rr)
297 // 0 11110s xxxxxr 2 UInt(s) UInt(r)
298 // (s bits must not be all set)
299 //
300 // A pattern is constructed of size bits, where the least significant S+1
301 // bits are set. The pattern is rotated right by R, and repeated across a
302 // 32 or 64-bit value, depending on destination register width.
303
304 if (n == 1) {
305 DCHECK_NE(imm_s, 0x3fU);
buzbeef77e9772014-09-02 15:39:57 -0700306 uint64_t bits = bit_mask(imm_s + 1);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100307 return RotateRight(bits, imm_r, 64);
308 } else {
309 DCHECK_NE((imm_s >> 1), 0x1fU);
310 for (unsigned width = 0x20; width >= 0x2; width >>= 1) {
311 if ((imm_s & width) == 0) {
312 unsigned mask = (unsigned)(width - 1);
313 DCHECK_NE((imm_s & mask), mask);
buzbeef77e9772014-09-02 15:39:57 -0700314 uint64_t bits = bit_mask((imm_s & mask) + 1);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100315 return RepeatBitsAcrossReg(is_wide, RotateRight(bits, imm_r & mask, width), width);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100316 }
317 }
318 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100319 return 0;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100320}
321
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100322/**
323 * @brief Decode an 8-bit single point number encoded with EncodeImmSingle().
324 */
325static float DecodeImmSingle(uint8_t small_float) {
326 int mantissa = (small_float & 0x0f) + 0x10;
327 int sign = ((small_float & 0x80) == 0) ? 1 : -1;
328 float signed_mantissa = static_cast<float>(sign*mantissa);
329 int exponent = (((small_float >> 4) & 0x7) + 4) & 0x7;
330 return signed_mantissa*static_cast<float>(1 << exponent)*0.0078125f;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100331}
332
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100333static const char* cc_names[] = {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc",
334 "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"};
Matteo Franchin43ec8732014-03-31 15:00:14 +0100335/*
336 * Interpret a format string and build a string no longer than size
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100337 * See format key in assemble_arm64.cc.
Matteo Franchin43ec8732014-03-31 15:00:14 +0100338 */
339std::string Arm64Mir2Lir::BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) {
340 std::string buf;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100341 const char* fmt_end = &fmt[strlen(fmt)];
342 char tbuf[256];
343 const char* name;
344 char nc;
345 while (fmt < fmt_end) {
346 int operand;
347 if (*fmt == '!') {
348 fmt++;
349 DCHECK_LT(fmt, fmt_end);
350 nc = *fmt++;
351 if (nc == '!') {
352 strcpy(tbuf, "!");
353 } else {
354 DCHECK_LT(fmt, fmt_end);
355 DCHECK_LT(static_cast<unsigned>(nc-'0'), 4U);
356 operand = lir->operands[nc-'0'];
357 switch (*fmt++) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100358 case 'e': {
359 // Omit ", uxtw #0" in strings like "add w0, w1, w3, uxtw #0" and
360 // ", uxtx #0" in strings like "add x0, x1, x3, uxtx #0"
361 int omittable = ((IS_WIDE(lir->opcode)) ? EncodeExtend(kA64Uxtw, 0) :
362 EncodeExtend(kA64Uxtw, 0));
363 if (LIKELY(operand == omittable)) {
364 strcpy(tbuf, "");
365 } else {
366 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
367 }
368 }
369 break;
370 case 'o':
371 // Omit ", lsl #0"
372 if (LIKELY(operand == EncodeShift(kA64Lsl, 0))) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100373 strcpy(tbuf, "");
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100374 } else {
375 DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100376 }
377 break;
378 case 'B':
379 switch (operand) {
380 case kSY:
381 name = "sy";
382 break;
383 case kST:
384 name = "st";
385 break;
386 case kISH:
387 name = "ish";
388 break;
389 case kISHST:
390 name = "ishst";
391 break;
392 case kNSH:
393 name = "nsh";
394 break;
395 case kNSHST:
396 name = "shst";
397 break;
398 default:
399 name = "DecodeError2";
400 break;
401 }
402 strcpy(tbuf, name);
403 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100404 case 's':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100405 snprintf(tbuf, arraysize(tbuf), "s%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100406 break;
407 case 'S':
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100408 snprintf(tbuf, arraysize(tbuf), "d%d", operand & RegStorage::kRegNumMask);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100409 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100410 case 'f':
Matteo Franchin4163c532014-07-15 15:20:27 +0100411 snprintf(tbuf, arraysize(tbuf), "%c%d", (IS_WIDE(lir->opcode)) ? 'd' : 's',
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100412 operand & RegStorage::kRegNumMask);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100413 break;
414 case 'l': {
415 bool is_wide = IS_WIDE(lir->opcode);
416 uint64_t imm = DecodeLogicalImmediate(is_wide, operand);
417 snprintf(tbuf, arraysize(tbuf), "%" PRId64 " (%#" PRIx64 ")", imm, imm);
418 }
419 break;
420 case 'I':
421 snprintf(tbuf, arraysize(tbuf), "%f", DecodeImmSingle(operand));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100422 break;
423 case 'M':
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100424 if (LIKELY(operand == 0))
425 strcpy(tbuf, "");
426 else
427 snprintf(tbuf, arraysize(tbuf), ", lsl #%d", 16*operand);
428 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100429 case 'd':
430 snprintf(tbuf, arraysize(tbuf), "%d", operand);
431 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100432 case 'w':
433 if (LIKELY(operand != rwzr))
434 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
435 else
436 strcpy(tbuf, "wzr");
437 break;
438 case 'W':
439 if (LIKELY(operand != rwsp))
440 snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask);
441 else
442 strcpy(tbuf, "wsp");
443 break;
444 case 'x':
445 if (LIKELY(operand != rxzr))
446 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
447 else
448 strcpy(tbuf, "xzr");
449 break;
450 case 'X':
451 if (LIKELY(operand != rsp))
452 snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask);
453 else
454 strcpy(tbuf, "sp");
455 break;
456 case 'D':
457 snprintf(tbuf, arraysize(tbuf), "%d", operand*((IS_WIDE(lir->opcode)) ? 8 : 4));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100458 break;
459 case 'E':
460 snprintf(tbuf, arraysize(tbuf), "%d", operand*4);
461 break;
462 case 'F':
463 snprintf(tbuf, arraysize(tbuf), "%d", operand*2);
464 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100465 case 'G':
466 if (LIKELY(operand == 0))
467 strcpy(tbuf, "");
468 else
469 strcpy(tbuf, (IS_WIDE(lir->opcode)) ? ", lsl #3" : ", lsl #2");
470 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100471 case 'c':
472 strcpy(tbuf, cc_names[operand]);
473 break;
474 case 't':
475 snprintf(tbuf, arraysize(tbuf), "0x%08" PRIxPTR " (L%p)",
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100476 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + (operand << 2),
Matteo Franchin43ec8732014-03-31 15:00:14 +0100477 lir->target);
478 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100479 case 'r': {
480 bool is_wide = IS_WIDE(lir->opcode);
481 if (LIKELY(operand != rwzr && operand != rxzr)) {
482 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
483 operand & RegStorage::kRegNumMask);
484 } else {
485 strcpy(tbuf, (is_wide) ? "xzr" : "wzr");
486 }
487 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100488 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100489 case 'R': {
490 bool is_wide = IS_WIDE(lir->opcode);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100491 if (LIKELY(operand != rwsp && operand != rsp)) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100492 snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w',
493 operand & RegStorage::kRegNumMask);
494 } else {
495 strcpy(tbuf, (is_wide) ? "sp" : "wsp");
496 }
497 }
Matteo Franchin43ec8732014-03-31 15:00:14 +0100498 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100499 case 'p':
500 snprintf(tbuf, arraysize(tbuf), ".+%d (addr %#" PRIxPTR ")", 4*operand,
501 reinterpret_cast<uintptr_t>(base_addr) + lir->offset + 4*operand);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100502 break;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100503 case 'T':
504 if (LIKELY(operand == 0))
505 strcpy(tbuf, "");
506 else if (operand == 1)
507 strcpy(tbuf, ", lsl #12");
508 else
509 strcpy(tbuf, ", DecodeError3");
Matteo Franchin43ec8732014-03-31 15:00:14 +0100510 break;
Zheng Xu5d7cdec2014-08-18 17:28:22 +0800511 case 'h':
512 snprintf(tbuf, arraysize(tbuf), "%d", operand);
513 break;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100514 default:
515 strcpy(tbuf, "DecodeError1");
516 break;
517 }
518 buf += tbuf;
519 }
520 } else {
521 buf += *fmt++;
522 }
523 }
524 return buf;
525}
526
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100527void Arm64Mir2Lir::DumpResourceMask(LIR* arm_lir, const ResourceMask& mask, const char* prefix) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100528 char buf[256];
529 buf[0] = 0;
530
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100531 if (mask.Equals(kEncodeAll)) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100532 strcpy(buf, "all");
533 } else {
534 char num[8];
535 int i;
536
Matteo Franchin4163c532014-07-15 15:20:27 +0100537 for (i = 0; i < kA64RegEnd; i++) {
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100538 if (mask.HasBit(i)) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100539 snprintf(num, arraysize(num), "%d ", i);
540 strcat(buf, num);
541 }
542 }
543
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100544 if (mask.HasBit(ResourceMask::kCCode)) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100545 strcat(buf, "cc ");
546 }
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100547 if (mask.HasBit(ResourceMask::kFPStatus)) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100548 strcat(buf, "fpcc ");
549 }
550
551 /* Memory bits */
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100552 if (arm_lir && (mask.HasBit(ResourceMask::kDalvikReg))) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100553 snprintf(buf + strlen(buf), arraysize(buf) - strlen(buf), "dr%d%s",
554 DECODE_ALIAS_INFO_REG(arm_lir->flags.alias_info),
555 DECODE_ALIAS_INFO_WIDE(arm_lir->flags.alias_info) ? "(+1)" : "");
556 }
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100557 if (mask.HasBit(ResourceMask::kLiteral)) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100558 strcat(buf, "lit ");
559 }
560
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100561 if (mask.HasBit(ResourceMask::kHeapRef)) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100562 strcat(buf, "heap ");
563 }
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100564 if (mask.HasBit(ResourceMask::kMustNotAlias)) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100565 strcat(buf, "noalias ");
566 }
567 }
568 if (buf[0]) {
569 LOG(INFO) << prefix << ": " << buf;
570 }
571}
572
573bool Arm64Mir2Lir::IsUnconditionalBranch(LIR* lir) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100574 return (lir->opcode == kA64B1t);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100575}
576
Vladimir Marko674744e2014-04-24 15:18:26 +0100577RegisterClass Arm64Mir2Lir::RegClassForFieldLoadStore(OpSize size, bool is_volatile) {
578 if (UNLIKELY(is_volatile)) {
579 // On arm64, fp register load/store is atomic only for single bytes.
580 if (size != kSignedByte && size != kUnsignedByte) {
buzbeea0cd2d72014-06-01 09:33:49 -0700581 return (size == kReference) ? kRefReg : kCoreReg;
Vladimir Marko674744e2014-04-24 15:18:26 +0100582 }
583 }
584 return RegClassBySize(size);
585}
586
Matteo Franchin43ec8732014-03-31 15:00:14 +0100587Arm64Mir2Lir::Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena)
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +0100588 : Mir2Lir(cu, mir_graph, arena),
589 call_method_insns_(arena->Adapter()) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100590 // Sanity check - make sure encoding map lines up.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100591 for (int i = 0; i < kA64Last; i++) {
592 if (UNWIDE(Arm64Mir2Lir::EncodingMap[i].opcode) != i) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100593 LOG(FATAL) << "Encoding order for " << Arm64Mir2Lir::EncodingMap[i].name
594 << " is wrong: expecting " << i << ", seeing "
595 << static_cast<int>(Arm64Mir2Lir::EncodingMap[i].opcode);
596 }
597 }
598}
599
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100600Mir2Lir* Arm64CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph,
601 ArenaAllocator* const arena) {
Matteo Franchin43ec8732014-03-31 15:00:14 +0100602 return new Arm64Mir2Lir(cu, mir_graph, arena);
603}
604
Matteo Franchin43ec8732014-03-31 15:00:14 +0100605void Arm64Mir2Lir::CompilerInitializeRegAlloc() {
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100606 reg_pool_.reset(new (arena_) RegisterPool(this, arena_, core_regs, core64_regs, sp_regs, dp_regs,
607 reserved_regs, reserved64_regs,
608 core_temps, core64_temps, sp_temps, dp_temps));
Matteo Franchin43ec8732014-03-31 15:00:14 +0100609
610 // Target-specific adjustments.
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100611 // Alias single precision float registers to corresponding double registers.
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100612 for (RegisterInfo* info : reg_pool_->sp_regs_) {
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100613 int fp_reg_num = info->GetReg().GetRegNum();
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100614 RegStorage dp_reg = RegStorage::FloatSolo64(fp_reg_num);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100615 RegisterInfo* dp_reg_info = GetRegInfo(dp_reg);
616 // Double precision register's master storage should refer to itself.
617 DCHECK_EQ(dp_reg_info, dp_reg_info->Master());
618 // Redirect single precision's master storage to master.
619 info->SetMaster(dp_reg_info);
620 // Singles should show a single 32-bit mask bit, at first referring to the low half.
621 DCHECK_EQ(info->StorageMask(), 0x1U);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100622 }
623
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100624 // Alias 32bit W registers to corresponding 64bit X registers.
Vladimir Markoe39c54e2014-09-22 14:50:02 +0100625 for (RegisterInfo* info : reg_pool_->core_regs_) {
Serban Constantinescued65c5e2014-05-22 15:10:18 +0100626 int x_reg_num = info->GetReg().GetRegNum();
627 RegStorage x_reg = RegStorage::Solo64(x_reg_num);
628 RegisterInfo* x_reg_info = GetRegInfo(x_reg);
629 // 64bit X register's master storage should refer to itself.
630 DCHECK_EQ(x_reg_info, x_reg_info->Master());
631 // Redirect 32bit W master storage to 64bit X.
632 info->SetMaster(x_reg_info);
633 // 32bit W should show a single 32-bit mask bit, at first referring to the low half.
634 DCHECK_EQ(info->StorageMask(), 0x1U);
635 }
636
Matteo Franchin43ec8732014-03-31 15:00:14 +0100637 // Don't start allocating temps at r0/s0/d0 or you may clobber return regs in early-exit methods.
638 // TODO: adjust when we roll to hard float calling convention.
639 reg_pool_->next_core_reg_ = 2;
640 reg_pool_->next_sp_reg_ = 0;
641 reg_pool_->next_dp_reg_ = 0;
642}
643
Matteo Franchin43ec8732014-03-31 15:00:14 +0100644/*
645 * TUNING: is true leaf? Can't just use METHOD_IS_LEAF to determine as some
646 * instructions might call out to C/assembly helper functions. Until
647 * machinery is in place, always spill lr.
648 */
649
650void Arm64Mir2Lir::AdjustSpillMask() {
Zheng Xubaa7c882014-06-30 14:26:50 +0800651 core_spill_mask_ |= (1 << rs_xLR.GetRegNum());
Matteo Franchin43ec8732014-03-31 15:00:14 +0100652 num_core_spills_++;
653}
654
Matteo Franchin43ec8732014-03-31 15:00:14 +0100655/* Clobber all regs that might be used by an external C call */
656void Arm64Mir2Lir::ClobberCallerSave() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100657 Clobber(rs_x0);
658 Clobber(rs_x1);
659 Clobber(rs_x2);
660 Clobber(rs_x3);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100661 Clobber(rs_x4);
662 Clobber(rs_x5);
663 Clobber(rs_x6);
664 Clobber(rs_x7);
665 Clobber(rs_x8);
666 Clobber(rs_x9);
667 Clobber(rs_x10);
668 Clobber(rs_x11);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100669 Clobber(rs_x12);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100670 Clobber(rs_x13);
671 Clobber(rs_x14);
672 Clobber(rs_x15);
673 Clobber(rs_x16);
674 Clobber(rs_x17);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100675 Clobber(rs_x30);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100676
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100677 Clobber(rs_f0);
678 Clobber(rs_f1);
679 Clobber(rs_f2);
680 Clobber(rs_f3);
681 Clobber(rs_f4);
682 Clobber(rs_f5);
683 Clobber(rs_f6);
684 Clobber(rs_f7);
Matteo Franchinbc6d1972014-05-13 12:33:28 +0100685 Clobber(rs_f16);
686 Clobber(rs_f17);
687 Clobber(rs_f18);
688 Clobber(rs_f19);
689 Clobber(rs_f20);
690 Clobber(rs_f21);
691 Clobber(rs_f22);
692 Clobber(rs_f23);
693 Clobber(rs_f24);
694 Clobber(rs_f25);
695 Clobber(rs_f26);
696 Clobber(rs_f27);
697 Clobber(rs_f28);
698 Clobber(rs_f29);
699 Clobber(rs_f30);
700 Clobber(rs_f31);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100701}
702
703RegLocation Arm64Mir2Lir::GetReturnWideAlt() {
704 RegLocation res = LocCReturnWide();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100705 res.reg.SetReg(rx2);
706 res.reg.SetHighReg(rx3);
707 Clobber(rs_x2);
708 Clobber(rs_x3);
709 MarkInUse(rs_x2);
710 MarkInUse(rs_x3);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100711 MarkWide(res.reg);
712 return res;
713}
714
715RegLocation Arm64Mir2Lir::GetReturnAlt() {
716 RegLocation res = LocCReturn();
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100717 res.reg.SetReg(rx1);
718 Clobber(rs_x1);
719 MarkInUse(rs_x1);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100720 return res;
721}
722
723/* To be used when explicitly managing register use */
724void Arm64Mir2Lir::LockCallTemps() {
buzbee33ae5582014-06-12 14:56:32 -0700725 // TODO: needs cleanup.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100726 LockTemp(rs_x0);
727 LockTemp(rs_x1);
728 LockTemp(rs_x2);
729 LockTemp(rs_x3);
buzbee33ae5582014-06-12 14:56:32 -0700730 LockTemp(rs_x4);
731 LockTemp(rs_x5);
732 LockTemp(rs_x6);
733 LockTemp(rs_x7);
734 LockTemp(rs_f0);
735 LockTemp(rs_f1);
736 LockTemp(rs_f2);
737 LockTemp(rs_f3);
738 LockTemp(rs_f4);
739 LockTemp(rs_f5);
740 LockTemp(rs_f6);
741 LockTemp(rs_f7);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100742}
743
744/* To be used when explicitly managing register use */
745void Arm64Mir2Lir::FreeCallTemps() {
buzbee33ae5582014-06-12 14:56:32 -0700746 // TODO: needs cleanup.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100747 FreeTemp(rs_x0);
748 FreeTemp(rs_x1);
749 FreeTemp(rs_x2);
750 FreeTemp(rs_x3);
buzbee33ae5582014-06-12 14:56:32 -0700751 FreeTemp(rs_x4);
752 FreeTemp(rs_x5);
753 FreeTemp(rs_x6);
754 FreeTemp(rs_x7);
755 FreeTemp(rs_f0);
756 FreeTemp(rs_f1);
757 FreeTemp(rs_f2);
758 FreeTemp(rs_f3);
759 FreeTemp(rs_f4);
760 FreeTemp(rs_f5);
761 FreeTemp(rs_f6);
762 FreeTemp(rs_f7);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100763}
764
Andreas Gampe98430592014-07-27 19:44:50 -0700765RegStorage Arm64Mir2Lir::LoadHelper(QuickEntrypointEnum trampoline) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100766 // TODO(Arm64): use LoadWordDisp instead.
767 // e.g. LoadWordDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR);
Andreas Gampe98430592014-07-27 19:44:50 -0700768 LoadBaseDisp(rs_xSELF, GetThreadOffset<8>(trampoline).Int32Value(), rs_xLR, k64, kNotVolatile);
Zheng Xubaa7c882014-06-30 14:26:50 +0800769 return rs_xLR;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100770}
771
772LIR* Arm64Mir2Lir::CheckSuspendUsingLoad() {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100773 RegStorage tmp = rs_x0;
Zheng Xubaa7c882014-06-30 14:26:50 +0800774 LoadWordDisp(rs_xSELF, Thread::ThreadSuspendTriggerOffset<8>().Int32Value(), tmp);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100775 LIR* load2 = LoadWordDisp(tmp, 0, tmp);
Matteo Franchin43ec8732014-03-31 15:00:14 +0100776 return load2;
777}
778
779uint64_t Arm64Mir2Lir::GetTargetInstFlags(int opcode) {
780 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100781 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].flags;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100782}
783
784const char* Arm64Mir2Lir::GetTargetInstName(int opcode) {
785 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100786 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].name;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100787}
788
789const char* Arm64Mir2Lir::GetTargetInstFmt(int opcode) {
790 DCHECK(!IsPseudoLirOp(opcode));
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100791 return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].fmt;
Matteo Franchin43ec8732014-03-31 15:00:14 +0100792}
793
buzbee33ae5582014-06-12 14:56:32 -0700794RegStorage Arm64Mir2Lir::InToRegStorageArm64Mapper::GetNextReg(bool is_double_or_float,
Zheng Xu949cd972014-06-23 18:33:08 +0800795 bool is_wide,
796 bool is_ref) {
buzbee33ae5582014-06-12 14:56:32 -0700797 const RegStorage coreArgMappingToPhysicalReg[] =
798 {rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7};
799 const int coreArgMappingToPhysicalRegSize =
800 sizeof(coreArgMappingToPhysicalReg) / sizeof(RegStorage);
801 const RegStorage fpArgMappingToPhysicalReg[] =
802 {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7};
803 const int fpArgMappingToPhysicalRegSize =
804 sizeof(fpArgMappingToPhysicalReg) / sizeof(RegStorage);
805
806 RegStorage result = RegStorage::InvalidReg();
807 if (is_double_or_float) {
808 if (cur_fp_reg_ < fpArgMappingToPhysicalRegSize) {
Zheng Xu949cd972014-06-23 18:33:08 +0800809 DCHECK(!is_ref);
buzbee33ae5582014-06-12 14:56:32 -0700810 result = fpArgMappingToPhysicalReg[cur_fp_reg_++];
811 if (result.Valid()) {
812 // TODO: switching between widths remains a bit ugly. Better way?
813 int res_reg = result.GetReg();
814 result = is_wide ? RegStorage::FloatSolo64(res_reg) : RegStorage::FloatSolo32(res_reg);
815 }
816 }
817 } else {
818 if (cur_core_reg_ < coreArgMappingToPhysicalRegSize) {
819 result = coreArgMappingToPhysicalReg[cur_core_reg_++];
820 if (result.Valid()) {
821 // TODO: switching between widths remains a bit ugly. Better way?
822 int res_reg = result.GetReg();
Zheng Xu949cd972014-06-23 18:33:08 +0800823 DCHECK(!(is_wide && is_ref));
824 result = (is_wide || is_ref) ? RegStorage::Solo64(res_reg) : RegStorage::Solo32(res_reg);
buzbee33ae5582014-06-12 14:56:32 -0700825 }
826 }
827 }
828 return result;
829}
830
831RegStorage Arm64Mir2Lir::InToRegStorageMapping::Get(int in_position) {
832 DCHECK(IsInitialized());
833 auto res = mapping_.find(in_position);
834 return res != mapping_.end() ? res->second : RegStorage::InvalidReg();
835}
836
837void Arm64Mir2Lir::InToRegStorageMapping::Initialize(RegLocation* arg_locs, int count,
838 InToRegStorageMapper* mapper) {
839 DCHECK(mapper != nullptr);
840 max_mapped_in_ = -1;
841 is_there_stack_mapped_ = false;
842 for (int in_position = 0; in_position < count; in_position++) {
Zheng Xu949cd972014-06-23 18:33:08 +0800843 RegStorage reg = mapper->GetNextReg(arg_locs[in_position].fp,
844 arg_locs[in_position].wide,
845 arg_locs[in_position].ref);
buzbee33ae5582014-06-12 14:56:32 -0700846 if (reg.Valid()) {
847 mapping_[in_position] = reg;
Zheng Xu949cd972014-06-23 18:33:08 +0800848 if (arg_locs[in_position].wide) {
buzbee33ae5582014-06-12 14:56:32 -0700849 // We covered 2 args, so skip the next one
850 in_position++;
851 }
Zheng Xu949cd972014-06-23 18:33:08 +0800852 max_mapped_in_ = std::max(max_mapped_in_, in_position);
buzbee33ae5582014-06-12 14:56:32 -0700853 } else {
854 is_there_stack_mapped_ = true;
855 }
856 }
857 initialized_ = true;
858}
859
860
861// Deprecate. Use the new mechanism.
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100862// TODO(Arm64): reuse info in QuickArgumentVisitor?
863static RegStorage GetArgPhysicalReg(RegLocation* loc, int* num_gpr_used, int* num_fpr_used,
864 OpSize* op_size) {
865 if (loc->fp) {
866 int n = *num_fpr_used;
867 if (n < 8) {
868 *num_fpr_used = n + 1;
869 RegStorage::RegStorageKind reg_kind;
870 if (loc->wide) {
871 *op_size = kDouble;
872 reg_kind = RegStorage::k64BitSolo;
873 } else {
874 *op_size = kSingle;
875 reg_kind = RegStorage::k32BitSolo;
876 }
877 return RegStorage(RegStorage::kValid | reg_kind | RegStorage::kFloatingPoint | n);
878 }
879 } else {
880 int n = *num_gpr_used;
buzbee33ae5582014-06-12 14:56:32 -0700881 if (n < 8) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100882 *num_gpr_used = n + 1;
buzbeeb5860fb2014-06-21 15:31:01 -0700883 if (loc->wide || loc->ref) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100884 *op_size = k64;
885 return RegStorage::Solo64(n);
886 } else {
887 *op_size = k32;
888 return RegStorage::Solo32(n);
889 }
890 }
891 }
Ian Rogers54874942014-06-10 16:31:03 -0700892 *op_size = kWord;
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100893 return RegStorage::InvalidReg();
894}
895
buzbee33ae5582014-06-12 14:56:32 -0700896RegStorage Arm64Mir2Lir::GetArgMappingToPhysicalReg(int arg_num) {
897 if (!in_to_reg_storage_mapping_.IsInitialized()) {
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700898 int start_vreg = mir_graph_->GetFirstInVR();
buzbee33ae5582014-06-12 14:56:32 -0700899 RegLocation* arg_locs = &mir_graph_->reg_location_[start_vreg];
900
901 InToRegStorageArm64Mapper mapper;
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700902 in_to_reg_storage_mapping_.Initialize(arg_locs, mir_graph_->GetNumOfInVRs(), &mapper);
buzbee33ae5582014-06-12 14:56:32 -0700903 }
904 return in_to_reg_storage_mapping_.Get(arg_num);
905}
906
907
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100908/*
909 * If there are any ins passed in registers that have not been promoted
910 * to a callee-save register, flush them to the frame. Perform initial
911 * assignment of promoted arguments.
912 *
913 * ArgLocs is an array of location records describing the incoming arguments
914 * with one location record per word of argument.
915 */
916void Arm64Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) {
917 int num_gpr_used = 1;
918 int num_fpr_used = 0;
919
920 /*
Zheng Xu511c8a62014-06-03 16:22:23 +0800921 * Dummy up a RegLocation for the incoming StackReference<mirror::ArtMethod>
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100922 * It will attempt to keep kArg0 live (or copy it to home location
923 * if promoted).
924 */
925 RegLocation rl_src = rl_method;
926 rl_src.location = kLocPhysReg;
Matteo Franchined7a0f22014-06-10 19:23:45 +0100927 rl_src.reg = TargetReg(kArg0, kRef);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100928 rl_src.home = false;
929 MarkLive(rl_src);
Zheng Xu511c8a62014-06-03 16:22:23 +0800930 StoreValue(rl_method, rl_src);
931 // If Method* has been promoted, explicitly flush
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100932 if (rl_method.location == kLocPhysReg) {
Matteo Franchined7a0f22014-06-10 19:23:45 +0100933 StoreRefDisp(TargetPtrReg(kSp), 0, rl_src.reg, kNotVolatile);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100934 }
935
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700936 if (mir_graph_->GetNumOfInVRs() == 0) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100937 return;
938 }
939
Vladimir Marko8dea81c2014-06-06 14:50:36 +0100940 // Handle dalvik registers.
941 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Razvan A Lupusoru8d0d03e2014-06-06 17:04:52 -0700942 int start_vreg = mir_graph_->GetFirstInVR();
943 for (uint32_t i = 0; i < mir_graph_->GetNumOfInVRs(); i++) {
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100944 RegLocation* t_loc = &ArgLocs[i];
945 OpSize op_size;
946 RegStorage reg = GetArgPhysicalReg(t_loc, &num_gpr_used, &num_fpr_used, &op_size);
947
948 if (reg.Valid()) {
buzbeeb5860fb2014-06-21 15:31:01 -0700949 // If arriving in register.
950
951 // We have already updated the arg location with promoted info
952 // so we can be based on it.
953 if (t_loc->location == kLocPhysReg) {
954 // Just copy it.
955 OpRegCopy(t_loc->reg, reg);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100956 } else {
buzbeeb5860fb2014-06-21 15:31:01 -0700957 // Needs flush.
958 if (t_loc->ref) {
Matteo Franchined7a0f22014-06-10 19:23:45 +0100959 StoreRefDisp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), reg, kNotVolatile);
buzbeeb5860fb2014-06-21 15:31:01 -0700960 } else {
Matteo Franchined7a0f22014-06-10 19:23:45 +0100961 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), reg, t_loc->wide ? k64 : k32,
buzbeeb5860fb2014-06-21 15:31:01 -0700962 kNotVolatile);
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100963 }
964 }
965 } else {
buzbeeb5860fb2014-06-21 15:31:01 -0700966 // If arriving in frame & promoted.
967 if (t_loc->location == kLocPhysReg) {
968 if (t_loc->ref) {
Matteo Franchined7a0f22014-06-10 19:23:45 +0100969 LoadRefDisp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), t_loc->reg, kNotVolatile);
buzbeeb5860fb2014-06-21 15:31:01 -0700970 } else {
Matteo Franchined7a0f22014-06-10 19:23:45 +0100971 LoadBaseDisp(TargetPtrReg(kSp), SRegOffset(start_vreg + i), t_loc->reg,
buzbeeb5860fb2014-06-21 15:31:01 -0700972 t_loc->wide ? k64 : k32, kNotVolatile);
973 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +0100974 }
975 }
buzbeeb5860fb2014-06-21 15:31:01 -0700976 if (t_loc->wide) {
977 // Increment i to skip the next one.
978 i++;
979 }
980 // if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) {
981 // OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg);
982 // } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) {
983 // OpRegCopy(RegStorage::Solo32(v_map->fp_reg), reg);
984 // } else {
985 // StoreBaseDisp(TargetReg(kSp), SRegOffset(start_vreg + i), reg, op_size, kNotVolatile);
986 // if (reg.Is64Bit()) {
987 // if (SRegOffset(start_vreg + i) + 4 != SRegOffset(start_vreg + i + 1)) {
988 // LOG(FATAL) << "64 bit value stored in non-consecutive 4 bytes slots";
989 // }
990 // i += 1;
991 // }
992 // }
993 // } else {
994 // // If arriving in frame & promoted
995 // if (v_map->core_location == kLocPhysReg) {
996 // LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i),
997 // RegStorage::Solo32(v_map->core_reg));
998 // }
999 // if (v_map->fp_location == kLocPhysReg) {
1000 // LoadWordDisp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->fp_reg));
1001 // }
Matteo Franchine45fb9e2014-05-06 10:10:30 +01001002 }
1003}
1004
buzbee33ae5582014-06-12 14:56:32 -07001005/*
1006 * Load up to 5 arguments, the first three of which will be in
1007 * kArg1 .. kArg3. On entry kArg0 contains the current method pointer,
1008 * and as part of the load sequence, it must be replaced with
1009 * the target method pointer.
1010 */
1011int Arm64Mir2Lir::GenDalvikArgsNoRange(CallInfo* info,
1012 int call_state, LIR** pcrLabel, NextCallInsn next_call_insn,
1013 const MethodReference& target_method,
1014 uint32_t vtable_idx, uintptr_t direct_code,
1015 uintptr_t direct_method, InvokeType type, bool skip_this) {
1016 return GenDalvikArgsRange(info,
1017 call_state, pcrLabel, next_call_insn,
1018 target_method,
1019 vtable_idx, direct_code,
1020 direct_method, type, skip_this);
1021}
1022
1023/*
1024 * May have 0+ arguments (also used for jumbo). Note that
1025 * source virtual registers may be in physical registers, so may
1026 * need to be flushed to home location before copying. This
1027 * applies to arg3 and above (see below).
1028 *
1029 * FIXME: update comments.
1030 *
1031 * Two general strategies:
1032 * If < 20 arguments
1033 * Pass args 3-18 using vldm/vstm block copy
1034 * Pass arg0, arg1 & arg2 in kArg1-kArg3
1035 * If 20+ arguments
1036 * Pass args arg19+ using memcpy block copy
1037 * Pass arg0, arg1 & arg2 in kArg1-kArg3
1038 *
1039 */
1040int Arm64Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state,
1041 LIR** pcrLabel, NextCallInsn next_call_insn,
1042 const MethodReference& target_method,
1043 uint32_t vtable_idx, uintptr_t direct_code,
1044 uintptr_t direct_method, InvokeType type, bool skip_this) {
1045 /* If no arguments, just return */
1046 if (info->num_arg_words == 0)
1047 return call_state;
1048
1049 const int start_index = skip_this ? 1 : 0;
1050
1051 InToRegStorageArm64Mapper mapper;
1052 InToRegStorageMapping in_to_reg_storage_mapping;
1053 in_to_reg_storage_mapping.Initialize(info->args, info->num_arg_words, &mapper);
1054 const int last_mapped_in = in_to_reg_storage_mapping.GetMaxMappedIn();
Zheng Xu949cd972014-06-23 18:33:08 +08001055 int regs_left_to_pass_via_stack = info->num_arg_words - (last_mapped_in + 1);
buzbee33ae5582014-06-12 14:56:32 -07001056
Matteo Franchinf1013192014-07-07 13:35:14 +01001057 // First of all, check whether it makes sense to use bulk copying.
1058 // Bulk copying is done only for the range case.
buzbee33ae5582014-06-12 14:56:32 -07001059 // TODO: make a constant instead of 2
1060 if (info->is_range && regs_left_to_pass_via_stack >= 2) {
1061 // Scan the rest of the args - if in phys_reg flush to memory
Zheng Xu949cd972014-06-23 18:33:08 +08001062 for (int next_arg = last_mapped_in + 1; next_arg < info->num_arg_words;) {
buzbee33ae5582014-06-12 14:56:32 -07001063 RegLocation loc = info->args[next_arg];
1064 if (loc.wide) {
1065 loc = UpdateLocWide(loc);
1066 if (loc.location == kLocPhysReg) {
1067 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
Matteo Franchined7a0f22014-06-10 19:23:45 +01001068 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile);
buzbee33ae5582014-06-12 14:56:32 -07001069 }
1070 next_arg += 2;
1071 } else {
1072 loc = UpdateLoc(loc);
1073 if (loc.location == kLocPhysReg) {
1074 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
buzbeeb5860fb2014-06-21 15:31:01 -07001075 if (loc.ref) {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001076 StoreRefDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, kNotVolatile);
buzbeeb5860fb2014-06-21 15:31:01 -07001077 } else {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001078 StoreBaseDisp(TargetPtrReg(kSp), SRegOffset(loc.s_reg_low), loc.reg, k32,
1079 kNotVolatile);
buzbeeb5860fb2014-06-21 15:31:01 -07001080 }
buzbee33ae5582014-06-12 14:56:32 -07001081 }
1082 next_arg++;
Matteo Franchine45fb9e2014-05-06 10:10:30 +01001083 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +01001084 }
buzbee33ae5582014-06-12 14:56:32 -07001085
buzbee33ae5582014-06-12 14:56:32 -07001086 // The rest can be copied together
Zheng Xu949cd972014-06-23 18:33:08 +08001087 int start_offset = SRegOffset(info->args[last_mapped_in + 1].s_reg_low);
1088 int outs_offset = StackVisitor::GetOutVROffset(last_mapped_in + 1,
buzbee33ae5582014-06-12 14:56:32 -07001089 cu_->instruction_set);
1090
1091 int current_src_offset = start_offset;
1092 int current_dest_offset = outs_offset;
1093
1094 // Only davik regs are accessed in this loop; no next_call_insn() calls.
1095 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
1096 while (regs_left_to_pass_via_stack > 0) {
1097 /*
1098 * TODO: Improve by adding block copy for large number of arguments. This
1099 * should be done, if possible, as a target-depending helper. For now, just
1100 * copy a Dalvik vreg at a time.
1101 */
1102 // Moving 32-bits via general purpose register.
1103 size_t bytes_to_move = sizeof(uint32_t);
1104
1105 // Instead of allocating a new temp, simply reuse one of the registers being used
1106 // for argument passing.
Andreas Gampeccc60262014-07-04 18:02:38 -07001107 RegStorage temp = TargetReg(kArg3, kNotWide);
buzbee33ae5582014-06-12 14:56:32 -07001108
1109 // Now load the argument VR and store to the outs.
Matteo Franchined7a0f22014-06-10 19:23:45 +01001110 Load32Disp(TargetPtrReg(kSp), current_src_offset, temp);
1111 Store32Disp(TargetPtrReg(kSp), current_dest_offset, temp);
buzbee33ae5582014-06-12 14:56:32 -07001112
1113 current_src_offset += bytes_to_move;
1114 current_dest_offset += bytes_to_move;
1115 regs_left_to_pass_via_stack -= (bytes_to_move >> 2);
1116 }
1117 DCHECK_EQ(regs_left_to_pass_via_stack, 0);
1118 }
1119
1120 // Now handle rest not registers if they are
1121 if (in_to_reg_storage_mapping.IsThereStackMapped()) {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001122 RegStorage regWide = TargetReg(kArg3, kWide);
buzbee33ae5582014-06-12 14:56:32 -07001123 for (int i = start_index; i <= last_mapped_in + regs_left_to_pass_via_stack; i++) {
1124 RegLocation rl_arg = info->args[i];
1125 rl_arg = UpdateRawLoc(rl_arg);
1126 RegStorage reg = in_to_reg_storage_mapping.Get(i);
1127 if (!reg.Valid()) {
1128 int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set);
1129
1130 {
1131 ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg);
1132 if (rl_arg.wide) {
1133 if (rl_arg.location == kLocPhysReg) {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001134 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k64, kNotVolatile);
buzbee33ae5582014-06-12 14:56:32 -07001135 } else {
1136 LoadValueDirectWideFixed(rl_arg, regWide);
Matteo Franchined7a0f22014-06-10 19:23:45 +01001137 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regWide, k64, kNotVolatile);
buzbee33ae5582014-06-12 14:56:32 -07001138 }
buzbee33ae5582014-06-12 14:56:32 -07001139 } else {
1140 if (rl_arg.location == kLocPhysReg) {
Andreas Gampe3c12c512014-06-24 18:46:29 +00001141 if (rl_arg.ref) {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001142 StoreRefDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, kNotVolatile);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001143 } else {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001144 StoreBaseDisp(TargetPtrReg(kSp), out_offset, rl_arg.reg, k32, kNotVolatile);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001145 }
buzbee33ae5582014-06-12 14:56:32 -07001146 } else {
Andreas Gampe3c12c512014-06-24 18:46:29 +00001147 if (rl_arg.ref) {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001148 RegStorage regSingle = TargetReg(kArg2, kRef);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001149 LoadValueDirectFixed(rl_arg, regSingle);
Matteo Franchined7a0f22014-06-10 19:23:45 +01001150 StoreRefDisp(TargetPtrReg(kSp), out_offset, regSingle, kNotVolatile);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001151 } else {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001152 RegStorage regSingle = TargetReg(kArg2, kNotWide);
1153 LoadValueDirectFixed(rl_arg, regSingle);
1154 StoreBaseDisp(TargetPtrReg(kSp), out_offset, regSingle, k32, kNotVolatile);
Andreas Gampe3c12c512014-06-24 18:46:29 +00001155 }
buzbee33ae5582014-06-12 14:56:32 -07001156 }
1157 }
1158 }
1159 call_state = next_call_insn(cu_, info, call_state, target_method,
1160 vtable_idx, direct_code, direct_method, type);
1161 }
Matteo Franchinf1013192014-07-07 13:35:14 +01001162 if (rl_arg.wide) {
1163 i++;
1164 }
buzbee33ae5582014-06-12 14:56:32 -07001165 }
1166 }
1167
1168 // Finish with mapped registers
1169 for (int i = start_index; i <= last_mapped_in; i++) {
1170 RegLocation rl_arg = info->args[i];
1171 rl_arg = UpdateRawLoc(rl_arg);
1172 RegStorage reg = in_to_reg_storage_mapping.Get(i);
1173 if (reg.Valid()) {
1174 if (rl_arg.wide) {
1175 LoadValueDirectWideFixed(rl_arg, reg);
buzbee33ae5582014-06-12 14:56:32 -07001176 } else {
1177 LoadValueDirectFixed(rl_arg, reg);
1178 }
1179 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
Matteo Franchinf1013192014-07-07 13:35:14 +01001180 direct_code, direct_method, type);
1181 }
1182 if (rl_arg.wide) {
1183 i++;
buzbee33ae5582014-06-12 14:56:32 -07001184 }
1185 }
1186
1187 call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx,
1188 direct_code, direct_method, type);
1189 if (pcrLabel) {
Dave Allison69dfe512014-07-11 17:11:58 +00001190 if (!cu_->compiler_driver->GetCompilerOptions().GetImplicitNullChecks()) {
Matteo Franchined7a0f22014-06-10 19:23:45 +01001191 *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1, kRef), info->opt_flags);
buzbee33ae5582014-06-12 14:56:32 -07001192 } else {
1193 *pcrLabel = nullptr;
1194 // In lieu of generating a check for kArg1 being null, we need to
1195 // perform a load when doing implicit checks.
1196 RegStorage tmp = AllocTemp();
Matteo Franchined7a0f22014-06-10 19:23:45 +01001197 Load32Disp(TargetReg(kArg1, kRef), 0, tmp);
buzbee33ae5582014-06-12 14:56:32 -07001198 MarkPossibleNullPointerException(info->opt_flags);
1199 FreeTemp(tmp);
1200 }
Matteo Franchine45fb9e2014-05-06 10:10:30 +01001201 }
1202 return call_state;
1203}
1204
Vladimir Marko7c2ad5a2014-09-24 12:42:55 +01001205void Arm64Mir2Lir::InstallLiteralPools() {
1206 // PC-relative calls to methods.
1207 patches_.reserve(call_method_insns_.size());
1208 for (LIR* p : call_method_insns_) {
1209 DCHECK_EQ(p->opcode, kA64Bl1t);
1210 uint32_t target_method_idx = p->operands[1];
1211 const DexFile* target_dex_file =
1212 reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[2]));
1213
1214 patches_.push_back(LinkerPatch::RelativeCodePatch(p->offset,
1215 target_dex_file, target_method_idx));
1216 }
1217
1218 // And do the normal processing.
1219 Mir2Lir::InstallLiteralPools();
1220}
1221
Matteo Franchin43ec8732014-03-31 15:00:14 +01001222} // namespace art