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

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

Issue 1502243002: [Interpreter] Local flow control in the bytecode graph builder. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix bug in jump classification. Created 5 years 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 #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/zone-containers.h" 10 #include "src/zone-containers.h"
(...skipping 26 matching lines...) Expand all
37 37
38 // This method should be called by the control flow owner before 38 // This method should be called by the control flow owner before
39 // destruction to update sites that emit jumps for break. 39 // destruction to update sites that emit jumps for break.
40 void SetBreakTarget(const BytecodeLabel& break_target); 40 void SetBreakTarget(const BytecodeLabel& break_target);
41 41
42 // This method is called when visiting break statements in the AST. 42 // This method is called when visiting break statements in the AST.
43 // Inserts a jump to a unbound label that is patched when the corresponding 43 // Inserts a jump to a unbound label that is patched when the corresponding
44 // SetBreakTarget is called. 44 // SetBreakTarget is called.
45 void Break() { EmitJump(&break_sites_); } 45 void Break() { EmitJump(&break_sites_); }
46 void BreakIfTrue() { EmitJumpIfTrue(&break_sites_); } 46 void BreakIfTrue() { EmitJumpIfTrue(&break_sites_); }
47 void BreakIfFalse() { EmitJumpIfFalse(&break_sites_); }
47 void BreakIfUndefined() { EmitJumpIfUndefined(&break_sites_); } 48 void BreakIfUndefined() { EmitJumpIfUndefined(&break_sites_); }
48 void BreakIfNull() { EmitJumpIfNull(&break_sites_); } 49 void BreakIfNull() { EmitJumpIfNull(&break_sites_); }
49 50
51
Michael Starzinger 2015/12/16 12:40:12 nit: Stray empty newline.
oth 2015/12/16 14:17:06 Done.
50 protected: 52 protected:
51 void EmitJump(ZoneVector<BytecodeLabel>* labels); 53 void EmitJump(ZoneVector<BytecodeLabel>* labels);
52 void EmitJump(ZoneVector<BytecodeLabel>* labels, int index); 54 void EmitJump(ZoneVector<BytecodeLabel>* labels, int index);
53 void EmitJumpIfTrue(ZoneVector<BytecodeLabel>* labels); 55 void EmitJumpIfTrue(ZoneVector<BytecodeLabel>* labels);
54 void EmitJumpIfTrue(ZoneVector<BytecodeLabel>* labels, int index); 56 void EmitJumpIfTrue(ZoneVector<BytecodeLabel>* labels, int index);
57 void EmitJumpIfFalse(ZoneVector<BytecodeLabel>* labels);
58 void EmitJumpIfFalse(ZoneVector<BytecodeLabel>* labels, int index);
55 void EmitJumpIfUndefined(ZoneVector<BytecodeLabel>* labels); 59 void EmitJumpIfUndefined(ZoneVector<BytecodeLabel>* labels);
56 void EmitJumpIfNull(ZoneVector<BytecodeLabel>* labels); 60 void EmitJumpIfNull(ZoneVector<BytecodeLabel>* labels);
57 61
58 void BindLabels(const BytecodeLabel& target, ZoneVector<BytecodeLabel>* site); 62 void BindLabels(const BytecodeLabel& target, ZoneVector<BytecodeLabel>* site);
59 63
60 private: 64 private:
61 // Unbound labels that identify jumps for break statements in the code. 65 // Unbound labels that identify jumps for break statements in the code.
62 ZoneVector<BytecodeLabel> break_sites_; 66 ZoneVector<BytecodeLabel> break_sites_;
63 }; 67 };
64 68
65 // A class to help with co-ordinating break and continue statements with 69 // A class to help with co-ordinating break and continue statements with
66 // their loop. 70 // their loop.
67 // TODO(oth): add support for TF branch/merge info.
68 class LoopBuilder final : public BreakableControlFlowBuilder { 71 class LoopBuilder final : public BreakableControlFlowBuilder {
69 public: 72 public:
70 explicit LoopBuilder(BytecodeArrayBuilder* builder) 73 explicit LoopBuilder(BytecodeArrayBuilder* builder)
71 : BreakableControlFlowBuilder(builder), 74 : BreakableControlFlowBuilder(builder),
72 continue_sites_(builder->zone()) {} 75 continue_sites_(builder->zone()) {}
73 ~LoopBuilder(); 76 ~LoopBuilder();
74 77
75 // This methods should be called by the LoopBuilder owner before 78 void LoopHeader() { builder()->Bind(&loop_header_); }
76 // destruction to update sites that emit jumps for continue. 79 void Condition() { builder()->Bind(&condition_); }
77 void SetContinueTarget(const BytecodeLabel& continue_target); 80 void Next() { builder()->Bind(&next_); }
81 void JumpToHeader() { builder()->Jump(&loop_header_); }
82 void JumpToHeaderIfTrue() { builder()->JumpIfTrue(&loop_header_); }
83 void LoopEnd();
78 84
79 // This method is called when visiting continue statements in the AST. 85 // This method is called when visiting continue statements in the AST.
80 // Inserts a jump to a unbound label that is patched when the corresponding 86 // Inserts a jump to a unbound label that is patched when the corresponding
81 // SetContinueTarget is called. 87 // SetContinueTarget is called.
82 void Continue() { EmitJump(&continue_sites_); } 88 void Continue() { EmitJump(&continue_sites_); }
83 void ContinueIfTrue() { EmitJumpIfTrue(&continue_sites_); } 89 void ContinueIfTrue() { EmitJumpIfTrue(&continue_sites_); }
84 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_sites_); } 90 void ContinueIfUndefined() { EmitJumpIfUndefined(&continue_sites_); }
85 void ContinueIfNull() { EmitJumpIfNull(&continue_sites_); } 91 void ContinueIfNull() { EmitJumpIfNull(&continue_sites_); }
86 92
87 private: 93 private:
94 void SetContinueTarget(const BytecodeLabel& continue_target);
95
96 BytecodeLabel loop_header_;
97 BytecodeLabel condition_;
98 BytecodeLabel next_;
99 BytecodeLabel loop_end_;
100
88 // Unbound labels that identify jumps for continue statements in the code. 101 // Unbound labels that identify jumps for continue statements in the code.
89 ZoneVector<BytecodeLabel> continue_sites_; 102 ZoneVector<BytecodeLabel> continue_sites_;
90 }; 103 };
91 104
92 // A class to help with co-ordinating break statements with their switch. 105 // A class to help with co-ordinating break statements with their switch.
93 // TODO(oth): add support for TF branch/merge info. 106 // TODO(oth): add support for TF branch/merge info.
94 class SwitchBuilder final : public BreakableControlFlowBuilder { 107 class SwitchBuilder final : public BreakableControlFlowBuilder {
95 public: 108 public:
96 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases) 109 explicit SwitchBuilder(BytecodeArrayBuilder* builder, int number_of_cases)
97 : BreakableControlFlowBuilder(builder), 110 : BreakableControlFlowBuilder(builder),
(...skipping 19 matching lines...) Expand all
117 private: 130 private:
118 // Unbound labels that identify jumps for case statements in the code. 131 // Unbound labels that identify jumps for case statements in the code.
119 ZoneVector<BytecodeLabel> case_sites_; 132 ZoneVector<BytecodeLabel> case_sites_;
120 }; 133 };
121 134
122 } // namespace interpreter 135 } // namespace interpreter
123 } // namespace internal 136 } // namespace internal
124 } // namespace v8 137 } // namespace v8
125 138
126 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_ 139 #endif // V8_INTERPRETER_CONTROL_FLOW_BUILDERS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698