| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/bytecode-analysis.h" | 5 #include "src/compiler/bytecode-analysis.h" |
| 6 | 6 |
| 7 #include "src/interpreter/bytecode-array-iterator.h" | 7 #include "src/interpreter/bytecode-array-iterator.h" |
| 8 #include "src/interpreter/bytecode-array-reverse-iterator.h" | 8 #include "src/interpreter/bytecode-array-reverse-iterator.h" |
| 9 #include "src/objects-inl.h" | 9 #include "src/objects-inl.h" |
| 10 | 10 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // The last JumpLoop that we haven't done a guaranteed valid liveness pass | 154 // The last JumpLoop that we haven't done a guaranteed valid liveness pass |
| 155 // over. See the below wall of text for a more thorough explanation. | 155 // over. See the below wall of text for a more thorough explanation. |
| 156 int last_invalid_jumploop_offset = -1; | 156 int last_invalid_jumploop_offset = -1; |
| 157 | 157 |
| 158 BytecodeArrayReverseIterator iterator(bytecode_array(), zone()); | 158 BytecodeArrayReverseIterator iterator(bytecode_array(), zone()); |
| 159 for (; !iterator.done(); iterator.Advance()) { | 159 for (; !iterator.done(); iterator.Advance()) { |
| 160 Bytecode bytecode = iterator.current_bytecode(); | 160 Bytecode bytecode = iterator.current_bytecode(); |
| 161 int current_offset = iterator.current_offset(); | 161 int current_offset = iterator.current_offset(); |
| 162 | 162 |
| 163 if (bytecode == Bytecode::kJumpLoop) { | 163 if (bytecode == Bytecode::kJumpLoop) { |
| 164 PushLoop(iterator.GetJumpTargetOffset(), current_offset); | 164 // Every byte up to and including the last byte within the backwards jump |
| 165 // instruction is considered part of the loop, set loop end accordingly. |
| 166 int loop_end = current_offset + iterator.current_bytecode_size(); |
| 167 PushLoop(iterator.GetJumpTargetOffset(), loop_end); |
| 165 | 168 |
| 166 // Save the last offset so that we can do another pass later. | 169 // Save the last offset so that we can do another pass later. |
| 167 if (last_invalid_jumploop_offset == -1) { | 170 if (last_invalid_jumploop_offset == -1) { |
| 168 last_invalid_jumploop_offset = current_offset; | 171 last_invalid_jumploop_offset = current_offset; |
| 169 } | 172 } |
| 170 } else if (current_offset == loop_stack_.top()) { | 173 } else if (current_offset == loop_stack_.top()) { |
| 171 loop_stack_.pop(); | 174 loop_stack_.pop(); |
| 172 } | 175 } |
| 173 | 176 |
| 174 if (do_liveness_analysis_) { | 177 if (do_liveness_analysis_) { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 header_to_parent_.insert( | 292 header_to_parent_.insert( |
| 290 ZoneMap<int, int>::value_type(loop_header, loop_stack_.top())); | 293 ZoneMap<int, int>::value_type(loop_header, loop_stack_.top())); |
| 291 loop_stack_.push(loop_header); | 294 loop_stack_.push(loop_header); |
| 292 } | 295 } |
| 293 | 296 |
| 294 bool BytecodeAnalysis::IsLoopHeader(int offset) const { | 297 bool BytecodeAnalysis::IsLoopHeader(int offset) const { |
| 295 return header_to_parent_.find(offset) != header_to_parent_.end(); | 298 return header_to_parent_.find(offset) != header_to_parent_.end(); |
| 296 } | 299 } |
| 297 | 300 |
| 298 int BytecodeAnalysis::GetLoopOffsetFor(int offset) const { | 301 int BytecodeAnalysis::GetLoopOffsetFor(int offset) const { |
| 299 auto loop_end_to_header = end_to_header_.lower_bound(offset); | 302 auto loop_end_to_header = end_to_header_.upper_bound(offset); |
| 300 // If there is no next end => offset is not in a loop. | 303 // If there is no next end => offset is not in a loop. |
| 301 if (loop_end_to_header == end_to_header_.end()) { | 304 if (loop_end_to_header == end_to_header_.end()) { |
| 302 return -1; | 305 return -1; |
| 303 } | 306 } |
| 304 // If the header preceeds the offset, this is the loop | 307 // If the header preceeds the offset, this is the loop |
| 305 // | 308 // |
| 306 // .> header <--loop_end_to_header | 309 // .> header <--loop_end_to_header |
| 307 // | | 310 // | |
| 308 // | <--offset | 311 // | <--offset |
| 309 // | | 312 // | |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 495 } |
| 493 } | 496 } |
| 494 | 497 |
| 495 return invalid_offset == -1; | 498 return invalid_offset == -1; |
| 496 } | 499 } |
| 497 #endif | 500 #endif |
| 498 | 501 |
| 499 } // namespace compiler | 502 } // namespace compiler |
| 500 } // namespace internal | 503 } // namespace internal |
| 501 } // namespace v8 | 504 } // namespace v8 |
| OLD | NEW |