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 | |
| 17 | #include "dex/compiler_ir.h" |
Vladimir Marko | 5c96e6b | 2013-11-14 15:34:17 +0000 | [diff] [blame] | 18 | #include "dex/frontend.h" |
| 19 | #include "dex/quick/dex_file_method_inliner.h" |
| 20 | #include "dex/quick/dex_file_to_method_inliner_map.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 21 | #include "dex_file-inl.h" |
Ian Rogers | 166db04 | 2013-07-26 12:05:57 -0700 | [diff] [blame] | 22 | #include "entrypoints/quick/quick_entrypoints.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | #include "invoke_type.h" |
| 24 | #include "mirror/array.h" |
| 25 | #include "mirror/string.h" |
| 26 | #include "mir_to_lir-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 27 | #include "x86/codegen_x86.h" |
| 28 | |
| 29 | namespace art { |
| 30 | |
| 31 | /* |
| 32 | * This source files contains "gen" codegen routines that should |
| 33 | * be applicable to most targets. Only mid-level support utilities |
| 34 | * and "op" calls may be used here. |
| 35 | */ |
| 36 | |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 37 | void Mir2Lir::AddIntrinsicLaunchpad(CallInfo* info, LIR* branch, LIR* resume) { |
| 38 | class IntrinsicLaunchpadPath : public Mir2Lir::LIRSlowPath { |
| 39 | public: |
| 40 | IntrinsicLaunchpadPath(Mir2Lir* m2l, CallInfo* info, LIR* branch, LIR* resume = nullptr) |
| 41 | : LIRSlowPath(m2l, info->offset, branch, resume), info_(info) { |
| 42 | } |
| 43 | |
| 44 | void Compile() { |
| 45 | m2l_->ResetRegPool(); |
| 46 | m2l_->ResetDefTracking(); |
| 47 | LIR* label = GenerateTargetLabel(); |
| 48 | label->opcode = kPseudoIntrinsicRetry; |
| 49 | // NOTE: GenInvokeNoInline() handles MarkSafepointPC. |
| 50 | m2l_->GenInvokeNoInline(info_); |
| 51 | if (cont_ != nullptr) { |
| 52 | m2l_->OpUnconditionalBranch(cont_); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | private: |
| 57 | CallInfo* const info_; |
| 58 | }; |
| 59 | |
| 60 | AddSlowPath(new (arena_) IntrinsicLaunchpadPath(this, info, branch, resume)); |
| 61 | } |
| 62 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 63 | /* |
| 64 | * To save scheduling time, helper calls are broken into two parts: generation of |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 65 | * the helper target address, and the actual call to the helper. Because x86 |
| 66 | * has a memory call operation, part 1 is a NOP for x86. For other targets, |
| 67 | * load arguments between the two parts. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 68 | */ |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 69 | RegStorage Mir2Lir::CallHelperSetup(ThreadOffset<4> helper_offset) { |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 70 | return (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) ? RegStorage::InvalidReg() : LoadHelper(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* NOTE: if r_tgt is a temp, it will be freed following use */ |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 74 | LIR* Mir2Lir::CallHelper(RegStorage r_tgt, ThreadOffset<4> helper_offset, bool safepoint_pc, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 75 | bool use_link) { |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 76 | LIR* call_inst; |
Brian Carlstrom | 60d7a65 | 2014-03-13 18:10:08 -0700 | [diff] [blame] | 77 | OpKind op = use_link ? kOpBlx : kOpBx; |
Dave Allison | d6ed642 | 2014-04-09 23:36:15 +0000 | [diff] [blame] | 78 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
| 79 | call_inst = OpThreadMem(op, helper_offset); |
| 80 | } else { |
| 81 | call_inst = OpReg(op, r_tgt); |
| 82 | FreeTemp(r_tgt); |
| 83 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 84 | if (safepoint_pc) { |
| 85 | MarkSafepointPC(call_inst); |
| 86 | } |
| 87 | return call_inst; |
| 88 | } |
| 89 | |
Mingyao Yang | 4289456 | 2014-04-07 12:42:16 -0700 | [diff] [blame] | 90 | void Mir2Lir::CallRuntimeHelper(ThreadOffset<4> helper_offset, bool safepoint_pc) { |
| 91 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 92 | ClobberCallerSave(); |
| 93 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 94 | } |
| 95 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 96 | void Mir2Lir::CallRuntimeHelperImm(ThreadOffset<4> helper_offset, int arg0, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 97 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 98 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 99 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 100 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 101 | } |
| 102 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 103 | void Mir2Lir::CallRuntimeHelperReg(ThreadOffset<4> helper_offset, RegStorage arg0, |
| 104 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 105 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 106 | OpRegCopy(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 107 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 108 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 109 | } |
| 110 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 111 | void Mir2Lir::CallRuntimeHelperRegLocation(ThreadOffset<4> helper_offset, RegLocation arg0, |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 112 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 113 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 114 | if (arg0.wide == 0) { |
| 115 | LoadValueDirectFixed(arg0, TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 116 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 117 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg0), TargetReg(kArg1)); |
| 118 | LoadValueDirectWideFixed(arg0, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 119 | } |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 120 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 121 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 122 | } |
| 123 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 124 | void Mir2Lir::CallRuntimeHelperImmImm(ThreadOffset<4> helper_offset, int arg0, int arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 125 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 126 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 127 | LoadConstant(TargetReg(kArg0), arg0); |
| 128 | LoadConstant(TargetReg(kArg1), arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 129 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 130 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 131 | } |
| 132 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 133 | void Mir2Lir::CallRuntimeHelperImmRegLocation(ThreadOffset<4> helper_offset, int arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 134 | RegLocation arg1, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 135 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 136 | if (arg1.wide == 0) { |
| 137 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 138 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 139 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg1), TargetReg(kArg2)); |
| 140 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 141 | } |
| 142 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 143 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 144 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 145 | } |
| 146 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 147 | void Mir2Lir::CallRuntimeHelperRegLocationImm(ThreadOffset<4> helper_offset, RegLocation arg0, |
| 148 | int arg1, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 149 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 150 | LoadValueDirectFixed(arg0, TargetReg(kArg0)); |
| 151 | LoadConstant(TargetReg(kArg1), arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 152 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 153 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 154 | } |
| 155 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 156 | void Mir2Lir::CallRuntimeHelperImmReg(ThreadOffset<4> helper_offset, int arg0, RegStorage arg1, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 157 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 158 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 159 | OpRegCopy(TargetReg(kArg1), arg1); |
| 160 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 161 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 162 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 163 | } |
| 164 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 165 | void Mir2Lir::CallRuntimeHelperRegImm(ThreadOffset<4> helper_offset, RegStorage arg0, int arg1, |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 166 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 167 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 168 | OpRegCopy(TargetReg(kArg0), arg0); |
| 169 | LoadConstant(TargetReg(kArg1), arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 170 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 171 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 172 | } |
| 173 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 174 | void Mir2Lir::CallRuntimeHelperImmMethod(ThreadOffset<4> helper_offset, int arg0, |
| 175 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 176 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 177 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 178 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 179 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 180 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 181 | } |
| 182 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 183 | void Mir2Lir::CallRuntimeHelperRegMethod(ThreadOffset<4> helper_offset, RegStorage arg0, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 184 | bool safepoint_pc) { |
| 185 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 186 | DCHECK_NE(TargetReg(kArg1).GetReg(), arg0.GetReg()); |
Hiroshi Yamauchi | be1ca55 | 2014-01-15 11:46:48 -0800 | [diff] [blame] | 187 | if (TargetReg(kArg0) != arg0) { |
| 188 | OpRegCopy(TargetReg(kArg0), arg0); |
| 189 | } |
| 190 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 191 | ClobberCallerSave(); |
| 192 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 193 | } |
| 194 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 195 | void Mir2Lir::CallRuntimeHelperRegMethodRegLocation(ThreadOffset<4> helper_offset, RegStorage arg0, |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 196 | RegLocation arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 197 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
| 198 | DCHECK_NE(TargetReg(kArg1).GetReg(), arg0.GetReg()); |
Hiroshi Yamauchi | bb8f0ab | 2014-01-27 16:50:29 -0800 | [diff] [blame] | 199 | if (TargetReg(kArg0) != arg0) { |
| 200 | OpRegCopy(TargetReg(kArg0), arg0); |
| 201 | } |
| 202 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 203 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
| 204 | ClobberCallerSave(); |
| 205 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 206 | } |
| 207 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 208 | void Mir2Lir::CallRuntimeHelperRegLocationRegLocation(ThreadOffset<4> helper_offset, |
| 209 | RegLocation arg0, RegLocation arg1, |
| 210 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 211 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 212 | if (arg0.wide == 0) { |
| 213 | LoadValueDirectFixed(arg0, arg0.fp ? TargetReg(kFArg0) : TargetReg(kArg0)); |
| 214 | if (arg1.wide == 0) { |
| 215 | if (cu_->instruction_set == kMips) { |
| 216 | LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg1)); |
| 217 | } else { |
| 218 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 219 | } |
| 220 | } else { |
| 221 | if (cu_->instruction_set == kMips) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 222 | RegStorage r_tmp; |
| 223 | if (arg1.fp) { |
| 224 | r_tmp = RegStorage::MakeRegPair(TargetReg(kFArg2), TargetReg(kFArg3)); |
| 225 | } else { |
| 226 | r_tmp = RegStorage::MakeRegPair(TargetReg(kArg1), TargetReg(kArg2)); |
| 227 | } |
| 228 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 229 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 230 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg1), TargetReg(kArg2)); |
| 231 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 232 | } |
| 233 | } |
| 234 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 235 | RegStorage r_tmp; |
| 236 | if (arg0.fp) { |
| 237 | r_tmp = RegStorage::MakeRegPair(TargetReg(kFArg0), TargetReg(kFArg1)); |
| 238 | } else { |
| 239 | r_tmp = RegStorage::MakeRegPair(TargetReg(kArg0), TargetReg(kArg1)); |
| 240 | } |
| 241 | LoadValueDirectWideFixed(arg0, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 242 | if (arg1.wide == 0) { |
| 243 | LoadValueDirectFixed(arg1, arg1.fp ? TargetReg(kFArg2) : TargetReg(kArg2)); |
| 244 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 245 | RegStorage r_tmp; |
| 246 | if (arg1.fp) { |
| 247 | r_tmp = RegStorage::MakeRegPair(TargetReg(kFArg2), TargetReg(kFArg3)); |
| 248 | } else { |
| 249 | r_tmp = RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3)); |
| 250 | } |
| 251 | LoadValueDirectWideFixed(arg1, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 252 | } |
| 253 | } |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 254 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 255 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 256 | } |
| 257 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 258 | void Mir2Lir::CallRuntimeHelperRegReg(ThreadOffset<4> helper_offset, RegStorage arg0, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 259 | RegStorage arg1, bool safepoint_pc) { |
| 260 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7fff544 | 2014-04-17 23:11:17 -0700 | [diff] [blame] | 261 | DCHECK_NE(TargetReg(kArg0).GetReg(), arg1.GetReg()); // check copy into arg0 won't clobber arg1 |
| 262 | OpRegCopy(TargetReg(kArg0), arg0); |
| 263 | OpRegCopy(TargetReg(kArg1), arg1); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 264 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 265 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 266 | } |
| 267 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 268 | void Mir2Lir::CallRuntimeHelperRegRegImm(ThreadOffset<4> helper_offset, RegStorage arg0, |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 269 | RegStorage arg1, int arg2, bool safepoint_pc) { |
| 270 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7fff544 | 2014-04-17 23:11:17 -0700 | [diff] [blame] | 271 | DCHECK_NE(TargetReg(kArg0).GetReg(), arg1.GetReg()); // check copy into arg0 won't clobber arg1 |
| 272 | OpRegCopy(TargetReg(kArg0), arg0); |
| 273 | OpRegCopy(TargetReg(kArg1), arg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 274 | LoadConstant(TargetReg(kArg2), arg2); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 275 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 276 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 277 | } |
| 278 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 279 | void Mir2Lir::CallRuntimeHelperImmMethodRegLocation(ThreadOffset<4> helper_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 280 | int arg0, RegLocation arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 281 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 282 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
| 283 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 284 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 285 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 286 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 287 | } |
| 288 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 289 | void Mir2Lir::CallRuntimeHelperImmMethodImm(ThreadOffset<4> helper_offset, int arg0, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 290 | int arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 291 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 292 | LoadCurrMethodDirect(TargetReg(kArg1)); |
| 293 | LoadConstant(TargetReg(kArg2), arg2); |
| 294 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 295 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 296 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 297 | } |
| 298 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 299 | void Mir2Lir::CallRuntimeHelperImmRegLocationRegLocation(ThreadOffset<4> helper_offset, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 300 | int arg0, RegLocation arg1, |
| 301 | RegLocation arg2, bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 302 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 303 | DCHECK_EQ(arg1.wide, 0U); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 304 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 305 | if (arg2.wide == 0) { |
| 306 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
| 307 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 308 | RegStorage r_tmp = RegStorage::MakeRegPair(TargetReg(kArg2), TargetReg(kArg3)); |
| 309 | LoadValueDirectWideFixed(arg2, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 310 | } |
| 311 | LoadConstant(TargetReg(kArg0), arg0); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 312 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 313 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 314 | } |
| 315 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 316 | void Mir2Lir::CallRuntimeHelperRegLocationRegLocationRegLocation(ThreadOffset<4> helper_offset, |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 317 | RegLocation arg0, RegLocation arg1, |
| 318 | RegLocation arg2, |
| 319 | bool safepoint_pc) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 320 | RegStorage r_tgt = CallHelperSetup(helper_offset); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 321 | DCHECK_EQ(arg0.wide, 0U); |
| 322 | LoadValueDirectFixed(arg0, TargetReg(kArg0)); |
| 323 | DCHECK_EQ(arg1.wide, 0U); |
| 324 | LoadValueDirectFixed(arg1, TargetReg(kArg1)); |
| 325 | DCHECK_EQ(arg1.wide, 0U); |
| 326 | LoadValueDirectFixed(arg2, TargetReg(kArg2)); |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 327 | ClobberCallerSave(); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 328 | CallHelper(r_tgt, helper_offset, safepoint_pc); |
| 329 | } |
| 330 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 331 | /* |
| 332 | * If there are any ins passed in registers that have not been promoted |
| 333 | * to a callee-save register, flush them to the frame. Perform intial |
| 334 | * assignment of promoted arguments. |
| 335 | * |
| 336 | * ArgLocs is an array of location records describing the incoming arguments |
| 337 | * with one location record per word of argument. |
| 338 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 339 | void Mir2Lir::FlushIns(RegLocation* ArgLocs, RegLocation rl_method) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 340 | /* |
| 341 | * Dummy up a RegLocation for the incoming Method* |
| 342 | * It will attempt to keep kArg0 live (or copy it to home location |
| 343 | * if promoted). |
| 344 | */ |
| 345 | RegLocation rl_src = rl_method; |
| 346 | rl_src.location = kLocPhysReg; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 347 | rl_src.reg = TargetReg(kArg0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 348 | rl_src.home = false; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 349 | MarkLive(rl_src.reg, rl_src.s_reg_low); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 350 | if (rl_method.wide) { |
| 351 | StoreValueWide(rl_method, rl_src); |
| 352 | } else { |
| 353 | StoreValue(rl_method, rl_src); |
| 354 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 355 | // If Method* has been promoted, explicitly flush |
| 356 | if (rl_method.location == kLocPhysReg) { |
| 357 | StoreWordDisp(TargetReg(kSp), 0, TargetReg(kArg0)); |
| 358 | } |
| 359 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 360 | if (cu_->num_ins == 0) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 361 | return; |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 362 | } |
| 363 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 364 | int start_vreg = cu_->num_dalvik_registers - cu_->num_ins; |
| 365 | /* |
| 366 | * Copy incoming arguments to their proper home locations. |
| 367 | * NOTE: an older version of dx had an issue in which |
| 368 | * it would reuse static method argument registers. |
| 369 | * This could result in the same Dalvik virtual register |
| 370 | * being promoted to both core and fp regs. To account for this, |
| 371 | * we only copy to the corresponding promoted physical register |
| 372 | * if it matches the type of the SSA name for the incoming |
| 373 | * argument. It is also possible that long and double arguments |
| 374 | * end up half-promoted. In those cases, we must flush the promoted |
| 375 | * half to memory as well. |
| 376 | */ |
| 377 | for (int i = 0; i < cu_->num_ins; i++) { |
| 378 | PromotionMap* v_map = &promotion_map_[start_vreg + i]; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 379 | RegStorage reg = GetArgMappingToPhysicalReg(i); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 380 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 381 | if (reg.Valid()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 382 | // If arriving in register |
| 383 | bool need_flush = true; |
| 384 | RegLocation* t_loc = &ArgLocs[i]; |
| 385 | if ((v_map->core_location == kLocPhysReg) && !t_loc->fp) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 386 | OpRegCopy(RegStorage::Solo32(v_map->core_reg), reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 387 | need_flush = false; |
| 388 | } else if ((v_map->fp_location == kLocPhysReg) && t_loc->fp) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 389 | OpRegCopy(RegStorage::Solo32(v_map->FpReg), reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 390 | need_flush = false; |
| 391 | } else { |
| 392 | need_flush = true; |
| 393 | } |
| 394 | |
buzbee | d0a03b8 | 2013-09-14 08:21:05 -0700 | [diff] [blame] | 395 | // For wide args, force flush if not fully promoted |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 396 | if (t_loc->wide) { |
| 397 | PromotionMap* p_map = v_map + (t_loc->high_word ? -1 : +1); |
buzbee | d0a03b8 | 2013-09-14 08:21:05 -0700 | [diff] [blame] | 398 | // Is only half promoted? |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 399 | need_flush |= (p_map->core_location != v_map->core_location) || |
| 400 | (p_map->fp_location != v_map->fp_location); |
buzbee | d0a03b8 | 2013-09-14 08:21:05 -0700 | [diff] [blame] | 401 | if ((cu_->instruction_set == kThumb2) && t_loc->fp && !need_flush) { |
| 402 | /* |
| 403 | * In Arm, a double is represented as a pair of consecutive single float |
| 404 | * registers starting at an even number. It's possible that both Dalvik vRegs |
| 405 | * representing the incoming double were independently promoted as singles - but |
| 406 | * not in a form usable as a double. If so, we need to flush - even though the |
| 407 | * incoming arg appears fully in register. At this point in the code, both |
| 408 | * halves of the double are promoted. Make sure they are in a usable form. |
| 409 | */ |
| 410 | int lowreg_index = start_vreg + i + (t_loc->high_word ? -1 : 0); |
| 411 | int low_reg = promotion_map_[lowreg_index].FpReg; |
| 412 | int high_reg = promotion_map_[lowreg_index + 1].FpReg; |
| 413 | if (((low_reg & 0x1) != 0) || (high_reg != (low_reg + 1))) { |
| 414 | need_flush = true; |
| 415 | } |
| 416 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 417 | } |
| 418 | if (need_flush) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 419 | Store32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 420 | } |
| 421 | } else { |
| 422 | // If arriving in frame & promoted |
| 423 | if (v_map->core_location == kLocPhysReg) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 424 | Load32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->core_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 425 | } |
| 426 | if (v_map->fp_location == kLocPhysReg) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 427 | Load32Disp(TargetReg(kSp), SRegOffset(start_vreg + i), RegStorage::Solo32(v_map->FpReg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 428 | } |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | /* |
| 434 | * Bit of a hack here - in the absence of a real scheduling pass, |
| 435 | * emit the next instruction in static & direct invoke sequences. |
| 436 | */ |
| 437 | static int NextSDCallInsn(CompilationUnit* cu, CallInfo* info, |
| 438 | int state, const MethodReference& target_method, |
| 439 | uint32_t unused, |
| 440 | uintptr_t direct_code, uintptr_t direct_method, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 441 | InvokeType type) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 442 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 443 | if (direct_code != 0 && direct_method != 0) { |
| 444 | switch (state) { |
| 445 | case 0: // Get the current Method* [sets kArg0] |
| 446 | if (direct_code != static_cast<unsigned int>(-1)) { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 447 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Ian Rogers | 83883d7 | 2013-10-21 21:07:24 -0700 | [diff] [blame] | 448 | cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code); |
| 449 | } |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 450 | } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 451 | cg->LoadCodeAddress(target_method, type, kInvokeTgt); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 452 | } |
| 453 | if (direct_method != static_cast<unsigned int>(-1)) { |
| 454 | cg->LoadConstant(cg->TargetReg(kArg0), direct_method); |
| 455 | } else { |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 456 | cg->LoadMethodAddress(target_method, type, kArg0); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 457 | } |
| 458 | break; |
| 459 | default: |
| 460 | return -1; |
| 461 | } |
| 462 | } else { |
| 463 | switch (state) { |
| 464 | case 0: // Get the current Method* [sets kArg0] |
| 465 | // TUNING: we can save a reg copy if Method* has been promoted. |
| 466 | cg->LoadCurrMethodDirect(cg->TargetReg(kArg0)); |
| 467 | break; |
| 468 | case 1: // Get method->dex_cache_resolved_methods_ |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 469 | cg->LoadRefDisp(cg->TargetReg(kArg0), |
| 470 | mirror::ArtMethod::DexCacheResolvedMethodsOffset().Int32Value(), |
| 471 | cg->TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 472 | // Set up direct code if known. |
| 473 | if (direct_code != 0) { |
| 474 | if (direct_code != static_cast<unsigned int>(-1)) { |
| 475 | cg->LoadConstant(cg->TargetReg(kInvokeTgt), direct_code); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 476 | } else if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Ian Rogers | 83883d7 | 2013-10-21 21:07:24 -0700 | [diff] [blame] | 477 | CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds()); |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 478 | cg->LoadCodeAddress(target_method, type, kInvokeTgt); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | break; |
| 482 | case 2: // Grab target method* |
| 483 | CHECK_EQ(cu->dex_file, target_method.dex_file); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 484 | cg->LoadRefDisp(cg->TargetReg(kArg0), |
| 485 | mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value() + |
| 486 | (target_method.dex_method_index * 4), cg->TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 487 | break; |
| 488 | case 3: // Grab the code from the method* |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 489 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 490 | if (direct_code == 0) { |
| 491 | cg->LoadWordDisp(cg->TargetReg(kArg0), |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 492 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 493 | cg->TargetReg(kInvokeTgt)); |
| 494 | } |
| 495 | break; |
| 496 | } |
| 497 | // Intentional fallthrough for x86 |
| 498 | default: |
| 499 | return -1; |
| 500 | } |
| 501 | } |
| 502 | return state + 1; |
| 503 | } |
| 504 | |
| 505 | /* |
| 506 | * Bit of a hack here - in the absence of a real scheduling pass, |
| 507 | * emit the next instruction in a virtual invoke sequence. |
| 508 | * We can use kLr as a temp prior to target address loading |
| 509 | * Note also that we'll load the first argument ("this") into |
| 510 | * kArg1 here rather than the standard LoadArgRegs. |
| 511 | */ |
| 512 | static int NextVCallInsn(CompilationUnit* cu, CallInfo* info, |
| 513 | int state, const MethodReference& target_method, |
| 514 | uint32_t method_idx, uintptr_t unused, uintptr_t unused2, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 515 | InvokeType unused3) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 516 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
| 517 | /* |
| 518 | * This is the fast path in which the target virtual method is |
| 519 | * fully resolved at compile time. |
| 520 | */ |
| 521 | switch (state) { |
| 522 | case 0: { // Get "this" [set kArg1] |
| 523 | RegLocation rl_arg = info->args[0]; |
| 524 | cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1)); |
| 525 | break; |
| 526 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 527 | case 1: // Is "this" null? [use kArg1] |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 528 | cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 529 | // get this->klass_ [use kArg1, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 530 | cg->LoadRefDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), |
| 531 | cg->TargetReg(kInvokeTgt)); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 532 | cg->MarkPossibleNullPointerException(info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 533 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 534 | case 2: // Get this->klass_->vtable [usr kInvokeTgt, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 535 | cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), mirror::Class::VTableOffset().Int32Value(), |
| 536 | cg->TargetReg(kInvokeTgt)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 537 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 538 | case 3: // Get target method [use kInvokeTgt, set kArg0] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 539 | cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), (method_idx * 4) + |
| 540 | mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(), |
| 541 | cg->TargetReg(kArg0)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 542 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 543 | case 4: // Get the compiled code address [uses kArg0, sets kInvokeTgt] |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 544 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 545 | cg->LoadWordDisp(cg->TargetReg(kArg0), |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 546 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 547 | cg->TargetReg(kInvokeTgt)); |
| 548 | break; |
| 549 | } |
| 550 | // Intentional fallthrough for X86 |
| 551 | default: |
| 552 | return -1; |
| 553 | } |
| 554 | return state + 1; |
| 555 | } |
| 556 | |
| 557 | /* |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 558 | * Emit the next instruction in an invoke interface sequence. This will do a lookup in the |
| 559 | * class's IMT, calling either the actual method or art_quick_imt_conflict_trampoline if |
| 560 | * more than one interface method map to the same index. Note also that we'll load the first |
| 561 | * argument ("this") into kArg1 here rather than the standard LoadArgRegs. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 562 | */ |
| 563 | static int NextInterfaceCallInsn(CompilationUnit* cu, CallInfo* info, int state, |
| 564 | const MethodReference& target_method, |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 565 | uint32_t method_idx, uintptr_t unused, |
| 566 | uintptr_t direct_method, InvokeType unused2) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 567 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 568 | |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 569 | switch (state) { |
| 570 | case 0: // Set target method index in case of conflict [set kHiddenArg, kHiddenFpArg (x86)] |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 571 | CHECK_LT(target_method.dex_method_index, target_method.dex_file->NumMethodIds()); |
| 572 | cg->LoadConstant(cg->TargetReg(kHiddenArg), target_method.dex_method_index); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 573 | if (cu->instruction_set == kX86 || cu->instruction_set == kX86_64) { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 574 | cg->OpRegCopy(cg->TargetReg(kHiddenFpArg), cg->TargetReg(kHiddenArg)); |
| 575 | } |
| 576 | break; |
| 577 | case 1: { // Get "this" [set kArg1] |
| 578 | RegLocation rl_arg = info->args[0]; |
| 579 | cg->LoadValueDirectFixed(rl_arg, cg->TargetReg(kArg1)); |
| 580 | break; |
| 581 | } |
| 582 | case 2: // Is "this" null? [use kArg1] |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 583 | cg->GenNullCheck(cg->TargetReg(kArg1), info->opt_flags); |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 584 | // Get this->klass_ [use kArg1, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 585 | cg->LoadRefDisp(cg->TargetReg(kArg1), mirror::Object::ClassOffset().Int32Value(), |
| 586 | cg->TargetReg(kInvokeTgt)); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 587 | cg->MarkPossibleNullPointerException(info->opt_flags); |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 588 | break; |
| 589 | case 3: // Get this->klass_->imtable [use kInvokeTgt, set kInvokeTgt] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 590 | // NOTE: native pointer. |
| 591 | cg->LoadRefDisp(cg->TargetReg(kInvokeTgt), mirror::Class::ImTableOffset().Int32Value(), |
| 592 | cg->TargetReg(kInvokeTgt)); |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 593 | break; |
| 594 | case 4: // Get target method [use kInvokeTgt, set kArg0] |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 595 | // NOTE: native pointer. |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 596 | cg->LoadWordDisp(cg->TargetReg(kInvokeTgt), ((method_idx % ClassLinker::kImtSize) * 4) + |
| 597 | mirror::Array::DataOffset(sizeof(mirror::Object*)).Int32Value(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 598 | cg->TargetReg(kArg0)); |
| 599 | break; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 600 | case 5: // Get the compiled code address [use kArg0, set kInvokeTgt] |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 601 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 602 | cg->LoadWordDisp(cg->TargetReg(kArg0), |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 603 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value(), |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 604 | cg->TargetReg(kInvokeTgt)); |
| 605 | break; |
| 606 | } |
| 607 | // Intentional fallthrough for X86 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 608 | default: |
| 609 | return -1; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 610 | } |
| 611 | return state + 1; |
| 612 | } |
| 613 | |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 614 | static int NextInvokeInsnSP(CompilationUnit* cu, CallInfo* info, ThreadOffset<4> trampoline, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 615 | int state, const MethodReference& target_method, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 616 | uint32_t method_idx) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 617 | Mir2Lir* cg = static_cast<Mir2Lir*>(cu->cg.get()); |
| 618 | /* |
| 619 | * This handles the case in which the base method is not fully |
| 620 | * resolved at compile time, we bail to a runtime helper. |
| 621 | */ |
| 622 | if (state == 0) { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 623 | if (cu->instruction_set != kX86 && cu->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 624 | // Load trampoline target |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 625 | cg->LoadWordDisp(cg->TargetReg(kSelf), trampoline.Int32Value(), cg->TargetReg(kInvokeTgt)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 626 | } |
| 627 | // Load kArg0 with method index |
| 628 | CHECK_EQ(cu->dex_file, target_method.dex_file); |
| 629 | cg->LoadConstant(cg->TargetReg(kArg0), target_method.dex_method_index); |
| 630 | return 1; |
| 631 | } |
| 632 | return -1; |
| 633 | } |
| 634 | |
| 635 | static int NextStaticCallInsnSP(CompilationUnit* cu, CallInfo* info, |
| 636 | int state, |
| 637 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 638 | uint32_t unused, uintptr_t unused2, |
| 639 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 640 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeStaticTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 641 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 642 | } |
| 643 | |
| 644 | static int NextDirectCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, |
| 645 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 646 | uint32_t unused, uintptr_t unused2, |
| 647 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 648 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeDirectTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 649 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 650 | } |
| 651 | |
| 652 | static int NextSuperCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, |
| 653 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 654 | uint32_t unused, uintptr_t unused2, |
| 655 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 656 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeSuperTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 657 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 658 | } |
| 659 | |
| 660 | static int NextVCallInsnSP(CompilationUnit* cu, CallInfo* info, int state, |
| 661 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 662 | uint32_t unused, uintptr_t unused2, |
| 663 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 664 | ThreadOffset<4> trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeVirtualTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 665 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 666 | } |
| 667 | |
| 668 | static int NextInterfaceCallInsnWithAccessCheck(CompilationUnit* cu, |
| 669 | CallInfo* info, int state, |
| 670 | const MethodReference& target_method, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 671 | uint32_t unused, uintptr_t unused2, |
| 672 | uintptr_t unused3, InvokeType unused4) { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 673 | ThreadOffset<4> trampoline = |
| 674 | QUICK_ENTRYPOINT_OFFSET(4, pInvokeInterfaceTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 675 | return NextInvokeInsnSP(cu, info, trampoline, state, target_method, 0); |
| 676 | } |
| 677 | |
| 678 | int Mir2Lir::LoadArgRegs(CallInfo* info, int call_state, |
| 679 | NextCallInsn next_call_insn, |
| 680 | const MethodReference& target_method, |
| 681 | uint32_t vtable_idx, uintptr_t direct_code, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 682 | uintptr_t direct_method, InvokeType type, bool skip_this) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 683 | int last_arg_reg = TargetReg(kArg3).GetReg(); |
| 684 | int next_reg = TargetReg(kArg1).GetReg(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 685 | int next_arg = 0; |
| 686 | if (skip_this) { |
| 687 | next_reg++; |
| 688 | next_arg++; |
| 689 | } |
| 690 | for (; (next_reg <= last_arg_reg) && (next_arg < info->num_arg_words); next_reg++) { |
| 691 | RegLocation rl_arg = info->args[next_arg++]; |
| 692 | rl_arg = UpdateRawLoc(rl_arg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 693 | if (rl_arg.wide && (next_reg <= TargetReg(kArg2).GetReg())) { |
| 694 | RegStorage r_tmp(RegStorage::k64BitPair, next_reg, next_reg + 1); |
| 695 | LoadValueDirectWideFixed(rl_arg, r_tmp); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 696 | next_reg++; |
| 697 | next_arg++; |
| 698 | } else { |
| 699 | if (rl_arg.wide) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 700 | rl_arg = NarrowRegLoc(rl_arg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 701 | rl_arg.is_const = false; |
| 702 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 703 | LoadValueDirectFixed(rl_arg, RegStorage::Solo32(next_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 704 | } |
| 705 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 706 | direct_code, direct_method, type); |
| 707 | } |
| 708 | return call_state; |
| 709 | } |
| 710 | |
| 711 | /* |
| 712 | * Load up to 5 arguments, the first three of which will be in |
| 713 | * kArg1 .. kArg3. On entry kArg0 contains the current method pointer, |
| 714 | * and as part of the load sequence, it must be replaced with |
| 715 | * the target method pointer. Note, this may also be called |
| 716 | * for "range" variants if the number of arguments is 5 or fewer. |
| 717 | */ |
| 718 | int Mir2Lir::GenDalvikArgsNoRange(CallInfo* info, |
| 719 | int call_state, LIR** pcrLabel, NextCallInsn next_call_insn, |
| 720 | const MethodReference& target_method, |
| 721 | uint32_t vtable_idx, uintptr_t direct_code, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 722 | uintptr_t direct_method, InvokeType type, bool skip_this) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 723 | RegLocation rl_arg; |
| 724 | |
| 725 | /* If no arguments, just return */ |
| 726 | if (info->num_arg_words == 0) |
| 727 | return call_state; |
| 728 | |
| 729 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 730 | direct_code, direct_method, type); |
| 731 | |
| 732 | DCHECK_LE(info->num_arg_words, 5); |
| 733 | if (info->num_arg_words > 3) { |
| 734 | int32_t next_use = 3; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 735 | // Detect special case of wide arg spanning arg3/arg4 |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 736 | RegLocation rl_use0 = info->args[0]; |
| 737 | RegLocation rl_use1 = info->args[1]; |
| 738 | RegLocation rl_use2 = info->args[2]; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 739 | if (((!rl_use0.wide && !rl_use1.wide) || rl_use0.wide) && rl_use2.wide) { |
| 740 | RegStorage reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 741 | // Wide spans, we need the 2nd half of uses[2]. |
| 742 | rl_arg = UpdateLocWide(rl_use2); |
| 743 | if (rl_arg.location == kLocPhysReg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 744 | reg = rl_arg.reg.GetHigh(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 745 | } else { |
| 746 | // kArg2 & rArg3 can safely be used here |
| 747 | reg = TargetReg(kArg3); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 748 | Load32Disp(TargetReg(kSp), SRegOffset(rl_arg.s_reg_low) + 4, reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 749 | call_state = next_call_insn(cu_, info, call_state, target_method, |
| 750 | vtable_idx, direct_code, direct_method, type); |
| 751 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 752 | Store32Disp(TargetReg(kSp), (next_use + 1) * 4, reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 753 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 754 | direct_code, direct_method, type); |
| 755 | next_use++; |
| 756 | } |
| 757 | // Loop through the rest |
| 758 | while (next_use < info->num_arg_words) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 759 | RegStorage low_reg; |
| 760 | RegStorage high_reg; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 761 | rl_arg = info->args[next_use]; |
| 762 | rl_arg = UpdateRawLoc(rl_arg); |
| 763 | if (rl_arg.location == kLocPhysReg) { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 764 | if (rl_arg.wide) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 765 | low_reg = rl_arg.reg.GetLow(); |
| 766 | high_reg = rl_arg.reg.GetHigh(); |
| 767 | } else { |
| 768 | low_reg = rl_arg.reg; |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 769 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 770 | } else { |
| 771 | low_reg = TargetReg(kArg2); |
| 772 | if (rl_arg.wide) { |
| 773 | high_reg = TargetReg(kArg3); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 774 | LoadValueDirectWideFixed(rl_arg, RegStorage::MakeRegPair(low_reg, high_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 775 | } else { |
| 776 | LoadValueDirectFixed(rl_arg, low_reg); |
| 777 | } |
| 778 | call_state = next_call_insn(cu_, info, call_state, target_method, |
| 779 | vtable_idx, direct_code, direct_method, type); |
| 780 | } |
| 781 | int outs_offset = (next_use + 1) * 4; |
| 782 | if (rl_arg.wide) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 783 | StoreBaseDispWide(TargetReg(kSp), outs_offset, RegStorage::MakeRegPair(low_reg, high_reg)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 784 | next_use += 2; |
| 785 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 786 | Store32Disp(TargetReg(kSp), outs_offset, low_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 787 | next_use++; |
| 788 | } |
| 789 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 790 | direct_code, direct_method, type); |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | call_state = LoadArgRegs(info, call_state, next_call_insn, |
| 795 | target_method, vtable_idx, direct_code, direct_method, |
| 796 | type, skip_this); |
| 797 | |
| 798 | if (pcrLabel) { |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 799 | if (Runtime::Current()->ExplicitNullChecks()) { |
| 800 | *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1), info->opt_flags); |
| 801 | } else { |
| 802 | *pcrLabel = nullptr; |
| 803 | // In lieu of generating a check for kArg1 being null, we need to |
| 804 | // perform a load when doing implicit checks. |
| 805 | RegStorage tmp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 806 | Load32Disp(TargetReg(kArg1), 0, tmp); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 807 | MarkPossibleNullPointerException(info->opt_flags); |
| 808 | FreeTemp(tmp); |
| 809 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 810 | } |
| 811 | return call_state; |
| 812 | } |
| 813 | |
| 814 | /* |
| 815 | * May have 0+ arguments (also used for jumbo). Note that |
| 816 | * source virtual registers may be in physical registers, so may |
| 817 | * need to be flushed to home location before copying. This |
| 818 | * applies to arg3 and above (see below). |
| 819 | * |
| 820 | * Two general strategies: |
| 821 | * If < 20 arguments |
| 822 | * Pass args 3-18 using vldm/vstm block copy |
| 823 | * Pass arg0, arg1 & arg2 in kArg1-kArg3 |
| 824 | * If 20+ arguments |
| 825 | * Pass args arg19+ using memcpy block copy |
| 826 | * Pass arg0, arg1 & arg2 in kArg1-kArg3 |
| 827 | * |
| 828 | */ |
| 829 | int Mir2Lir::GenDalvikArgsRange(CallInfo* info, int call_state, |
| 830 | LIR** pcrLabel, NextCallInsn next_call_insn, |
| 831 | const MethodReference& target_method, |
| 832 | uint32_t vtable_idx, uintptr_t direct_code, uintptr_t direct_method, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 833 | InvokeType type, bool skip_this) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 834 | // If we can treat it as non-range (Jumbo ops will use range form) |
| 835 | if (info->num_arg_words <= 5) |
| 836 | return GenDalvikArgsNoRange(info, call_state, pcrLabel, |
| 837 | next_call_insn, target_method, vtable_idx, |
| 838 | direct_code, direct_method, type, skip_this); |
| 839 | /* |
| 840 | * First load the non-register arguments. Both forms expect all |
| 841 | * of the source arguments to be in their home frame location, so |
| 842 | * scan the s_reg names and flush any that have been promoted to |
| 843 | * frame backing storage. |
| 844 | */ |
| 845 | // Scan the rest of the args - if in phys_reg flush to memory |
| 846 | for (int next_arg = 0; next_arg < info->num_arg_words;) { |
| 847 | RegLocation loc = info->args[next_arg]; |
| 848 | if (loc.wide) { |
| 849 | loc = UpdateLocWide(loc); |
| 850 | if ((next_arg >= 2) && (loc.location == kLocPhysReg)) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 851 | StoreBaseDispWide(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 852 | } |
| 853 | next_arg += 2; |
| 854 | } else { |
| 855 | loc = UpdateLoc(loc); |
| 856 | if ((next_arg >= 3) && (loc.location == kLocPhysReg)) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 857 | Store32Disp(TargetReg(kSp), SRegOffset(loc.s_reg_low), loc.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 858 | } |
| 859 | next_arg++; |
| 860 | } |
| 861 | } |
| 862 | |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 863 | // Logic below assumes that Method pointer is at offset zero from SP. |
| 864 | DCHECK_EQ(VRegOffset(static_cast<int>(kVRegMethodPtrBaseReg)), 0); |
| 865 | |
| 866 | // The first 3 arguments are passed via registers. |
| 867 | // TODO: For 64-bit, instead of hardcoding 4 for Method* size, we should either |
| 868 | // get size of uintptr_t or size of object reference according to model being used. |
| 869 | int outs_offset = 4 /* Method* */ + (3 * sizeof(uint32_t)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 870 | int start_offset = SRegOffset(info->args[3].s_reg_low); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 871 | int regs_left_to_pass_via_stack = info->num_arg_words - 3; |
| 872 | DCHECK_GT(regs_left_to_pass_via_stack, 0); |
| 873 | |
| 874 | if (cu_->instruction_set == kThumb2 && regs_left_to_pass_via_stack <= 16) { |
| 875 | // Use vldm/vstm pair using kArg3 as a temp |
| 876 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 877 | direct_code, direct_method, type); |
| 878 | OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), start_offset); |
| 879 | LIR* ld = OpVldm(TargetReg(kArg3), regs_left_to_pass_via_stack); |
| 880 | // TUNING: loosen barrier |
| 881 | ld->u.m.def_mask = ENCODE_ALL; |
| 882 | SetMemRefType(ld, true /* is_load */, kDalvikReg); |
| 883 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 884 | direct_code, direct_method, type); |
| 885 | OpRegRegImm(kOpAdd, TargetReg(kArg3), TargetReg(kSp), 4 /* Method* */ + (3 * 4)); |
| 886 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 887 | direct_code, direct_method, type); |
| 888 | LIR* st = OpVstm(TargetReg(kArg3), regs_left_to_pass_via_stack); |
| 889 | SetMemRefType(st, false /* is_load */, kDalvikReg); |
| 890 | st->u.m.def_mask = ENCODE_ALL; |
| 891 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 892 | direct_code, direct_method, type); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 893 | } else if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 894 | int current_src_offset = start_offset; |
| 895 | int current_dest_offset = outs_offset; |
| 896 | |
| 897 | while (regs_left_to_pass_via_stack > 0) { |
| 898 | // This is based on the knowledge that the stack itself is 16-byte aligned. |
| 899 | bool src_is_16b_aligned = (current_src_offset & 0xF) == 0; |
| 900 | bool dest_is_16b_aligned = (current_dest_offset & 0xF) == 0; |
| 901 | size_t bytes_to_move; |
| 902 | |
| 903 | /* |
| 904 | * The amount to move defaults to 32-bit. If there are 4 registers left to move, then do a |
| 905 | * a 128-bit move because we won't get the chance to try to aligned. If there are more than |
| 906 | * 4 registers left to move, consider doing a 128-bit only if either src or dest are aligned. |
| 907 | * We do this because we could potentially do a smaller move to align. |
| 908 | */ |
| 909 | if (regs_left_to_pass_via_stack == 4 || |
| 910 | (regs_left_to_pass_via_stack > 4 && (src_is_16b_aligned || dest_is_16b_aligned))) { |
| 911 | // Moving 128-bits via xmm register. |
| 912 | bytes_to_move = sizeof(uint32_t) * 4; |
| 913 | |
| 914 | // Allocate a free xmm temp. Since we are working through the calling sequence, |
| 915 | // we expect to have an xmm temporary available. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 916 | RegStorage temp = AllocTempDouble(); |
| 917 | CHECK_GT(temp.GetLowReg(), 0); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 918 | |
| 919 | LIR* ld1 = nullptr; |
| 920 | LIR* ld2 = nullptr; |
| 921 | LIR* st1 = nullptr; |
| 922 | LIR* st2 = nullptr; |
| 923 | |
| 924 | /* |
| 925 | * The logic is similar for both loads and stores. If we have 16-byte alignment, |
| 926 | * do an aligned move. If we have 8-byte alignment, then do the move in two |
| 927 | * parts. This approach prevents possible cache line splits. Finally, fall back |
| 928 | * to doing an unaligned move. In most cases we likely won't split the cache |
| 929 | * line but we cannot prove it and thus take a conservative approach. |
| 930 | */ |
| 931 | bool src_is_8b_aligned = (current_src_offset & 0x7) == 0; |
| 932 | bool dest_is_8b_aligned = (current_dest_offset & 0x7) == 0; |
| 933 | |
| 934 | if (src_is_16b_aligned) { |
| 935 | ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovA128FP); |
| 936 | } else if (src_is_8b_aligned) { |
| 937 | ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovLo128FP); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 938 | ld2 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset + (bytes_to_move >> 1), |
| 939 | kMovHi128FP); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 940 | } else { |
| 941 | ld1 = OpMovRegMem(temp, TargetReg(kSp), current_src_offset, kMovU128FP); |
| 942 | } |
| 943 | |
| 944 | if (dest_is_16b_aligned) { |
| 945 | st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovA128FP); |
| 946 | } else if (dest_is_8b_aligned) { |
| 947 | st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovLo128FP); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 948 | st2 = OpMovMemReg(TargetReg(kSp), current_dest_offset + (bytes_to_move >> 1), |
| 949 | temp, kMovHi128FP); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 950 | } else { |
| 951 | st1 = OpMovMemReg(TargetReg(kSp), current_dest_offset, temp, kMovU128FP); |
| 952 | } |
| 953 | |
| 954 | // TODO If we could keep track of aliasing information for memory accesses that are wider |
| 955 | // than 64-bit, we wouldn't need to set up a barrier. |
| 956 | if (ld1 != nullptr) { |
| 957 | if (ld2 != nullptr) { |
| 958 | // For 64-bit load we can actually set up the aliasing information. |
| 959 | AnnotateDalvikRegAccess(ld1, current_src_offset >> 2, true, true); |
| 960 | AnnotateDalvikRegAccess(ld2, (current_src_offset + (bytes_to_move >> 1)) >> 2, true, true); |
| 961 | } else { |
| 962 | // Set barrier for 128-bit load. |
| 963 | SetMemRefType(ld1, true /* is_load */, kDalvikReg); |
| 964 | ld1->u.m.def_mask = ENCODE_ALL; |
| 965 | } |
| 966 | } |
| 967 | if (st1 != nullptr) { |
| 968 | if (st2 != nullptr) { |
| 969 | // For 64-bit store we can actually set up the aliasing information. |
| 970 | AnnotateDalvikRegAccess(st1, current_dest_offset >> 2, false, true); |
| 971 | AnnotateDalvikRegAccess(st2, (current_dest_offset + (bytes_to_move >> 1)) >> 2, false, true); |
| 972 | } else { |
| 973 | // Set barrier for 128-bit store. |
| 974 | SetMemRefType(st1, false /* is_load */, kDalvikReg); |
| 975 | st1->u.m.def_mask = ENCODE_ALL; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | // Free the temporary used for the data movement. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 980 | // CLEANUP: temp is currently a bogus pair, elmiminate extra free when updated. |
| 981 | FreeTemp(temp.GetLow()); |
| 982 | FreeTemp(temp.GetHigh()); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 983 | } else { |
| 984 | // Moving 32-bits via general purpose register. |
| 985 | bytes_to_move = sizeof(uint32_t); |
| 986 | |
| 987 | // Instead of allocating a new temp, simply reuse one of the registers being used |
| 988 | // for argument passing. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 989 | RegStorage temp = TargetReg(kArg3); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 990 | |
| 991 | // Now load the argument VR and store to the outs. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 992 | Load32Disp(TargetReg(kSp), current_src_offset, temp); |
| 993 | Store32Disp(TargetReg(kSp), current_dest_offset, temp); |
Razvan A Lupusoru | 2c498d1 | 2014-01-29 16:02:57 -0800 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | current_src_offset += bytes_to_move; |
| 997 | current_dest_offset += bytes_to_move; |
| 998 | regs_left_to_pass_via_stack -= (bytes_to_move >> 2); |
| 999 | } |
| 1000 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1001 | // Generate memcpy |
| 1002 | OpRegRegImm(kOpAdd, TargetReg(kArg0), TargetReg(kSp), outs_offset); |
| 1003 | OpRegRegImm(kOpAdd, TargetReg(kArg1), TargetReg(kSp), start_offset); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1004 | CallRuntimeHelperRegRegImm(QUICK_ENTRYPOINT_OFFSET(4, pMemcpy), TargetReg(kArg0), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1005 | TargetReg(kArg1), (info->num_arg_words - 3) * 4, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | call_state = LoadArgRegs(info, call_state, next_call_insn, |
| 1009 | target_method, vtable_idx, direct_code, direct_method, |
| 1010 | type, skip_this); |
| 1011 | |
| 1012 | call_state = next_call_insn(cu_, info, call_state, target_method, vtable_idx, |
| 1013 | direct_code, direct_method, type); |
| 1014 | if (pcrLabel) { |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1015 | if (Runtime::Current()->ExplicitNullChecks()) { |
| 1016 | *pcrLabel = GenExplicitNullCheck(TargetReg(kArg1), info->opt_flags); |
| 1017 | } else { |
| 1018 | *pcrLabel = nullptr; |
| 1019 | // In lieu of generating a check for kArg1 being null, we need to |
| 1020 | // perform a load when doing implicit checks. |
| 1021 | RegStorage tmp = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1022 | Load32Disp(TargetReg(kArg1), 0, tmp); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1023 | MarkPossibleNullPointerException(info->opt_flags); |
| 1024 | FreeTemp(tmp); |
| 1025 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1026 | } |
| 1027 | return call_state; |
| 1028 | } |
| 1029 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1030 | RegLocation Mir2Lir::InlineTarget(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1031 | RegLocation res; |
| 1032 | if (info->result.location == kLocInvalid) { |
| 1033 | res = GetReturn(false); |
| 1034 | } else { |
| 1035 | res = info->result; |
| 1036 | } |
| 1037 | return res; |
| 1038 | } |
| 1039 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1040 | RegLocation Mir2Lir::InlineTargetWide(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1041 | RegLocation res; |
| 1042 | if (info->result.location == kLocInvalid) { |
| 1043 | res = GetReturnWide(false); |
| 1044 | } else { |
| 1045 | res = info->result; |
| 1046 | } |
| 1047 | return res; |
| 1048 | } |
| 1049 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1050 | bool Mir2Lir::GenInlinedCharAt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1051 | if (cu_->instruction_set == kMips) { |
| 1052 | // TODO - add Mips implementation |
| 1053 | return false; |
| 1054 | } |
| 1055 | // Location of reference to data array |
| 1056 | int value_offset = mirror::String::ValueOffset().Int32Value(); |
| 1057 | // Location of count |
| 1058 | int count_offset = mirror::String::CountOffset().Int32Value(); |
| 1059 | // Starting offset within data array |
| 1060 | int offset_offset = mirror::String::OffsetOffset().Int32Value(); |
| 1061 | // Start of char data with array_ |
| 1062 | int data_offset = mirror::Array::DataOffset(sizeof(uint16_t)).Int32Value(); |
| 1063 | |
| 1064 | RegLocation rl_obj = info->args[0]; |
| 1065 | RegLocation rl_idx = info->args[1]; |
| 1066 | rl_obj = LoadValue(rl_obj, kCoreReg); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1067 | // X86 wants to avoid putting a constant index into a register. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1068 | if (!((cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64)&& rl_idx.is_const)) { |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1069 | rl_idx = LoadValue(rl_idx, kCoreReg); |
| 1070 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1071 | RegStorage reg_max; |
| 1072 | GenNullCheck(rl_obj.reg, info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1073 | bool range_check = (!(info->opt_flags & MIR_IGNORE_RANGE_CHECK)); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1074 | LIR* range_check_branch = nullptr; |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1075 | RegStorage reg_off; |
| 1076 | RegStorage reg_ptr; |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1077 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1078 | reg_off = AllocTemp(); |
| 1079 | reg_ptr = AllocTemp(); |
| 1080 | if (range_check) { |
| 1081 | reg_max = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1082 | Load32Disp(rl_obj.reg, count_offset, reg_max); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 1083 | MarkPossibleNullPointerException(info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1084 | } |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1085 | Load32Disp(rl_obj.reg, offset_offset, reg_off); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 1086 | MarkPossibleNullPointerException(info->opt_flags); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1087 | Load32Disp(rl_obj.reg, value_offset, reg_ptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1088 | if (range_check) { |
| 1089 | // Set up a launch pad to allow retry in case of bounds violation */ |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1090 | OpRegReg(kOpCmp, rl_idx.reg, reg_max); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1091 | FreeTemp(reg_max); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1092 | range_check_branch = OpCondBranch(kCondUge, nullptr); |
Brian Carlstrom | 6f485c6 | 2013-07-18 15:35:35 -0700 | [diff] [blame] | 1093 | } |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1094 | OpRegImm(kOpAdd, reg_ptr, data_offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1095 | } else { |
| 1096 | if (range_check) { |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1097 | // On x86, we can compare to memory directly |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1098 | // Set up a launch pad to allow retry in case of bounds violation */ |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1099 | if (rl_idx.is_const) { |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1100 | range_check_branch = OpCmpMemImmBranch( |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1101 | kCondUlt, RegStorage::InvalidReg(), rl_obj.reg, count_offset, |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1102 | mir_graph_->ConstantValue(rl_idx.orig_sreg), nullptr); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1103 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1104 | OpRegMem(kOpCmp, rl_idx.reg, rl_obj.reg, count_offset); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1105 | range_check_branch = OpCondBranch(kCondUge, nullptr); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1106 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1107 | } |
| 1108 | reg_off = AllocTemp(); |
| 1109 | reg_ptr = AllocTemp(); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1110 | Load32Disp(rl_obj.reg, offset_offset, reg_off); |
| 1111 | Load32Disp(rl_obj.reg, value_offset, reg_ptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1112 | } |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1113 | if (rl_idx.is_const) { |
| 1114 | OpRegImm(kOpAdd, reg_off, mir_graph_->ConstantValue(rl_idx.orig_sreg)); |
| 1115 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1116 | OpRegReg(kOpAdd, reg_off, rl_idx.reg); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1117 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1118 | FreeTemp(rl_obj.reg); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 1119 | if (rl_idx.location == kLocPhysReg) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1120 | FreeTemp(rl_idx.reg); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1121 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1122 | RegLocation rl_dest = InlineTarget(info); |
| 1123 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1124 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1125 | LoadBaseIndexed(reg_ptr, reg_off, rl_result.reg, 1, kUnsignedHalf); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1126 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1127 | LoadBaseIndexedDisp(reg_ptr, reg_off, 1, data_offset, rl_result.reg, |
| 1128 | RegStorage::InvalidReg(), kUnsignedHalf, INVALID_SREG); |
Mark Mendell | 2b724cb | 2014-02-06 05:24:20 -0800 | [diff] [blame] | 1129 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1130 | FreeTemp(reg_off); |
| 1131 | FreeTemp(reg_ptr); |
| 1132 | StoreValue(rl_dest, rl_result); |
| 1133 | if (range_check) { |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1134 | DCHECK(range_check_branch != nullptr); |
| 1135 | info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've already null checked. |
| 1136 | AddIntrinsicLaunchpad(info, range_check_branch); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1137 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1138 | return true; |
| 1139 | } |
| 1140 | |
| 1141 | // Generates an inlined String.is_empty or String.length. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1142 | bool Mir2Lir::GenInlinedStringIsEmptyOrLength(CallInfo* info, bool is_empty) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1143 | if (cu_->instruction_set == kMips) { |
| 1144 | // TODO - add Mips implementation |
| 1145 | return false; |
| 1146 | } |
| 1147 | // dst = src.length(); |
| 1148 | RegLocation rl_obj = info->args[0]; |
| 1149 | rl_obj = LoadValue(rl_obj, kCoreReg); |
| 1150 | RegLocation rl_dest = InlineTarget(info); |
| 1151 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1152 | GenNullCheck(rl_obj.reg, info->opt_flags); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1153 | Load32Disp(rl_obj.reg, mirror::String::CountOffset().Int32Value(), rl_result.reg); |
Dave Allison | b373e09 | 2014-02-20 16:06:36 -0800 | [diff] [blame] | 1154 | MarkPossibleNullPointerException(info->opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1155 | if (is_empty) { |
| 1156 | // dst = (dst == 0); |
| 1157 | if (cu_->instruction_set == kThumb2) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1158 | RegStorage t_reg = AllocTemp(); |
| 1159 | OpRegReg(kOpNeg, t_reg, rl_result.reg); |
| 1160 | OpRegRegReg(kOpAdc, rl_result.reg, rl_result.reg, t_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1161 | } else { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1162 | DCHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1163 | OpRegImm(kOpSub, rl_result.reg, 1); |
| 1164 | OpRegImm(kOpLsr, rl_result.reg, 31); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | StoreValue(rl_dest, rl_result); |
| 1168 | return true; |
| 1169 | } |
| 1170 | |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1171 | bool Mir2Lir::GenInlinedReverseBytes(CallInfo* info, OpSize size) { |
| 1172 | if (cu_->instruction_set == kMips) { |
| 1173 | // TODO - add Mips implementation |
| 1174 | return false; |
| 1175 | } |
| 1176 | RegLocation rl_src_i = info->args[0]; |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1177 | RegLocation rl_dest = (size == k64) ? InlineTargetWide(info) : InlineTarget(info); // result reg |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1178 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1179 | if (size == k64) { |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1180 | RegLocation rl_i = LoadValueWide(rl_src_i, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1181 | RegStorage r_i_low = rl_i.reg.GetLow(); |
| 1182 | if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) { |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 1183 | // First REV shall clobber rl_result.reg.GetReg(), save the value in a temp for the second REV. |
Vladimir Marko | f246af2 | 2013-11-27 12:30:15 +0000 | [diff] [blame] | 1184 | r_i_low = AllocTemp(); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1185 | OpRegCopy(r_i_low, rl_i.reg); |
Vladimir Marko | f246af2 | 2013-11-27 12:30:15 +0000 | [diff] [blame] | 1186 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1187 | OpRegReg(kOpRev, rl_result.reg.GetLow(), rl_i.reg.GetHigh()); |
| 1188 | OpRegReg(kOpRev, rl_result.reg.GetHigh(), r_i_low); |
| 1189 | if (rl_i.reg.GetLowReg() == rl_result.reg.GetLowReg()) { |
Vladimir Marko | f246af2 | 2013-11-27 12:30:15 +0000 | [diff] [blame] | 1190 | FreeTemp(r_i_low); |
| 1191 | } |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1192 | StoreValueWide(rl_dest, rl_result); |
| 1193 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1194 | DCHECK(size == k32 || size == kSignedHalf); |
| 1195 | OpKind op = (size == k32) ? kOpRev : kOpRevsh; |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1196 | RegLocation rl_i = LoadValue(rl_src_i, kCoreReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1197 | OpRegReg(op, rl_result.reg, rl_i.reg); |
Vladimir Marko | 6bdf1ff | 2013-10-29 17:40:46 +0000 | [diff] [blame] | 1198 | StoreValue(rl_dest, rl_result); |
| 1199 | } |
| 1200 | return true; |
| 1201 | } |
| 1202 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1203 | bool Mir2Lir::GenInlinedAbsInt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1204 | if (cu_->instruction_set == kMips) { |
| 1205 | // TODO - add Mips implementation |
| 1206 | return false; |
| 1207 | } |
| 1208 | RegLocation rl_src = info->args[0]; |
| 1209 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1210 | RegLocation rl_dest = InlineTarget(info); |
| 1211 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1212 | RegStorage sign_reg = AllocTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1213 | // abs(x) = y<=x>>31, (x+y)^y. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1214 | OpRegRegImm(kOpAsr, sign_reg, rl_src.reg, 31); |
| 1215 | OpRegRegReg(kOpAdd, rl_result.reg, rl_src.reg, sign_reg); |
| 1216 | OpRegReg(kOpXor, rl_result.reg, sign_reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1217 | StoreValue(rl_dest, rl_result); |
| 1218 | return true; |
| 1219 | } |
| 1220 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1221 | bool Mir2Lir::GenInlinedAbsLong(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1222 | if (cu_->instruction_set == kMips) { |
| 1223 | // TODO - add Mips implementation |
| 1224 | return false; |
| 1225 | } |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1226 | RegLocation rl_src = info->args[0]; |
| 1227 | rl_src = LoadValueWide(rl_src, kCoreReg); |
| 1228 | RegLocation rl_dest = InlineTargetWide(info); |
| 1229 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1230 | |
| 1231 | // If on x86 or if we would clobber a register needed later, just copy the source first. |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1232 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64 || rl_result.reg.GetLowReg() == rl_src.reg.GetHighReg()) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1233 | OpRegCopyWide(rl_result.reg, rl_src.reg); |
| 1234 | if (rl_result.reg.GetLowReg() != rl_src.reg.GetLowReg() && |
| 1235 | rl_result.reg.GetLowReg() != rl_src.reg.GetHighReg() && |
| 1236 | rl_result.reg.GetHighReg() != rl_src.reg.GetLowReg() && |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1237 | rl_result.reg.GetHighReg() != rl_src.reg.GetHighReg()) { |
| 1238 | // Reuse source registers to avoid running out of temps. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1239 | FreeTemp(rl_src.reg); |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1240 | } |
| 1241 | rl_src = rl_result; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1242 | } |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1243 | |
| 1244 | // abs(x) = y<=x>>31, (x+y)^y. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1245 | RegStorage sign_reg = AllocTemp(); |
| 1246 | OpRegRegImm(kOpAsr, sign_reg, rl_src.reg.GetHigh(), 31); |
| 1247 | OpRegRegReg(kOpAdd, rl_result.reg.GetLow(), rl_src.reg.GetLow(), sign_reg); |
| 1248 | OpRegRegReg(kOpAdc, rl_result.reg.GetHigh(), rl_src.reg.GetHigh(), sign_reg); |
| 1249 | OpRegReg(kOpXor, rl_result.reg.GetLow(), sign_reg); |
| 1250 | OpRegReg(kOpXor, rl_result.reg.GetHigh(), sign_reg); |
Vladimir Marko | b982331 | 2014-03-20 17:38:43 +0000 | [diff] [blame] | 1251 | StoreValueWide(rl_dest, rl_result); |
| 1252 | return true; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1253 | } |
| 1254 | |
Yixin Shou | dbb17e3 | 2014-02-07 05:09:30 -0800 | [diff] [blame] | 1255 | bool Mir2Lir::GenInlinedAbsFloat(CallInfo* info) { |
| 1256 | if (cu_->instruction_set == kMips) { |
| 1257 | // TODO - add Mips implementation |
| 1258 | return false; |
| 1259 | } |
| 1260 | RegLocation rl_src = info->args[0]; |
| 1261 | rl_src = LoadValue(rl_src, kCoreReg); |
| 1262 | RegLocation rl_dest = InlineTarget(info); |
| 1263 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1264 | OpRegRegImm(kOpAnd, rl_result.reg, rl_src.reg, 0x7fffffff); |
Yixin Shou | dbb17e3 | 2014-02-07 05:09:30 -0800 | [diff] [blame] | 1265 | StoreValue(rl_dest, rl_result); |
| 1266 | return true; |
| 1267 | } |
| 1268 | |
| 1269 | bool Mir2Lir::GenInlinedAbsDouble(CallInfo* info) { |
| 1270 | if (cu_->instruction_set == kMips) { |
| 1271 | // TODO - add Mips implementation |
| 1272 | return false; |
| 1273 | } |
| 1274 | RegLocation rl_src = info->args[0]; |
| 1275 | rl_src = LoadValueWide(rl_src, kCoreReg); |
| 1276 | RegLocation rl_dest = InlineTargetWide(info); |
| 1277 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1278 | OpRegCopyWide(rl_result.reg, rl_src.reg); |
| 1279 | OpRegImm(kOpAnd, rl_result.reg.GetHigh(), 0x7fffffff); |
Yixin Shou | dbb17e3 | 2014-02-07 05:09:30 -0800 | [diff] [blame] | 1280 | StoreValueWide(rl_dest, rl_result); |
| 1281 | return true; |
| 1282 | } |
| 1283 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1284 | bool Mir2Lir::GenInlinedFloatCvt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1285 | if (cu_->instruction_set == kMips) { |
| 1286 | // TODO - add Mips implementation |
| 1287 | return false; |
| 1288 | } |
| 1289 | RegLocation rl_src = info->args[0]; |
| 1290 | RegLocation rl_dest = InlineTarget(info); |
| 1291 | StoreValue(rl_dest, rl_src); |
| 1292 | return true; |
| 1293 | } |
| 1294 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1295 | bool Mir2Lir::GenInlinedDoubleCvt(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1296 | if (cu_->instruction_set == kMips) { |
| 1297 | // TODO - add Mips implementation |
| 1298 | return false; |
| 1299 | } |
| 1300 | RegLocation rl_src = info->args[0]; |
| 1301 | RegLocation rl_dest = InlineTargetWide(info); |
| 1302 | StoreValueWide(rl_dest, rl_src); |
| 1303 | return true; |
| 1304 | } |
| 1305 | |
| 1306 | /* |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1307 | * Fast String.indexOf(I) & (II). Tests for simple case of char <= 0xFFFF, |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1308 | * otherwise bails to standard library code. |
| 1309 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1310 | bool Mir2Lir::GenInlinedIndexOf(CallInfo* info, bool zero_based) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1311 | if (cu_->instruction_set == kMips) { |
| 1312 | // TODO - add Mips implementation |
| 1313 | return false; |
| 1314 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1315 | RegLocation rl_obj = info->args[0]; |
| 1316 | RegLocation rl_char = info->args[1]; |
| 1317 | if (rl_char.is_const && (mir_graph_->ConstantValue(rl_char) & ~0xFFFF) != 0) { |
| 1318 | // Code point beyond 0xFFFF. Punt to the real String.indexOf(). |
| 1319 | return false; |
| 1320 | } |
| 1321 | |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1322 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1323 | LockCallTemps(); // Using fixed registers |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1324 | RegStorage reg_ptr = TargetReg(kArg0); |
| 1325 | RegStorage reg_char = TargetReg(kArg1); |
| 1326 | RegStorage reg_start = TargetReg(kArg2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1327 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1328 | LoadValueDirectFixed(rl_obj, reg_ptr); |
| 1329 | LoadValueDirectFixed(rl_char, reg_char); |
| 1330 | if (zero_based) { |
| 1331 | LoadConstant(reg_start, 0); |
| 1332 | } else { |
buzbee | a44d4f5 | 2014-03-05 11:26:39 -0800 | [diff] [blame] | 1333 | RegLocation rl_start = info->args[2]; // 3rd arg only present in III flavor of IndexOf. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1334 | LoadValueDirectFixed(rl_start, reg_start); |
| 1335 | } |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1336 | RegStorage r_tgt = LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pIndexOf)); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1337 | GenExplicitNullCheck(reg_ptr, info->opt_flags); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1338 | LIR* high_code_point_branch = |
| 1339 | rl_char.is_const ? nullptr : OpCmpImmBranch(kCondGt, reg_char, 0xFFFF, nullptr); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1340 | // NOTE: not a safepoint |
Mark Mendell | 4028a6c | 2014-02-19 20:06:20 -0800 | [diff] [blame] | 1341 | OpReg(kOpBlx, r_tgt); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1342 | if (!rl_char.is_const) { |
| 1343 | // Add the slow path for code points beyond 0xFFFF. |
| 1344 | DCHECK(high_code_point_branch != nullptr); |
| 1345 | LIR* resume_tgt = NewLIR0(kPseudoTargetLabel); |
| 1346 | info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. |
| 1347 | AddIntrinsicLaunchpad(info, high_code_point_branch, resume_tgt); |
| 1348 | } else { |
| 1349 | DCHECK_EQ(mir_graph_->ConstantValue(rl_char) & ~0xFFFF, 0); |
| 1350 | DCHECK(high_code_point_branch == nullptr); |
| 1351 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1352 | RegLocation rl_return = GetReturn(false); |
| 1353 | RegLocation rl_dest = InlineTarget(info); |
| 1354 | StoreValue(rl_dest, rl_return); |
| 1355 | return true; |
| 1356 | } |
| 1357 | |
| 1358 | /* Fast string.compareTo(Ljava/lang/string;)I. */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1359 | bool Mir2Lir::GenInlinedStringCompareTo(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1360 | if (cu_->instruction_set == kMips) { |
| 1361 | // TODO - add Mips implementation |
| 1362 | return false; |
| 1363 | } |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1364 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1365 | LockCallTemps(); // Using fixed registers |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1366 | RegStorage reg_this = TargetReg(kArg0); |
| 1367 | RegStorage reg_cmp = TargetReg(kArg1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1368 | |
| 1369 | RegLocation rl_this = info->args[0]; |
| 1370 | RegLocation rl_cmp = info->args[1]; |
| 1371 | LoadValueDirectFixed(rl_this, reg_this); |
| 1372 | LoadValueDirectFixed(rl_cmp, reg_cmp); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1373 | RegStorage r_tgt = (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) ? |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1374 | LoadHelper(QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo)) : RegStorage::InvalidReg(); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 1375 | GenExplicitNullCheck(reg_this, info->opt_flags); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1376 | info->opt_flags |= MIR_IGNORE_NULL_CHECK; // Record that we've null checked. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 1377 | // TUNING: check if rl_cmp.s_reg_low is already null checked |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1378 | LIR* cmp_null_check_branch = OpCmpImmBranch(kCondEq, reg_cmp, 0, nullptr); |
| 1379 | AddIntrinsicLaunchpad(info, cmp_null_check_branch); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1380 | // NOTE: not a safepoint |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1381 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1382 | OpReg(kOpBlx, r_tgt); |
| 1383 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1384 | OpThreadMem(kOpBlx, QUICK_ENTRYPOINT_OFFSET(4, pStringCompareTo)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1385 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1386 | RegLocation rl_return = GetReturn(false); |
| 1387 | RegLocation rl_dest = InlineTarget(info); |
| 1388 | StoreValue(rl_dest, rl_return); |
| 1389 | return true; |
| 1390 | } |
| 1391 | |
| 1392 | bool Mir2Lir::GenInlinedCurrentThread(CallInfo* info) { |
| 1393 | RegLocation rl_dest = InlineTarget(info); |
| 1394 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1395 | ThreadOffset<4> offset = Thread::PeerOffset<4>(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1396 | if (cu_->instruction_set == kThumb2 || cu_->instruction_set == kMips) { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1397 | Load32Disp(TargetReg(kSelf), offset.Int32Value(), rl_result.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1398 | } else { |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1399 | CHECK(cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64); |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 1400 | reinterpret_cast<X86Mir2Lir*>(this)->OpRegThreadMem(kOpMov, rl_result.reg.GetReg(), offset); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1401 | } |
| 1402 | StoreValue(rl_dest, rl_result); |
| 1403 | return true; |
| 1404 | } |
| 1405 | |
| 1406 | bool Mir2Lir::GenInlinedUnsafeGet(CallInfo* info, |
| 1407 | bool is_long, bool is_volatile) { |
| 1408 | if (cu_->instruction_set == kMips) { |
| 1409 | // TODO - add Mips implementation |
| 1410 | return false; |
| 1411 | } |
| 1412 | // Unused - RegLocation rl_src_unsafe = info->args[0]; |
| 1413 | RegLocation rl_src_obj = info->args[1]; // Object |
| 1414 | RegLocation rl_src_offset = info->args[2]; // long low |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1415 | rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3] |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1416 | RegLocation rl_dest = is_long ? InlineTargetWide(info) : InlineTarget(info); // result reg |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1417 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1418 | RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg); |
| 1419 | RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg); |
| 1420 | RegLocation rl_result = EvalLoc(rl_dest, kCoreReg, true); |
| 1421 | if (is_long) { |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1422 | if (cu_->instruction_set == kX86) { |
Vladimir Marko | 99f391e | 2014-04-03 12:56:06 +0100 | [diff] [blame] | 1423 | LoadBaseIndexedDisp(rl_object.reg, rl_offset.reg, 0, 0, rl_result.reg.GetLow(), |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1424 | rl_result.reg.GetHigh(), k64, INVALID_SREG); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1425 | } else { |
| 1426 | RegStorage rl_temp_offset = AllocTemp(); |
| 1427 | OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg); |
| 1428 | LoadBaseDispWide(rl_temp_offset, 0, rl_result.reg, INVALID_SREG); |
| 1429 | FreeTemp(rl_temp_offset.GetReg()); |
| 1430 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1431 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1432 | LoadBaseIndexed(rl_object.reg, rl_offset.reg, rl_result.reg, 0, k32); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | if (is_volatile) { |
| 1436 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 1437 | // In this case, either a load or store may follow so we issue both barriers. |
| 1438 | GenMemBarrier(kLoadLoad); |
| 1439 | GenMemBarrier(kLoadStore); |
| 1440 | } |
| 1441 | |
| 1442 | if (is_long) { |
| 1443 | StoreValueWide(rl_dest, rl_result); |
| 1444 | } else { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1445 | StoreValue(rl_dest, rl_result); |
| 1446 | } |
| 1447 | return true; |
| 1448 | } |
| 1449 | |
| 1450 | bool Mir2Lir::GenInlinedUnsafePut(CallInfo* info, bool is_long, |
| 1451 | bool is_object, bool is_volatile, bool is_ordered) { |
| 1452 | if (cu_->instruction_set == kMips) { |
| 1453 | // TODO - add Mips implementation |
| 1454 | return false; |
| 1455 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1456 | // Unused - RegLocation rl_src_unsafe = info->args[0]; |
| 1457 | RegLocation rl_src_obj = info->args[1]; // Object |
| 1458 | RegLocation rl_src_offset = info->args[2]; // long low |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1459 | rl_src_offset = NarrowRegLoc(rl_src_offset); // ignore high half in info->args[3] |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1460 | RegLocation rl_src_value = info->args[4]; // value to store |
| 1461 | if (is_volatile || is_ordered) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1462 | // There might have been a store before this volatile one so insert StoreStore barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1463 | GenMemBarrier(kStoreStore); |
| 1464 | } |
| 1465 | RegLocation rl_object = LoadValue(rl_src_obj, kCoreReg); |
| 1466 | RegLocation rl_offset = LoadValue(rl_src_offset, kCoreReg); |
| 1467 | RegLocation rl_value; |
| 1468 | if (is_long) { |
| 1469 | rl_value = LoadValueWide(rl_src_value, kCoreReg); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1470 | if (cu_->instruction_set == kX86) { |
Vladimir Marko | 99f391e | 2014-04-03 12:56:06 +0100 | [diff] [blame] | 1471 | StoreBaseIndexedDisp(rl_object.reg, rl_offset.reg, 0, 0, rl_value.reg.GetLow(), |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1472 | rl_value.reg.GetHigh(), k64, INVALID_SREG); |
Mathieu Chartier | 7c95cef | 2014-04-02 17:09:17 -0700 | [diff] [blame] | 1473 | } else { |
| 1474 | RegStorage rl_temp_offset = AllocTemp(); |
| 1475 | OpRegRegReg(kOpAdd, rl_temp_offset, rl_object.reg, rl_offset.reg); |
| 1476 | StoreBaseDispWide(rl_temp_offset, 0, rl_value.reg); |
| 1477 | FreeTemp(rl_temp_offset.GetReg()); |
| 1478 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1479 | } else { |
| 1480 | rl_value = LoadValue(rl_src_value, kCoreReg); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame^] | 1481 | StoreBaseIndexed(rl_object.reg, rl_offset.reg, rl_value.reg, 0, k32); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1482 | } |
Mark Mendell | df8ee2e | 2014-01-27 16:37:47 -0800 | [diff] [blame] | 1483 | |
| 1484 | // Free up the temp early, to ensure x86 doesn't run out of temporaries in MarkGCCard. |
Bill Buzbee | 00e1ec6 | 2014-02-27 23:44:13 +0000 | [diff] [blame] | 1485 | FreeTemp(rl_offset.reg.GetReg()); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1486 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1487 | if (is_volatile) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 1488 | // A load might follow the volatile store so insert a StoreLoad barrier. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1489 | GenMemBarrier(kStoreLoad); |
| 1490 | } |
| 1491 | if (is_object) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 1492 | MarkGCCard(rl_value.reg, rl_object.reg); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1493 | } |
| 1494 | return true; |
| 1495 | } |
| 1496 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1497 | void Mir2Lir::GenInvoke(CallInfo* info) { |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 1498 | if ((info->opt_flags & MIR_INLINED) != 0) { |
| 1499 | // Already inlined but we may still need the null check. |
| 1500 | if (info->type != kStatic && |
| 1501 | ((cu_->disable_opt & (1 << kNullCheckElimination)) != 0 || |
| 1502 | (info->opt_flags & MIR_IGNORE_NULL_CHECK) == 0)) { |
| 1503 | RegLocation rl_obj = LoadValue(info->args[0], kCoreReg); |
Mingyao Yang | e643a17 | 2014-04-08 11:02:52 -0700 | [diff] [blame] | 1504 | GenNullCheck(rl_obj.reg); |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 1505 | } |
| 1506 | return; |
| 1507 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1508 | DCHECK(cu_->compiler_driver->GetMethodInlinerMap() != nullptr); |
| 1509 | if (cu_->compiler_driver->GetMethodInlinerMap()->GetMethodInliner(cu_->dex_file) |
| 1510 | ->GenIntrinsic(this, info)) { |
| 1511 | return; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1512 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1513 | GenInvokeNoInline(info); |
| 1514 | } |
| 1515 | |
| 1516 | void Mir2Lir::GenInvokeNoInline(CallInfo* info) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1517 | int call_state = 0; |
| 1518 | LIR* null_ck; |
| 1519 | LIR** p_null_ck = NULL; |
| 1520 | NextCallInsn next_call_insn; |
| 1521 | FlushAllRegs(); /* Everything to home location */ |
| 1522 | // Explicit register usage |
| 1523 | LockCallTemps(); |
| 1524 | |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1525 | const MirMethodLoweringInfo& method_info = mir_graph_->GetMethodLoweringInfo(info->mir); |
| 1526 | cu_->compiler_driver->ProcessedInvoke(method_info.GetInvokeType(), method_info.StatsFlags()); |
| 1527 | InvokeType original_type = static_cast<InvokeType>(method_info.GetInvokeType()); |
| 1528 | info->type = static_cast<InvokeType>(method_info.GetSharpType()); |
| 1529 | bool fast_path = method_info.FastPath(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1530 | bool skip_this; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1531 | if (info->type == kInterface) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1532 | next_call_insn = fast_path ? NextInterfaceCallInsn : NextInterfaceCallInsnWithAccessCheck; |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 1533 | skip_this = fast_path; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1534 | } else if (info->type == kDirect) { |
| 1535 | if (fast_path) { |
| 1536 | p_null_ck = &null_ck; |
| 1537 | } |
| 1538 | next_call_insn = fast_path ? NextSDCallInsn : NextDirectCallInsnSP; |
| 1539 | skip_this = false; |
| 1540 | } else if (info->type == kStatic) { |
| 1541 | next_call_insn = fast_path ? NextSDCallInsn : NextStaticCallInsnSP; |
| 1542 | skip_this = false; |
| 1543 | } else if (info->type == kSuper) { |
| 1544 | DCHECK(!fast_path); // Fast path is a direct call. |
| 1545 | next_call_insn = NextSuperCallInsnSP; |
| 1546 | skip_this = false; |
| 1547 | } else { |
| 1548 | DCHECK_EQ(info->type, kVirtual); |
| 1549 | next_call_insn = fast_path ? NextVCallInsn : NextVCallInsnSP; |
| 1550 | skip_this = fast_path; |
| 1551 | } |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1552 | MethodReference target_method = method_info.GetTargetMethod(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1553 | if (!info->is_range) { |
| 1554 | call_state = GenDalvikArgsNoRange(info, call_state, p_null_ck, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1555 | next_call_insn, target_method, method_info.VTableIndex(), |
| 1556 | method_info.DirectCode(), method_info.DirectMethod(), |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1557 | original_type, skip_this); |
| 1558 | } else { |
| 1559 | call_state = GenDalvikArgsRange(info, call_state, p_null_ck, |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1560 | next_call_insn, target_method, method_info.VTableIndex(), |
| 1561 | method_info.DirectCode(), method_info.DirectMethod(), |
| 1562 | original_type, skip_this); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1563 | } |
| 1564 | // Finish up any of the call sequence not interleaved in arg loading |
| 1565 | while (call_state >= 0) { |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1566 | call_state = next_call_insn(cu_, info, call_state, target_method, method_info.VTableIndex(), |
| 1567 | method_info.DirectCode(), method_info.DirectMethod(), original_type); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1568 | } |
| 1569 | LIR* call_inst; |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 1570 | if (cu_->instruction_set != kX86 && cu_->instruction_set != kX86_64) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1571 | call_inst = OpReg(kOpBlx, TargetReg(kInvokeTgt)); |
| 1572 | } else { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 1573 | if (fast_path) { |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1574 | if (method_info.DirectCode() == static_cast<uintptr_t>(-1)) { |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1575 | // We can have the linker fixup a call relative. |
| 1576 | call_inst = |
Jeff Hao | 49161ce | 2014-03-12 11:05:25 -0700 | [diff] [blame] | 1577 | reinterpret_cast<X86Mir2Lir*>(this)->CallWithLinkerFixup(target_method, info->type); |
Mark Mendell | 55d0eac | 2014-02-06 11:02:52 -0800 | [diff] [blame] | 1578 | } else { |
| 1579 | call_inst = OpMem(kOpBlx, TargetReg(kArg0), |
| 1580 | mirror::ArtMethod::EntryPointFromQuickCompiledCodeOffset().Int32Value()); |
| 1581 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1582 | } else { |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1583 | ThreadOffset<4> trampoline(-1); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1584 | switch (info->type) { |
| 1585 | case kInterface: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1586 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeInterfaceTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1587 | break; |
| 1588 | case kDirect: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1589 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeDirectTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1590 | break; |
| 1591 | case kStatic: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1592 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeStaticTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1593 | break; |
| 1594 | case kSuper: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1595 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeSuperTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1596 | break; |
| 1597 | case kVirtual: |
Ian Rogers | dd7624d | 2014-03-14 17:43:00 -0700 | [diff] [blame] | 1598 | trampoline = QUICK_ENTRYPOINT_OFFSET(4, pInvokeVirtualTrampolineWithAccessCheck); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1599 | break; |
| 1600 | default: |
| 1601 | LOG(FATAL) << "Unexpected invoke type"; |
| 1602 | } |
| 1603 | call_inst = OpThreadMem(kOpBlx, trampoline); |
| 1604 | } |
| 1605 | } |
| 1606 | MarkSafepointPC(call_inst); |
| 1607 | |
Vladimir Marko | 31c2aac | 2013-12-09 16:31:19 +0000 | [diff] [blame] | 1608 | ClobberCallerSave(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1609 | if (info->result.location != kLocInvalid) { |
| 1610 | // We have a following MOVE_RESULT - do it now. |
| 1611 | if (info->result.wide) { |
| 1612 | RegLocation ret_loc = GetReturnWide(info->result.fp); |
| 1613 | StoreValueWide(info->result, ret_loc); |
| 1614 | } else { |
| 1615 | RegLocation ret_loc = GetReturn(info->result.fp); |
| 1616 | StoreValue(info->result, ret_loc); |
| 1617 | } |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | } // namespace art |