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