Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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 | |
Nicolas Geoffray | f3e2cc4 | 2014-02-18 18:37:26 +0000 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <inttypes.h> |
| 19 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 20 | #include "codegen_x86.h" |
| 21 | #include "dex/compiler_internals.h" |
| 22 | #include "dex/quick/mir_to_lir-inl.h" |
buzbee | b5860fb | 2014-06-21 15:31:01 -0700 | [diff] [blame] | 23 | #include "dex/reg_storage_eq.h" |
Mark Mendell | e19c91f | 2014-02-25 08:19:08 -0800 | [diff] [blame] | 24 | #include "mirror/array.h" |
| 25 | #include "mirror/string.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 26 | #include "x86_lir.h" |
| 27 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 28 | namespace art { |
| 29 | |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 30 | static constexpr RegStorage core_regs_arr_32[] = { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 31 | rs_rAX, rs_rCX, rs_rDX, rs_rBX, rs_rX86_SP_32, rs_rBP, rs_rSI, rs_rDI, |
| 32 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 33 | static constexpr RegStorage core_regs_arr_64[] = { |
Dmitry Petrochenko | 76af0d3 | 2014-06-05 21:15:08 +0700 | [diff] [blame] | 34 | rs_rAX, rs_rCX, rs_rDX, rs_rBX, rs_rX86_SP_32, rs_rBP, rs_rSI, rs_rDI, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 35 | rs_r8, rs_r9, rs_r10, rs_r11, rs_r12, rs_r13, rs_r14, rs_r15 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 36 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 37 | static constexpr RegStorage core_regs_arr_64q[] = { |
Dmitry Petrochenko | 0999a6f | 2014-05-22 12:26:50 +0700 | [diff] [blame] | 38 | rs_r0q, rs_r1q, rs_r2q, rs_r3q, rs_rX86_SP_64, rs_r5q, rs_r6q, rs_r7q, |
Dmitry Petrochenko | a20468c | 2014-04-30 13:40:19 +0700 | [diff] [blame] | 39 | rs_r8q, rs_r9q, rs_r10q, rs_r11q, rs_r12q, rs_r13q, rs_r14q, rs_r15q |
Dmitry Petrochenko | 0999a6f | 2014-05-22 12:26:50 +0700 | [diff] [blame] | 40 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 41 | static constexpr RegStorage sp_regs_arr_32[] = { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 42 | rs_fr0, rs_fr1, rs_fr2, rs_fr3, rs_fr4, rs_fr5, rs_fr6, rs_fr7, |
| 43 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 44 | static constexpr RegStorage sp_regs_arr_64[] = { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 45 | rs_fr0, rs_fr1, rs_fr2, rs_fr3, rs_fr4, rs_fr5, rs_fr6, rs_fr7, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 46 | rs_fr8, rs_fr9, rs_fr10, rs_fr11, rs_fr12, rs_fr13, rs_fr14, rs_fr15 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 47 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 48 | static constexpr RegStorage dp_regs_arr_32[] = { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 49 | rs_dr0, rs_dr1, rs_dr2, rs_dr3, rs_dr4, rs_dr5, rs_dr6, rs_dr7, |
| 50 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 51 | static constexpr RegStorage dp_regs_arr_64[] = { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 52 | rs_dr0, rs_dr1, rs_dr2, rs_dr3, rs_dr4, rs_dr5, rs_dr6, rs_dr7, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 53 | rs_dr8, rs_dr9, rs_dr10, rs_dr11, rs_dr12, rs_dr13, rs_dr14, rs_dr15 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 54 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 55 | static constexpr RegStorage reserved_regs_arr_32[] = {rs_rX86_SP_32}; |
Dmitry Petrochenko | 76af0d3 | 2014-06-05 21:15:08 +0700 | [diff] [blame] | 56 | static constexpr RegStorage reserved_regs_arr_64[] = {rs_rX86_SP_32}; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 57 | static constexpr RegStorage reserved_regs_arr_64q[] = {rs_rX86_SP_64}; |
| 58 | static constexpr RegStorage core_temps_arr_32[] = {rs_rAX, rs_rCX, rs_rDX, rs_rBX}; |
| 59 | static constexpr RegStorage core_temps_arr_64[] = { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 60 | rs_rAX, rs_rCX, rs_rDX, rs_rSI, rs_rDI, |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 61 | rs_r8, rs_r9, rs_r10, rs_r11 |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 62 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 63 | static constexpr RegStorage core_temps_arr_64q[] = { |
Dmitry Petrochenko | 0999a6f | 2014-05-22 12:26:50 +0700 | [diff] [blame] | 64 | rs_r0q, rs_r1q, rs_r2q, rs_r6q, rs_r7q, |
Dmitry Petrochenko | 0999a6f | 2014-05-22 12:26:50 +0700 | [diff] [blame] | 65 | rs_r8q, rs_r9q, rs_r10q, rs_r11q |
Dmitry Petrochenko | 0999a6f | 2014-05-22 12:26:50 +0700 | [diff] [blame] | 66 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 67 | static constexpr RegStorage sp_temps_arr_32[] = { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 68 | rs_fr0, rs_fr1, rs_fr2, rs_fr3, rs_fr4, rs_fr5, rs_fr6, rs_fr7, |
| 69 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 70 | static constexpr RegStorage sp_temps_arr_64[] = { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 71 | rs_fr0, rs_fr1, rs_fr2, rs_fr3, rs_fr4, rs_fr5, rs_fr6, rs_fr7, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 72 | rs_fr8, rs_fr9, rs_fr10, rs_fr11, rs_fr12, rs_fr13, rs_fr14, rs_fr15 |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 73 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 74 | static constexpr RegStorage dp_temps_arr_32[] = { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 75 | rs_dr0, rs_dr1, rs_dr2, rs_dr3, rs_dr4, rs_dr5, rs_dr6, rs_dr7, |
| 76 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 77 | static constexpr RegStorage dp_temps_arr_64[] = { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 78 | rs_dr0, rs_dr1, rs_dr2, rs_dr3, rs_dr4, rs_dr5, rs_dr6, rs_dr7, |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 79 | rs_dr8, rs_dr9, rs_dr10, rs_dr11, rs_dr12, rs_dr13, rs_dr14, rs_dr15 |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 80 | }; |
| 81 | |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 82 | static constexpr RegStorage xp_temps_arr_32[] = { |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 83 | rs_xr0, rs_xr1, rs_xr2, rs_xr3, rs_xr4, rs_xr5, rs_xr6, rs_xr7, |
| 84 | }; |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 85 | static constexpr RegStorage xp_temps_arr_64[] = { |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 86 | rs_xr0, rs_xr1, rs_xr2, rs_xr3, rs_xr4, rs_xr5, rs_xr6, rs_xr7, |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 87 | rs_xr8, rs_xr9, rs_xr10, rs_xr11, rs_xr12, rs_xr13, rs_xr14, rs_xr15 |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 88 | }; |
| 89 | |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 90 | static constexpr ArrayRef<const RegStorage> empty_pool; |
| 91 | static constexpr ArrayRef<const RegStorage> core_regs_32(core_regs_arr_32); |
| 92 | static constexpr ArrayRef<const RegStorage> core_regs_64(core_regs_arr_64); |
| 93 | static constexpr ArrayRef<const RegStorage> core_regs_64q(core_regs_arr_64q); |
| 94 | static constexpr ArrayRef<const RegStorage> sp_regs_32(sp_regs_arr_32); |
| 95 | static constexpr ArrayRef<const RegStorage> sp_regs_64(sp_regs_arr_64); |
| 96 | static constexpr ArrayRef<const RegStorage> dp_regs_32(dp_regs_arr_32); |
| 97 | static constexpr ArrayRef<const RegStorage> dp_regs_64(dp_regs_arr_64); |
| 98 | static constexpr ArrayRef<const RegStorage> reserved_regs_32(reserved_regs_arr_32); |
| 99 | static constexpr ArrayRef<const RegStorage> reserved_regs_64(reserved_regs_arr_64); |
| 100 | static constexpr ArrayRef<const RegStorage> reserved_regs_64q(reserved_regs_arr_64q); |
| 101 | static constexpr ArrayRef<const RegStorage> core_temps_32(core_temps_arr_32); |
| 102 | static constexpr ArrayRef<const RegStorage> core_temps_64(core_temps_arr_64); |
| 103 | static constexpr ArrayRef<const RegStorage> core_temps_64q(core_temps_arr_64q); |
| 104 | static constexpr ArrayRef<const RegStorage> sp_temps_32(sp_temps_arr_32); |
| 105 | static constexpr ArrayRef<const RegStorage> sp_temps_64(sp_temps_arr_64); |
| 106 | static constexpr ArrayRef<const RegStorage> dp_temps_32(dp_temps_arr_32); |
| 107 | static constexpr ArrayRef<const RegStorage> dp_temps_64(dp_temps_arr_64); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 108 | |
Vladimir Marko | 089142c | 2014-06-05 10:57:05 +0100 | [diff] [blame] | 109 | static constexpr ArrayRef<const RegStorage> xp_temps_32(xp_temps_arr_32); |
| 110 | static constexpr ArrayRef<const RegStorage> xp_temps_64(xp_temps_arr_64); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 111 | |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 112 | RegStorage rs_rX86_SP; |
| 113 | |
| 114 | X86NativeRegisterPool rX86_ARG0; |
| 115 | X86NativeRegisterPool rX86_ARG1; |
| 116 | X86NativeRegisterPool rX86_ARG2; |
| 117 | X86NativeRegisterPool rX86_ARG3; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 118 | X86NativeRegisterPool rX86_ARG4; |
| 119 | X86NativeRegisterPool rX86_ARG5; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 120 | X86NativeRegisterPool rX86_FARG0; |
| 121 | X86NativeRegisterPool rX86_FARG1; |
| 122 | X86NativeRegisterPool rX86_FARG2; |
| 123 | X86NativeRegisterPool rX86_FARG3; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 124 | X86NativeRegisterPool rX86_FARG4; |
| 125 | X86NativeRegisterPool rX86_FARG5; |
| 126 | X86NativeRegisterPool rX86_FARG6; |
| 127 | X86NativeRegisterPool rX86_FARG7; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 128 | X86NativeRegisterPool rX86_RET0; |
| 129 | X86NativeRegisterPool rX86_RET1; |
| 130 | X86NativeRegisterPool rX86_INVOKE_TGT; |
| 131 | X86NativeRegisterPool rX86_COUNT; |
| 132 | |
| 133 | RegStorage rs_rX86_ARG0; |
| 134 | RegStorage rs_rX86_ARG1; |
| 135 | RegStorage rs_rX86_ARG2; |
| 136 | RegStorage rs_rX86_ARG3; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 137 | RegStorage rs_rX86_ARG4; |
| 138 | RegStorage rs_rX86_ARG5; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 139 | RegStorage rs_rX86_FARG0; |
| 140 | RegStorage rs_rX86_FARG1; |
| 141 | RegStorage rs_rX86_FARG2; |
| 142 | RegStorage rs_rX86_FARG3; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 143 | RegStorage rs_rX86_FARG4; |
| 144 | RegStorage rs_rX86_FARG5; |
| 145 | RegStorage rs_rX86_FARG6; |
| 146 | RegStorage rs_rX86_FARG7; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 147 | RegStorage rs_rX86_RET0; |
| 148 | RegStorage rs_rX86_RET1; |
| 149 | RegStorage rs_rX86_INVOKE_TGT; |
| 150 | RegStorage rs_rX86_COUNT; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 151 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 152 | RegLocation X86Mir2Lir::LocCReturn() { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 153 | return x86_loc_c_return; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 154 | } |
| 155 | |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 156 | RegLocation X86Mir2Lir::LocCReturnRef() { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 157 | return cu_->target64 ? x86_64_loc_c_return_ref : x86_loc_c_return_ref; |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 160 | RegLocation X86Mir2Lir::LocCReturnWide() { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 161 | return cu_->target64 ? x86_64_loc_c_return_wide : x86_loc_c_return_wide; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 164 | RegLocation X86Mir2Lir::LocCReturnFloat() { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 165 | return x86_loc_c_return_float; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 168 | RegLocation X86Mir2Lir::LocCReturnDouble() { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 169 | return x86_loc_c_return_double; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 172 | // Return a target-dependent special register for 32-bit. |
| 173 | RegStorage X86Mir2Lir::TargetReg32(SpecialTargetRegister reg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 174 | RegStorage res_reg = RegStorage::InvalidReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 175 | switch (reg) { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 176 | case kSelf: res_reg = RegStorage::InvalidReg(); break; |
| 177 | case kSuspend: res_reg = RegStorage::InvalidReg(); break; |
| 178 | case kLr: res_reg = RegStorage::InvalidReg(); break; |
| 179 | case kPc: res_reg = RegStorage::InvalidReg(); break; |
| 180 | case kSp: res_reg = rs_rX86_SP; break; |
| 181 | case kArg0: res_reg = rs_rX86_ARG0; break; |
| 182 | case kArg1: res_reg = rs_rX86_ARG1; break; |
| 183 | case kArg2: res_reg = rs_rX86_ARG2; break; |
| 184 | case kArg3: res_reg = rs_rX86_ARG3; break; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 185 | case kArg4: res_reg = rs_rX86_ARG4; break; |
| 186 | case kArg5: res_reg = rs_rX86_ARG5; break; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 187 | case kFArg0: res_reg = rs_rX86_FARG0; break; |
| 188 | case kFArg1: res_reg = rs_rX86_FARG1; break; |
| 189 | case kFArg2: res_reg = rs_rX86_FARG2; break; |
| 190 | case kFArg3: res_reg = rs_rX86_FARG3; break; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 191 | case kFArg4: res_reg = rs_rX86_FARG4; break; |
| 192 | case kFArg5: res_reg = rs_rX86_FARG5; break; |
| 193 | case kFArg6: res_reg = rs_rX86_FARG6; break; |
| 194 | case kFArg7: res_reg = rs_rX86_FARG7; break; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 195 | case kRet0: res_reg = rs_rX86_RET0; break; |
| 196 | case kRet1: res_reg = rs_rX86_RET1; break; |
| 197 | case kInvokeTgt: res_reg = rs_rX86_INVOKE_TGT; break; |
| 198 | case kHiddenArg: res_reg = rs_rAX; break; |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 199 | case kHiddenFpArg: DCHECK(!cu_->target64); res_reg = rs_fr0; break; |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 200 | case kCount: res_reg = rs_rX86_COUNT; break; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 201 | default: res_reg = RegStorage::InvalidReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 202 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 203 | return res_reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 204 | } |
| 205 | |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 206 | RegStorage X86Mir2Lir::TargetReg(SpecialTargetRegister reg) { |
| 207 | LOG(FATAL) << "Do not use this function!!!"; |
| 208 | return RegStorage::InvalidReg(); |
| 209 | } |
| 210 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 211 | /* |
| 212 | * Decode the register id. |
| 213 | */ |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 214 | ResourceMask X86Mir2Lir::GetRegMaskCommon(const RegStorage& reg) const { |
| 215 | /* Double registers in x86 are just a single FP register. This is always just a single bit. */ |
| 216 | return ResourceMask::Bit( |
| 217 | /* FP register starts at bit position 16 */ |
| 218 | ((reg.IsFloat() || reg.StorageSize() > 8) ? kX86FPReg0 : 0) + reg.GetRegNum()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 221 | ResourceMask X86Mir2Lir::GetPCUseDefEncoding() const { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 222 | /* |
| 223 | * FIXME: might make sense to use a virtual resource encoding bit for pc. Might be |
| 224 | * able to clean up some of the x86/Arm_Mips differences |
| 225 | */ |
| 226 | LOG(FATAL) << "Unexpected call to GetPCUseDefEncoding for x86"; |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 227 | return kEncodeNone; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 230 | void X86Mir2Lir::SetupTargetResourceMasks(LIR* lir, uint64_t flags, |
| 231 | ResourceMask* use_mask, ResourceMask* def_mask) { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 232 | DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 233 | DCHECK(!lir->flags.use_def_invalid); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 234 | |
| 235 | // X86-specific resource map setup here. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 236 | if (flags & REG_USE_SP) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 237 | use_mask->SetBit(kX86RegSP); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | if (flags & REG_DEF_SP) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 241 | def_mask->SetBit(kX86RegSP); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | if (flags & REG_DEFA) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 245 | SetupRegMask(def_mask, rs_rAX.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | if (flags & REG_DEFD) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 249 | SetupRegMask(def_mask, rs_rDX.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 250 | } |
| 251 | if (flags & REG_USEA) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 252 | SetupRegMask(use_mask, rs_rAX.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | if (flags & REG_USEC) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 256 | SetupRegMask(use_mask, rs_rCX.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | if (flags & REG_USED) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 260 | SetupRegMask(use_mask, rs_rDX.GetReg()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 261 | } |
Vladimir Marko | 70b797d | 2013-12-03 15:25:24 +0000 | [diff] [blame] | 262 | |
| 263 | if (flags & REG_USEB) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 264 | SetupRegMask(use_mask, rs_rBX.GetReg()); |
Vladimir Marko | 70b797d | 2013-12-03 15:25:24 +0000 | [diff] [blame] | 265 | } |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 266 | |
| 267 | // Fixup hard to describe instruction: Uses rAX, rCX, rDI; sets rDI. |
| 268 | if (lir->opcode == kX86RepneScasw) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 269 | SetupRegMask(use_mask, rs_rAX.GetReg()); |
| 270 | SetupRegMask(use_mask, rs_rCX.GetReg()); |
| 271 | SetupRegMask(use_mask, rs_rDI.GetReg()); |
| 272 | SetupRegMask(def_mask, rs_rDI.GetReg()); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 273 | } |
Serguei Katkov | e90501d | 2014-03-12 15:56:54 +0700 | [diff] [blame] | 274 | |
| 275 | if (flags & USE_FP_STACK) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 276 | use_mask->SetBit(kX86FPStack); |
| 277 | def_mask->SetBit(kX86FPStack); |
Serguei Katkov | e90501d | 2014-03-12 15:56:54 +0700 | [diff] [blame] | 278 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | /* For dumping instructions */ |
| 282 | static const char* x86RegName[] = { |
| 283 | "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi", |
| 284 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" |
| 285 | }; |
| 286 | |
| 287 | static const char* x86CondName[] = { |
| 288 | "O", |
| 289 | "NO", |
| 290 | "B/NAE/C", |
| 291 | "NB/AE/NC", |
| 292 | "Z/EQ", |
| 293 | "NZ/NE", |
| 294 | "BE/NA", |
| 295 | "NBE/A", |
| 296 | "S", |
| 297 | "NS", |
| 298 | "P/PE", |
| 299 | "NP/PO", |
| 300 | "L/NGE", |
| 301 | "NL/GE", |
| 302 | "LE/NG", |
| 303 | "NLE/G" |
| 304 | }; |
| 305 | |
| 306 | /* |
| 307 | * Interpret a format string and build a string no longer than size |
| 308 | * See format key in Assemble.cc. |
| 309 | */ |
| 310 | std::string X86Mir2Lir::BuildInsnString(const char *fmt, LIR *lir, unsigned char* base_addr) { |
| 311 | std::string buf; |
| 312 | size_t i = 0; |
| 313 | size_t fmt_len = strlen(fmt); |
| 314 | while (i < fmt_len) { |
| 315 | if (fmt[i] != '!') { |
| 316 | buf += fmt[i]; |
| 317 | i++; |
| 318 | } else { |
| 319 | i++; |
| 320 | DCHECK_LT(i, fmt_len); |
| 321 | char operand_number_ch = fmt[i]; |
| 322 | i++; |
| 323 | if (operand_number_ch == '!') { |
| 324 | buf += "!"; |
| 325 | } else { |
| 326 | int operand_number = operand_number_ch - '0'; |
| 327 | DCHECK_LT(operand_number, 6); // Expect upto 6 LIR operands. |
| 328 | DCHECK_LT(i, fmt_len); |
| 329 | int operand = lir->operands[operand_number]; |
| 330 | switch (fmt[i]) { |
| 331 | case 'c': |
| 332 | DCHECK_LT(static_cast<size_t>(operand), sizeof(x86CondName)); |
| 333 | buf += x86CondName[operand]; |
| 334 | break; |
| 335 | case 'd': |
| 336 | buf += StringPrintf("%d", operand); |
| 337 | break; |
Yixin Shou | 5192cbb | 2014-07-01 13:48:17 -0400 | [diff] [blame] | 338 | case 'q': { |
| 339 | int64_t value = static_cast<int64_t>(static_cast<int64_t>(operand) << 32 | |
| 340 | static_cast<uint32_t>(lir->operands[operand_number+1])); |
| 341 | buf +=StringPrintf("%" PRId64, value); |
| 342 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 343 | case 'p': { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 344 | EmbeddedData *tab_rec = reinterpret_cast<EmbeddedData*>(UnwrapPointer(operand)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 345 | buf += StringPrintf("0x%08x", tab_rec->offset); |
| 346 | break; |
| 347 | } |
| 348 | case 'r': |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 349 | if (RegStorage::IsFloat(operand)) { |
| 350 | int fp_reg = RegStorage::RegNum(operand); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 351 | buf += StringPrintf("xmm%d", fp_reg); |
| 352 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 353 | int reg_num = RegStorage::RegNum(operand); |
| 354 | DCHECK_LT(static_cast<size_t>(reg_num), sizeof(x86RegName)); |
| 355 | buf += x86RegName[reg_num]; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 356 | } |
| 357 | break; |
| 358 | case 't': |
Ian Rogers | 107c31e | 2014-01-23 20:55:29 -0800 | [diff] [blame] | 359 | buf += StringPrintf("0x%08" PRIxPTR " (L%p)", |
| 360 | reinterpret_cast<uintptr_t>(base_addr) + lir->offset + operand, |
| 361 | lir->target); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 362 | break; |
| 363 | default: |
| 364 | buf += StringPrintf("DecodeError '%c'", fmt[i]); |
| 365 | break; |
| 366 | } |
| 367 | i++; |
| 368 | } |
| 369 | } |
| 370 | } |
| 371 | return buf; |
| 372 | } |
| 373 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 374 | void X86Mir2Lir::DumpResourceMask(LIR *x86LIR, const ResourceMask& mask, const char *prefix) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 375 | char buf[256]; |
| 376 | buf[0] = 0; |
| 377 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 378 | if (mask.Equals(kEncodeAll)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 379 | strcpy(buf, "all"); |
| 380 | } else { |
| 381 | char num[8]; |
| 382 | int i; |
| 383 | |
| 384 | for (i = 0; i < kX86RegEnd; i++) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 385 | if (mask.HasBit(i)) { |
Ian Rogers | 988e6ea | 2014-01-08 11:30:50 -0800 | [diff] [blame] | 386 | snprintf(num, arraysize(num), "%d ", i); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 387 | strcat(buf, num); |
| 388 | } |
| 389 | } |
| 390 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 391 | if (mask.HasBit(ResourceMask::kCCode)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 392 | strcat(buf, "cc "); |
| 393 | } |
| 394 | /* Memory bits */ |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 395 | if (x86LIR && (mask.HasBit(ResourceMask::kDalvikReg))) { |
Ian Rogers | 988e6ea | 2014-01-08 11:30:50 -0800 | [diff] [blame] | 396 | snprintf(buf + strlen(buf), arraysize(buf) - strlen(buf), "dr%d%s", |
| 397 | DECODE_ALIAS_INFO_REG(x86LIR->flags.alias_info), |
| 398 | (DECODE_ALIAS_INFO_WIDE(x86LIR->flags.alias_info)) ? "(+1)" : ""); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 399 | } |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 400 | if (mask.HasBit(ResourceMask::kLiteral)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 401 | strcat(buf, "lit "); |
| 402 | } |
| 403 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 404 | if (mask.HasBit(ResourceMask::kHeapRef)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 405 | strcat(buf, "heap "); |
| 406 | } |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 407 | if (mask.HasBit(ResourceMask::kMustNotAlias)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 408 | strcat(buf, "noalias "); |
| 409 | } |
| 410 | } |
| 411 | if (buf[0]) { |
| 412 | LOG(INFO) << prefix << ": " << buf; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | void X86Mir2Lir::AdjustSpillMask() { |
| 417 | // Adjustment for LR spilling, x86 has no LR so nothing to do here |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 418 | core_spill_mask_ |= (1 << rs_rRET.GetRegNum()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 419 | num_core_spills_++; |
| 420 | } |
| 421 | |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 422 | RegStorage X86Mir2Lir::AllocateByteRegister() { |
Chao-ying Fu | 7e399fd | 2014-06-10 18:11:11 -0700 | [diff] [blame] | 423 | RegStorage reg = AllocTypedTemp(false, kCoreReg); |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 424 | if (!cu_->target64) { |
Chao-ying Fu | 7e399fd | 2014-06-10 18:11:11 -0700 | [diff] [blame] | 425 | DCHECK_LT(reg.GetRegNum(), rs_rX86_SP.GetRegNum()); |
| 426 | } |
| 427 | return reg; |
| 428 | } |
| 429 | |
| 430 | bool X86Mir2Lir::IsByteRegister(RegStorage reg) { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 431 | return cu_->target64 || reg.GetRegNum() < rs_rX86_SP.GetRegNum(); |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 432 | } |
| 433 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 434 | /* Clobber all regs that might be used by an external C call */ |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 435 | void X86Mir2Lir::ClobberCallerSave() { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 436 | Clobber(rs_rAX); |
| 437 | Clobber(rs_rCX); |
| 438 | Clobber(rs_rDX); |
| 439 | Clobber(rs_rBX); |
Chao-ying Fu | 35ec2b5 | 2014-06-16 16:40:31 -0700 | [diff] [blame] | 440 | |
| 441 | Clobber(rs_fr0); |
| 442 | Clobber(rs_fr1); |
| 443 | Clobber(rs_fr2); |
| 444 | Clobber(rs_fr3); |
| 445 | Clobber(rs_fr4); |
| 446 | Clobber(rs_fr5); |
| 447 | Clobber(rs_fr6); |
| 448 | Clobber(rs_fr7); |
| 449 | |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 450 | if (cu_->target64) { |
Chao-ying Fu | 35ec2b5 | 2014-06-16 16:40:31 -0700 | [diff] [blame] | 451 | Clobber(rs_r8); |
| 452 | Clobber(rs_r9); |
| 453 | Clobber(rs_r10); |
| 454 | Clobber(rs_r11); |
| 455 | |
| 456 | Clobber(rs_fr8); |
| 457 | Clobber(rs_fr9); |
| 458 | Clobber(rs_fr10); |
| 459 | Clobber(rs_fr11); |
| 460 | Clobber(rs_fr12); |
| 461 | Clobber(rs_fr13); |
| 462 | Clobber(rs_fr14); |
| 463 | Clobber(rs_fr15); |
| 464 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | RegLocation X86Mir2Lir::GetReturnWideAlt() { |
| 468 | RegLocation res = LocCReturnWide(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 469 | DCHECK(res.reg.GetLowReg() == rs_rAX.GetReg()); |
| 470 | DCHECK(res.reg.GetHighReg() == rs_rDX.GetReg()); |
| 471 | Clobber(rs_rAX); |
| 472 | Clobber(rs_rDX); |
| 473 | MarkInUse(rs_rAX); |
| 474 | MarkInUse(rs_rDX); |
| 475 | MarkWide(res.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 476 | return res; |
| 477 | } |
| 478 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 479 | RegLocation X86Mir2Lir::GetReturnAlt() { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 480 | RegLocation res = LocCReturn(); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 481 | res.reg.SetReg(rs_rDX.GetReg()); |
| 482 | Clobber(rs_rDX); |
| 483 | MarkInUse(rs_rDX); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 484 | return res; |
| 485 | } |
| 486 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 487 | /* To be used when explicitly managing register use */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 488 | void X86Mir2Lir::LockCallTemps() { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 489 | LockTemp(rs_rX86_ARG0); |
| 490 | LockTemp(rs_rX86_ARG1); |
| 491 | LockTemp(rs_rX86_ARG2); |
| 492 | LockTemp(rs_rX86_ARG3); |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 493 | if (cu_->target64) { |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 494 | LockTemp(rs_rX86_ARG4); |
| 495 | LockTemp(rs_rX86_ARG5); |
| 496 | LockTemp(rs_rX86_FARG0); |
| 497 | LockTemp(rs_rX86_FARG1); |
| 498 | LockTemp(rs_rX86_FARG2); |
| 499 | LockTemp(rs_rX86_FARG3); |
| 500 | LockTemp(rs_rX86_FARG4); |
| 501 | LockTemp(rs_rX86_FARG5); |
| 502 | LockTemp(rs_rX86_FARG6); |
| 503 | LockTemp(rs_rX86_FARG7); |
| 504 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /* To be used when explicitly managing register use */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 508 | void X86Mir2Lir::FreeCallTemps() { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 509 | FreeTemp(rs_rX86_ARG0); |
| 510 | FreeTemp(rs_rX86_ARG1); |
| 511 | FreeTemp(rs_rX86_ARG2); |
| 512 | FreeTemp(rs_rX86_ARG3); |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 513 | if (cu_->target64) { |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 514 | FreeTemp(rs_rX86_ARG4); |
| 515 | FreeTemp(rs_rX86_ARG5); |
| 516 | FreeTemp(rs_rX86_FARG0); |
| 517 | FreeTemp(rs_rX86_FARG1); |
| 518 | FreeTemp(rs_rX86_FARG2); |
| 519 | FreeTemp(rs_rX86_FARG3); |
| 520 | FreeTemp(rs_rX86_FARG4); |
| 521 | FreeTemp(rs_rX86_FARG5); |
| 522 | FreeTemp(rs_rX86_FARG6); |
| 523 | FreeTemp(rs_rX86_FARG7); |
| 524 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 527 | bool X86Mir2Lir::ProvidesFullMemoryBarrier(X86OpCode opcode) { |
| 528 | switch (opcode) { |
| 529 | case kX86LockCmpxchgMR: |
| 530 | case kX86LockCmpxchgAR: |
Ian Rogers | 0f9b9c5 | 2014-06-09 01:32:12 -0700 | [diff] [blame] | 531 | case kX86LockCmpxchg64M: |
| 532 | case kX86LockCmpxchg64A: |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 533 | case kX86XchgMR: |
| 534 | case kX86Mfence: |
| 535 | // Atomic memory instructions provide full barrier. |
| 536 | return true; |
| 537 | default: |
| 538 | break; |
| 539 | } |
| 540 | |
| 541 | // Conservative if cannot prove it provides full barrier. |
| 542 | return false; |
| 543 | } |
| 544 | |
Andreas Gampe | b14329f | 2014-05-15 11:16:06 -0700 | [diff] [blame] | 545 | bool X86Mir2Lir::GenMemBarrier(MemBarrierKind barrier_kind) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 546 | #if ANDROID_SMP != 0 |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 547 | // Start off with using the last LIR as the barrier. If it is not enough, then we will update it. |
| 548 | LIR* mem_barrier = last_lir_insn_; |
| 549 | |
Andreas Gampe | b14329f | 2014-05-15 11:16:06 -0700 | [diff] [blame] | 550 | bool ret = false; |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 551 | /* |
| 552 | * According to the JSR-133 Cookbook, for x86 only StoreLoad barriers need memory fence. All other barriers |
| 553 | * (LoadLoad, LoadStore, StoreStore) are nops due to the x86 memory model. For those cases, all we need |
| 554 | * to ensure is that there is a scheduling barrier in place. |
| 555 | */ |
| 556 | if (barrier_kind == kStoreLoad) { |
| 557 | // If no LIR exists already that can be used a barrier, then generate an mfence. |
| 558 | if (mem_barrier == nullptr) { |
| 559 | mem_barrier = NewLIR0(kX86Mfence); |
Andreas Gampe | b14329f | 2014-05-15 11:16:06 -0700 | [diff] [blame] | 560 | ret = true; |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | // If last instruction does not provide full barrier, then insert an mfence. |
| 564 | if (ProvidesFullMemoryBarrier(static_cast<X86OpCode>(mem_barrier->opcode)) == false) { |
| 565 | mem_barrier = NewLIR0(kX86Mfence); |
Andreas Gampe | b14329f | 2014-05-15 11:16:06 -0700 | [diff] [blame] | 566 | ret = true; |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | |
| 570 | // Now ensure that a scheduling barrier is in place. |
| 571 | if (mem_barrier == nullptr) { |
| 572 | GenBarrier(); |
| 573 | } else { |
| 574 | // Mark as a scheduling barrier. |
| 575 | DCHECK(!mem_barrier->flags.use_def_invalid); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 576 | mem_barrier->u.m.def_mask = &kEncodeAll; |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 577 | } |
Andreas Gampe | b14329f | 2014-05-15 11:16:06 -0700 | [diff] [blame] | 578 | return ret; |
| 579 | #else |
| 580 | return false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 581 | #endif |
| 582 | } |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 583 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 584 | void X86Mir2Lir::CompilerInitializeRegAlloc() { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 585 | if (cu_->target64) { |
Dmitry Petrochenko | 76af0d3 | 2014-06-05 21:15:08 +0700 | [diff] [blame] | 586 | reg_pool_ = new (arena_) RegisterPool(this, arena_, core_regs_64, core_regs_64q, sp_regs_64, |
| 587 | dp_regs_64, reserved_regs_64, reserved_regs_64q, |
| 588 | core_temps_64, core_temps_64q, sp_temps_64, dp_temps_64); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 589 | } else { |
buzbee | b01bf15 | 2014-05-13 15:59:07 -0700 | [diff] [blame] | 590 | reg_pool_ = new (arena_) RegisterPool(this, arena_, core_regs_32, empty_pool, sp_regs_32, |
| 591 | dp_regs_32, reserved_regs_32, empty_pool, |
| 592 | core_temps_32, empty_pool, sp_temps_32, dp_temps_32); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 593 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 594 | |
| 595 | // Target-specific adjustments. |
| 596 | |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 597 | // Add in XMM registers. |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 598 | const ArrayRef<const RegStorage> *xp_temps = cu_->target64 ? &xp_temps_64 : &xp_temps_32; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 599 | for (RegStorage reg : *xp_temps) { |
| 600 | RegisterInfo* info = new (arena_) RegisterInfo(reg, GetRegMaskCommon(reg)); |
| 601 | reginfo_map_.Put(reg.GetReg(), info); |
| 602 | info->SetIsTemp(true); |
| 603 | } |
| 604 | |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 605 | // Alias single precision xmm to double xmms. |
| 606 | // TODO: as needed, add larger vector sizes - alias all to the largest. |
| 607 | GrowableArray<RegisterInfo*>::Iterator it(®_pool_->sp_regs_); |
| 608 | for (RegisterInfo* info = it.Next(); info != nullptr; info = it.Next()) { |
| 609 | int sp_reg_num = info->GetReg().GetRegNum(); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 610 | RegStorage xp_reg = RegStorage::Solo128(sp_reg_num); |
| 611 | RegisterInfo* xp_reg_info = GetRegInfo(xp_reg); |
| 612 | // 128-bit xmm vector register's master storage should refer to itself. |
| 613 | DCHECK_EQ(xp_reg_info, xp_reg_info->Master()); |
| 614 | |
| 615 | // Redirect 32-bit vector's master storage to 128-bit vector. |
| 616 | info->SetMaster(xp_reg_info); |
| 617 | |
Dmitry Petrochenko | 76af0d3 | 2014-06-05 21:15:08 +0700 | [diff] [blame] | 618 | RegStorage dp_reg = RegStorage::FloatSolo64(sp_reg_num); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 619 | RegisterInfo* dp_reg_info = GetRegInfo(dp_reg); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 620 | // Redirect 64-bit vector's master storage to 128-bit vector. |
| 621 | dp_reg_info->SetMaster(xp_reg_info); |
Dmitry Petrochenko | 76af0d3 | 2014-06-05 21:15:08 +0700 | [diff] [blame] | 622 | // Singles should show a single 32-bit mask bit, at first referring to the low half. |
| 623 | DCHECK_EQ(info->StorageMask(), 0x1U); |
| 624 | } |
| 625 | |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 626 | if (cu_->target64) { |
Dmitry Petrochenko | 76af0d3 | 2014-06-05 21:15:08 +0700 | [diff] [blame] | 627 | // Alias 32bit W registers to corresponding 64bit X registers. |
| 628 | GrowableArray<RegisterInfo*>::Iterator w_it(®_pool_->core_regs_); |
| 629 | for (RegisterInfo* info = w_it.Next(); info != nullptr; info = w_it.Next()) { |
| 630 | int x_reg_num = info->GetReg().GetRegNum(); |
| 631 | RegStorage x_reg = RegStorage::Solo64(x_reg_num); |
| 632 | RegisterInfo* x_reg_info = GetRegInfo(x_reg); |
| 633 | // 64bit X register's master storage should refer to itself. |
| 634 | DCHECK_EQ(x_reg_info, x_reg_info->Master()); |
| 635 | // Redirect 32bit W master storage to 64bit X. |
| 636 | info->SetMaster(x_reg_info); |
| 637 | // 32bit W should show a single 32-bit mask bit, at first referring to the low half. |
| 638 | DCHECK_EQ(info->StorageMask(), 0x1U); |
| 639 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 640 | } |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 641 | |
| 642 | // Don't start allocating temps at r0/s0/d0 or you may clobber return regs in early-exit methods. |
| 643 | // TODO: adjust for x86/hard float calling convention. |
| 644 | reg_pool_->next_core_reg_ = 2; |
| 645 | reg_pool_->next_sp_reg_ = 2; |
| 646 | reg_pool_->next_dp_reg_ = 1; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 647 | } |
| 648 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 649 | void X86Mir2Lir::SpillCoreRegs() { |
| 650 | if (num_core_spills_ == 0) { |
| 651 | return; |
| 652 | } |
| 653 | // Spill mask not including fake return address register |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 654 | uint32_t mask = core_spill_mask_ & ~(1 << rs_rRET.GetRegNum()); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 655 | int offset = frame_size_ - (GetInstructionSetPointerSize(cu_->instruction_set) * num_core_spills_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 656 | for (int reg = 0; mask; mask >>= 1, reg++) { |
| 657 | if (mask & 0x1) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 658 | StoreWordDisp(rs_rX86_SP, offset, RegStorage::Solo32(reg)); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 659 | offset += GetInstructionSetPointerSize(cu_->instruction_set); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | void X86Mir2Lir::UnSpillCoreRegs() { |
| 665 | if (num_core_spills_ == 0) { |
| 666 | return; |
| 667 | } |
| 668 | // Spill mask not including fake return address register |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 669 | uint32_t mask = core_spill_mask_ & ~(1 << rs_rRET.GetRegNum()); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 670 | int offset = frame_size_ - (GetInstructionSetPointerSize(cu_->instruction_set) * num_core_spills_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 671 | for (int reg = 0; mask; mask >>= 1, reg++) { |
| 672 | if (mask & 0x1) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 673 | LoadWordDisp(rs_rX86_SP, offset, RegStorage::Solo32(reg)); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 674 | offset += GetInstructionSetPointerSize(cu_->instruction_set); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 679 | bool X86Mir2Lir::IsUnconditionalBranch(LIR* lir) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 680 | return (lir->opcode == kX86Jmp8 || lir->opcode == kX86Jmp32); |
| 681 | } |
| 682 | |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 683 | bool X86Mir2Lir::SupportsVolatileLoadStore(OpSize size) { |
| 684 | return true; |
| 685 | } |
| 686 | |
| 687 | RegisterClass X86Mir2Lir::RegClassForFieldLoadStore(OpSize size, bool is_volatile) { |
Chao-ying Fu | e0ccdc0 | 2014-06-06 17:32:37 -0700 | [diff] [blame] | 688 | // X86_64 can handle any size. |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 689 | if (cu_->target64) { |
Chao-ying Fu | e0ccdc0 | 2014-06-06 17:32:37 -0700 | [diff] [blame] | 690 | if (size == kReference) { |
| 691 | return kRefReg; |
| 692 | } |
| 693 | return kCoreReg; |
| 694 | } |
| 695 | |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 696 | if (UNLIKELY(is_volatile)) { |
| 697 | // On x86, atomic 64-bit load/store requires an fp register. |
| 698 | // Smaller aligned load/store is atomic for both core and fp registers. |
| 699 | if (size == k64 || size == kDouble) { |
| 700 | return kFPReg; |
| 701 | } |
| 702 | } |
| 703 | return RegClassBySize(size); |
| 704 | } |
| 705 | |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 706 | X86Mir2Lir::X86Mir2Lir(CompilationUnit* cu, MIRGraph* mir_graph, ArenaAllocator* arena) |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 707 | : Mir2Lir(cu, mir_graph, arena), |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 708 | base_of_code_(nullptr), store_method_addr_(false), store_method_addr_used_(false), |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 709 | method_address_insns_(arena, 100, kGrowableArrayMisc), |
| 710 | class_type_address_insns_(arena, 100, kGrowableArrayMisc), |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 711 | call_method_insns_(arena, 100, kGrowableArrayMisc), |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 712 | stack_decrement_(nullptr), stack_increment_(nullptr), |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 713 | const_vectors_(nullptr) { |
| 714 | store_method_addr_used_ = false; |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 715 | if (kIsDebugBuild) { |
| 716 | for (int i = 0; i < kX86Last; i++) { |
| 717 | if (X86Mir2Lir::EncodingMap[i].opcode != i) { |
| 718 | LOG(FATAL) << "Encoding order for " << X86Mir2Lir::EncodingMap[i].name |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 719 | << " is wrong: expecting " << i << ", seeing " |
| 720 | << static_cast<int>(X86Mir2Lir::EncodingMap[i].opcode); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 721 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 722 | } |
| 723 | } |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 724 | if (cu_->target64) { |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 725 | rs_rX86_SP = rs_rX86_SP_64; |
| 726 | |
| 727 | rs_rX86_ARG0 = rs_rDI; |
| 728 | rs_rX86_ARG1 = rs_rSI; |
| 729 | rs_rX86_ARG2 = rs_rDX; |
| 730 | rs_rX86_ARG3 = rs_rCX; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 731 | rs_rX86_ARG4 = rs_r8; |
| 732 | rs_rX86_ARG5 = rs_r9; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 733 | rs_rX86_FARG0 = rs_fr0; |
| 734 | rs_rX86_FARG1 = rs_fr1; |
| 735 | rs_rX86_FARG2 = rs_fr2; |
| 736 | rs_rX86_FARG3 = rs_fr3; |
| 737 | rs_rX86_FARG4 = rs_fr4; |
| 738 | rs_rX86_FARG5 = rs_fr5; |
| 739 | rs_rX86_FARG6 = rs_fr6; |
| 740 | rs_rX86_FARG7 = rs_fr7; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 741 | rX86_ARG0 = rDI; |
| 742 | rX86_ARG1 = rSI; |
| 743 | rX86_ARG2 = rDX; |
| 744 | rX86_ARG3 = rCX; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 745 | rX86_ARG4 = r8; |
| 746 | rX86_ARG5 = r9; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 747 | rX86_FARG0 = fr0; |
| 748 | rX86_FARG1 = fr1; |
| 749 | rX86_FARG2 = fr2; |
| 750 | rX86_FARG3 = fr3; |
| 751 | rX86_FARG4 = fr4; |
| 752 | rX86_FARG5 = fr5; |
| 753 | rX86_FARG6 = fr6; |
| 754 | rX86_FARG7 = fr7; |
Mark Mendell | 55884bc | 2014-06-10 10:21:29 -0400 | [diff] [blame] | 755 | rs_rX86_INVOKE_TGT = rs_rDI; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 756 | } else { |
| 757 | rs_rX86_SP = rs_rX86_SP_32; |
| 758 | |
| 759 | rs_rX86_ARG0 = rs_rAX; |
| 760 | rs_rX86_ARG1 = rs_rCX; |
| 761 | rs_rX86_ARG2 = rs_rDX; |
| 762 | rs_rX86_ARG3 = rs_rBX; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 763 | rs_rX86_ARG4 = RegStorage::InvalidReg(); |
| 764 | rs_rX86_ARG5 = RegStorage::InvalidReg(); |
| 765 | rs_rX86_FARG0 = rs_rAX; |
| 766 | rs_rX86_FARG1 = rs_rCX; |
| 767 | rs_rX86_FARG2 = rs_rDX; |
| 768 | rs_rX86_FARG3 = rs_rBX; |
| 769 | rs_rX86_FARG4 = RegStorage::InvalidReg(); |
| 770 | rs_rX86_FARG5 = RegStorage::InvalidReg(); |
| 771 | rs_rX86_FARG6 = RegStorage::InvalidReg(); |
| 772 | rs_rX86_FARG7 = RegStorage::InvalidReg(); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 773 | rX86_ARG0 = rAX; |
| 774 | rX86_ARG1 = rCX; |
| 775 | rX86_ARG2 = rDX; |
| 776 | rX86_ARG3 = rBX; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 777 | rX86_FARG0 = rAX; |
| 778 | rX86_FARG1 = rCX; |
| 779 | rX86_FARG2 = rDX; |
| 780 | rX86_FARG3 = rBX; |
Mark Mendell | 55884bc | 2014-06-10 10:21:29 -0400 | [diff] [blame] | 781 | rs_rX86_INVOKE_TGT = rs_rAX; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 782 | // TODO(64): Initialize with invalid reg |
| 783 | // rX86_ARG4 = RegStorage::InvalidReg(); |
| 784 | // rX86_ARG5 = RegStorage::InvalidReg(); |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 785 | } |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 786 | rs_rX86_RET0 = rs_rAX; |
| 787 | rs_rX86_RET1 = rs_rDX; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 788 | rs_rX86_COUNT = rs_rCX; |
Dmitry Petrochenko | 9ee801f | 2014-05-12 11:31:37 +0700 | [diff] [blame] | 789 | rX86_RET0 = rAX; |
| 790 | rX86_RET1 = rDX; |
| 791 | rX86_INVOKE_TGT = rAX; |
| 792 | rX86_COUNT = rCX; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | Mir2Lir* X86CodeGenerator(CompilationUnit* const cu, MIRGraph* const mir_graph, |
| 796 | ArenaAllocator* const arena) { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 797 | return new X86Mir2Lir(cu, mir_graph, arena); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | // Not used in x86 |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 801 | RegStorage X86Mir2Lir::LoadHelper(ThreadOffset<4> offset) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 802 | LOG(FATAL) << "Unexpected use of LoadHelper in x86"; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 803 | return RegStorage::InvalidReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 804 | } |
| 805 | |
Andreas Gampe | 2f244e9 | 2014-05-08 03:35:25 -0700 | [diff] [blame] | 806 | // Not used in x86 |
| 807 | RegStorage X86Mir2Lir::LoadHelper(ThreadOffset<8> offset) { |
| 808 | LOG(FATAL) << "Unexpected use of LoadHelper in x86"; |
| 809 | return RegStorage::InvalidReg(); |
| 810 | } |
| 811 | |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 812 | LIR* X86Mir2Lir::CheckSuspendUsingLoad() { |
| 813 | LOG(FATAL) << "Unexpected use of CheckSuspendUsingLoad in x86"; |
| 814 | return nullptr; |
| 815 | } |
| 816 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 817 | uint64_t X86Mir2Lir::GetTargetInstFlags(int opcode) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 818 | DCHECK(!IsPseudoLirOp(opcode)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 819 | return X86Mir2Lir::EncodingMap[opcode].flags; |
| 820 | } |
| 821 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 822 | const char* X86Mir2Lir::GetTargetInstName(int opcode) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 823 | DCHECK(!IsPseudoLirOp(opcode)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 824 | return X86Mir2Lir::EncodingMap[opcode].name; |
| 825 | } |
| 826 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 827 | const char* X86Mir2Lir::GetTargetInstFmt(int opcode) { |
buzbee | 409fe94 | 2013-10-11 10:49:56 -0700 | [diff] [blame] | 828 | DCHECK(!IsPseudoLirOp(opcode)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 829 | return X86Mir2Lir::EncodingMap[opcode].fmt; |
| 830 | } |
| 831 | |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 832 | void X86Mir2Lir::GenConstWide(RegLocation rl_dest, int64_t value) { |
| 833 | // Can we do this directly to memory? |
| 834 | rl_dest = UpdateLocWide(rl_dest); |
| 835 | if ((rl_dest.location == kLocDalvikFrame) || |
| 836 | (rl_dest.location == kLocCompilerTemp)) { |
| 837 | int32_t val_lo = Low32Bits(value); |
| 838 | int32_t val_hi = High32Bits(value); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 839 | int r_base = rs_rX86_SP.GetReg(); |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 840 | int displacement = SRegOffset(rl_dest.s_reg_low); |
| 841 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 842 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 843 | LIR * store = NewLIR3(kX86Mov32MI, r_base, displacement + LOWORD_OFFSET, val_lo); |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 844 | AnnotateDalvikRegAccess(store, (displacement + LOWORD_OFFSET) >> 2, |
| 845 | false /* is_load */, true /* is64bit */); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 846 | store = NewLIR3(kX86Mov32MI, r_base, displacement + HIWORD_OFFSET, val_hi); |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 847 | AnnotateDalvikRegAccess(store, (displacement + HIWORD_OFFSET) >> 2, |
| 848 | false /* is_load */, true /* is64bit */); |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | // Just use the standard code to do the generation. |
| 853 | Mir2Lir::GenConstWide(rl_dest, value); |
| 854 | } |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 855 | |
| 856 | // TODO: Merge with existing RegLocation dumper in vreg_analysis.cc |
| 857 | void X86Mir2Lir::DumpRegLocation(RegLocation loc) { |
| 858 | LOG(INFO) << "location: " << loc.location << ',' |
| 859 | << (loc.wide ? " w" : " ") |
| 860 | << (loc.defined ? " D" : " ") |
| 861 | << (loc.is_const ? " c" : " ") |
| 862 | << (loc.fp ? " F" : " ") |
| 863 | << (loc.core ? " C" : " ") |
| 864 | << (loc.ref ? " r" : " ") |
| 865 | << (loc.high_word ? " h" : " ") |
| 866 | << (loc.home ? " H" : " ") |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 867 | << ", low: " << static_cast<int>(loc.reg.GetLowReg()) |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 868 | << ", high: " << static_cast<int>(loc.reg.GetHighReg()) |
Mark Mendell | e02d48f | 2014-01-15 11:19:23 -0800 | [diff] [blame] | 869 | << ", s_reg: " << loc.s_reg_low |
| 870 | << ", orig: " << loc.orig_sreg; |
| 871 | } |
| 872 | |
Mark Mendell | 67c39c4 | 2014-01-31 17:28:00 -0800 | [diff] [blame] | 873 | void X86Mir2Lir::Materialize() { |
| 874 | // A good place to put the analysis before starting. |
| 875 | AnalyzeMIR(); |
| 876 | |
| 877 | // Now continue with regular code generation. |
| 878 | Mir2Lir::Materialize(); |
| 879 | } |
| 880 | |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 881 | void X86Mir2Lir::LoadMethodAddress(const MethodReference& target_method, InvokeType type, |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 882 | SpecialTargetRegister symbolic_reg) { |
| 883 | /* |
| 884 | * For x86, just generate a 32 bit move immediate instruction, that will be filled |
| 885 | * in at 'link time'. For now, put a unique value based on target to ensure that |
| 886 | * code deduplication works. |
| 887 | */ |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 888 | int target_method_idx = target_method.dex_method_index; |
| 889 | const DexFile* target_dex_file = target_method.dex_file; |
| 890 | const DexFile::MethodId& target_method_id = target_dex_file->GetMethodId(target_method_idx); |
| 891 | uintptr_t target_method_id_ptr = reinterpret_cast<uintptr_t>(&target_method_id); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 892 | |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 893 | // Generate the move instruction with the unique pointer and save index, dex_file, and type. |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 894 | LIR *move = RawLIR(current_dalvik_offset_, kX86Mov32RI, TargetReg(symbolic_reg, false).GetReg(), |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 895 | static_cast<int>(target_method_id_ptr), target_method_idx, |
| 896 | WrapPointer(const_cast<DexFile*>(target_dex_file)), type); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 897 | AppendLIR(move); |
| 898 | method_address_insns_.Insert(move); |
| 899 | } |
| 900 | |
| 901 | void X86Mir2Lir::LoadClassType(uint32_t type_idx, SpecialTargetRegister symbolic_reg) { |
| 902 | /* |
| 903 | * For x86, just generate a 32 bit move immediate instruction, that will be filled |
| 904 | * in at 'link time'. For now, put a unique value based on target to ensure that |
| 905 | * code deduplication works. |
| 906 | */ |
| 907 | const DexFile::TypeId& id = cu_->dex_file->GetTypeId(type_idx); |
| 908 | uintptr_t ptr = reinterpret_cast<uintptr_t>(&id); |
| 909 | |
| 910 | // Generate the move instruction with the unique pointer and save index and type. |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 911 | LIR *move = RawLIR(current_dalvik_offset_, kX86Mov32RI, TargetReg(symbolic_reg, false).GetReg(), |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 912 | static_cast<int>(ptr), type_idx); |
| 913 | AppendLIR(move); |
| 914 | class_type_address_insns_.Insert(move); |
| 915 | } |
| 916 | |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 917 | LIR *X86Mir2Lir::CallWithLinkerFixup(const MethodReference& target_method, InvokeType type) { |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 918 | /* |
| 919 | * For x86, just generate a 32 bit call relative instruction, that will be filled |
| 920 | * in at 'link time'. For now, put a unique value based on target to ensure that |
| 921 | * code deduplication works. |
| 922 | */ |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 923 | int target_method_idx = target_method.dex_method_index; |
| 924 | const DexFile* target_dex_file = target_method.dex_file; |
| 925 | const DexFile::MethodId& target_method_id = target_dex_file->GetMethodId(target_method_idx); |
| 926 | uintptr_t target_method_id_ptr = reinterpret_cast<uintptr_t>(&target_method_id); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 927 | |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 928 | // Generate the call instruction with the unique pointer and save index, dex_file, and type. |
| 929 | LIR *call = RawLIR(current_dalvik_offset_, kX86CallI, static_cast<int>(target_method_id_ptr), |
| 930 | target_method_idx, WrapPointer(const_cast<DexFile*>(target_dex_file)), type); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 931 | AppendLIR(call); |
| 932 | call_method_insns_.Insert(call); |
| 933 | return call; |
| 934 | } |
| 935 | |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 936 | /* |
| 937 | * @brief Enter a 32 bit quantity into a buffer |
| 938 | * @param buf buffer. |
| 939 | * @param data Data value. |
| 940 | */ |
| 941 | |
| 942 | static void PushWord(std::vector<uint8_t>&buf, int32_t data) { |
| 943 | buf.push_back(data & 0xff); |
| 944 | buf.push_back((data >> 8) & 0xff); |
| 945 | buf.push_back((data >> 16) & 0xff); |
| 946 | buf.push_back((data >> 24) & 0xff); |
| 947 | } |
| 948 | |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 949 | void X86Mir2Lir::InstallLiteralPools() { |
| 950 | // These are handled differently for x86. |
| 951 | DCHECK(code_literal_list_ == nullptr); |
| 952 | DCHECK(method_literal_list_ == nullptr); |
| 953 | DCHECK(class_literal_list_ == nullptr); |
| 954 | |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 955 | // Align to 16 byte boundary. We have implicit knowledge that the start of the method is |
| 956 | // on a 4 byte boundary. How can I check this if it changes (other than aligned loads |
| 957 | // will fail at runtime)? |
| 958 | if (const_vectors_ != nullptr) { |
| 959 | int align_size = (16-4) - (code_buffer_.size() & 0xF); |
| 960 | if (align_size < 0) { |
| 961 | align_size += 16; |
| 962 | } |
| 963 | |
| 964 | while (align_size > 0) { |
| 965 | code_buffer_.push_back(0); |
| 966 | align_size--; |
| 967 | } |
| 968 | for (LIR *p = const_vectors_; p != nullptr; p = p->next) { |
| 969 | PushWord(code_buffer_, p->operands[0]); |
| 970 | PushWord(code_buffer_, p->operands[1]); |
| 971 | PushWord(code_buffer_, p->operands[2]); |
| 972 | PushWord(code_buffer_, p->operands[3]); |
| 973 | } |
| 974 | } |
| 975 | |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 976 | // Handle the fixups for methods. |
| 977 | for (uint32_t i = 0; i < method_address_insns_.Size(); i++) { |
| 978 | LIR* p = method_address_insns_.Get(i); |
| 979 | DCHECK_EQ(p->opcode, kX86Mov32RI); |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 980 | uint32_t target_method_idx = p->operands[2]; |
| 981 | const DexFile* target_dex_file = |
| 982 | reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[3])); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 983 | |
| 984 | // The offset to patch is the last 4 bytes of the instruction. |
| 985 | int patch_offset = p->offset + p->flags.size - 4; |
| 986 | cu_->compiler_driver->AddMethodPatch(cu_->dex_file, cu_->class_def_idx, |
| 987 | cu_->method_idx, cu_->invoke_type, |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 988 | target_method_idx, target_dex_file, |
| 989 | static_cast<InvokeType>(p->operands[4]), |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 990 | patch_offset); |
| 991 | } |
| 992 | |
| 993 | // Handle the fixups for class types. |
| 994 | for (uint32_t i = 0; i < class_type_address_insns_.Size(); i++) { |
| 995 | LIR* p = class_type_address_insns_.Get(i); |
| 996 | DCHECK_EQ(p->opcode, kX86Mov32RI); |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 997 | uint32_t target_method_idx = p->operands[2]; |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 998 | |
| 999 | // The offset to patch is the last 4 bytes of the instruction. |
| 1000 | int patch_offset = p->offset + p->flags.size - 4; |
| 1001 | cu_->compiler_driver->AddClassPatch(cu_->dex_file, cu_->class_def_idx, |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 1002 | cu_->method_idx, target_method_idx, patch_offset); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | // And now the PC-relative calls to methods. |
| 1006 | for (uint32_t i = 0; i < call_method_insns_.Size(); i++) { |
| 1007 | LIR* p = call_method_insns_.Get(i); |
| 1008 | DCHECK_EQ(p->opcode, kX86CallI); |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 1009 | uint32_t target_method_idx = p->operands[1]; |
| 1010 | const DexFile* target_dex_file = |
| 1011 | reinterpret_cast<const DexFile*>(UnwrapPointer(p->operands[2])); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1012 | |
| 1013 | // The offset to patch is the last 4 bytes of the instruction. |
| 1014 | int patch_offset = p->offset + p->flags.size - 4; |
| 1015 | cu_->compiler_driver->AddRelativeCodePatch(cu_->dex_file, cu_->class_def_idx, |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 1016 | cu_->method_idx, cu_->invoke_type, |
| 1017 | target_method_idx, target_dex_file, |
| 1018 | static_cast<InvokeType>(p->operands[3]), |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1019 | patch_offset, -4 /* offset */); |
| 1020 | } |
| 1021 | |
| 1022 | // And do the normal processing. |
| 1023 | Mir2Lir::InstallLiteralPools(); |
| 1024 | } |
| 1025 | |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1026 | /* |
| 1027 | * Fast string.index_of(I) & (II). Inline check for simple case of char <= 0xffff, |
| 1028 | * otherwise bails to standard library code. |
| 1029 | */ |
| 1030 | bool X86Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { |
| 1031 | ClobberCallerSave(); |
| 1032 | LockCallTemps(); // Using fixed registers |
| 1033 | |
| 1034 | // EAX: 16 bit character being searched. |
| 1035 | // ECX: count: number of words to be searched. |
| 1036 | // EDI: String being searched. |
| 1037 | // EDX: temporary during execution. |
| 1038 | // EBX: temporary during execution. |
| 1039 | |
| 1040 | RegLocation rl_obj = info->args[0]; |
| 1041 | RegLocation rl_char = info->args[1]; |
buzbee | a44d4f5 | 2014-03-05 11:26:39 -0800 | [diff] [blame] | 1042 | RegLocation rl_start; // Note: only present in III flavor or IndexOf. |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1043 | |
| 1044 | uint32_t char_value = |
| 1045 | rl_char.is_const ? mir_graph_->ConstantValue(rl_char.orig_sreg) : 0; |
| 1046 | |
| 1047 | if (char_value > 0xFFFF) { |
| 1048 | // We have to punt to the real String.indexOf. |
| 1049 | return false; |
| 1050 | } |
| 1051 | |
| 1052 | // Okay, we are commited to inlining this. |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 1053 | RegLocation rl_return = GetReturn(kCoreReg); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1054 | RegLocation rl_dest = InlineTarget(info); |
| 1055 | |
| 1056 | // Is the string non-NULL? |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1057 | LoadValueDirectFixed(rl_obj, rs_rDX); |
| 1058 | GenNullCheck(rs_rDX, info->opt_flags); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1059 | info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1060 | |
| 1061 | // Does the character fit in 16 bits? |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1062 | LIR* slowpath_branch = nullptr; |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1063 | if (rl_char.is_const) { |
| 1064 | // We need the value in EAX. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1065 | LoadConstantNoClobber(rs_rAX, char_value); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1066 | } else { |
| 1067 | // Character is not a constant; compare at runtime. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1068 | LoadValueDirectFixed(rl_char, rs_rAX); |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1069 | slowpath_branch = OpCmpImmBranch(kCondGt, rs_rAX, 0xFFFF, nullptr); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | // From here down, we know that we are looking for a char that fits in 16 bits. |
Mark Mendell | e19c91f | 2014-02-25 08:19:08 -0800 | [diff] [blame] | 1073 | // Location of reference to data array within the String object. |
| 1074 | int value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1075 | // Location of count within the String object. |
| 1076 | int count_offset = mirror::String::CountOffset().Int32Value(); |
| 1077 | // Starting offset within data array. |
| 1078 | int offset_offset = mirror::String::OffsetOffset().Int32Value(); |
| 1079 | // Start of char data with array_. |
| 1080 | int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value(); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1081 | |
| 1082 | // Character is in EAX. |
| 1083 | // Object pointer is in EDX. |
| 1084 | |
| 1085 | // We need to preserve EDI, but have no spare registers, so push it on the stack. |
| 1086 | // We have to remember that all stack addresses after this are offset by sizeof(EDI). |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1087 | NewLIR1(kX86Push32R, rs_rDI.GetReg()); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1088 | |
| 1089 | // Compute the number of words to search in to rCX. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1090 | Load32Disp(rs_rDX, count_offset, rs_rCX); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1091 | LIR *length_compare = nullptr; |
| 1092 | int start_value = 0; |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1093 | bool is_index_on_stack = false; |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1094 | if (zero_based) { |
| 1095 | // We have to handle an empty string. Use special instruction JECXZ. |
| 1096 | length_compare = NewLIR0(kX86Jecxz8); |
| 1097 | } else { |
buzbee | a44d4f5 | 2014-03-05 11:26:39 -0800 | [diff] [blame] | 1098 | rl_start = info->args[2]; |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1099 | // We have to offset by the start index. |
| 1100 | if (rl_start.is_const) { |
| 1101 | start_value = mir_graph_->ConstantValue(rl_start.orig_sreg); |
| 1102 | start_value = std::max(start_value, 0); |
| 1103 | |
| 1104 | // Is the start > count? |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1105 | length_compare = OpCmpImmBranch(kCondLe, rs_rCX, start_value, nullptr); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1106 | |
| 1107 | if (start_value != 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1108 | OpRegImm(kOpSub, rs_rCX, start_value); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1109 | } |
| 1110 | } else { |
| 1111 | // Runtime start index. |
buzbee | 30adc73 | 2014-05-09 15:10:18 -0700 | [diff] [blame] | 1112 | rl_start = UpdateLocTyped(rl_start, kCoreReg); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1113 | if (rl_start.location == kLocPhysReg) { |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1114 | // Handle "start index < 0" case. |
| 1115 | OpRegReg(kOpXor, rs_rBX, rs_rBX); |
| 1116 | OpRegReg(kOpCmp, rl_start.reg, rs_rBX); |
| 1117 | OpCondRegReg(kOpCmov, kCondLt, rl_start.reg, rs_rBX); |
| 1118 | |
| 1119 | // The length of the string should be greater than the start index. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1120 | length_compare = OpCmpBranch(kCondLe, rs_rCX, rl_start.reg, nullptr); |
| 1121 | OpRegReg(kOpSub, rs_rCX, rl_start.reg); |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1122 | if (rl_start.reg == rs_rDI) { |
| 1123 | // The special case. We will use EDI further, so lets put start index to stack. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1124 | NewLIR1(kX86Push32R, rs_rDI.GetReg()); |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1125 | is_index_on_stack = true; |
| 1126 | } |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1127 | } else { |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1128 | // Load the start index from stack, remembering that we pushed EDI. |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1129 | int displacement = SRegOffset(rl_start.s_reg_low) + sizeof(uint32_t); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 1130 | { |
| 1131 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
| 1132 | Load32Disp(rs_rX86_SP, displacement, rs_rBX); |
| 1133 | } |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1134 | OpRegReg(kOpXor, rs_rDI, rs_rDI); |
| 1135 | OpRegReg(kOpCmp, rs_rBX, rs_rDI); |
| 1136 | OpCondRegReg(kOpCmov, kCondLt, rs_rBX, rs_rDI); |
| 1137 | |
| 1138 | length_compare = OpCmpBranch(kCondLe, rs_rCX, rs_rBX, nullptr); |
| 1139 | OpRegReg(kOpSub, rs_rCX, rs_rBX); |
| 1140 | // Put the start index to stack. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1141 | NewLIR1(kX86Push32R, rs_rBX.GetReg()); |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1142 | is_index_on_stack = true; |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1143 | } |
| 1144 | } |
| 1145 | } |
| 1146 | DCHECK(length_compare != nullptr); |
| 1147 | |
| 1148 | // ECX now contains the count in words to be searched. |
| 1149 | |
| 1150 | // Load the address of the string into EBX. |
Mark Mendell | e19c91f | 2014-02-25 08:19:08 -0800 | [diff] [blame] | 1151 | // The string starts at VALUE(String) + 2 * OFFSET(String) + DATA_OFFSET. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 1152 | Load32Disp(rs_rDX, value_offset, rs_rDI); |
| 1153 | Load32Disp(rs_rDX, offset_offset, rs_rBX); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1154 | OpLea(rs_rBX, rs_rDI, rs_rBX, 1, data_offset); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1155 | |
| 1156 | // Now compute into EDI where the search will start. |
| 1157 | if (zero_based || rl_start.is_const) { |
| 1158 | if (start_value == 0) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1159 | OpRegCopy(rs_rDI, rs_rBX); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1160 | } else { |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1161 | NewLIR3(kX86Lea32RM, rs_rDI.GetReg(), rs_rBX.GetReg(), 2 * start_value); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1162 | } |
| 1163 | } else { |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1164 | if (is_index_on_stack == true) { |
| 1165 | // Load the start index from stack. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1166 | NewLIR1(kX86Pop32R, rs_rDX.GetReg()); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1167 | OpLea(rs_rDI, rs_rBX, rs_rDX, 1, 0); |
Alexei Zavjalov | a1758d8 | 2014-04-17 01:55:43 +0700 | [diff] [blame] | 1168 | } else { |
| 1169 | OpLea(rs_rDI, rs_rBX, rl_start.reg, 1, 0); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | // EDI now contains the start of the string to be searched. |
| 1174 | // We are all prepared to do the search for the character. |
| 1175 | NewLIR0(kX86RepneScasw); |
| 1176 | |
| 1177 | // Did we find a match? |
| 1178 | LIR* failed_branch = OpCondBranch(kCondNe, nullptr); |
| 1179 | |
| 1180 | // yes, we matched. Compute the index of the result. |
| 1181 | // index = ((curr_ptr - orig_ptr) / 2) - 1. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1182 | OpRegReg(kOpSub, rs_rDI, rs_rBX); |
| 1183 | OpRegImm(kOpAsr, rs_rDI, 1); |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1184 | NewLIR3(kX86Lea32RM, rl_return.reg.GetReg(), rs_rDI.GetReg(), -1); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1185 | LIR *all_done = NewLIR1(kX86Jmp8, 0); |
| 1186 | |
| 1187 | // Failed to match; return -1. |
| 1188 | LIR *not_found = NewLIR0(kPseudoTargetLabel); |
| 1189 | length_compare->target = not_found; |
| 1190 | failed_branch->target = not_found; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1191 | LoadConstantNoClobber(rl_return.reg, -1); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1192 | |
| 1193 | // And join up at the end. |
| 1194 | all_done->target = NewLIR0(kPseudoTargetLabel); |
| 1195 | // Restore EDI from the stack. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1196 | NewLIR1(kX86Pop32R, rs_rDI.GetReg()); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1197 | |
| 1198 | // Out of line code returns here. |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1199 | if (slowpath_branch != nullptr) { |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1200 | LIR *return_point = NewLIR0(kPseudoTargetLabel); |
Mingyao Yang | 3a74d15 | 2014-04-21 15:39:44 -0700 | [diff] [blame] | 1201 | AddIntrinsicSlowPath(info, slowpath_branch, return_point); |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | StoreValue(rl_dest, rl_return); |
| 1205 | return true; |
| 1206 | } |
| 1207 | |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 1208 | /* |
Mark Mendell | ae9fd93 | 2014-02-10 16:14:35 -0800 | [diff] [blame] | 1209 | * @brief Enter an 'advance LOC' into the FDE buffer |
| 1210 | * @param buf FDE buffer. |
| 1211 | * @param increment Amount by which to increase the current location. |
| 1212 | */ |
| 1213 | static void AdvanceLoc(std::vector<uint8_t>&buf, uint32_t increment) { |
| 1214 | if (increment < 64) { |
| 1215 | // Encoding in opcode. |
| 1216 | buf.push_back(0x1 << 6 | increment); |
| 1217 | } else if (increment < 256) { |
| 1218 | // Single byte delta. |
| 1219 | buf.push_back(0x02); |
| 1220 | buf.push_back(increment); |
| 1221 | } else if (increment < 256 * 256) { |
| 1222 | // Two byte delta. |
| 1223 | buf.push_back(0x03); |
| 1224 | buf.push_back(increment & 0xff); |
| 1225 | buf.push_back((increment >> 8) & 0xff); |
| 1226 | } else { |
| 1227 | // Four byte delta. |
| 1228 | buf.push_back(0x04); |
| 1229 | PushWord(buf, increment); |
| 1230 | } |
| 1231 | } |
| 1232 | |
| 1233 | |
| 1234 | std::vector<uint8_t>* X86CFIInitialization() { |
| 1235 | return X86Mir2Lir::ReturnCommonCallFrameInformation(); |
| 1236 | } |
| 1237 | |
| 1238 | std::vector<uint8_t>* X86Mir2Lir::ReturnCommonCallFrameInformation() { |
| 1239 | std::vector<uint8_t>*cfi_info = new std::vector<uint8_t>; |
| 1240 | |
| 1241 | // Length of the CIE (except for this field). |
| 1242 | PushWord(*cfi_info, 16); |
| 1243 | |
| 1244 | // CIE id. |
| 1245 | PushWord(*cfi_info, 0xFFFFFFFFU); |
| 1246 | |
| 1247 | // Version: 3. |
| 1248 | cfi_info->push_back(0x03); |
| 1249 | |
| 1250 | // Augmentation: empty string. |
| 1251 | cfi_info->push_back(0x0); |
| 1252 | |
| 1253 | // Code alignment: 1. |
| 1254 | cfi_info->push_back(0x01); |
| 1255 | |
| 1256 | // Data alignment: -4. |
| 1257 | cfi_info->push_back(0x7C); |
| 1258 | |
| 1259 | // Return address register (R8). |
| 1260 | cfi_info->push_back(0x08); |
| 1261 | |
| 1262 | // Initial return PC is 4(ESP): DW_CFA_def_cfa R4 4. |
| 1263 | cfi_info->push_back(0x0C); |
| 1264 | cfi_info->push_back(0x04); |
| 1265 | cfi_info->push_back(0x04); |
| 1266 | |
| 1267 | // Return address location: 0(SP): DW_CFA_offset R8 1 (* -4);. |
| 1268 | cfi_info->push_back(0x2 << 6 | 0x08); |
| 1269 | cfi_info->push_back(0x01); |
| 1270 | |
| 1271 | // And 2 Noops to align to 4 byte boundary. |
| 1272 | cfi_info->push_back(0x0); |
| 1273 | cfi_info->push_back(0x0); |
| 1274 | |
| 1275 | DCHECK_EQ(cfi_info->size() & 3, 0U); |
| 1276 | return cfi_info; |
| 1277 | } |
| 1278 | |
| 1279 | static void EncodeUnsignedLeb128(std::vector<uint8_t>& buf, uint32_t value) { |
| 1280 | uint8_t buffer[12]; |
| 1281 | uint8_t *ptr = EncodeUnsignedLeb128(buffer, value); |
| 1282 | for (uint8_t *p = buffer; p < ptr; p++) { |
| 1283 | buf.push_back(*p); |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | std::vector<uint8_t>* X86Mir2Lir::ReturnCallFrameInformation() { |
| 1288 | std::vector<uint8_t>*cfi_info = new std::vector<uint8_t>; |
| 1289 | |
| 1290 | // Generate the FDE for the method. |
| 1291 | DCHECK_NE(data_offset_, 0U); |
| 1292 | |
| 1293 | // Length (will be filled in later in this routine). |
| 1294 | PushWord(*cfi_info, 0); |
| 1295 | |
| 1296 | // CIE_pointer (can be filled in by linker); might be left at 0 if there is only |
| 1297 | // one CIE for the whole debug_frame section. |
| 1298 | PushWord(*cfi_info, 0); |
| 1299 | |
| 1300 | // 'initial_location' (filled in by linker). |
| 1301 | PushWord(*cfi_info, 0); |
| 1302 | |
| 1303 | // 'address_range' (number of bytes in the method). |
| 1304 | PushWord(*cfi_info, data_offset_); |
| 1305 | |
| 1306 | // The instructions in the FDE. |
| 1307 | if (stack_decrement_ != nullptr) { |
| 1308 | // Advance LOC to just past the stack decrement. |
| 1309 | uint32_t pc = NEXT_LIR(stack_decrement_)->offset; |
| 1310 | AdvanceLoc(*cfi_info, pc); |
| 1311 | |
| 1312 | // Now update the offset to the call frame: DW_CFA_def_cfa_offset frame_size. |
| 1313 | cfi_info->push_back(0x0e); |
| 1314 | EncodeUnsignedLeb128(*cfi_info, frame_size_); |
| 1315 | |
| 1316 | // We continue with that stack until the epilogue. |
| 1317 | if (stack_increment_ != nullptr) { |
| 1318 | uint32_t new_pc = NEXT_LIR(stack_increment_)->offset; |
| 1319 | AdvanceLoc(*cfi_info, new_pc - pc); |
| 1320 | |
| 1321 | // We probably have code snippets after the epilogue, so save the |
| 1322 | // current state: DW_CFA_remember_state. |
| 1323 | cfi_info->push_back(0x0a); |
| 1324 | |
| 1325 | // We have now popped the stack: DW_CFA_def_cfa_offset 4. There is only the return |
| 1326 | // PC on the stack now. |
| 1327 | cfi_info->push_back(0x0e); |
| 1328 | EncodeUnsignedLeb128(*cfi_info, 4); |
| 1329 | |
| 1330 | // Everything after that is the same as before the epilogue. |
| 1331 | // Stack bump was followed by RET instruction. |
| 1332 | LIR *post_ret_insn = NEXT_LIR(NEXT_LIR(stack_increment_)); |
| 1333 | if (post_ret_insn != nullptr) { |
| 1334 | pc = new_pc; |
| 1335 | new_pc = post_ret_insn->offset; |
| 1336 | AdvanceLoc(*cfi_info, new_pc - pc); |
| 1337 | // Restore the state: DW_CFA_restore_state. |
| 1338 | cfi_info->push_back(0x0b); |
| 1339 | } |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | // Padding to a multiple of 4 |
| 1344 | while ((cfi_info->size() & 3) != 0) { |
| 1345 | // DW_CFA_nop is encoded as 0. |
| 1346 | cfi_info->push_back(0); |
| 1347 | } |
| 1348 | |
| 1349 | // Set the length of the FDE inside the generated bytes. |
| 1350 | uint32_t length = cfi_info->size() - 4; |
| 1351 | (*cfi_info)[0] = length; |
| 1352 | (*cfi_info)[1] = length >> 8; |
| 1353 | (*cfi_info)[2] = length >> 16; |
| 1354 | (*cfi_info)[3] = length >> 24; |
| 1355 | return cfi_info; |
| 1356 | } |
| 1357 | |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1358 | void X86Mir2Lir::GenMachineSpecificExtendedMethodMIR(BasicBlock* bb, MIR* mir) { |
| 1359 | switch (static_cast<ExtendedMIROpcode>(mir->dalvikInsn.opcode)) { |
| 1360 | case kMirOpConstVector: |
| 1361 | GenConst128(bb, mir); |
| 1362 | break; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1363 | case kMirOpMoveVector: |
| 1364 | GenMoveVector(bb, mir); |
| 1365 | break; |
| 1366 | case kMirOpPackedMultiply: |
| 1367 | GenMultiplyVector(bb, mir); |
| 1368 | break; |
| 1369 | case kMirOpPackedAddition: |
| 1370 | GenAddVector(bb, mir); |
| 1371 | break; |
| 1372 | case kMirOpPackedSubtract: |
| 1373 | GenSubtractVector(bb, mir); |
| 1374 | break; |
| 1375 | case kMirOpPackedShiftLeft: |
| 1376 | GenShiftLeftVector(bb, mir); |
| 1377 | break; |
| 1378 | case kMirOpPackedSignedShiftRight: |
| 1379 | GenSignedShiftRightVector(bb, mir); |
| 1380 | break; |
| 1381 | case kMirOpPackedUnsignedShiftRight: |
| 1382 | GenUnsignedShiftRightVector(bb, mir); |
| 1383 | break; |
| 1384 | case kMirOpPackedAnd: |
| 1385 | GenAndVector(bb, mir); |
| 1386 | break; |
| 1387 | case kMirOpPackedOr: |
| 1388 | GenOrVector(bb, mir); |
| 1389 | break; |
| 1390 | case kMirOpPackedXor: |
| 1391 | GenXorVector(bb, mir); |
| 1392 | break; |
| 1393 | case kMirOpPackedAddReduce: |
| 1394 | GenAddReduceVector(bb, mir); |
| 1395 | break; |
| 1396 | case kMirOpPackedReduce: |
| 1397 | GenReduceVector(bb, mir); |
| 1398 | break; |
| 1399 | case kMirOpPackedSet: |
| 1400 | GenSetVector(bb, mir); |
| 1401 | break; |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1402 | default: |
| 1403 | break; |
| 1404 | } |
| 1405 | } |
| 1406 | |
| 1407 | void X86Mir2Lir::GenConst128(BasicBlock* bb, MIR* mir) { |
| 1408 | int type_size = mir->dalvikInsn.vA; |
| 1409 | // We support 128 bit vectors. |
| 1410 | DCHECK_EQ(type_size & 0xFFFF, 128); |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1411 | RegStorage rs_dest = RegStorage::Solo128(mir->dalvikInsn.vB); |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1412 | uint32_t *args = mir->dalvikInsn.arg; |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1413 | int reg = rs_dest.GetReg(); |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1414 | // Check for all 0 case. |
| 1415 | if (args[0] == 0 && args[1] == 0 && args[2] == 0 && args[3] == 0) { |
| 1416 | NewLIR2(kX86XorpsRR, reg, reg); |
| 1417 | return; |
| 1418 | } |
| 1419 | // Okay, load it from the constant vector area. |
| 1420 | LIR *data_target = ScanVectorLiteral(mir); |
| 1421 | if (data_target == nullptr) { |
| 1422 | data_target = AddVectorLiteral(mir); |
| 1423 | } |
| 1424 | |
| 1425 | // Address the start of the method. |
| 1426 | RegLocation rl_method = mir_graph_->GetRegLocation(base_of_code_->s_reg_low); |
Chao-ying Fu | e0ccdc0 | 2014-06-06 17:32:37 -0700 | [diff] [blame] | 1427 | if (rl_method.wide) { |
| 1428 | rl_method = LoadValueWide(rl_method, kCoreReg); |
| 1429 | } else { |
| 1430 | rl_method = LoadValue(rl_method, kCoreReg); |
| 1431 | } |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1432 | |
| 1433 | // Load the proper value from the literal area. |
| 1434 | // We don't know the proper offset for the value, so pick one that will force |
| 1435 | // 4 byte offset. We will fix this up in the assembler later to have the right |
| 1436 | // value. |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 1437 | ScopedMemRefType mem_ref_type(this, ResourceMask::kLiteral); |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1438 | LIR *load = NewLIR3(kX86Mova128RM, reg, rl_method.reg.GetReg(), 256 /* bogus */); |
| 1439 | load->flags.fixup = kFixupLoad; |
| 1440 | load->target = data_target; |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1441 | } |
| 1442 | |
Mark Mendell | fe94578 | 2014-05-22 09:52:36 -0400 | [diff] [blame] | 1443 | void X86Mir2Lir::GenMoveVector(BasicBlock *bb, MIR *mir) { |
| 1444 | // We only support 128 bit registers. |
| 1445 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1446 | RegStorage rs_dest = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1447 | RegStorage rs_src = RegStorage::Solo128(mir->dalvikInsn.vC); |
| 1448 | NewLIR2(kX86Mova128RR, rs_dest.GetReg(), rs_src.GetReg()); |
| 1449 | } |
| 1450 | |
| 1451 | void X86Mir2Lir::GenMultiplyVector(BasicBlock *bb, MIR *mir) { |
| 1452 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1453 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1454 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1455 | RegStorage rs_src2 = RegStorage::Solo128(mir->dalvikInsn.vC); |
| 1456 | int opcode = 0; |
| 1457 | switch (opsize) { |
| 1458 | case k32: |
| 1459 | opcode = kX86PmulldRR; |
| 1460 | break; |
| 1461 | case kSignedHalf: |
| 1462 | opcode = kX86PmullwRR; |
| 1463 | break; |
| 1464 | case kSingle: |
| 1465 | opcode = kX86MulpsRR; |
| 1466 | break; |
| 1467 | case kDouble: |
| 1468 | opcode = kX86MulpdRR; |
| 1469 | break; |
| 1470 | default: |
| 1471 | LOG(FATAL) << "Unsupported vector multiply " << opsize; |
| 1472 | break; |
| 1473 | } |
| 1474 | NewLIR2(opcode, rs_dest_src1.GetReg(), rs_src2.GetReg()); |
| 1475 | } |
| 1476 | |
| 1477 | void X86Mir2Lir::GenAddVector(BasicBlock *bb, MIR *mir) { |
| 1478 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1479 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1480 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1481 | RegStorage rs_src2 = RegStorage::Solo128(mir->dalvikInsn.vC); |
| 1482 | int opcode = 0; |
| 1483 | switch (opsize) { |
| 1484 | case k32: |
| 1485 | opcode = kX86PadddRR; |
| 1486 | break; |
| 1487 | case kSignedHalf: |
| 1488 | case kUnsignedHalf: |
| 1489 | opcode = kX86PaddwRR; |
| 1490 | break; |
| 1491 | case kUnsignedByte: |
| 1492 | case kSignedByte: |
| 1493 | opcode = kX86PaddbRR; |
| 1494 | break; |
| 1495 | case kSingle: |
| 1496 | opcode = kX86AddpsRR; |
| 1497 | break; |
| 1498 | case kDouble: |
| 1499 | opcode = kX86AddpdRR; |
| 1500 | break; |
| 1501 | default: |
| 1502 | LOG(FATAL) << "Unsupported vector addition " << opsize; |
| 1503 | break; |
| 1504 | } |
| 1505 | NewLIR2(opcode, rs_dest_src1.GetReg(), rs_src2.GetReg()); |
| 1506 | } |
| 1507 | |
| 1508 | void X86Mir2Lir::GenSubtractVector(BasicBlock *bb, MIR *mir) { |
| 1509 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1510 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1511 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1512 | RegStorage rs_src2 = RegStorage::Solo128(mir->dalvikInsn.vC); |
| 1513 | int opcode = 0; |
| 1514 | switch (opsize) { |
| 1515 | case k32: |
| 1516 | opcode = kX86PsubdRR; |
| 1517 | break; |
| 1518 | case kSignedHalf: |
| 1519 | case kUnsignedHalf: |
| 1520 | opcode = kX86PsubwRR; |
| 1521 | break; |
| 1522 | case kUnsignedByte: |
| 1523 | case kSignedByte: |
| 1524 | opcode = kX86PsubbRR; |
| 1525 | break; |
| 1526 | case kSingle: |
| 1527 | opcode = kX86SubpsRR; |
| 1528 | break; |
| 1529 | case kDouble: |
| 1530 | opcode = kX86SubpdRR; |
| 1531 | break; |
| 1532 | default: |
| 1533 | LOG(FATAL) << "Unsupported vector subtraction " << opsize; |
| 1534 | break; |
| 1535 | } |
| 1536 | NewLIR2(opcode, rs_dest_src1.GetReg(), rs_src2.GetReg()); |
| 1537 | } |
| 1538 | |
| 1539 | void X86Mir2Lir::GenShiftLeftVector(BasicBlock *bb, MIR *mir) { |
| 1540 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1541 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1542 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1543 | int imm = mir->dalvikInsn.vC; |
| 1544 | int opcode = 0; |
| 1545 | switch (opsize) { |
| 1546 | case k32: |
| 1547 | opcode = kX86PslldRI; |
| 1548 | break; |
| 1549 | case k64: |
| 1550 | opcode = kX86PsllqRI; |
| 1551 | break; |
| 1552 | case kSignedHalf: |
| 1553 | case kUnsignedHalf: |
| 1554 | opcode = kX86PsllwRI; |
| 1555 | break; |
| 1556 | default: |
| 1557 | LOG(FATAL) << "Unsupported vector shift left " << opsize; |
| 1558 | break; |
| 1559 | } |
| 1560 | NewLIR2(opcode, rs_dest_src1.GetReg(), imm); |
| 1561 | } |
| 1562 | |
| 1563 | void X86Mir2Lir::GenSignedShiftRightVector(BasicBlock *bb, MIR *mir) { |
| 1564 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1565 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1566 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1567 | int imm = mir->dalvikInsn.vC; |
| 1568 | int opcode = 0; |
| 1569 | switch (opsize) { |
| 1570 | case k32: |
| 1571 | opcode = kX86PsradRI; |
| 1572 | break; |
| 1573 | case kSignedHalf: |
| 1574 | case kUnsignedHalf: |
| 1575 | opcode = kX86PsrawRI; |
| 1576 | break; |
| 1577 | default: |
| 1578 | LOG(FATAL) << "Unsupported vector signed shift right " << opsize; |
| 1579 | break; |
| 1580 | } |
| 1581 | NewLIR2(opcode, rs_dest_src1.GetReg(), imm); |
| 1582 | } |
| 1583 | |
| 1584 | void X86Mir2Lir::GenUnsignedShiftRightVector(BasicBlock *bb, MIR *mir) { |
| 1585 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1586 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1587 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1588 | int imm = mir->dalvikInsn.vC; |
| 1589 | int opcode = 0; |
| 1590 | switch (opsize) { |
| 1591 | case k32: |
| 1592 | opcode = kX86PsrldRI; |
| 1593 | break; |
| 1594 | case k64: |
| 1595 | opcode = kX86PsrlqRI; |
| 1596 | break; |
| 1597 | case kSignedHalf: |
| 1598 | case kUnsignedHalf: |
| 1599 | opcode = kX86PsrlwRI; |
| 1600 | break; |
| 1601 | default: |
| 1602 | LOG(FATAL) << "Unsupported vector unsigned shift right " << opsize; |
| 1603 | break; |
| 1604 | } |
| 1605 | NewLIR2(opcode, rs_dest_src1.GetReg(), imm); |
| 1606 | } |
| 1607 | |
| 1608 | void X86Mir2Lir::GenAndVector(BasicBlock *bb, MIR *mir) { |
| 1609 | // We only support 128 bit registers. |
| 1610 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1611 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1612 | RegStorage rs_src2 = RegStorage::Solo128(mir->dalvikInsn.vC); |
| 1613 | NewLIR2(kX86PandRR, rs_dest_src1.GetReg(), rs_src2.GetReg()); |
| 1614 | } |
| 1615 | |
| 1616 | void X86Mir2Lir::GenOrVector(BasicBlock *bb, MIR *mir) { |
| 1617 | // We only support 128 bit registers. |
| 1618 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1619 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1620 | RegStorage rs_src2 = RegStorage::Solo128(mir->dalvikInsn.vC); |
| 1621 | NewLIR2(kX86PorRR, rs_dest_src1.GetReg(), rs_src2.GetReg()); |
| 1622 | } |
| 1623 | |
| 1624 | void X86Mir2Lir::GenXorVector(BasicBlock *bb, MIR *mir) { |
| 1625 | // We only support 128 bit registers. |
| 1626 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1627 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1628 | RegStorage rs_src2 = RegStorage::Solo128(mir->dalvikInsn.vC); |
| 1629 | NewLIR2(kX86PxorRR, rs_dest_src1.GetReg(), rs_src2.GetReg()); |
| 1630 | } |
| 1631 | |
| 1632 | void X86Mir2Lir::GenAddReduceVector(BasicBlock *bb, MIR *mir) { |
| 1633 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1634 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1635 | RegStorage rs_dest_src1 = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1636 | int imm = mir->dalvikInsn.vC; |
| 1637 | int opcode = 0; |
| 1638 | switch (opsize) { |
| 1639 | case k32: |
| 1640 | opcode = kX86PhadddRR; |
| 1641 | break; |
| 1642 | case kSignedHalf: |
| 1643 | case kUnsignedHalf: |
| 1644 | opcode = kX86PhaddwRR; |
| 1645 | break; |
| 1646 | default: |
| 1647 | LOG(FATAL) << "Unsupported vector add reduce " << opsize; |
| 1648 | break; |
| 1649 | } |
| 1650 | NewLIR2(opcode, rs_dest_src1.GetReg(), imm); |
| 1651 | } |
| 1652 | |
| 1653 | void X86Mir2Lir::GenReduceVector(BasicBlock *bb, MIR *mir) { |
| 1654 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1655 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1656 | RegStorage rs_src = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1657 | int index = mir->dalvikInsn.arg[0]; |
| 1658 | int opcode = 0; |
| 1659 | switch (opsize) { |
| 1660 | case k32: |
| 1661 | opcode = kX86PextrdRRI; |
| 1662 | break; |
| 1663 | case kSignedHalf: |
| 1664 | case kUnsignedHalf: |
| 1665 | opcode = kX86PextrwRRI; |
| 1666 | break; |
| 1667 | case kUnsignedByte: |
| 1668 | case kSignedByte: |
| 1669 | opcode = kX86PextrbRRI; |
| 1670 | break; |
| 1671 | default: |
| 1672 | LOG(FATAL) << "Unsupported vector reduce " << opsize; |
| 1673 | break; |
| 1674 | } |
| 1675 | // We need to extract to a GPR. |
| 1676 | RegStorage temp = AllocTemp(); |
| 1677 | NewLIR3(opcode, temp.GetReg(), rs_src.GetReg(), index); |
| 1678 | |
| 1679 | // Assume that the destination VR is in the def for the mir. |
| 1680 | RegLocation rl_dest = mir_graph_->GetDest(mir); |
| 1681 | RegLocation rl_temp = |
| 1682 | {kLocPhysReg, 0, 0, 0, 0, 0, 0, 0, 1, temp, INVALID_SREG, INVALID_SREG}; |
| 1683 | StoreValue(rl_dest, rl_temp); |
| 1684 | } |
| 1685 | |
| 1686 | void X86Mir2Lir::GenSetVector(BasicBlock *bb, MIR *mir) { |
| 1687 | DCHECK_EQ(mir->dalvikInsn.vA & 0xFFFF, 128U); |
| 1688 | OpSize opsize = static_cast<OpSize>(mir->dalvikInsn.vA >> 16); |
| 1689 | RegStorage rs_dest = RegStorage::Solo128(mir->dalvikInsn.vB); |
| 1690 | int op_low = 0, op_high = 0; |
| 1691 | switch (opsize) { |
| 1692 | case k32: |
| 1693 | op_low = kX86PshufdRRI; |
| 1694 | break; |
| 1695 | case kSignedHalf: |
| 1696 | case kUnsignedHalf: |
| 1697 | // Handles low quadword. |
| 1698 | op_low = kX86PshuflwRRI; |
| 1699 | // Handles upper quadword. |
| 1700 | op_high = kX86PshufdRRI; |
| 1701 | break; |
| 1702 | default: |
| 1703 | LOG(FATAL) << "Unsupported vector set " << opsize; |
| 1704 | break; |
| 1705 | } |
| 1706 | |
| 1707 | // Load the value from the VR into a GPR. |
| 1708 | RegLocation rl_src = mir_graph_->GetSrc(mir, 0); |
| 1709 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1710 | |
| 1711 | // Load the value into the XMM register. |
| 1712 | NewLIR2(kX86MovdxrRR, rs_dest.GetReg(), rl_src.reg.GetReg()); |
| 1713 | |
| 1714 | // Now shuffle the value across the destination. |
| 1715 | NewLIR3(op_low, rs_dest.GetReg(), rs_dest.GetReg(), 0); |
| 1716 | |
| 1717 | // And then repeat as needed. |
| 1718 | if (op_high != 0) { |
| 1719 | NewLIR3(op_high, rs_dest.GetReg(), rs_dest.GetReg(), 0); |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1724 | LIR *X86Mir2Lir::ScanVectorLiteral(MIR *mir) { |
| 1725 | int *args = reinterpret_cast<int*>(mir->dalvikInsn.arg); |
| 1726 | for (LIR *p = const_vectors_; p != nullptr; p = p->next) { |
| 1727 | if (args[0] == p->operands[0] && args[1] == p->operands[1] && |
| 1728 | args[2] == p->operands[2] && args[3] == p->operands[3]) { |
| 1729 | return p; |
| 1730 | } |
| 1731 | } |
| 1732 | return nullptr; |
| 1733 | } |
| 1734 | |
| 1735 | LIR *X86Mir2Lir::AddVectorLiteral(MIR *mir) { |
| 1736 | LIR* new_value = static_cast<LIR*>(arena_->Alloc(sizeof(LIR), kArenaAllocData)); |
| 1737 | int *args = reinterpret_cast<int*>(mir->dalvikInsn.arg); |
| 1738 | new_value->operands[0] = args[0]; |
| 1739 | new_value->operands[1] = args[1]; |
| 1740 | new_value->operands[2] = args[2]; |
| 1741 | new_value->operands[3] = args[3]; |
| 1742 | new_value->next = const_vectors_; |
| 1743 | if (const_vectors_ == nullptr) { |
| 1744 | estimated_native_code_size_ += 12; // Amount needed to align to 16 byte boundary. |
| 1745 | } |
| 1746 | estimated_native_code_size_ += 16; // Space for one vector. |
| 1747 | const_vectors_ = new_value; |
| 1748 | return new_value; |
| 1749 | } |
| 1750 | |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1751 | // ------------ ABI support: mapping of args to physical registers ------------- |
| 1752 | RegStorage X86Mir2Lir::InToRegStorageX86_64Mapper::GetNextReg(bool is_double_or_float, bool is_wide) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1753 | const SpecialTargetRegister coreArgMappingToPhysicalReg[] = {kArg1, kArg2, kArg3, kArg4, kArg5}; |
| 1754 | const int coreArgMappingToPhysicalRegSize = sizeof(coreArgMappingToPhysicalReg) / sizeof(SpecialTargetRegister); |
| 1755 | const SpecialTargetRegister fpArgMappingToPhysicalReg[] = {kFArg0, kFArg1, kFArg2, kFArg3, |
| 1756 | kFArg4, kFArg5, kFArg6, kFArg7}; |
| 1757 | const int fpArgMappingToPhysicalRegSize = sizeof(fpArgMappingToPhysicalReg) / sizeof(SpecialTargetRegister); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1758 | |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1759 | if (is_double_or_float) { |
| 1760 | if (cur_fp_reg_ < fpArgMappingToPhysicalRegSize) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1761 | return ml_->TargetReg(fpArgMappingToPhysicalReg[cur_fp_reg_++], is_wide); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1762 | } |
| 1763 | } else { |
| 1764 | if (cur_core_reg_ < coreArgMappingToPhysicalRegSize) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1765 | return ml_->TargetReg(coreArgMappingToPhysicalReg[cur_core_reg_++], is_wide); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1766 | } |
| 1767 | } |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1768 | return RegStorage::InvalidReg(); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1769 | } |
| 1770 | |
| 1771 | RegStorage X86Mir2Lir::InToRegStorageMapping::Get(int in_position) { |
| 1772 | DCHECK(IsInitialized()); |
| 1773 | auto res = mapping_.find(in_position); |
| 1774 | return res != mapping_.end() ? res->second : RegStorage::InvalidReg(); |
| 1775 | } |
| 1776 | |
| 1777 | void X86Mir2Lir::InToRegStorageMapping::Initialize(RegLocation* arg_locs, int count, InToRegStorageMapper* mapper) { |
| 1778 | DCHECK(mapper != nullptr); |
| 1779 | max_mapped_in_ = -1; |
| 1780 | is_there_stack_mapped_ = false; |
| 1781 | for (int in_position = 0; in_position < count; in_position++) { |
| 1782 | RegStorage reg = mapper->GetNextReg(arg_locs[in_position].fp, arg_locs[in_position].wide); |
| 1783 | if (reg.Valid()) { |
| 1784 | mapping_[in_position] = reg; |
| 1785 | max_mapped_in_ = std::max(max_mapped_in_, in_position); |
| 1786 | if (reg.Is64BitSolo()) { |
| 1787 | // We covered 2 args, so skip the next one |
| 1788 | in_position++; |
| 1789 | } |
| 1790 | } else { |
| 1791 | is_there_stack_mapped_ = true; |
| 1792 | } |
| 1793 | } |
| 1794 | initialized_ = true; |
| 1795 | } |
| 1796 | |
| 1797 | RegStorage X86Mir2Lir::GetArgMappingToPhysicalReg(int arg_num) { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 1798 | if (!cu_->target64) { |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1799 | return GetCoreArgMappingToPhysicalReg(arg_num); |
| 1800 | } |
| 1801 | |
| 1802 | if (!in_to_reg_storage_mapping_.IsInitialized()) { |
| 1803 | int start_vreg = cu_->num_dalvik_registers - cu_->num_ins; |
| 1804 | RegLocation* arg_locs = &mir_graph_->reg_location_[start_vreg]; |
| 1805 | |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1806 | InToRegStorageX86_64Mapper mapper(this); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1807 | in_to_reg_storage_mapping_.Initialize(arg_locs, cu_->num_ins, &mapper); |
| 1808 | } |
| 1809 | return in_to_reg_storage_mapping_.Get(arg_num); |
| 1810 | } |
| 1811 | |
| 1812 | RegStorage X86Mir2Lir::GetCoreArgMappingToPhysicalReg(int core_arg_num) { |
| 1813 | // For the 32-bit internal ABI, the first 3 arguments are passed in registers. |
| 1814 | // Not used for 64-bit, TODO: Move X86_32 to the same framework |
| 1815 | switch (core_arg_num) { |
| 1816 | case 0: |
| 1817 | return rs_rX86_ARG1; |
| 1818 | case 1: |
| 1819 | return rs_rX86_ARG2; |
| 1820 | case 2: |
| 1821 | return rs_rX86_ARG3; |
| 1822 | default: |
| 1823 | return RegStorage::InvalidReg(); |
| 1824 | } |
| 1825 | } |
| 1826 | |
| 1827 | // ---------End of ABI support: mapping of args to physical registers ------------- |
| 1828 | |
| 1829 | /* |
| 1830 | * If there are any ins passed in registers that have not been promoted |
| 1831 | * to a callee-save register, flush them to the frame. Perform initial |
| 1832 | * assignment of promoted arguments. |
| 1833 | * |
| 1834 | * ArgLocs is an array of location records describing the incoming arguments |
| 1835 | * with one location record per word of argument. |
| 1836 | */ |
| 1837 | void X86Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 1838 | if (!cu_->target64) return Mir2Lir::FlushIns(ArgLocs, rl_method); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1839 | /* |
| 1840 | * Dummy up a RegLocation for the incoming Method* |
| 1841 | * It will attempt to keep kArg0 live (or copy it to home location |
| 1842 | * if promoted). |
| 1843 | */ |
| 1844 | |
| 1845 | RegLocation rl_src = rl_method; |
| 1846 | rl_src.location = kLocPhysReg; |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1847 | rl_src.reg = TargetRefReg(kArg0); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1848 | rl_src.home = false; |
| 1849 | MarkLive(rl_src); |
| 1850 | StoreValue(rl_method, rl_src); |
| 1851 | // If Method* has been promoted, explicitly flush |
| 1852 | if (rl_method.location == kLocPhysReg) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1853 | StoreRefDisp(rs_rX86_SP, 0, As32BitReg(TargetRefReg(kArg0)), kNotVolatile); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1854 | } |
| 1855 | |
| 1856 | if (cu_->num_ins == 0) { |
| 1857 | return; |
| 1858 | } |
| 1859 | |
| 1860 | int start_vreg = cu_->num_dalvik_registers - cu_->num_ins; |
| 1861 | /* |
| 1862 | * Copy incoming arguments to their proper home locations. |
| 1863 | * NOTE: an older version of dx had an issue in which |
| 1864 | * it would reuse static method argument registers. |
| 1865 | * This could result in the same Dalvik virtual register |
| 1866 | * being promoted to both core and fp regs. To account for this, |
| 1867 | * we only copy to the corresponding promoted physical register |
| 1868 | * if it matches the type of the SSA name for the incoming |
| 1869 | * argument. It is also possible that long and double arguments |
| 1870 | * end up half-promoted. In those cases, we must flush the promoted |
| 1871 | * half to memory as well. |
| 1872 | */ |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 1873 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1874 | for (int i = 0; i < cu_->num_ins; i++) { |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1875 | // get reg corresponding to input |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1876 | RegStorage reg = GetArgMappingToPhysicalReg(i); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1877 | |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1878 | RegLocation* t_loc = &ArgLocs[i]; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1879 | if (reg.Valid()) { |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1880 | // If arriving in register. |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1881 | |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1882 | // We have already updated the arg location with promoted info |
| 1883 | // so we can be based on it. |
| 1884 | if (t_loc->location == kLocPhysReg) { |
| 1885 | // Just copy it. |
| 1886 | OpRegCopy(t_loc->reg, reg); |
| 1887 | } else { |
| 1888 | // Needs flush. |
| 1889 | if (t_loc->ref) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1890 | StoreRefDisp(rs_rX86_SP, SRegOffset(start_vreg + i), reg, kNotVolatile); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1891 | } else { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1892 | StoreBaseDisp(rs_rX86_SP, SRegOffset(start_vreg + i), reg, t_loc->wide ? k64 : k32, |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1893 | kNotVolatile); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1894 | } |
| 1895 | } |
| 1896 | } else { |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1897 | // If arriving in frame & promoted. |
| 1898 | if (t_loc->location == kLocPhysReg) { |
| 1899 | if (t_loc->ref) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1900 | LoadRefDisp(rs_rX86_SP, SRegOffset(start_vreg + i), t_loc->reg, kNotVolatile); |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1901 | } else { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1902 | LoadBaseDisp(rs_rX86_SP, SRegOffset(start_vreg + i), t_loc->reg, |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1903 | t_loc->wide ? k64 : k32, kNotVolatile); |
| 1904 | } |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1905 | } |
Dmitry Petrochenko | 4d5d794 | 2014-06-27 12:25:01 +0700 | [diff] [blame] | 1906 | } |
| 1907 | if (t_loc->wide) { |
| 1908 | // Increment i to skip the next one. |
| 1909 | i++; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1910 | } |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | /* |
| 1915 | * Load up to 5 arguments, the first three of which will be in |
| 1916 | * kArg1 .. kArg3. On entry kArg0 contains the current method pointer, |
| 1917 | * and as part of the load sequence, it must be replaced with |
| 1918 | * the target method pointer. Note, this may also be called |
| 1919 | * for "range" variants if the number of arguments is 5 or fewer. |
| 1920 | */ |
| 1921 | int X86Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, |
| 1922 | int call_state, LIR** pcrLabel, NextCallInsn next_call_insn, |
| 1923 | const MethodReference& target_method, |
| 1924 | uint32_t vtable_idx, uintptr_t direct_code, |
| 1925 | uintptr_t direct_method, InvokeType type, bool skip_this) { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 1926 | if (!cu_->target64) { |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1927 | return Mir2Lir::GenDalvikArgsNoRange(info, |
| 1928 | call_state, pcrLabel, next_call_insn, |
| 1929 | target_method, |
| 1930 | vtable_idx, direct_code, |
| 1931 | direct_method, type, skip_this); |
| 1932 | } |
| 1933 | return GenDalvikArgsRange(info, |
| 1934 | call_state, pcrLabel, next_call_insn, |
| 1935 | target_method, |
| 1936 | vtable_idx, direct_code, |
| 1937 | direct_method, type, skip_this); |
| 1938 | } |
| 1939 | |
| 1940 | /* |
| 1941 | * May have 0+ arguments (also used for jumbo). Note that |
| 1942 | * source virtual registers may be in physical registers, so may |
| 1943 | * need to be flushed to home location before copying. This |
| 1944 | * applies to arg3 and above (see below). |
| 1945 | * |
| 1946 | * Two general strategies: |
| 1947 | * If < 20 arguments |
| 1948 | * Pass args 3-18 using vldm/vstm block copy |
| 1949 | * Pass arg0, arg1 & arg2 in kArg1-kArg3 |
| 1950 | * If 20+ arguments |
| 1951 | * Pass args arg19+ using memcpy block copy |
| 1952 | * Pass arg0, arg1 & arg2 in kArg1-kArg3 |
| 1953 | * |
| 1954 | */ |
| 1955 | int X86Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state, |
| 1956 | LIR** pcrLabel, NextCallInsn next_call_insn, |
| 1957 | const MethodReference& target_method, |
| 1958 | uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, |
| 1959 | InvokeType type, bool skip_this) { |
Elena Sayapina | dd64450 | 2014-07-01 18:39:52 +0700 | [diff] [blame] | 1960 | if (!cu_->target64) { |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1961 | return Mir2Lir::GenDalvikArgsRange(info, call_state, |
| 1962 | pcrLabel, next_call_insn, |
| 1963 | target_method, |
| 1964 | vtable_idx, direct_code, direct_method, |
| 1965 | type, skip_this); |
| 1966 | } |
| 1967 | |
| 1968 | /* If no arguments, just return */ |
| 1969 | if (info->num_arg_words == 0) |
| 1970 | return call_state; |
| 1971 | |
| 1972 | const int start_index = skip_this ? 1 : 0; |
| 1973 | |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1974 | InToRegStorageX86_64Mapper mapper(this); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1975 | InToRegStorageMapping in_to_reg_storage_mapping; |
| 1976 | in_to_reg_storage_mapping.Initialize(info->args, info->num_arg_words, &mapper); |
| 1977 | const int last_mapped_in = in_to_reg_storage_mapping.GetMaxMappedIn(); |
| 1978 | const int size_of_the_last_mapped = last_mapped_in == -1 ? 1 : |
| 1979 | in_to_reg_storage_mapping.Get(last_mapped_in).Is64BitSolo() ? 2 : 1; |
| 1980 | int regs_left_to_pass_via_stack = info->num_arg_words - (last_mapped_in + size_of_the_last_mapped); |
| 1981 | |
| 1982 | // Fisrt of all, check whether it make sense to use bulk copying |
| 1983 | // Optimization is aplicable only for range case |
| 1984 | // TODO: make a constant instead of 2 |
| 1985 | if (info->is_range && regs_left_to_pass_via_stack >= 2) { |
| 1986 | // Scan the rest of the args - if in phys_reg flush to memory |
| 1987 | for (int next_arg = last_mapped_in + size_of_the_last_mapped; next_arg < info->num_arg_words;) { |
| 1988 | RegLocation loc = info->args[next_arg]; |
| 1989 | if (loc.wide) { |
| 1990 | loc = UpdateLocWide(loc); |
| 1991 | if (loc.location == kLocPhysReg) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 1992 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 1993 | StoreBaseDisp(rs_rX86_SP, SRegOffset(loc.s_reg_low), loc.reg, k64, kNotVolatile); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 1994 | } |
| 1995 | next_arg += 2; |
| 1996 | } else { |
| 1997 | loc = UpdateLoc(loc); |
| 1998 | if (loc.location == kLocPhysReg) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 1999 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2000 | StoreBaseDisp(rs_rX86_SP, SRegOffset(loc.s_reg_low), loc.reg, k32, kNotVolatile); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2001 | } |
| 2002 | next_arg++; |
| 2003 | } |
| 2004 | } |
| 2005 | |
| 2006 | // Logic below assumes that Method pointer is at offset zero from SP. |
| 2007 | DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0); |
| 2008 | |
| 2009 | // The rest can be copied together |
| 2010 | int start_offset = SRegOffset(info->args[last_mapped_in + size_of_the_last_mapped].s_reg_low); |
| 2011 | int outs_offset = StackVisitor::GetOutVROffset(last_mapped_in + size_of_the_last_mapped, cu_->instruction_set); |
| 2012 | |
| 2013 | int current_src_offset = start_offset; |
| 2014 | int current_dest_offset = outs_offset; |
| 2015 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2016 | // Only davik regs are accessed in this loop; no next_call_insn() calls. |
| 2017 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2018 | while (regs_left_to_pass_via_stack > 0) { |
| 2019 | // This is based on the knowledge that the stack itself is 16-byte aligned. |
| 2020 | bool src_is_16b_aligned = (current_src_offset & 0xF) == 0; |
| 2021 | bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0; |
| 2022 | size_t bytes_to_move; |
| 2023 | |
| 2024 | /* |
| 2025 | * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a |
| 2026 | * a 128-bit move because we won't get the chance to try to aligned. If there are more than |
| 2027 | * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned. |
| 2028 | * We do this because we could potentially do a smaller move to align. |
| 2029 | */ |
| 2030 | if (regs_left_to_pass_via_stack == 4 || |
| 2031 | (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) { |
| 2032 | // Moving 128-bits via xmm register. |
| 2033 | bytes_to_move = sizeof(uint32_t) * 4; |
| 2034 | |
| 2035 | // Allocate a free xmm temp. Since we are working through the calling sequence, |
| 2036 | // we expect to have an xmm temporary available. AllocTempDouble will abort if |
| 2037 | // there are no free registers. |
| 2038 | RegStorage temp = AllocTempDouble(); |
| 2039 | |
| 2040 | LIR* ld1 = nullptr; |
| 2041 | LIR* ld2 = nullptr; |
| 2042 | LIR* st1 = nullptr; |
| 2043 | LIR* st2 = nullptr; |
| 2044 | |
| 2045 | /* |
| 2046 | * The logic is similar for both loads and stores. If we have 16-byte alignment, |
| 2047 | * do an aligned move. If we have 8-byte alignment, then do the move in two |
| 2048 | * parts. This approach prevents possible cache line splits. Finally, fall back |
| 2049 | * to doing an unaligned move. In most cases we likely won't split the cache |
| 2050 | * line but we cannot prove it and thus take a conservative approach. |
| 2051 | */ |
| 2052 | bool src_is_8b_aligned = (current_src_offset & 0x7) == 0; |
| 2053 | bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0; |
| 2054 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2055 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2056 | if (src_is_16b_aligned) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2057 | ld1 = OpMovRegMem(temp, rs_rX86_SP, current_src_offset, kMovA128FP); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2058 | } else if (src_is_8b_aligned) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2059 | ld1 = OpMovRegMem(temp, rs_rX86_SP, current_src_offset, kMovLo128FP); |
| 2060 | ld2 = OpMovRegMem(temp, rs_rX86_SP, current_src_offset + (bytes_to_move >> 1), |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2061 | kMovHi128FP); |
| 2062 | } else { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2063 | ld1 = OpMovRegMem(temp, rs_rX86_SP, current_src_offset, kMovU128FP); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | if (dest_is_16b_aligned) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2067 | st1 = OpMovMemReg(rs_rX86_SP, current_dest_offset, temp, kMovA128FP); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2068 | } else if (dest_is_8b_aligned) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2069 | st1 = OpMovMemReg(rs_rX86_SP, current_dest_offset, temp, kMovLo128FP); |
| 2070 | st2 = OpMovMemReg(rs_rX86_SP, current_dest_offset + (bytes_to_move >> 1), |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2071 | temp, kMovHi128FP); |
| 2072 | } else { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2073 | st1 = OpMovMemReg(rs_rX86_SP, current_dest_offset, temp, kMovU128FP); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | // TODO If we could keep track of aliasing information for memory accesses that are wider |
| 2077 | // than 64-bit, we wouldn't need to set up a barrier. |
| 2078 | if (ld1 != nullptr) { |
| 2079 | if (ld2 != nullptr) { |
| 2080 | // For 64-bit load we can actually set up the aliasing information. |
| 2081 | AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true); |
| 2082 | AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true, true); |
| 2083 | } else { |
| 2084 | // Set barrier for 128-bit load. |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2085 | ld1->u.m.def_mask = &kEncodeAll; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | if (st1 != nullptr) { |
| 2089 | if (st2 != nullptr) { |
| 2090 | // For 64-bit store we can actually set up the aliasing information. |
| 2091 | AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true); |
| 2092 | AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false, true); |
| 2093 | } else { |
| 2094 | // Set barrier for 128-bit store. |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2095 | st1->u.m.def_mask = &kEncodeAll; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2096 | } |
| 2097 | } |
| 2098 | |
| 2099 | // Free the temporary used for the data movement. |
| 2100 | FreeTemp(temp); |
| 2101 | } else { |
| 2102 | // Moving 32-bits via general purpose register. |
| 2103 | bytes_to_move = sizeof(uint32_t); |
| 2104 | |
| 2105 | // Instead of allocating a new temp, simply reuse one of the registers being used |
| 2106 | // for argument passing. |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2107 | RegStorage temp = TargetReg(kArg3, false); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2108 | |
| 2109 | // Now load the argument VR and store to the outs. |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2110 | Load32Disp(rs_rX86_SP, current_src_offset, temp); |
| 2111 | Store32Disp(rs_rX86_SP, current_dest_offset, temp); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | current_src_offset += bytes_to_move; |
| 2115 | current_dest_offset += bytes_to_move; |
| 2116 | regs_left_to_pass_via_stack -= (bytes_to_move >> 2); |
| 2117 | } |
| 2118 | DCHECK_EQ(regs_left_to_pass_via_stack, 0); |
| 2119 | } |
| 2120 | |
| 2121 | // Now handle rest not registers if they are |
| 2122 | if (in_to_reg_storage_mapping.IsThereStackMapped()) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2123 | RegStorage regSingle = TargetReg(kArg2, false); |
| 2124 | RegStorage regWide = TargetReg(kArg3, true); |
Chao-ying Fu | b6564c1 | 2014-06-24 13:24:36 -0700 | [diff] [blame] | 2125 | for (int i = start_index; |
| 2126 | i < last_mapped_in + size_of_the_last_mapped + regs_left_to_pass_via_stack; i++) { |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2127 | RegLocation rl_arg = info->args[i]; |
| 2128 | rl_arg = UpdateRawLoc(rl_arg); |
| 2129 | RegStorage reg = in_to_reg_storage_mapping.Get(i); |
| 2130 | if (!reg.Valid()) { |
| 2131 | int out_offset = StackVisitor::GetOutVROffset(i, cu_->instruction_set); |
| 2132 | |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2133 | { |
| 2134 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
| 2135 | if (rl_arg.wide) { |
| 2136 | if (rl_arg.location == kLocPhysReg) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2137 | StoreBaseDisp(rs_rX86_SP, out_offset, rl_arg.reg, k64, kNotVolatile); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2138 | } else { |
| 2139 | LoadValueDirectWideFixed(rl_arg, regWide); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2140 | StoreBaseDisp(rs_rX86_SP, out_offset, regWide, k64, kNotVolatile); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2141 | } |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2142 | } else { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2143 | if (rl_arg.location == kLocPhysReg) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2144 | StoreBaseDisp(rs_rX86_SP, out_offset, rl_arg.reg, k32, kNotVolatile); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2145 | } else { |
| 2146 | LoadValueDirectFixed(rl_arg, regSingle); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2147 | StoreBaseDisp(rs_rX86_SP, out_offset, regSingle, k32, kNotVolatile); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 2148 | } |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2149 | } |
| 2150 | } |
| 2151 | call_state = next_call_insn(cu_, info, call_state, target_method, |
| 2152 | vtable_idx, direct_code, direct_method, type); |
| 2153 | } |
Chao-ying Fu | b6564c1 | 2014-06-24 13:24:36 -0700 | [diff] [blame] | 2154 | if (rl_arg.wide) { |
| 2155 | i++; |
| 2156 | } |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2157 | } |
| 2158 | } |
| 2159 | |
| 2160 | // Finish with mapped registers |
| 2161 | for (int i = start_index; i <= last_mapped_in; i++) { |
| 2162 | RegLocation rl_arg = info->args[i]; |
| 2163 | rl_arg = UpdateRawLoc(rl_arg); |
| 2164 | RegStorage reg = in_to_reg_storage_mapping.Get(i); |
| 2165 | if (reg.Valid()) { |
| 2166 | if (rl_arg.wide) { |
| 2167 | LoadValueDirectWideFixed(rl_arg, reg); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2168 | } else { |
| 2169 | LoadValueDirectFixed(rl_arg, reg); |
| 2170 | } |
| 2171 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 2172 | direct_code, direct_method, type); |
| 2173 | } |
Chao-ying Fu | b6564c1 | 2014-06-24 13:24:36 -0700 | [diff] [blame] | 2174 | if (rl_arg.wide) { |
| 2175 | i++; |
| 2176 | } |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 2180 | direct_code, direct_method, type); |
| 2181 | if (pcrLabel) { |
Andreas Gampe | 5655e84 | 2014-06-17 16:36:07 -0700 | [diff] [blame] | 2182 | if (cu_->compiler_driver->GetCompilerOptions().GetExplicitNullChecks()) { |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2183 | *pcrLabel = GenExplicitNullCheck(TargetRefReg(kArg1), info->opt_flags); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2184 | } else { |
| 2185 | *pcrLabel = nullptr; |
| 2186 | // In lieu of generating a check for kArg1 being null, we need to |
| 2187 | // perform a load when doing implicit checks. |
| 2188 | RegStorage tmp = AllocTemp(); |
Chao-ying Fu | a77ee51 | 2014-07-01 17:43:41 -0700 | [diff] [blame] | 2189 | Load32Disp(TargetRefReg(kArg1), 0, tmp); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 2190 | MarkPossibleNullPointerException(info->opt_flags); |
| 2191 | FreeTemp(tmp); |
| 2192 | } |
| 2193 | } |
| 2194 | return call_state; |
| 2195 | } |
| 2196 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 2197 | } // namespace art |