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