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

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

Issue 1641723002: [interpreter] Translate exception handlers into graph. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments. 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') | src/compiler/bytecode-graph-builder.h » ('j') | 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 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 BytecodeBranchAnalysis::BytecodeBranchAnalysis( 48 BytecodeBranchAnalysis::BytecodeBranchAnalysis(
49 Handle<BytecodeArray> bytecode_array, Zone* zone) 49 Handle<BytecodeArray> bytecode_array, Zone* zone)
50 : branch_infos_(zone), 50 : branch_infos_(zone),
51 bytecode_array_(bytecode_array), 51 bytecode_array_(bytecode_array),
52 reachable_(bytecode_array->length(), zone), 52 reachable_(bytecode_array->length(), zone),
53 zone_(zone) {} 53 zone_(zone) {}
54 54
55 55
56 void BytecodeBranchAnalysis::Analyze() { 56 void BytecodeBranchAnalysis::Analyze() {
57 interpreter::BytecodeArrayIterator iterator(bytecode_array()); 57 interpreter::BytecodeArrayIterator iterator(bytecode_array());
58 AnalyzeExceptionHandlers();
58 bool reachable = true; 59 bool reachable = true;
59 while (!iterator.done()) { 60 while (!iterator.done()) {
60 interpreter::Bytecode bytecode = iterator.current_bytecode(); 61 interpreter::Bytecode bytecode = iterator.current_bytecode();
61 int current_offset = iterator.current_offset(); 62 int current_offset = iterator.current_offset();
62 // All bytecode basic blocks are generated to be forward reachable 63 // All bytecode basic blocks are generated to be forward reachable
63 // and may also be backward reachable. Hence if there's a forward 64 // and may also be backward reachable. Hence if there's a forward
64 // branch targetting here the code becomes reachable. 65 // branch targetting here the code becomes reachable.
65 reachable = reachable || forward_branches_target(current_offset); 66 reachable = reachable || forward_branches_target(current_offset);
67 // Some bytecode basic blocks are reachable through a side-entry
68 // (e.g. exception handler), which has been represented in the
69 // bit-vector by a corresponding pre-pass.
70 reachable = reachable || reachable_.Contains(current_offset);
66 if (reachable) { 71 if (reachable) {
67 reachable_.Add(current_offset); 72 reachable_.Add(current_offset);
68 if (interpreter::Bytecodes::IsConditionalJump(bytecode)) { 73 if (interpreter::Bytecodes::IsConditionalJump(bytecode)) {
69 // Only the branch is recorded, the forward path falls through 74 // Only the branch is recorded, the forward path falls through
70 // and is handled as normal bytecode data flow. 75 // and is handled as normal bytecode data flow.
71 AddBranch(current_offset, iterator.GetJumpTargetOffset()); 76 AddBranch(current_offset, iterator.GetJumpTargetOffset());
72 } else if (interpreter::Bytecodes::IsJump(bytecode)) { 77 } else if (interpreter::Bytecodes::IsJump(bytecode)) {
73 // Unless the branch targets the next bytecode it's not 78 // Unless the branch targets the next bytecode it's not
74 // reachable. If it targets the next bytecode the check at the 79 // reachable. If it targets the next bytecode the check at the
75 // start of the loop will set the reachable flag. 80 // start of the loop will set the reachable flag.
(...skipping 23 matching lines...) Expand all
99 const ZoneVector<int>* BytecodeBranchAnalysis::ForwardBranchesTargetting( 104 const ZoneVector<int>* BytecodeBranchAnalysis::ForwardBranchesTargetting(
100 int offset) const { 105 int offset) const {
101 auto iterator = branch_infos_.find(offset); 106 auto iterator = branch_infos_.find(offset);
102 if (branch_infos_.end() != iterator) { 107 if (branch_infos_.end() != iterator) {
103 return iterator->second->fore_edge_offsets(); 108 return iterator->second->fore_edge_offsets();
104 } else { 109 } else {
105 return nullptr; 110 return nullptr;
106 } 111 }
107 } 112 }
108 113
114 void BytecodeBranchAnalysis::AddExceptionalBranch(int throw_offset,
115 int handler_offset) {
116 DCHECK(is_reachable(handler_offset)); // Handler was marked reachable.
117 DCHECK_LT(throw_offset, handler_offset); // Always a forward branch.
118 AddBranch(throw_offset, handler_offset);
119 }
109 120
110 void BytecodeBranchAnalysis::AddBranch(int source_offset, int target_offset) { 121 void BytecodeBranchAnalysis::AddBranch(int source_offset, int target_offset) {
111 BytecodeBranchInfo* branch_info = nullptr; 122 BytecodeBranchInfo* branch_info = nullptr;
112 auto iterator = branch_infos_.find(target_offset); 123 auto iterator = branch_infos_.find(target_offset);
113 if (branch_infos_.end() == iterator) { 124 if (branch_infos_.end() == iterator) {
114 branch_info = new (zone()) BytecodeBranchInfo(zone()); 125 branch_info = new (zone()) BytecodeBranchInfo(zone());
115 branch_infos_.insert(std::make_pair(target_offset, branch_info)); 126 branch_infos_.insert(std::make_pair(target_offset, branch_info));
116 } else { 127 } else {
117 branch_info = iterator->second; 128 branch_info = iterator->second;
118 } 129 }
119 branch_info->AddBranch(source_offset, target_offset); 130 branch_info->AddBranch(source_offset, target_offset);
120 } 131 }
121 132
133 void BytecodeBranchAnalysis::AnalyzeExceptionHandlers() {
134 HandlerTable* table = HandlerTable::cast(bytecode_array()->handler_table());
135 for (int i = 0; i < table->NumberOfRangeEntries(); ++i) {
136 reachable_.Add(table->GetRangeHandler(i));
137 }
138 }
122 139
123 } // namespace compiler 140 } // namespace compiler
124 } // namespace internal 141 } // namespace internal
125 } // namespace v8 142 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/bytecode-branch-analysis.h ('k') | src/compiler/bytecode-graph-builder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698