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" |
| 21 | #include "object_utils.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 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 56 | void Mir2Lir::LockArg(int in_position, bool wide) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 57 | RegStorage reg_arg_low = GetArgMappingToPhysicalReg(in_position); |
| 58 | RegStorage reg_arg_high = wide ? GetArgMappingToPhysicalReg(in_position + 1) : |
| 59 | RegStorage::InvalidReg(); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 60 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 61 | if (reg_arg_low.Valid()) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 62 | LockTemp(reg_arg_low); |
| 63 | } |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 64 | if (reg_arg_high.Valid() && reg_arg_low != reg_arg_high) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 65 | LockTemp(reg_arg_high); |
| 66 | } |
| 67 | } |
| 68 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 69 | // TODO: needs revisit for 64-bit. |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 70 | RegStorage Mir2Lir::LoadArg(int in_position, RegisterClass reg_class, bool wide) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 71 | RegStorage reg_arg_low = GetArgMappingToPhysicalReg(in_position); |
| 72 | RegStorage reg_arg_high = wide ? GetArgMappingToPhysicalReg(in_position + 1) : |
| 73 | RegStorage::InvalidReg(); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 74 | |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 75 | int offset = StackVisitor::GetOutVROffset(in_position, cu_->instruction_set); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 76 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 77 | /* |
| 78 | * When doing a call for x86, it moves the stack pointer in order to push return. |
| 79 | * Thus, we add another 4 bytes to figure out the out of caller (in of callee). |
| 80 | * TODO: This needs revisited for 64-bit. |
| 81 | */ |
| 82 | offset += sizeof(uint32_t); |
| 83 | } |
| 84 | |
| 85 | // If the VR is wide and there is no register for high part, we need to load it. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 86 | if (wide && !reg_arg_high.Valid()) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 87 | // If the low part is not in a reg, we allocate a pair. Otherwise, we just load to high reg. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 88 | if (!reg_arg_low.Valid()) { |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 89 | RegStorage new_regs = AllocTypedTempWide(false, reg_class); |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 90 | LoadBaseDisp(TargetReg(kSp), offset, new_regs, k64); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 91 | return new_regs; // The reg_class is OK, we can return. |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 92 | } else { |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 93 | // Assume that no ABI allows splitting a wide fp reg between a narrow fp reg and memory, |
| 94 | // i.e. the low part is in a core reg. Load the second part in a core reg as well for now. |
| 95 | DCHECK(!reg_arg_low.IsFloat()); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 96 | reg_arg_high = AllocTemp(); |
| 97 | int offset_high = offset + sizeof(uint32_t); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 98 | Load32Disp(TargetReg(kSp), offset_high, reg_arg_high); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 99 | // Continue below to check the reg_class. |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
| 103 | // If the low part is not in a register yet, we need to load it. |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 104 | if (!reg_arg_low.Valid()) { |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 105 | // Assume that if the low part of a wide arg is passed in memory, so is the high part, |
| 106 | // thus we don't get here for wide args as it's handled above. Big-endian ABIs could |
| 107 | // conceivably break this assumption but Android supports only little-endian architectures. |
| 108 | DCHECK(!wide); |
| 109 | reg_arg_low = AllocTypedTemp(false, reg_class); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 110 | Load32Disp(TargetReg(kSp), offset, reg_arg_low); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 111 | return reg_arg_low; // The reg_class is OK, we can return. |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 114 | RegStorage reg_arg = wide ? RegStorage::MakeRegPair(reg_arg_low, reg_arg_high) : reg_arg_low; |
| 115 | // Check if we need to copy the arg to a different reg_class. |
| 116 | if (!RegClassMatches(reg_class, reg_arg)) { |
| 117 | if (wide) { |
| 118 | RegStorage new_regs = AllocTypedTempWide(false, reg_class); |
| 119 | OpRegCopyWide(new_regs, reg_arg); |
| 120 | reg_arg = new_regs; |
| 121 | } else { |
| 122 | RegStorage new_reg = AllocTypedTemp(false, reg_class); |
| 123 | OpRegCopy(new_reg, reg_arg); |
| 124 | reg_arg = new_reg; |
| 125 | } |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 126 | } |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 127 | return reg_arg; |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | void Mir2Lir::LoadArgDirect(int in_position, RegLocation rl_dest) { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 131 | int offset = StackVisitor::GetOutVROffset(in_position, cu_->instruction_set); |
Dmitry Petrochenko | 6a58cb1 | 2014-04-02 17:27:59 +0700 | [diff] [blame] | 132 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 133 | /* |
| 134 | * When doing a call for x86, it moves the stack pointer in order to push return. |
| 135 | * Thus, we add another 4 bytes to figure out the out of caller (in of callee). |
| 136 | * TODO: This needs revisited for 64-bit. |
| 137 | */ |
| 138 | offset += sizeof(uint32_t); |
| 139 | } |
| 140 | |
| 141 | if (!rl_dest.wide) { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 142 | RegStorage reg = GetArgMappingToPhysicalReg(in_position); |
| 143 | if (reg.Valid()) { |
| 144 | OpRegCopy(rl_dest.reg, reg); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 145 | } else { |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 146 | Load32Disp(TargetReg(kSp), offset, rl_dest.reg); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 147 | } |
| 148 | } else { |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 149 | RegStorage reg_arg_low = GetArgMappingToPhysicalReg(in_position); |
| 150 | RegStorage reg_arg_high = GetArgMappingToPhysicalReg(in_position + 1); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 151 | |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 152 | if (reg_arg_low.Valid() && reg_arg_high.Valid()) { |
| 153 | OpRegCopyWide(rl_dest.reg, RegStorage::MakeRegPair(reg_arg_low, reg_arg_high)); |
| 154 | } else if (reg_arg_low.Valid() && !reg_arg_high.Valid()) { |
| 155 | OpRegCopy(rl_dest.reg, reg_arg_low); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 156 | int offset_high = offset + sizeof(uint32_t); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 157 | Load32Disp(TargetReg(kSp), offset_high, rl_dest.reg.GetHigh()); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 158 | } else if (!reg_arg_low.Valid() && reg_arg_high.Valid()) { |
| 159 | OpRegCopy(rl_dest.reg.GetHigh(), reg_arg_high); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 160 | Load32Disp(TargetReg(kSp), offset, rl_dest.reg.GetLow()); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 161 | } else { |
Vladimir Marko | 3bf7c60 | 2014-05-07 14:55:43 +0100 | [diff] [blame] | 162 | LoadBaseDisp(TargetReg(kSp), offset, rl_dest.reg, k64); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | bool Mir2Lir::GenSpecialIGet(MIR* mir, const InlineMethod& special) { |
| 168 | // FastInstance() already checked by DexFileMethodInliner. |
| 169 | const InlineIGetIPutData& data = special.d.ifield_data; |
Vladimir Marko | e1fced1 | 2014-04-04 14:52:53 +0100 | [diff] [blame] | 170 | if (data.method_is_static != 0u || data.object_arg != 0u) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 171 | // The object is not "this" and has to be null-checked. |
| 172 | return false; |
| 173 | } |
| 174 | |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 175 | bool wide = (data.op_variant == InlineMethodAnalyser::IGetVariant(Instruction::IGET_WIDE)); |
Vladimir Marko | 455759b | 2014-05-06 20:49:36 +0100 | [diff] [blame] | 176 | bool ref = (data.op_variant == InlineMethodAnalyser::IGetVariant(Instruction::IGET_OBJECT)); |
| 177 | OpSize size = LoadStoreOpSize(wide, ref); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 178 | if (data.is_volatile && !SupportsVolatileLoadStore(size)) { |
| 179 | return false; |
| 180 | } |
Vladimir Marko | 455759b | 2014-05-06 20:49:36 +0100 | [diff] [blame] | 181 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 182 | // Point of no return - no aborts after this |
| 183 | GenPrintLabel(mir); |
| 184 | LockArg(data.object_arg); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 185 | RegStorage reg_obj = LoadArg(data.object_arg, kRefReg); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 186 | RegisterClass reg_class = RegClassForFieldLoadStore(size, data.is_volatile); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 187 | RegisterClass ret_reg_class = ShortyToRegClass(cu_->shorty[0]); |
| 188 | RegLocation rl_dest = wide ? GetReturnWide(ret_reg_class) : GetReturn(ret_reg_class); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 189 | RegStorage r_result = rl_dest.reg; |
| 190 | if (!RegClassMatches(reg_class, r_result)) { |
| 191 | r_result = wide ? AllocTypedTempWide(rl_dest.fp, reg_class) |
| 192 | : AllocTypedTemp(rl_dest.fp, reg_class); |
| 193 | } |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 194 | if (data.is_volatile) { |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 195 | LoadBaseDispVolatile(reg_obj, data.field_offset, r_result, size); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 196 | // Without context sensitive analysis, we must issue the most conservative barriers. |
| 197 | // In this case, either a load or store may follow so we issue both barriers. |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 198 | GenMemBarrier(kLoadLoad); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 199 | GenMemBarrier(kLoadStore); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 200 | } else { |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 201 | LoadBaseDisp(reg_obj, data.field_offset, r_result, size); |
| 202 | } |
| 203 | if (r_result != rl_dest.reg) { |
| 204 | if (wide) { |
| 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 | |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 225 | bool wide = (data.op_variant == InlineMethodAnalyser::IPutVariant(Instruction::IPUT_WIDE)); |
Vladimir Marko | 455759b | 2014-05-06 20:49:36 +0100 | [diff] [blame] | 226 | bool ref = (data.op_variant == InlineMethodAnalyser::IGetVariant(Instruction::IGET_OBJECT)); |
| 227 | OpSize size = LoadStoreOpSize(wide, ref); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 228 | if (data.is_volatile && !SupportsVolatileLoadStore(size)) { |
| 229 | return false; |
| 230 | } |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 231 | |
| 232 | // Point of no return - no aborts after this |
| 233 | GenPrintLabel(mir); |
| 234 | LockArg(data.object_arg); |
| 235 | LockArg(data.src_arg, wide); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 236 | RegStorage reg_obj = LoadArg(data.object_arg, kRefReg); |
Vladimir Marko | c93ac8b | 2014-05-13 17:53:49 +0100 | [diff] [blame] | 237 | RegisterClass reg_class = RegClassForFieldLoadStore(size, data.is_volatile); |
| 238 | RegStorage reg_src = LoadArg(data.src_arg, reg_class, wide); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 239 | if (data.is_volatile) { |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 240 | // There might have been a store before this volatile one so insert StoreStore barrier. |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 241 | GenMemBarrier(kStoreStore); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 242 | StoreBaseDispVolatile(reg_obj, data.field_offset, reg_src, size); |
Razvan A Lupusoru | 99ad723 | 2014-02-25 17:41:08 -0800 | [diff] [blame] | 243 | // A load might follow the volatile store so insert a StoreLoad barrier. |
| 244 | GenMemBarrier(kStoreLoad); |
Vladimir Marko | 674744e | 2014-04-24 15:18:26 +0100 | [diff] [blame] | 245 | } else { |
| 246 | StoreBaseDisp(reg_obj, data.field_offset, reg_src, size); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 247 | } |
Vladimir Marko | 455759b | 2014-05-06 20:49:36 +0100 | [diff] [blame] | 248 | if (ref) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 249 | MarkGCCard(reg_src, reg_obj); |
| 250 | } |
| 251 | return true; |
| 252 | } |
| 253 | |
| 254 | bool Mir2Lir::GenSpecialIdentity(MIR* mir, const InlineMethod& special) { |
| 255 | const InlineReturnArgData& data = special.d.return_data; |
Vladimir Marko | e3e0260 | 2014-03-12 15:42:41 +0000 | [diff] [blame] | 256 | bool wide = (data.is_wide != 0u); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 257 | |
| 258 | // Point of no return - no aborts after this |
| 259 | GenPrintLabel(mir); |
| 260 | LockArg(data.arg, wide); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 261 | RegisterClass reg_class = ShortyToRegClass(cu_->shorty[0]); |
| 262 | RegLocation rl_dest = wide ? GetReturnWide(reg_class) : GetReturn(reg_class); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 263 | LoadArgDirect(data.arg, rl_dest); |
| 264 | return true; |
| 265 | } |
| 266 | |
| 267 | /* |
| 268 | * Special-case code generation for simple non-throwing leaf methods. |
| 269 | */ |
| 270 | bool Mir2Lir::GenSpecialCase(BasicBlock* bb, MIR* mir, const InlineMethod& special) { |
| 271 | DCHECK(special.flags & kInlineSpecial); |
| 272 | current_dalvik_offset_ = mir->offset; |
| 273 | MIR* return_mir = nullptr; |
| 274 | bool successful = false; |
| 275 | |
| 276 | switch (special.opcode) { |
| 277 | case kInlineOpNop: |
| 278 | successful = true; |
| 279 | DCHECK_EQ(mir->dalvikInsn.opcode, Instruction::RETURN_VOID); |
| 280 | return_mir = mir; |
| 281 | break; |
| 282 | case kInlineOpNonWideConst: { |
| 283 | successful = true; |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 284 | RegLocation rl_dest = GetReturn(ShortyToRegClass(cu_->shorty[0])); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 285 | GenPrintLabel(mir); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 286 | LoadConstant(rl_dest.reg, static_cast<int>(special.d.data)); |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 287 | return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 288 | break; |
| 289 | } |
| 290 | case kInlineOpReturnArg: |
| 291 | successful = GenSpecialIdentity(mir, special); |
| 292 | return_mir = mir; |
| 293 | break; |
| 294 | case kInlineOpIGet: |
| 295 | successful = GenSpecialIGet(mir, special); |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 296 | return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 297 | break; |
| 298 | case kInlineOpIPut: |
| 299 | successful = GenSpecialIPut(mir, special); |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 300 | return_mir = bb->GetNextUnconditionalMir(mir_graph_, mir); |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 301 | break; |
| 302 | default: |
| 303 | break; |
| 304 | } |
| 305 | |
| 306 | if (successful) { |
Vladimir Marko | 39d95e6 | 2014-02-28 12:51:24 +0000 | [diff] [blame] | 307 | if (kIsDebugBuild) { |
| 308 | // Clear unreachable catch entries. |
| 309 | mir_graph_->catches_.clear(); |
| 310 | } |
| 311 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 312 | // Handle verbosity for return MIR. |
| 313 | if (return_mir != nullptr) { |
| 314 | current_dalvik_offset_ = return_mir->offset; |
| 315 | // Not handling special identity case because it already generated code as part |
| 316 | // of the return. The label should have been added before any code was generated. |
| 317 | if (special.opcode != kInlineOpReturnArg) { |
| 318 | GenPrintLabel(return_mir); |
| 319 | } |
| 320 | } |
| 321 | GenSpecialExitSequence(); |
| 322 | |
| 323 | core_spill_mask_ = 0; |
| 324 | num_core_spills_ = 0; |
| 325 | fp_spill_mask_ = 0; |
| 326 | num_fp_spills_ = 0; |
| 327 | frame_size_ = 0; |
| 328 | core_vmap_table_.clear(); |
| 329 | fp_vmap_table_.clear(); |
| 330 | } |
| 331 | |
| 332 | return successful; |
| 333 | } |
| 334 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 335 | /* |
| 336 | * Target-independent code generation. Use only high-level |
| 337 | * load/store utilities here, or target-dependent genXX() handlers |
| 338 | * when necessary. |
| 339 | */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 340 | void Mir2Lir::CompileDalvikInstruction(MIR* mir, BasicBlock* bb, LIR* label_list) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 341 | RegLocation rl_src[3]; |
| 342 | RegLocation rl_dest = mir_graph_->GetBadLoc(); |
| 343 | RegLocation rl_result = mir_graph_->GetBadLoc(); |
| 344 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
| 345 | int opt_flags = mir->optimization_flags; |
| 346 | uint32_t vB = mir->dalvikInsn.vB; |
| 347 | uint32_t vC = mir->dalvikInsn.vC; |
buzbee | 082833c | 2014-05-17 23:16:26 -0700 | [diff] [blame] | 348 | DCHECK(CheckCorePoolSanity()) << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " @ 0x:" |
| 349 | << std::hex << current_dalvik_offset_; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 350 | |
| 351 | // Prep Src and Dest locations. |
| 352 | int next_sreg = 0; |
| 353 | int next_loc = 0; |
Jean Christophe Beyler | cc794c3 | 2014-05-02 09:34:13 -0700 | [diff] [blame] | 354 | uint64_t attrs = MIRGraph::GetDataFlowAttributes(opcode); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 355 | rl_src[0] = rl_src[1] = rl_src[2] = mir_graph_->GetBadLoc(); |
| 356 | if (attrs & DF_UA) { |
| 357 | if (attrs & DF_A_WIDE) { |
| 358 | rl_src[next_loc++] = mir_graph_->GetSrcWide(mir, next_sreg); |
| 359 | next_sreg+= 2; |
| 360 | } else { |
| 361 | rl_src[next_loc++] = mir_graph_->GetSrc(mir, next_sreg); |
| 362 | next_sreg++; |
| 363 | } |
| 364 | } |
| 365 | if (attrs & DF_UB) { |
| 366 | if (attrs & DF_B_WIDE) { |
| 367 | rl_src[next_loc++] = mir_graph_->GetSrcWide(mir, next_sreg); |
| 368 | next_sreg+= 2; |
| 369 | } else { |
| 370 | rl_src[next_loc++] = mir_graph_->GetSrc(mir, next_sreg); |
| 371 | next_sreg++; |
| 372 | } |
| 373 | } |
| 374 | if (attrs & DF_UC) { |
| 375 | if (attrs & DF_C_WIDE) { |
| 376 | rl_src[next_loc++] = mir_graph_->GetSrcWide(mir, next_sreg); |
| 377 | } else { |
| 378 | rl_src[next_loc++] = mir_graph_->GetSrc(mir, next_sreg); |
| 379 | } |
| 380 | } |
| 381 | if (attrs & DF_DA) { |
| 382 | if (attrs & DF_A_WIDE) { |
| 383 | rl_dest = mir_graph_->GetDestWide(mir); |
| 384 | } else { |
| 385 | rl_dest = mir_graph_->GetDest(mir); |
| 386 | } |
| 387 | } |
| 388 | switch (opcode) { |
| 389 | case Instruction::NOP: |
| 390 | break; |
| 391 | |
| 392 | case Instruction::MOVE_EXCEPTION: |
| 393 | GenMoveException(rl_dest); |
| 394 | break; |
| 395 | |
| 396 | case Instruction::RETURN_VOID: |
| 397 | if (((cu_->access_flags & kAccConstructor) != 0) && |
| 398 | cu_->compiler_driver->RequiresConstructorBarrier(Thread::Current(), cu_->dex_file, |
| 399 | cu_->class_def_idx)) { |
| 400 | GenMemBarrier(kStoreStore); |
| 401 | } |
| 402 | if (!mir_graph_->MethodIsLeaf()) { |
| 403 | GenSuspendTest(opt_flags); |
| 404 | } |
| 405 | break; |
| 406 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 407 | case Instruction::RETURN_OBJECT: |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 408 | DCHECK(rl_src[0].ref); |
| 409 | // Intentional fallthrough. |
| 410 | case Instruction::RETURN: |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 411 | if (!mir_graph_->MethodIsLeaf()) { |
| 412 | GenSuspendTest(opt_flags); |
| 413 | } |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 414 | DCHECK_EQ(LocToRegClass(rl_src[0]), ShortyToRegClass(cu_->shorty[0])); |
| 415 | StoreValue(GetReturn(LocToRegClass(rl_src[0])), rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 416 | break; |
| 417 | |
| 418 | case Instruction::RETURN_WIDE: |
| 419 | if (!mir_graph_->MethodIsLeaf()) { |
| 420 | GenSuspendTest(opt_flags); |
| 421 | } |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 422 | DCHECK_EQ(LocToRegClass(rl_src[0]), ShortyToRegClass(cu_->shorty[0])); |
| 423 | StoreValueWide(GetReturnWide(LocToRegClass(rl_src[0])), rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 424 | break; |
| 425 | |
| 426 | case Instruction::MOVE_RESULT_WIDE: |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 427 | if ((opt_flags & MIR_INLINED) != 0) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 428 | break; // Nop - combined w/ previous invoke. |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 429 | } |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 430 | StoreValueWide(rl_dest, GetReturnWide(LocToRegClass(rl_dest))); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 431 | break; |
| 432 | |
| 433 | case Instruction::MOVE_RESULT: |
| 434 | case Instruction::MOVE_RESULT_OBJECT: |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 435 | if ((opt_flags & MIR_INLINED) != 0) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 436 | break; // Nop - combined w/ previous invoke. |
Vladimir Marko | 9820b7c | 2014-01-02 16:40:37 +0000 | [diff] [blame] | 437 | } |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 438 | StoreValue(rl_dest, GetReturn(LocToRegClass(rl_dest))); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 439 | break; |
| 440 | |
| 441 | case Instruction::MOVE: |
| 442 | case Instruction::MOVE_OBJECT: |
| 443 | case Instruction::MOVE_16: |
| 444 | case Instruction::MOVE_OBJECT_16: |
| 445 | case Instruction::MOVE_FROM16: |
| 446 | case Instruction::MOVE_OBJECT_FROM16: |
| 447 | StoreValue(rl_dest, rl_src[0]); |
| 448 | break; |
| 449 | |
| 450 | case Instruction::MOVE_WIDE: |
| 451 | case Instruction::MOVE_WIDE_16: |
| 452 | case Instruction::MOVE_WIDE_FROM16: |
| 453 | StoreValueWide(rl_dest, rl_src[0]); |
| 454 | break; |
| 455 | |
| 456 | case Instruction::CONST: |
| 457 | case Instruction::CONST_4: |
| 458 | case Instruction::CONST_16: |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 459 | GenConst(rl_dest, vB); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 460 | break; |
| 461 | |
| 462 | case Instruction::CONST_HIGH16: |
Mark Mendell | e87f9b5 | 2014-04-30 14:13:18 -0400 | [diff] [blame] | 463 | GenConst(rl_dest, vB << 16); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 464 | break; |
| 465 | |
| 466 | case Instruction::CONST_WIDE_16: |
| 467 | case Instruction::CONST_WIDE_32: |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 468 | GenConstWide(rl_dest, static_cast<int64_t>(static_cast<int32_t>(vB))); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 469 | break; |
| 470 | |
| 471 | case Instruction::CONST_WIDE: |
Bill Buzbee | d61ba4b | 2014-01-13 21:44:01 +0000 | [diff] [blame] | 472 | GenConstWide(rl_dest, mir->dalvikInsn.vB_wide); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 473 | break; |
| 474 | |
| 475 | case Instruction::CONST_WIDE_HIGH16: |
| 476 | rl_result = EvalLoc(rl_dest, kAnyReg, true); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 477 | LoadConstantWide(rl_result.reg, static_cast<int64_t>(vB) << 48); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 478 | StoreValueWide(rl_dest, rl_result); |
| 479 | break; |
| 480 | |
| 481 | case Instruction::MONITOR_ENTER: |
| 482 | GenMonitorEnter(opt_flags, rl_src[0]); |
| 483 | break; |
| 484 | |
| 485 | case Instruction::MONITOR_EXIT: |
| 486 | GenMonitorExit(opt_flags, rl_src[0]); |
| 487 | break; |
| 488 | |
| 489 | case Instruction::CHECK_CAST: { |
| 490 | GenCheckCast(mir->offset, vB, rl_src[0]); |
| 491 | break; |
| 492 | } |
| 493 | case Instruction::INSTANCE_OF: |
| 494 | GenInstanceof(vC, rl_dest, rl_src[0]); |
| 495 | break; |
| 496 | |
| 497 | case Instruction::NEW_INSTANCE: |
| 498 | GenNewInstance(vB, rl_dest); |
| 499 | break; |
| 500 | |
| 501 | case Instruction::THROW: |
| 502 | GenThrow(rl_src[0]); |
| 503 | break; |
| 504 | |
| 505 | case Instruction::ARRAY_LENGTH: |
| 506 | int len_offset; |
| 507 | len_offset = mirror::Array::LengthOffset().Int32Value(); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 508 | rl_src[0] = LoadValue(rl_src[0], kRefReg); |
buzbee | 2700f7e | 2014-03-07 09:46:20 -0800 | [diff] [blame] | 509 | GenNullCheck(rl_src[0].reg, opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 510 | rl_result = EvalLoc(rl_dest, kCoreReg, true); |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 511 | Load32Disp(rl_src[0].reg, len_offset, rl_result.reg); |
Dave Allison | f943914 | 2014-03-27 15:10:22 -0700 | [diff] [blame] | 512 | MarkPossibleNullPointerException(opt_flags); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 513 | StoreValue(rl_dest, rl_result); |
| 514 | break; |
| 515 | |
| 516 | case Instruction::CONST_STRING: |
| 517 | case Instruction::CONST_STRING_JUMBO: |
| 518 | GenConstString(vB, rl_dest); |
| 519 | break; |
| 520 | |
| 521 | case Instruction::CONST_CLASS: |
| 522 | GenConstClass(vB, rl_dest); |
| 523 | break; |
| 524 | |
| 525 | case Instruction::FILL_ARRAY_DATA: |
| 526 | GenFillArrayData(vB, rl_src[0]); |
| 527 | break; |
| 528 | |
| 529 | case Instruction::FILLED_NEW_ARRAY: |
| 530 | GenFilledNewArray(mir_graph_->NewMemCallInfo(bb, mir, kStatic, |
| 531 | false /* not range */)); |
| 532 | break; |
| 533 | |
| 534 | case Instruction::FILLED_NEW_ARRAY_RANGE: |
| 535 | GenFilledNewArray(mir_graph_->NewMemCallInfo(bb, mir, kStatic, |
| 536 | true /* range */)); |
| 537 | break; |
| 538 | |
| 539 | case Instruction::NEW_ARRAY: |
| 540 | GenNewArray(vC, rl_dest, rl_src[0]); |
| 541 | break; |
| 542 | |
| 543 | case Instruction::GOTO: |
| 544 | case Instruction::GOTO_16: |
| 545 | case Instruction::GOTO_32: |
buzbee | 9329e6d | 2013-08-19 12:55:10 -0700 | [diff] [blame] | 546 | if (mir_graph_->IsBackedge(bb, bb->taken)) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 547 | GenSuspendTestAndBranch(opt_flags, &label_list[bb->taken]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 548 | } else { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 549 | OpUnconditionalBranch(&label_list[bb->taken]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 550 | } |
| 551 | break; |
| 552 | |
| 553 | case Instruction::PACKED_SWITCH: |
| 554 | GenPackedSwitch(mir, vB, rl_src[0]); |
| 555 | break; |
| 556 | |
| 557 | case Instruction::SPARSE_SWITCH: |
| 558 | GenSparseSwitch(mir, vB, rl_src[0]); |
| 559 | break; |
| 560 | |
| 561 | case Instruction::CMPL_FLOAT: |
| 562 | case Instruction::CMPG_FLOAT: |
| 563 | case Instruction::CMPL_DOUBLE: |
| 564 | case Instruction::CMPG_DOUBLE: |
| 565 | GenCmpFP(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 566 | break; |
| 567 | |
| 568 | case Instruction::CMP_LONG: |
| 569 | GenCmpLong(rl_dest, rl_src[0], rl_src[1]); |
| 570 | break; |
| 571 | |
| 572 | case Instruction::IF_EQ: |
| 573 | case Instruction::IF_NE: |
| 574 | case Instruction::IF_LT: |
| 575 | case Instruction::IF_GE: |
| 576 | case Instruction::IF_GT: |
| 577 | case Instruction::IF_LE: { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 578 | LIR* taken = &label_list[bb->taken]; |
| 579 | LIR* fall_through = &label_list[bb->fall_through]; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 580 | // Result known at compile time? |
| 581 | if (rl_src[0].is_const && rl_src[1].is_const) { |
| 582 | bool is_taken = EvaluateBranch(opcode, mir_graph_->ConstantValue(rl_src[0].orig_sreg), |
| 583 | mir_graph_->ConstantValue(rl_src[1].orig_sreg)); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 584 | BasicBlockId target_id = is_taken ? bb->taken : bb->fall_through; |
| 585 | if (mir_graph_->IsBackedge(bb, target_id)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 586 | GenSuspendTest(opt_flags); |
| 587 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 588 | OpUnconditionalBranch(&label_list[target_id]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 589 | } else { |
buzbee | 9329e6d | 2013-08-19 12:55:10 -0700 | [diff] [blame] | 590 | if (mir_graph_->IsBackwardsBranch(bb)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 591 | GenSuspendTest(opt_flags); |
| 592 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 593 | GenCompareAndBranch(opcode, rl_src[0], rl_src[1], taken, fall_through); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 594 | } |
| 595 | break; |
| 596 | } |
| 597 | |
| 598 | case Instruction::IF_EQZ: |
| 599 | case Instruction::IF_NEZ: |
| 600 | case Instruction::IF_LTZ: |
| 601 | case Instruction::IF_GEZ: |
| 602 | case Instruction::IF_GTZ: |
| 603 | case Instruction::IF_LEZ: { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 604 | LIR* taken = &label_list[bb->taken]; |
| 605 | LIR* fall_through = &label_list[bb->fall_through]; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 606 | // Result known at compile time? |
| 607 | if (rl_src[0].is_const) { |
| 608 | bool is_taken = EvaluateBranch(opcode, mir_graph_->ConstantValue(rl_src[0].orig_sreg), 0); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 609 | BasicBlockId target_id = is_taken ? bb->taken : bb->fall_through; |
| 610 | if (mir_graph_->IsBackedge(bb, target_id)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 611 | GenSuspendTest(opt_flags); |
| 612 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 613 | OpUnconditionalBranch(&label_list[target_id]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 614 | } else { |
buzbee | 9329e6d | 2013-08-19 12:55:10 -0700 | [diff] [blame] | 615 | if (mir_graph_->IsBackwardsBranch(bb)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 616 | GenSuspendTest(opt_flags); |
| 617 | } |
| 618 | GenCompareZeroAndBranch(opcode, rl_src[0], taken, fall_through); |
| 619 | } |
| 620 | break; |
| 621 | } |
| 622 | |
| 623 | case Instruction::AGET_WIDE: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 624 | GenArrayGet(opt_flags, k64, rl_src[0], rl_src[1], rl_dest, 3); |
| 625 | break; |
| 626 | case Instruction::AGET_OBJECT: |
| 627 | 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] | 628 | break; |
| 629 | case Instruction::AGET: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 630 | GenArrayGet(opt_flags, k32, rl_src[0], rl_src[1], rl_dest, 2); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 631 | break; |
| 632 | case Instruction::AGET_BOOLEAN: |
| 633 | GenArrayGet(opt_flags, kUnsignedByte, rl_src[0], rl_src[1], rl_dest, 0); |
| 634 | break; |
| 635 | case Instruction::AGET_BYTE: |
| 636 | GenArrayGet(opt_flags, kSignedByte, rl_src[0], rl_src[1], rl_dest, 0); |
| 637 | break; |
| 638 | case Instruction::AGET_CHAR: |
| 639 | GenArrayGet(opt_flags, kUnsignedHalf, rl_src[0], rl_src[1], rl_dest, 1); |
| 640 | break; |
| 641 | case Instruction::AGET_SHORT: |
| 642 | GenArrayGet(opt_flags, kSignedHalf, rl_src[0], rl_src[1], rl_dest, 1); |
| 643 | break; |
| 644 | case Instruction::APUT_WIDE: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 645 | GenArrayPut(opt_flags, k64, rl_src[1], rl_src[2], rl_src[0], 3, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 646 | break; |
| 647 | case Instruction::APUT: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 648 | GenArrayPut(opt_flags, k32, rl_src[1], rl_src[2], rl_src[0], 2, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 649 | break; |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 650 | case Instruction::APUT_OBJECT: { |
| 651 | bool is_null = mir_graph_->IsConstantNullRef(rl_src[0]); |
| 652 | bool is_safe = is_null; // Always safe to store null. |
| 653 | if (!is_safe) { |
| 654 | // Check safety from verifier type information. |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 655 | const DexCompilationUnit* unit = mir_graph_->GetCurrentDexCompilationUnit(); |
| 656 | is_safe = cu_->compiler_driver->IsSafeCast(unit, mir->offset); |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 657 | } |
| 658 | if (is_null || is_safe) { |
| 659 | // Store of constant null doesn't require an assignability test and can be generated inline |
| 660 | // without fixed register usage or a card mark. |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 661 | 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] | 662 | } else { |
| 663 | GenArrayObjPut(opt_flags, rl_src[1], rl_src[2], rl_src[0]); |
| 664 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 665 | break; |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 666 | } |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 667 | case Instruction::APUT_SHORT: |
| 668 | case Instruction::APUT_CHAR: |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 669 | 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] | 670 | break; |
| 671 | case Instruction::APUT_BYTE: |
| 672 | case Instruction::APUT_BOOLEAN: |
Ian Rogers | a9a8254 | 2013-10-04 11:17:26 -0700 | [diff] [blame] | 673 | 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] | 674 | break; |
| 675 | |
| 676 | case Instruction::IGET_OBJECT: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 677 | GenIGet(mir, opt_flags, kReference, rl_dest, rl_src[0], false, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 678 | break; |
| 679 | |
| 680 | case Instruction::IGET_WIDE: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 681 | GenIGet(mir, opt_flags, k64, rl_dest, rl_src[0], true, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 682 | break; |
| 683 | |
| 684 | case Instruction::IGET: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 685 | GenIGet(mir, opt_flags, k32, rl_dest, rl_src[0], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 686 | break; |
| 687 | |
| 688 | case Instruction::IGET_CHAR: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 689 | GenIGet(mir, opt_flags, kUnsignedHalf, rl_dest, rl_src[0], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 690 | break; |
| 691 | |
| 692 | case Instruction::IGET_SHORT: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 693 | GenIGet(mir, opt_flags, kSignedHalf, rl_dest, rl_src[0], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 694 | break; |
| 695 | |
| 696 | case Instruction::IGET_BOOLEAN: |
| 697 | case Instruction::IGET_BYTE: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 698 | GenIGet(mir, opt_flags, kUnsignedByte, rl_dest, rl_src[0], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 699 | break; |
| 700 | |
| 701 | case Instruction::IPUT_WIDE: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 702 | GenIPut(mir, opt_flags, k64, rl_src[0], rl_src[1], true, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 703 | break; |
| 704 | |
| 705 | case Instruction::IPUT_OBJECT: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 706 | GenIPut(mir, opt_flags, kReference, rl_src[0], rl_src[1], false, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 707 | break; |
| 708 | |
| 709 | case Instruction::IPUT: |
buzbee | 695d13a | 2014-04-19 13:32:20 -0700 | [diff] [blame] | 710 | GenIPut(mir, opt_flags, k32, rl_src[0], rl_src[1], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 711 | break; |
| 712 | |
| 713 | case Instruction::IPUT_BOOLEAN: |
| 714 | case Instruction::IPUT_BYTE: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 715 | GenIPut(mir, opt_flags, kUnsignedByte, rl_src[0], rl_src[1], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 716 | break; |
| 717 | |
| 718 | case Instruction::IPUT_CHAR: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 719 | GenIPut(mir, opt_flags, kUnsignedHalf, rl_src[0], rl_src[1], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 720 | break; |
| 721 | |
| 722 | case Instruction::IPUT_SHORT: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 723 | GenIPut(mir, opt_flags, kSignedHalf, rl_src[0], rl_src[1], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 724 | break; |
| 725 | |
| 726 | case Instruction::SGET_OBJECT: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 727 | GenSget(mir, rl_dest, false, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 728 | break; |
| 729 | case Instruction::SGET: |
| 730 | case Instruction::SGET_BOOLEAN: |
| 731 | case Instruction::SGET_BYTE: |
| 732 | case Instruction::SGET_CHAR: |
| 733 | case Instruction::SGET_SHORT: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 734 | GenSget(mir, rl_dest, false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 735 | break; |
| 736 | |
| 737 | case Instruction::SGET_WIDE: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 738 | GenSget(mir, rl_dest, true, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 739 | break; |
| 740 | |
| 741 | case Instruction::SPUT_OBJECT: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 742 | GenSput(mir, rl_src[0], false, true); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case Instruction::SPUT: |
| 746 | case Instruction::SPUT_BOOLEAN: |
| 747 | case Instruction::SPUT_BYTE: |
| 748 | case Instruction::SPUT_CHAR: |
| 749 | case Instruction::SPUT_SHORT: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 750 | GenSput(mir, rl_src[0], false, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 751 | break; |
| 752 | |
| 753 | case Instruction::SPUT_WIDE: |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 754 | GenSput(mir, rl_src[0], true, false); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 755 | break; |
| 756 | |
| 757 | case Instruction::INVOKE_STATIC_RANGE: |
| 758 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kStatic, true)); |
| 759 | break; |
| 760 | case Instruction::INVOKE_STATIC: |
| 761 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kStatic, false)); |
| 762 | break; |
| 763 | |
| 764 | case Instruction::INVOKE_DIRECT: |
| 765 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kDirect, false)); |
| 766 | break; |
| 767 | case Instruction::INVOKE_DIRECT_RANGE: |
| 768 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kDirect, true)); |
| 769 | break; |
| 770 | |
| 771 | case Instruction::INVOKE_VIRTUAL: |
| 772 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kVirtual, false)); |
| 773 | break; |
| 774 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 775 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kVirtual, true)); |
| 776 | break; |
| 777 | |
| 778 | case Instruction::INVOKE_SUPER: |
| 779 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kSuper, false)); |
| 780 | break; |
| 781 | case Instruction::INVOKE_SUPER_RANGE: |
| 782 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kSuper, true)); |
| 783 | break; |
| 784 | |
| 785 | case Instruction::INVOKE_INTERFACE: |
| 786 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kInterface, false)); |
| 787 | break; |
| 788 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 789 | GenInvoke(mir_graph_->NewMemCallInfo(bb, mir, kInterface, true)); |
| 790 | break; |
| 791 | |
| 792 | case Instruction::NEG_INT: |
| 793 | case Instruction::NOT_INT: |
| 794 | GenArithOpInt(opcode, rl_dest, rl_src[0], rl_src[0]); |
| 795 | break; |
| 796 | |
| 797 | case Instruction::NEG_LONG: |
| 798 | case Instruction::NOT_LONG: |
| 799 | GenArithOpLong(opcode, rl_dest, rl_src[0], rl_src[0]); |
| 800 | break; |
| 801 | |
| 802 | case Instruction::NEG_FLOAT: |
| 803 | GenArithOpFloat(opcode, rl_dest, rl_src[0], rl_src[0]); |
| 804 | break; |
| 805 | |
| 806 | case Instruction::NEG_DOUBLE: |
| 807 | GenArithOpDouble(opcode, rl_dest, rl_src[0], rl_src[0]); |
| 808 | break; |
| 809 | |
| 810 | case Instruction::INT_TO_LONG: |
| 811 | GenIntToLong(rl_dest, rl_src[0]); |
| 812 | break; |
| 813 | |
| 814 | case Instruction::LONG_TO_INT: |
| 815 | rl_src[0] = UpdateLocWide(rl_src[0]); |
buzbee | a0cd2d7 | 2014-06-01 09:33:49 -0700 | [diff] [blame] | 816 | rl_src[0] = NarrowRegLoc(rl_src[0]); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 817 | StoreValue(rl_dest, rl_src[0]); |
| 818 | break; |
| 819 | |
| 820 | case Instruction::INT_TO_BYTE: |
| 821 | case Instruction::INT_TO_SHORT: |
| 822 | case Instruction::INT_TO_CHAR: |
| 823 | GenIntNarrowing(opcode, rl_dest, rl_src[0]); |
| 824 | break; |
| 825 | |
| 826 | case Instruction::INT_TO_FLOAT: |
| 827 | case Instruction::INT_TO_DOUBLE: |
| 828 | case Instruction::LONG_TO_FLOAT: |
| 829 | case Instruction::LONG_TO_DOUBLE: |
| 830 | case Instruction::FLOAT_TO_INT: |
| 831 | case Instruction::FLOAT_TO_LONG: |
| 832 | case Instruction::FLOAT_TO_DOUBLE: |
| 833 | case Instruction::DOUBLE_TO_INT: |
| 834 | case Instruction::DOUBLE_TO_LONG: |
| 835 | case Instruction::DOUBLE_TO_FLOAT: |
| 836 | GenConversion(opcode, rl_dest, rl_src[0]); |
| 837 | break; |
| 838 | |
| 839 | |
| 840 | case Instruction::ADD_INT: |
| 841 | case Instruction::ADD_INT_2ADDR: |
| 842 | case Instruction::MUL_INT: |
| 843 | case Instruction::MUL_INT_2ADDR: |
| 844 | case Instruction::AND_INT: |
| 845 | case Instruction::AND_INT_2ADDR: |
| 846 | case Instruction::OR_INT: |
| 847 | case Instruction::OR_INT_2ADDR: |
| 848 | case Instruction::XOR_INT: |
| 849 | case Instruction::XOR_INT_2ADDR: |
| 850 | if (rl_src[0].is_const && |
| 851 | InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src[0]))) { |
| 852 | GenArithOpIntLit(opcode, rl_dest, rl_src[1], |
| 853 | mir_graph_->ConstantValue(rl_src[0].orig_sreg)); |
| 854 | } else if (rl_src[1].is_const && |
| 855 | InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src[1]))) { |
| 856 | GenArithOpIntLit(opcode, rl_dest, rl_src[0], |
| 857 | mir_graph_->ConstantValue(rl_src[1].orig_sreg)); |
| 858 | } else { |
| 859 | GenArithOpInt(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 860 | } |
| 861 | break; |
| 862 | |
| 863 | case Instruction::SUB_INT: |
| 864 | case Instruction::SUB_INT_2ADDR: |
| 865 | case Instruction::DIV_INT: |
| 866 | case Instruction::DIV_INT_2ADDR: |
| 867 | case Instruction::REM_INT: |
| 868 | case Instruction::REM_INT_2ADDR: |
| 869 | case Instruction::SHL_INT: |
| 870 | case Instruction::SHL_INT_2ADDR: |
| 871 | case Instruction::SHR_INT: |
| 872 | case Instruction::SHR_INT_2ADDR: |
| 873 | case Instruction::USHR_INT: |
| 874 | case Instruction::USHR_INT_2ADDR: |
| 875 | if (rl_src[1].is_const && |
| 876 | InexpensiveConstantInt(mir_graph_->ConstantValue(rl_src[1]))) { |
| 877 | GenArithOpIntLit(opcode, rl_dest, rl_src[0], mir_graph_->ConstantValue(rl_src[1])); |
| 878 | } else { |
| 879 | GenArithOpInt(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 880 | } |
| 881 | break; |
| 882 | |
| 883 | case Instruction::ADD_LONG: |
| 884 | case Instruction::SUB_LONG: |
| 885 | case Instruction::AND_LONG: |
| 886 | case Instruction::OR_LONG: |
| 887 | case Instruction::XOR_LONG: |
| 888 | case Instruction::ADD_LONG_2ADDR: |
| 889 | case Instruction::SUB_LONG_2ADDR: |
| 890 | case Instruction::AND_LONG_2ADDR: |
| 891 | case Instruction::OR_LONG_2ADDR: |
| 892 | case Instruction::XOR_LONG_2ADDR: |
| 893 | if (rl_src[0].is_const || rl_src[1].is_const) { |
| 894 | GenArithImmOpLong(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 895 | break; |
| 896 | } |
| 897 | // Note: intentional fallthrough. |
| 898 | |
| 899 | case Instruction::MUL_LONG: |
| 900 | case Instruction::DIV_LONG: |
| 901 | case Instruction::REM_LONG: |
| 902 | case Instruction::MUL_LONG_2ADDR: |
| 903 | case Instruction::DIV_LONG_2ADDR: |
| 904 | case Instruction::REM_LONG_2ADDR: |
| 905 | GenArithOpLong(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 906 | break; |
| 907 | |
| 908 | case Instruction::SHL_LONG: |
| 909 | case Instruction::SHR_LONG: |
| 910 | case Instruction::USHR_LONG: |
| 911 | case Instruction::SHL_LONG_2ADDR: |
| 912 | case Instruction::SHR_LONG_2ADDR: |
| 913 | case Instruction::USHR_LONG_2ADDR: |
| 914 | if (rl_src[1].is_const) { |
| 915 | GenShiftImmOpLong(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 916 | } else { |
| 917 | GenShiftOpLong(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 918 | } |
| 919 | break; |
| 920 | |
| 921 | case Instruction::ADD_FLOAT: |
| 922 | case Instruction::SUB_FLOAT: |
| 923 | case Instruction::MUL_FLOAT: |
| 924 | case Instruction::DIV_FLOAT: |
| 925 | case Instruction::REM_FLOAT: |
| 926 | case Instruction::ADD_FLOAT_2ADDR: |
| 927 | case Instruction::SUB_FLOAT_2ADDR: |
| 928 | case Instruction::MUL_FLOAT_2ADDR: |
| 929 | case Instruction::DIV_FLOAT_2ADDR: |
| 930 | case Instruction::REM_FLOAT_2ADDR: |
| 931 | GenArithOpFloat(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 932 | break; |
| 933 | |
| 934 | case Instruction::ADD_DOUBLE: |
| 935 | case Instruction::SUB_DOUBLE: |
| 936 | case Instruction::MUL_DOUBLE: |
| 937 | case Instruction::DIV_DOUBLE: |
| 938 | case Instruction::REM_DOUBLE: |
| 939 | case Instruction::ADD_DOUBLE_2ADDR: |
| 940 | case Instruction::SUB_DOUBLE_2ADDR: |
| 941 | case Instruction::MUL_DOUBLE_2ADDR: |
| 942 | case Instruction::DIV_DOUBLE_2ADDR: |
| 943 | case Instruction::REM_DOUBLE_2ADDR: |
| 944 | GenArithOpDouble(opcode, rl_dest, rl_src[0], rl_src[1]); |
| 945 | break; |
| 946 | |
| 947 | case Instruction::RSUB_INT: |
| 948 | case Instruction::ADD_INT_LIT16: |
| 949 | case Instruction::MUL_INT_LIT16: |
| 950 | case Instruction::DIV_INT_LIT16: |
| 951 | case Instruction::REM_INT_LIT16: |
| 952 | case Instruction::AND_INT_LIT16: |
| 953 | case Instruction::OR_INT_LIT16: |
| 954 | case Instruction::XOR_INT_LIT16: |
| 955 | case Instruction::ADD_INT_LIT8: |
| 956 | case Instruction::RSUB_INT_LIT8: |
| 957 | case Instruction::MUL_INT_LIT8: |
| 958 | case Instruction::DIV_INT_LIT8: |
| 959 | case Instruction::REM_INT_LIT8: |
| 960 | case Instruction::AND_INT_LIT8: |
| 961 | case Instruction::OR_INT_LIT8: |
| 962 | case Instruction::XOR_INT_LIT8: |
| 963 | case Instruction::SHL_INT_LIT8: |
| 964 | case Instruction::SHR_INT_LIT8: |
| 965 | case Instruction::USHR_INT_LIT8: |
| 966 | GenArithOpIntLit(opcode, rl_dest, rl_src[0], vC); |
| 967 | break; |
| 968 | |
| 969 | default: |
| 970 | LOG(FATAL) << "Unexpected opcode: " << opcode; |
| 971 | } |
buzbee | 082833c | 2014-05-17 23:16:26 -0700 | [diff] [blame] | 972 | DCHECK(CheckCorePoolSanity()); |
Brian Carlstrom | 1895ea3 | 2013-07-18 13:28:37 -0700 | [diff] [blame] | 973 | } // NOLINT(readability/fn_size) |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 974 | |
| 975 | // Process extended MIR instructions |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 976 | void Mir2Lir::HandleExtendedMethodMIR(BasicBlock* bb, MIR* mir) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 977 | switch (static_cast<ExtendedMIROpcode>(mir->dalvikInsn.opcode)) { |
| 978 | case kMirOpCopy: { |
| 979 | RegLocation rl_src = mir_graph_->GetSrc(mir, 0); |
| 980 | RegLocation rl_dest = mir_graph_->GetDest(mir); |
| 981 | StoreValue(rl_dest, rl_src); |
| 982 | break; |
| 983 | } |
| 984 | case kMirOpFusedCmplFloat: |
| 985 | GenFusedFPCmpBranch(bb, mir, false /*gt bias*/, false /*double*/); |
| 986 | break; |
| 987 | case kMirOpFusedCmpgFloat: |
| 988 | GenFusedFPCmpBranch(bb, mir, true /*gt bias*/, false /*double*/); |
| 989 | break; |
| 990 | case kMirOpFusedCmplDouble: |
| 991 | GenFusedFPCmpBranch(bb, mir, false /*gt bias*/, true /*double*/); |
| 992 | break; |
| 993 | case kMirOpFusedCmpgDouble: |
| 994 | GenFusedFPCmpBranch(bb, mir, true /*gt bias*/, true /*double*/); |
| 995 | break; |
| 996 | case kMirOpFusedCmpLong: |
| 997 | GenFusedLongCmpBranch(bb, mir); |
| 998 | break; |
| 999 | case kMirOpSelect: |
| 1000 | GenSelect(bb, mir); |
| 1001 | break; |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1002 | case kMirOpPhi: |
| 1003 | case kMirOpNop: |
| 1004 | case kMirOpNullCheck: |
| 1005 | case kMirOpRangeCheck: |
| 1006 | case kMirOpDivZeroCheck: |
| 1007 | case kMirOpCheck: |
| 1008 | case kMirOpCheckPart2: |
| 1009 | // Ignore these known opcodes |
| 1010 | break; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1011 | default: |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 1012 | // Give the backends a chance to handle unknown extended MIR opcodes. |
| 1013 | GenMachineSpecificExtendedMethodMIR(bb, mir); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1014 | break; |
| 1015 | } |
| 1016 | } |
| 1017 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1018 | void Mir2Lir::GenPrintLabel(MIR* mir) { |
| 1019 | // Mark the beginning of a Dalvik instruction for line tracking. |
| 1020 | if (cu_->verbose) { |
| 1021 | char* inst_str = mir_graph_->GetDalvikDisassembly(mir); |
| 1022 | MarkBoundary(mir->offset, inst_str); |
| 1023 | } |
| 1024 | } |
| 1025 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1026 | // Handle the content in each basic block. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1027 | bool Mir2Lir::MethodBlockCodeGen(BasicBlock* bb) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1028 | if (bb->block_type == kDead) return false; |
| 1029 | current_dalvik_offset_ = bb->start_offset; |
| 1030 | MIR* mir; |
| 1031 | int block_id = bb->id; |
| 1032 | |
| 1033 | block_label_list_[block_id].operands[0] = bb->start_offset; |
| 1034 | |
| 1035 | // Insert the block label. |
| 1036 | block_label_list_[block_id].opcode = kPseudoNormalBlockLabel; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 1037 | block_label_list_[block_id].flags.fixup = kFixupLabel; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1038 | AppendLIR(&block_label_list_[block_id]); |
| 1039 | |
| 1040 | LIR* head_lir = NULL; |
| 1041 | |
| 1042 | // If this is a catch block, export the start address. |
| 1043 | if (bb->catch_entry) { |
| 1044 | head_lir = NewLIR0(kPseudoExportedPC); |
| 1045 | } |
| 1046 | |
| 1047 | // Free temp registers and reset redundant store tracking. |
buzbee | ba57451 | 2014-05-12 15:13:16 -0700 | [diff] [blame] | 1048 | ClobberAllTemps(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1049 | |
| 1050 | if (bb->block_type == kEntryBlock) { |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 1051 | ResetRegPool(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1052 | int start_vreg = cu_->num_dalvik_registers - cu_->num_ins; |
| 1053 | GenEntrySequence(&mir_graph_->reg_location_[start_vreg], |
| 1054 | mir_graph_->reg_location_[mir_graph_->GetMethodSReg()]); |
| 1055 | } else if (bb->block_type == kExitBlock) { |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 1056 | ResetRegPool(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1057 | GenExitSequence(); |
| 1058 | } |
| 1059 | |
| 1060 | for (mir = bb->first_mir_insn; mir != NULL; mir = mir->next) { |
| 1061 | ResetRegPool(); |
| 1062 | if (cu_->disable_opt & (1 << kTrackLiveTemps)) { |
buzbee | ba57451 | 2014-05-12 15:13:16 -0700 | [diff] [blame] | 1063 | ClobberAllTemps(); |
buzbee | 7a11ab0 | 2014-04-28 20:02:38 -0700 | [diff] [blame] | 1064 | // Reset temp allocation to minimize differences when A/B testing. |
buzbee | 091cc40 | 2014-03-31 10:14:40 -0700 | [diff] [blame] | 1065 | reg_pool_->ResetNextTemp(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | if (cu_->disable_opt & (1 << kSuppressLoads)) { |
| 1069 | ResetDefTracking(); |
| 1070 | } |
| 1071 | |
| 1072 | // Reset temp tracking sanity check. |
| 1073 | if (kIsDebugBuild) { |
| 1074 | live_sreg_ = INVALID_SREG; |
| 1075 | } |
| 1076 | |
| 1077 | current_dalvik_offset_ = mir->offset; |
| 1078 | int opcode = mir->dalvikInsn.opcode; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1079 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1080 | GenPrintLabel(mir); |
| 1081 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1082 | // Remember the first LIR for this block. |
| 1083 | if (head_lir == NULL) { |
buzbee | 252254b | 2013-09-08 16:20:53 -0700 | [diff] [blame] | 1084 | head_lir = &block_label_list_[bb->id]; |
| 1085 | // Set the first label as a scheduling barrier. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 1086 | DCHECK(!head_lir->flags.use_def_invalid); |
| 1087 | head_lir->u.m.def_mask = ENCODE_ALL; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | if (opcode == kMirOpCheck) { |
| 1091 | // Combine check and work halves of throwing instruction. |
| 1092 | MIR* work_half = mir->meta.throw_insn; |
| 1093 | mir->dalvikInsn.opcode = work_half->dalvikInsn.opcode; |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 1094 | 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] | 1095 | opcode = work_half->dalvikInsn.opcode; |
| 1096 | SSARepresentation* ssa_rep = work_half->ssa_rep; |
| 1097 | work_half->ssa_rep = mir->ssa_rep; |
| 1098 | mir->ssa_rep = ssa_rep; |
| 1099 | work_half->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpCheckPart2); |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 1100 | work_half->meta.throw_insn = mir; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1101 | } |
| 1102 | |
buzbee | 35ba7f3 | 2014-05-31 08:59:01 -0700 | [diff] [blame] | 1103 | if (MIRGraph::IsPseudoMirOp(opcode)) { |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1104 | HandleExtendedMethodMIR(bb, mir); |
| 1105 | continue; |
| 1106 | } |
| 1107 | |
| 1108 | CompileDalvikInstruction(mir, bb, block_label_list_); |
| 1109 | } |
| 1110 | |
| 1111 | if (head_lir) { |
| 1112 | // Eliminate redundant loads/stores and delay stores into later slots. |
| 1113 | ApplyLocalOptimizations(head_lir, last_lir_insn_); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1114 | } |
| 1115 | return false; |
| 1116 | } |
| 1117 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1118 | bool Mir2Lir::SpecialMIR2LIR(const InlineMethod& special) { |
Vladimir Marko | 5816ed4 | 2013-11-27 17:04:20 +0000 | [diff] [blame] | 1119 | cu_->NewTimingSplit("SpecialMIR2LIR"); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1120 | // Find the first DalvikByteCode block. |
| 1121 | int num_reachable_blocks = mir_graph_->GetNumReachableBlocks(); |
| 1122 | BasicBlock*bb = NULL; |
| 1123 | for (int idx = 0; idx < num_reachable_blocks; idx++) { |
| 1124 | // TODO: no direct access of growable lists. |
| 1125 | int dfs_index = mir_graph_->GetDfsOrder()->Get(idx); |
| 1126 | bb = mir_graph_->GetBasicBlock(dfs_index); |
| 1127 | if (bb->block_type == kDalvikByteCode) { |
| 1128 | break; |
| 1129 | } |
| 1130 | } |
| 1131 | if (bb == NULL) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1132 | return false; |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1133 | } |
| 1134 | DCHECK_EQ(bb->start_offset, 0); |
| 1135 | DCHECK(bb->first_mir_insn != NULL); |
| 1136 | |
| 1137 | // Get the first instruction. |
| 1138 | MIR* mir = bb->first_mir_insn; |
| 1139 | |
| 1140 | // Free temp registers and reset redundant store tracking. |
| 1141 | ResetRegPool(); |
| 1142 | ResetDefTracking(); |
buzbee | ba57451 | 2014-05-12 15:13:16 -0700 | [diff] [blame] | 1143 | ClobberAllTemps(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1144 | |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1145 | return GenSpecialCase(bb, mir, special); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1148 | void Mir2Lir::MethodMIR2LIR() { |
buzbee | a61f495 | 2013-08-23 14:27:06 -0700 | [diff] [blame] | 1149 | cu_->NewTimingSplit("MIR2LIR"); |
| 1150 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1151 | // Hold the labels of each block. |
| 1152 | block_label_list_ = |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 1153 | static_cast<LIR*>(arena_->Alloc(sizeof(LIR) * mir_graph_->GetNumBlocks(), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 1154 | kArenaAllocLIR)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1155 | |
buzbee | 56c7178 | 2013-09-05 17:13:19 -0700 | [diff] [blame] | 1156 | PreOrderDfsIterator iter(mir_graph_); |
buzbee | 252254b | 2013-09-08 16:20:53 -0700 | [diff] [blame] | 1157 | BasicBlock* curr_bb = iter.Next(); |
| 1158 | BasicBlock* next_bb = iter.Next(); |
| 1159 | while (curr_bb != NULL) { |
| 1160 | MethodBlockCodeGen(curr_bb); |
| 1161 | // 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] | 1162 | BasicBlock* curr_bb_fall_through = mir_graph_->GetBasicBlock(curr_bb->fall_through); |
| 1163 | if ((curr_bb_fall_through != NULL) && (curr_bb_fall_through != next_bb)) { |
| 1164 | OpUnconditionalBranch(&block_label_list_[curr_bb->fall_through]); |
buzbee | 252254b | 2013-09-08 16:20:53 -0700 | [diff] [blame] | 1165 | } |
| 1166 | curr_bb = next_bb; |
| 1167 | do { |
| 1168 | next_bb = iter.Next(); |
| 1169 | } while ((next_bb != NULL) && (next_bb->block_type == kDead)); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1170 | } |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1171 | HandleSlowPaths(); |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1174 | // |
| 1175 | // LIR Slow Path |
| 1176 | // |
| 1177 | |
Mingyao Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 1178 | LIR* Mir2Lir::LIRSlowPath::GenerateTargetLabel(int opcode) { |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1179 | m2l_->SetCurrentDexPc(current_dex_pc_); |
Mingyao Yang | 6ffcfa0 | 2014-04-25 11:06:00 -0700 | [diff] [blame] | 1180 | LIR* target = m2l_->NewLIR0(opcode); |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1181 | fromfast_->target = target; |
Dave Allison | bcec6fb | 2014-01-17 12:52:22 -0800 | [diff] [blame] | 1182 | return target; |
| 1183 | } |
Vladimir Marko | 3bc8615 | 2014-03-13 14:11:28 +0000 | [diff] [blame] | 1184 | |
Brian Carlstrom | 7940e44 | 2013-07-12 13:46:57 -0700 | [diff] [blame] | 1185 | } // namespace art |