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

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

Issue 2795183002: [Interpreter] Move ToBoolean elision in BytecodeGenerator. (Closed)
Patch Set: tests Created 3 years, 8 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/interpreter/bytecode-peephole-table.h ('k') | src/interpreter/control-flow-builders.cc » ('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 #ifndef V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ 5 #ifndef V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
6 #define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ 6 #define V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
7 7
8 #include "src/interpreter/bytecode-array-builder.h" 8 #include "src/interpreter/bytecode-array-builder.h"
9 9
10 #include "src/interpreter/bytecode-label.h" 10 #include "src/interpreter/bytecode-label.h"
(...skipping 26 matching lines...) Expand all
37 virtual ~BreakableControlFlowBuilder(); 37 virtual ~BreakableControlFlowBuilder();
38 38
39 // This method should be called by the control flow owner before 39 // This method should be called by the control flow owner before
40 // destruction to update sites that emit jumps for break. 40 // destruction to update sites that emit jumps for break.
41 void BindBreakTarget(); 41 void BindBreakTarget();
42 42
43 // This method is called when visiting break statements in the AST. 43 // This method is called when visiting break statements in the AST.
44 // Inserts a jump to an unbound label that is patched when the corresponding 44 // Inserts a jump to an unbound label that is patched when the corresponding
45 // BindBreakTarget is called. 45 // BindBreakTarget is called.
46 void Break() { EmitJump(&break_labels_); } 46 void Break() { EmitJump(&break_labels_); }
47 void BreakIfTrue() { EmitJumpIfTrue(&break_labels_); } 47 void BreakIfTrue(BytecodeArrayBuilder::ToBooleanMode mode) {
48 void BreakIfFalse() { EmitJumpIfFalse(&break_labels_); } 48 EmitJumpIfTrue(mode, &break_labels_);
49 }
50 void BreakIfFalse(BytecodeArrayBuilder::ToBooleanMode mode) {
51 EmitJumpIfFalse(mode, &break_labels_);
52 }
49 void BreakIfUndefined() { EmitJumpIfUndefined(&break_labels_); } 53 void BreakIfUndefined() { EmitJumpIfUndefined(&break_labels_); }
50 void BreakIfNull() { EmitJumpIfNull(&break_labels_); } 54 void BreakIfNull() { EmitJumpIfNull(&break_labels_); }
51 55
52 BytecodeLabels* break_labels() { return &break_labels_; } 56 BytecodeLabels* break_labels() { return &break_labels_; }
53 57
54 protected: 58 protected:
55 void EmitJump(BytecodeLabels* labels); 59 void EmitJump(BytecodeLabels* labels);
56 void EmitJumpIfTrue(BytecodeLabels* labels); 60 void EmitJumpIfTrue(BytecodeArrayBuilder::ToBooleanMode mode,
57 void EmitJumpIfFalse(BytecodeLabels* labels); 61 BytecodeLabels* labels);
62 void EmitJumpIfFalse(BytecodeArrayBuilder::ToBooleanMode mode,
63 BytecodeLabels* labels);
58 void EmitJumpIfUndefined(BytecodeLabels* labels); 64 void EmitJumpIfUndefined(BytecodeLabels* labels);
59 void EmitJumpIfNull(BytecodeLabels* labels); 65 void EmitJumpIfNull(BytecodeLabels* labels);
60 66
61 // Unbound labels that identify jumps for break statements in the code. 67 // Unbound labels that identify jumps for break statements in the code.
62 BytecodeLabels break_labels_; 68 BytecodeLabels break_labels_;
63 }; 69 };
64 70
65 71
66 // Class to track control flow for block statements (which can break in JS). 72 // Class to track control flow for block statements (which can break in JS).
67 class V8_EXPORT_PRIVATE BlockBuilder final 73 class V8_EXPORT_PRIVATE BlockBuilder final
(...skipping 21 matching lines...) Expand all
89 95
90 void LoopHeader(ZoneVector<BytecodeLabel>* additional_labels = nullptr); 96 void LoopHeader(ZoneVector<BytecodeLabel>* additional_labels = nullptr);
91 void JumpToHeader(int loop_depth); 97 void JumpToHeader(int loop_depth);
92 void BindContinueTarget(); 98 void BindContinueTarget();
93 void EndLoop(); 99 void EndLoop();
94 100
95 // This method is called when visiting continue statements in the AST. 101 // This method is called when visiting continue statements in the AST.
96 // Inserts a jump to an unbound label that is patched when BindContinueTarget 102 // Inserts a jump to an unbound label that is patched when BindContinueTarget
97 // is called. 103 // is called.
98 void Continue() { EmitJump(&continue_labels_); } 104 void Continue() { EmitJump(&continue_labels_); }
99 void ContinueIfTrue() { EmitJumpIfTrue(&continue_labels_); }
100 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_labels_); } 105 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_labels_); }
101 void ContinueIfNull() { EmitJumpIfNull(&continue_labels_); } 106 void ContinueIfNull() { EmitJumpIfNull(&continue_labels_); }
102 107
103 private: 108 private:
104 BytecodeLabel loop_header_; 109 BytecodeLabel loop_header_;
105 110
106 // Unbound labels that identify jumps for continue statements in the code and 111 // Unbound labels that identify jumps for continue statements in the code and
107 // jumps from checking the loop condition to the header for do-while loops. 112 // jumps from checking the loop condition to the header for do-while loops.
108 BytecodeLabels continue_labels_; 113 BytecodeLabels continue_labels_;
109 BytecodeLabels header_labels_; 114 BytecodeLabels header_labels_;
110 }; 115 };
111 116
112 117
113 // A class to help with co-ordinating break statements with their switch. 118 // A class to help with co-ordinating break statements with their switch.
114 class V8_EXPORT_PRIVATE SwitchBuilder final 119 class V8_EXPORT_PRIVATE SwitchBuilder final
115 : public BreakableControlFlowBuilder { 120 : public BreakableControlFlowBuilder {
116 public: 121 public:
117 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases) 122 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases)
118 : BreakableControlFlowBuilder(builder), 123 : BreakableControlFlowBuilder(builder),
119 case_sites_(builder->zone()) { 124 case_sites_(builder->zone()) {
120 case_sites_.resize(number_of_cases); 125 case_sites_.resize(number_of_cases);
121 } 126 }
122 ~SwitchBuilder(); 127 ~SwitchBuilder();
123 128
124 // This method should be called by the SwitchBuilder owner when the case 129 // This method should be called by the SwitchBuilder owner when the case
125 // statement with |index| is emitted to update the case jump site. 130 // statement with |index| is emitted to update the case jump site.
126 void SetCaseTarget(int index); 131 void SetCaseTarget(int index);
127 132
128 // This method is called when visiting case comparison operation for |index|. 133 // This method is called when visiting case comparison operation for |index|.
129 // Inserts a JumpIfTrue to a unbound label that is patched when the 134 // Inserts a JumpIfTrue with ToBooleanMode |mode| to a unbound label that is
130 // corresponding SetCaseTarget is called. 135 // patched when the corresponding SetCaseTarget is called.
131 void Case(int index) { builder()->JumpIfTrue(&case_sites_.at(index)); } 136 void Case(BytecodeArrayBuilder::ToBooleanMode mode, int index) {
137 builder()->JumpIfTrue(mode, &case_sites_.at(index));
138 }
132 139
133 // This method is called when all cases comparisons have been emitted if there 140 // This method is called when all cases comparisons have been emitted if there
134 // is a default case statement. Inserts a Jump to a unbound label that is 141 // is a default case statement. Inserts a Jump to a unbound label that is
135 // patched when the corresponding SetCaseTarget is called. 142 // patched when the corresponding SetCaseTarget is called.
136 void DefaultAt(int index) { builder()->Jump(&case_sites_.at(index)); } 143 void DefaultAt(int index) { builder()->Jump(&case_sites_.at(index)); }
137 144
138 private: 145 private:
139 // Unbound labels that identify jumps for case statements in the code. 146 // Unbound labels that identify jumps for case statements in the code.
140 ZoneVector<BytecodeLabel> case_sites_; 147 ZoneVector<BytecodeLabel> case_sites_;
141 }; 148 };
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 193
187 // Unbound labels that identify jumps to the finally block in the code. 194 // Unbound labels that identify jumps to the finally block in the code.
188 BytecodeLabels finalization_sites_; 195 BytecodeLabels finalization_sites_;
189 }; 196 };
190 197
191 } // namespace interpreter 198 } // namespace interpreter
192 } // namespace internal 199 } // namespace internal
193 } // namespace v8 200 } // namespace v8
194 201
195 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ 202 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-peephole-table.h ('k') | src/interpreter/control-flow-builders.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698