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.h" | 8 #include "src/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" |
11 | 11 |
12 namespace v8 { | 12 namespace v8 { |
13 namespace internal { | 13 namespace internal { |
14 namespace interpreter { | 14 namespace interpreter { |
15 | 15 |
16 class BytecodeGenerator : public AstVisitor { | 16 class BytecodeGenerator final : public AstVisitor { |
17 public: | 17 public: |
18 BytecodeGenerator(Isolate* isolate, Zone* zone); | 18 BytecodeGenerator(Isolate* isolate, Zone* zone); |
19 virtual ~BytecodeGenerator(); | |
20 | 19 |
21 Handle<BytecodeArray> MakeBytecode(CompilationInfo* info); | 20 Handle<BytecodeArray> MakeBytecode(CompilationInfo* info); |
22 | 21 |
23 #define DECLARE_VISIT(type) void Visit##type(type* node) override; | 22 #define DECLARE_VISIT(type) void Visit##type(type* node) override; |
24 AST_NODE_LIST(DECLARE_VISIT) | 23 AST_NODE_LIST(DECLARE_VISIT) |
25 #undef DECLARE_VISIT | 24 #undef DECLARE_VISIT |
26 | 25 |
27 // Visiting function for declarations list is overridden. | 26 // Visiting function for declarations list is overridden. |
28 void VisitDeclarations(ZoneList<Declaration*>* declarations) override; | 27 void VisitDeclarations(ZoneList<Declaration*>* declarations) override; |
29 | 28 |
30 private: | 29 private: |
31 class ContextScope; | 30 class ContextScope; |
32 class ControlScope; | 31 class ControlScope; |
33 class ControlScopeForIteration; | 32 class ControlScopeForIteration; |
34 class ControlScopeForSwitch; | 33 class ControlScopeForSwitch; |
35 class ExpressionResultScope; | 34 class ExpressionResultScope; |
36 class EffectResultScope; | 35 class EffectResultScope; |
37 class AccumulatorResultScope; | 36 class AccumulatorResultScope; |
38 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 void EnterScope(); | |
52 void LeaveScope(); | |
rmcilroy
2015/11/12 12:49:15
nit - move Enter / Leave to private and make Assig
oth
2015/11/13 12:43:30
Done.
| |
53 MUST_USE_RESULT Register GetRegisterForLoad(Register reg); | |
54 MUST_USE_RESULT Register GetRegisterForStore(Register reg); | |
55 | |
56 private: | |
57 void RestoreAliasedLocalsAndParameters(); | |
58 | |
59 BytecodeGenerator* generator_; | |
60 ZoneMap<int, int> alias_mappings_; | |
61 ZoneSet<int> aliased_locals_and_parameters_; | |
62 ExpressionResultScope* execution_result_; | |
63 int scope_depth_; | |
64 | |
65 DISALLOW_COPY_AND_ASSIGN(AssignmentHazardHelper); | |
66 }; | |
39 | 67 |
40 void MakeBytecodeBody(); | 68 void MakeBytecodeBody(); |
41 Register NextContextRegister() const; | 69 Register NextContextRegister() const; |
42 | 70 |
43 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); | 71 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); |
44 | 72 |
45 // Dispatched from VisitBinaryOperation. | 73 // Dispatched from VisitBinaryOperation. |
46 void VisitArithmeticExpression(BinaryOperation* binop); | 74 void VisitArithmeticExpression(BinaryOperation* binop); |
47 void VisitCommaExpression(BinaryOperation* binop); | 75 void VisitCommaExpression(BinaryOperation* binop); |
48 void VisitLogicalOrExpression(BinaryOperation* binop); | 76 void VisitLogicalOrExpression(BinaryOperation* binop); |
49 void VisitLogicalAndExpression(BinaryOperation* binop); | 77 void VisitLogicalAndExpression(BinaryOperation* binop); |
50 | 78 |
51 // Dispatched from VisitUnaryOperation. | 79 // Dispatched from VisitUnaryOperation. |
52 void VisitVoid(UnaryOperation* expr); | 80 void VisitVoid(UnaryOperation* expr); |
53 void VisitTypeOf(UnaryOperation* expr); | 81 void VisitTypeOf(UnaryOperation* expr); |
54 void VisitNot(UnaryOperation* expr); | 82 void VisitNot(UnaryOperation* expr); |
55 void VisitDelete(UnaryOperation* expr); | 83 void VisitDelete(UnaryOperation* expr); |
56 | 84 |
85 // Used by flow control routines to evaluate loop condition. | |
86 void VisitCondition(Expression* expr); | |
87 | |
57 // Helper visitors which perform common operations. | 88 // Helper visitors which perform common operations. |
58 Register VisitArguments(ZoneList<Expression*>* arguments); | 89 Register VisitArguments(ZoneList<Expression*>* arguments); |
59 | 90 |
60 void VisitPropertyLoad(Register obj, Property* expr); | 91 void VisitPropertyLoad(Register obj, Property* expr); |
61 void VisitPropertyLoadForAccumulator(Register obj, Property* expr); | 92 void VisitPropertyLoadForAccumulator(Register obj, Property* expr); |
62 | 93 |
63 void VisitVariableLoad(Variable* variable, FeedbackVectorSlot slot, | 94 void VisitVariableLoad(Variable* variable, FeedbackVectorSlot slot, |
64 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); | 95 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); |
65 void VisitVariableLoadForAccumulatorValue( | 96 void VisitVariableLoadForAccumulatorValue( |
66 Variable* variable, FeedbackVectorSlot slot, | 97 Variable* variable, FeedbackVectorSlot slot, |
(...skipping 10 matching lines...) Expand all Loading... | |
77 void VisitBuildLocalActivationContext(); | 108 void VisitBuildLocalActivationContext(); |
78 void VisitNewLocalBlockContext(Scope* scope); | 109 void VisitNewLocalBlockContext(Scope* scope); |
79 void VisitFunctionClosureForContext(); | 110 void VisitFunctionClosureForContext(); |
80 void VisitSetHomeObject(Register value, Register home_object, | 111 void VisitSetHomeObject(Register value, Register home_object, |
81 ObjectLiteralProperty* property, int slot_number = 0); | 112 ObjectLiteralProperty* property, int slot_number = 0); |
82 void VisitObjectLiteralAccessor(Register home_object, | 113 void VisitObjectLiteralAccessor(Register home_object, |
83 ObjectLiteralProperty* property, | 114 ObjectLiteralProperty* property, |
84 Register value_out); | 115 Register value_out); |
85 void VisitForInAssignment(Expression* expr, FeedbackVectorSlot slot); | 116 void VisitForInAssignment(Expression* expr, FeedbackVectorSlot slot); |
86 | 117 |
87 | |
88 // Visitors for obtaining expression result in the accumulator, in a | 118 // Visitors for obtaining expression result in the accumulator, in a |
89 // register, or just getting the effect. | 119 // register, or just getting the effect. |
90 void VisitForAccumulatorValue(Expression* expression); | 120 void VisitForAccumulatorValue(Expression* expression); |
91 MUST_USE_RESULT Register VisitForRegisterValue(Expression* expression); | 121 MUST_USE_RESULT Register VisitForRegisterValue(Expression* expression); |
92 void VisitForEffect(Expression* node); | 122 void VisitForEffect(Expression* node); |
93 | 123 |
94 // Methods marking the start and end of binary expressions. | |
95 void PrepareForBinaryExpression(); | |
96 void CompleteBinaryExpression(); | |
97 | |
98 // Methods for tracking and remapping register. | 124 // Methods for tracking and remapping register. |
99 void RecordStoreToRegister(Register reg); | 125 void RecordStoreToRegister(Register reg); |
100 Register LoadFromAliasedRegister(Register reg); | 126 Register LoadFromAliasedRegister(Register reg); |
101 | 127 |
102 inline BytecodeArrayBuilder* builder() { return &builder_; } | 128 inline BytecodeArrayBuilder* builder() { return &builder_; } |
103 | 129 |
104 inline Isolate* isolate() const { return isolate_; } | 130 inline Isolate* isolate() const { return isolate_; } |
105 inline Zone* zone() const { return zone_; } | 131 inline Zone* zone() const { return zone_; } |
106 | 132 |
107 inline Scope* scope() const { return scope_; } | 133 inline Scope* scope() const { return scope_; } |
108 inline void set_scope(Scope* scope) { scope_ = scope; } | 134 inline void set_scope(Scope* scope) { scope_ = scope; } |
109 inline CompilationInfo* info() const { return info_; } | 135 inline CompilationInfo* info() const { return info_; } |
110 inline void set_info(CompilationInfo* info) { info_ = info; } | 136 inline void set_info(CompilationInfo* info) { info_ = info; } |
111 | 137 |
112 inline ControlScope* execution_control() const { return execution_control_; } | 138 inline ControlScope* execution_control() const { return execution_control_; } |
113 inline void set_execution_control(ControlScope* scope) { | 139 inline void set_execution_control(ControlScope* scope) { |
114 execution_control_ = scope; | 140 execution_control_ = scope; |
115 } | 141 } |
116 inline ContextScope* execution_context() const { return execution_context_; } | 142 inline ContextScope* execution_context() const { return execution_context_; } |
117 inline void set_execution_context(ContextScope* context) { | 143 inline void set_execution_context(ContextScope* context) { |
118 execution_context_ = context; | 144 execution_context_ = context; |
119 } | 145 } |
120 inline void set_execution_result(ExpressionResultScope* execution_result) { | 146 inline void set_execution_result(ExpressionResultScope* execution_result) { |
121 execution_result_ = execution_result; | 147 execution_result_ = execution_result; |
122 } | 148 } |
123 ExpressionResultScope* execution_result() const { return execution_result_; } | 149 ExpressionResultScope* execution_result() const { return execution_result_; } |
150 inline AssignmentHazardHelper* assignment_hazard_helper() { | |
151 return &assignment_hazard_helper_; | |
152 } | |
124 | 153 |
125 ZoneVector<Handle<Object>>* globals() { return &globals_; } | 154 ZoneVector<Handle<Object>>* globals() { return &globals_; } |
126 inline LanguageMode language_mode() const; | 155 inline LanguageMode language_mode() const; |
127 Strength language_mode_strength() const; | 156 Strength language_mode_strength() const; |
128 int feedback_index(FeedbackVectorSlot slot) const; | 157 int feedback_index(FeedbackVectorSlot slot) const; |
129 | 158 |
130 Isolate* isolate_; | 159 Isolate* isolate_; |
131 Zone* zone_; | 160 Zone* zone_; |
132 BytecodeArrayBuilder builder_; | 161 BytecodeArrayBuilder builder_; |
133 CompilationInfo* info_; | 162 CompilationInfo* info_; |
134 Scope* scope_; | 163 Scope* scope_; |
135 ZoneVector<Handle<Object>> globals_; | 164 ZoneVector<Handle<Object>> globals_; |
136 ControlScope* execution_control_; | 165 ControlScope* execution_control_; |
137 ContextScope* execution_context_; | 166 ContextScope* execution_context_; |
138 ExpressionResultScope* execution_result_; | 167 ExpressionResultScope* execution_result_; |
139 | 168 AssignmentHazardHelper assignment_hazard_helper_; |
140 int binary_expression_depth_; | |
141 ZoneSet<int> binary_expression_hazard_set_; | |
142 }; | 169 }; |
143 | 170 |
144 } // namespace interpreter | 171 } // namespace interpreter |
145 } // namespace internal | 172 } // namespace internal |
146 } // namespace v8 | 173 } // namespace v8 |
147 | 174 |
148 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ | 175 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ |
OLD | NEW |