Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler/bytecode-branch-analysis.h" |
| 6 | |
| 7 | #include "src/interpreter/bytecode-array-iterator.h" |
| 8 | #include "src/objects-inl.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | namespace compiler { |
| 13 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 14 | BytecodeBranchAnalysis::BytecodeBranchAnalysis( |
| 15 | Handle<BytecodeArray> bytecode_array, Zone* zone) |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 16 | : bytecode_array_(bytecode_array), |
| 17 | is_backward_target_(bytecode_array->length(), zone), |
| 18 | is_forward_target_(bytecode_array->length(), zone), |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 19 | zone_(zone) {} |
| 20 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 21 | void BytecodeBranchAnalysis::Analyze() { |
| 22 | interpreter::BytecodeArrayIterator iterator(bytecode_array()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 23 | while (!iterator.done()) { |
| 24 | interpreter::Bytecode bytecode = iterator.current_bytecode(); |
| 25 | int current_offset = iterator.current_offset(); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 26 | if (interpreter::Bytecodes::IsJump(bytecode)) { |
| 27 | AddBranch(current_offset, iterator.GetJumpTargetOffset()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 28 | } |
| 29 | iterator.Advance(); |
| 30 | } |
| 31 | } |
| 32 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 33 | void BytecodeBranchAnalysis::AddBranch(int source_offset, int target_offset) { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 34 | if (source_offset < target_offset) { |
| 35 | is_forward_target_.Add(target_offset); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 36 | } else { |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 37 | is_backward_target_.Add(target_offset); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 38 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 39 | } |
| 40 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 41 | } // namespace compiler |
| 42 | } // namespace internal |
| 43 | } // namespace v8 |