Chromium Code Reviews

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

Issue 2894293003: Save/restore only live registers in the generator suspend/resume. (Closed)
Patch Set: Fix comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 2259 matching lines...)
2270 index = NewNode( 2270 index = NewNode(
2271 simplified()->SpeculativeNumberAdd(NumberOperationHint::kSignedSmall), 2271 simplified()->SpeculativeNumberAdd(NumberOperationHint::kSignedSmall),
2272 index, jsgraph()->OneConstant()); 2272 index, jsgraph()->OneConstant());
2273 environment()->BindAccumulator(index, Environment::kAttachFrameState); 2273 environment()->BindAccumulator(index, Environment::kAttachFrameState);
2274 } 2274 }
2275 2275
2276 void BytecodeGraphBuilder::VisitSuspendGenerator() { 2276 void BytecodeGraphBuilder::VisitSuspendGenerator() {
2277 Node* state = environment()->LookupAccumulator(); 2277 Node* state = environment()->LookupAccumulator();
2278 Node* generator = environment()->LookupRegister( 2278 Node* generator = environment()->LookupRegister(
2279 bytecode_iterator().GetRegisterOperand(0)); 2279 bytecode_iterator().GetRegisterOperand(0));
2280 interpreter::Register first_reg = bytecode_iterator().GetRegisterOperand(1);
2281 // We assume we are storing a range starting from index 0.
2282 CHECK_EQ(0, first_reg.index());
2283 int register_count =
2284 static_cast<int>(bytecode_iterator().GetRegisterCountOperand(2));
2280 SuspendFlags flags = interpreter::SuspendGeneratorBytecodeFlags::Decode( 2285 SuspendFlags flags = interpreter::SuspendGeneratorBytecodeFlags::Decode(
2281 bytecode_iterator().GetFlagOperand(1)); 2286 bytecode_iterator().GetFlagOperand(3));
2287
2282 // The offsets used by the bytecode iterator are relative to a different base 2288 // The offsets used by the bytecode iterator are relative to a different base
2283 // than what is used in the interpreter, hence the addition. 2289 // than what is used in the interpreter, hence the addition.
2284 Node* offset = 2290 Node* offset =
2285 jsgraph()->Constant(bytecode_iterator().current_offset() + 2291 jsgraph()->Constant(bytecode_iterator().current_offset() +
2286 (BytecodeArray::kHeaderSize - kHeapObjectTag)); 2292 (BytecodeArray::kHeaderSize - kHeapObjectTag));
2287 2293
2288 int register_count = environment()->register_count();
2289 int value_input_count = 3 + register_count; 2294 int value_input_count = 3 + register_count;
2290 2295
2291 Node** value_inputs = local_zone()->NewArray<Node*>(value_input_count); 2296 Node** value_inputs = local_zone()->NewArray<Node*>(value_input_count);
2292 value_inputs[0] = generator; 2297 value_inputs[0] = generator;
2293 value_inputs[1] = state; 2298 value_inputs[1] = state;
2294 value_inputs[2] = offset; 2299 value_inputs[2] = offset;
2295 for (int i = 0; i < register_count; ++i) { 2300 for (int i = 0; i < register_count; ++i) {
2296 value_inputs[3 + i] = 2301 value_inputs[3 + i] =
2297 environment()->LookupRegister(interpreter::Register(i)); 2302 environment()->LookupRegister(interpreter::Register(i));
2298 } 2303 }
2299 2304
2300 MakeNode(javascript()->GeneratorStore(register_count, flags), 2305 MakeNode(javascript()->GeneratorStore(register_count, flags),
2301 value_input_count, value_inputs, false); 2306 value_input_count, value_inputs, false);
2302 } 2307 }
2303 2308
2304 void BytecodeGraphBuilder::VisitResumeGenerator() { 2309 void BytecodeGraphBuilder::VisitResumeGenerator() {
2305 Node* generator = environment()->LookupRegister( 2310 Node* generator = environment()->LookupRegister(
2306 bytecode_iterator().GetRegisterOperand(0)); 2311 bytecode_iterator().GetRegisterOperand(0));
2307 2312
2313 Node* state =
2314 NewNode(javascript()->GeneratorRestoreContinuation(), generator);
2315
2316 environment()->BindAccumulator(state, Environment::kAttachFrameState);
2317 }
2318
2319 void BytecodeGraphBuilder::VisitRestoreGeneratorRegisters() {
2320 PrepareEagerCheckpoint();
2321
2322 Node* generator =
2323 environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
2324 interpreter::Register first_reg = bytecode_iterator().GetRegisterOperand(1);
2325 // We assume we are restoring registers starting fromm index 0.
2326 CHECK_EQ(0, first_reg.index());
2327 int register_count =
2328 static_cast<int>(bytecode_iterator().GetRegisterCountOperand(2));
2329
2308 // Bijection between registers and array indices must match that used in 2330 // Bijection between registers and array indices must match that used in
2309 // InterpreterAssembler::ExportRegisterFile. 2331 // InterpreterAssembler::ExportRegisterFile.
2310 for (int i = 0; i < environment()->register_count(); ++i) { 2332 for (int i = 0; i < register_count; ++i) {
2311 Node* value = NewNode(javascript()->GeneratorRestoreRegister(i), generator); 2333 Node* value = NewNode(javascript()->GeneratorRestoreRegister(i), generator);
2312 environment()->BindRegister(interpreter::Register(i), value); 2334 environment()->BindRegister(interpreter::Register(i), value);
2313 } 2335 }
2314 2336
2315 Node* state = 2337 Node* state =
2316 NewNode(javascript()->GeneratorRestoreContinuation(), generator); 2338 NewNode(javascript()->GeneratorRestoreContinuation(), generator);
2317 2339
2318 environment()->BindAccumulator(state); 2340 environment()->BindAccumulator(state);
2319 } 2341 }
2320 2342
(...skipping 510 matching lines...)
2831 it->source_position().ScriptOffset(), start_position_.InliningId())); 2853 it->source_position().ScriptOffset(), start_position_.InliningId()));
2832 it->Advance(); 2854 it->Advance();
2833 } else { 2855 } else {
2834 DCHECK_GT(it->code_offset(), offset); 2856 DCHECK_GT(it->code_offset(), offset);
2835 } 2857 }
2836 } 2858 }
2837 2859
2838 } // namespace compiler 2860 } // namespace compiler
2839 } // namespace internal 2861 } // namespace internal
2840 } // namespace v8 2862 } // namespace v8
OLDNEW

Powered by Google App Engine