Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "dex/compiler_internals.h" |
| 18 | #include "dex/dataflow_iterator-inl.h" |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 19 | #include "dex/quick/dex_file_method_inliner.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 20 | #include "mir_to_lir-inl.h" |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 21 | #include "primitive.h" |
Ian Rogers | 02ed4c0 | 2013-09-06 13:10:04 -0700 | [diff] [blame] | 22 | #include "thread-inl.h" |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 23 | |
| 24 | namespace art { |
| 25 | |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 26 | RegisterClass Mir2Lir::ShortyToRegClass(char shorty_type) { |
| 27 | RegisterClass res; |
| 28 | switch (shorty_type) { |
| 29 | case 'L': |
| 30 | res = kRefReg; |
| 31 | break; |
| 32 | case 'F': |
| 33 | // Expected fallthrough. |
| 34 | case 'D': |
| 35 | res = kFPReg; |
| 36 | break; |
| 37 | default: |
| 38 | res = kCoreReg; |
| 39 | } |
| 40 | return res; |
| 41 | } |
| 42 | |
| 43 | RegisterClass Mir2Lir::LocToRegClass(RegLocation loc) { |
| 44 | RegisterClass res; |
| 45 | if (loc.fp) { |
| 46 | DCHECK(!loc.ref) << "At most, one of ref/fp may be set"; |
| 47 | res = kFPReg; |
| 48 | } else if (loc.ref) { |
| 49 | res = kRefReg; |
| 50 | } else { |
| 51 | res = kCoreReg; |
| 52 | } |
| 53 | return res; |
| 54 | } |
| 55 | |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 56 | void Mir2Lir::LockArg(int in_position, bool) { |
| 57 | RegStorage reg_arg = GetArgMappingToPhysicalReg(in_position); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 58 | |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 59 | if (reg_arg.Valid()) { |
| 60 | LockTemp(reg_arg); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 61 | } |
| 62 | } |
| 63 | |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 64 | RegStorage Mir2Lir::LoadArg(int in_position, RegisterClass reg_class, bool wide) { |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 65 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 66 | int offset = StackVisitor::GetOutVROffset(in_position, cu_->instruction_set); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 67 | |
| 68 | if (cu_->instruction_set == kX86) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 69 | /* |
| 70 | * When doing a call for x86, it moves the stack pointer in order to push return. |
| 71 | * Thus, we add another 4 bytes to figure out the out of caller (in of callee). |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 72 | */ |
| 73 | offset += sizeof(uint32_t); |
| 74 | } |
| 75 | |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 76 | if (cu_->instruction_set == kX86_64) { |
| 77 | /* |
| 78 | * When doing a call for x86, it moves the stack pointer in order to push return. |
| 79 | * Thus, we add another 8 bytes to figure out the out of caller (in of callee). |
| 80 | */ |
| 81 | offset += sizeof(uint64_t); |
| 82 | } |
| 83 | |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 84 | RegStorage reg_arg = GetArgMappingToPhysicalReg(in_position); |
| 85 | |
| 86 | // TODO: REVISIT: This adds a spill of low part while we could just copy it. |
| 87 | if (reg_arg.Valid() && wide && (reg_arg.GetWideKind() == kNotWide)) { |
| 88 | // For wide register we've got only half of it. |
| 89 | // Flush it to memory then. |
| 90 | StoreBaseDisp(TargetPtrReg(kSp), offset, reg_arg, k32, kNotVolatile); |
| 91 | reg_arg = RegStorage::InvalidReg(); |
| 92 | } |
| 93 | |
| 94 | if (!reg_arg.Valid()) { |
| 95 | reg_arg = wide ? AllocTypedTempWide(false, reg_class) : AllocTypedTemp(false, reg_class); |
| 96 | LoadBaseDisp(TargetPtrReg(kSp), offset, reg_arg, wide ? k64 : k32, kNotVolatile); |
| 97 | } else { |
| 98 | // Check if we need to copy the arg to a different reg_class. |
| 99 | if (!RegClassMatches(reg_class, reg_arg)) { |
| 100 | if (wide) { |
| 101 | RegStorage new_reg = AllocTypedTempWide(false, reg_class); |
| 102 | OpRegCopyWide(new_reg, reg_arg); |
| 103 | reg_arg = new_reg; |
| 104 | } else { |
| 105 | RegStorage new_reg = AllocTypedTemp(false, reg_class); |
| 106 | OpRegCopy(new_reg, reg_arg); |
| 107 | reg_arg = new_reg; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 108 | } |
| 109 | } |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 110 | } |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 111 | return reg_arg; |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | void Mir2Lir::LoadArgDirect(int in_position, RegLocation rl_dest) { |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 115 | DCHECK_EQ(rl_dest.location, kLocPhysReg); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 116 | ScopedMemRefType mem_ref_type(this, ResourceMask::kDalvikReg); |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 117 | int offset = StackVisitor::GetOutVROffset(in_position, cu_->instruction_set); |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 118 | if (cu_->instruction_set == kX86) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 119 | /* |
| 120 | * When doing a call for x86, it moves the stack pointer in order to push return. |
| 121 | * Thus, we add another 4 bytes to figure out the out of caller (in of callee). |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 122 | */ |
| 123 | offset += sizeof(uint32_t); |
| 124 | } |
| 125 | |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 126 | if (cu_->instruction_set == kX86_64) { |
| 127 | /* |
| 128 | * When doing a call for x86, it moves the stack pointer in order to push return. |
| 129 | * Thus, we add another 8 bytes to figure out the out of caller (in of callee). |
| 130 | */ |
| 131 | offset += sizeof(uint64_t); |
| 132 | } |
| 133 | |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 134 | RegStorage reg_arg = GetArgMappingToPhysicalReg(in_position); |
| 135 | |
| 136 | // TODO: REVISIT: This adds a spill of low part while we could just copy it. |
| 137 | if (reg_arg.Valid() && rl_dest.wide && (reg_arg.GetWideKind() == kNotWide)) { |
| 138 | // For wide register we've got only half of it. |
| 139 | // Flush it to memory then. |
| 140 | StoreBaseDisp(TargetPtrReg(kSp), offset, reg_arg, k32, kNotVolatile); |
| 141 | reg_arg = RegStorage::InvalidReg(); |
| 142 | } |
| 143 | |
| 144 | if (!reg_arg.Valid()) { |
| 145 | LoadBaseDisp(TargetPtrReg(kSp), offset, rl_dest.reg, rl_dest.wide ? k64 : k32, kNotVolatile); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 146 | } else { |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 147 | if (rl_dest.wide) { |
| 148 | OpRegCopyWide(rl_dest.reg, reg_arg); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 149 | } else { |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 150 | OpRegCopy(rl_dest.reg, reg_arg); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | bool Mir2Lir::GenSpecialIGet(MIR* mir, const InlineMethod& special) { |
| 156 | // FastInstance() already checked by DexFileMethodInliner. |
| 157 | const InlineIGetIPutData& data = special.d.ifield_data; |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 158 | if (data.method_is_static != 0u || data.object_arg != 0u) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 159 | // The object is not "this" and has to be null-checked. |
| 160 | return false; |
| 161 | } |
| 162 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 163 | OpSize size = k32; |
| 164 | switch (data.op_variant) { |
| 165 | case InlineMethodAnalyser::IGetVariant(Instruction::IGET_OBJECT): |
| 166 | size = kReference; |
| 167 | break; |
| 168 | case InlineMethodAnalyser::IGetVariant(Instruction::IGET_WIDE): |
| 169 | size = k64; |
| 170 | break; |
| 171 | case InlineMethodAnalyser::IGetVariant(Instruction::IGET_SHORT): |
| 172 | size = kSignedHalf; |
| 173 | break; |
| 174 | case InlineMethodAnalyser::IGetVariant(Instruction::IGET_CHAR): |
| 175 | size = kUnsignedHalf; |
| 176 | break; |
| 177 | case InlineMethodAnalyser::IGetVariant(Instruction::IGET_BYTE): |
| 178 | size = kSignedByte; |
| 179 | break; |
| 180 | case InlineMethodAnalyser::IGetVariant(Instruction::IGET_BOOLEAN): |
| 181 | size = kUnsignedByte; |
| 182 | break; |
| 183 | } |
Vladimir Marko | 455759b | 2014-05-06 20:49:36 +0100 | [diff] [blame] | 184 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 185 | // Point of no return - no aborts after this |
| 186 | GenPrintLabel(mir); |
| 187 | LockArg(data.object_arg); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 188 | RegStorage reg_obj = LoadArg(data.object_arg, kRefReg); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 189 | RegisterClass reg_class = RegClassForFieldLoadStore(size, data.is_volatile); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 190 | RegisterClass ret_reg_class = ShortyToRegClass(cu_->shorty[0]); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 191 | RegLocation rl_dest = IsWide(size) ? GetReturnWide(ret_reg_class) : GetReturn(ret_reg_class); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 192 | RegStorage r_result = rl_dest.reg; |
| 193 | if (!RegClassMatches(reg_class, r_result)) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 194 | r_result = IsWide(size) ? AllocTypedTempWide(rl_dest.fp, reg_class) |
| 195 | : AllocTypedTemp(rl_dest.fp, reg_class); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 196 | } |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 197 | if (IsRef(size)) { |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 198 | LoadRefDisp(reg_obj, data.field_offset, r_result, data.is_volatile ? kVolatile : kNotVolatile); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 199 | } else { |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 200 | LoadBaseDisp(reg_obj, data.field_offset, r_result, size, data.is_volatile ? kVolatile : |
| 201 | kNotVolatile); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 202 | } |
buzbee | b5860fb | 2014-06-21 15:31:01 -0700 | [diff] [blame] | 203 | if (r_result.NotExactlyEquals(rl_dest.reg)) { |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 204 | if (IsWide(size)) { |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 205 | OpRegCopyWide(rl_dest.reg, r_result); |
| 206 | } else { |
| 207 | OpRegCopy(rl_dest.reg, r_result); |
| 208 | } |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 209 | } |
| 210 | return true; |
| 211 | } |
| 212 | |
| 213 | bool Mir2Lir::GenSpecialIPut(MIR* mir, const InlineMethod& special) { |
| 214 | // FastInstance() already checked by DexFileMethodInliner. |
| 215 | const InlineIGetIPutData& data = special.d.ifield_data; |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 216 | if (data.method_is_static != 0u || data.object_arg != 0u) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 217 | // The object is not "this" and has to be null-checked. |
| 218 | return false; |
| 219 | } |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 220 | if (data.return_arg_plus1 != 0u) { |
| 221 | // The setter returns a method argument which we don't support here. |
| 222 | return false; |
| 223 | } |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 224 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 225 | OpSize size = k32; |
| 226 | switch (data.op_variant) { |
| 227 | case InlineMethodAnalyser::IPutVariant(Instruction::IPUT_OBJECT): |
| 228 | size = kReference; |
| 229 | break; |
| 230 | case InlineMethodAnalyser::IPutVariant(Instruction::IPUT_WIDE): |
| 231 | size = k64; |
| 232 | break; |
| 233 | case InlineMethodAnalyser::IPutVariant(Instruction::IPUT_SHORT): |
| 234 | size = kSignedHalf; |
| 235 | break; |
| 236 | case InlineMethodAnalyser::IPutVariant(Instruction::IPUT_CHAR): |
| 237 | size = kUnsignedHalf; |
| 238 | break; |
| 239 | case InlineMethodAnalyser::IPutVariant(Instruction::IPUT_BYTE): |
| 240 | size = kSignedByte; |
| 241 | break; |
| 242 | case InlineMethodAnalyser::IPutVariant(Instruction::IPUT_BOOLEAN): |
| 243 | size = kUnsignedByte; |
| 244 | break; |
| 245 | } |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 246 | |
| 247 | // Point of no return - no aborts after this |
| 248 | GenPrintLabel(mir); |
| 249 | LockArg(data.object_arg); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 250 | LockArg(data.src_arg, IsWide(size)); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 251 | RegStorage reg_obj = LoadArg(data.object_arg, kRefReg); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 252 | RegisterClass reg_class = RegClassForFieldLoadStore(size, data.is_volatile); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 253 | RegStorage reg_src = LoadArg(data.src_arg, reg_class, IsWide(size)); |
| 254 | if (IsRef(size)) { |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 255 | StoreRefDisp(reg_obj, data.field_offset, reg_src, data.is_volatile ? kVolatile : kNotVolatile); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 256 | } else { |
Andreas Gampe | 3c12c51 | 2014-06-24 18:46:29 +0000 | [diff] [blame] | 257 | StoreBaseDisp(reg_obj, data.field_offset, reg_src, size, data.is_volatile ? kVolatile : |
| 258 | kNotVolatile); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 259 | } |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 260 | if (IsRef(size)) { |
Vladimir Marko | 743b98c | 2014-11-24 19:45:41 +0000 | [diff] [blame] | 261 | MarkGCCard(0, reg_src, reg_obj); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 262 | } |
| 263 | return true; |
| 264 | } |
| 265 | |
| 266 | bool Mir2Lir::GenSpecialIdentity(MIR* mir, const InlineMethod& special) { |
| 267 | const InlineReturnArgData& data = special.d.return_data; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 268 | bool wide = (data.is_wide != 0u); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 269 | |
| 270 | // Point of no return - no aborts after this |
| 271 | GenPrintLabel(mir); |
| 272 | LockArg(data.arg, wide); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 273 | RegisterClass reg_class = ShortyToRegClass(cu_->shorty[0]); |
| 274 | RegLocation rl_dest = wide ? GetReturnWide(reg_class) : GetReturn(reg_class); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 275 | LoadArgDirect(data.arg, rl_dest); |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * Special-case code generation for simple non-throwing leaf methods. |
| 281 | */ |
| 282 | bool Mir2Lir::GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special) { |
| 283 | DCHECK(special.flags & kInlineSpecial); |
| 284 | current_dalvik_offset_ = mir->offset; |
| 285 | MIR* return_mir = nullptr; |
| 286 | bool successful = false; |
| 287 | |
| 288 | switch (special.opcode) { |
| 289 | case kInlineOpNop: |
| 290 | successful = true; |
| 291 | DCHECK_EQ(mir->dalvikInsn.opcode, Instruction::RETURN_VOID); |
| 292 | return_mir = mir; |
| 293 | break; |
| 294 | case kInlineOpNonWideConst: { |
| 295 | successful = true; |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 296 | RegLocation rl_dest = GetReturn(ShortyToRegClass(cu_->shorty[0])); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 297 | GenPrintLabel(mir); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 298 | LoadConstant(rl_dest.reg, static_cast<int>(special.d.data)); |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 299 | return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 300 | break; |
| 301 | } |
| 302 | case kInlineOpReturnArg: |
| 303 | successful = GenSpecialIdentity(mir, special); |
| 304 | return_mir = mir; |
| 305 | break; |
| 306 | case kInlineOpIGet: |
| 307 | successful = GenSpecialIGet(mir, special); |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 308 | return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 309 | break; |
| 310 | case kInlineOpIPut: |
| 311 | successful = GenSpecialIPut(mir, special); |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 312 | return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 313 | break; |
| 314 | default: |
| 315 | break; |
| 316 | } |
| 317 | |
| 318 | if (successful) { |
Vladimir Marko | 39d95e6 | 2014-02-28 12:51:24 +0000 | [diff] [blame] | 319 | if (kIsDebugBuild) { |
| 320 | // Clear unreachable catch entries. |
| 321 | mir_graph_->catches_.clear(); |
| 322 | } |
| 323 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 324 | // Handle verbosity for return MIR. |
| 325 | if (return_mir != nullptr) { |
| 326 | current_dalvik_offset_ = return_mir->offset; |
| 327 | // Not handling special identity case because it already generated code as part |
| 328 | // of the return. The label should have been added before any code was generated. |
| 329 | if (special.opcode != kInlineOpReturnArg) { |
| 330 | GenPrintLabel(return_mir); |
| 331 | } |
| 332 | } |
| 333 | GenSpecialExitSequence(); |
| 334 | |
| 335 | core_spill_mask_ = 0; |
| 336 | num_core_spills_ = 0; |
| 337 | fp_spill_mask_ = 0; |
| 338 | num_fp_spills_ = 0; |
| 339 | frame_size_ = 0; |
| 340 | core_vmap_table_.clear(); |
| 341 | fp_vmap_table_.clear(); |
| 342 | } |
| 343 | |
| 344 | return successful; |
| 345 | } |
| 346 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 347 | /* |
| 348 | * Target-independent code generation. Use only high-level |
| 349 | * load/store utilities here, or target-dependent genXX() handlers |
| 350 | * when necessary. |
| 351 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 352 | void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 353 | RegLocation rl_src[3]; |
| 354 | RegLocation rl_dest = mir_graph_->GetBadLoc(); |
| 355 | RegLocation rl_result = mir_graph_->GetBadLoc(); |
Ian Rogers | c35cda8 | 2014-11-10 16:34:29 -0800 | [diff] [blame] | 356 | const Instruction::Code opcode = mir->dalvikInsn.opcode; |
| 357 | const int opt_flags = mir->optimization_flags; |
| 358 | const uint32_t vB = mir->dalvikInsn.vB; |
| 359 | const uint32_t vC = mir->dalvikInsn.vC; |
buzbee | 082833c | 2014-05-17 23:16:26 -0700 | [diff] [blame] | 360 | DCHECK(CheckCorePoolSanity()) << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " @ 0x:" |
| 361 | << std::hex << current_dalvik_offset_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 362 | |
| 363 | // Prep Src and Dest locations. |
| 364 | int next_sreg = 0; |
| 365 | int next_loc = 0; |
Jean Christophe Beyler | cc794c3 | 2014-05-02 09:34:13 -0700 | [diff] [blame] | 366 | uint64_t attrs = MIRGraph::GetDataFlowAttributes(opcode); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 367 | rl_src[0] = rl_src[1] = rl_src[2] = mir_graph_->GetBadLoc(); |
| 368 | if (attrs & DF_UA) { |
| 369 | if (attrs & DF_A_WIDE) { |
| 370 | rl_src[next_loc++] = mir_graph_->GetSrcWide(mir, next_sreg); |
| 371 | next_sreg+= 2; |
| 372 | } else { |
| 373 | rl_src[next_loc++] = mir_graph_->GetSrc(mir, next_sreg); |
| 374 | next_sreg++; |
| 375 | } |
| 376 | } |
| 377 | if (attrs & DF_UB) { |
| 378 | if (attrs & DF_B_WIDE) { |
| 379 | rl_src[next_loc++] = mir_graph_->GetSrcWide(mir, next_sreg); |
| 380 | next_sreg+= 2; |
| 381 | } else { |
| 382 | rl_src[next_loc++] = mir_graph_->GetSrc(mir, next_sreg); |
| 383 | next_sreg++; |
| 384 | } |
| 385 | } |
| 386 | if (attrs & DF_UC) { |
| 387 | if (attrs & DF_C_WIDE) { |
| 388 | rl_src[next_loc++] = mir_graph_->GetSrcWide(mir, next_sreg); |
| 389 | } else { |
| 390 | rl_src[next_loc++] = mir_graph_->GetSrc(mir, next_sreg); |
| 391 | } |
| 392 | } |
| 393 | if (attrs & DF_DA) { |
| 394 | if (attrs & DF_A_WIDE) { |
| 395 | rl_dest = mir_graph_->GetDestWide(mir); |
| 396 | } else { |
| 397 | rl_dest = mir_graph_->GetDest(mir); |
| 398 | } |
| 399 | } |
| 400 | switch (opcode) { |
| 401 | case Instruction::NOP: |
| 402 | break; |
| 403 | |
| 404 | case Instruction::MOVE_EXCEPTION: |
| 405 | GenMoveException(rl_dest); |
| 406 | break; |
| 407 | |
| 408 | case Instruction::RETURN_VOID: |
| 409 | if (((cu_->access_flags & kAccConstructor) != 0) && |
| 410 | cu_->compiler_driver->RequiresConstructorBarrier(Thread::Current(), cu_->dex_file, |
| 411 | cu_->class_def_idx)) { |
| 412 | GenMemBarrier(kStoreStore); |
| 413 | } |
Wei Jin | 04f4d8a | 2014-05-29 18:04:29 -0700 | [diff] [blame] | 414 | if (!kLeafOptimization || !mir_graph_->MethodIsLeaf()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 415 | GenSuspendTest(opt_flags); |
| 416 | } |
| 417 | break; |
| 418 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 419 | case Instruction::RETURN_OBJECT: |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 420 | DCHECK(rl_src[0].ref); |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 421 | FALLTHROUGH_INTENDED; |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 422 | case Instruction::RETURN: |
Wei Jin | 04f4d8a | 2014-05-29 18:04:29 -0700 | [diff] [blame] | 423 | if (!kLeafOptimization || !mir_graph_->MethodIsLeaf()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 424 | GenSuspendTest(opt_flags); |
| 425 | } |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 426 | DCHECK_EQ(LocToRegClass(rl_src[0]), ShortyToRegClass(cu_->shorty[0])); |
| 427 | StoreValue(GetReturn(LocToRegClass(rl_src[0])), rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 428 | break; |
| 429 | |
| 430 | case Instruction::RETURN_WIDE: |
Wei Jin | 04f4d8a | 2014-05-29 18:04:29 -0700 | [diff] [blame] | 431 | if (!kLeafOptimization || !mir_graph_->MethodIsLeaf()) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 432 | GenSuspendTest(opt_flags); |
| 433 | } |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 434 | DCHECK_EQ(LocToRegClass(rl_src[0]), ShortyToRegClass(cu_->shorty[0])); |
| 435 | StoreValueWide(GetReturnWide(LocToRegClass(rl_src[0])), rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 436 | break; |
| 437 | |
| 438 | case Instruction::MOVE_RESULT_WIDE: |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 439 | StoreValueWide(rl_dest, GetReturnWide(LocToRegClass(rl_dest))); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 440 | break; |
| 441 | |
| 442 | case Instruction::MOVE_RESULT: |
| 443 | case Instruction::MOVE_RESULT_OBJECT: |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 444 | StoreValue(rl_dest, GetReturn(LocToRegClass(rl_dest))); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 445 | break; |
| 446 | |
| 447 | case Instruction::MOVE: |
| 448 | case Instruction::MOVE_OBJECT: |
| 449 | case Instruction::MOVE_16: |
| 450 | case Instruction::MOVE_OBJECT_16: |
| 451 | case Instruction::MOVE_FROM16: |
| 452 | case Instruction::MOVE_OBJECT_FROM16: |
| 453 | StoreValue(rl_dest, rl_src[0]); |
| 454 | break; |
| 455 | |
| 456 | case Instruction::MOVE_WIDE: |
| 457 | case Instruction::MOVE_WIDE_16: |
| 458 | case Instruction::MOVE_WIDE_FROM16: |
| 459 | StoreValueWide(rl_dest, rl_src[0]); |
| 460 | break; |
| 461 | |
| 462 | case Instruction::CONST: |
| 463 | case Instruction::CONST_4: |
| 464 | case Instruction::CONST_16: |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 465 | GenConst(rl_dest, vB); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 466 | break; |
| 467 | |
| 468 | case Instruction::CONST_HIGH16: |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 469 | GenConst(rl_dest, vB << 16); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 470 | break; |
| 471 | |
| 472 | case Instruction::CONST_WIDE_16: |
| 473 | case Instruction::CONST_WIDE_32: |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 474 | GenConstWide(rl_dest, static_cast<int64_t>(static_cast<int32_t>(vB))); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 475 | break; |
| 476 | |
| 477 | case Instruction::CONST_WIDE: |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 478 | GenConstWide(rl_dest, mir->dalvikInsn.vB_wide); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 479 | break; |
| 480 | |
| 481 | case Instruction::CONST_WIDE_HIGH16: |
| 482 | rl_result = EvalLoc(rl_dest, kAnyReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 483 | LoadConstantWide(rl_result.reg, static_cast<int64_t>(vB) << 48); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 484 | StoreValueWide(rl_dest, rl_result); |
| 485 | break; |
| 486 | |
| 487 | case Instruction::MONITOR_ENTER: |
| 488 | GenMonitorEnter(opt_flags, rl_src[0]); |
| 489 | break; |
| 490 | |
| 491 | case Instruction::MONITOR_EXIT: |
| 492 | GenMonitorExit(opt_flags, rl_src[0]); |
| 493 | break; |
| 494 | |
| 495 | case Instruction::CHECK_CAST: { |
| 496 | GenCheckCast(mir->offset, vB, rl_src[0]); |
| 497 | break; |
| 498 | } |
| 499 | case Instruction::INSTANCE_OF: |
| 500 | GenInstanceof(vC, rl_dest, rl_src[0]); |
| 501 | break; |
| 502 | |
| 503 | case Instruction::NEW_INSTANCE: |
| 504 | GenNewInstance(vB, rl_dest); |
| 505 | break; |
| 506 | |
| 507 | case Instruction::THROW: |
| 508 | GenThrow(rl_src[0]); |
| 509 | break; |
| 510 | |
Ian Rogers | c35cda8 | 2014-11-10 16:34:29 -0800 | [diff] [blame] | 511 | case Instruction::ARRAY_LENGTH: { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 512 | int len_offset; |
| 513 | len_offset = mirror::Array::LengthOffset().Int32Value(); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 514 | rl_src[0] = LoadValue(rl_src[0], kRefReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 515 | GenNullCheck(rl_src[0].reg, opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 516 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 517 | Load32Disp(rl_src[0].reg, len_offset, rl_result.reg); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 518 | MarkPossibleNullPointerException(opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 519 | StoreValue(rl_dest, rl_result); |
| 520 | break; |
Ian Rogers | c35cda8 | 2014-11-10 16:34:29 -0800 | [diff] [blame] | 521 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 522 | case Instruction::CONST_STRING: |
| 523 | case Instruction::CONST_STRING_JUMBO: |
| 524 | GenConstString(vB, rl_dest); |
| 525 | break; |
| 526 | |
| 527 | case Instruction::CONST_CLASS: |
| 528 | GenConstClass(vB, rl_dest); |
| 529 | break; |
| 530 | |
| 531 | case Instruction::FILL_ARRAY_DATA: |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 532 | GenFillArrayData(mir, vB, rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 533 | break; |
| 534 | |
| 535 | case Instruction::FILLED_NEW_ARRAY: |
| 536 | GenFilledNewArray(mir_graph_->NewMemCallInfo(bb, mir, kStatic, |
| 537 | false /* not range */)); |
| 538 | break; |
| 539 | |
| 540 | case Instruction::FILLED_NEW_ARRAY_RANGE: |
| 541 | GenFilledNewArray(mir_graph_->NewMemCallInfo(bb, mir, kStatic, |
| 542 | true /* range */)); |
| 543 | break; |
| 544 | |
| 545 | case Instruction::NEW_ARRAY: |
| 546 | GenNewArray(vC, rl_dest, rl_src[0]); |
| 547 | break; |
| 548 | |
| 549 | case Instruction::GOTO: |
| 550 | case Instruction::GOTO_16: |
| 551 | case Instruction::GOTO_32: |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 552 | if (mir_graph_->IsBackEdge(bb, bb->taken)) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 553 | GenSuspendTestAndBranch(opt_flags, &label_list[bb->taken]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 554 | } else { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 555 | OpUnconditionalBranch(&label_list[bb->taken]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 556 | } |
| 557 | break; |
| 558 | |
| 559 | case Instruction::PACKED_SWITCH: |
| 560 | GenPackedSwitch(mir, vB, rl_src[0]); |
| 561 | break; |
| 562 | |
| 563 | case Instruction::SPARSE_SWITCH: |
| 564 | GenSparseSwitch(mir, vB, rl_src[0]); |
| 565 | break; |
| 566 | |
| 567 | case Instruction::CMPL_FLOAT: |
| 568 | case Instruction::CMPG_FLOAT: |
| 569 | case Instruction::CMPL_DOUBLE: |
| 570 | case Instruction::CMPG_DOUBLE: |
| 571 | GenCmpFP(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 572 | break; |
| 573 | |
| 574 | case Instruction::CMP_LONG: |
| 575 | GenCmpLong(rl_dest, rl_src[0], rl_src[1]); |
| 576 | break; |
| 577 | |
| 578 | case Instruction::IF_EQ: |
| 579 | case Instruction::IF_NE: |
| 580 | case Instruction::IF_LT: |
| 581 | case Instruction::IF_GE: |
| 582 | case Instruction::IF_GT: |
| 583 | case Instruction::IF_LE: { |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 584 | if (mir_graph_->IsBackEdge(bb, bb->taken) || mir_graph_->IsBackEdge(bb, bb->fall_through)) { |
Vladimir Marko | 7ab2fce | 2014-11-28 13:38:28 +0000 | [diff] [blame] | 585 | GenSuspendTest(opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 586 | } |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 587 | LIR* taken = &label_list[bb->taken]; |
Vladimir Marko | 7ab2fce | 2014-11-28 13:38:28 +0000 | [diff] [blame] | 588 | GenCompareAndBranch(opcode, rl_src[0], rl_src[1], taken); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 589 | break; |
Ian Rogers | c35cda8 | 2014-11-10 16:34:29 -0800 | [diff] [blame] | 590 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 591 | case Instruction::IF_EQZ: |
| 592 | case Instruction::IF_NEZ: |
| 593 | case Instruction::IF_LTZ: |
| 594 | case Instruction::IF_GEZ: |
| 595 | case Instruction::IF_GTZ: |
| 596 | case Instruction::IF_LEZ: { |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 597 | if (mir_graph_->IsBackEdge(bb, bb->taken) || mir_graph_->IsBackEdge(bb, bb->fall_through)) { |
Vladimir Marko | 7ab2fce | 2014-11-28 13:38:28 +0000 | [diff] [blame] | 598 | GenSuspendTest(opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 599 | } |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 600 | LIR* taken = &label_list[bb->taken]; |
Vladimir Marko | 7ab2fce | 2014-11-28 13:38:28 +0000 | [diff] [blame] | 601 | GenCompareZeroAndBranch(opcode, rl_src[0], taken); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 602 | break; |
Ian Rogers | c35cda8 | 2014-11-10 16:34:29 -0800 | [diff] [blame] | 603 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 604 | |
| 605 | case Instruction::AGET_WIDE: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 606 | GenArrayGet(opt_flags, rl_dest.fp ? kDouble : k64, rl_src[0], rl_src[1], rl_dest, 3); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 607 | break; |
| 608 | case Instruction::AGET_OBJECT: |
| 609 | GenArrayGet(opt_flags, kReference, rl_src[0], rl_src[1], rl_dest, 2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 610 | break; |
| 611 | case Instruction::AGET: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 612 | GenArrayGet(opt_flags, rl_dest.fp ? kSingle : k32, rl_src[0], rl_src[1], rl_dest, 2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 613 | break; |
| 614 | case Instruction::AGET_BOOLEAN: |
| 615 | GenArrayGet(opt_flags, kUnsignedByte, rl_src[0], rl_src[1], rl_dest, 0); |
| 616 | break; |
| 617 | case Instruction::AGET_BYTE: |
| 618 | GenArrayGet(opt_flags, kSignedByte, rl_src[0], rl_src[1], rl_dest, 0); |
| 619 | break; |
| 620 | case Instruction::AGET_CHAR: |
| 621 | GenArrayGet(opt_flags, kUnsignedHalf, rl_src[0], rl_src[1], rl_dest, 1); |
| 622 | break; |
| 623 | case Instruction::AGET_SHORT: |
| 624 | GenArrayGet(opt_flags, kSignedHalf, rl_src[0], rl_src[1], rl_dest, 1); |
| 625 | break; |
| 626 | case Instruction::APUT_WIDE: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 627 | GenArrayPut(opt_flags, rl_src[0].fp ? kDouble : k64, rl_src[1], rl_src[2], rl_src[0], 3, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 628 | break; |
| 629 | case Instruction::APUT: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 630 | GenArrayPut(opt_flags, rl_src[0].fp ? kSingle : k32, rl_src[1], rl_src[2], rl_src[0], 2, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 631 | break; |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 632 | case Instruction::APUT_OBJECT: { |
| 633 | bool is_null = mir_graph_->IsConstantNullRef(rl_src[0]); |
| 634 | bool is_safe = is_null; // Always safe to store null. |
| 635 | if (!is_safe) { |
| 636 | // Check safety from verifier type information. |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 637 | const DexCompilationUnit* unit = mir_graph_->GetCurrentDexCompilationUnit(); |
| 638 | is_safe = cu_->compiler_driver->IsSafeCast(unit, mir->offset); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 639 | } |
| 640 | if (is_null || is_safe) { |
| 641 | // Store of constant null doesn't require an assignability test and can be generated inline |
| 642 | // without fixed register usage or a card mark. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 643 | GenArrayPut(opt_flags, kReference, rl_src[1], rl_src[2], rl_src[0], 2, !is_null); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 644 | } else { |
| 645 | GenArrayObjPut(opt_flags, rl_src[1], rl_src[2], rl_src[0]); |
| 646 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 647 | break; |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 648 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 649 | case Instruction::APUT_SHORT: |
| 650 | case Instruction::APUT_CHAR: |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 651 | GenArrayPut(opt_flags, kUnsignedHalf, rl_src[1], rl_src[2], rl_src[0], 1, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 652 | break; |
| 653 | case Instruction::APUT_BYTE: |
| 654 | case Instruction::APUT_BOOLEAN: |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 655 | GenArrayPut(opt_flags, kUnsignedByte, rl_src[1], rl_src[2], rl_src[0], 0, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | case Instruction::IGET_OBJECT: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 659 | GenIGet(mir, opt_flags, kReference, Primitive::kPrimNot, rl_dest, rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 660 | break; |
| 661 | |
| 662 | case Instruction::IGET_WIDE: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 663 | // kPrimLong and kPrimDouble share the same entrypoints. |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 664 | if (rl_dest.fp) { |
| 665 | GenIGet(mir, opt_flags, kDouble, Primitive::kPrimDouble, rl_dest, rl_src[0]); |
| 666 | } else { |
| 667 | GenIGet(mir, opt_flags, k64, Primitive::kPrimLong, rl_dest, rl_src[0]); |
| 668 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
| 671 | case Instruction::IGET: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 672 | if (rl_dest.fp) { |
| 673 | GenIGet(mir, opt_flags, kSingle, Primitive::kPrimFloat, rl_dest, rl_src[0]); |
| 674 | } else { |
| 675 | GenIGet(mir, opt_flags, k32, Primitive::kPrimInt, rl_dest, rl_src[0]); |
| 676 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 677 | break; |
| 678 | |
| 679 | case Instruction::IGET_CHAR: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 680 | GenIGet(mir, opt_flags, kUnsignedHalf, Primitive::kPrimChar, rl_dest, rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 681 | break; |
| 682 | |
| 683 | case Instruction::IGET_SHORT: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 684 | GenIGet(mir, opt_flags, kSignedHalf, Primitive::kPrimShort, rl_dest, rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 685 | break; |
| 686 | |
| 687 | case Instruction::IGET_BOOLEAN: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 688 | GenIGet(mir, opt_flags, kUnsignedByte, Primitive::kPrimBoolean, rl_dest, rl_src[0]); |
| 689 | break; |
| 690 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 691 | case Instruction::IGET_BYTE: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 692 | GenIGet(mir, opt_flags, kSignedByte, Primitive::kPrimByte, rl_dest, rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 693 | break; |
| 694 | |
| 695 | case Instruction::IPUT_WIDE: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 696 | GenIPut(mir, opt_flags, rl_src[0].fp ? kDouble : k64, rl_src[0], rl_src[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 697 | break; |
| 698 | |
| 699 | case Instruction::IPUT_OBJECT: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 700 | GenIPut(mir, opt_flags, kReference, rl_src[0], rl_src[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 701 | break; |
| 702 | |
| 703 | case Instruction::IPUT: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 704 | GenIPut(mir, opt_flags, rl_src[0].fp ? kSingle : k32, rl_src[0], rl_src[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 705 | break; |
| 706 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 707 | case Instruction::IPUT_BYTE: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 708 | case Instruction::IPUT_BOOLEAN: |
| 709 | GenIPut(mir, opt_flags, kUnsignedByte, rl_src[0], rl_src[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 710 | break; |
| 711 | |
| 712 | case Instruction::IPUT_CHAR: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 713 | GenIPut(mir, opt_flags, kUnsignedHalf, rl_src[0], rl_src[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 714 | break; |
| 715 | |
| 716 | case Instruction::IPUT_SHORT: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 717 | GenIPut(mir, opt_flags, kSignedHalf, rl_src[0], rl_src[1]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 718 | break; |
| 719 | |
| 720 | case Instruction::SGET_OBJECT: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 721 | GenSget(mir, rl_dest, kReference, Primitive::kPrimNot); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 722 | break; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 723 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 724 | case Instruction::SGET: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 725 | GenSget(mir, rl_dest, rl_dest.fp ? kSingle : k32, Primitive::kPrimInt); |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 726 | break; |
| 727 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 728 | case Instruction::SGET_CHAR: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 729 | GenSget(mir, rl_dest, kUnsignedHalf, Primitive::kPrimChar); |
| 730 | break; |
| 731 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 732 | case Instruction::SGET_SHORT: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 733 | GenSget(mir, rl_dest, kSignedHalf, Primitive::kPrimShort); |
| 734 | break; |
| 735 | |
| 736 | case Instruction::SGET_BOOLEAN: |
| 737 | GenSget(mir, rl_dest, kUnsignedByte, Primitive::kPrimBoolean); |
| 738 | break; |
| 739 | |
| 740 | case Instruction::SGET_BYTE: |
| 741 | GenSget(mir, rl_dest, kSignedByte, Primitive::kPrimByte); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 742 | break; |
| 743 | |
| 744 | case Instruction::SGET_WIDE: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 745 | // kPrimLong and kPrimDouble share the same entrypoints. |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 746 | GenSget(mir, rl_dest, rl_dest.fp ? kDouble : k64, Primitive::kPrimDouble); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 747 | break; |
| 748 | |
| 749 | case Instruction::SPUT_OBJECT: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 750 | GenSput(mir, rl_src[0], kReference); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case Instruction::SPUT: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 754 | GenSput(mir, rl_src[0], rl_src[0].fp ? kSingle : k32); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 755 | break; |
| 756 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 757 | case Instruction::SPUT_BYTE: |
| 758 | case Instruction::SPUT_BOOLEAN: |
| 759 | GenSput(mir, rl_src[0], kUnsignedByte); |
| 760 | break; |
| 761 | |
| 762 | case Instruction::SPUT_CHAR: |
| 763 | GenSput(mir, rl_src[0], kUnsignedHalf); |
| 764 | break; |
| 765 | |
| 766 | case Instruction::SPUT_SHORT: |
| 767 | GenSput(mir, rl_src[0], kSignedHalf); |
| 768 | break; |
| 769 | |
| 770 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 771 | case Instruction::SPUT_WIDE: |
Mark Mendell | ca54134 | 2014-10-15 16:59:49 -0400 | [diff] [blame] | 772 | GenSput(mir, rl_src[0], rl_src[0].fp ? kDouble : k64); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 773 | break; |
| 774 | |
| 775 | case Instruction::INVOKE_STATIC_RANGE: |
| 776 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kStatic, true)); |
| 777 | break; |
| 778 | case Instruction::INVOKE_STATIC: |
| 779 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kStatic, false)); |
| 780 | break; |
| 781 | |
| 782 | case Instruction::INVOKE_DIRECT: |
| 783 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kDirect, false)); |
| 784 | break; |
| 785 | case Instruction::INVOKE_DIRECT_RANGE: |
| 786 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kDirect, true)); |
| 787 | break; |
| 788 | |
| 789 | case Instruction::INVOKE_VIRTUAL: |
| 790 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kVirtual, false)); |
| 791 | break; |
| 792 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 793 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kVirtual, true)); |
| 794 | break; |
| 795 | |
| 796 | case Instruction::INVOKE_SUPER: |
| 797 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kSuper, false)); |
| 798 | break; |
| 799 | case Instruction::INVOKE_SUPER_RANGE: |
| 800 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kSuper, true)); |
| 801 | break; |
| 802 | |
| 803 | case Instruction::INVOKE_INTERFACE: |
| 804 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kInterface, false)); |
| 805 | break; |
| 806 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 807 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kInterface, true)); |
| 808 | break; |
| 809 | |
| 810 | case Instruction::NEG_INT: |
| 811 | case Instruction::NOT_INT: |
Razvan A Lupusoru | 5c5676b | 2014-09-29 16:42:11 -0700 | [diff] [blame] | 812 | GenArithOpInt(opcode, rl_dest, rl_src[0], rl_src[0], opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 813 | break; |
| 814 | |
| 815 | case Instruction::NEG_LONG: |
| 816 | case Instruction::NOT_LONG: |
Razvan A Lupusoru | 5c5676b | 2014-09-29 16:42:11 -0700 | [diff] [blame] | 817 | GenArithOpLong(opcode, rl_dest, rl_src[0], rl_src[0], opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | case Instruction::NEG_FLOAT: |
| 821 | GenArithOpFloat(opcode, rl_dest, rl_src[0], rl_src[0]); |
| 822 | break; |
| 823 | |
| 824 | case Instruction::NEG_DOUBLE: |
| 825 | GenArithOpDouble(opcode, rl_dest, rl_src[0], rl_src[0]); |
| 826 | break; |
| 827 | |
| 828 | case Instruction::INT_TO_LONG: |
| 829 | GenIntToLong(rl_dest, rl_src[0]); |
| 830 | break; |
| 831 | |
| 832 | case Instruction::LONG_TO_INT: |
Yevgeny Rouban | 6af8206 | 2014-11-26 18:11:54 +0600 | [diff] [blame] | 833 | GenLongToInt(rl_dest, rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 834 | break; |
| 835 | |
| 836 | case Instruction::INT_TO_BYTE: |
| 837 | case Instruction::INT_TO_SHORT: |
| 838 | case Instruction::INT_TO_CHAR: |
| 839 | GenIntNarrowing(opcode, rl_dest, rl_src[0]); |
| 840 | break; |
| 841 | |
| 842 | case Instruction::INT_TO_FLOAT: |
| 843 | case Instruction::INT_TO_DOUBLE: |
| 844 | case Instruction::LONG_TO_FLOAT: |
| 845 | case Instruction::LONG_TO_DOUBLE: |
| 846 | case Instruction::FLOAT_TO_INT: |
| 847 | case Instruction::FLOAT_TO_LONG: |
| 848 | case Instruction::FLOAT_TO_DOUBLE: |
| 849 | case Instruction::DOUBLE_TO_INT: |
| 850 | case Instruction::DOUBLE_TO_LONG: |
| 851 | case Instruction::DOUBLE_TO_FLOAT: |
| 852 | GenConversion(opcode, rl_dest, rl_src[0]); |
| 853 | break; |
| 854 | |
| 855 | |
| 856 | case Instruction::ADD_INT: |
| 857 | case Instruction::ADD_INT_2ADDR: |
| 858 | case Instruction::MUL_INT: |
| 859 | case Instruction::MUL_INT_2ADDR: |
| 860 | case Instruction::AND_INT: |
| 861 | case Instruction::AND_INT_2ADDR: |
| 862 | case Instruction::OR_INT: |
| 863 | case Instruction::OR_INT_2ADDR: |
| 864 | case Instruction::XOR_INT: |
| 865 | case Instruction::XOR_INT_2ADDR: |
| 866 | if (rl_src[0].is_const && |
Matteo Franchin | c763e35 | 2014-07-04 12:53:27 +0100 | [diff] [blame] | 867 | InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src[0]), opcode)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 868 | GenArithOpIntLit(opcode, rl_dest, rl_src[1], |
| 869 | mir_graph_->ConstantValue(rl_src[0].orig_sreg)); |
| 870 | } else if (rl_src[1].is_const && |
Matteo Franchin | c763e35 | 2014-07-04 12:53:27 +0100 | [diff] [blame] | 871 | InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src[1]), opcode)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 872 | GenArithOpIntLit(opcode, rl_dest, rl_src[0], |
| 873 | mir_graph_->ConstantValue(rl_src[1].orig_sreg)); |
| 874 | } else { |
Razvan A Lupusoru | 5c5676b | 2014-09-29 16:42:11 -0700 | [diff] [blame] | 875 | GenArithOpInt(opcode, rl_dest, rl_src[0], rl_src[1], opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 876 | } |
| 877 | break; |
| 878 | |
| 879 | case Instruction::SUB_INT: |
| 880 | case Instruction::SUB_INT_2ADDR: |
| 881 | case Instruction::DIV_INT: |
| 882 | case Instruction::DIV_INT_2ADDR: |
| 883 | case Instruction::REM_INT: |
| 884 | case Instruction::REM_INT_2ADDR: |
| 885 | case Instruction::SHL_INT: |
| 886 | case Instruction::SHL_INT_2ADDR: |
| 887 | case Instruction::SHR_INT: |
| 888 | case Instruction::SHR_INT_2ADDR: |
| 889 | case Instruction::USHR_INT: |
| 890 | case Instruction::USHR_INT_2ADDR: |
| 891 | if (rl_src[1].is_const && |
Matteo Franchin | c763e35 | 2014-07-04 12:53:27 +0100 | [diff] [blame] | 892 | InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src[1]), opcode)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 893 | GenArithOpIntLit(opcode, rl_dest, rl_src[0], mir_graph_->ConstantValue(rl_src[1])); |
| 894 | } else { |
Razvan A Lupusoru | 5c5676b | 2014-09-29 16:42:11 -0700 | [diff] [blame] | 895 | GenArithOpInt(opcode, rl_dest, rl_src[0], rl_src[1], opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 896 | } |
| 897 | break; |
| 898 | |
| 899 | case Instruction::ADD_LONG: |
| 900 | case Instruction::SUB_LONG: |
| 901 | case Instruction::AND_LONG: |
| 902 | case Instruction::OR_LONG: |
| 903 | case Instruction::XOR_LONG: |
| 904 | case Instruction::ADD_LONG_2ADDR: |
| 905 | case Instruction::SUB_LONG_2ADDR: |
| 906 | case Instruction::AND_LONG_2ADDR: |
| 907 | case Instruction::OR_LONG_2ADDR: |
| 908 | case Instruction::XOR_LONG_2ADDR: |
| 909 | if (rl_src[0].is_const || rl_src[1].is_const) { |
Razvan A Lupusoru | 5c5676b | 2014-09-29 16:42:11 -0700 | [diff] [blame] | 910 | GenArithImmOpLong(opcode, rl_dest, rl_src[0], rl_src[1], opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 911 | break; |
| 912 | } |
Ian Rogers | fc787ec | 2014-10-09 21:56:44 -0700 | [diff] [blame] | 913 | FALLTHROUGH_INTENDED; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 914 | case Instruction::MUL_LONG: |
| 915 | case Instruction::DIV_LONG: |
| 916 | case Instruction::REM_LONG: |
| 917 | case Instruction::MUL_LONG_2ADDR: |
| 918 | case Instruction::DIV_LONG_2ADDR: |
| 919 | case Instruction::REM_LONG_2ADDR: |
Razvan A Lupusoru | 5c5676b | 2014-09-29 16:42:11 -0700 | [diff] [blame] | 920 | GenArithOpLong(opcode, rl_dest, rl_src[0], rl_src[1], opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 921 | break; |
| 922 | |
| 923 | case Instruction::SHL_LONG: |
| 924 | case Instruction::SHR_LONG: |
| 925 | case Instruction::USHR_LONG: |
| 926 | case Instruction::SHL_LONG_2ADDR: |
| 927 | case Instruction::SHR_LONG_2ADDR: |
| 928 | case Instruction::USHR_LONG_2ADDR: |
| 929 | if (rl_src[1].is_const) { |
Razvan A Lupusoru | 5c5676b | 2014-09-29 16:42:11 -0700 | [diff] [blame] | 930 | GenShiftImmOpLong(opcode, rl_dest, rl_src[0], rl_src[1], opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 931 | } else { |
| 932 | GenShiftOpLong(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 933 | } |
| 934 | break; |
| 935 | |
Ningsheng Jian | 675e09b | 2014-10-23 13:48:36 +0800 | [diff] [blame] | 936 | case Instruction::DIV_FLOAT: |
| 937 | case Instruction::DIV_FLOAT_2ADDR: |
| 938 | if (HandleEasyFloatingPointDiv(rl_dest, rl_src[0], rl_src[1])) { |
| 939 | break; |
| 940 | } |
| 941 | FALLTHROUGH_INTENDED; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 942 | case Instruction::ADD_FLOAT: |
| 943 | case Instruction::SUB_FLOAT: |
| 944 | case Instruction::MUL_FLOAT: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 945 | case Instruction::REM_FLOAT: |
| 946 | case Instruction::ADD_FLOAT_2ADDR: |
| 947 | case Instruction::SUB_FLOAT_2ADDR: |
| 948 | case Instruction::MUL_FLOAT_2ADDR: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 949 | case Instruction::REM_FLOAT_2ADDR: |
| 950 | GenArithOpFloat(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 951 | break; |
| 952 | |
Ningsheng Jian | 675e09b | 2014-10-23 13:48:36 +0800 | [diff] [blame] | 953 | case Instruction::DIV_DOUBLE: |
| 954 | case Instruction::DIV_DOUBLE_2ADDR: |
| 955 | if (HandleEasyFloatingPointDiv(rl_dest, rl_src[0], rl_src[1])) { |
| 956 | break; |
| 957 | } |
| 958 | FALLTHROUGH_INTENDED; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 959 | case Instruction::ADD_DOUBLE: |
| 960 | case Instruction::SUB_DOUBLE: |
| 961 | case Instruction::MUL_DOUBLE: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 962 | case Instruction::REM_DOUBLE: |
| 963 | case Instruction::ADD_DOUBLE_2ADDR: |
| 964 | case Instruction::SUB_DOUBLE_2ADDR: |
| 965 | case Instruction::MUL_DOUBLE_2ADDR: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 966 | case Instruction::REM_DOUBLE_2ADDR: |
| 967 | GenArithOpDouble(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 968 | break; |
| 969 | |
| 970 | case Instruction::RSUB_INT: |
| 971 | case Instruction::ADD_INT_LIT16: |
| 972 | case Instruction::MUL_INT_LIT16: |
| 973 | case Instruction::DIV_INT_LIT16: |
| 974 | case Instruction::REM_INT_LIT16: |
| 975 | case Instruction::AND_INT_LIT16: |
| 976 | case Instruction::OR_INT_LIT16: |
| 977 | case Instruction::XOR_INT_LIT16: |
| 978 | case Instruction::ADD_INT_LIT8: |
| 979 | case Instruction::RSUB_INT_LIT8: |
| 980 | case Instruction::MUL_INT_LIT8: |
| 981 | case Instruction::DIV_INT_LIT8: |
| 982 | case Instruction::REM_INT_LIT8: |
| 983 | case Instruction::AND_INT_LIT8: |
| 984 | case Instruction::OR_INT_LIT8: |
| 985 | case Instruction::XOR_INT_LIT8: |
| 986 | case Instruction::SHL_INT_LIT8: |
| 987 | case Instruction::SHR_INT_LIT8: |
| 988 | case Instruction::USHR_INT_LIT8: |
| 989 | GenArithOpIntLit(opcode, rl_dest, rl_src[0], vC); |
| 990 | break; |
| 991 | |
| 992 | default: |
| 993 | LOG(FATAL) << "Unexpected opcode: " << opcode; |
| 994 | } |
buzbee | 082833c | 2014-05-17 23:16:26 -0700 | [diff] [blame] | 995 | DCHECK(CheckCorePoolSanity()); |
Brian Carlstrom | 1895ea3 | 2013-07-18 13:28:37 -0700 | [diff] [blame] | 996 | } // NOLINT(readability/fn_size) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 997 | |
| 998 | // Process extended MIR instructions |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 999 | void Mir2Lir::HandleExtendedMethodMIR(BasicBlock* bb, MIR* mir) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1000 | switch (static_cast<ExtendedMIROpcode>(mir->dalvikInsn.opcode)) { |
| 1001 | case kMirOpCopy: { |
| 1002 | RegLocation rl_src = mir_graph_->GetSrc(mir, 0); |
| 1003 | RegLocation rl_dest = mir_graph_->GetDest(mir); |
| 1004 | StoreValue(rl_dest, rl_src); |
| 1005 | break; |
| 1006 | } |
| 1007 | case kMirOpFusedCmplFloat: |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 1008 | if (mir_graph_->IsBackEdge(bb, bb->taken) || mir_graph_->IsBackEdge(bb, bb->fall_through)) { |
| 1009 | GenSuspendTest(mir->optimization_flags); |
| 1010 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1011 | GenFusedFPCmpBranch(bb, mir, false /*gt bias*/, false /*double*/); |
| 1012 | break; |
| 1013 | case kMirOpFusedCmpgFloat: |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 1014 | if (mir_graph_->IsBackEdge(bb, bb->taken) || mir_graph_->IsBackEdge(bb, bb->fall_through)) { |
| 1015 | GenSuspendTest(mir->optimization_flags); |
| 1016 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1017 | GenFusedFPCmpBranch(bb, mir, true /*gt bias*/, false /*double*/); |
| 1018 | break; |
| 1019 | case kMirOpFusedCmplDouble: |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 1020 | if (mir_graph_->IsBackEdge(bb, bb->taken) || mir_graph_->IsBackEdge(bb, bb->fall_through)) { |
| 1021 | GenSuspendTest(mir->optimization_flags); |
| 1022 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1023 | GenFusedFPCmpBranch(bb, mir, false /*gt bias*/, true /*double*/); |
| 1024 | break; |
| 1025 | case kMirOpFusedCmpgDouble: |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 1026 | if (mir_graph_->IsBackEdge(bb, bb->taken) || mir_graph_->IsBackEdge(bb, bb->fall_through)) { |
| 1027 | GenSuspendTest(mir->optimization_flags); |
| 1028 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1029 | GenFusedFPCmpBranch(bb, mir, true /*gt bias*/, true /*double*/); |
| 1030 | break; |
| 1031 | case kMirOpFusedCmpLong: |
Vladimir Marko | 8b858e1 | 2014-11-27 14:52:37 +0000 | [diff] [blame] | 1032 | if (mir_graph_->IsBackEdge(bb, bb->taken) || mir_graph_->IsBackEdge(bb, bb->fall_through)) { |
| 1033 | GenSuspendTest(mir->optimization_flags); |
| 1034 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1035 | GenFusedLongCmpBranch(bb, mir); |
| 1036 | break; |
| 1037 | case kMirOpSelect: |
| 1038 | GenSelect(bb, mir); |
| 1039 | break; |
Razvan A Lupusoru | 7642324 | 2014-08-04 09:38:46 -0700 | [diff] [blame] | 1040 | case kMirOpNullCheck: { |
| 1041 | RegLocation rl_obj = mir_graph_->GetSrc(mir, 0); |
| 1042 | rl_obj = LoadValue(rl_obj, kRefReg); |
| 1043 | // An explicit check is done because it is not expected that when this is used, |
| 1044 | // that it will actually trip up the implicit checks (since an invalid access |
| 1045 | // is needed on the null object). |
| 1046 | GenExplicitNullCheck(rl_obj.reg, mir->optimization_flags); |
| 1047 | break; |
| 1048 | } |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1049 | case kMirOpPhi: |
| 1050 | case kMirOpNop: |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1051 | case kMirOpRangeCheck: |
| 1052 | case kMirOpDivZeroCheck: |
| 1053 | case kMirOpCheck: |
| 1054 | case kMirOpCheckPart2: |
| 1055 | // Ignore these known opcodes |
| 1056 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1057 | default: |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1058 | // Give the backends a chance to handle unknown extended MIR opcodes. |
| 1059 | GenMachineSpecificExtendedMethodMIR(bb, mir); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1060 | break; |
| 1061 | } |
| 1062 | } |
| 1063 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1064 | void Mir2Lir::GenPrintLabel(MIR* mir) { |
| 1065 | // Mark the beginning of a Dalvik instruction for line tracking. |
| 1066 | if (cu_->verbose) { |
| 1067 | char* inst_str = mir_graph_->GetDalvikDisassembly(mir); |
| 1068 | MarkBoundary(mir->offset, inst_str); |
| 1069 | } |
| 1070 | } |
| 1071 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1072 | // Handle the content in each basic block. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1073 | bool Mir2Lir::MethodBlockCodeGen(BasicBlock* bb) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1074 | if (bb->block_type == kDead) return false; |
| 1075 | current_dalvik_offset_ = bb->start_offset; |
| 1076 | MIR* mir; |
| 1077 | int block_id = bb->id; |
| 1078 | |
| 1079 | block_label_list_[block_id].operands[0] = bb->start_offset; |
| 1080 | |
| 1081 | // Insert the block label. |
| 1082 | block_label_list_[block_id].opcode = kPseudoNormalBlockLabel; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 1083 | block_label_list_[block_id].flags.fixup = kFixupLabel; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1084 | AppendLIR(&block_label_list_[block_id]); |
| 1085 | |
| 1086 | LIR* head_lir = NULL; |
| 1087 | |
| 1088 | // If this is a catch block, export the start address. |
| 1089 | if (bb->catch_entry) { |
| 1090 | head_lir = NewLIR0(kPseudoExportedPC); |
| 1091 | } |
| 1092 | |
| 1093 | // Free temp registers and reset redundant store tracking. |
buzbee | ba57451 | 2014-05-12 15:13:16 -0700 | [diff] [blame] | 1094 | ClobberAllTemps(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1095 | |
| 1096 | if (bb->block_type == kEntryBlock) { |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 1097 | ResetRegPool(); |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 1098 | int start_vreg = mir_graph_->GetFirstInVR(); |
| 1099 | GenEntrySequence(&mir_graph_->reg_location_[start_vreg], mir_graph_->GetMethodLoc()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1100 | } else if (bb->block_type == kExitBlock) { |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 1101 | ResetRegPool(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1102 | GenExitSequence(); |
| 1103 | } |
| 1104 | |
| 1105 | for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 1106 | ResetRegPool(); |
| 1107 | if (cu_->disable_opt & (1 << kTrackLiveTemps)) { |
buzbee | ba57451 | 2014-05-12 15:13:16 -0700 | [diff] [blame] | 1108 | ClobberAllTemps(); |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 1109 | // Reset temp allocation to minimize differences when A/B testing. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1110 | reg_pool_->ResetNextTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | if (cu_->disable_opt & (1 << kSuppressLoads)) { |
| 1114 | ResetDefTracking(); |
| 1115 | } |
| 1116 | |
| 1117 | // Reset temp tracking sanity check. |
| 1118 | if (kIsDebugBuild) { |
| 1119 | live_sreg_ = INVALID_SREG; |
| 1120 | } |
| 1121 | |
| 1122 | current_dalvik_offset_ = mir->offset; |
| 1123 | int opcode = mir->dalvikInsn.opcode; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1124 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1125 | GenPrintLabel(mir); |
| 1126 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1127 | // Remember the first LIR for this block. |
| 1128 | if (head_lir == NULL) { |
buzbee | 252254b | 2013-09-08 16:20:53 -0700 | [diff] [blame] | 1129 | head_lir = &block_label_list_[bb->id]; |
| 1130 | // Set the first label as a scheduling barrier. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 1131 | DCHECK(!head_lir->flags.use_def_invalid); |
Vladimir Marko | 8dea81c | 2014-06-06 14:50:36 +0100 | [diff] [blame] | 1132 | head_lir->u.m.def_mask = &kEncodeAll; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | if (opcode == kMirOpCheck) { |
| 1136 | // Combine check and work halves of throwing instruction. |
| 1137 | MIR* work_half = mir->meta.throw_insn; |
Alexei Zavjalov | 56e8e60 | 2014-10-30 20:47:28 +0600 | [diff] [blame] | 1138 | mir->dalvikInsn = work_half->dalvikInsn; |
Vladimir Marko | cc8cc7c | 2014-10-06 10:52:20 +0100 | [diff] [blame] | 1139 | mir->optimization_flags = work_half->optimization_flags; |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 1140 | mir->meta = work_half->meta; // Whatever the work_half had, we need to copy it. |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1141 | opcode = work_half->dalvikInsn.opcode; |
| 1142 | SSARepresentation* ssa_rep = work_half->ssa_rep; |
| 1143 | work_half->ssa_rep = mir->ssa_rep; |
| 1144 | mir->ssa_rep = ssa_rep; |
| 1145 | work_half->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpCheckPart2); |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 1146 | work_half->meta.throw_insn = mir; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Jean Christophe Beyler | 2ab40eb | 2014-06-02 09:03:14 -0700 | [diff] [blame] | 1149 | if (MIR::DecodedInstruction::IsPseudoMirOp(opcode)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1150 | HandleExtendedMethodMIR(bb, mir); |
| 1151 | continue; |
| 1152 | } |
| 1153 | |
| 1154 | CompileDalvikInstruction(mir, bb, block_label_list_); |
| 1155 | } |
| 1156 | |
| 1157 | if (head_lir) { |
| 1158 | // Eliminate redundant loads/stores and delay stores into later slots. |
| 1159 | ApplyLocalOptimizations(head_lir, last_lir_insn_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1160 | } |
| 1161 | return false; |
| 1162 | } |
| 1163 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1164 | bool Mir2Lir::SpecialMIR2LIR(const InlineMethod& special) { |
Vladimir Marko | 5816ed4 | 2013-11-27 17:04:20 +0000 | [diff] [blame] | 1165 | cu_->NewTimingSplit("SpecialMIR2LIR"); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1166 | // Find the first DalvikByteCode block. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1167 | DCHECK_EQ(mir_graph_->GetNumReachableBlocks(), mir_graph_->GetDfsOrder().size()); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1168 | BasicBlock*bb = NULL; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1169 | for (BasicBlockId dfs_id : mir_graph_->GetDfsOrder()) { |
| 1170 | BasicBlock* candidate = mir_graph_->GetBasicBlock(dfs_id); |
| 1171 | if (candidate->block_type == kDalvikByteCode) { |
| 1172 | bb = candidate; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1173 | break; |
| 1174 | } |
| 1175 | } |
| 1176 | if (bb == NULL) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1177 | return false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1178 | } |
| 1179 | DCHECK_EQ(bb->start_offset, 0); |
| 1180 | DCHECK(bb->first_mir_insn != NULL); |
| 1181 | |
| 1182 | // Get the first instruction. |
| 1183 | MIR* mir = bb->first_mir_insn; |
| 1184 | |
| 1185 | // Free temp registers and reset redundant store tracking. |
| 1186 | ResetRegPool(); |
| 1187 | ResetDefTracking(); |
buzbee | ba57451 | 2014-05-12 15:13:16 -0700 | [diff] [blame] | 1188 | ClobberAllTemps(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1189 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1190 | return GenSpecialCase(bb, mir, special); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1191 | } |
| 1192 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1193 | void Mir2Lir::MethodMIR2LIR() { |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 1194 | cu_->NewTimingSplit("MIR2LIR"); |
| 1195 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1196 | // Hold the labels of each block. |
| 1197 | block_label_list_ = |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 1198 | static_cast<LIR*>(arena_->Alloc(sizeof(LIR) * mir_graph_->GetNumBlocks(), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 1199 | kArenaAllocLIR)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1200 | |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 1201 | PreOrderDfsIterator iter(mir_graph_); |
buzbee | 252254b | 2013-09-08 16:20:53 -0700 | [diff] [blame] | 1202 | BasicBlock* curr_bb = iter.Next(); |
| 1203 | BasicBlock* next_bb = iter.Next(); |
| 1204 | while (curr_bb != NULL) { |
| 1205 | MethodBlockCodeGen(curr_bb); |
| 1206 | // If the fall_through block is no longer laid out consecutively, drop in a branch. |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 1207 | BasicBlock* curr_bb_fall_through = mir_graph_->GetBasicBlock(curr_bb->fall_through); |
| 1208 | if ((curr_bb_fall_through != NULL) && (curr_bb_fall_through != next_bb)) { |
| 1209 | OpUnconditionalBranch(&block_label_list_[curr_bb->fall_through]); |
buzbee | 252254b | 2013-09-08 16:20:53 -0700 | [diff] [blame] | 1210 | } |
| 1211 | curr_bb = next_bb; |
| 1212 | do { |
| 1213 | next_bb = iter.Next(); |
| 1214 | } while ((next_bb != NULL) && (next_bb->block_type == kDead)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1215 | } |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1216 | HandleSlowPaths(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1217 | } |
| 1218 | |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1219 | // |
| 1220 | // LIR Slow Path |
| 1221 | // |
| 1222 | |
Mingyao Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 1223 | LIR* Mir2Lir::LIRSlowPath::GenerateTargetLabel(int opcode) { |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1224 | m2l_->SetCurrentDexPc(current_dex_pc_); |
Mingyao Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 1225 | LIR* target = m2l_->NewLIR0(opcode); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1226 | fromfast_->target = target; |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1227 | return target; |
| 1228 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1229 | |
Andreas Gampe | 4b537a8 | 2014-06-30 22:24:53 -0700 | [diff] [blame] | 1230 | |
| 1231 | void Mir2Lir::CheckRegStorageImpl(RegStorage rs, WidenessCheck wide, RefCheck ref, FPCheck fp, |
| 1232 | bool fail, bool report) |
| 1233 | const { |
| 1234 | if (rs.Valid()) { |
| 1235 | if (ref == RefCheck::kCheckRef) { |
| 1236 | if (cu_->target64 && !rs.Is64Bit()) { |
| 1237 | if (fail) { |
| 1238 | CHECK(false) << "Reg storage not 64b for ref."; |
| 1239 | } else if (report) { |
| 1240 | LOG(WARNING) << "Reg storage not 64b for ref."; |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | if (wide == WidenessCheck::kCheckWide) { |
| 1245 | if (!rs.Is64Bit()) { |
| 1246 | if (fail) { |
| 1247 | CHECK(false) << "Reg storage not 64b for wide."; |
| 1248 | } else if (report) { |
| 1249 | LOG(WARNING) << "Reg storage not 64b for wide."; |
| 1250 | } |
| 1251 | } |
| 1252 | } |
| 1253 | // A tighter check would be nice, but for now soft-float will not check float at all. |
| 1254 | if (fp == FPCheck::kCheckFP && cu_->instruction_set != kArm) { |
| 1255 | if (!rs.IsFloat()) { |
| 1256 | if (fail) { |
| 1257 | CHECK(false) << "Reg storage not float for fp."; |
| 1258 | } else if (report) { |
| 1259 | LOG(WARNING) << "Reg storage not float for fp."; |
| 1260 | } |
| 1261 | } |
| 1262 | } else if (fp == FPCheck::kCheckNotFP) { |
| 1263 | if (rs.IsFloat()) { |
| 1264 | if (fail) { |
| 1265 | CHECK(false) << "Reg storage float for not-fp."; |
| 1266 | } else if (report) { |
| 1267 | LOG(WARNING) << "Reg storage float for not-fp."; |
| 1268 | } |
| 1269 | } |
| 1270 | } |
| 1271 | } |
| 1272 | } |
| 1273 | |
| 1274 | void Mir2Lir::CheckRegLocationImpl(RegLocation rl, bool fail, bool report) const { |
| 1275 | // Regrettably can't use the fp part of rl, as that is not really indicative of where a value |
| 1276 | // will be stored. |
| 1277 | CheckRegStorageImpl(rl.reg, rl.wide ? WidenessCheck::kCheckWide : WidenessCheck::kCheckNotWide, |
| 1278 | rl.ref ? RefCheck::kCheckRef : RefCheck::kCheckNotRef, FPCheck::kIgnoreFP, fail, report); |
| 1279 | } |
| 1280 | |
Serban Constantinescu | 6399968 | 2014-07-15 17:44:21 +0100 | [diff] [blame] | 1281 | size_t Mir2Lir::GetInstructionOffset(LIR* lir) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1282 | UNUSED(lir); |
| 1283 | UNIMPLEMENTED(FATAL) << "Unsupported GetInstructionOffset()"; |
| 1284 | UNREACHABLE(); |
Serban Constantinescu | 6399968 | 2014-07-15 17:44:21 +0100 | [diff] [blame] | 1285 | } |
| 1286 | |
Serguei Katkov | 717a3e4 | 2014-11-13 17:19:42 +0600 | [diff] [blame] | 1287 | void Mir2Lir::InToRegStorageMapping::Initialize(ShortyIterator* shorty, |
| 1288 | InToRegStorageMapper* mapper) { |
| 1289 | DCHECK(mapper != nullptr); |
| 1290 | DCHECK(shorty != nullptr); |
| 1291 | max_mapped_in_ = -1; |
| 1292 | has_arguments_on_stack_ = false; |
| 1293 | while (shorty->Next()) { |
| 1294 | ShortyArg arg = shorty->GetArg(); |
| 1295 | RegStorage reg = mapper->GetNextReg(arg); |
| 1296 | if (reg.Valid()) { |
| 1297 | mapping_.Put(count_, reg); |
| 1298 | max_mapped_in_ = count_; |
| 1299 | // If the VR is wide and was mapped as wide then account for it. |
| 1300 | if (arg.IsWide() && reg.Is64Bit()) { |
| 1301 | max_mapped_in_++; |
| 1302 | } |
| 1303 | } else { |
| 1304 | has_arguments_on_stack_ = true; |
| 1305 | } |
| 1306 | count_ += arg.IsWide() ? 2 : 1; |
| 1307 | } |
| 1308 | initialized_ = true; |
| 1309 | } |
| 1310 | |
| 1311 | RegStorage Mir2Lir::InToRegStorageMapping::Get(int in_position) { |
| 1312 | DCHECK(IsInitialized()); |
| 1313 | DCHECK_LT(in_position, count_); |
| 1314 | auto res = mapping_.find(in_position); |
| 1315 | return res != mapping_.end() ? res->second : RegStorage::InvalidReg(); |
| 1316 | } |
| 1317 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1318 | } // namespace art |