Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 1 | /* |
| 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> |
Zheng Xu | a34e760 | 2015-02-03 12:03:15 +0800 | [diff] [blame] | 22 | #include <sstream> |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 23 | |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 24 | #include "backend_arm64.h" |
Andreas Gampe | 0b9203e | 2015-01-22 20:39:27 -0800 | [diff] [blame] | 25 | #include "base/logging.h" |
| 26 | #include "dex/mir_graph.h" |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 27 | #include "dex/quick/mir_to_lir-inl.h" |
buzbee | b5860fb | 2014-06-21 15:31:01 -0700 | [diff] [blame] | 28 | #include "dex/reg_storage_eq.h" |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 32 | static constexpr RegStorage core_regs_arr[] = |
buzbee | b01bf15 | 2014-05-13 15:59:07 -0700 | [diff] [blame] | 33 | {rs_w0, rs_w1, rs_w2, rs_w3, rs_w4, rs_w5, rs_w6, rs_w7, |
| 34 | rs_w8, rs_w9, rs_w10, rs_w11, rs_w12, rs_w13, rs_w14, rs_w15, |
| 35 | rs_w16, rs_w17, rs_w18, rs_w19, rs_w20, rs_w21, rs_w22, rs_w23, |
| 36 | rs_w24, rs_w25, rs_w26, rs_w27, rs_w28, rs_w29, rs_w30, rs_w31, |
| 37 | rs_wzr}; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 38 | static constexpr RegStorage core64_regs_arr[] = |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 39 | {rs_x0, rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7, |
| 40 | rs_x8, rs_x9, rs_x10, rs_x11, rs_x12, rs_x13, rs_x14, rs_x15, |
| 41 | rs_x16, rs_x17, rs_x18, rs_x19, rs_x20, rs_x21, rs_x22, rs_x23, |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 42 | rs_x24, rs_x25, rs_x26, rs_x27, rs_x28, rs_x29, rs_x30, rs_x31, |
| 43 | rs_xzr}; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 44 | static constexpr RegStorage sp_regs_arr[] = |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 45 | {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7, |
| 46 | rs_f8, rs_f9, rs_f10, rs_f11, rs_f12, rs_f13, rs_f14, rs_f15, |
| 47 | rs_f16, rs_f17, rs_f18, rs_f19, rs_f20, rs_f21, rs_f22, rs_f23, |
| 48 | rs_f24, rs_f25, rs_f26, rs_f27, rs_f28, rs_f29, rs_f30, rs_f31}; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 49 | static constexpr RegStorage dp_regs_arr[] = |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 50 | {rs_d0, rs_d1, rs_d2, rs_d3, rs_d4, rs_d5, rs_d6, rs_d7, |
Zheng Xu | c830430 | 2014-05-15 17:21:01 +0100 | [diff] [blame] | 51 | rs_d8, rs_d9, rs_d10, rs_d11, rs_d12, rs_d13, rs_d14, rs_d15, |
| 52 | rs_d16, rs_d17, rs_d18, rs_d19, rs_d20, rs_d21, rs_d22, rs_d23, |
| 53 | rs_d24, rs_d25, rs_d26, rs_d27, rs_d28, rs_d29, rs_d30, rs_d31}; |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 54 | static constexpr RegStorage reserved_regs_arr[] = {rs_wSELF, rs_wsp, rs_wLR, rs_wzr}; |
| 55 | static constexpr RegStorage reserved64_regs_arr[] = {rs_xSELF, rs_sp, rs_xLR, rs_xzr}; |
| 56 | |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 57 | static constexpr RegStorage core_temps_arr[] = |
buzbee | b01bf15 | 2014-05-13 15:59:07 -0700 | [diff] [blame] | 58 | {rs_w0, rs_w1, rs_w2, rs_w3, rs_w4, rs_w5, rs_w6, rs_w7, |
| 59 | rs_w8, rs_w9, rs_w10, rs_w11, rs_w12, rs_w13, rs_w14, rs_w15, rs_w16, |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame^] | 60 | rs_w17, rs_w18}; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 61 | static constexpr RegStorage core64_temps_arr[] = |
Zheng Xu | c830430 | 2014-05-15 17:21:01 +0100 | [diff] [blame] | 62 | {rs_x0, rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7, |
| 63 | rs_x8, rs_x9, rs_x10, rs_x11, rs_x12, rs_x13, rs_x14, rs_x15, rs_x16, |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame^] | 64 | rs_x17, rs_x18}; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 65 | static constexpr RegStorage sp_temps_arr[] = |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 66 | {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7, |
Zheng Xu | c830430 | 2014-05-15 17:21:01 +0100 | [diff] [blame] | 67 | rs_f16, rs_f17, rs_f18, rs_f19, rs_f20, rs_f21, rs_f22, rs_f23, |
| 68 | rs_f24, rs_f25, rs_f26, rs_f27, rs_f28, rs_f29, rs_f30, rs_f31}; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 69 | static constexpr RegStorage dp_temps_arr[] = |
Zheng Xu | c830430 | 2014-05-15 17:21:01 +0100 | [diff] [blame] | 70 | {rs_d0, rs_d1, rs_d2, rs_d3, rs_d4, rs_d5, rs_d6, rs_d7, |
| 71 | rs_d16, rs_d17, rs_d18, rs_d19, rs_d20, rs_d21, rs_d22, rs_d23, |
| 72 | rs_d24, rs_d25, rs_d26, rs_d27, rs_d28, rs_d29, rs_d30, rs_d31}; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 73 | |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 74 | static constexpr ArrayRef<const RegStorage> core_regs(core_regs_arr); |
| 75 | static constexpr ArrayRef<const RegStorage> core64_regs(core64_regs_arr); |
| 76 | static constexpr ArrayRef<const RegStorage> sp_regs(sp_regs_arr); |
| 77 | static constexpr ArrayRef<const RegStorage> dp_regs(dp_regs_arr); |
| 78 | static constexpr ArrayRef<const RegStorage> reserved_regs(reserved_regs_arr); |
| 79 | static constexpr ArrayRef<const RegStorage> reserved64_regs(reserved64_regs_arr); |
| 80 | static constexpr ArrayRef<const RegStorage> core_temps(core_temps_arr); |
| 81 | static constexpr ArrayRef<const RegStorage> core64_temps(core64_temps_arr); |
| 82 | static constexpr ArrayRef<const RegStorage> sp_temps(sp_temps_arr); |
| 83 | static constexpr ArrayRef<const RegStorage> dp_temps(dp_temps_arr); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 84 | |
| 85 | RegLocation Arm64Mir2Lir::LocCReturn() { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 86 | return a64_loc_c_return; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 87 | } |
| 88 | |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 89 | RegLocation Arm64Mir2Lir::LocCReturnRef() { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 90 | return a64_loc_c_return_ref; |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 93 | RegLocation Arm64Mir2Lir::LocCReturnWide() { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 94 | return a64_loc_c_return_wide; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | RegLocation Arm64Mir2Lir::LocCReturnFloat() { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 98 | return a64_loc_c_return_float; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | RegLocation Arm64Mir2Lir::LocCReturnDouble() { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 102 | return a64_loc_c_return_double; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | // Return a target-dependent special register. |
| 106 | RegStorage Arm64Mir2Lir::TargetReg(SpecialTargetRegister reg) { |
| 107 | RegStorage res_reg = RegStorage::InvalidReg(); |
| 108 | switch (reg) { |
Matteo Franchin | ed7a0f2 | 2014-06-10 19:23:45 +0100 | [diff] [blame] | 109 | case kSelf: res_reg = rs_wSELF; break; |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 110 | case kSuspend: res_reg = RegStorage::InvalidReg(); break; |
Matteo Franchin | ed7a0f2 | 2014-06-10 19:23:45 +0100 | [diff] [blame] | 111 | case kLr: res_reg = rs_wLR; break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 112 | case kPc: res_reg = RegStorage::InvalidReg(); break; |
Matteo Franchin | ed7a0f2 | 2014-06-10 19:23:45 +0100 | [diff] [blame] | 113 | case kSp: res_reg = rs_wsp; break; |
| 114 | case kArg0: res_reg = rs_w0; break; |
| 115 | case kArg1: res_reg = rs_w1; break; |
| 116 | case kArg2: res_reg = rs_w2; break; |
| 117 | case kArg3: res_reg = rs_w3; break; |
| 118 | case kArg4: res_reg = rs_w4; break; |
| 119 | case kArg5: res_reg = rs_w5; break; |
| 120 | case kArg6: res_reg = rs_w6; break; |
| 121 | case kArg7: res_reg = rs_w7; break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 122 | case kFArg0: res_reg = rs_f0; break; |
| 123 | case kFArg1: res_reg = rs_f1; break; |
| 124 | case kFArg2: res_reg = rs_f2; break; |
| 125 | case kFArg3: res_reg = rs_f3; break; |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 126 | case kFArg4: res_reg = rs_f4; break; |
| 127 | case kFArg5: res_reg = rs_f5; break; |
| 128 | case kFArg6: res_reg = rs_f6; break; |
| 129 | case kFArg7: res_reg = rs_f7; break; |
Matteo Franchin | ed7a0f2 | 2014-06-10 19:23:45 +0100 | [diff] [blame] | 130 | case kRet0: res_reg = rs_w0; break; |
| 131 | case kRet1: res_reg = rs_w1; break; |
| 132 | case kInvokeTgt: res_reg = rs_wLR; break; |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 133 | case kHiddenArg: res_reg = rs_wIP1; break; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 134 | case kHiddenFpArg: res_reg = RegStorage::InvalidReg(); break; |
| 135 | case kCount: res_reg = RegStorage::InvalidReg(); break; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 136 | default: res_reg = RegStorage::InvalidReg(); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 137 | } |
| 138 | return res_reg; |
| 139 | } |
| 140 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 141 | /* |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 142 | * Decode the register id. This routine makes assumptions on the encoding made by RegStorage. |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 143 | */ |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 144 | ResourceMask Arm64Mir2Lir::GetRegMaskCommon(const RegStorage& reg) const { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 145 | // TODO(Arm64): this function depends too much on the internal RegStorage encoding. Refactor. |
| 146 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 147 | // Check if the shape mask is zero (i.e. invalid). |
| 148 | if (UNLIKELY(reg == rs_wzr || reg == rs_xzr)) { |
| 149 | // The zero register is not a true register. It is just an immediate zero. |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 150 | return kEncodeNone; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 151 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 152 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 153 | return ResourceMask::Bit( |
| 154 | // FP register starts at bit position 32. |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 155 | (reg.IsFloat() ? kA64FPReg0 : 0) + reg.GetRegNum()); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 156 | } |
| 157 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 158 | ResourceMask Arm64Mir2Lir::GetPCUseDefEncoding() const { |
Zheng Xu | 421efca | 2014-07-11 17:33:59 +0800 | [diff] [blame] | 159 | // Note: On arm64, we are not able to set pc except branch instructions, which is regarded as a |
| 160 | // kind of barrier. All other instructions only use pc, which has no dependency between any |
| 161 | // of them. So it is fine to just return kEncodeNone here. |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 162 | return kEncodeNone; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 163 | } |
| 164 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 165 | // Arm64 specific setup. TODO: inline?: |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 166 | void Arm64Mir2Lir::SetupTargetResourceMasks(LIR* lir, uint64_t flags, |
| 167 | ResourceMask* use_mask, ResourceMask* def_mask) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 168 | DCHECK_EQ(cu_->instruction_set, kArm64); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 169 | DCHECK(!lir->flags.use_def_invalid); |
| 170 | |
Zheng Xu | 421efca | 2014-07-11 17:33:59 +0800 | [diff] [blame] | 171 | // Note: REG_USE_PC is ignored, the reason is the same with what we do in GetPCUseDefEncoding(). |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 172 | // These flags are somewhat uncommon - bypass if we can. |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 173 | if ((flags & (REG_DEF_SP | REG_USE_SP | REG_DEF_LR)) != 0) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 174 | if (flags & REG_DEF_SP) { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 175 | def_mask->SetBit(kA64RegSP); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | if (flags & REG_USE_SP) { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 179 | use_mask->SetBit(kA64RegSP); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 180 | } |
| 181 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 182 | if (flags & REG_DEF_LR) { |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 183 | def_mask->SetBit(kA64RegLR); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | ArmConditionCode Arm64Mir2Lir::ArmConditionEncoding(ConditionCode ccode) { |
| 189 | ArmConditionCode res; |
| 190 | switch (ccode) { |
| 191 | case kCondEq: res = kArmCondEq; break; |
| 192 | case kCondNe: res = kArmCondNe; break; |
| 193 | case kCondCs: res = kArmCondCs; break; |
| 194 | case kCondCc: res = kArmCondCc; break; |
| 195 | case kCondUlt: res = kArmCondCc; break; |
| 196 | case kCondUge: res = kArmCondCs; break; |
| 197 | case kCondMi: res = kArmCondMi; break; |
| 198 | case kCondPl: res = kArmCondPl; break; |
| 199 | case kCondVs: res = kArmCondVs; break; |
| 200 | case kCondVc: res = kArmCondVc; break; |
| 201 | case kCondHi: res = kArmCondHi; break; |
| 202 | case kCondLs: res = kArmCondLs; break; |
| 203 | case kCondGe: res = kArmCondGe; break; |
| 204 | case kCondLt: res = kArmCondLt; break; |
| 205 | case kCondGt: res = kArmCondGt; break; |
| 206 | case kCondLe: res = kArmCondLe; break; |
| 207 | case kCondAl: res = kArmCondAl; break; |
| 208 | case kCondNv: res = kArmCondNv; break; |
| 209 | default: |
| 210 | LOG(FATAL) << "Bad condition code " << ccode; |
| 211 | res = static_cast<ArmConditionCode>(0); // Quiet gcc |
| 212 | } |
| 213 | return res; |
| 214 | } |
| 215 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 216 | static const char *shift_names[4] = { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 217 | "lsl", |
| 218 | "lsr", |
| 219 | "asr", |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 220 | "ror" |
| 221 | }; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 222 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 223 | static const char* extend_names[8] = { |
| 224 | "uxtb", |
| 225 | "uxth", |
| 226 | "uxtw", |
| 227 | "uxtx", |
| 228 | "sxtb", |
| 229 | "sxth", |
| 230 | "sxtw", |
| 231 | "sxtx", |
| 232 | }; |
| 233 | |
| 234 | /* Decode and print a register extension (e.g. ", uxtb #1") */ |
| 235 | static void DecodeRegExtendOrShift(int operand, char *buf, size_t buf_size) { |
| 236 | if ((operand & (1 << 6)) == 0) { |
| 237 | const char *shift_name = shift_names[(operand >> 7) & 0x3]; |
| 238 | int amount = operand & 0x3f; |
| 239 | snprintf(buf, buf_size, ", %s #%d", shift_name, amount); |
| 240 | } else { |
| 241 | const char *extend_name = extend_names[(operand >> 3) & 0x7]; |
| 242 | int amount = operand & 0x7; |
| 243 | if (amount == 0) { |
| 244 | snprintf(buf, buf_size, ", %s", extend_name); |
| 245 | } else { |
| 246 | snprintf(buf, buf_size, ", %s #%d", extend_name, amount); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | |
buzbee | f77e977 | 2014-09-02 15:39:57 -0700 | [diff] [blame] | 251 | static uint64_t bit_mask(unsigned width) { |
| 252 | DCHECK_LE(width, 64U); |
| 253 | return (width == 64) ? static_cast<uint64_t>(-1) : ((UINT64_C(1) << (width)) - UINT64_C(1)); |
| 254 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 255 | |
| 256 | static uint64_t RotateRight(uint64_t value, unsigned rotate, unsigned width) { |
| 257 | DCHECK_LE(width, 64U); |
| 258 | rotate &= 63; |
buzbee | f77e977 | 2014-09-02 15:39:57 -0700 | [diff] [blame] | 259 | value = value & bit_mask(width); |
| 260 | return ((value & bit_mask(rotate)) << (width - rotate)) | (value >> rotate); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static uint64_t RepeatBitsAcrossReg(bool is_wide, uint64_t value, unsigned width) { |
| 264 | unsigned i; |
| 265 | unsigned reg_size = (is_wide) ? 64 : 32; |
buzbee | f77e977 | 2014-09-02 15:39:57 -0700 | [diff] [blame] | 266 | uint64_t result = value & bit_mask(width); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 267 | for (i = width; i < reg_size; i *= 2) { |
| 268 | result |= (result << i); |
| 269 | } |
| 270 | DCHECK_EQ(i, reg_size); |
| 271 | return result; |
| 272 | } |
| 273 | |
| 274 | /** |
| 275 | * @brief Decode an immediate in the form required by logical instructions. |
| 276 | * |
| 277 | * @param is_wide Whether @p value encodes a 64-bit (as opposed to 32-bit) immediate. |
| 278 | * @param value The encoded logical immediates that is to be decoded. |
| 279 | * @return The decoded logical immediate. |
| 280 | * @note This is the inverse of Arm64Mir2Lir::EncodeLogicalImmediate(). |
| 281 | */ |
| 282 | uint64_t Arm64Mir2Lir::DecodeLogicalImmediate(bool is_wide, int value) { |
| 283 | unsigned n = (value >> 12) & 0x01; |
| 284 | unsigned imm_r = (value >> 6) & 0x3f; |
| 285 | unsigned imm_s = (value >> 0) & 0x3f; |
| 286 | |
| 287 | // An integer is constructed from the n, imm_s and imm_r bits according to |
| 288 | // the following table: |
| 289 | // |
| 290 | // N imms immr size S R |
| 291 | // 1 ssssss rrrrrr 64 UInt(ssssss) UInt(rrrrrr) |
| 292 | // 0 0sssss xrrrrr 32 UInt(sssss) UInt(rrrrr) |
| 293 | // 0 10ssss xxrrrr 16 UInt(ssss) UInt(rrrr) |
| 294 | // 0 110sss xxxrrr 8 UInt(sss) UInt(rrr) |
| 295 | // 0 1110ss xxxxrr 4 UInt(ss) UInt(rr) |
| 296 | // 0 11110s xxxxxr 2 UInt(s) UInt(r) |
| 297 | // (s bits must not be all set) |
| 298 | // |
| 299 | // A pattern is constructed of size bits, where the least significant S+1 |
| 300 | // bits are set. The pattern is rotated right by R, and repeated across a |
| 301 | // 32 or 64-bit value, depending on destination register width. |
| 302 | |
| 303 | if (n == 1) { |
| 304 | DCHECK_NE(imm_s, 0x3fU); |
buzbee | f77e977 | 2014-09-02 15:39:57 -0700 | [diff] [blame] | 305 | uint64_t bits = bit_mask(imm_s + 1); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 306 | return RotateRight(bits, imm_r, 64); |
| 307 | } else { |
| 308 | DCHECK_NE((imm_s >> 1), 0x1fU); |
| 309 | for (unsigned width = 0x20; width >= 0x2; width >>= 1) { |
| 310 | if ((imm_s & width) == 0) { |
| 311 | unsigned mask = (unsigned)(width - 1); |
| 312 | DCHECK_NE((imm_s & mask), mask); |
buzbee | f77e977 | 2014-09-02 15:39:57 -0700 | [diff] [blame] | 313 | uint64_t bits = bit_mask((imm_s & mask) + 1); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 314 | return RepeatBitsAcrossReg(is_wide, RotateRight(bits, imm_r & mask, width), width); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | } |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 318 | return 0; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 319 | } |
| 320 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 321 | /** |
| 322 | * @brief Decode an 8-bit single point number encoded with EncodeImmSingle(). |
| 323 | */ |
| 324 | static float DecodeImmSingle(uint8_t small_float) { |
| 325 | int mantissa = (small_float & 0x0f) + 0x10; |
| 326 | int sign = ((small_float & 0x80) == 0) ? 1 : -1; |
| 327 | float signed_mantissa = static_cast<float>(sign*mantissa); |
| 328 | int exponent = (((small_float >> 4) & 0x7) + 4) & 0x7; |
| 329 | return signed_mantissa*static_cast<float>(1 << exponent)*0.0078125f; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 330 | } |
| 331 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 332 | static const char* cc_names[] = {"eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", |
| 333 | "hi", "ls", "ge", "lt", "gt", "le", "al", "nv"}; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 334 | /* |
| 335 | * Interpret a format string and build a string no longer than size |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 336 | * See format key in assemble_arm64.cc. |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 337 | */ |
| 338 | std::string Arm64Mir2Lir::BuildInsnString(const char* fmt, LIR* lir, unsigned char* base_addr) { |
| 339 | std::string buf; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 340 | const char* fmt_end = &fmt[strlen(fmt)]; |
| 341 | char tbuf[256]; |
| 342 | const char* name; |
| 343 | char nc; |
| 344 | while (fmt < fmt_end) { |
| 345 | int operand; |
| 346 | if (*fmt == '!') { |
| 347 | fmt++; |
| 348 | DCHECK_LT(fmt, fmt_end); |
| 349 | nc = *fmt++; |
| 350 | if (nc == '!') { |
| 351 | strcpy(tbuf, "!"); |
| 352 | } else { |
| 353 | DCHECK_LT(fmt, fmt_end); |
| 354 | DCHECK_LT(static_cast<unsigned>(nc-'0'), 4U); |
| 355 | operand = lir->operands[nc-'0']; |
| 356 | switch (*fmt++) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 357 | case 'e': { |
| 358 | // Omit ", uxtw #0" in strings like "add w0, w1, w3, uxtw #0" and |
| 359 | // ", uxtx #0" in strings like "add x0, x1, x3, uxtx #0" |
| 360 | int omittable = ((IS_WIDE(lir->opcode)) ? EncodeExtend(kA64Uxtw, 0) : |
| 361 | EncodeExtend(kA64Uxtw, 0)); |
| 362 | if (LIKELY(operand == omittable)) { |
| 363 | strcpy(tbuf, ""); |
| 364 | } else { |
| 365 | DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf)); |
| 366 | } |
| 367 | } |
| 368 | break; |
| 369 | case 'o': |
| 370 | // Omit ", lsl #0" |
| 371 | if (LIKELY(operand == EncodeShift(kA64Lsl, 0))) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 372 | strcpy(tbuf, ""); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 373 | } else { |
| 374 | DecodeRegExtendOrShift(operand, tbuf, arraysize(tbuf)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 375 | } |
| 376 | break; |
| 377 | case 'B': |
| 378 | switch (operand) { |
| 379 | case kSY: |
| 380 | name = "sy"; |
| 381 | break; |
| 382 | case kST: |
| 383 | name = "st"; |
| 384 | break; |
| 385 | case kISH: |
| 386 | name = "ish"; |
| 387 | break; |
| 388 | case kISHST: |
| 389 | name = "ishst"; |
| 390 | break; |
| 391 | case kNSH: |
| 392 | name = "nsh"; |
| 393 | break; |
| 394 | case kNSHST: |
| 395 | name = "shst"; |
| 396 | break; |
| 397 | default: |
| 398 | name = "DecodeError2"; |
| 399 | break; |
| 400 | } |
| 401 | strcpy(tbuf, name); |
| 402 | break; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 403 | case 's': |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 404 | snprintf(tbuf, arraysize(tbuf), "s%d", operand & RegStorage::kRegNumMask); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 405 | break; |
| 406 | case 'S': |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 407 | snprintf(tbuf, arraysize(tbuf), "d%d", operand & RegStorage::kRegNumMask); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 408 | break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 409 | case 'f': |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 410 | snprintf(tbuf, arraysize(tbuf), "%c%d", (IS_WIDE(lir->opcode)) ? 'd' : 's', |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 411 | operand & RegStorage::kRegNumMask); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 412 | break; |
| 413 | case 'l': { |
| 414 | bool is_wide = IS_WIDE(lir->opcode); |
| 415 | uint64_t imm = DecodeLogicalImmediate(is_wide, operand); |
| 416 | snprintf(tbuf, arraysize(tbuf), "%" PRId64 " (%#" PRIx64 ")", imm, imm); |
| 417 | } |
| 418 | break; |
| 419 | case 'I': |
| 420 | snprintf(tbuf, arraysize(tbuf), "%f", DecodeImmSingle(operand)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 421 | break; |
| 422 | case 'M': |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 423 | if (LIKELY(operand == 0)) |
| 424 | strcpy(tbuf, ""); |
| 425 | else |
| 426 | snprintf(tbuf, arraysize(tbuf), ", lsl #%d", 16*operand); |
| 427 | break; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 428 | case 'd': |
| 429 | snprintf(tbuf, arraysize(tbuf), "%d", operand); |
| 430 | break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 431 | case 'w': |
| 432 | if (LIKELY(operand != rwzr)) |
| 433 | snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask); |
| 434 | else |
| 435 | strcpy(tbuf, "wzr"); |
| 436 | break; |
| 437 | case 'W': |
| 438 | if (LIKELY(operand != rwsp)) |
| 439 | snprintf(tbuf, arraysize(tbuf), "w%d", operand & RegStorage::kRegNumMask); |
| 440 | else |
| 441 | strcpy(tbuf, "wsp"); |
| 442 | break; |
| 443 | case 'x': |
| 444 | if (LIKELY(operand != rxzr)) |
| 445 | snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask); |
| 446 | else |
| 447 | strcpy(tbuf, "xzr"); |
| 448 | break; |
| 449 | case 'X': |
| 450 | if (LIKELY(operand != rsp)) |
| 451 | snprintf(tbuf, arraysize(tbuf), "x%d", operand & RegStorage::kRegNumMask); |
| 452 | else |
| 453 | strcpy(tbuf, "sp"); |
| 454 | break; |
| 455 | case 'D': |
| 456 | snprintf(tbuf, arraysize(tbuf), "%d", operand*((IS_WIDE(lir->opcode)) ? 8 : 4)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 457 | break; |
| 458 | case 'E': |
| 459 | snprintf(tbuf, arraysize(tbuf), "%d", operand*4); |
| 460 | break; |
| 461 | case 'F': |
| 462 | snprintf(tbuf, arraysize(tbuf), "%d", operand*2); |
| 463 | break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 464 | case 'G': |
| 465 | if (LIKELY(operand == 0)) |
| 466 | strcpy(tbuf, ""); |
| 467 | else |
| 468 | strcpy(tbuf, (IS_WIDE(lir->opcode)) ? ", lsl #3" : ", lsl #2"); |
| 469 | break; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 470 | case 'c': |
| 471 | strcpy(tbuf, cc_names[operand]); |
| 472 | break; |
| 473 | case 't': |
| 474 | snprintf(tbuf, arraysize(tbuf), "0x%08" PRIxPTR " (L%p)", |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 475 | reinterpret_cast<uintptr_t>(base_addr) + lir->offset + (operand << 2), |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 476 | lir->target); |
| 477 | break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 478 | case 'r': { |
| 479 | bool is_wide = IS_WIDE(lir->opcode); |
| 480 | if (LIKELY(operand != rwzr && operand != rxzr)) { |
| 481 | snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w', |
| 482 | operand & RegStorage::kRegNumMask); |
| 483 | } else { |
| 484 | strcpy(tbuf, (is_wide) ? "xzr" : "wzr"); |
| 485 | } |
| 486 | } |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 487 | break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 488 | case 'R': { |
| 489 | bool is_wide = IS_WIDE(lir->opcode); |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 490 | if (LIKELY(operand != rwsp && operand != rsp)) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 491 | snprintf(tbuf, arraysize(tbuf), "%c%d", (is_wide) ? 'x' : 'w', |
| 492 | operand & RegStorage::kRegNumMask); |
| 493 | } else { |
| 494 | strcpy(tbuf, (is_wide) ? "sp" : "wsp"); |
| 495 | } |
| 496 | } |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 497 | break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 498 | case 'p': |
| 499 | snprintf(tbuf, arraysize(tbuf), ".+%d (addr %#" PRIxPTR ")", 4*operand, |
| 500 | reinterpret_cast<uintptr_t>(base_addr) + lir->offset + 4*operand); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 501 | break; |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 502 | case 'T': |
| 503 | if (LIKELY(operand == 0)) |
| 504 | strcpy(tbuf, ""); |
| 505 | else if (operand == 1) |
| 506 | strcpy(tbuf, ", lsl #12"); |
| 507 | else |
| 508 | strcpy(tbuf, ", DecodeError3"); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 509 | break; |
Zheng Xu | 5d7cdec | 2014-08-18 17:28:22 +0800 | [diff] [blame] | 510 | case 'h': |
| 511 | snprintf(tbuf, arraysize(tbuf), "%d", operand); |
| 512 | break; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 513 | default: |
| 514 | strcpy(tbuf, "DecodeError1"); |
| 515 | break; |
| 516 | } |
| 517 | buf += tbuf; |
| 518 | } |
| 519 | } else { |
| 520 | buf += *fmt++; |
| 521 | } |
| 522 | } |
Zheng Xu | a34e760 | 2015-02-03 12:03:15 +0800 | [diff] [blame] | 523 | // Dump thread offset. |
| 524 | std::string fmt_str = GetTargetInstFmt(lir->opcode); |
| 525 | if (std::string::npos != fmt_str.find(", [!1X, #!2") && rxSELF == lir->operands[1] && |
| 526 | std::string::npos != buf.find(", [")) { |
| 527 | int offset = lir->operands[2]; |
| 528 | if (std::string::npos != fmt_str.find("#!2d")) { |
| 529 | } else if (std::string::npos != fmt_str.find("#!2D")) { |
| 530 | offset *= (IS_WIDE(lir->opcode)) ? 8 : 4; |
| 531 | } else if (std::string::npos != fmt_str.find("#!2F")) { |
| 532 | offset *= 2; |
| 533 | } else { |
| 534 | LOG(FATAL) << "Should not reach here"; |
| 535 | } |
| 536 | std::ostringstream tmp_stream; |
| 537 | Thread::DumpThreadOffset<8>(tmp_stream, offset); |
| 538 | buf += " ; "; |
| 539 | buf += tmp_stream.str(); |
| 540 | } |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 541 | return buf; |
| 542 | } |
| 543 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 544 | void Arm64Mir2Lir::DumpResourceMask(LIR* arm_lir, const ResourceMask& mask, const char* prefix) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 545 | char buf[256]; |
| 546 | buf[0] = 0; |
| 547 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 548 | if (mask.Equals(kEncodeAll)) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 549 | strcpy(buf, "all"); |
| 550 | } else { |
| 551 | char num[8]; |
| 552 | int i; |
| 553 | |
Matteo Franchin | 4163c53 | 2014-07-15 15:20:27 +0100 | [diff] [blame] | 554 | for (i = 0; i < kA64RegEnd; i++) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 555 | if (mask.HasBit(i)) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 556 | snprintf(num, arraysize(num), "%d ", i); |
| 557 | strcat(buf, num); |
| 558 | } |
| 559 | } |
| 560 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 561 | if (mask.HasBit(ResourceMask::kCCode)) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 562 | strcat(buf, "cc "); |
| 563 | } |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 564 | if (mask.HasBit(ResourceMask::kFPStatus)) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 565 | strcat(buf, "fpcc "); |
| 566 | } |
| 567 | |
| 568 | /* Memory bits */ |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 569 | if (arm_lir && (mask.HasBit(ResourceMask::kDalvikReg))) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 570 | snprintf(buf + strlen(buf), arraysize(buf) - strlen(buf), "dr%d%s", |
| 571 | DECODE_ALIAS_INFO_REG(arm_lir->flags.alias_info), |
| 572 | DECODE_ALIAS_INFO_WIDE(arm_lir->flags.alias_info) ? "(+1)" : ""); |
| 573 | } |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 574 | if (mask.HasBit(ResourceMask::kLiteral)) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 575 | strcat(buf, "lit "); |
| 576 | } |
| 577 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 578 | if (mask.HasBit(ResourceMask::kHeapRef)) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 579 | strcat(buf, "heap "); |
| 580 | } |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 581 | if (mask.HasBit(ResourceMask::kMustNotAlias)) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 582 | strcat(buf, "noalias "); |
| 583 | } |
| 584 | } |
| 585 | if (buf[0]) { |
| 586 | LOG(INFO) << prefix << ": " << buf; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | bool Arm64Mir2Lir::IsUnconditionalBranch(LIR* lir) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 591 | return (lir->opcode == kA64B1t); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 594 | RegisterClass Arm64Mir2Lir::RegClassForFieldLoadStore(OpSize size, bool is_volatile) { |
| 595 | if (UNLIKELY(is_volatile)) { |
| 596 | // On arm64, fp register load/store is atomic only for single bytes. |
| 597 | if (size != kSignedByte && size != kUnsignedByte) { |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 598 | return (size == kReference) ? kRefReg : kCoreReg; |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 599 | } |
| 600 | } |
| 601 | return RegClassBySize(size); |
| 602 | } |
| 603 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 604 | Arm64Mir2Lir::Arm64Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena) |
Vladimir Marko | 7c2ad5a | 2014-09-24 12:42:55 +0100 | [diff] [blame] | 605 | : Mir2Lir(cu, mir_graph, arena), |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 606 | call_method_insns_(arena->Adapter()), |
| 607 | dex_cache_access_insns_(arena->Adapter()) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 608 | // Sanity check - make sure encoding map lines up. |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 609 | for (int i = 0; i < kA64Last; i++) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 610 | DCHECK_EQ(UNWIDE(Arm64Mir2Lir::EncodingMap[i].opcode), i) |
| 611 | << "Encoding order for " << Arm64Mir2Lir::EncodingMap[i].name |
| 612 | << " is wrong: expecting " << i << ", seeing " |
| 613 | << static_cast<int>(Arm64Mir2Lir::EncodingMap[i].opcode); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 617 | Mir2Lir* Arm64CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph, |
| 618 | ArenaAllocator* const arena) { |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 619 | return new Arm64Mir2Lir(cu, mir_graph, arena); |
| 620 | } |
| 621 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 622 | void Arm64Mir2Lir::CompilerInitializeRegAlloc() { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 623 | reg_pool_.reset(new (arena_) RegisterPool(this, arena_, core_regs, core64_regs, sp_regs, dp_regs, |
| 624 | reserved_regs, reserved64_regs, |
| 625 | core_temps, core64_temps, sp_temps, dp_temps)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 626 | |
| 627 | // Target-specific adjustments. |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 628 | // Alias single precision float registers to corresponding double registers. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 629 | for (RegisterInfo* info : reg_pool_->sp_regs_) { |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 630 | int fp_reg_num = info->GetReg().GetRegNum(); |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 631 | RegStorage dp_reg = RegStorage::FloatSolo64(fp_reg_num); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 632 | RegisterInfo* dp_reg_info = GetRegInfo(dp_reg); |
| 633 | // Double precision register's master storage should refer to itself. |
| 634 | DCHECK_EQ(dp_reg_info, dp_reg_info->Master()); |
| 635 | // Redirect single precision's master storage to master. |
| 636 | info->SetMaster(dp_reg_info); |
| 637 | // Singles should show a single 32-bit mask bit, at first referring to the low half. |
| 638 | DCHECK_EQ(info->StorageMask(), 0x1U); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 639 | } |
| 640 | |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 641 | // Alias 32bit W registers to corresponding 64bit X registers. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 642 | for (RegisterInfo* info : reg_pool_->core_regs_) { |
Serban Constantinescu | ed65c5e | 2014-05-22 15:10:18 +0100 | [diff] [blame] | 643 | int x_reg_num = info->GetReg().GetRegNum(); |
| 644 | RegStorage x_reg = RegStorage::Solo64(x_reg_num); |
| 645 | RegisterInfo* x_reg_info = GetRegInfo(x_reg); |
| 646 | // 64bit X register's master storage should refer to itself. |
| 647 | DCHECK_EQ(x_reg_info, x_reg_info->Master()); |
| 648 | // Redirect 32bit W master storage to 64bit X. |
| 649 | info->SetMaster(x_reg_info); |
| 650 | // 32bit W should show a single 32-bit mask bit, at first referring to the low half. |
| 651 | DCHECK_EQ(info->StorageMask(), 0x1U); |
| 652 | } |
| 653 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 654 | // Don't start allocating temps at r0/s0/d0 or you may clobber return regs in early-exit methods. |
| 655 | // TODO: adjust when we roll to hard float calling convention. |
| 656 | reg_pool_->next_core_reg_ = 2; |
| 657 | reg_pool_->next_sp_reg_ = 0; |
| 658 | reg_pool_->next_dp_reg_ = 0; |
| 659 | } |
| 660 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 661 | /* |
| 662 | * TUNING: is true leaf? Can't just use METHOD_IS_LEAF to determine as some |
| 663 | * instructions might call out to C/assembly helper functions. Until |
| 664 | * machinery is in place, always spill lr. |
| 665 | */ |
| 666 | |
| 667 | void Arm64Mir2Lir::AdjustSpillMask() { |
Zheng Xu | baa7c88 | 2014-06-30 14:26:50 +0800 | [diff] [blame] | 668 | core_spill_mask_ |= (1 << rs_xLR.GetRegNum()); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 669 | num_core_spills_++; |
| 670 | } |
| 671 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 672 | /* Clobber all regs that might be used by an external C call */ |
| 673 | void Arm64Mir2Lir::ClobberCallerSave() { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 674 | Clobber(rs_x0); |
| 675 | Clobber(rs_x1); |
| 676 | Clobber(rs_x2); |
| 677 | Clobber(rs_x3); |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 678 | Clobber(rs_x4); |
| 679 | Clobber(rs_x5); |
| 680 | Clobber(rs_x6); |
| 681 | Clobber(rs_x7); |
| 682 | Clobber(rs_x8); |
| 683 | Clobber(rs_x9); |
| 684 | Clobber(rs_x10); |
| 685 | Clobber(rs_x11); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 686 | Clobber(rs_x12); |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 687 | Clobber(rs_x13); |
| 688 | Clobber(rs_x14); |
| 689 | Clobber(rs_x15); |
| 690 | Clobber(rs_x16); |
| 691 | Clobber(rs_x17); |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame^] | 692 | Clobber(rs_x18); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 693 | Clobber(rs_x30); |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 694 | |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 695 | Clobber(rs_f0); |
| 696 | Clobber(rs_f1); |
| 697 | Clobber(rs_f2); |
| 698 | Clobber(rs_f3); |
| 699 | Clobber(rs_f4); |
| 700 | Clobber(rs_f5); |
| 701 | Clobber(rs_f6); |
| 702 | Clobber(rs_f7); |
Matteo Franchin | bc6d197 | 2014-05-13 12:33:28 +0100 | [diff] [blame] | 703 | Clobber(rs_f16); |
| 704 | Clobber(rs_f17); |
| 705 | Clobber(rs_f18); |
| 706 | Clobber(rs_f19); |
| 707 | Clobber(rs_f20); |
| 708 | Clobber(rs_f21); |
| 709 | Clobber(rs_f22); |
| 710 | Clobber(rs_f23); |
| 711 | Clobber(rs_f24); |
| 712 | Clobber(rs_f25); |
| 713 | Clobber(rs_f26); |
| 714 | Clobber(rs_f27); |
| 715 | Clobber(rs_f28); |
| 716 | Clobber(rs_f29); |
| 717 | Clobber(rs_f30); |
| 718 | Clobber(rs_f31); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | RegLocation Arm64Mir2Lir::GetReturnWideAlt() { |
| 722 | RegLocation res = LocCReturnWide(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 723 | res.reg.SetReg(rx2); |
| 724 | res.reg.SetHighReg(rx3); |
| 725 | Clobber(rs_x2); |
| 726 | Clobber(rs_x3); |
| 727 | MarkInUse(rs_x2); |
| 728 | MarkInUse(rs_x3); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 729 | MarkWide(res.reg); |
| 730 | return res; |
| 731 | } |
| 732 | |
| 733 | RegLocation Arm64Mir2Lir::GetReturnAlt() { |
| 734 | RegLocation res = LocCReturn(); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 735 | res.reg.SetReg(rx1); |
| 736 | Clobber(rs_x1); |
| 737 | MarkInUse(rs_x1); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 738 | return res; |
| 739 | } |
| 740 | |
| 741 | /* To be used when explicitly managing register use */ |
| 742 | void Arm64Mir2Lir::LockCallTemps() { |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 743 | // TODO: needs cleanup. |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 744 | LockTemp(rs_x0); |
| 745 | LockTemp(rs_x1); |
| 746 | LockTemp(rs_x2); |
| 747 | LockTemp(rs_x3); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 748 | LockTemp(rs_x4); |
| 749 | LockTemp(rs_x5); |
| 750 | LockTemp(rs_x6); |
| 751 | LockTemp(rs_x7); |
| 752 | LockTemp(rs_f0); |
| 753 | LockTemp(rs_f1); |
| 754 | LockTemp(rs_f2); |
| 755 | LockTemp(rs_f3); |
| 756 | LockTemp(rs_f4); |
| 757 | LockTemp(rs_f5); |
| 758 | LockTemp(rs_f6); |
| 759 | LockTemp(rs_f7); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /* To be used when explicitly managing register use */ |
| 763 | void Arm64Mir2Lir::FreeCallTemps() { |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 764 | // TODO: needs cleanup. |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 765 | FreeTemp(rs_x0); |
| 766 | FreeTemp(rs_x1); |
| 767 | FreeTemp(rs_x2); |
| 768 | FreeTemp(rs_x3); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 769 | FreeTemp(rs_x4); |
| 770 | FreeTemp(rs_x5); |
| 771 | FreeTemp(rs_x6); |
| 772 | FreeTemp(rs_x7); |
| 773 | FreeTemp(rs_f0); |
| 774 | FreeTemp(rs_f1); |
| 775 | FreeTemp(rs_f2); |
| 776 | FreeTemp(rs_f3); |
| 777 | FreeTemp(rs_f4); |
| 778 | FreeTemp(rs_f5); |
| 779 | FreeTemp(rs_f6); |
| 780 | FreeTemp(rs_f7); |
Vladimir Marko | bfe400b | 2014-12-19 19:27:26 +0000 | [diff] [blame] | 781 | FreeTemp(TargetReg(kHiddenArg)); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 782 | } |
| 783 | |
Andreas Gampe | 9843059 | 2014-07-27 19:44:50 -0700 | [diff] [blame] | 784 | RegStorage Arm64Mir2Lir::LoadHelper(QuickEntrypointEnum trampoline) { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 785 | // TODO(Arm64): use LoadWordDisp instead. |
| 786 | // e.g. LoadWordDisp(rs_rA64_SELF, offset.Int32Value(), rs_rA64_LR); |
Andreas Gampe | 9843059 | 2014-07-27 19:44:50 -0700 | [diff] [blame] | 787 | LoadBaseDisp(rs_xSELF, GetThreadOffset<8>(trampoline).Int32Value(), rs_xLR, k64, kNotVolatile); |
Zheng Xu | baa7c88 | 2014-06-30 14:26:50 +0800 | [diff] [blame] | 788 | return rs_xLR; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 789 | } |
| 790 | |
| 791 | LIR* Arm64Mir2Lir::CheckSuspendUsingLoad() { |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 792 | RegStorage tmp = rs_x0; |
Zheng Xu | baa7c88 | 2014-06-30 14:26:50 +0800 | [diff] [blame] | 793 | LoadWordDisp(rs_xSELF, Thread::ThreadSuspendTriggerOffset<8>().Int32Value(), tmp); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 794 | LIR* load2 = LoadWordDisp(tmp, 0, tmp); |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 795 | return load2; |
| 796 | } |
| 797 | |
| 798 | uint64_t Arm64Mir2Lir::GetTargetInstFlags(int opcode) { |
| 799 | DCHECK(!IsPseudoLirOp(opcode)); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 800 | return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].flags; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | const char* Arm64Mir2Lir::GetTargetInstName(int opcode) { |
| 804 | DCHECK(!IsPseudoLirOp(opcode)); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 805 | return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].name; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | const char* Arm64Mir2Lir::GetTargetInstFmt(int opcode) { |
| 809 | DCHECK(!IsPseudoLirOp(opcode)); |
Matteo Franchin | e45fb9e | 2014-05-06 10:10:30 +0100 | [diff] [blame] | 810 | return Arm64Mir2Lir::EncodingMap[UNWIDE(opcode)].fmt; |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 811 | } |
| 812 | |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 813 | RegStorage Arm64Mir2Lir::InToRegStorageArm64Mapper::GetNextReg(ShortyArg arg) { |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 814 | const RegStorage coreArgMappingToPhysicalReg[] = |
| 815 | {rs_x1, rs_x2, rs_x3, rs_x4, rs_x5, rs_x6, rs_x7}; |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 816 | const size_t coreArgMappingToPhysicalRegSize = arraysize(coreArgMappingToPhysicalReg); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 817 | const RegStorage fpArgMappingToPhysicalReg[] = |
| 818 | {rs_f0, rs_f1, rs_f2, rs_f3, rs_f4, rs_f5, rs_f6, rs_f7}; |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 819 | const size_t fpArgMappingToPhysicalRegSize = arraysize(fpArgMappingToPhysicalReg); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 820 | |
| 821 | RegStorage result = RegStorage::InvalidReg(); |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 822 | if (arg.IsFP()) { |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 823 | if (cur_fp_reg_ < fpArgMappingToPhysicalRegSize) { |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 824 | DCHECK(!arg.IsRef()); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 825 | result = fpArgMappingToPhysicalReg[cur_fp_reg_++]; |
| 826 | if (result.Valid()) { |
| 827 | // TODO: switching between widths remains a bit ugly. Better way? |
| 828 | int res_reg = result.GetReg(); |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 829 | result = arg.IsWide() ? RegStorage::FloatSolo64(res_reg) : RegStorage::FloatSolo32(res_reg); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | } else { |
| 833 | if (cur_core_reg_ < coreArgMappingToPhysicalRegSize) { |
| 834 | result = coreArgMappingToPhysicalReg[cur_core_reg_++]; |
| 835 | if (result.Valid()) { |
| 836 | // TODO: switching between widths remains a bit ugly. Better way? |
| 837 | int res_reg = result.GetReg(); |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 838 | DCHECK(!(arg.IsWide() && arg.IsRef())); |
| 839 | result = (arg.IsWide() || arg.IsRef()) ? |
| 840 | RegStorage::Solo64(res_reg) : RegStorage::Solo32(res_reg); |
buzbee | 33ae558 | 2014-06-12 14:56:32 -0700 | [diff] [blame] | 841 | } |
| 842 | } |
| 843 | } |
| 844 | return result; |
| 845 | } |
| 846 | |
Vladimir Marko | 7c2ad5a | 2014-09-24 12:42:55 +0100 | [diff] [blame] | 847 | void Arm64Mir2Lir::InstallLiteralPools() { |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 848 | patches_.reserve(call_method_insns_.size() + dex_cache_access_insns_.size()); |
| 849 | |
Vladimir Marko | 7c2ad5a | 2014-09-24 12:42:55 +0100 | [diff] [blame] | 850 | // PC-relative calls to methods. |
Vladimir Marko | 7c2ad5a | 2014-09-24 12:42:55 +0100 | [diff] [blame] | 851 | for (LIR* p : call_method_insns_) { |
| 852 | DCHECK_EQ(p->opcode, kA64Bl1t); |
| 853 | uint32_t target_method_idx = p->operands[1]; |
Vladimir Marko | f6737f7 | 2015-03-23 17:05:14 +0000 | [diff] [blame] | 854 | const DexFile* target_dex_file = UnwrapPointer<DexFile>(p->operands[2]); |
Vladimir Marko | 7c2ad5a | 2014-09-24 12:42:55 +0100 | [diff] [blame] | 855 | patches_.push_back(LinkerPatch::RelativeCodePatch(p->offset, |
| 856 | target_dex_file, target_method_idx)); |
| 857 | } |
| 858 | |
Vladimir Marko | 20f8559 | 2015-03-19 10:07:02 +0000 | [diff] [blame] | 859 | // PC-relative references to dex cache arrays. |
| 860 | for (LIR* p : dex_cache_access_insns_) { |
| 861 | DCHECK(p->opcode == kA64Adrp2xd || p->opcode == kA64Ldr3rXD); |
| 862 | const LIR* adrp = UnwrapPointer<LIR>(p->operands[4]); |
| 863 | DCHECK_EQ(adrp->opcode, kA64Adrp2xd); |
| 864 | const DexFile* dex_file = UnwrapPointer<DexFile>(adrp->operands[2]); |
| 865 | uint32_t offset = adrp->operands[3]; |
| 866 | DCHECK(!p->flags.is_nop); |
| 867 | DCHECK(!adrp->flags.is_nop); |
| 868 | patches_.push_back(LinkerPatch::DexCacheArrayPatch(p->offset, dex_file, adrp->offset, offset)); |
| 869 | } |
| 870 | |
Vladimir Marko | 7c2ad5a | 2014-09-24 12:42:55 +0100 | [diff] [blame] | 871 | // And do the normal processing. |
| 872 | Mir2Lir::InstallLiteralPools(); |
| 873 | } |
| 874 | |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 875 | int Arm64Mir2Lir::GenDalvikArgsBulkCopy(CallInfo* /*info*/, int /*first*/, int count) { |
| 876 | /* |
| 877 | * TODO: Improve by adding block copy for large number of arguments. For now, just |
| 878 | * copy a Dalvik vreg at a time. |
| 879 | */ |
| 880 | return count; |
| 881 | } |
| 882 | |
Ningsheng Jian | a262f77 | 2014-11-25 16:48:07 +0800 | [diff] [blame] | 883 | void Arm64Mir2Lir::GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir) { |
| 884 | UNUSED(bb); |
| 885 | DCHECK(MIR::DecodedInstruction::IsPseudoMirOp(mir->dalvikInsn.opcode)); |
| 886 | RegLocation rl_src[3]; |
| 887 | RegLocation rl_dest = mir_graph_->GetBadLoc(); |
| 888 | rl_src[0] = rl_src[1] = rl_src[2] = mir_graph_->GetBadLoc(); |
| 889 | ExtendedMIROpcode opcode = static_cast<ExtendedMIROpcode>(mir->dalvikInsn.opcode); |
| 890 | switch (opcode) { |
| 891 | case kMirOpMaddInt: |
| 892 | case kMirOpMsubInt: |
| 893 | rl_dest = mir_graph_->GetDest(mir); |
| 894 | rl_src[0] = mir_graph_->GetSrc(mir, 0); |
| 895 | rl_src[1] = mir_graph_->GetSrc(mir, 1); |
| 896 | rl_src[2]= mir_graph_->GetSrc(mir, 2); |
| 897 | GenMaddMsubInt(rl_dest, rl_src[0], rl_src[1], rl_src[2], |
| 898 | (opcode == kMirOpMsubInt) ? true : false); |
| 899 | break; |
| 900 | case kMirOpMaddLong: |
| 901 | case kMirOpMsubLong: |
| 902 | rl_dest = mir_graph_->GetDestWide(mir); |
| 903 | rl_src[0] = mir_graph_->GetSrcWide(mir, 0); |
| 904 | rl_src[1] = mir_graph_->GetSrcWide(mir, 2); |
| 905 | rl_src[2] = mir_graph_->GetSrcWide(mir, 4); |
| 906 | GenMaddMsubLong(rl_dest, rl_src[0], rl_src[1], rl_src[2], |
| 907 | (opcode == kMirOpMsubLong) ? true : false); |
| 908 | break; |
| 909 | default: |
| 910 | LOG(FATAL) << "Unexpected opcode: " << static_cast<int>(opcode); |
| 911 | } |
| 912 | } |
| 913 | |
Matteo Franchin | 43ec873 | 2014-03-31 15:00:14 +0100 | [diff] [blame] | 914 | } // namespace art |