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

Side by Side Diff: src/interpreter/bytecode-generator.h

Issue 1412683011: [Interpreter] Enable assignments in expressions. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Sync test bytecode sequences to avoid unnecessary Ldar/Star instructions. Created 5 years, 1 month 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-array-builder.cc ('k') | src/interpreter/bytecode-generator.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_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 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 };
39 69
40 void MakeBytecodeBody(); 70 void MakeBytecodeBody();
41 Register NextContextRegister() const; 71 Register NextContextRegister() const;
42 72
43 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS(); 73 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
44 74
45 // Dispatched from VisitBinaryOperation. 75 // Dispatched from VisitBinaryOperation.
46 void VisitArithmeticExpression(BinaryOperation* binop); 76 void VisitArithmeticExpression(BinaryOperation* binop);
47 void VisitCommaExpression(BinaryOperation* binop); 77 void VisitCommaExpression(BinaryOperation* binop);
48 void VisitLogicalOrExpression(BinaryOperation* binop); 78 void VisitLogicalOrExpression(BinaryOperation* binop);
49 void VisitLogicalAndExpression(BinaryOperation* binop); 79 void VisitLogicalAndExpression(BinaryOperation* binop);
50 80
51 // Dispatched from VisitUnaryOperation. 81 // Dispatched from VisitUnaryOperation.
52 void VisitVoid(UnaryOperation* expr); 82 void VisitVoid(UnaryOperation* expr);
53 void VisitTypeOf(UnaryOperation* expr); 83 void VisitTypeOf(UnaryOperation* expr);
54 void VisitNot(UnaryOperation* expr); 84 void VisitNot(UnaryOperation* expr);
55 void VisitDelete(UnaryOperation* expr); 85 void VisitDelete(UnaryOperation* expr);
56 86
87 // Used by flow control routines to evaluate loop condition.
88 void VisitCondition(Expression* expr);
89
57 // Helper visitors which perform common operations. 90 // Helper visitors which perform common operations.
58 Register VisitArguments(ZoneList<Expression*>* arguments); 91 Register VisitArguments(ZoneList<Expression*>* arguments);
59 92
60 void VisitPropertyLoad(Register obj, Property* expr); 93 void VisitPropertyLoad(Register obj, Property* expr);
61 void VisitPropertyLoadForAccumulator(Register obj, Property* expr); 94 void VisitPropertyLoadForAccumulator(Register obj, Property* expr);
62 95
63 void VisitVariableLoad(Variable* variable, FeedbackVectorSlot slot, 96 void VisitVariableLoad(Variable* variable, FeedbackVectorSlot slot,
64 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF); 97 TypeofMode typeof_mode = NOT_INSIDE_TYPEOF);
65 void VisitVariableLoadForAccumulatorValue( 98 void VisitVariableLoadForAccumulatorValue(
66 Variable* variable, FeedbackVectorSlot slot, 99 Variable* variable, FeedbackVectorSlot slot,
(...skipping 10 matching lines...) Expand all
77 void VisitBuildLocalActivationContext(); 110 void VisitBuildLocalActivationContext();
78 void VisitNewLocalBlockContext(Scope* scope); 111 void VisitNewLocalBlockContext(Scope* scope);
79 void VisitFunctionClosureForContext(); 112 void VisitFunctionClosureForContext();
80 void VisitSetHomeObject(Register value, Register home_object, 113 void VisitSetHomeObject(Register value, Register home_object,
81 ObjectLiteralProperty* property, int slot_number = 0); 114 ObjectLiteralProperty* property, int slot_number = 0);
82 void VisitObjectLiteralAccessor(Register home_object, 115 void VisitObjectLiteralAccessor(Register home_object,
83 ObjectLiteralProperty* property, 116 ObjectLiteralProperty* property,
84 Register value_out); 117 Register value_out);
85 void VisitForInAssignment(Expression* expr, FeedbackVectorSlot slot); 118 void VisitForInAssignment(Expression* expr, FeedbackVectorSlot slot);
86 119
87
88 // Visitors for obtaining expression result in the accumulator, in a 120 // Visitors for obtaining expression result in the accumulator, in a
89 // register, or just getting the effect. 121 // register, or just getting the effect.
90 void VisitForAccumulatorValue(Expression* expression); 122 void VisitForAccumulatorValue(Expression* expression);
91 MUST_USE_RESULT Register VisitForRegisterValue(Expression* expression); 123 MUST_USE_RESULT Register VisitForRegisterValue(Expression* expression);
92 void VisitForEffect(Expression* node); 124 void VisitForEffect(Expression* node);
93 125
94 // Methods marking the start and end of binary expressions.
95 void PrepareForBinaryExpression();
96 void CompleteBinaryExpression();
97
98 // Methods for tracking and remapping register. 126 // Methods for tracking and remapping register.
99 void RecordStoreToRegister(Register reg); 127 void RecordStoreToRegister(Register reg);
100 Register LoadFromAliasedRegister(Register reg); 128 Register LoadFromAliasedRegister(Register reg);
101 129
102 inline BytecodeArrayBuilder* builder() { return &builder_; } 130 inline BytecodeArrayBuilder* builder() { return &builder_; }
103 131
104 inline Isolate* isolate() const { return isolate_; } 132 inline Isolate* isolate() const { return isolate_; }
105 inline Zone* zone() const { return zone_; } 133 inline Zone* zone() const { return zone_; }
106 134
107 inline Scope* scope() const { return scope_; } 135 inline Scope* scope() const { return scope_; }
108 inline void set_scope(Scope* scope) { scope_ = scope; } 136 inline void set_scope(Scope* scope) { scope_ = scope; }
109 inline CompilationInfo* info() const { return info_; } 137 inline CompilationInfo* info() const { return info_; }
110 inline void set_info(CompilationInfo* info) { info_ = info; } 138 inline void set_info(CompilationInfo* info) { info_ = info; }
111 139
112 inline ControlScope* execution_control() const { return execution_control_; } 140 inline ControlScope* execution_control() const { return execution_control_; }
113 inline void set_execution_control(ControlScope* scope) { 141 inline void set_execution_control(ControlScope* scope) {
114 execution_control_ = scope; 142 execution_control_ = scope;
115 } 143 }
116 inline ContextScope* execution_context() const { return execution_context_; } 144 inline ContextScope* execution_context() const { return execution_context_; }
117 inline void set_execution_context(ContextScope* context) { 145 inline void set_execution_context(ContextScope* context) {
118 execution_context_ = context; 146 execution_context_ = context;
119 } 147 }
120 inline void set_execution_result(ExpressionResultScope* execution_result) { 148 inline void set_execution_result(ExpressionResultScope* execution_result) {
121 execution_result_ = execution_result; 149 execution_result_ = execution_result;
122 } 150 }
123 ExpressionResultScope* execution_result() const { return execution_result_; } 151 ExpressionResultScope* execution_result() const { return execution_result_; }
152 inline AssignmentHazardHelper* assignment_hazard_helper() {
153 return &assignment_hazard_helper_;
154 }
124 155
125 ZoneVector<Handle<Object>>* globals() { return &globals_; } 156 ZoneVector<Handle<Object>>* globals() { return &globals_; }
126 inline LanguageMode language_mode() const; 157 inline LanguageMode language_mode() const;
127 Strength language_mode_strength() const; 158 Strength language_mode_strength() const;
128 int feedback_index(FeedbackVectorSlot slot) const; 159 int feedback_index(FeedbackVectorSlot slot) const;
129 160
130 Isolate* isolate_; 161 Isolate* isolate_;
131 Zone* zone_; 162 Zone* zone_;
132 BytecodeArrayBuilder builder_; 163 BytecodeArrayBuilder builder_;
133 CompilationInfo* info_; 164 CompilationInfo* info_;
134 Scope* scope_; 165 Scope* scope_;
135 ZoneVector<Handle<Object>> globals_; 166 ZoneVector<Handle<Object>> globals_;
136 ControlScope* execution_control_; 167 ControlScope* execution_control_;
137 ContextScope* execution_context_; 168 ContextScope* execution_context_;
138 ExpressionResultScope* execution_result_; 169 ExpressionResultScope* execution_result_;
139 170 AssignmentHazardHelper assignment_hazard_helper_;
140 int binary_expression_depth_;
141 ZoneSet<int> binary_expression_hazard_set_;
142 }; 171 };
143 172
144 } // namespace interpreter 173 } // namespace interpreter
145 } // namespace internal 174 } // namespace internal
146 } // namespace v8 175 } // namespace v8
147 176
148 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_ 177 #endif // V8_INTERPRETER_BYTECODE_GENERATOR_H_
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | src/interpreter/bytecode-generator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698