Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: src/compiler/bytecode-branch-analysis.cc

Issue 1646873004: [interpreter] Simplify BytecodeBranchAnalysis to minimum. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_interpreter-cleanup-graph-builder-reachability
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/bytecode-branch-analysis.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 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-branch-analysis.h" 5 #include "src/compiler/bytecode-branch-analysis.h"
6 6
7 #include "src/interpreter/bytecode-array-iterator.h" 7 #include "src/interpreter/bytecode-array-iterator.h"
8 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 namespace compiler { 12 namespace compiler {
13 13
14 // The class contains all of the sites that contain
15 // branches to a particular target (bytecode offset).
16 class BytecodeBranchInfo final : public ZoneObject {
17 public:
18 explicit BytecodeBranchInfo(Zone* zone)
19 : back_edge_offsets_(zone), fore_edge_offsets_(zone) {}
20
21 void AddBranch(int source_offset, int target_offset);
22
23 // The offsets of bytecodes that refer to this bytecode as
24 // a back-edge predecessor.
25 const ZoneVector<int>* back_edge_offsets() { return &back_edge_offsets_; }
26
27 // The offsets of bytecodes that refer to this bytecode as
28 // a forwards-edge predecessor.
29 const ZoneVector<int>* fore_edge_offsets() { return &fore_edge_offsets_; }
30
31 private:
32 ZoneVector<int> back_edge_offsets_;
33 ZoneVector<int> fore_edge_offsets_;
34
35 DISALLOW_COPY_AND_ASSIGN(BytecodeBranchInfo);
36 };
37
38
39 void BytecodeBranchInfo::AddBranch(int source_offset, int target_offset) {
40 if (source_offset < target_offset) {
41 fore_edge_offsets_.push_back(source_offset);
42 } else {
43 back_edge_offsets_.push_back(source_offset);
44 }
45 }
46
47
48 BytecodeBranchAnalysis::BytecodeBranchAnalysis( 14 BytecodeBranchAnalysis::BytecodeBranchAnalysis(
49 Handle<BytecodeArray> bytecode_array, Zone* zone) 15 Handle<BytecodeArray> bytecode_array, Zone* zone)
50 : branch_infos_(zone), 16 : bytecode_array_(bytecode_array),
51 bytecode_array_(bytecode_array), 17 is_backward_target_(bytecode_array->length(), zone),
18 is_forward_target_(bytecode_array->length(), zone),
52 zone_(zone) {} 19 zone_(zone) {}
53 20
54
55 void BytecodeBranchAnalysis::Analyze() { 21 void BytecodeBranchAnalysis::Analyze() {
56 interpreter::BytecodeArrayIterator iterator(bytecode_array()); 22 interpreter::BytecodeArrayIterator iterator(bytecode_array());
57 while (!iterator.done()) { 23 while (!iterator.done()) {
58 interpreter::Bytecode bytecode = iterator.current_bytecode(); 24 interpreter::Bytecode bytecode = iterator.current_bytecode();
59 int current_offset = iterator.current_offset(); 25 int current_offset = iterator.current_offset();
60 if (interpreter::Bytecodes::IsJump(bytecode)) { 26 if (interpreter::Bytecodes::IsJump(bytecode)) {
61 AddBranch(current_offset, iterator.GetJumpTargetOffset()); 27 AddBranch(current_offset, iterator.GetJumpTargetOffset());
62 } 28 }
63 iterator.Advance(); 29 iterator.Advance();
64 } 30 }
65 } 31 }
66 32
67
68 const ZoneVector<int>* BytecodeBranchAnalysis::BackwardBranchesTargetting(
69 int offset) const {
70 auto iterator = branch_infos_.find(offset);
71 if (branch_infos_.end() != iterator) {
72 return iterator->second->back_edge_offsets();
73 } else {
74 return nullptr;
75 }
76 }
77
78
79 const ZoneVector<int>* BytecodeBranchAnalysis::ForwardBranchesTargetting(
80 int offset) const {
81 auto iterator = branch_infos_.find(offset);
82 if (branch_infos_.end() != iterator) {
83 return iterator->second->fore_edge_offsets();
84 } else {
85 return nullptr;
86 }
87 }
88
89 void BytecodeBranchAnalysis::AddBranch(int source_offset, int target_offset) { 33 void BytecodeBranchAnalysis::AddBranch(int source_offset, int target_offset) {
90 BytecodeBranchInfo* branch_info = nullptr; 34 if (source_offset < target_offset) {
91 auto iterator = branch_infos_.find(target_offset); 35 is_forward_target_.Add(target_offset);
92 if (branch_infos_.end() == iterator) {
93 branch_info = new (zone()) BytecodeBranchInfo(zone());
94 branch_infos_.insert(std::make_pair(target_offset, branch_info));
95 } else { 36 } else {
96 branch_info = iterator->second; 37 is_backward_target_.Add(target_offset);
97 } 38 }
98 branch_info->AddBranch(source_offset, target_offset);
99 } 39 }
100 40
101 } // namespace compiler 41 } // namespace compiler
102 } // namespace internal 42 } // namespace internal
103 } // namespace v8 43 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/bytecode-branch-analysis.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698