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