buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
Nicolas Geoffray | f3e2cc4 | 2014-02-18 18:37:26 +0000 | [diff] [blame] | 17 | #include "mir_graph.h" |
| 18 | |
| 19 | #include <inttypes.h> |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 20 | #include <queue> |
Nicolas Geoffray | f3e2cc4 | 2014-02-18 18:37:26 +0000 | [diff] [blame] | 21 | |
Ian Rogers | e77493c | 2014-08-20 15:08:45 -0700 | [diff] [blame] | 22 | #include "base/bit_vector-inl.h" |
Ian Rogers | 6282dc1 | 2013-04-18 15:54:02 -0700 | [diff] [blame] | 23 | #include "base/stl_util.h" |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 24 | #include "compiler_internals.h" |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 25 | #include "dex_file-inl.h" |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 26 | #include "dex_instruction-inl.h" |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 27 | #include "dex/global_value_numbering.h" |
Vladimir Marko | 5816ed4 | 2013-11-27 17:04:20 +0000 | [diff] [blame] | 28 | #include "dex/quick/dex_file_to_method_inliner_map.h" |
| 29 | #include "dex/quick/dex_file_method_inliner.h" |
Nicolas Geoffray | f3e2cc4 | 2014-02-18 18:37:26 +0000 | [diff] [blame] | 30 | #include "leb128.h" |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 31 | #include "pass_driver_me_post_opt.h" |
Andreas Gampe | 53c913b | 2014-08-12 23:19:23 -0700 | [diff] [blame] | 32 | #include "stack.h" |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 33 | #include "utils/scoped_arena_containers.h" |
Vladimir Marko | 5816ed4 | 2013-11-27 17:04:20 +0000 | [diff] [blame] | 34 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 35 | namespace art { |
| 36 | |
| 37 | #define MAX_PATTERN_LEN 5 |
| 38 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 39 | const char* MIRGraph::extended_mir_op_names_[kMirOpLast - kMirOpFirst] = { |
| 40 | "Phi", |
| 41 | "Copy", |
| 42 | "FusedCmplFloat", |
| 43 | "FusedCmpgFloat", |
| 44 | "FusedCmplDouble", |
| 45 | "FusedCmpgDouble", |
| 46 | "FusedCmpLong", |
| 47 | "Nop", |
| 48 | "OpNullCheck", |
| 49 | "OpRangeCheck", |
| 50 | "OpDivZeroCheck", |
| 51 | "Check1", |
| 52 | "Check2", |
| 53 | "Select", |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 54 | "ConstVector", |
| 55 | "MoveVector", |
| 56 | "PackedMultiply", |
| 57 | "PackedAddition", |
| 58 | "PackedSubtract", |
| 59 | "PackedShiftLeft", |
| 60 | "PackedSignedShiftRight", |
| 61 | "PackedUnsignedShiftRight", |
| 62 | "PackedAnd", |
| 63 | "PackedOr", |
| 64 | "PackedXor", |
| 65 | "PackedAddReduce", |
| 66 | "PackedReduce", |
| 67 | "PackedSet", |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 68 | "ReserveVectorRegisters", |
| 69 | "ReturnVectorRegisters", |
Jean Christophe Beyler | b5bce7c | 2014-07-25 12:32:18 -0700 | [diff] [blame] | 70 | "MemBarrier", |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 71 | "PackedArrayGet", |
| 72 | "PackedArrayPut", |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 73 | }; |
| 74 | |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 75 | MIRGraph::MIRGraph(CompilationUnit* cu, ArenaAllocator* arena) |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 76 | : reg_location_(NULL), |
Vladimir Marko | 8081d2b | 2014-07-31 15:33:43 +0100 | [diff] [blame] | 77 | block_id_map_(std::less<unsigned int>(), arena->Adapter()), |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 78 | cu_(cu), |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 79 | ssa_base_vregs_(arena->Adapter(kArenaAllocSSAToDalvikMap)), |
| 80 | ssa_subscripts_(arena->Adapter(kArenaAllocSSAToDalvikMap)), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 81 | vreg_to_ssa_map_(NULL), |
| 82 | ssa_last_defs_(NULL), |
| 83 | is_constant_v_(NULL), |
| 84 | constant_values_(NULL), |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 85 | use_counts_(arena->Adapter()), |
| 86 | raw_use_counts_(arena->Adapter()), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 87 | num_reachable_blocks_(0), |
Jean Christophe Beyler | 4896d7b | 2014-05-01 15:36:22 -0700 | [diff] [blame] | 88 | max_num_reachable_blocks_(0), |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 89 | dfs_order_(arena->Adapter(kArenaAllocDfsPreOrder)), |
| 90 | dfs_post_order_(arena->Adapter(kArenaAllocDfsPostOrder)), |
| 91 | dom_post_order_traversal_(arena->Adapter(kArenaAllocDomPostOrder)), |
| 92 | topological_order_(arena->Adapter(kArenaAllocTopologicalSortOrder)), |
| 93 | topological_order_loop_ends_(arena->Adapter(kArenaAllocTopologicalSortOrder)), |
| 94 | topological_order_indexes_(arena->Adapter(kArenaAllocTopologicalSortOrder)), |
| 95 | topological_order_loop_head_stack_(arena->Adapter(kArenaAllocTopologicalSortOrder)), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 96 | i_dom_list_(NULL), |
Vladimir Marko | bfea9c2 | 2014-01-17 17:49:33 +0000 | [diff] [blame] | 97 | temp_scoped_alloc_(), |
| 98 | temp_insn_data_(nullptr), |
| 99 | temp_bit_vector_size_(0u), |
| 100 | temp_bit_vector_(nullptr), |
Vladimir Marko | 5229cf1 | 2014-10-09 14:57:59 +0100 | [diff] [blame^] | 101 | temp_bit_matrix_(nullptr), |
Vladimir Marko | 95a0597 | 2014-05-30 10:01:32 +0100 | [diff] [blame] | 102 | temp_gvn_(), |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 103 | block_list_(arena->Adapter(kArenaAllocBBList)), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 104 | try_block_addr_(NULL), |
| 105 | entry_block_(NULL), |
| 106 | exit_block_(NULL), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 107 | num_blocks_(0), |
| 108 | current_code_item_(NULL), |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 109 | dex_pc_to_block_map_(arena->Adapter()), |
Vladimir Marko | 8081d2b | 2014-07-31 15:33:43 +0100 | [diff] [blame] | 110 | m_units_(arena->Adapter()), |
| 111 | method_stack_(arena->Adapter()), |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 112 | current_method_(kInvalidEntry), |
| 113 | current_offset_(kInvalidEntry), |
| 114 | def_count_(0), |
| 115 | opcode_count_(NULL), |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 116 | num_ssa_regs_(0), |
Vladimir Marko | 8081d2b | 2014-07-31 15:33:43 +0100 | [diff] [blame] | 117 | extended_basic_blocks_(arena->Adapter()), |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 118 | method_sreg_(0), |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 119 | attributes_(METHOD_IS_LEAF), // Start with leaf assumption, change on encountering invoke. |
| 120 | checkstats_(NULL), |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 121 | arena_(arena), |
| 122 | backward_branches_(0), |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 123 | forward_branches_(0), |
Razvan A Lupusoru | da7a69b | 2014-01-08 15:09:50 -0800 | [diff] [blame] | 124 | num_non_special_compiler_temps_(0), |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 125 | max_available_special_compiler_temps_(1), // We only need the method ptr as a special temp for now. |
| 126 | requested_backend_temp_(false), |
| 127 | compiler_temps_committed_(false), |
Vladimir Marko | be0e546 | 2014-02-26 11:24:15 +0000 | [diff] [blame] | 128 | punt_to_interpreter_(false), |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 129 | merged_df_flags_(0u), |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 130 | ifield_lowering_infos_(arena->Adapter(kArenaAllocLoweringInfo)), |
| 131 | sfield_lowering_infos_(arena->Adapter(kArenaAllocLoweringInfo)), |
| 132 | method_lowering_infos_(arena->Adapter(kArenaAllocLoweringInfo)), |
| 133 | gen_suspend_test_list_(arena->Adapter()) { |
| 134 | use_counts_.reserve(256); |
| 135 | raw_use_counts_.reserve(256); |
| 136 | block_list_.reserve(100); |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 137 | try_block_addr_ = new (arena_) ArenaBitVector(arena_, 0, true /* expandable */); |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 138 | |
| 139 | |
| 140 | if (cu_->instruction_set == kX86 || cu_->instruction_set == kX86_64) { |
| 141 | // X86 requires a temp to keep track of the method address. |
| 142 | // TODO For x86_64, addressing can be done with RIP. When that is implemented, |
| 143 | // this needs to be updated to reserve 0 temps for BE. |
| 144 | max_available_non_special_compiler_temps_ = cu_->target64 ? 2 : 1; |
| 145 | reserved_temps_for_backend_ = max_available_non_special_compiler_temps_; |
| 146 | } else { |
| 147 | // Other architectures do not have a known lower bound for non-special temps. |
| 148 | // We allow the update of the max to happen at BE initialization stage and simply set 0 for now. |
| 149 | max_available_non_special_compiler_temps_ = 0; |
| 150 | reserved_temps_for_backend_ = 0; |
| 151 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Ian Rogers | 6282dc1 | 2013-04-18 15:54:02 -0700 | [diff] [blame] | 154 | MIRGraph::~MIRGraph() { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 155 | STLDeleteElements(&block_list_); |
Ian Rogers | 6282dc1 | 2013-04-18 15:54:02 -0700 | [diff] [blame] | 156 | STLDeleteElements(&m_units_); |
| 157 | } |
| 158 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 159 | /* |
| 160 | * Parse an instruction, return the length of the instruction |
| 161 | */ |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 162 | int MIRGraph::ParseInsn(const uint16_t* code_ptr, MIR::DecodedInstruction* decoded_instruction) { |
| 163 | const Instruction* inst = Instruction::At(code_ptr); |
| 164 | decoded_instruction->opcode = inst->Opcode(); |
| 165 | decoded_instruction->vA = inst->HasVRegA() ? inst->VRegA() : 0; |
| 166 | decoded_instruction->vB = inst->HasVRegB() ? inst->VRegB() : 0; |
| 167 | decoded_instruction->vB_wide = inst->HasWideVRegB() ? inst->WideVRegB() : 0; |
| 168 | decoded_instruction->vC = inst->HasVRegC() ? inst->VRegC() : 0; |
| 169 | if (inst->HasVarArgs()) { |
| 170 | inst->GetVarArgs(decoded_instruction->arg); |
| 171 | } |
| 172 | return inst->SizeInCodeUnits(); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
| 176 | /* Split an existing block from the specified code offset into two */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 177 | BasicBlock* MIRGraph::SplitBlock(DexOffset code_offset, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 178 | BasicBlock* orig_block, BasicBlock** immed_pred_block_p) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 179 | DCHECK_GT(code_offset, orig_block->start_offset); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 180 | MIR* insn = orig_block->first_mir_insn; |
Mathew Zaleski | 33c1702 | 2014-09-15 09:44:14 -0400 | [diff] [blame] | 181 | MIR* prev = NULL; // Will be set to instruction before split. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 182 | while (insn) { |
| 183 | if (insn->offset == code_offset) break; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 184 | prev = insn; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 185 | insn = insn->next; |
| 186 | } |
| 187 | if (insn == NULL) { |
| 188 | LOG(FATAL) << "Break split failed"; |
| 189 | } |
Mathew Zaleski | 33c1702 | 2014-09-15 09:44:14 -0400 | [diff] [blame] | 190 | // Now insn is at the instruction where we want to split, namely |
| 191 | // insn will be the first instruction of the "bottom" block. |
| 192 | // Similarly, prev will be the last instruction of the "top" block |
| 193 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 194 | BasicBlock* bottom_block = CreateNewBB(kDalvikByteCode); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 195 | |
| 196 | bottom_block->start_offset = code_offset; |
| 197 | bottom_block->first_mir_insn = insn; |
| 198 | bottom_block->last_mir_insn = orig_block->last_mir_insn; |
| 199 | |
Junmo Park | 90223cc | 2014-08-04 18:51:21 +0900 | [diff] [blame] | 200 | /* If this block was terminated by a return, conditional branch or throw, |
| 201 | * the flag needs to go with the bottom block |
| 202 | */ |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 203 | bottom_block->terminated_by_return = orig_block->terminated_by_return; |
| 204 | orig_block->terminated_by_return = false; |
| 205 | |
Junmo Park | 90223cc | 2014-08-04 18:51:21 +0900 | [diff] [blame] | 206 | bottom_block->conditional_branch = orig_block->conditional_branch; |
| 207 | orig_block->conditional_branch = false; |
| 208 | |
| 209 | bottom_block->explicit_throw = orig_block->explicit_throw; |
| 210 | orig_block->explicit_throw = false; |
| 211 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 212 | /* Handle the taken path */ |
| 213 | bottom_block->taken = orig_block->taken; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 214 | if (bottom_block->taken != NullBasicBlockId) { |
| 215 | orig_block->taken = NullBasicBlockId; |
| 216 | BasicBlock* bb_taken = GetBasicBlock(bottom_block->taken); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 217 | bb_taken->ErasePredecessor(orig_block->id); |
| 218 | bb_taken->predecessors.push_back(bottom_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | /* Handle the fallthrough path */ |
| 222 | bottom_block->fall_through = orig_block->fall_through; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 223 | orig_block->fall_through = bottom_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 224 | bottom_block->predecessors.push_back(orig_block->id); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 225 | if (bottom_block->fall_through != NullBasicBlockId) { |
| 226 | BasicBlock* bb_fall_through = GetBasicBlock(bottom_block->fall_through); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 227 | bb_fall_through->ErasePredecessor(orig_block->id); |
| 228 | bb_fall_through->predecessors.push_back(bottom_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | /* Handle the successor list */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 232 | if (orig_block->successor_block_list_type != kNotUsed) { |
| 233 | bottom_block->successor_block_list_type = orig_block->successor_block_list_type; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 234 | bottom_block->successor_blocks.swap(orig_block->successor_blocks); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 235 | orig_block->successor_block_list_type = kNotUsed; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 236 | DCHECK(orig_block->successor_blocks.empty()); // Empty after the swap() above. |
| 237 | for (SuccessorBlockInfo* successor_block_info : bottom_block->successor_blocks) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 238 | BasicBlock* bb = GetBasicBlock(successor_block_info->block); |
Niranjan Kumar | 989367a | 2014-06-12 12:15:48 -0700 | [diff] [blame] | 239 | if (bb != nullptr) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 240 | bb->ErasePredecessor(orig_block->id); |
| 241 | bb->predecessors.push_back(bottom_block->id); |
Niranjan Kumar | 989367a | 2014-06-12 12:15:48 -0700 | [diff] [blame] | 242 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 246 | orig_block->last_mir_insn = prev; |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 247 | prev->next = nullptr; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 248 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 249 | /* |
| 250 | * Update the immediate predecessor block pointer so that outgoing edges |
| 251 | * can be applied to the proper block. |
| 252 | */ |
| 253 | if (immed_pred_block_p) { |
| 254 | DCHECK_EQ(*immed_pred_block_p, orig_block); |
| 255 | *immed_pred_block_p = bottom_block; |
| 256 | } |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 257 | |
| 258 | // Associate dex instructions in the bottom block with the new container. |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 259 | DCHECK(insn != nullptr); |
| 260 | DCHECK(insn != orig_block->first_mir_insn); |
| 261 | DCHECK(insn == bottom_block->first_mir_insn); |
| 262 | DCHECK_EQ(insn->offset, bottom_block->start_offset); |
| 263 | DCHECK(static_cast<int>(insn->dalvikInsn.opcode) == kMirOpCheck || |
Jean Christophe Beyler | 2ab40eb | 2014-06-02 09:03:14 -0700 | [diff] [blame] | 264 | !MIR::DecodedInstruction::IsPseudoMirOp(insn->dalvikInsn.opcode)); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 265 | DCHECK_EQ(dex_pc_to_block_map_[insn->offset], orig_block->id); |
Mathew Zaleski | 33c1702 | 2014-09-15 09:44:14 -0400 | [diff] [blame] | 266 | // Scan the "bottom" instructions, remapping them to the |
| 267 | // newly created "bottom" block. |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 268 | MIR* p = insn; |
Mathew Zaleski | 33c1702 | 2014-09-15 09:44:14 -0400 | [diff] [blame] | 269 | p->bb = bottom_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 270 | dex_pc_to_block_map_[p->offset] = bottom_block->id; |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 271 | while (p != bottom_block->last_mir_insn) { |
| 272 | p = p->next; |
| 273 | DCHECK(p != nullptr); |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 274 | p->bb = bottom_block->id; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 275 | int opcode = p->dalvikInsn.opcode; |
| 276 | /* |
| 277 | * Some messiness here to ensure that we only enter real opcodes and only the |
| 278 | * first half of a potentially throwing instruction that has been split into |
Vladimir Marko | 4376c87 | 2014-01-23 12:39:29 +0000 | [diff] [blame] | 279 | * CHECK and work portions. Since the 2nd half of a split operation is always |
| 280 | * the first in a BasicBlock, we can't hit it here. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 281 | */ |
Jean Christophe Beyler | 2ab40eb | 2014-06-02 09:03:14 -0700 | [diff] [blame] | 282 | if ((opcode == kMirOpCheck) || !MIR::DecodedInstruction::IsPseudoMirOp(opcode)) { |
Mathew Zaleski | 33c1702 | 2014-09-15 09:44:14 -0400 | [diff] [blame] | 283 | BasicBlockId mapped_id = dex_pc_to_block_map_[p->offset]; |
| 284 | // At first glance the instructions should all be mapped to orig_block. |
| 285 | // However, multiple instructions may correspond to the same dex, hence an earlier |
| 286 | // instruction may have already moved the mapping for dex to bottom_block. |
| 287 | DCHECK((mapped_id == orig_block->id) || (mapped_id == bottom_block->id)); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 288 | dex_pc_to_block_map_[p->offset] = bottom_block->id; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 289 | } |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 290 | } |
| 291 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 292 | return bottom_block; |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * Given a code offset, find out the block that starts with it. If the offset |
| 297 | * is in the middle of an existing block, split it into two. If immed_pred_block_p |
| 298 | * is not non-null and is the block being split, update *immed_pred_block_p to |
| 299 | * point to the bottom block so that outgoing edges can be set up properly |
| 300 | * (by the caller) |
| 301 | * Utilizes a map for fast lookup of the typical cases. |
| 302 | */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 303 | BasicBlock* MIRGraph::FindBlock(DexOffset code_offset, bool split, bool create, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 304 | BasicBlock** immed_pred_block_p) { |
Razvan A Lupusoru | 09ae022 | 2014-07-07 16:29:37 -0700 | [diff] [blame] | 305 | if (code_offset >= current_code_item_->insns_size_in_code_units_) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 306 | return NULL; |
| 307 | } |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 308 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 309 | int block_id = dex_pc_to_block_map_[code_offset]; |
| 310 | BasicBlock* bb = GetBasicBlock(block_id); |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 311 | |
| 312 | if ((bb != NULL) && (bb->start_offset == code_offset)) { |
| 313 | // Does this containing block start with the desired instruction? |
buzbee | bd663de | 2013-09-10 15:41:31 -0700 | [diff] [blame] | 314 | return bb; |
| 315 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 316 | |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 317 | // No direct hit. |
| 318 | if (!create) { |
| 319 | return NULL; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 320 | } |
| 321 | |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 322 | if (bb != NULL) { |
| 323 | // The target exists somewhere in an existing block. |
| 324 | return SplitBlock(code_offset, bb, bb == *immed_pred_block_p ? immed_pred_block_p : NULL); |
| 325 | } |
| 326 | |
| 327 | // Create a new block. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 328 | bb = CreateNewBB(kDalvikByteCode); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 329 | bb->start_offset = code_offset; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 330 | dex_pc_to_block_map_[bb->start_offset] = bb->id; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 331 | return bb; |
| 332 | } |
| 333 | |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 334 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 335 | /* Identify code range in try blocks and set up the empty catch blocks */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 336 | void MIRGraph::ProcessTryCatchBlocks() { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 337 | int tries_size = current_code_item_->tries_size_; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 338 | DexOffset offset; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 339 | |
| 340 | if (tries_size == 0) { |
| 341 | return; |
| 342 | } |
| 343 | |
| 344 | for (int i = 0; i < tries_size; i++) { |
| 345 | const DexFile::TryItem* pTry = |
| 346 | DexFile::GetTryItems(*current_code_item_, i); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 347 | DexOffset start_offset = pTry->start_addr_; |
| 348 | DexOffset end_offset = start_offset + pTry->insn_count_; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 349 | for (offset = start_offset; offset < end_offset; offset++) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 350 | try_block_addr_->SetBit(offset); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 354 | // Iterate over each of the handlers to enqueue the empty Catch blocks. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 355 | const byte* handlers_ptr = DexFile::GetCatchHandlerData(*current_code_item_, 0); |
| 356 | uint32_t handlers_size = DecodeUnsignedLeb128(&handlers_ptr); |
| 357 | for (uint32_t idx = 0; idx < handlers_size; idx++) { |
| 358 | CatchHandlerIterator iterator(handlers_ptr); |
| 359 | for (; iterator.HasNext(); iterator.Next()) { |
| 360 | uint32_t address = iterator.GetHandlerAddress(); |
| 361 | FindBlock(address, false /* split */, true /*create*/, |
| 362 | /* immed_pred_block_p */ NULL); |
| 363 | } |
| 364 | handlers_ptr = iterator.EndDataPointer(); |
| 365 | } |
| 366 | } |
| 367 | |
Vladimir Marko | e8ae814 | 2014-07-08 18:06:45 +0100 | [diff] [blame] | 368 | bool MIRGraph::IsBadMonitorExitCatch(NarrowDexOffset monitor_exit_offset, |
| 369 | NarrowDexOffset catch_offset) { |
| 370 | // Catches for monitor-exit during stack unwinding have the pattern |
| 371 | // move-exception (move)* (goto)? monitor-exit throw |
| 372 | // In the currently generated dex bytecode we see these catching a bytecode range including |
| 373 | // either its own or an identical monitor-exit, http://b/15745363 . This function checks if |
| 374 | // it's the case for a given monitor-exit and catch block so that we can ignore it. |
| 375 | // (We don't want to ignore all monitor-exit catches since one could enclose a synchronized |
| 376 | // block in a try-block and catch the NPE, Error or Throwable and we should let it through; |
| 377 | // even though a throwing monitor-exit certainly indicates a bytecode error.) |
Razvan A Lupusoru | 09ae022 | 2014-07-07 16:29:37 -0700 | [diff] [blame] | 378 | const Instruction* monitor_exit = Instruction::At(current_code_item_->insns_ + monitor_exit_offset); |
Vladimir Marko | e8ae814 | 2014-07-08 18:06:45 +0100 | [diff] [blame] | 379 | DCHECK(monitor_exit->Opcode() == Instruction::MONITOR_EXIT); |
| 380 | int monitor_reg = monitor_exit->VRegA_11x(); |
Razvan A Lupusoru | 09ae022 | 2014-07-07 16:29:37 -0700 | [diff] [blame] | 381 | const Instruction* check_insn = Instruction::At(current_code_item_->insns_ + catch_offset); |
Vladimir Marko | e8ae814 | 2014-07-08 18:06:45 +0100 | [diff] [blame] | 382 | DCHECK(check_insn->Opcode() == Instruction::MOVE_EXCEPTION); |
| 383 | if (check_insn->VRegA_11x() == monitor_reg) { |
| 384 | // Unexpected move-exception to the same register. Probably not the pattern we're looking for. |
| 385 | return false; |
| 386 | } |
| 387 | check_insn = check_insn->Next(); |
| 388 | while (true) { |
| 389 | int dest = -1; |
| 390 | bool wide = false; |
| 391 | switch (check_insn->Opcode()) { |
| 392 | case Instruction::MOVE_WIDE: |
| 393 | wide = true; |
| 394 | // Intentional fall-through. |
| 395 | case Instruction::MOVE_OBJECT: |
| 396 | case Instruction::MOVE: |
| 397 | dest = check_insn->VRegA_12x(); |
| 398 | break; |
| 399 | |
| 400 | case Instruction::MOVE_WIDE_FROM16: |
| 401 | wide = true; |
| 402 | // Intentional fall-through. |
| 403 | case Instruction::MOVE_OBJECT_FROM16: |
| 404 | case Instruction::MOVE_FROM16: |
| 405 | dest = check_insn->VRegA_22x(); |
| 406 | break; |
| 407 | |
| 408 | case Instruction::MOVE_WIDE_16: |
| 409 | wide = true; |
| 410 | // Intentional fall-through. |
| 411 | case Instruction::MOVE_OBJECT_16: |
| 412 | case Instruction::MOVE_16: |
| 413 | dest = check_insn->VRegA_32x(); |
| 414 | break; |
| 415 | |
| 416 | case Instruction::GOTO: |
| 417 | case Instruction::GOTO_16: |
| 418 | case Instruction::GOTO_32: |
| 419 | check_insn = check_insn->RelativeAt(check_insn->GetTargetOffset()); |
| 420 | // Intentional fall-through. |
| 421 | default: |
| 422 | return check_insn->Opcode() == Instruction::MONITOR_EXIT && |
| 423 | check_insn->VRegA_11x() == monitor_reg; |
| 424 | } |
| 425 | |
| 426 | if (dest == monitor_reg || (wide && dest + 1 == monitor_reg)) { |
| 427 | return false; |
| 428 | } |
| 429 | |
| 430 | check_insn = check_insn->Next(); |
| 431 | } |
| 432 | } |
| 433 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 434 | /* Process instructions with the kBranch flag */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 435 | BasicBlock* MIRGraph::ProcessCanBranch(BasicBlock* cur_block, MIR* insn, DexOffset cur_offset, |
| 436 | int width, int flags, const uint16_t* code_ptr, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 437 | const uint16_t* code_end) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 438 | DexOffset target = cur_offset; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 439 | switch (insn->dalvikInsn.opcode) { |
| 440 | case Instruction::GOTO: |
| 441 | case Instruction::GOTO_16: |
| 442 | case Instruction::GOTO_32: |
| 443 | target += insn->dalvikInsn.vA; |
| 444 | break; |
| 445 | case Instruction::IF_EQ: |
| 446 | case Instruction::IF_NE: |
| 447 | case Instruction::IF_LT: |
| 448 | case Instruction::IF_GE: |
| 449 | case Instruction::IF_GT: |
| 450 | case Instruction::IF_LE: |
| 451 | cur_block->conditional_branch = true; |
| 452 | target += insn->dalvikInsn.vC; |
| 453 | break; |
| 454 | case Instruction::IF_EQZ: |
| 455 | case Instruction::IF_NEZ: |
| 456 | case Instruction::IF_LTZ: |
| 457 | case Instruction::IF_GEZ: |
| 458 | case Instruction::IF_GTZ: |
| 459 | case Instruction::IF_LEZ: |
| 460 | cur_block->conditional_branch = true; |
| 461 | target += insn->dalvikInsn.vB; |
| 462 | break; |
| 463 | default: |
| 464 | LOG(FATAL) << "Unexpected opcode(" << insn->dalvikInsn.opcode << ") with kBranch set"; |
| 465 | } |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 466 | CountBranch(target); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 467 | BasicBlock* taken_block = FindBlock(target, /* split */ true, /* create */ true, |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 468 | /* immed_pred_block_p */ &cur_block); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 469 | cur_block->taken = taken_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 470 | taken_block->predecessors.push_back(cur_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 471 | |
| 472 | /* Always terminate the current block for conditional branches */ |
| 473 | if (flags & Instruction::kContinue) { |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 474 | BasicBlock* fallthrough_block = FindBlock(cur_offset + width, |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 475 | /* |
| 476 | * If the method is processed |
| 477 | * in sequential order from the |
| 478 | * beginning, we don't need to |
| 479 | * specify split for continue |
| 480 | * blocks. However, this |
| 481 | * routine can be called by |
| 482 | * compileLoop, which starts |
| 483 | * parsing the method from an |
| 484 | * arbitrary address in the |
| 485 | * method body. |
| 486 | */ |
| 487 | true, |
| 488 | /* create */ |
| 489 | true, |
| 490 | /* immed_pred_block_p */ |
| 491 | &cur_block); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 492 | cur_block->fall_through = fallthrough_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 493 | fallthrough_block->predecessors.push_back(cur_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 494 | } else if (code_ptr < code_end) { |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 495 | FindBlock(cur_offset + width, /* split */ false, /* create */ true, |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 496 | /* immed_pred_block_p */ NULL); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 497 | } |
| 498 | return cur_block; |
| 499 | } |
| 500 | |
| 501 | /* Process instructions with the kSwitch flag */ |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 502 | BasicBlock* MIRGraph::ProcessCanSwitch(BasicBlock* cur_block, MIR* insn, DexOffset cur_offset, |
| 503 | int width, int flags) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 504 | const uint16_t* switch_data = |
| 505 | reinterpret_cast<const uint16_t*>(GetCurrentInsns() + cur_offset + insn->dalvikInsn.vB); |
| 506 | int size; |
| 507 | const int* keyTable; |
| 508 | const int* target_table; |
| 509 | int i; |
| 510 | int first_key; |
| 511 | |
| 512 | /* |
| 513 | * Packed switch data format: |
| 514 | * ushort ident = 0x0100 magic value |
| 515 | * ushort size number of entries in the table |
| 516 | * int first_key first (and lowest) switch case value |
| 517 | * int targets[size] branch targets, relative to switch opcode |
| 518 | * |
| 519 | * Total size is (4+size*2) 16-bit code units. |
| 520 | */ |
| 521 | if (insn->dalvikInsn.opcode == Instruction::PACKED_SWITCH) { |
| 522 | DCHECK_EQ(static_cast<int>(switch_data[0]), |
| 523 | static_cast<int>(Instruction::kPackedSwitchSignature)); |
| 524 | size = switch_data[1]; |
| 525 | first_key = switch_data[2] | (switch_data[3] << 16); |
| 526 | target_table = reinterpret_cast<const int*>(&switch_data[4]); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 527 | keyTable = NULL; // Make the compiler happy. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 528 | /* |
| 529 | * Sparse switch data format: |
| 530 | * ushort ident = 0x0200 magic value |
| 531 | * ushort size number of entries in the table; > 0 |
| 532 | * int keys[size] keys, sorted low-to-high; 32-bit aligned |
| 533 | * int targets[size] branch targets, relative to switch opcode |
| 534 | * |
| 535 | * Total size is (2+size*4) 16-bit code units. |
| 536 | */ |
| 537 | } else { |
| 538 | DCHECK_EQ(static_cast<int>(switch_data[0]), |
| 539 | static_cast<int>(Instruction::kSparseSwitchSignature)); |
| 540 | size = switch_data[1]; |
| 541 | keyTable = reinterpret_cast<const int*>(&switch_data[2]); |
| 542 | target_table = reinterpret_cast<const int*>(&switch_data[2 + size*2]); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 543 | first_key = 0; // To make the compiler happy. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 544 | } |
| 545 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 546 | if (cur_block->successor_block_list_type != kNotUsed) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 547 | LOG(FATAL) << "Successor block list already in use: " |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 548 | << static_cast<int>(cur_block->successor_block_list_type); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 549 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 550 | cur_block->successor_block_list_type = |
| 551 | (insn->dalvikInsn.opcode == Instruction::PACKED_SWITCH) ? kPackedSwitch : kSparseSwitch; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 552 | cur_block->successor_blocks.reserve(size); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 553 | |
| 554 | for (i = 0; i < size; i++) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 555 | BasicBlock* case_block = FindBlock(cur_offset + target_table[i], /* split */ true, |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 556 | /* create */ true, /* immed_pred_block_p */ &cur_block); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 557 | SuccessorBlockInfo* successor_block_info = |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 558 | static_cast<SuccessorBlockInfo*>(arena_->Alloc(sizeof(SuccessorBlockInfo), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 559 | kArenaAllocSuccessor)); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 560 | successor_block_info->block = case_block->id; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 561 | successor_block_info->key = |
| 562 | (insn->dalvikInsn.opcode == Instruction::PACKED_SWITCH) ? |
| 563 | first_key + i : keyTable[i]; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 564 | cur_block->successor_blocks.push_back(successor_block_info); |
| 565 | case_block->predecessors.push_back(cur_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* Fall-through case */ |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 569 | BasicBlock* fallthrough_block = FindBlock(cur_offset + width, /* split */ false, |
| 570 | /* create */ true, /* immed_pred_block_p */ NULL); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 571 | cur_block->fall_through = fallthrough_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 572 | fallthrough_block->predecessors.push_back(cur_block->id); |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 573 | return cur_block; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /* Process instructions with the kThrow flag */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 577 | BasicBlock* MIRGraph::ProcessCanThrow(BasicBlock* cur_block, MIR* insn, DexOffset cur_offset, |
| 578 | int width, int flags, ArenaBitVector* try_block_addr, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 579 | const uint16_t* code_ptr, const uint16_t* code_end) { |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 580 | bool in_try_block = try_block_addr->IsBitSet(cur_offset); |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 581 | bool is_throw = (insn->dalvikInsn.opcode == Instruction::THROW); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 582 | |
| 583 | /* In try block */ |
| 584 | if (in_try_block) { |
| 585 | CatchHandlerIterator iterator(*current_code_item_, cur_offset); |
| 586 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 587 | if (cur_block->successor_block_list_type != kNotUsed) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 588 | LOG(INFO) << PrettyMethod(cu_->method_idx, *cu_->dex_file); |
| 589 | LOG(FATAL) << "Successor block list already in use: " |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 590 | << static_cast<int>(cur_block->successor_block_list_type); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Brian Carlstrom | 02c8cc6 | 2013-07-18 15:54:44 -0700 | [diff] [blame] | 593 | for (; iterator.HasNext(); iterator.Next()) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 594 | BasicBlock* catch_block = FindBlock(iterator.GetHandlerAddress(), false /* split*/, |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 595 | false /* creat */, NULL /* immed_pred_block_p */); |
Vladimir Marko | e8ae814 | 2014-07-08 18:06:45 +0100 | [diff] [blame] | 596 | if (insn->dalvikInsn.opcode == Instruction::MONITOR_EXIT && |
| 597 | IsBadMonitorExitCatch(insn->offset, catch_block->start_offset)) { |
| 598 | // Don't allow monitor-exit to catch its own exception, http://b/15745363 . |
| 599 | continue; |
| 600 | } |
| 601 | if (cur_block->successor_block_list_type == kNotUsed) { |
| 602 | cur_block->successor_block_list_type = kCatch; |
Vladimir Marko | e8ae814 | 2014-07-08 18:06:45 +0100 | [diff] [blame] | 603 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 604 | catch_block->catch_entry = true; |
| 605 | if (kIsDebugBuild) { |
| 606 | catches_.insert(catch_block->start_offset); |
| 607 | } |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 608 | SuccessorBlockInfo* successor_block_info = reinterpret_cast<SuccessorBlockInfo*> |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 609 | (arena_->Alloc(sizeof(SuccessorBlockInfo), kArenaAllocSuccessor)); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 610 | successor_block_info->block = catch_block->id; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 611 | successor_block_info->key = iterator.GetHandlerTypeIndex(); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 612 | cur_block->successor_blocks.push_back(successor_block_info); |
| 613 | catch_block->predecessors.push_back(cur_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 614 | } |
Vladimir Marko | e8ae814 | 2014-07-08 18:06:45 +0100 | [diff] [blame] | 615 | in_try_block = (cur_block->successor_block_list_type != kNotUsed); |
| 616 | } |
Vladimir Marko | e767f6c | 2014-10-01 17:38:02 +0100 | [diff] [blame] | 617 | bool build_all_edges = |
| 618 | (cu_->disable_opt & (1 << kSuppressExceptionEdges)) || is_throw || in_try_block; |
Vladimir Marko | e8ae814 | 2014-07-08 18:06:45 +0100 | [diff] [blame] | 619 | if (!in_try_block && build_all_edges) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 620 | BasicBlock* eh_block = CreateNewBB(kExceptionHandling); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 621 | cur_block->taken = eh_block->id; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 622 | eh_block->start_offset = cur_offset; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 623 | eh_block->predecessors.push_back(cur_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 624 | } |
| 625 | |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 626 | if (is_throw) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 627 | cur_block->explicit_throw = true; |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 628 | if (code_ptr < code_end) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 629 | // Force creation of new block following THROW via side-effect. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 630 | FindBlock(cur_offset + width, /* split */ false, /* create */ true, |
| 631 | /* immed_pred_block_p */ NULL); |
| 632 | } |
| 633 | if (!in_try_block) { |
| 634 | // Don't split a THROW that can't rethrow - we're done. |
| 635 | return cur_block; |
| 636 | } |
| 637 | } |
| 638 | |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 639 | if (!build_all_edges) { |
| 640 | /* |
| 641 | * Even though there is an exception edge here, control cannot return to this |
| 642 | * method. Thus, for the purposes of dataflow analysis and optimization, we can |
| 643 | * ignore the edge. Doing this reduces compile time, and increases the scope |
| 644 | * of the basic-block level optimization pass. |
| 645 | */ |
| 646 | return cur_block; |
| 647 | } |
| 648 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 649 | /* |
| 650 | * Split the potentially-throwing instruction into two parts. |
| 651 | * The first half will be a pseudo-op that captures the exception |
| 652 | * edges and terminates the basic block. It always falls through. |
| 653 | * Then, create a new basic block that begins with the throwing instruction |
| 654 | * (minus exceptions). Note: this new basic block must NOT be entered into |
| 655 | * the block_map. If the potentially-throwing instruction is the target of a |
| 656 | * future branch, we need to find the check psuedo half. The new |
| 657 | * basic block containing the work portion of the instruction should |
| 658 | * only be entered via fallthrough from the block containing the |
| 659 | * pseudo exception edge MIR. Note also that this new block is |
| 660 | * not automatically terminated after the work portion, and may |
| 661 | * contain following instructions. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 662 | * |
| 663 | * Note also that the dex_pc_to_block_map_ entry for the potentially |
| 664 | * throwing instruction will refer to the original basic block. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 665 | */ |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 666 | BasicBlock* new_block = CreateNewBB(kDalvikByteCode); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 667 | new_block->start_offset = insn->offset; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 668 | cur_block->fall_through = new_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 669 | new_block->predecessors.push_back(cur_block->id); |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 670 | MIR* new_insn = NewMIR(); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 671 | *new_insn = *insn; |
buzbee | 35ba7f3 | 2014-05-31 08:59:01 -0700 | [diff] [blame] | 672 | insn->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpCheck); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 673 | // Associate the two halves. |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 674 | insn->meta.throw_insn = new_insn; |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 675 | new_block->AppendMIR(new_insn); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 676 | return new_block; |
| 677 | } |
| 678 | |
| 679 | /* Parse a Dex method and insert it into the MIRGraph at the current insert point. */ |
| 680 | void MIRGraph::InlineMethod(const DexFile::CodeItem* code_item, uint32_t access_flags, |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 681 | InvokeType invoke_type, uint16_t class_def_idx, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 682 | uint32_t method_idx, jobject class_loader, const DexFile& dex_file) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 683 | current_code_item_ = code_item; |
| 684 | method_stack_.push_back(std::make_pair(current_method_, current_offset_)); |
| 685 | current_method_ = m_units_.size(); |
| 686 | current_offset_ = 0; |
| 687 | // TODO: will need to snapshot stack image and use that as the mir context identification. |
| 688 | m_units_.push_back(new DexCompilationUnit(cu_, class_loader, Runtime::Current()->GetClassLinker(), |
Vladimir Marko | 2730db0 | 2014-01-27 11:15:17 +0000 | [diff] [blame] | 689 | dex_file, current_code_item_, class_def_idx, method_idx, access_flags, |
| 690 | cu_->compiler_driver->GetVerifiedMethod(&dex_file, method_idx))); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 691 | const uint16_t* code_ptr = current_code_item_->insns_; |
| 692 | const uint16_t* code_end = |
| 693 | current_code_item_->insns_ + current_code_item_->insns_size_in_code_units_; |
| 694 | |
| 695 | // TODO: need to rework expansion of block list & try_block_addr when inlining activated. |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 696 | // TUNING: use better estimate of basic blocks for following resize. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 697 | block_list_.reserve(block_list_.size() + current_code_item_->insns_size_in_code_units_); |
| 698 | dex_pc_to_block_map_.resize(dex_pc_to_block_map_.size() + current_code_item_->insns_size_in_code_units_); |
buzbee | bd663de | 2013-09-10 15:41:31 -0700 | [diff] [blame] | 699 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 700 | // TODO: replace with explicit resize routine. Using automatic extension side effect for now. |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 701 | try_block_addr_->SetBit(current_code_item_->insns_size_in_code_units_); |
| 702 | try_block_addr_->ClearBit(current_code_item_->insns_size_in_code_units_); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 703 | |
| 704 | // If this is the first method, set up default entry and exit blocks. |
| 705 | if (current_method_ == 0) { |
| 706 | DCHECK(entry_block_ == NULL); |
| 707 | DCHECK(exit_block_ == NULL); |
Andreas Gampe | 4439596 | 2014-06-13 13:44:40 -0700 | [diff] [blame] | 708 | DCHECK_EQ(num_blocks_, 0U); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 709 | // Use id 0 to represent a null block. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 710 | BasicBlock* null_block = CreateNewBB(kNullBlock); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 711 | DCHECK_EQ(null_block->id, NullBasicBlockId); |
| 712 | null_block->hidden = true; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 713 | entry_block_ = CreateNewBB(kEntryBlock); |
| 714 | exit_block_ = CreateNewBB(kExitBlock); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 715 | // TODO: deprecate all "cu->" fields; move what's left to wherever CompilationUnit is allocated. |
| 716 | cu_->dex_file = &dex_file; |
| 717 | cu_->class_def_idx = class_def_idx; |
| 718 | cu_->method_idx = method_idx; |
| 719 | cu_->access_flags = access_flags; |
| 720 | cu_->invoke_type = invoke_type; |
| 721 | cu_->shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(method_idx)); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 722 | } else { |
| 723 | UNIMPLEMENTED(FATAL) << "Nested inlining not implemented."; |
| 724 | /* |
| 725 | * Will need to manage storage for ins & outs, push prevous state and update |
| 726 | * insert point. |
| 727 | */ |
| 728 | } |
| 729 | |
| 730 | /* Current block to record parsed instructions */ |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 731 | BasicBlock* cur_block = CreateNewBB(kDalvikByteCode); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 732 | DCHECK_EQ(current_offset_, 0U); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 733 | cur_block->start_offset = current_offset_; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 734 | // TODO: for inlining support, insert at the insert point rather than entry block. |
| 735 | entry_block_->fall_through = cur_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 736 | cur_block->predecessors.push_back(entry_block_->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 737 | |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 738 | /* Identify code range in try blocks and set up the empty catch blocks */ |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 739 | ProcessTryCatchBlocks(); |
| 740 | |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 741 | uint64_t merged_df_flags = 0u; |
| 742 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 743 | /* Parse all instructions and put them into containing basic blocks */ |
| 744 | while (code_ptr < code_end) { |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 745 | MIR *insn = NewMIR(); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 746 | insn->offset = current_offset_; |
| 747 | insn->m_unit_index = current_method_; |
| 748 | int width = ParseInsn(code_ptr, &insn->dalvikInsn); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 749 | Instruction::Code opcode = insn->dalvikInsn.opcode; |
| 750 | if (opcode_count_ != NULL) { |
| 751 | opcode_count_[static_cast<int>(opcode)]++; |
| 752 | } |
| 753 | |
Jean Christophe Beyler | fb0ea2d | 2014-07-29 13:20:42 -0700 | [diff] [blame] | 754 | int flags = insn->dalvikInsn.FlagsOf(); |
buzbee | b1f1d64 | 2014-02-27 12:55:32 -0800 | [diff] [blame] | 755 | int verify_flags = Instruction::VerifyFlagsOf(insn->dalvikInsn.opcode); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 756 | |
Jean Christophe Beyler | cc794c3 | 2014-05-02 09:34:13 -0700 | [diff] [blame] | 757 | uint64_t df_flags = GetDataFlowAttributes(insn); |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 758 | merged_df_flags |= df_flags; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 759 | |
| 760 | if (df_flags & DF_HAS_DEFS) { |
| 761 | def_count_ += (df_flags & DF_A_WIDE) ? 2 : 1; |
| 762 | } |
| 763 | |
buzbee | 1da1e2f | 2013-11-15 13:37:01 -0800 | [diff] [blame] | 764 | if (df_flags & DF_LVN) { |
| 765 | cur_block->use_lvn = true; // Run local value numbering on this basic block. |
| 766 | } |
| 767 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 768 | // Check for inline data block signatures. |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 769 | if (opcode == Instruction::NOP) { |
| 770 | // A simple NOP will have a width of 1 at this point, embedded data NOP > 1. |
| 771 | if ((width == 1) && ((current_offset_ & 0x1) == 0x1) && ((code_end - code_ptr) > 1)) { |
| 772 | // Could be an aligning nop. If an embedded data NOP follows, treat pair as single unit. |
| 773 | uint16_t following_raw_instruction = code_ptr[1]; |
| 774 | if ((following_raw_instruction == Instruction::kSparseSwitchSignature) || |
| 775 | (following_raw_instruction == Instruction::kPackedSwitchSignature) || |
| 776 | (following_raw_instruction == Instruction::kArrayDataSignature)) { |
| 777 | width += Instruction::At(code_ptr + 1)->SizeInCodeUnits(); |
| 778 | } |
| 779 | } |
| 780 | if (width == 1) { |
| 781 | // It is a simple nop - treat normally. |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 782 | cur_block->AppendMIR(insn); |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 783 | } else { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 784 | DCHECK(cur_block->fall_through == NullBasicBlockId); |
| 785 | DCHECK(cur_block->taken == NullBasicBlockId); |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 786 | // Unreachable instruction, mark for no continuation. |
| 787 | flags &= ~Instruction::kContinue; |
| 788 | } |
| 789 | } else { |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 790 | cur_block->AppendMIR(insn); |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 791 | } |
| 792 | |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 793 | // Associate the starting dex_pc for this opcode with its containing basic block. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 794 | dex_pc_to_block_map_[insn->offset] = cur_block->id; |
buzbee | b48819d | 2013-09-14 16:15:25 -0700 | [diff] [blame] | 795 | |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 796 | code_ptr += width; |
| 797 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 798 | if (flags & Instruction::kBranch) { |
| 799 | cur_block = ProcessCanBranch(cur_block, insn, current_offset_, |
| 800 | width, flags, code_ptr, code_end); |
| 801 | } else if (flags & Instruction::kReturn) { |
| 802 | cur_block->terminated_by_return = true; |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 803 | cur_block->fall_through = exit_block_->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 804 | exit_block_->predecessors.push_back(cur_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 805 | /* |
| 806 | * Terminate the current block if there are instructions |
| 807 | * afterwards. |
| 808 | */ |
| 809 | if (code_ptr < code_end) { |
| 810 | /* |
| 811 | * Create a fallthrough block for real instructions |
| 812 | * (incl. NOP). |
| 813 | */ |
buzbee | 2724776 | 2013-07-28 12:03:58 -0700 | [diff] [blame] | 814 | FindBlock(current_offset_ + width, /* split */ false, /* create */ true, |
| 815 | /* immed_pred_block_p */ NULL); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 816 | } |
| 817 | } else if (flags & Instruction::kThrow) { |
| 818 | cur_block = ProcessCanThrow(cur_block, insn, current_offset_, width, flags, try_block_addr_, |
| 819 | code_ptr, code_end); |
| 820 | } else if (flags & Instruction::kSwitch) { |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 821 | cur_block = ProcessCanSwitch(cur_block, insn, current_offset_, width, flags); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 822 | } |
Alexei Zavjalov | 688e7c5 | 2014-07-16 02:17:58 +0700 | [diff] [blame] | 823 | if (verify_flags & Instruction::kVerifyVarArgRange || |
| 824 | verify_flags & Instruction::kVerifyVarArgRangeNonZero) { |
buzbee | b1f1d64 | 2014-02-27 12:55:32 -0800 | [diff] [blame] | 825 | /* |
| 826 | * The Quick backend's runtime model includes a gap between a method's |
| 827 | * argument ("in") vregs and the rest of its vregs. Handling a range instruction |
| 828 | * which spans the gap is somewhat complicated, and should not happen |
| 829 | * in normal usage of dx. Punt to the interpreter. |
| 830 | */ |
| 831 | int first_reg_in_range = insn->dalvikInsn.vC; |
| 832 | int last_reg_in_range = first_reg_in_range + insn->dalvikInsn.vA - 1; |
| 833 | if (IsInVReg(first_reg_in_range) != IsInVReg(last_reg_in_range)) { |
| 834 | punt_to_interpreter_ = true; |
| 835 | } |
| 836 | } |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 837 | current_offset_ += width; |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 838 | BasicBlock* next_block = FindBlock(current_offset_, /* split */ false, /* create */ |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 839 | false, /* immed_pred_block_p */ NULL); |
| 840 | if (next_block) { |
| 841 | /* |
| 842 | * The next instruction could be the target of a previously parsed |
| 843 | * forward branch so a block is already created. If the current |
| 844 | * instruction is not an unconditional branch, connect them through |
| 845 | * the fall-through link. |
| 846 | */ |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 847 | DCHECK(cur_block->fall_through == NullBasicBlockId || |
| 848 | GetBasicBlock(cur_block->fall_through) == next_block || |
| 849 | GetBasicBlock(cur_block->fall_through) == exit_block_); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 850 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 851 | if ((cur_block->fall_through == NullBasicBlockId) && (flags & Instruction::kContinue)) { |
| 852 | cur_block->fall_through = next_block->id; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 853 | next_block->predecessors.push_back(cur_block->id); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 854 | } |
| 855 | cur_block = next_block; |
| 856 | } |
| 857 | } |
Vladimir Marko | 3d73ba2 | 2014-03-06 15:18:04 +0000 | [diff] [blame] | 858 | merged_df_flags_ = merged_df_flags; |
Vladimir Marko | 5816ed4 | 2013-11-27 17:04:20 +0000 | [diff] [blame] | 859 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 860 | if (cu_->enable_debug & (1 << kDebugDumpCFG)) { |
| 861 | DumpCFG("/sdcard/1_post_parse_cfg/", true); |
| 862 | } |
| 863 | |
| 864 | if (cu_->verbose) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 865 | DumpMIRGraph(); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 869 | void MIRGraph::ShowOpcodeStats() { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 870 | DCHECK(opcode_count_ != NULL); |
| 871 | LOG(INFO) << "Opcode Count"; |
| 872 | for (int i = 0; i < kNumPackedOpcodes; i++) { |
| 873 | if (opcode_count_[i] != 0) { |
| 874 | LOG(INFO) << "-C- " << Instruction::Name(static_cast<Instruction::Code>(i)) |
| 875 | << " " << opcode_count_[i]; |
| 876 | } |
| 877 | } |
| 878 | } |
| 879 | |
Jean Christophe Beyler | cc794c3 | 2014-05-02 09:34:13 -0700 | [diff] [blame] | 880 | uint64_t MIRGraph::GetDataFlowAttributes(Instruction::Code opcode) { |
| 881 | DCHECK_LT((size_t) opcode, (sizeof(oat_data_flow_attributes_) / sizeof(oat_data_flow_attributes_[0]))); |
| 882 | return oat_data_flow_attributes_[opcode]; |
| 883 | } |
| 884 | |
| 885 | uint64_t MIRGraph::GetDataFlowAttributes(MIR* mir) { |
| 886 | DCHECK(mir != nullptr); |
| 887 | Instruction::Code opcode = mir->dalvikInsn.opcode; |
| 888 | return GetDataFlowAttributes(opcode); |
| 889 | } |
| 890 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 891 | // TODO: use a configurable base prefix, and adjust callers to supply pass name. |
| 892 | /* Dump the CFG into a DOT graph */ |
Jean Christophe Beyler | d0a5155 | 2014-01-10 14:18:31 -0800 | [diff] [blame] | 893 | void MIRGraph::DumpCFG(const char* dir_prefix, bool all_blocks, const char *suffix) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 894 | FILE* file; |
Jean Christophe Beyler | a8869e6 | 2014-06-19 09:34:51 -0700 | [diff] [blame] | 895 | static AtomicInteger cnt(0); |
| 896 | |
| 897 | // Increment counter to get a unique file number. |
| 898 | cnt++; |
| 899 | |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 900 | std::string fname(PrettyMethod(cu_->method_idx, *cu_->dex_file)); |
| 901 | ReplaceSpecialChars(fname); |
Jean Christophe Beyler | a8869e6 | 2014-06-19 09:34:51 -0700 | [diff] [blame] | 902 | fname = StringPrintf("%s%s%x%s_%d.dot", dir_prefix, fname.c_str(), |
Jean Christophe Beyler | d0a5155 | 2014-01-10 14:18:31 -0800 | [diff] [blame] | 903 | GetBasicBlock(GetEntryBlock()->fall_through)->start_offset, |
Jean Christophe Beyler | a8869e6 | 2014-06-19 09:34:51 -0700 | [diff] [blame] | 904 | suffix == nullptr ? "" : suffix, |
| 905 | cnt.LoadRelaxed()); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 906 | file = fopen(fname.c_str(), "w"); |
| 907 | if (file == NULL) { |
| 908 | return; |
| 909 | } |
| 910 | fprintf(file, "digraph G {\n"); |
| 911 | |
| 912 | fprintf(file, " rankdir=TB\n"); |
| 913 | |
| 914 | int num_blocks = all_blocks ? GetNumBlocks() : num_reachable_blocks_; |
| 915 | int idx; |
| 916 | |
| 917 | for (idx = 0; idx < num_blocks; idx++) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 918 | int block_idx = all_blocks ? idx : dfs_order_[idx]; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 919 | BasicBlock* bb = GetBasicBlock(block_idx); |
Razvan A Lupusoru | 25bc279 | 2014-03-19 14:27:59 -0700 | [diff] [blame] | 920 | if (bb == NULL) continue; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 921 | if (bb->block_type == kDead) continue; |
Jean Christophe Beyler | a8869e6 | 2014-06-19 09:34:51 -0700 | [diff] [blame] | 922 | if (bb->hidden) continue; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 923 | if (bb->block_type == kEntryBlock) { |
| 924 | fprintf(file, " entry_%d [shape=Mdiamond];\n", bb->id); |
| 925 | } else if (bb->block_type == kExitBlock) { |
| 926 | fprintf(file, " exit_%d [shape=Mdiamond];\n", bb->id); |
| 927 | } else if (bb->block_type == kDalvikByteCode) { |
| 928 | fprintf(file, " block%04x_%d [shape=record,label = \"{ \\\n", |
| 929 | bb->start_offset, bb->id); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 930 | const MIR* mir; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 931 | fprintf(file, " {block id %d\\l}%s\\\n", bb->id, |
| 932 | bb->first_mir_insn ? " | " : " "); |
| 933 | for (mir = bb->first_mir_insn; mir; mir = mir->next) { |
| 934 | int opcode = mir->dalvikInsn.opcode; |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 935 | fprintf(file, " {%04x %s %s %s %s %s %s %s\\l}%s\\\n", mir->offset, |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 936 | mir->ssa_rep ? GetDalvikDisassembly(mir) : |
Jean Christophe Beyler | 2ab40eb | 2014-06-02 09:03:14 -0700 | [diff] [blame] | 937 | !MIR::DecodedInstruction::IsPseudoMirOp(opcode) ? |
| 938 | Instruction::Name(mir->dalvikInsn.opcode) : |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 939 | extended_mir_op_names_[opcode - kMirOpFirst], |
| 940 | (mir->optimization_flags & MIR_IGNORE_RANGE_CHECK) != 0 ? " no_rangecheck" : " ", |
| 941 | (mir->optimization_flags & MIR_IGNORE_NULL_CHECK) != 0 ? " no_nullcheck" : " ", |
Udayan Banerji | 60bfe7b | 2014-07-08 19:59:43 -0700 | [diff] [blame] | 942 | (mir->optimization_flags & MIR_IGNORE_SUSPEND_CHECK) != 0 ? " no_suspendcheck" : " ", |
Jean Christophe Beyler | b5bce7c | 2014-07-25 12:32:18 -0700 | [diff] [blame] | 943 | (mir->optimization_flags & MIR_STORE_NON_TEMPORAL) != 0 ? " non_temporal" : " ", |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 944 | (mir->optimization_flags & MIR_CALLEE) != 0 ? " inlined" : " ", |
| 945 | (mir->optimization_flags & MIR_IGNORE_CLINIT_CHECK) != 0 ? " no_clinit" : " ", |
Mark Mendell | d65c51a | 2014-04-29 16:55:20 -0400 | [diff] [blame] | 946 | mir->next ? " | " : " "); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 947 | } |
| 948 | fprintf(file, " }\"];\n\n"); |
| 949 | } else if (bb->block_type == kExceptionHandling) { |
| 950 | char block_name[BLOCK_NAME_LEN]; |
| 951 | |
| 952 | GetBlockName(bb, block_name); |
| 953 | fprintf(file, " %s [shape=invhouse];\n", block_name); |
| 954 | } |
| 955 | |
| 956 | char block_name1[BLOCK_NAME_LEN], block_name2[BLOCK_NAME_LEN]; |
| 957 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 958 | if (bb->taken != NullBasicBlockId) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 959 | GetBlockName(bb, block_name1); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 960 | GetBlockName(GetBasicBlock(bb->taken), block_name2); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 961 | fprintf(file, " %s:s -> %s:n [style=dotted]\n", |
| 962 | block_name1, block_name2); |
| 963 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 964 | if (bb->fall_through != NullBasicBlockId) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 965 | GetBlockName(bb, block_name1); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 966 | GetBlockName(GetBasicBlock(bb->fall_through), block_name2); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 967 | fprintf(file, " %s:s -> %s:n\n", block_name1, block_name2); |
| 968 | } |
| 969 | |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 970 | if (bb->successor_block_list_type != kNotUsed) { |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 971 | fprintf(file, " succ%04x_%d [shape=%s,label = \"{ \\\n", |
| 972 | bb->start_offset, bb->id, |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 973 | (bb->successor_block_list_type == kCatch) ? "Mrecord" : "record"); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 974 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 975 | int last_succ_id = static_cast<int>(bb->successor_blocks.size() - 1u); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 976 | int succ_id = 0; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 977 | for (SuccessorBlockInfo* successor_block_info : bb->successor_blocks) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 978 | BasicBlock* dest_block = GetBasicBlock(successor_block_info->block); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 979 | fprintf(file, " {<f%d> %04x: %04x\\l}%s\\\n", |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 980 | succ_id, |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 981 | successor_block_info->key, |
| 982 | dest_block->start_offset, |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 983 | (succ_id != last_succ_id) ? " | " : " "); |
| 984 | ++succ_id; |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 985 | } |
| 986 | fprintf(file, " }\"];\n\n"); |
| 987 | |
| 988 | GetBlockName(bb, block_name1); |
| 989 | fprintf(file, " %s:s -> succ%04x_%d:n [style=dashed]\n", |
| 990 | block_name1, bb->start_offset, bb->id); |
| 991 | |
Razvan A Lupusoru | 25bc279 | 2014-03-19 14:27:59 -0700 | [diff] [blame] | 992 | // Link the successor pseudo-block with all of its potential targets. |
Razvan A Lupusoru | 25bc279 | 2014-03-19 14:27:59 -0700 | [diff] [blame] | 993 | succ_id = 0; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 994 | for (SuccessorBlockInfo* successor_block_info : bb->successor_blocks) { |
Razvan A Lupusoru | 25bc279 | 2014-03-19 14:27:59 -0700 | [diff] [blame] | 995 | BasicBlock* dest_block = GetBasicBlock(successor_block_info->block); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 996 | |
Razvan A Lupusoru | 25bc279 | 2014-03-19 14:27:59 -0700 | [diff] [blame] | 997 | GetBlockName(dest_block, block_name2); |
| 998 | fprintf(file, " succ%04x_%d:f%d:e -> %s:n\n", bb->start_offset, |
| 999 | bb->id, succ_id++, block_name2); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | fprintf(file, "\n"); |
| 1003 | |
| 1004 | if (cu_->verbose) { |
| 1005 | /* Display the dominator tree */ |
| 1006 | GetBlockName(bb, block_name1); |
| 1007 | fprintf(file, " cfg%s [label=\"%s\", shape=none];\n", |
| 1008 | block_name1, block_name1); |
| 1009 | if (bb->i_dom) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 1010 | GetBlockName(GetBasicBlock(bb->i_dom), block_name2); |
buzbee | 311ca16 | 2013-02-28 15:56:43 -0800 | [diff] [blame] | 1011 | fprintf(file, " cfg%s:s -> cfg%s:n\n\n", block_name2, block_name1); |
| 1012 | } |
| 1013 | } |
| 1014 | } |
| 1015 | fprintf(file, "}\n"); |
| 1016 | fclose(file); |
| 1017 | } |
| 1018 | |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1019 | /* Insert an MIR instruction to the end of a basic block. */ |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 1020 | void BasicBlock::AppendMIR(MIR* mir) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1021 | // Insert it after the last MIR. |
| 1022 | InsertMIRListAfter(last_mir_insn, mir, mir); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1025 | void BasicBlock::AppendMIRList(MIR* first_list_mir, MIR* last_list_mir) { |
| 1026 | // Insert it after the last MIR. |
| 1027 | InsertMIRListAfter(last_mir_insn, first_list_mir, last_list_mir); |
| 1028 | } |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1029 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1030 | void BasicBlock::AppendMIRList(const std::vector<MIR*>& insns) { |
| 1031 | for (std::vector<MIR*>::const_iterator it = insns.begin(); it != insns.end(); it++) { |
| 1032 | MIR* new_mir = *it; |
| 1033 | |
| 1034 | // Add a copy of each MIR. |
| 1035 | InsertMIRListAfter(last_mir_insn, new_mir, new_mir); |
| 1036 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1037 | } |
| 1038 | |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1039 | /* Insert a MIR instruction after the specified MIR. */ |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 1040 | void BasicBlock::InsertMIRAfter(MIR* current_mir, MIR* new_mir) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1041 | InsertMIRListAfter(current_mir, new_mir, new_mir); |
| 1042 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1043 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1044 | void BasicBlock::InsertMIRListAfter(MIR* insert_after, MIR* first_list_mir, MIR* last_list_mir) { |
| 1045 | // If no MIR, we are done. |
| 1046 | if (first_list_mir == nullptr || last_list_mir == nullptr) { |
| 1047 | return; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1048 | } |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1049 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1050 | // If insert_after is null, assume BB is empty. |
| 1051 | if (insert_after == nullptr) { |
| 1052 | first_mir_insn = first_list_mir; |
| 1053 | last_mir_insn = last_list_mir; |
| 1054 | last_list_mir->next = nullptr; |
| 1055 | } else { |
| 1056 | MIR* after_list = insert_after->next; |
| 1057 | insert_after->next = first_list_mir; |
| 1058 | last_list_mir->next = after_list; |
| 1059 | if (after_list == nullptr) { |
| 1060 | last_mir_insn = last_list_mir; |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | // Set this BB to be the basic block of the MIRs. |
| 1065 | MIR* last = last_list_mir->next; |
| 1066 | for (MIR* mir = first_list_mir; mir != last; mir = mir->next) { |
| 1067 | mir->bb = id; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | /* Insert an MIR instruction to the head of a basic block. */ |
| 1072 | void BasicBlock::PrependMIR(MIR* mir) { |
| 1073 | InsertMIRListBefore(first_mir_insn, mir, mir); |
| 1074 | } |
| 1075 | |
| 1076 | void BasicBlock::PrependMIRList(MIR* first_list_mir, MIR* last_list_mir) { |
| 1077 | // Insert it before the first MIR. |
| 1078 | InsertMIRListBefore(first_mir_insn, first_list_mir, last_list_mir); |
| 1079 | } |
| 1080 | |
| 1081 | void BasicBlock::PrependMIRList(const std::vector<MIR*>& to_add) { |
| 1082 | for (std::vector<MIR*>::const_iterator it = to_add.begin(); it != to_add.end(); it++) { |
| 1083 | MIR* mir = *it; |
| 1084 | |
| 1085 | InsertMIRListBefore(first_mir_insn, mir, mir); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | /* Insert a MIR instruction before the specified MIR. */ |
| 1090 | void BasicBlock::InsertMIRBefore(MIR* current_mir, MIR* new_mir) { |
| 1091 | // Insert as a single element list. |
| 1092 | return InsertMIRListBefore(current_mir, new_mir, new_mir); |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | MIR* BasicBlock::FindPreviousMIR(MIR* mir) { |
| 1096 | MIR* current = first_mir_insn; |
| 1097 | |
| 1098 | while (current != nullptr) { |
| 1099 | MIR* next = current->next; |
| 1100 | |
| 1101 | if (next == mir) { |
| 1102 | return current; |
| 1103 | } |
| 1104 | |
| 1105 | current = next; |
| 1106 | } |
| 1107 | |
| 1108 | return nullptr; |
| 1109 | } |
| 1110 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1111 | void BasicBlock::InsertMIRListBefore(MIR* insert_before, MIR* first_list_mir, MIR* last_list_mir) { |
| 1112 | // If no MIR, we are done. |
| 1113 | if (first_list_mir == nullptr || last_list_mir == nullptr) { |
| 1114 | return; |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1115 | } |
| 1116 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1117 | // If insert_before is null, assume BB is empty. |
| 1118 | if (insert_before == nullptr) { |
| 1119 | first_mir_insn = first_list_mir; |
| 1120 | last_mir_insn = last_list_mir; |
| 1121 | last_list_mir->next = nullptr; |
| 1122 | } else { |
| 1123 | if (first_mir_insn == insert_before) { |
| 1124 | last_list_mir->next = first_mir_insn; |
| 1125 | first_mir_insn = first_list_mir; |
| 1126 | } else { |
| 1127 | // Find the preceding MIR. |
| 1128 | MIR* before_list = FindPreviousMIR(insert_before); |
| 1129 | DCHECK(before_list != nullptr); |
| 1130 | before_list->next = first_list_mir; |
| 1131 | last_list_mir->next = insert_before; |
| 1132 | } |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1133 | } |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1134 | |
| 1135 | // Set this BB to be the basic block of the MIRs. |
| 1136 | for (MIR* mir = first_list_mir; mir != last_list_mir->next; mir = mir->next) { |
| 1137 | mir->bb = id; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | bool BasicBlock::RemoveMIR(MIR* mir) { |
| 1142 | // Remove as a single element list. |
| 1143 | return RemoveMIRList(mir, mir); |
| 1144 | } |
| 1145 | |
| 1146 | bool BasicBlock::RemoveMIRList(MIR* first_list_mir, MIR* last_list_mir) { |
| 1147 | if (first_list_mir == nullptr) { |
| 1148 | return false; |
| 1149 | } |
| 1150 | |
| 1151 | // Try to find the MIR. |
| 1152 | MIR* before_list = nullptr; |
| 1153 | MIR* after_list = nullptr; |
| 1154 | |
| 1155 | // If we are removing from the beginning of the MIR list. |
| 1156 | if (first_mir_insn == first_list_mir) { |
| 1157 | before_list = nullptr; |
| 1158 | } else { |
| 1159 | before_list = FindPreviousMIR(first_list_mir); |
| 1160 | if (before_list == nullptr) { |
| 1161 | // We did not find the mir. |
| 1162 | return false; |
| 1163 | } |
| 1164 | } |
| 1165 | |
Jean Christophe Beyler | a4307ac | 2014-06-02 09:04:32 -0700 | [diff] [blame] | 1166 | // Remove the BB information and also find the after_list. |
Chao-ying Fu | 590c6a4 | 2014-09-23 14:54:32 -0700 | [diff] [blame] | 1167 | for (MIR* mir = first_list_mir; mir != last_list_mir->next; mir = mir->next) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1168 | mir->bb = NullBasicBlockId; |
| 1169 | } |
| 1170 | |
| 1171 | after_list = last_list_mir->next; |
| 1172 | |
Jean Christophe Beyler | a4307ac | 2014-06-02 09:04:32 -0700 | [diff] [blame] | 1173 | // If there is nothing before the list, after_list is the first_mir. |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1174 | if (before_list == nullptr) { |
| 1175 | first_mir_insn = after_list; |
Jean Christophe Beyler | a4307ac | 2014-06-02 09:04:32 -0700 | [diff] [blame] | 1176 | } else { |
| 1177 | before_list->next = after_list; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Jean Christophe Beyler | a4307ac | 2014-06-02 09:04:32 -0700 | [diff] [blame] | 1180 | // If there is nothing after the list, before_list is last_mir. |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1181 | if (after_list == nullptr) { |
| 1182 | last_mir_insn = before_list; |
| 1183 | } |
| 1184 | |
| 1185 | return true; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1186 | } |
| 1187 | |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 1188 | MIR* BasicBlock::GetNextUnconditionalMir(MIRGraph* mir_graph, MIR* current) { |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1189 | MIR* next_mir = nullptr; |
| 1190 | |
| 1191 | if (current != nullptr) { |
| 1192 | next_mir = current->next; |
| 1193 | } |
| 1194 | |
| 1195 | if (next_mir == nullptr) { |
| 1196 | // Only look for next MIR that follows unconditionally. |
Jean Christophe Beyler | cdacac4 | 2014-03-13 14:54:59 -0700 | [diff] [blame] | 1197 | if ((taken == NullBasicBlockId) && (fall_through != NullBasicBlockId)) { |
| 1198 | next_mir = mir_graph->GetBasicBlock(fall_through)->first_mir_insn; |
Razvan A Lupusoru | 3bc0174 | 2014-02-06 13:18:43 -0800 | [diff] [blame] | 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | return next_mir; |
| 1203 | } |
| 1204 | |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1205 | static void FillTypeSizeString(uint32_t type_size, std::string* decoded_mir) { |
| 1206 | DCHECK(decoded_mir != nullptr); |
| 1207 | OpSize type = static_cast<OpSize>(type_size >> 16); |
| 1208 | uint16_t vect_size = (type_size & 0xFFFF); |
| 1209 | |
| 1210 | // Now print the type and vector size. |
| 1211 | std::stringstream ss; |
| 1212 | ss << " (type:"; |
| 1213 | ss << type; |
| 1214 | ss << " vectsize:"; |
| 1215 | ss << vect_size; |
| 1216 | ss << ")"; |
| 1217 | |
| 1218 | decoded_mir->append(ss.str()); |
| 1219 | } |
| 1220 | |
| 1221 | void MIRGraph::DisassembleExtendedInstr(const MIR* mir, std::string* decoded_mir) { |
| 1222 | DCHECK(decoded_mir != nullptr); |
| 1223 | int opcode = mir->dalvikInsn.opcode; |
| 1224 | SSARepresentation* ssa_rep = mir->ssa_rep; |
| 1225 | int defs = (ssa_rep != nullptr) ? ssa_rep->num_defs : 0; |
| 1226 | int uses = (ssa_rep != nullptr) ? ssa_rep->num_uses : 0; |
| 1227 | |
| 1228 | decoded_mir->append(extended_mir_op_names_[opcode - kMirOpFirst]); |
| 1229 | |
| 1230 | switch (opcode) { |
| 1231 | case kMirOpPhi: { |
| 1232 | if (defs > 0 && uses > 0) { |
| 1233 | BasicBlockId* incoming = mir->meta.phi_incoming; |
| 1234 | decoded_mir->append(StringPrintf(" %s = (%s", |
| 1235 | GetSSANameWithConst(ssa_rep->defs[0], true).c_str(), |
| 1236 | GetSSANameWithConst(ssa_rep->uses[0], true).c_str())); |
| 1237 | decoded_mir->append(StringPrintf(":%d", incoming[0])); |
| 1238 | for (int i = 1; i < uses; i++) { |
| 1239 | decoded_mir->append(StringPrintf(", %s:%d", GetSSANameWithConst(ssa_rep->uses[i], true).c_str(), incoming[i])); |
| 1240 | } |
| 1241 | decoded_mir->append(")"); |
| 1242 | } |
| 1243 | break; |
| 1244 | } |
| 1245 | case kMirOpCopy: |
| 1246 | if (ssa_rep != nullptr) { |
| 1247 | decoded_mir->append(" "); |
| 1248 | decoded_mir->append(GetSSANameWithConst(ssa_rep->defs[0], false)); |
| 1249 | if (defs > 1) { |
| 1250 | decoded_mir->append(", "); |
| 1251 | decoded_mir->append(GetSSANameWithConst(ssa_rep->defs[1], false)); |
| 1252 | } |
| 1253 | decoded_mir->append(" = "); |
| 1254 | decoded_mir->append(GetSSANameWithConst(ssa_rep->uses[0], false)); |
| 1255 | if (uses > 1) { |
| 1256 | decoded_mir->append(", "); |
| 1257 | decoded_mir->append(GetSSANameWithConst(ssa_rep->uses[1], false)); |
| 1258 | } |
| 1259 | } else { |
| 1260 | decoded_mir->append(StringPrintf(" v%d = v%d", mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1261 | } |
| 1262 | break; |
| 1263 | case kMirOpFusedCmplFloat: |
| 1264 | case kMirOpFusedCmpgFloat: |
| 1265 | case kMirOpFusedCmplDouble: |
| 1266 | case kMirOpFusedCmpgDouble: |
| 1267 | case kMirOpFusedCmpLong: |
| 1268 | if (ssa_rep != nullptr) { |
| 1269 | decoded_mir->append(" "); |
| 1270 | decoded_mir->append(GetSSANameWithConst(ssa_rep->uses[0], false)); |
| 1271 | for (int i = 1; i < uses; i++) { |
| 1272 | decoded_mir->append(", "); |
| 1273 | decoded_mir->append(GetSSANameWithConst(ssa_rep->uses[i], false)); |
| 1274 | } |
| 1275 | } else { |
| 1276 | decoded_mir->append(StringPrintf(" v%d, v%d", mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1277 | } |
| 1278 | break; |
| 1279 | case kMirOpMoveVector: |
| 1280 | decoded_mir->append(StringPrintf(" vect%d = vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1281 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1282 | break; |
| 1283 | case kMirOpPackedAddition: |
| 1284 | decoded_mir->append(StringPrintf(" vect%d = vect%d + vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1285 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1286 | break; |
| 1287 | case kMirOpPackedMultiply: |
| 1288 | decoded_mir->append(StringPrintf(" vect%d = vect%d * vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1289 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1290 | break; |
| 1291 | case kMirOpPackedSubtract: |
| 1292 | decoded_mir->append(StringPrintf(" vect%d = vect%d - vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1293 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1294 | break; |
| 1295 | case kMirOpPackedAnd: |
| 1296 | decoded_mir->append(StringPrintf(" vect%d = vect%d & vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1297 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1298 | break; |
| 1299 | case kMirOpPackedOr: |
| 1300 | decoded_mir->append(StringPrintf(" vect%d = vect%d \\| vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1301 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1302 | break; |
| 1303 | case kMirOpPackedXor: |
| 1304 | decoded_mir->append(StringPrintf(" vect%d = vect%d ^ vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1305 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1306 | break; |
| 1307 | case kMirOpPackedShiftLeft: |
| 1308 | decoded_mir->append(StringPrintf(" vect%d = vect%d \\<\\< %d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1309 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1310 | break; |
| 1311 | case kMirOpPackedUnsignedShiftRight: |
| 1312 | decoded_mir->append(StringPrintf(" vect%d = vect%d \\>\\>\\> %d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1313 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1314 | break; |
| 1315 | case kMirOpPackedSignedShiftRight: |
| 1316 | decoded_mir->append(StringPrintf(" vect%d = vect%d \\>\\> %d", mir->dalvikInsn.vA, mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1317 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1318 | break; |
| 1319 | case kMirOpConstVector: |
| 1320 | decoded_mir->append(StringPrintf(" vect%d = %x, %x, %x, %x", mir->dalvikInsn.vA, mir->dalvikInsn.arg[0], |
| 1321 | mir->dalvikInsn.arg[1], mir->dalvikInsn.arg[2], mir->dalvikInsn.arg[3])); |
| 1322 | break; |
| 1323 | case kMirOpPackedSet: |
| 1324 | if (ssa_rep != nullptr) { |
| 1325 | decoded_mir->append(StringPrintf(" vect%d = %s", mir->dalvikInsn.vA, |
| 1326 | GetSSANameWithConst(ssa_rep->uses[0], false).c_str())); |
| 1327 | if (uses > 1) { |
| 1328 | decoded_mir->append(", "); |
| 1329 | decoded_mir->append(GetSSANameWithConst(ssa_rep->uses[1], false)); |
| 1330 | } |
| 1331 | } else { |
| 1332 | decoded_mir->append(StringPrintf(" vect%d = v%d", mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1333 | } |
| 1334 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1335 | break; |
| 1336 | case kMirOpPackedAddReduce: |
| 1337 | if (ssa_rep != nullptr) { |
| 1338 | decoded_mir->append(" "); |
| 1339 | decoded_mir->append(GetSSANameWithConst(ssa_rep->defs[0], false)); |
| 1340 | if (defs > 1) { |
| 1341 | decoded_mir->append(", "); |
| 1342 | decoded_mir->append(GetSSANameWithConst(ssa_rep->defs[1], false)); |
| 1343 | } |
| 1344 | decoded_mir->append(StringPrintf(" = vect%d + %s", mir->dalvikInsn.vB, |
| 1345 | GetSSANameWithConst(ssa_rep->uses[0], false).c_str())); |
| 1346 | if (uses > 1) { |
| 1347 | decoded_mir->append(", "); |
| 1348 | decoded_mir->append(GetSSANameWithConst(ssa_rep->uses[1], false)); |
| 1349 | } |
| 1350 | } else { |
| 1351 | decoded_mir->append(StringPrintf("v%d = vect%d + v%d", mir->dalvikInsn.vA, mir->dalvikInsn.vB, mir->dalvikInsn.vA)); |
| 1352 | } |
| 1353 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1354 | break; |
| 1355 | case kMirOpPackedReduce: |
| 1356 | if (ssa_rep != nullptr) { |
| 1357 | decoded_mir->append(" "); |
| 1358 | decoded_mir->append(GetSSANameWithConst(ssa_rep->defs[0], false)); |
| 1359 | if (defs > 1) { |
| 1360 | decoded_mir->append(", "); |
| 1361 | decoded_mir->append(GetSSANameWithConst(ssa_rep->defs[1], false)); |
| 1362 | } |
| 1363 | decoded_mir->append(StringPrintf(" = vect%d", mir->dalvikInsn.vB)); |
| 1364 | } else { |
| 1365 | decoded_mir->append(StringPrintf(" v%d = vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1366 | } |
| 1367 | FillTypeSizeString(mir->dalvikInsn.vC, decoded_mir); |
| 1368 | break; |
| 1369 | case kMirOpReserveVectorRegisters: |
| 1370 | case kMirOpReturnVectorRegisters: |
| 1371 | decoded_mir->append(StringPrintf(" vect%d - vect%d", mir->dalvikInsn.vA, mir->dalvikInsn.vB)); |
| 1372 | break; |
| 1373 | case kMirOpMemBarrier: { |
| 1374 | decoded_mir->append(" type:"); |
| 1375 | std::stringstream ss; |
| 1376 | ss << static_cast<MemBarrierKind>(mir->dalvikInsn.vA); |
| 1377 | decoded_mir->append(ss.str()); |
| 1378 | break; |
| 1379 | } |
Lupusoru, Razvan A | b3a84e2 | 2014-07-28 14:11:01 -0700 | [diff] [blame] | 1380 | case kMirOpPackedArrayGet: |
| 1381 | case kMirOpPackedArrayPut: |
| 1382 | decoded_mir->append(StringPrintf(" vect%d", mir->dalvikInsn.vA)); |
| 1383 | if (ssa_rep != nullptr) { |
| 1384 | decoded_mir->append(StringPrintf(", %s[%s]", |
| 1385 | GetSSANameWithConst(ssa_rep->uses[0], false).c_str(), |
| 1386 | GetSSANameWithConst(ssa_rep->uses[1], false).c_str())); |
| 1387 | } else { |
| 1388 | decoded_mir->append(StringPrintf(", v%d[v%d]", mir->dalvikInsn.vB, mir->dalvikInsn.vC)); |
| 1389 | } |
| 1390 | FillTypeSizeString(mir->dalvikInsn.arg[0], decoded_mir); |
| 1391 | break; |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1392 | default: |
| 1393 | break; |
| 1394 | } |
| 1395 | } |
| 1396 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1397 | char* MIRGraph::GetDalvikDisassembly(const MIR* mir) { |
Ian Rogers | 29a2648 | 2014-05-02 15:27:29 -0700 | [diff] [blame] | 1398 | MIR::DecodedInstruction insn = mir->dalvikInsn; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1399 | std::string str; |
| 1400 | int flags = 0; |
| 1401 | int opcode = insn.opcode; |
| 1402 | char* ret; |
| 1403 | bool nop = false; |
| 1404 | SSARepresentation* ssa_rep = mir->ssa_rep; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1405 | Instruction::Format dalvik_format = Instruction::k10x; // Default to no-operand format. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1406 | |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1407 | // Handle special cases that recover the original dalvik instruction. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1408 | if ((opcode == kMirOpCheck) || (opcode == kMirOpCheckPart2)) { |
| 1409 | str.append(extended_mir_op_names_[opcode - kMirOpFirst]); |
| 1410 | str.append(": "); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1411 | // Recover the original Dex instruction. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1412 | insn = mir->meta.throw_insn->dalvikInsn; |
| 1413 | ssa_rep = mir->meta.throw_insn->ssa_rep; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1414 | opcode = insn.opcode; |
| 1415 | } else if (opcode == kMirOpNop) { |
| 1416 | str.append("["); |
Razvan A Lupusoru | 7503597 | 2014-09-11 15:24:59 -0700 | [diff] [blame] | 1417 | if (mir->offset < current_code_item_->insns_size_in_code_units_) { |
| 1418 | // Recover original opcode. |
| 1419 | insn.opcode = Instruction::At(current_code_item_->insns_ + mir->offset)->Opcode(); |
| 1420 | opcode = insn.opcode; |
| 1421 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1422 | nop = true; |
| 1423 | } |
Serguei Katkov | 0f3e498 | 2014-08-21 16:43:54 +0700 | [diff] [blame] | 1424 | int defs = (ssa_rep != NULL) ? ssa_rep->num_defs : 0; |
| 1425 | int uses = (ssa_rep != NULL) ? ssa_rep->num_uses : 0; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1426 | |
Jean Christophe Beyler | 2ab40eb | 2014-06-02 09:03:14 -0700 | [diff] [blame] | 1427 | if (MIR::DecodedInstruction::IsPseudoMirOp(opcode)) { |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1428 | // Note that this does not check the MIR's opcode in all cases. In cases where it |
| 1429 | // recovered dalvik instruction, it uses opcode of that instead of the extended one. |
| 1430 | DisassembleExtendedInstr(mir, &str); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1431 | } else { |
| 1432 | dalvik_format = Instruction::FormatOf(insn.opcode); |
Jean Christophe Beyler | fb0ea2d | 2014-07-29 13:20:42 -0700 | [diff] [blame] | 1433 | flags = insn.FlagsOf(); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1434 | str.append(Instruction::Name(insn.opcode)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1435 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1436 | // For invokes-style formats, treat wide regs as a pair of singles. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1437 | bool show_singles = ((dalvik_format == Instruction::k35c) || |
| 1438 | (dalvik_format == Instruction::k3rc)); |
| 1439 | if (defs != 0) { |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1440 | str.append(" "); |
| 1441 | str.append(GetSSANameWithConst(ssa_rep->defs[0], false)); |
| 1442 | if (defs > 1) { |
| 1443 | str.append(", "); |
| 1444 | str.append(GetSSANameWithConst(ssa_rep->defs[1], false)); |
| 1445 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1446 | if (uses != 0) { |
| 1447 | str.append(", "); |
| 1448 | } |
| 1449 | } |
| 1450 | for (int i = 0; i < uses; i++) { |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1451 | str.append(" "); |
| 1452 | str.append(GetSSANameWithConst(ssa_rep->uses[i], show_singles)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1453 | if (!show_singles && (reg_location_ != NULL) && reg_location_[i].wide) { |
| 1454 | // For the listing, skip the high sreg. |
| 1455 | i++; |
| 1456 | } |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1457 | if (i != (uses - 1)) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1458 | str.append(","); |
| 1459 | } |
| 1460 | } |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1461 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1462 | switch (dalvik_format) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1463 | case Instruction::k11n: // Add one immediate from vB. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1464 | case Instruction::k21s: |
| 1465 | case Instruction::k31i: |
| 1466 | case Instruction::k21h: |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1467 | str.append(StringPrintf(", #0x%x", insn.vB)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1468 | break; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1469 | case Instruction::k51l: // Add one wide immediate. |
Ian Rogers | 23b03b5 | 2014-01-24 11:10:03 -0800 | [diff] [blame] | 1470 | str.append(StringPrintf(", #%" PRId64, insn.vB_wide)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1471 | break; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1472 | case Instruction::k21c: // One register, one string/type/method index. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1473 | case Instruction::k31c: |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1474 | str.append(StringPrintf(", index #0x%x", insn.vB)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1475 | break; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1476 | case Instruction::k22c: // Two registers, one string/type/method index. |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1477 | str.append(StringPrintf(", index #0x%x", insn.vC)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1478 | break; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1479 | case Instruction::k22s: // Add one immediate from vC. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1480 | case Instruction::k22b: |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1481 | str.append(StringPrintf(", #0x%x", insn.vC)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1482 | break; |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1483 | default: |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1484 | // Nothing left to print. |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1485 | break; |
Brian Carlstrom | 02c8cc6 | 2013-07-18 15:54:44 -0700 | [diff] [blame] | 1486 | } |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1487 | |
Serguei Katkov | 0f3e498 | 2014-08-21 16:43:54 +0700 | [diff] [blame] | 1488 | if ((flags & Instruction::kBranch) != 0) { |
| 1489 | // For branches, decode the instructions to print out the branch targets. |
| 1490 | int offset = 0; |
| 1491 | switch (dalvik_format) { |
| 1492 | case Instruction::k21t: |
| 1493 | offset = insn.vB; |
| 1494 | break; |
| 1495 | case Instruction::k22t: |
| 1496 | offset = insn.vC; |
| 1497 | break; |
| 1498 | case Instruction::k10t: |
| 1499 | case Instruction::k20t: |
| 1500 | case Instruction::k30t: |
| 1501 | offset = insn.vA; |
| 1502 | break; |
| 1503 | default: |
| 1504 | LOG(FATAL) << "Unexpected branch format " << dalvik_format << " from " << insn.opcode; |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1505 | break; |
Serguei Katkov | 0f3e498 | 2014-08-21 16:43:54 +0700 | [diff] [blame] | 1506 | } |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1507 | str.append(StringPrintf(", 0x%x (%c%x)", mir->offset + offset, |
Serguei Katkov | 0f3e498 | 2014-08-21 16:43:54 +0700 | [diff] [blame] | 1508 | offset > 0 ? '+' : '-', offset > 0 ? offset : -offset)); |
| 1509 | } |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1510 | |
| 1511 | if (nop) { |
| 1512 | str.append("]--optimized away"); |
| 1513 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1514 | } |
| 1515 | int length = str.length() + 1; |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 1516 | ret = static_cast<char*>(arena_->Alloc(length, kArenaAllocDFInfo)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1517 | strncpy(ret, str.c_str(), length); |
| 1518 | return ret; |
| 1519 | } |
| 1520 | |
| 1521 | /* Turn method name into a legal Linux file name */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1522 | void MIRGraph::ReplaceSpecialChars(std::string& str) { |
Brian Carlstrom | 9b7085a | 2013-07-18 15:15:21 -0700 | [diff] [blame] | 1523 | static const struct { const char before; const char after; } match[] = { |
| 1524 | {'/', '-'}, {';', '#'}, {' ', '#'}, {'$', '+'}, |
| 1525 | {'(', '@'}, {')', '@'}, {'<', '='}, {'>', '='} |
| 1526 | }; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1527 | for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) { |
| 1528 | std::replace(str.begin(), str.end(), match[i].before, match[i].after); |
| 1529 | } |
| 1530 | } |
| 1531 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1532 | std::string MIRGraph::GetSSAName(int ssa_reg) { |
Ian Rogers | 39ebcb8 | 2013-05-30 16:57:23 -0700 | [diff] [blame] | 1533 | // TODO: This value is needed for LLVM and debugging. Currently, we compute this and then copy to |
| 1534 | // the arena. We should be smarter and just place straight into the arena, or compute the |
| 1535 | // value more lazily. |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1536 | int vreg = SRegToVReg(ssa_reg); |
| 1537 | if (vreg >= static_cast<int>(GetFirstTempVR())) { |
| 1538 | return StringPrintf("t%d_%d", SRegToVReg(ssa_reg), GetSSASubscript(ssa_reg)); |
| 1539 | } else { |
| 1540 | return StringPrintf("v%d_%d", SRegToVReg(ssa_reg), GetSSASubscript(ssa_reg)); |
| 1541 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
| 1544 | // Similar to GetSSAName, but if ssa name represents an immediate show that as well. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1545 | std::string MIRGraph::GetSSANameWithConst(int ssa_reg, bool singles_only) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1546 | if (reg_location_ == NULL) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1547 | // Pre-SSA - just use the standard name. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1548 | return GetSSAName(ssa_reg); |
| 1549 | } |
| 1550 | if (IsConst(reg_location_[ssa_reg])) { |
Mark Mendell | 9944b3b | 2014-10-06 10:58:54 -0400 | [diff] [blame] | 1551 | if (!singles_only && reg_location_[ssa_reg].wide && |
| 1552 | !reg_location_[ssa_reg].high_word) { |
Ian Rogers | 23b03b5 | 2014-01-24 11:10:03 -0800 | [diff] [blame] | 1553 | return StringPrintf("v%d_%d#0x%" PRIx64, SRegToVReg(ssa_reg), GetSSASubscript(ssa_reg), |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1554 | ConstantValueWide(reg_location_[ssa_reg])); |
| 1555 | } else { |
Brian Carlstrom | b1eba21 | 2013-07-17 18:07:19 -0700 | [diff] [blame] | 1556 | return StringPrintf("v%d_%d#0x%x", SRegToVReg(ssa_reg), GetSSASubscript(ssa_reg), |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1557 | ConstantValue(reg_location_[ssa_reg])); |
| 1558 | } |
| 1559 | } else { |
Razvan A Lupusoru | 1500e6f | 2014-08-22 15:39:50 -0700 | [diff] [blame] | 1560 | int vreg = SRegToVReg(ssa_reg); |
| 1561 | if (vreg >= static_cast<int>(GetFirstTempVR())) { |
| 1562 | return StringPrintf("t%d_%d", SRegToVReg(ssa_reg), GetSSASubscript(ssa_reg)); |
| 1563 | } else { |
| 1564 | return StringPrintf("v%d_%d", SRegToVReg(ssa_reg), GetSSASubscript(ssa_reg)); |
| 1565 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1566 | } |
| 1567 | } |
| 1568 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1569 | void MIRGraph::GetBlockName(BasicBlock* bb, char* name) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1570 | switch (bb->block_type) { |
| 1571 | case kEntryBlock: |
| 1572 | snprintf(name, BLOCK_NAME_LEN, "entry_%d", bb->id); |
| 1573 | break; |
| 1574 | case kExitBlock: |
| 1575 | snprintf(name, BLOCK_NAME_LEN, "exit_%d", bb->id); |
| 1576 | break; |
| 1577 | case kDalvikByteCode: |
| 1578 | snprintf(name, BLOCK_NAME_LEN, "block%04x_%d", bb->start_offset, bb->id); |
| 1579 | break; |
| 1580 | case kExceptionHandling: |
| 1581 | snprintf(name, BLOCK_NAME_LEN, "exception%04x_%d", bb->start_offset, |
| 1582 | bb->id); |
| 1583 | break; |
| 1584 | default: |
| 1585 | snprintf(name, BLOCK_NAME_LEN, "_%d", bb->id); |
| 1586 | break; |
| 1587 | } |
| 1588 | } |
| 1589 | |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1590 | const char* MIRGraph::GetShortyFromTargetIdx(int target_idx) { |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 1591 | // TODO: for inlining support, use current code unit. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1592 | const DexFile::MethodId& method_id = cu_->dex_file->GetMethodId(target_idx); |
| 1593 | return cu_->dex_file->GetShorty(method_id.proto_idx_); |
| 1594 | } |
| 1595 | |
| 1596 | /* Debug Utility - dump a compilation unit */ |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1597 | void MIRGraph::DumpMIRGraph() { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1598 | const char* block_type_names[] = { |
buzbee | 17189ac | 2013-11-08 11:07:02 -0800 | [diff] [blame] | 1599 | "Null Block", |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1600 | "Entry Block", |
| 1601 | "Code Block", |
| 1602 | "Exit Block", |
| 1603 | "Exception Handling", |
| 1604 | "Catch Block" |
| 1605 | }; |
| 1606 | |
| 1607 | LOG(INFO) << "Compiling " << PrettyMethod(cu_->method_idx, *cu_->dex_file); |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 1608 | LOG(INFO) << GetInsns(0) << " insns"; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1609 | LOG(INFO) << GetNumBlocks() << " blocks in total"; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1610 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1611 | for (BasicBlock* bb : block_list_) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1612 | LOG(INFO) << StringPrintf("Block %d (%s) (insn %04x - %04x%s)", |
| 1613 | bb->id, |
| 1614 | block_type_names[bb->block_type], |
| 1615 | bb->start_offset, |
| 1616 | bb->last_mir_insn ? bb->last_mir_insn->offset : bb->start_offset, |
| 1617 | bb->last_mir_insn ? "" : " empty"); |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 1618 | if (bb->taken != NullBasicBlockId) { |
| 1619 | LOG(INFO) << " Taken branch: block " << bb->taken |
| 1620 | << "(0x" << std::hex << GetBasicBlock(bb->taken)->start_offset << ")"; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1621 | } |
buzbee | 0d82948 | 2013-10-11 15:24:55 -0700 | [diff] [blame] | 1622 | if (bb->fall_through != NullBasicBlockId) { |
| 1623 | LOG(INFO) << " Fallthrough : block " << bb->fall_through |
| 1624 | << " (0x" << std::hex << GetBasicBlock(bb->fall_through)->start_offset << ")"; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | /* |
| 1630 | * Build an array of location records for the incoming arguments. |
| 1631 | * Note: one location record per word of arguments, with dummy |
| 1632 | * high-word loc for wide arguments. Also pull up any following |
| 1633 | * MOVE_RESULT and incorporate it into the invoke. |
| 1634 | */ |
| 1635 | CallInfo* MIRGraph::NewMemCallInfo(BasicBlock* bb, MIR* mir, InvokeType type, |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1636 | bool is_range) { |
Mathieu Chartier | f6c4b3b | 2013-08-24 16:11:37 -0700 | [diff] [blame] | 1637 | CallInfo* info = static_cast<CallInfo*>(arena_->Alloc(sizeof(CallInfo), |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 1638 | kArenaAllocMisc)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1639 | MIR* move_result_mir = FindMoveResult(bb, mir); |
| 1640 | if (move_result_mir == NULL) { |
| 1641 | info->result.location = kLocInvalid; |
| 1642 | } else { |
| 1643 | info->result = GetRawDest(move_result_mir); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1644 | move_result_mir->dalvikInsn.opcode = static_cast<Instruction::Code>(kMirOpNop); |
| 1645 | } |
| 1646 | info->num_arg_words = mir->ssa_rep->num_uses; |
| 1647 | info->args = (info->num_arg_words == 0) ? NULL : static_cast<RegLocation*> |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 1648 | (arena_->Alloc(sizeof(RegLocation) * info->num_arg_words, kArenaAllocMisc)); |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1649 | for (int i = 0; i < info->num_arg_words; i++) { |
| 1650 | info->args[i] = GetRawSrc(mir, i); |
| 1651 | } |
| 1652 | info->opt_flags = mir->optimization_flags; |
| 1653 | info->type = type; |
| 1654 | info->is_range = is_range; |
| 1655 | info->index = mir->dalvikInsn.vB; |
| 1656 | info->offset = mir->offset; |
Vladimir Marko | f096aad | 2014-01-23 15:51:58 +0000 | [diff] [blame] | 1657 | info->mir = mir; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1658 | return info; |
| 1659 | } |
| 1660 | |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 1661 | // Allocate a new MIR. |
| 1662 | MIR* MIRGraph::NewMIR() { |
| 1663 | MIR* mir = new (arena_) MIR(); |
| 1664 | return mir; |
| 1665 | } |
| 1666 | |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 1667 | // Allocate a new basic block. |
Brian Carlstrom | 2ce745c | 2013-07-17 17:44:30 -0700 | [diff] [blame] | 1668 | BasicBlock* MIRGraph::NewMemBB(BBType block_type, int block_id) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1669 | BasicBlock* bb = new (arena_) BasicBlock(block_id, block_type, arena_); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1670 | |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 1671 | // TUNING: better estimate of the exit block predecessors? |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1672 | bb->predecessors.reserve((block_type == kExitBlock) ? 2048 : 2); |
buzbee | 862a760 | 2013-04-05 10:58:54 -0700 | [diff] [blame] | 1673 | block_id_map_.Put(block_id, block_id); |
| 1674 | return bb; |
| 1675 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame] | 1676 | |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 1677 | void MIRGraph::InitializeConstantPropagation() { |
| 1678 | is_constant_v_ = new (arena_) ArenaBitVector(arena_, GetNumSSARegs(), false); |
Vladimir Marko | 83cc7ae | 2014-02-12 18:02:05 +0000 | [diff] [blame] | 1679 | constant_values_ = static_cast<int*>(arena_->Alloc(sizeof(int) * GetNumSSARegs(), kArenaAllocDFInfo)); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | void MIRGraph::InitializeMethodUses() { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 1683 | // The gate starts by initializing the use counts. |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 1684 | int num_ssa_regs = GetNumSSARegs(); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1685 | use_counts_.clear(); |
| 1686 | use_counts_.reserve(num_ssa_regs + 32); |
| 1687 | use_counts_.resize(num_ssa_regs, 0u); |
| 1688 | raw_use_counts_.clear(); |
| 1689 | raw_use_counts_.reserve(num_ssa_regs + 32); |
| 1690 | raw_use_counts_.resize(num_ssa_regs, 0u); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 1691 | } |
| 1692 | |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 1693 | void MIRGraph::SSATransformationStart() { |
| 1694 | DCHECK(temp_scoped_alloc_.get() == nullptr); |
| 1695 | temp_scoped_alloc_.reset(ScopedArenaAllocator::Create(&cu_->arena_stack)); |
Razvan A Lupusoru | 8d0d03e | 2014-06-06 17:04:52 -0700 | [diff] [blame] | 1696 | temp_bit_vector_size_ = GetNumOfCodeAndTempVRs(); |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 1697 | temp_bit_vector_ = new (temp_scoped_alloc_.get()) ArenaBitVector( |
| 1698 | temp_scoped_alloc_.get(), temp_bit_vector_size_, false, kBitMapRegisterV); |
Jean Christophe Beyler | 4e97c53 | 2014-01-07 10:07:18 -0800 | [diff] [blame] | 1699 | } |
| 1700 | |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 1701 | void MIRGraph::SSATransformationEnd() { |
| 1702 | // Verify the dataflow information after the pass. |
| 1703 | if (cu_->enable_debug & (1 << kDebugVerifyDataflow)) { |
| 1704 | VerifyDataflow(); |
| 1705 | } |
| 1706 | |
| 1707 | temp_bit_vector_size_ = 0u; |
| 1708 | temp_bit_vector_ = nullptr; |
Vladimir Marko | 5229cf1 | 2014-10-09 14:57:59 +0100 | [diff] [blame^] | 1709 | temp_bit_matrix_ = nullptr; // Def block matrix. |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 1710 | DCHECK(temp_scoped_alloc_.get() != nullptr); |
| 1711 | temp_scoped_alloc_.reset(); |
Johnny Qiu | c029c98 | 2014-06-04 07:23:49 +0000 | [diff] [blame] | 1712 | |
| 1713 | // Update the maximum number of reachable blocks. |
| 1714 | max_num_reachable_blocks_ = num_reachable_blocks_; |
Vladimir Marko | a5b8fde | 2014-05-23 15:16:44 +0100 | [diff] [blame] | 1715 | } |
| 1716 | |
Razvan A Lupusoru | 7503597 | 2014-09-11 15:24:59 -0700 | [diff] [blame] | 1717 | size_t MIRGraph::GetNumDalvikInsns() const { |
| 1718 | size_t cumulative_size = 0u; |
| 1719 | bool counted_current_item = false; |
| 1720 | const uint8_t size_for_null_code_item = 2u; |
| 1721 | |
| 1722 | for (auto it : m_units_) { |
| 1723 | const DexFile::CodeItem* code_item = it->GetCodeItem(); |
| 1724 | // Even if the code item is null, we still count non-zero value so that |
| 1725 | // each m_unit is counted as having impact. |
| 1726 | cumulative_size += (code_item == nullptr ? |
| 1727 | size_for_null_code_item : code_item->insns_size_in_code_units_); |
| 1728 | if (code_item == current_code_item_) { |
| 1729 | counted_current_item = true; |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | // If the current code item was not counted yet, count it now. |
| 1734 | // This can happen for example in unit tests where some fields like m_units_ |
| 1735 | // are not initialized. |
| 1736 | if (counted_current_item == false) { |
| 1737 | cumulative_size += (current_code_item_ == nullptr ? |
| 1738 | size_for_null_code_item : current_code_item_->insns_size_in_code_units_); |
| 1739 | } |
| 1740 | |
| 1741 | return cumulative_size; |
| 1742 | } |
| 1743 | |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1744 | static BasicBlock* SelectTopologicalSortOrderFallBack( |
| 1745 | MIRGraph* mir_graph, const ArenaBitVector* current_loop, |
| 1746 | const ScopedArenaVector<size_t>* visited_cnt_values, ScopedArenaAllocator* allocator, |
| 1747 | ScopedArenaVector<BasicBlockId>* tmp_stack) { |
| 1748 | // No true loop head has been found but there may be true loop heads after the mess we need |
| 1749 | // to resolve. To avoid taking one of those, pick the candidate with the highest number of |
| 1750 | // reachable unvisited nodes. That candidate will surely be a part of a loop. |
| 1751 | BasicBlock* fall_back = nullptr; |
| 1752 | size_t fall_back_num_reachable = 0u; |
| 1753 | // Reuse the same bit vector for each candidate to mark reachable unvisited blocks. |
| 1754 | ArenaBitVector candidate_reachable(allocator, mir_graph->GetNumBlocks(), false, kBitMapMisc); |
| 1755 | AllNodesIterator iter(mir_graph); |
| 1756 | for (BasicBlock* candidate = iter.Next(); candidate != nullptr; candidate = iter.Next()) { |
| 1757 | if (candidate->hidden || // Hidden, or |
| 1758 | candidate->visited || // already processed, or |
| 1759 | (*visited_cnt_values)[candidate->id] == 0u || // no processed predecessors, or |
| 1760 | (current_loop != nullptr && // outside current loop. |
| 1761 | !current_loop->IsBitSet(candidate->id))) { |
| 1762 | continue; |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1763 | } |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1764 | DCHECK(tmp_stack->empty()); |
| 1765 | tmp_stack->push_back(candidate->id); |
| 1766 | candidate_reachable.ClearAllBits(); |
| 1767 | size_t num_reachable = 0u; |
| 1768 | while (!tmp_stack->empty()) { |
| 1769 | BasicBlockId current_id = tmp_stack->back(); |
| 1770 | tmp_stack->pop_back(); |
| 1771 | BasicBlock* current_bb = mir_graph->GetBasicBlock(current_id); |
| 1772 | DCHECK(current_bb != nullptr); |
| 1773 | ChildBlockIterator child_iter(current_bb, mir_graph); |
| 1774 | BasicBlock* child_bb = child_iter.Next(); |
| 1775 | for ( ; child_bb != nullptr; child_bb = child_iter.Next()) { |
| 1776 | DCHECK(!child_bb->hidden); |
| 1777 | if (child_bb->visited || // Already processed, or |
| 1778 | (current_loop != nullptr && // outside current loop. |
| 1779 | !current_loop->IsBitSet(child_bb->id))) { |
| 1780 | continue; |
| 1781 | } |
| 1782 | if (!candidate_reachable.IsBitSet(child_bb->id)) { |
| 1783 | candidate_reachable.SetBit(child_bb->id); |
| 1784 | tmp_stack->push_back(child_bb->id); |
| 1785 | num_reachable += 1u; |
| 1786 | } |
| 1787 | } |
| 1788 | } |
| 1789 | if (fall_back_num_reachable < num_reachable) { |
| 1790 | fall_back_num_reachable = num_reachable; |
| 1791 | fall_back = candidate; |
| 1792 | } |
| 1793 | } |
| 1794 | return fall_back; |
| 1795 | } |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1796 | |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1797 | // Compute from which unvisited blocks is bb_id reachable through unvisited blocks. |
| 1798 | static void ComputeUnvisitedReachableFrom(MIRGraph* mir_graph, BasicBlockId bb_id, |
| 1799 | ArenaBitVector* reachable, |
| 1800 | ScopedArenaVector<BasicBlockId>* tmp_stack) { |
| 1801 | // NOTE: Loop heads indicated by the "visited" flag. |
| 1802 | DCHECK(tmp_stack->empty()); |
| 1803 | reachable->ClearAllBits(); |
| 1804 | tmp_stack->push_back(bb_id); |
| 1805 | while (!tmp_stack->empty()) { |
| 1806 | BasicBlockId current_id = tmp_stack->back(); |
| 1807 | tmp_stack->pop_back(); |
| 1808 | BasicBlock* current_bb = mir_graph->GetBasicBlock(current_id); |
| 1809 | DCHECK(current_bb != nullptr); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1810 | for (BasicBlockId pred_id : current_bb->predecessors) { |
| 1811 | BasicBlock* pred_bb = mir_graph->GetBasicBlock(pred_id); |
| 1812 | DCHECK(pred_bb != nullptr); |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1813 | if (!pred_bb->visited && !reachable->IsBitSet(pred_bb->id)) { |
| 1814 | reachable->SetBit(pred_bb->id); |
| 1815 | tmp_stack->push_back(pred_bb->id); |
| 1816 | } |
| 1817 | } |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | void MIRGraph::ComputeTopologicalSortOrder() { |
| 1822 | ScopedArenaAllocator allocator(&cu_->arena_stack); |
| 1823 | unsigned int num_blocks = GetNumBlocks(); |
| 1824 | |
| 1825 | ScopedArenaQueue<BasicBlock*> q(allocator.Adapter()); |
| 1826 | ScopedArenaVector<size_t> visited_cnt_values(num_blocks, 0u, allocator.Adapter()); |
| 1827 | ScopedArenaVector<BasicBlockId> loop_head_stack(allocator.Adapter()); |
| 1828 | size_t max_nested_loops = 0u; |
| 1829 | ArenaBitVector loop_exit_blocks(&allocator, num_blocks, false, kBitMapMisc); |
| 1830 | loop_exit_blocks.ClearAllBits(); |
| 1831 | |
| 1832 | // Count the number of blocks to process and add the entry block(s). |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1833 | unsigned int num_blocks_to_process = 0u; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1834 | for (BasicBlock* bb : block_list_) { |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1835 | if (bb->hidden == true) { |
| 1836 | continue; |
| 1837 | } |
| 1838 | |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1839 | num_blocks_to_process += 1u; |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1840 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1841 | if (bb->predecessors.size() == 0u) { |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1842 | // Add entry block to the queue. |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1843 | q.push(bb); |
| 1844 | } |
| 1845 | } |
| 1846 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1847 | // Clear the topological order arrays. |
| 1848 | topological_order_.clear(); |
| 1849 | topological_order_.reserve(num_blocks); |
| 1850 | topological_order_loop_ends_.clear(); |
| 1851 | topological_order_loop_ends_.resize(num_blocks, 0u); |
| 1852 | topological_order_indexes_.clear(); |
| 1853 | topological_order_indexes_.resize(num_blocks, static_cast<uint16_t>(-1)); |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1854 | |
| 1855 | // Mark all blocks as unvisited. |
| 1856 | ClearAllVisitedFlags(); |
| 1857 | |
| 1858 | // For loop heads, keep track from which blocks they are reachable not going through other |
| 1859 | // loop heads. Other loop heads are excluded to detect the heads of nested loops. The children |
| 1860 | // in this set go into the loop body, the other children are jumping over the loop. |
| 1861 | ScopedArenaVector<ArenaBitVector*> loop_head_reachable_from(allocator.Adapter()); |
| 1862 | loop_head_reachable_from.resize(num_blocks, nullptr); |
| 1863 | // Reuse the same temp stack whenever calculating a loop_head_reachable_from[loop_head_id]. |
| 1864 | ScopedArenaVector<BasicBlockId> tmp_stack(allocator.Adapter()); |
| 1865 | |
| 1866 | while (num_blocks_to_process != 0u) { |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1867 | BasicBlock* bb = nullptr; |
| 1868 | if (!q.empty()) { |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1869 | num_blocks_to_process -= 1u; |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1870 | // Get top. |
| 1871 | bb = q.front(); |
| 1872 | q.pop(); |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1873 | if (bb->visited) { |
| 1874 | // Loop head: it was already processed, mark end and copy exit blocks to the queue. |
| 1875 | DCHECK(q.empty()) << PrettyMethod(cu_->method_idx, *cu_->dex_file); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1876 | uint16_t idx = static_cast<uint16_t>(topological_order_.size()); |
| 1877 | topological_order_loop_ends_[topological_order_indexes_[bb->id]] = idx; |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1878 | DCHECK_EQ(loop_head_stack.back(), bb->id); |
| 1879 | loop_head_stack.pop_back(); |
| 1880 | ArenaBitVector* reachable = |
| 1881 | loop_head_stack.empty() ? nullptr : loop_head_reachable_from[loop_head_stack.back()]; |
| 1882 | for (BasicBlockId candidate_id : loop_exit_blocks.Indexes()) { |
| 1883 | if (reachable == nullptr || reachable->IsBitSet(candidate_id)) { |
| 1884 | q.push(GetBasicBlock(candidate_id)); |
| 1885 | // NOTE: The BitVectorSet::IndexIterator will not check the pointed-to bit again, |
| 1886 | // so clearing the bit has no effect on the iterator. |
| 1887 | loop_exit_blocks.ClearBit(candidate_id); |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1888 | } |
| 1889 | } |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1890 | continue; |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1891 | } |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1892 | } else { |
| 1893 | // Find the new loop head. |
| 1894 | AllNodesIterator iter(this); |
| 1895 | while (true) { |
| 1896 | BasicBlock* candidate = iter.Next(); |
| 1897 | if (candidate == nullptr) { |
| 1898 | // We did not find a true loop head, fall back to a reachable block in any loop. |
| 1899 | ArenaBitVector* current_loop = |
| 1900 | loop_head_stack.empty() ? nullptr : loop_head_reachable_from[loop_head_stack.back()]; |
| 1901 | bb = SelectTopologicalSortOrderFallBack(this, current_loop, &visited_cnt_values, |
| 1902 | &allocator, &tmp_stack); |
| 1903 | DCHECK(bb != nullptr) << PrettyMethod(cu_->method_idx, *cu_->dex_file); |
| 1904 | if (kIsDebugBuild && cu_->dex_file != nullptr) { |
| 1905 | LOG(INFO) << "Topological sort order: Using fall-back in " |
| 1906 | << PrettyMethod(cu_->method_idx, *cu_->dex_file) << " BB #" << bb->id |
| 1907 | << " @0x" << std::hex << bb->start_offset |
| 1908 | << ", num_blocks = " << std::dec << num_blocks; |
| 1909 | } |
| 1910 | break; |
| 1911 | } |
| 1912 | if (candidate->hidden || // Hidden, or |
| 1913 | candidate->visited || // already processed, or |
| 1914 | visited_cnt_values[candidate->id] == 0u || // no processed predecessors, or |
| 1915 | (!loop_head_stack.empty() && // outside current loop. |
| 1916 | !loop_head_reachable_from[loop_head_stack.back()]->IsBitSet(candidate->id))) { |
| 1917 | continue; |
| 1918 | } |
| 1919 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1920 | for (BasicBlockId pred_id : candidate->predecessors) { |
| 1921 | BasicBlock* pred_bb = GetBasicBlock(pred_id); |
| 1922 | DCHECK(pred_bb != nullptr); |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1923 | if (pred_bb != candidate && !pred_bb->visited && |
| 1924 | !pred_bb->dominators->IsBitSet(candidate->id)) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1925 | candidate = nullptr; // Set candidate to null to indicate failure. |
| 1926 | break; |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1927 | } |
| 1928 | } |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1929 | if (candidate != nullptr) { |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1930 | bb = candidate; |
| 1931 | break; |
| 1932 | } |
| 1933 | } |
| 1934 | // Compute blocks from which the loop head is reachable and process those blocks first. |
| 1935 | ArenaBitVector* reachable = |
| 1936 | new (&allocator) ArenaBitVector(&allocator, num_blocks, false, kBitMapMisc); |
| 1937 | loop_head_reachable_from[bb->id] = reachable; |
| 1938 | ComputeUnvisitedReachableFrom(this, bb->id, reachable, &tmp_stack); |
| 1939 | // Now mark as loop head. (Even if it's only a fall back when we don't find a true loop.) |
| 1940 | loop_head_stack.push_back(bb->id); |
| 1941 | max_nested_loops = std::max(max_nested_loops, loop_head_stack.size()); |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1942 | } |
| 1943 | |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1944 | DCHECK_EQ(bb->hidden, false); |
| 1945 | DCHECK_EQ(bb->visited, false); |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1946 | bb->visited = true; |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1947 | |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1948 | // Now add the basic block. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1949 | uint16_t idx = static_cast<uint16_t>(topological_order_.size()); |
| 1950 | topological_order_indexes_[bb->id] = idx; |
| 1951 | topological_order_.push_back(bb->id); |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1952 | |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1953 | // Update visited_cnt_values for children. |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1954 | ChildBlockIterator succIter(bb, this); |
| 1955 | BasicBlock* successor = succIter.Next(); |
| 1956 | for ( ; successor != nullptr; successor = succIter.Next()) { |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1957 | if (successor->hidden) { |
Vladimir Marko | 622bdbe | 2014-06-19 14:59:05 +0100 | [diff] [blame] | 1958 | continue; |
| 1959 | } |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1960 | |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1961 | // One more predecessor was visited. |
| 1962 | visited_cnt_values[successor->id] += 1u; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1963 | if (visited_cnt_values[successor->id] == successor->predecessors.size()) { |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1964 | if (loop_head_stack.empty() || |
| 1965 | loop_head_reachable_from[loop_head_stack.back()]->IsBitSet(successor->id)) { |
| 1966 | q.push(successor); |
| 1967 | } else { |
| 1968 | DCHECK(!loop_exit_blocks.IsBitSet(successor->id)); |
| 1969 | loop_exit_blocks.SetBit(successor->id); |
| 1970 | } |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1971 | } |
| 1972 | } |
| 1973 | } |
Vladimir Marko | 55fff04 | 2014-07-10 12:42:52 +0100 | [diff] [blame] | 1974 | |
| 1975 | // Prepare the loop head stack for iteration. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1976 | topological_order_loop_head_stack_.clear(); |
| 1977 | topological_order_loop_head_stack_.reserve(max_nested_loops); |
Jean Christophe Beyler | 44e5bde | 2014-04-29 14:40:41 -0700 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | bool BasicBlock::IsExceptionBlock() const { |
| 1981 | if (block_type == kExceptionHandling) { |
| 1982 | return true; |
| 1983 | } |
| 1984 | return false; |
| 1985 | } |
| 1986 | |
Wei Jin | 04f4d8a | 2014-05-29 18:04:29 -0700 | [diff] [blame] | 1987 | bool MIRGraph::HasSuspendTestBetween(BasicBlock* source, BasicBlockId target_id) { |
| 1988 | BasicBlock* target = GetBasicBlock(target_id); |
| 1989 | |
| 1990 | if (source == nullptr || target == nullptr) |
| 1991 | return false; |
| 1992 | |
| 1993 | int idx; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 1994 | for (idx = gen_suspend_test_list_.size() - 1; idx >= 0; idx--) { |
| 1995 | BasicBlock* bb = gen_suspend_test_list_[idx]; |
Wei Jin | 04f4d8a | 2014-05-29 18:04:29 -0700 | [diff] [blame] | 1996 | if (bb == source) |
| 1997 | return true; // The block has been inserted by a suspend check before. |
| 1998 | if (source->dominators->IsBitSet(bb->id) && bb->dominators->IsBitSet(target_id)) |
| 1999 | return true; |
| 2000 | } |
| 2001 | |
| 2002 | return false; |
| 2003 | } |
| 2004 | |
Jean Christophe Beyler | f8c762b | 2014-05-02 12:54:37 -0700 | [diff] [blame] | 2005 | ChildBlockIterator::ChildBlockIterator(BasicBlock* bb, MIRGraph* mir_graph) |
| 2006 | : basic_block_(bb), mir_graph_(mir_graph), visited_fallthrough_(false), |
| 2007 | visited_taken_(false), have_successors_(false) { |
| 2008 | // Check if we actually do have successors. |
| 2009 | if (basic_block_ != 0 && basic_block_->successor_block_list_type != kNotUsed) { |
| 2010 | have_successors_ = true; |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2011 | successor_iter_ = basic_block_->successor_blocks.cbegin(); |
Jean Christophe Beyler | f8c762b | 2014-05-02 12:54:37 -0700 | [diff] [blame] | 2012 | } |
| 2013 | } |
| 2014 | |
| 2015 | BasicBlock* ChildBlockIterator::Next() { |
| 2016 | // We check if we have a basic block. If we don't we cannot get next child. |
| 2017 | if (basic_block_ == nullptr) { |
| 2018 | return nullptr; |
| 2019 | } |
| 2020 | |
| 2021 | // If we haven't visited fallthrough, return that. |
| 2022 | if (visited_fallthrough_ == false) { |
| 2023 | visited_fallthrough_ = true; |
| 2024 | |
| 2025 | BasicBlock* result = mir_graph_->GetBasicBlock(basic_block_->fall_through); |
| 2026 | if (result != nullptr) { |
| 2027 | return result; |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | // If we haven't visited taken, return that. |
| 2032 | if (visited_taken_ == false) { |
| 2033 | visited_taken_ = true; |
| 2034 | |
| 2035 | BasicBlock* result = mir_graph_->GetBasicBlock(basic_block_->taken); |
| 2036 | if (result != nullptr) { |
| 2037 | return result; |
| 2038 | } |
| 2039 | } |
| 2040 | |
| 2041 | // We visited both taken and fallthrough. Now check if we have successors we need to visit. |
| 2042 | if (have_successors_ == true) { |
| 2043 | // Get information about next successor block. |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2044 | auto end = basic_block_->successor_blocks.cend(); |
| 2045 | while (successor_iter_ != end) { |
| 2046 | SuccessorBlockInfo* successor_block_info = *successor_iter_; |
| 2047 | ++successor_iter_; |
Niranjan Kumar | 989367a | 2014-06-12 12:15:48 -0700 | [diff] [blame] | 2048 | // If block was replaced by zero block, take next one. |
| 2049 | if (successor_block_info->block != NullBasicBlockId) { |
| 2050 | return mir_graph_->GetBasicBlock(successor_block_info->block); |
| 2051 | } |
Jean Christophe Beyler | f8c762b | 2014-05-02 12:54:37 -0700 | [diff] [blame] | 2052 | } |
| 2053 | } |
| 2054 | |
| 2055 | // We do not have anything. |
| 2056 | return nullptr; |
| 2057 | } |
| 2058 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2059 | BasicBlock* BasicBlock::Copy(CompilationUnit* c_unit) { |
| 2060 | MIRGraph* mir_graph = c_unit->mir_graph.get(); |
| 2061 | return Copy(mir_graph); |
| 2062 | } |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2063 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2064 | BasicBlock* BasicBlock::Copy(MIRGraph* mir_graph) { |
| 2065 | BasicBlock* result_bb = mir_graph->CreateNewBB(block_type); |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2066 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2067 | // We don't do a memcpy style copy here because it would lead to a lot of things |
| 2068 | // to clean up. Let us do it by hand instead. |
| 2069 | // Copy in taken and fallthrough. |
| 2070 | result_bb->fall_through = fall_through; |
| 2071 | result_bb->taken = taken; |
| 2072 | |
| 2073 | // Copy successor links if needed. |
| 2074 | ArenaAllocator* arena = mir_graph->GetArena(); |
| 2075 | |
| 2076 | result_bb->successor_block_list_type = successor_block_list_type; |
| 2077 | if (result_bb->successor_block_list_type != kNotUsed) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2078 | result_bb->successor_blocks.reserve(successor_blocks.size()); |
| 2079 | for (SuccessorBlockInfo* sbi_old : successor_blocks) { |
| 2080 | SuccessorBlockInfo* sbi_new = static_cast<SuccessorBlockInfo*>( |
| 2081 | arena->Alloc(sizeof(SuccessorBlockInfo), kArenaAllocSuccessor)); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2082 | memcpy(sbi_new, sbi_old, sizeof(SuccessorBlockInfo)); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2083 | result_bb->successor_blocks.push_back(sbi_new); |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2084 | } |
| 2085 | } |
| 2086 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2087 | // Copy offset, method. |
| 2088 | result_bb->start_offset = start_offset; |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2089 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2090 | // Now copy instructions. |
| 2091 | for (MIR* mir = first_mir_insn; mir != 0; mir = mir->next) { |
| 2092 | // Get a copy first. |
| 2093 | MIR* copy = mir->Copy(mir_graph); |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2094 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2095 | // Append it. |
| 2096 | result_bb->AppendMIR(copy); |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2097 | } |
| 2098 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2099 | return result_bb; |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2100 | } |
| 2101 | |
| 2102 | MIR* MIR::Copy(MIRGraph* mir_graph) { |
| 2103 | MIR* res = mir_graph->NewMIR(); |
| 2104 | *res = *this; |
| 2105 | |
| 2106 | // Remove links |
| 2107 | res->next = nullptr; |
| 2108 | res->bb = NullBasicBlockId; |
| 2109 | res->ssa_rep = nullptr; |
| 2110 | |
| 2111 | return res; |
| 2112 | } |
| 2113 | |
| 2114 | MIR* MIR::Copy(CompilationUnit* c_unit) { |
| 2115 | return Copy(c_unit->mir_graph.get()); |
| 2116 | } |
| 2117 | |
| 2118 | uint32_t SSARepresentation::GetStartUseIndex(Instruction::Code opcode) { |
| 2119 | // Default result. |
| 2120 | int res = 0; |
| 2121 | |
| 2122 | // We are basically setting the iputs to their igets counterparts. |
| 2123 | switch (opcode) { |
| 2124 | case Instruction::IPUT: |
| 2125 | case Instruction::IPUT_OBJECT: |
| 2126 | case Instruction::IPUT_BOOLEAN: |
| 2127 | case Instruction::IPUT_BYTE: |
| 2128 | case Instruction::IPUT_CHAR: |
| 2129 | case Instruction::IPUT_SHORT: |
| 2130 | case Instruction::IPUT_QUICK: |
| 2131 | case Instruction::IPUT_OBJECT_QUICK: |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 2132 | case Instruction::IPUT_BOOLEAN_QUICK: |
| 2133 | case Instruction::IPUT_BYTE_QUICK: |
| 2134 | case Instruction::IPUT_CHAR_QUICK: |
| 2135 | case Instruction::IPUT_SHORT_QUICK: |
Jean Christophe Beyler | 3aa5773 | 2014-04-17 12:47:24 -0700 | [diff] [blame] | 2136 | case Instruction::APUT: |
| 2137 | case Instruction::APUT_OBJECT: |
| 2138 | case Instruction::APUT_BOOLEAN: |
| 2139 | case Instruction::APUT_BYTE: |
| 2140 | case Instruction::APUT_CHAR: |
| 2141 | case Instruction::APUT_SHORT: |
| 2142 | case Instruction::SPUT: |
| 2143 | case Instruction::SPUT_OBJECT: |
| 2144 | case Instruction::SPUT_BOOLEAN: |
| 2145 | case Instruction::SPUT_BYTE: |
| 2146 | case Instruction::SPUT_CHAR: |
| 2147 | case Instruction::SPUT_SHORT: |
| 2148 | // Skip the VR containing what to store. |
| 2149 | res = 1; |
| 2150 | break; |
| 2151 | case Instruction::IPUT_WIDE: |
| 2152 | case Instruction::IPUT_WIDE_QUICK: |
| 2153 | case Instruction::APUT_WIDE: |
| 2154 | case Instruction::SPUT_WIDE: |
| 2155 | // Skip the two VRs containing what to store. |
| 2156 | res = 2; |
| 2157 | break; |
| 2158 | default: |
| 2159 | // Do nothing in the general case. |
| 2160 | break; |
| 2161 | } |
| 2162 | |
| 2163 | return res; |
| 2164 | } |
| 2165 | |
Jean Christophe Beyler | c3db20b | 2014-05-05 21:09:40 -0700 | [diff] [blame] | 2166 | /** |
| 2167 | * @brief Given a decoded instruction, it checks whether the instruction |
| 2168 | * sets a constant and if it does, more information is provided about the |
| 2169 | * constant being set. |
| 2170 | * @param ptr_value pointer to a 64-bit holder for the constant. |
| 2171 | * @param wide Updated by function whether a wide constant is being set by bytecode. |
| 2172 | * @return Returns false if the decoded instruction does not represent a constant bytecode. |
| 2173 | */ |
| 2174 | bool MIR::DecodedInstruction::GetConstant(int64_t* ptr_value, bool* wide) const { |
| 2175 | bool sets_const = true; |
| 2176 | int64_t value = vB; |
| 2177 | |
| 2178 | DCHECK(ptr_value != nullptr); |
| 2179 | DCHECK(wide != nullptr); |
| 2180 | |
| 2181 | switch (opcode) { |
| 2182 | case Instruction::CONST_4: |
| 2183 | case Instruction::CONST_16: |
| 2184 | case Instruction::CONST: |
| 2185 | *wide = false; |
| 2186 | value <<= 32; // In order to get the sign extend. |
| 2187 | value >>= 32; |
| 2188 | break; |
| 2189 | case Instruction::CONST_HIGH16: |
| 2190 | *wide = false; |
| 2191 | value <<= 48; // In order to get the sign extend. |
| 2192 | value >>= 32; |
| 2193 | break; |
| 2194 | case Instruction::CONST_WIDE_16: |
| 2195 | case Instruction::CONST_WIDE_32: |
| 2196 | *wide = true; |
| 2197 | value <<= 32; // In order to get the sign extend. |
| 2198 | value >>= 32; |
| 2199 | break; |
| 2200 | case Instruction::CONST_WIDE: |
| 2201 | *wide = true; |
| 2202 | value = vB_wide; |
| 2203 | break; |
| 2204 | case Instruction::CONST_WIDE_HIGH16: |
| 2205 | *wide = true; |
| 2206 | value <<= 48; // In order to get the sign extend. |
| 2207 | break; |
| 2208 | default: |
| 2209 | sets_const = false; |
| 2210 | break; |
| 2211 | } |
| 2212 | |
| 2213 | if (sets_const) { |
| 2214 | *ptr_value = value; |
| 2215 | } |
| 2216 | |
| 2217 | return sets_const; |
| 2218 | } |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2219 | |
| 2220 | void BasicBlock::ResetOptimizationFlags(uint16_t reset_flags) { |
| 2221 | // Reset flags for all MIRs in bb. |
| 2222 | for (MIR* mir = first_mir_insn; mir != NULL; mir = mir->next) { |
| 2223 | mir->optimization_flags &= (~reset_flags); |
| 2224 | } |
| 2225 | } |
| 2226 | |
| 2227 | void BasicBlock::Hide(CompilationUnit* c_unit) { |
| 2228 | // First lets make it a dalvik bytecode block so it doesn't have any special meaning. |
| 2229 | block_type = kDalvikByteCode; |
| 2230 | |
| 2231 | // Mark it as hidden. |
| 2232 | hidden = true; |
| 2233 | |
| 2234 | // Detach it from its MIRs so we don't generate code for them. Also detached MIRs |
| 2235 | // are updated to know that they no longer have a parent. |
| 2236 | for (MIR* mir = first_mir_insn; mir != nullptr; mir = mir->next) { |
| 2237 | mir->bb = NullBasicBlockId; |
| 2238 | } |
| 2239 | first_mir_insn = nullptr; |
| 2240 | last_mir_insn = nullptr; |
| 2241 | |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2242 | MIRGraph* mir_graph = c_unit->mir_graph.get(); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2243 | for (BasicBlockId pred_id : predecessors) { |
| 2244 | BasicBlock* pred_bb = mir_graph->GetBasicBlock(pred_id); |
| 2245 | DCHECK(pred_bb != nullptr); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2246 | |
| 2247 | // Sadly we have to go through the children by hand here. |
| 2248 | pred_bb->ReplaceChild(id, NullBasicBlockId); |
| 2249 | } |
| 2250 | |
| 2251 | // Iterate through children of bb we are hiding. |
| 2252 | ChildBlockIterator successorChildIter(this, mir_graph); |
| 2253 | |
| 2254 | for (BasicBlock* childPtr = successorChildIter.Next(); childPtr != 0; childPtr = successorChildIter.Next()) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2255 | // Erase this predecessor from child. |
| 2256 | childPtr->ErasePredecessor(id); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2257 | } |
Jean Christophe Beyler | f588b50 | 2014-06-18 14:14:15 -0700 | [diff] [blame] | 2258 | |
| 2259 | // Remove link to children. |
| 2260 | taken = NullBasicBlockId; |
| 2261 | fall_through = NullBasicBlockId; |
| 2262 | successor_block_list_type = kNotUsed; |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2263 | } |
| 2264 | |
| 2265 | bool BasicBlock::IsSSALiveOut(const CompilationUnit* c_unit, int ssa_reg) { |
| 2266 | // In order to determine if the ssa reg is live out, we scan all the MIRs. We remember |
| 2267 | // the last SSA number of the same dalvik register. At the end, if it is different than ssa_reg, |
| 2268 | // then it is not live out of this BB. |
| 2269 | int dalvik_reg = c_unit->mir_graph->SRegToVReg(ssa_reg); |
| 2270 | |
| 2271 | int last_ssa_reg = -1; |
| 2272 | |
| 2273 | // Walk through the MIRs backwards. |
| 2274 | for (MIR* mir = first_mir_insn; mir != nullptr; mir = mir->next) { |
| 2275 | // Get ssa rep. |
| 2276 | SSARepresentation *ssa_rep = mir->ssa_rep; |
| 2277 | |
| 2278 | // Go through the defines for this MIR. |
| 2279 | for (int i = 0; i < ssa_rep->num_defs; i++) { |
| 2280 | DCHECK(ssa_rep->defs != nullptr); |
| 2281 | |
| 2282 | // Get the ssa reg. |
| 2283 | int def_ssa_reg = ssa_rep->defs[i]; |
| 2284 | |
| 2285 | // Get dalvik reg. |
| 2286 | int def_dalvik_reg = c_unit->mir_graph->SRegToVReg(def_ssa_reg); |
| 2287 | |
| 2288 | // Compare dalvik regs. |
| 2289 | if (dalvik_reg == def_dalvik_reg) { |
| 2290 | // We found a def of the register that we are being asked about. |
| 2291 | // Remember it. |
| 2292 | last_ssa_reg = def_ssa_reg; |
| 2293 | } |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | if (last_ssa_reg == -1) { |
| 2298 | // If we get to this point we couldn't find a define of register user asked about. |
| 2299 | // Let's assume the user knows what he's doing so we can be safe and say that if we |
| 2300 | // couldn't find a def, it is live out. |
| 2301 | return true; |
| 2302 | } |
| 2303 | |
| 2304 | // If it is not -1, we found a match, is it ssa_reg? |
| 2305 | return (ssa_reg == last_ssa_reg); |
| 2306 | } |
| 2307 | |
| 2308 | bool BasicBlock::ReplaceChild(BasicBlockId old_bb, BasicBlockId new_bb) { |
| 2309 | // We need to check taken, fall_through, and successor_blocks to replace. |
| 2310 | bool found = false; |
| 2311 | if (taken == old_bb) { |
| 2312 | taken = new_bb; |
| 2313 | found = true; |
| 2314 | } |
| 2315 | |
| 2316 | if (fall_through == old_bb) { |
| 2317 | fall_through = new_bb; |
| 2318 | found = true; |
| 2319 | } |
| 2320 | |
| 2321 | if (successor_block_list_type != kNotUsed) { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2322 | for (SuccessorBlockInfo* successor_block_info : successor_blocks) { |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2323 | if (successor_block_info->block == old_bb) { |
| 2324 | successor_block_info->block = new_bb; |
| 2325 | found = true; |
| 2326 | } |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | return found; |
| 2331 | } |
| 2332 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2333 | void BasicBlock::ErasePredecessor(BasicBlockId old_pred) { |
| 2334 | auto pos = std::find(predecessors.begin(), predecessors.end(), old_pred); |
| 2335 | DCHECK(pos != predecessors.end()); |
| 2336 | predecessors.erase(pos); |
| 2337 | } |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2338 | |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2339 | void BasicBlock::UpdatePredecessor(BasicBlockId old_pred, BasicBlockId new_pred) { |
| 2340 | DCHECK_NE(new_pred, NullBasicBlockId); |
| 2341 | auto pos = std::find(predecessors.begin(), predecessors.end(), old_pred); |
| 2342 | if (pos != predecessors.end()) { |
| 2343 | *pos = new_pred; |
| 2344 | } else { |
| 2345 | // If not found, add it. |
| 2346 | predecessors.push_back(new_pred); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2347 | } |
| 2348 | } |
| 2349 | |
| 2350 | // Create a new basic block with block_id as num_blocks_ that is |
| 2351 | // post-incremented. |
| 2352 | BasicBlock* MIRGraph::CreateNewBB(BBType block_type) { |
| 2353 | BasicBlock* res = NewMemBB(block_type, num_blocks_++); |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2354 | block_list_.push_back(res); |
Jean Christophe Beyler | 8512758 | 2014-05-11 23:36:41 -0700 | [diff] [blame] | 2355 | return res; |
| 2356 | } |
| 2357 | |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 2358 | void MIRGraph::CalculateBasicBlockInformation() { |
| 2359 | PassDriverMEPostOpt driver(cu_); |
| 2360 | driver.Launch(); |
| 2361 | } |
| 2362 | |
| 2363 | void MIRGraph::InitializeBasicBlockData() { |
Vladimir Marko | e39c54e | 2014-09-22 14:50:02 +0100 | [diff] [blame] | 2364 | num_blocks_ = block_list_.size(); |
Jean Christophe Beyler | 2469e60 | 2014-05-06 20:36:55 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
Jean Christophe Beyler | fb0ea2d | 2014-07-29 13:20:42 -0700 | [diff] [blame] | 2367 | int MIR::DecodedInstruction::FlagsOf() const { |
| 2368 | // Calculate new index. |
| 2369 | int idx = static_cast<int>(opcode) - kNumPackedOpcodes; |
| 2370 | |
| 2371 | // Check if it is an extended or not. |
| 2372 | if (idx < 0) { |
| 2373 | return Instruction::FlagsOf(opcode); |
| 2374 | } |
| 2375 | |
| 2376 | // For extended, we use a switch. |
| 2377 | switch (static_cast<int>(opcode)) { |
| 2378 | case kMirOpPhi: |
| 2379 | return Instruction::kContinue; |
| 2380 | case kMirOpCopy: |
| 2381 | return Instruction::kContinue; |
| 2382 | case kMirOpFusedCmplFloat: |
| 2383 | return Instruction::kContinue | Instruction::kBranch; |
| 2384 | case kMirOpFusedCmpgFloat: |
| 2385 | return Instruction::kContinue | Instruction::kBranch; |
| 2386 | case kMirOpFusedCmplDouble: |
| 2387 | return Instruction::kContinue | Instruction::kBranch; |
| 2388 | case kMirOpFusedCmpgDouble: |
| 2389 | return Instruction::kContinue | Instruction::kBranch; |
| 2390 | case kMirOpFusedCmpLong: |
| 2391 | return Instruction::kContinue | Instruction::kBranch; |
| 2392 | case kMirOpNop: |
| 2393 | return Instruction::kContinue; |
| 2394 | case kMirOpNullCheck: |
| 2395 | return Instruction::kContinue | Instruction::kThrow; |
| 2396 | case kMirOpRangeCheck: |
| 2397 | return Instruction::kContinue | Instruction::kThrow; |
| 2398 | case kMirOpDivZeroCheck: |
| 2399 | return Instruction::kContinue | Instruction::kThrow; |
| 2400 | case kMirOpCheck: |
Udayan Banerji | b7fc629 | 2014-09-09 16:49:34 -0700 | [diff] [blame] | 2401 | return Instruction::kContinue | Instruction::kThrow; |
Jean Christophe Beyler | fb0ea2d | 2014-07-29 13:20:42 -0700 | [diff] [blame] | 2402 | case kMirOpCheckPart2: |
Udayan Banerji | b7fc629 | 2014-09-09 16:49:34 -0700 | [diff] [blame] | 2403 | return Instruction::kContinue; |
Jean Christophe Beyler | fb0ea2d | 2014-07-29 13:20:42 -0700 | [diff] [blame] | 2404 | case kMirOpSelect: |
| 2405 | return Instruction::kContinue; |
| 2406 | case kMirOpConstVector: |
| 2407 | return Instruction::kContinue; |
| 2408 | case kMirOpMoveVector: |
| 2409 | return Instruction::kContinue; |
| 2410 | case kMirOpPackedMultiply: |
| 2411 | return Instruction::kContinue; |
| 2412 | case kMirOpPackedAddition: |
| 2413 | return Instruction::kContinue; |
| 2414 | case kMirOpPackedSubtract: |
| 2415 | return Instruction::kContinue; |
| 2416 | case kMirOpPackedShiftLeft: |
| 2417 | return Instruction::kContinue; |
| 2418 | case kMirOpPackedSignedShiftRight: |
| 2419 | return Instruction::kContinue; |
| 2420 | case kMirOpPackedUnsignedShiftRight: |
| 2421 | return Instruction::kContinue; |
| 2422 | case kMirOpPackedAnd: |
| 2423 | return Instruction::kContinue; |
| 2424 | case kMirOpPackedOr: |
| 2425 | return Instruction::kContinue; |
| 2426 | case kMirOpPackedXor: |
| 2427 | return Instruction::kContinue; |
| 2428 | case kMirOpPackedAddReduce: |
| 2429 | return Instruction::kContinue; |
| 2430 | case kMirOpPackedReduce: |
| 2431 | return Instruction::kContinue; |
| 2432 | case kMirOpPackedSet: |
| 2433 | return Instruction::kContinue; |
| 2434 | case kMirOpReserveVectorRegisters: |
| 2435 | return Instruction::kContinue; |
| 2436 | case kMirOpReturnVectorRegisters: |
| 2437 | return Instruction::kContinue; |
Udayan Banerji | b7fc629 | 2014-09-09 16:49:34 -0700 | [diff] [blame] | 2438 | case kMirOpMemBarrier: |
| 2439 | return Instruction::kContinue; |
| 2440 | case kMirOpPackedArrayGet: |
| 2441 | return Instruction::kContinue | Instruction::kThrow; |
| 2442 | case kMirOpPackedArrayPut: |
| 2443 | return Instruction::kContinue | Instruction::kThrow; |
Jean Christophe Beyler | fb0ea2d | 2014-07-29 13:20:42 -0700 | [diff] [blame] | 2444 | default: |
| 2445 | LOG(WARNING) << "ExtendedFlagsOf: Unhandled case: " << static_cast<int> (opcode); |
| 2446 | return 0; |
| 2447 | } |
| 2448 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 2449 | } // namespace art |