buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
buzbee | 395116c | 2013-02-27 14:30:25 -0800 | [diff] [blame] | 17 | #include "compiler/dex/compiler_internals.h" |
buzbee | 1bc37c6 | 2012-11-20 13:35:41 -0800 | [diff] [blame] | 18 | |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 19 | namespace art { |
| 20 | |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 21 | #define DEBUG_OPT(X) |
| 22 | |
Ian Rogers | 07ec8e1 | 2012-12-01 01:26:51 -0800 | [diff] [blame] | 23 | /* Check RAW, WAR, and RAW dependency on the register operands */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 24 | #define CHECK_REG_DEP(use, def, check) ((def & check->use_mask) || \ |
| 25 | ((use | def) & check->def_mask)) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 26 | |
| 27 | /* Scheduler heuristics */ |
| 28 | #define MAX_HOIST_DISTANCE 20 |
| 29 | #define LDLD_DISTANCE 4 |
| 30 | #define LD_LATENCY 2 |
| 31 | |
buzbee | aad9438 | 2012-11-21 07:40:50 -0800 | [diff] [blame] | 32 | static bool IsDalvikRegisterClobbered(LIR* lir1, LIR* lir2) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 33 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 34 | int reg1Lo = DECODE_ALIAS_INFO_REG(lir1->alias_info); |
| 35 | int reg1Hi = reg1Lo + DECODE_ALIAS_INFO_WIDE(lir1->alias_info); |
| 36 | int reg2Lo = DECODE_ALIAS_INFO_REG(lir2->alias_info); |
| 37 | int reg2Hi = reg2Lo + DECODE_ALIAS_INFO_WIDE(lir2->alias_info); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 38 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 39 | return (reg1Lo == reg2Lo) || (reg1Lo == reg2Hi) || (reg1Hi == reg2Lo); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /* Convert a more expensive instruction (ie load) into a move */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 43 | void Mir2Lir::ConvertMemOpIntoMove(LIR* orig_lir, int dest, int src) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 44 | { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 45 | /* Insert a move to replace the load */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 46 | LIR* move_lir; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 47 | move_lir = OpRegCopyNoInsert(dest, src); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 48 | /* |
| 49 | * Insert the converted instruction after the original since the |
| 50 | * optimization is scannng in the top-down order and the new instruction |
| 51 | * will need to be re-checked (eg the new dest clobbers the src used in |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 52 | * this_lir). |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 53 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 54 | InsertLIRAfter(orig_lir, move_lir); |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /* |
| 58 | * Perform a pass of top-down walk, from the second-last instruction in the |
| 59 | * superblock, to eliminate redundant loads and stores. |
| 60 | * |
| 61 | * An earlier load can eliminate a later load iff |
| 62 | * 1) They are must-aliases |
| 63 | * 2) The native register is not clobbered in between |
| 64 | * 3) The memory location is not written to in between |
| 65 | * |
| 66 | * An earlier store can eliminate a later load iff |
| 67 | * 1) They are must-aliases |
| 68 | * 2) The native register is not clobbered in between |
| 69 | * 3) The memory location is not written to in between |
| 70 | * |
| 71 | * A later store can be eliminated by an earlier store iff |
| 72 | * 1) They are must-aliases |
| 73 | * 2) The memory location is not written to in between |
| 74 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 75 | void Mir2Lir::ApplyLoadStoreElimination(LIR* head_lir, LIR* tail_lir) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 76 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 77 | LIR* this_lir; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 78 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 79 | if (head_lir == tail_lir) return; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 80 | |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 81 | for (this_lir = PREV_LIR(tail_lir); this_lir != head_lir; this_lir = PREV_LIR(this_lir)) { |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 82 | |
| 83 | if (is_pseudo_opcode(this_lir->opcode)) continue; |
| 84 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 85 | int sink_distance = 0; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 86 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 87 | uint64_t target_flags = GetTargetInstFlags(this_lir->opcode); |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 88 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 89 | /* Skip non-interesting instructions */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 90 | if ((this_lir->flags.is_nop == true) || |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 91 | (target_flags & IS_BRANCH) || |
| 92 | ((target_flags & (REG_DEF0 | REG_DEF1)) == (REG_DEF0 | REG_DEF1)) || // Skip wide loads. |
| 93 | ((target_flags & (REG_USE0 | REG_USE1 | REG_USE2)) == |
| 94 | (REG_USE0 | REG_USE1 | REG_USE2)) || // Skip wide stores. |
| 95 | !(target_flags & (IS_LOAD | IS_STORE))) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 96 | continue; |
| 97 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 98 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 99 | int native_reg_id; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 100 | if (cu_->instruction_set == kX86) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 101 | // If x86, location differs depending on whether memory/reg operation. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 102 | native_reg_id = (GetTargetInstFlags(this_lir->opcode) & IS_STORE) ? this_lir->operands[2] |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 103 | : this_lir->operands[0]; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 104 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 105 | native_reg_id = this_lir->operands[0]; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 106 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 107 | bool is_this_lir_load = GetTargetInstFlags(this_lir->opcode) & IS_LOAD; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 108 | LIR* check_lir; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 109 | /* Use the mem mask to determine the rough memory location */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 110 | uint64_t this_mem_mask = (this_lir->use_mask | this_lir->def_mask) & ENCODE_MEM; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 111 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 112 | /* |
| 113 | * Currently only eliminate redundant ld/st for constant and Dalvik |
| 114 | * register accesses. |
| 115 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 116 | if (!(this_mem_mask & (ENCODE_LITERAL | ENCODE_DALVIK_REG))) continue; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 117 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 118 | uint64_t stop_def_reg_mask = this_lir->def_mask & ~ENCODE_MEM; |
| 119 | uint64_t stop_use_reg_mask; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 120 | if (cu_->instruction_set == kX86) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 121 | stop_use_reg_mask = (IS_BRANCH | this_lir->use_mask) & ~ENCODE_MEM; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 122 | } else { |
| 123 | /* |
| 124 | * Add pc to the resource mask to prevent this instruction |
| 125 | * from sinking past branch instructions. Also take out the memory |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 126 | * region bits since stop_mask is used to check data/control |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 127 | * dependencies. |
| 128 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 129 | stop_use_reg_mask = (GetPCUseDefEncoding() | this_lir->use_mask) & ~ENCODE_MEM; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 130 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 131 | |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 132 | for (check_lir = NEXT_LIR(this_lir); check_lir != tail_lir; check_lir = NEXT_LIR(check_lir)) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 133 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 134 | /* |
| 135 | * Skip already dead instructions (whose dataflow information is |
| 136 | * outdated and misleading). |
| 137 | */ |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 138 | if (check_lir->flags.is_nop || is_pseudo_opcode(check_lir->opcode)) continue; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 139 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 140 | uint64_t check_mem_mask = (check_lir->use_mask | check_lir->def_mask) & ENCODE_MEM; |
| 141 | uint64_t alias_condition = this_mem_mask & check_mem_mask; |
| 142 | bool stop_here = false; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 143 | |
| 144 | /* |
| 145 | * Potential aliases seen - check the alias relations |
| 146 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 147 | uint64_t check_flags = GetTargetInstFlags(check_lir->opcode); |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 148 | // TUNING: Support instructions with multiple register targets. |
| 149 | if ((check_flags & (REG_DEF0 | REG_DEF1)) == (REG_DEF0 | REG_DEF1)) { |
| 150 | stop_here = true; |
| 151 | } else if (check_mem_mask != ENCODE_MEM && alias_condition != 0) { |
| 152 | bool is_check_lir_load = check_flags & IS_LOAD; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 153 | if (alias_condition == ENCODE_LITERAL) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 154 | /* |
| 155 | * Should only see literal loads in the instruction |
| 156 | * stream. |
| 157 | */ |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 158 | DCHECK(!(check_flags & IS_STORE)); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 159 | /* Same value && same register type */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 160 | if (check_lir->alias_info == this_lir->alias_info && |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 161 | SameRegType(check_lir->operands[0], native_reg_id)) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 162 | /* |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 163 | * Different destination register - insert |
| 164 | * a move |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 165 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 166 | if (check_lir->operands[0] != native_reg_id) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 167 | ConvertMemOpIntoMove(check_lir, check_lir->operands[0], native_reg_id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 168 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 169 | check_lir->flags.is_nop = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 170 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 171 | } else if (alias_condition == ENCODE_DALVIK_REG) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 172 | /* Must alias */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 173 | if (check_lir->alias_info == this_lir->alias_info) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 174 | /* Only optimize compatible registers */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 175 | bool reg_compatible = SameRegType(check_lir->operands[0], native_reg_id); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 176 | if ((is_this_lir_load && is_check_lir_load) || |
| 177 | (!is_this_lir_load && is_check_lir_load)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 178 | /* RAR or RAW */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 179 | if (reg_compatible) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 180 | /* |
| 181 | * Different destination register - |
| 182 | * insert a move |
| 183 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 184 | if (check_lir->operands[0] != |
| 185 | native_reg_id) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 186 | ConvertMemOpIntoMove(check_lir, check_lir->operands[0], native_reg_id); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 187 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 188 | check_lir->flags.is_nop = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 189 | } else { |
| 190 | /* |
| 191 | * Destinaions are of different types - |
| 192 | * something complicated going on so |
| 193 | * stop looking now. |
| 194 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 195 | stop_here = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 196 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 197 | } else if (is_this_lir_load && !is_check_lir_load) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 198 | /* WAR - register value is killed */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 199 | stop_here = true; |
| 200 | } else if (!is_this_lir_load && !is_check_lir_load) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 201 | /* WAW - nuke the earlier store */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 202 | this_lir->flags.is_nop = true; |
| 203 | stop_here = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 204 | } |
| 205 | /* Partial overlap */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 206 | } else if (IsDalvikRegisterClobbered(this_lir, check_lir)) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 207 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 208 | * It is actually ok to continue if check_lir |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 209 | * is a read. But it is hard to make a test |
| 210 | * case for this so we just stop here to be |
| 211 | * conservative. |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 212 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 213 | stop_here = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 214 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 215 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 216 | /* Memory content may be updated. Stop looking now. */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 217 | if (stop_here) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 218 | break; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 219 | /* The check_lir has been transformed - check the next one */ |
| 220 | } else if (check_lir->flags.is_nop) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 221 | continue; |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | |
| 226 | /* |
| 227 | * this and check LIRs have no memory dependency. Now check if |
| 228 | * their register operands have any RAW, WAR, and WAW |
| 229 | * dependencies. If so, stop looking. |
| 230 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 231 | if (stop_here == false) { |
| 232 | stop_here = CHECK_REG_DEP(stop_use_reg_mask, stop_def_reg_mask, check_lir); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 233 | } |
| 234 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 235 | if (stop_here == true) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 236 | if (cu_->instruction_set == kX86) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 237 | // Prevent stores from being sunk between ops that generate ccodes and |
| 238 | // ops that use them. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 239 | uint64_t flags = GetTargetInstFlags(check_lir->opcode); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 240 | if (sink_distance > 0 && (flags & IS_BRANCH) && (flags & USES_CCODES)) { |
| 241 | check_lir = PREV_LIR(check_lir); |
| 242 | sink_distance--; |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 243 | } |
jeffhao | 573b429 | 2012-07-30 16:37:41 -0700 | [diff] [blame] | 244 | } |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 245 | DEBUG_OPT(dump_dependent_insn_pair(this_lir, check_lir, "REG CLOBBERED")); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 246 | /* Only sink store instructions */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 247 | if (sink_distance && !is_this_lir_load) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 248 | LIR* new_store_lir = static_cast<LIR*>(NewMem(cu_, sizeof(LIR), true, kAllocLIR)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 249 | *new_store_lir = *this_lir; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 250 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 251 | * Stop point found - insert *before* the check_lir |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 252 | * since the instruction list is scanned in the |
| 253 | * top-down order. |
| 254 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 255 | InsertLIRBefore(check_lir, new_store_lir); |
| 256 | this_lir->flags.is_nop = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 257 | } |
| 258 | break; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 259 | } else if (!check_lir->flags.is_nop) { |
| 260 | sink_distance++; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 261 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 262 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 263 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Perform a pass of bottom-up walk, from the second instruction in the |
| 268 | * superblock, to try to hoist loads to earlier slots. |
| 269 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 270 | void Mir2Lir::ApplyLoadHoisting(LIR* head_lir, LIR* tail_lir) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 271 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 272 | LIR* this_lir, *check_lir; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 273 | /* |
| 274 | * Store the list of independent instructions that can be hoisted past. |
| 275 | * Will decide the best place to insert later. |
| 276 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 277 | LIR* prev_inst_list[MAX_HOIST_DISTANCE]; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 278 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 279 | /* Empty block */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 280 | if (head_lir == tail_lir) return; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 281 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 282 | /* Start from the second instruction */ |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 283 | for (this_lir = NEXT_LIR(head_lir); this_lir != tail_lir; this_lir = NEXT_LIR(this_lir)) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 284 | |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 285 | if (is_pseudo_opcode(this_lir->opcode)) continue; |
| 286 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 287 | uint64_t target_flags = GetTargetInstFlags(this_lir->opcode); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 288 | /* Skip non-interesting instructions */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 289 | if ((this_lir->flags.is_nop == true) || |
buzbee | 4ef3e45 | 2012-12-14 13:35:28 -0800 | [diff] [blame] | 290 | ((target_flags & (REG_DEF0 | REG_DEF1)) == (REG_DEF0 | REG_DEF1)) || |
| 291 | !(target_flags & IS_LOAD)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 292 | continue; |
| 293 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 294 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 295 | uint64_t stop_use_all_mask = this_lir->use_mask; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 296 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 297 | if (cu_->instruction_set != kX86) { |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 298 | /* |
| 299 | * Branches for null/range checks are marked with the true resource |
| 300 | * bits, and loads to Dalvik registers, constant pools, and non-alias |
| 301 | * locations are safe to be hoisted. So only mark the heap references |
| 302 | * conservatively here. |
| 303 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 304 | if (stop_use_all_mask & ENCODE_HEAP_REF) { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 305 | stop_use_all_mask |= GetPCUseDefEncoding(); |
buzbee | b046e16 | 2012-10-30 15:48:42 -0700 | [diff] [blame] | 306 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 307 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 308 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 309 | /* Similar as above, but just check for pure register dependency */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 310 | uint64_t stop_use_reg_mask = stop_use_all_mask & ~ENCODE_MEM; |
| 311 | uint64_t stop_def_reg_mask = this_lir->def_mask & ~ENCODE_MEM; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 312 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 313 | int next_slot = 0; |
| 314 | bool stop_here = false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 315 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 316 | /* Try to hoist the load to a good spot */ |
buzbee | 28c9a83 | 2012-11-21 15:39:13 -0800 | [diff] [blame] | 317 | for (check_lir = PREV_LIR(this_lir); check_lir != head_lir; check_lir = PREV_LIR(check_lir)) { |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 318 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 319 | /* |
| 320 | * Skip already dead instructions (whose dataflow information is |
| 321 | * outdated and misleading). |
| 322 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 323 | if (check_lir->flags.is_nop) continue; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 324 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 325 | uint64_t check_mem_mask = check_lir->def_mask & ENCODE_MEM; |
| 326 | uint64_t alias_condition = stop_use_all_mask & check_mem_mask; |
| 327 | stop_here = false; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 328 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 329 | /* Potential WAR alias seen - check the exact relation */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 330 | if (check_mem_mask != ENCODE_MEM && alias_condition != 0) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 331 | /* We can fully disambiguate Dalvik references */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 332 | if (alias_condition == ENCODE_DALVIK_REG) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 333 | /* Must alias or partually overlap */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 334 | if ((check_lir->alias_info == this_lir->alias_info) || |
| 335 | IsDalvikRegisterClobbered(this_lir, check_lir)) { |
| 336 | stop_here = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 337 | } |
| 338 | /* Conservatively treat all heap refs as may-alias */ |
| 339 | } else { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 340 | DCHECK_EQ(alias_condition, ENCODE_HEAP_REF); |
| 341 | stop_here = true; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 342 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 343 | /* Memory content may be updated. Stop looking now. */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 344 | if (stop_here) { |
| 345 | prev_inst_list[next_slot++] = check_lir; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 346 | break; |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 347 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 348 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 349 | |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 350 | if (stop_here == false) { |
| 351 | stop_here = CHECK_REG_DEP(stop_use_reg_mask, stop_def_reg_mask, |
| 352 | check_lir); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 353 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 354 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 355 | /* |
| 356 | * Store the dependent or non-pseudo/indepedent instruction to the |
| 357 | * list. |
| 358 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 359 | if (stop_here || !is_pseudo_opcode(check_lir->opcode)) { |
| 360 | prev_inst_list[next_slot++] = check_lir; |
| 361 | if (next_slot == MAX_HOIST_DISTANCE) break; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 362 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 363 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 364 | /* Found a new place to put the load - move it here */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 365 | if (stop_here == true) { |
| 366 | DEBUG_OPT(dump_dependent_insn_pair(check_lir, this_lir "HOIST STOP")); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 367 | break; |
| 368 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 369 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 370 | |
| 371 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 372 | * Reached the top - use head_lir as the dependent marker as all labels |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 373 | * are barriers. |
| 374 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 375 | if (stop_here == false && next_slot < MAX_HOIST_DISTANCE) { |
| 376 | prev_inst_list[next_slot++] = head_lir; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | /* |
| 380 | * At least one independent instruction is found. Scan in the reversed |
| 381 | * direction to find a beneficial slot. |
| 382 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 383 | if (next_slot >= 2) { |
| 384 | int first_slot = next_slot - 2; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 385 | int slot; |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 386 | LIR* dep_lir = prev_inst_list[next_slot-1]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 387 | /* If there is ld-ld dependency, wait LDLD_DISTANCE cycles */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 388 | if (!is_pseudo_opcode(dep_lir->opcode) && |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 389 | (GetTargetInstFlags(dep_lir->opcode) & IS_LOAD)) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 390 | first_slot -= LDLD_DISTANCE; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 391 | } |
| 392 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 393 | * Make sure we check slot >= 0 since first_slot may be negative |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 394 | * when the loop is first entered. |
| 395 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 396 | for (slot = first_slot; slot >= 0; slot--) { |
| 397 | LIR* cur_lir = prev_inst_list[slot]; |
| 398 | LIR* prev_lir = prev_inst_list[slot+1]; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 399 | |
| 400 | /* Check the highest instruction */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 401 | if (prev_lir->def_mask == ENCODE_ALL) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 402 | /* |
| 403 | * If the first instruction is a load, don't hoist anything |
| 404 | * above it since it is unlikely to be beneficial. |
| 405 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 406 | if (GetTargetInstFlags(cur_lir->opcode) & IS_LOAD) continue; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 407 | /* |
| 408 | * If the remaining number of slots is less than LD_LATENCY, |
| 409 | * insert the hoisted load here. |
| 410 | */ |
| 411 | if (slot < LD_LATENCY) break; |
| 412 | } |
| 413 | |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 414 | // Don't look across a barrier label |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 415 | if ((prev_lir->opcode == kPseudoTargetLabel) || |
| 416 | (prev_lir->opcode == kPseudoSafepointPC) || |
| 417 | (prev_lir->opcode == kPseudoBarrier)) { |
buzbee | 8320f38 | 2012-09-11 16:29:42 -0700 | [diff] [blame] | 418 | break; |
| 419 | } |
| 420 | |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 421 | /* |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 422 | * Try to find two instructions with load/use dependency until |
| 423 | * the remaining instructions are less than LD_LATENCY. |
| 424 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 425 | bool prev_is_load = is_pseudo_opcode(prev_lir->opcode) ? false : |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 426 | (GetTargetInstFlags(prev_lir->opcode) & IS_LOAD); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 427 | if (((cur_lir->use_mask & prev_lir->def_mask) && prev_is_load) || (slot < LD_LATENCY)) { |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 428 | break; |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /* Found a slot to hoist to */ |
| 433 | if (slot >= 0) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 434 | LIR* cur_lir = prev_inst_list[slot]; |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 435 | LIR* new_load_lir = static_cast<LIR*>(NewMem(cu_, sizeof(LIR), true, kAllocLIR)); |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 436 | *new_load_lir = *this_lir; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 437 | /* |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 438 | * Insertion is guaranteed to succeed since check_lir |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 439 | * is never the first LIR on the list |
| 440 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 441 | InsertLIRBefore(cur_lir, new_load_lir); |
| 442 | this_lir->flags.is_nop = true; |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 443 | } |
| 444 | } |
| 445 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 446 | } |
| 447 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 448 | void Mir2Lir::ApplyLocalOptimizations(LIR* head_lir, LIR* tail_lir) |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 449 | { |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 450 | if (!(cu_->disable_opt & (1 << kLoadStoreElimination))) { |
| 451 | ApplyLoadStoreElimination(head_lir, tail_lir); |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 452 | } |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 453 | if (!(cu_->disable_opt & (1 << kLoadHoisting))) { |
| 454 | ApplyLoadHoisting(head_lir, tail_lir); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 455 | } |
| 456 | } |
| 457 | |
| 458 | /* |
| 459 | * Nop any unconditional branches that go to the next instruction. |
| 460 | * Note: new redundant branches may be inserted later, and we'll |
| 461 | * use a check in final instruction assembly to nop those out. |
| 462 | */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 463 | void Mir2Lir::RemoveRedundantBranches() |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 464 | { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 465 | LIR* this_lir; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 466 | |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 467 | for (this_lir = first_lir_insn_; this_lir != last_lir_insn_; this_lir = NEXT_LIR(this_lir)) { |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 468 | |
| 469 | /* Branch to the next instruction */ |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 470 | if (IsUnconditionalBranch(this_lir)) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 471 | LIR* next_lir = this_lir; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 472 | |
| 473 | while (true) { |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 474 | next_lir = NEXT_LIR(next_lir); |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 475 | |
| 476 | /* |
| 477 | * Is the branch target the next instruction? |
| 478 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 479 | if (next_lir == this_lir->target) { |
| 480 | this_lir->flags.is_nop = true; |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 481 | break; |
| 482 | } |
| 483 | |
| 484 | /* |
| 485 | * Found real useful stuff between the branch and the target. |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 486 | * Need to explicitly check the last_lir_insn_ here because it |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 487 | * might be the last real instruction. |
| 488 | */ |
buzbee | fa57c47 | 2012-11-21 12:06:18 -0800 | [diff] [blame] | 489 | if (!is_pseudo_opcode(next_lir->opcode) || |
buzbee | 1fd3346 | 2013-03-25 13:40:45 -0700 | [diff] [blame^] | 490 | (next_lir == last_lir_insn_)) |
buzbee | cbd6d44 | 2012-11-17 14:11:25 -0800 | [diff] [blame] | 491 | break; |
| 492 | } |
| 493 | } |
Bill Buzbee | a114add | 2012-05-03 15:00:40 -0700 | [diff] [blame] | 494 | } |
buzbee | 67bf885 | 2011-08-17 17:51:35 -0700 | [diff] [blame] | 495 | } |
Elliott Hughes | 11d1b0c | 2012-01-23 16:57:47 -0800 | [diff] [blame] | 496 | |
| 497 | } // namespace art |