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

Side by Side Diff: src/compiler/bytecode-graph-builder.cc

Issue 2826223004: [turbofan] Graph builder: reuse the one-element cache for parameters state values. (Closed)
Patch Set: 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 | « no previous file | no next file » | 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 #include "src/compiler/bytecode-graph-builder.h" 5 #include "src/compiler/bytecode-graph-builder.h"
6 6
7 #include "src/ast/ast.h" 7 #include "src/ast/ast.h"
8 #include "src/ast/scopes.h" 8 #include "src/ast/scopes.h"
9 #include "src/compiler/access-builder.h" 9 #include "src/compiler/access-builder.h"
10 #include "src/compiler/compiler-source-position-table.h" 10 #include "src/compiler/compiler-source-position-table.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 void PrepareForOsrEntry(); 75 void PrepareForOsrEntry();
76 void PrepareForLoop(const BytecodeLoopAssignments& assignments); 76 void PrepareForLoop(const BytecodeLoopAssignments& assignments);
77 void PrepareForLoopExit(Node* loop, 77 void PrepareForLoopExit(Node* loop,
78 const BytecodeLoopAssignments& assignments); 78 const BytecodeLoopAssignments& assignments);
79 79
80 private: 80 private:
81 explicit Environment(const Environment* copy); 81 explicit Environment(const Environment* copy);
82 82
83 bool StateValuesRequireUpdate(Node** state_values, Node** values, int count); 83 bool StateValuesRequireUpdate(Node** state_values, Node** values, int count);
84 void UpdateStateValues(Node** state_values, Node** values, int count); 84 void UpdateStateValues(Node** state_values, Node** values, int count);
85 void UpdateStateValuesWithCache(Node** state_values, Node** values, int count, 85 Node* GetStateValuesFromCache(Node** values, int count,
86 const BitVector* liveness, 86 const BitVector* liveness, int liveness_offset);
87 int liveness_offset);
88 87
89 int RegisterToValuesIndex(interpreter::Register the_register) const; 88 int RegisterToValuesIndex(interpreter::Register the_register) const;
90 89
91 Zone* zone() const { return builder_->local_zone(); } 90 Zone* zone() const { return builder_->local_zone(); }
92 Graph* graph() const { return builder_->graph(); } 91 Graph* graph() const { return builder_->graph(); }
93 CommonOperatorBuilder* common() const { return builder_->common(); } 92 CommonOperatorBuilder* common() const { return builder_->common(); }
94 BytecodeGraphBuilder* builder() const { return builder_; } 93 BytecodeGraphBuilder* builder() const { return builder_; }
95 const NodeVector* values() const { return &values_; } 94 const NodeVector* values() const { return &values_; }
96 NodeVector* values() { return &values_; } 95 NodeVector* values() { return &values_; }
97 int register_base() const { return register_base_; } 96 int register_base() const { return register_base_; }
98 int accumulator_base() const { return accumulator_base_; } 97 int accumulator_base() const { return accumulator_base_; }
99 98
100 BytecodeGraphBuilder* builder_; 99 BytecodeGraphBuilder* builder_;
101 int register_count_; 100 int register_count_;
102 int parameter_count_; 101 int parameter_count_;
103 Node* context_; 102 Node* context_;
104 Node* control_dependency_; 103 Node* control_dependency_;
105 Node* effect_dependency_; 104 Node* effect_dependency_;
106 NodeVector values_; 105 NodeVector values_;
107 Node* parameters_state_values_; 106 Node* parameters_state_values_;
108 Node* registers_state_values_;
109 Node* accumulator_state_values_;
110 int register_base_; 107 int register_base_;
111 int accumulator_base_; 108 int accumulator_base_;
112 }; 109 };
113 110
114 111
115 // Issues: 112 // Issues:
116 // - Scopes - intimately tied to AST. Need to eval what is needed. 113 // - Scopes - intimately tied to AST. Need to eval what is needed.
117 // - Need to resolve closure parameter treatment. 114 // - Need to resolve closure parameter treatment.
118 BytecodeGraphBuilder::Environment::Environment(BytecodeGraphBuilder* builder, 115 BytecodeGraphBuilder::Environment::Environment(BytecodeGraphBuilder* builder,
119 int register_count, 116 int register_count,
120 int parameter_count, 117 int parameter_count,
121 Node* control_dependency, 118 Node* control_dependency,
122 Node* context) 119 Node* context)
123 : builder_(builder), 120 : builder_(builder),
124 register_count_(register_count), 121 register_count_(register_count),
125 parameter_count_(parameter_count), 122 parameter_count_(parameter_count),
126 context_(context), 123 context_(context),
127 control_dependency_(control_dependency), 124 control_dependency_(control_dependency),
128 effect_dependency_(control_dependency), 125 effect_dependency_(control_dependency),
129 values_(builder->local_zone()), 126 values_(builder->local_zone()),
130 parameters_state_values_(nullptr), 127 parameters_state_values_(nullptr) {
131 registers_state_values_(nullptr),
132 accumulator_state_values_(nullptr) {
133 // The layout of values_ is: 128 // The layout of values_ is:
134 // 129 //
135 // [receiver] [parameters] [registers] [accumulator] 130 // [receiver] [parameters] [registers] [accumulator]
136 // 131 //
137 // parameter[0] is the receiver (this), parameters 1..N are the 132 // parameter[0] is the receiver (this), parameters 1..N are the
138 // parameters supplied to the method (arg0..argN-1). The accumulator 133 // parameters supplied to the method (arg0..argN-1). The accumulator
139 // is stored separately. 134 // is stored separately.
140 135
141 // Parameters including the receiver 136 // Parameters including the receiver
142 for (int i = 0; i < parameter_count; i++) { 137 for (int i = 0; i < parameter_count; i++) {
(...skipping 15 matching lines...) Expand all
158 153
159 BytecodeGraphBuilder::Environment::Environment( 154 BytecodeGraphBuilder::Environment::Environment(
160 const BytecodeGraphBuilder::Environment* other) 155 const BytecodeGraphBuilder::Environment* other)
161 : builder_(other->builder_), 156 : builder_(other->builder_),
162 register_count_(other->register_count_), 157 register_count_(other->register_count_),
163 parameter_count_(other->parameter_count_), 158 parameter_count_(other->parameter_count_),
164 context_(other->context_), 159 context_(other->context_),
165 control_dependency_(other->control_dependency_), 160 control_dependency_(other->control_dependency_),
166 effect_dependency_(other->effect_dependency_), 161 effect_dependency_(other->effect_dependency_),
167 values_(other->zone()), 162 values_(other->zone()),
168 parameters_state_values_(nullptr), 163 parameters_state_values_(other->parameters_state_values_),
Jarin 2017/04/20 11:54:48 This line is the real fix, the rest is drive-by :-
169 registers_state_values_(nullptr),
170 accumulator_state_values_(nullptr),
171 register_base_(other->register_base_), 164 register_base_(other->register_base_),
172 accumulator_base_(other->accumulator_base_) { 165 accumulator_base_(other->accumulator_base_) {
173 values_ = other->values_; 166 values_ = other->values_;
174 } 167 }
175 168
176 169
177 int BytecodeGraphBuilder::Environment::RegisterToValuesIndex( 170 int BytecodeGraphBuilder::Environment::RegisterToValuesIndex(
178 interpreter::Register the_register) const { 171 interpreter::Register the_register) const {
179 if (the_register.is_parameter()) { 172 if (the_register.is_parameter()) {
180 return the_register.ToParameterIndex(parameter_count()); 173 return the_register.ToParameterIndex(parameter_count());
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 397
405 void BytecodeGraphBuilder::Environment::UpdateStateValues(Node** state_values, 398 void BytecodeGraphBuilder::Environment::UpdateStateValues(Node** state_values,
406 Node** values, 399 Node** values,
407 int count) { 400 int count) {
408 if (StateValuesRequireUpdate(state_values, values, count)) { 401 if (StateValuesRequireUpdate(state_values, values, count)) {
409 const Operator* op = common()->StateValues(count, SparseInputMask::Dense()); 402 const Operator* op = common()->StateValues(count, SparseInputMask::Dense());
410 (*state_values) = graph()->NewNode(op, count, values); 403 (*state_values) = graph()->NewNode(op, count, values);
411 } 404 }
412 } 405 }
413 406
414 void BytecodeGraphBuilder::Environment::UpdateStateValuesWithCache( 407 Node* BytecodeGraphBuilder::Environment::GetStateValuesFromCache(
415 Node** state_values, Node** values, int count, const BitVector* liveness, 408 Node** values, int count, const BitVector* liveness, int liveness_offset) {
416 int liveness_offset) { 409 return builder_->state_values_cache_.GetNodeForValues(
417 *state_values = builder_->state_values_cache_.GetNodeForValues(
418 values, static_cast<size_t>(count), liveness, liveness_offset); 410 values, static_cast<size_t>(count), liveness, liveness_offset);
419 } 411 }
420 412
421 Node* BytecodeGraphBuilder::Environment::Checkpoint( 413 Node* BytecodeGraphBuilder::Environment::Checkpoint(
422 BailoutId bailout_id, OutputFrameStateCombine combine, 414 BailoutId bailout_id, OutputFrameStateCombine combine,
423 bool owner_has_exception, const BytecodeLivenessState* liveness) { 415 bool owner_has_exception, const BytecodeLivenessState* liveness) {
424 if (parameter_count() == register_count()) { 416 if (parameter_count() == register_count()) {
425 // Re-use the state-value cache if the number of local registers happens 417 // Re-use the state-value cache if the number of local registers happens
426 // to match the parameter count. 418 // to match the parameter count.
427 UpdateStateValuesWithCache(&parameters_state_values_, &values()->at(0), 419 parameters_state_values_ = GetStateValuesFromCache(
428 parameter_count(), nullptr, 0); 420 &values()->at(0), parameter_count(), nullptr, 0);
429 } else { 421 } else {
430 UpdateStateValues(&parameters_state_values_, &values()->at(0), 422 UpdateStateValues(&parameters_state_values_, &values()->at(0),
431 parameter_count()); 423 parameter_count());
432 } 424 }
433 425
434 UpdateStateValuesWithCache(&registers_state_values_, 426 Node* registers_state_values =
435 &values()->at(register_base()), register_count(), 427 GetStateValuesFromCache(&values()->at(register_base()), register_count(),
436 liveness ? &liveness->bit_vector() : nullptr, 0); 428 liveness ? &liveness->bit_vector() : nullptr, 0);
437 429
438 bool accumulator_is_live = !liveness || liveness->AccumulatorIsLive(); 430 bool accumulator_is_live = !liveness || liveness->AccumulatorIsLive();
431 Node* accumulator_state_values;
439 if (parameter_count() == 1 && accumulator_is_live && 432 if (parameter_count() == 1 && accumulator_is_live &&
440 values()->at(accumulator_base()) == values()->at(0)) { 433 values()->at(accumulator_base()) == values()->at(0)) {
441 // Re-use the parameter state values if there happens to only be one 434 // Re-use the parameter state values if there happens to only be one
442 // parameter and the accumulator is live and holds that parameter's value. 435 // parameter and the accumulator is live and holds that parameter's value.
443 accumulator_state_values_ = parameters_state_values_; 436 accumulator_state_values = parameters_state_values_;
444 } else { 437 } else {
445 // Otherwise, use the state values cache to hopefully re-use local register 438 // Otherwise, use the state values cache to hopefully re-use local register
446 // state values (if there is only one local register), or at the very least 439 // state values (if there is only one local register), or at the very least
447 // re-use previous accumulator state values. 440 // re-use previous accumulator state values.
448 UpdateStateValuesWithCache( 441 accumulator_state_values = GetStateValuesFromCache(
449 &accumulator_state_values_, &values()->at(accumulator_base()), 1, 442 &values()->at(accumulator_base()), 1,
450 liveness ? &liveness->bit_vector() : nullptr, register_count()); 443 liveness ? &liveness->bit_vector() : nullptr, register_count());
451 } 444 }
452 445
453 const Operator* op = common()->FrameState( 446 const Operator* op = common()->FrameState(
454 bailout_id, combine, builder()->frame_state_function_info()); 447 bailout_id, combine, builder()->frame_state_function_info());
455 Node* result = graph()->NewNode( 448 Node* result = graph()->NewNode(
456 op, parameters_state_values_, registers_state_values_, 449 op, parameters_state_values_, registers_state_values,
457 accumulator_state_values_, Context(), builder()->GetFunctionClosure(), 450 accumulator_state_values, Context(), builder()->GetFunctionClosure(),
458 builder()->graph()->start()); 451 builder()->graph()->start());
459 452
460 return result; 453 return result;
461 } 454 }
462 455
463 BytecodeGraphBuilder::BytecodeGraphBuilder( 456 BytecodeGraphBuilder::BytecodeGraphBuilder(
464 Zone* local_zone, Handle<SharedFunctionInfo> shared_info, 457 Zone* local_zone, Handle<SharedFunctionInfo> shared_info,
465 Handle<FeedbackVector> feedback_vector, BailoutId osr_ast_id, 458 Handle<FeedbackVector> feedback_vector, BailoutId osr_ast_id,
466 JSGraph* jsgraph, float invocation_frequency, 459 JSGraph* jsgraph, float invocation_frequency,
467 SourcePositionTable* source_positions, int inlining_id, 460 SourcePositionTable* source_positions, int inlining_id,
(...skipping 2364 matching lines...) Expand 10 before | Expand all | Expand 10 after
2832 it->source_position().ScriptOffset(), start_position_.InliningId())); 2825 it->source_position().ScriptOffset(), start_position_.InliningId()));
2833 it->Advance(); 2826 it->Advance();
2834 } else { 2827 } else {
2835 DCHECK_GT(it->code_offset(), offset); 2828 DCHECK_GT(it->code_offset(), offset);
2836 } 2829 }
2837 } 2830 }
2838 2831
2839 } // namespace compiler 2832 } // namespace compiler
2840 } // namespace internal 2833 } // namespace internal
2841 } // namespace v8 2834 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698