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

Side by Side Diff: src/interpreter/control-flow-builders.cc

Issue 2254493002: [interpreter] Use VisitForTest for loop conditions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebase(line) golden file Created 4 years, 4 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
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/interpreter/control-flow-builders.h" 5 #include "src/interpreter/control-flow-builders.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace interpreter { 9 namespace interpreter {
10 10
11 11
12 BreakableControlFlowBuilder::~BreakableControlFlowBuilder() { 12 BreakableControlFlowBuilder::~BreakableControlFlowBuilder() {
13 DCHECK(break_sites_.empty()); 13 DCHECK(break_labels_.empty() || break_labels_.is_bound());
14 } 14 }
15 15
16 16 void BreakableControlFlowBuilder::BindBreakTarget() {
17 void BreakableControlFlowBuilder::SetBreakTarget(const BytecodeLabel& target) { 17 break_labels_.Bind(builder());
18 BindLabels(target, &break_sites_);
19 } 18 }
20 19
21 20 void BreakableControlFlowBuilder::EmitJump(BytecodeLabels* sites) {
22 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites) { 21 builder()->Jump(sites->New());
23 sites->push_back(BytecodeLabel());
24 builder()->Jump(&sites->back());
25 } 22 }
26 23
27 24 void BreakableControlFlowBuilder::EmitJumpIfTrue(BytecodeLabels* sites) {
28 void BreakableControlFlowBuilder::EmitJumpIfTrue( 25 builder()->JumpIfTrue(sites->New());
29 ZoneVector<BytecodeLabel>* sites) {
30 sites->push_back(BytecodeLabel());
31 builder()->JumpIfTrue(&sites->back());
32 } 26 }
33 27
34 28 void BreakableControlFlowBuilder::EmitJumpIfFalse(BytecodeLabels* sites) {
35 void BreakableControlFlowBuilder::EmitJumpIfFalse( 29 builder()->JumpIfFalse(sites->New());
36 ZoneVector<BytecodeLabel>* sites) {
37 sites->push_back(BytecodeLabel());
38 builder()->JumpIfFalse(&sites->back());
39 } 30 }
40 31
41 32 void BreakableControlFlowBuilder::EmitJumpIfUndefined(BytecodeLabels* sites) {
42 void BreakableControlFlowBuilder::EmitJumpIfUndefined( 33 builder()->JumpIfUndefined(sites->New());
43 ZoneVector<BytecodeLabel>* sites) {
44 sites->push_back(BytecodeLabel());
45 builder()->JumpIfUndefined(&sites->back());
46 } 34 }
47 35
48 36 void BreakableControlFlowBuilder::EmitJumpIfNull(BytecodeLabels* sites) {
49 void BreakableControlFlowBuilder::EmitJumpIfNull( 37 builder()->JumpIfNull(sites->New());
50 ZoneVector<BytecodeLabel>* sites) {
51 sites->push_back(BytecodeLabel());
52 builder()->JumpIfNull(&sites->back());
53 }
54
55
56 void BreakableControlFlowBuilder::EmitJump(ZoneVector<BytecodeLabel>* sites,
57 int index) {
58 builder()->Jump(&sites->at(index));
59 }
60
61
62 void BreakableControlFlowBuilder::EmitJumpIfTrue(
63 ZoneVector<BytecodeLabel>* sites, int index) {
64 builder()->JumpIfTrue(&sites->at(index));
65 }
66
67
68 void BreakableControlFlowBuilder::EmitJumpIfFalse(
69 ZoneVector<BytecodeLabel>* sites, int index) {
70 builder()->JumpIfFalse(&sites->at(index));
71 }
72
73
74 void BreakableControlFlowBuilder::BindLabels(const BytecodeLabel& target,
75 ZoneVector<BytecodeLabel>* sites) {
76 for (size_t i = 0; i < sites->size(); i++) {
77 BytecodeLabel& site = sites->at(i);
78 builder()->Bind(target, &site);
79 }
80 sites->clear();
81 } 38 }
82 39
83 40
84 void BlockBuilder::EndBlock() { 41 void BlockBuilder::EndBlock() {
85 builder()->Bind(&block_end_); 42 builder()->Bind(&block_end_);
86 SetBreakTarget(block_end_); 43 BindBreakTarget();
87 } 44 }
88 45
89 46 LoopBuilder::~LoopBuilder() {
90 LoopBuilder::~LoopBuilder() { DCHECK(continue_sites_.empty()); } 47 DCHECK(continue_labels_.empty() || continue_labels_.is_bound());
91 48 DCHECK(header_labels_.empty() || header_labels_.is_bound());
49 }
92 50
93 void LoopBuilder::LoopHeader(ZoneVector<BytecodeLabel>* additional_labels) { 51 void LoopBuilder::LoopHeader(ZoneVector<BytecodeLabel>* additional_labels) {
94 // Jumps from before the loop header into the loop violate ordering 52 // Jumps from before the loop header into the loop violate ordering
95 // requirements of bytecode basic blocks. The only entry into a loop 53 // requirements of bytecode basic blocks. The only entry into a loop
96 // must be the loop header. Surely breaks is okay? Not if nested 54 // must be the loop header. Surely breaks is okay? Not if nested
97 // and misplaced between the headers. 55 // and misplaced between the headers.
98 DCHECK(break_sites_.empty() && continue_sites_.empty()); 56 DCHECK(break_labels_.empty() && continue_labels_.empty());
99 builder()->Bind(&loop_header_); 57 builder()->Bind(&loop_header_);
100 for (auto& label : *additional_labels) { 58 for (auto& label : *additional_labels) {
101 builder()->Bind(loop_header_, &label); 59 builder()->Bind(&label);
102 } 60 }
103 } 61 }
104 62
105 void LoopBuilder::JumpToHeader() { 63 void LoopBuilder::JumpToHeader() {
106 // Loop must have closed form, i.e. all loop elements are within the loop, 64 // Loop must have closed form, i.e. all loop elements are within the loop,
107 // the loop header precedes the body and next elements in the loop. 65 // the loop header precedes the body and next elements in the loop.
108 DCHECK(loop_header_.is_bound()); 66 DCHECK(loop_header_.is_bound());
109 builder()->Jump(&loop_header_); 67 builder()->Jump(&loop_header_);
110 } 68 }
111 69
112 void LoopBuilder::JumpToHeaderIfTrue() { 70 void LoopBuilder::JumpToHeaderIfTrue() {
113 // Loop must have closed form, i.e. all loop elements are within the loop, 71 // Loop must have closed form, i.e. all loop elements are within the loop,
114 // the loop header precedes the body and next elements in the loop. 72 // the loop header precedes the body and next elements in the loop.
115 DCHECK(loop_header_.is_bound()); 73 DCHECK(loop_header_.is_bound());
116 builder()->JumpIfTrue(&loop_header_); 74 builder()->JumpIfTrue(&loop_header_);
117 } 75 }
118 76
119 void LoopBuilder::EndLoop() { 77 void LoopBuilder::EndLoop() {
120 builder()->Bind(&loop_end_); 78 BindBreakTarget();
121 SetBreakTarget(loop_end_); 79 header_labels_.BindToLabel(builder(), loop_header_);
122 } 80 }
123 81
124 void LoopBuilder::SetContinueTarget() { 82 void LoopBuilder::BindContinueTarget() { continue_labels_.Bind(builder()); }
125 BytecodeLabel target;
126 builder()->Bind(&target);
127 BindLabels(target, &continue_sites_);
128 }
129
130 83
131 SwitchBuilder::~SwitchBuilder() { 84 SwitchBuilder::~SwitchBuilder() {
132 #ifdef DEBUG 85 #ifdef DEBUG
133 for (auto site : case_sites_) { 86 for (auto site : case_sites_) {
134 DCHECK(site.is_bound()); 87 DCHECK(site.is_bound());
135 } 88 }
136 #endif 89 #endif
137 } 90 }
138 91
139 92
(...skipping 18 matching lines...) Expand all
158 111
159 void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); } 112 void TryCatchBuilder::EndCatch() { builder()->Bind(&exit_); }
160 113
161 114
162 void TryFinallyBuilder::BeginTry(Register context) { 115 void TryFinallyBuilder::BeginTry(Register context) {
163 builder()->MarkTryBegin(handler_id_, context); 116 builder()->MarkTryBegin(handler_id_, context);
164 } 117 }
165 118
166 119
167 void TryFinallyBuilder::LeaveTry() { 120 void TryFinallyBuilder::LeaveTry() {
168 finalization_sites_.push_back(BytecodeLabel()); 121 builder()->Jump(finalization_sites_.New());
169 builder()->Jump(&finalization_sites_.back());
170 } 122 }
171 123
172 124
173 void TryFinallyBuilder::EndTry() { 125 void TryFinallyBuilder::EndTry() {
174 builder()->MarkTryEnd(handler_id_); 126 builder()->MarkTryEnd(handler_id_);
175 } 127 }
176 128
177 129
178 void TryFinallyBuilder::BeginHandler() { 130 void TryFinallyBuilder::BeginHandler() {
179 builder()->Bind(&handler_); 131 builder()->Bind(&handler_);
180 builder()->MarkHandler(handler_id_, catch_prediction_); 132 builder()->MarkHandler(handler_id_, catch_prediction_);
181 } 133 }
182 134
183 135 void TryFinallyBuilder::BeginFinally() { finalization_sites_.Bind(builder()); }
184 void TryFinallyBuilder::BeginFinally() {
185 for (size_t i = 0; i < finalization_sites_.size(); i++) {
186 BytecodeLabel& site = finalization_sites_.at(i);
187 builder()->Bind(&site);
188 }
189 }
190
191 136
192 void TryFinallyBuilder::EndFinally() { 137 void TryFinallyBuilder::EndFinally() {
193 // Nothing to be done here. 138 // Nothing to be done here.
194 } 139 }
195 140
196 } // namespace interpreter 141 } // namespace interpreter
197 } // namespace internal 142 } // namespace internal
198 } // namespace v8 143 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/control-flow-builders.h ('k') | test/cctest/compiler/test-run-bytecode-graph-builder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698