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