OLD | NEW |
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_BYTECODE_GENERATOR_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
6 #define V8_INTERPRETER_BYTECODE_GENERATOR_H_ | 6 #define V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
10 #include "src/interpreter/bytecodes.h" | 10 #include "src/interpreter/bytecodes.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 private: | 29 private: |
30 class ContextScope; | 30 class ContextScope; |
31 class ControlScope; | 31 class ControlScope; |
32 class ControlScopeForBreakable; | 32 class ControlScopeForBreakable; |
33 class ControlScopeForIteration; | 33 class ControlScopeForIteration; |
34 class ExpressionResultScope; | 34 class ExpressionResultScope; |
35 class EffectResultScope; | 35 class EffectResultScope; |
36 class AccumulatorResultScope; | 36 class AccumulatorResultScope; |
37 class RegisterResultScope; | 37 class RegisterResultScope; |
38 class AssignmentHazardScope; | |
39 | |
40 // Helper class that aliases locals and parameters when assignment | |
41 // hazards occur in binary expressions. For y = x + (x = 1) has an | |
42 // assignment hazard because the lhs evaluates to the register | |
43 // holding x and the rhs (x = 1) potentially updates x. When this | |
44 // hazard is detected, the rhs uses a temporary to hold the newer | |
45 // value of x while preserving the lhs for the binary expresion | |
46 // evaluation. The newer value is spilled to x at the end of the | |
47 // binary expression evaluation. | |
48 class AssignmentHazardHelper final { | |
49 public: | |
50 explicit AssignmentHazardHelper(BytecodeGenerator* generator); | |
51 MUST_USE_RESULT Register GetRegisterForLoad(Register reg); | |
52 MUST_USE_RESULT Register GetRegisterForStore(Register reg); | |
53 | |
54 private: | |
55 friend class AssignmentHazardScope; | |
56 | |
57 void EnterScope(); | |
58 void LeaveScope(); | |
59 void RestoreAliasedLocalsAndParameters(); | |
60 | |
61 BytecodeGenerator* generator_; | |
62 ZoneMap<int, int> alias_mappings_; | |
63 ZoneSet<int> aliased_locals_and_parameters_; | |
64 ExpressionResultScope* execution_result_; | |
65 int scope_depth_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(AssignmentHazardHelper); | |
68 }; | |
69 | 38 |
70 void MakeBytecodeBody(); | 39 void MakeBytecodeBody(); |
71 Register NextContextRegister() const; | 40 Register NextContextRegister() const; |
72 | 41 |
73 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 42 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
74 | 43 |
75 // Dispatched from VisitBinaryOperation. | 44 // Dispatched from VisitBinaryOperation. |
76 void VisitArithmeticExpression(BinaryOperation* binop); | 45 void VisitArithmeticExpression(BinaryOperation* binop); |
77 void VisitCommaExpression(BinaryOperation* binop); | 46 void VisitCommaExpression(BinaryOperation* binop); |
78 void VisitLogicalOrExpression(BinaryOperation* binop); | 47 void VisitLogicalOrExpression(BinaryOperation* binop); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 execution_control_ = scope; | 111 execution_control_ = scope; |
143 } | 112 } |
144 inline ContextScope* execution_context() const { return execution_context_; } | 113 inline ContextScope* execution_context() const { return execution_context_; } |
145 inline void set_execution_context(ContextScope* context) { | 114 inline void set_execution_context(ContextScope* context) { |
146 execution_context_ = context; | 115 execution_context_ = context; |
147 } | 116 } |
148 inline void set_execution_result(ExpressionResultScope* execution_result) { | 117 inline void set_execution_result(ExpressionResultScope* execution_result) { |
149 execution_result_ = execution_result; | 118 execution_result_ = execution_result; |
150 } | 119 } |
151 ExpressionResultScope* execution_result() const { return execution_result_; } | 120 ExpressionResultScope* execution_result() const { return execution_result_; } |
152 inline AssignmentHazardHelper* assignment_hazard_helper() { | |
153 return &assignment_hazard_helper_; | |
154 } | |
155 | 121 |
156 ZoneVector<Handle<Object>>* globals() { return &globals_; } | 122 ZoneVector<Handle<Object>>* globals() { return &globals_; } |
157 inline LanguageMode language_mode() const; | 123 inline LanguageMode language_mode() const; |
158 Strength language_mode_strength() const; | 124 Strength language_mode_strength() const; |
159 int feedback_index(FeedbackVectorSlot slot) const; | 125 int feedback_index(FeedbackVectorSlot slot) const; |
160 | 126 |
161 Isolate* isolate_; | 127 Isolate* isolate_; |
162 Zone* zone_; | 128 Zone* zone_; |
163 BytecodeArrayBuilder builder_; | 129 BytecodeArrayBuilder builder_; |
164 CompilationInfo* info_; | 130 CompilationInfo* info_; |
165 Scope* scope_; | 131 Scope* scope_; |
166 ZoneVector<Handle<Object>> globals_; | 132 ZoneVector<Handle<Object>> globals_; |
167 ControlScope* execution_control_; | 133 ControlScope* execution_control_; |
168 ContextScope* execution_context_; | 134 ContextScope* execution_context_; |
169 ExpressionResultScope* execution_result_; | 135 ExpressionResultScope* execution_result_; |
170 AssignmentHazardHelper assignment_hazard_helper_; | |
171 }; | 136 }; |
172 | 137 |
173 } // namespace interpreter | 138 } // namespace interpreter |
174 } // namespace internal | 139 } // namespace internal |
175 } // namespace v8 | 140 } // namespace v8 |
176 | 141 |
177 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ | 142 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
OLD | NEW |