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

Side by Side Diff: src/full-codegen/x64/full-codegen-x64.cc

Issue 1606273002: Implement [Generator].prototype.return. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 11 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #if V8_TARGET_ARCH_X64 5 #if V8_TARGET_ARCH_X64
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/codegen.h" 10 #include "src/codegen.h"
(...skipping 1853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1864 case Yield::kSuspend: 1864 case Yield::kSuspend:
1865 // Pop value from top-of-stack slot; box result into result register. 1865 // Pop value from top-of-stack slot; box result into result register.
1866 EmitCreateIteratorResult(false); 1866 EmitCreateIteratorResult(false);
1867 __ Push(result_register()); 1867 __ Push(result_register());
1868 // Fall through. 1868 // Fall through.
1869 case Yield::kInitial: { 1869 case Yield::kInitial: {
1870 Label suspend, continuation, post_runtime, resume; 1870 Label suspend, continuation, post_runtime, resume;
1871 1871
1872 __ jmp(&suspend); 1872 __ jmp(&suspend);
1873 __ bind(&continuation); 1873 __ bind(&continuation);
1874 // When we arrive here, the stack top is the resume mode and
1875 // result_register() holds the input value (the argument given to the
1876 // respective resume operation).
1874 __ RecordGeneratorContinuation(); 1877 __ RecordGeneratorContinuation();
1875 __ jmp(&resume); 1878 __ Pop(rbx);
1879 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::RETURN));
1880 __ j(not_equal, &resume);
1881 __ Push(result_register());
1882 EmitCreateIteratorResult(true);
1883 EmitUnwindBeforeReturn();
1884 EmitReturnSequence();
1876 1885
1877 __ bind(&suspend); 1886 __ bind(&suspend);
1878 VisitForAccumulatorValue(expr->generator_object()); 1887 VisitForAccumulatorValue(expr->generator_object());
1879 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos())); 1888 DCHECK(continuation.pos() > 0 && Smi::IsValid(continuation.pos()));
1880 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), 1889 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset),
1881 Smi::FromInt(continuation.pos())); 1890 Smi::FromInt(continuation.pos()));
1882 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); 1891 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi);
1883 __ movp(rcx, rsi); 1892 __ movp(rcx, rsi);
1884 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx, 1893 __ RecordWriteField(rax, JSGeneratorObject::kContextOffset, rcx, rdx,
1885 kDontSaveFPRegs); 1894 kDontSaveFPRegs);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1942 __ bind(&l_try); 1951 __ bind(&l_try);
1943 __ Pop(rax); // result 1952 __ Pop(rax); // result
1944 int handler_index = NewHandlerTableEntry(); 1953 int handler_index = NewHandlerTableEntry();
1945 EnterTryBlock(handler_index, &l_catch); 1954 EnterTryBlock(handler_index, &l_catch);
1946 const int try_block_size = TryCatch::kElementCount * kPointerSize; 1955 const int try_block_size = TryCatch::kElementCount * kPointerSize;
1947 __ Push(rax); // result 1956 __ Push(rax); // result
1948 1957
1949 __ jmp(&l_suspend); 1958 __ jmp(&l_suspend);
1950 __ bind(&l_continuation); 1959 __ bind(&l_continuation);
1951 __ RecordGeneratorContinuation(); 1960 __ RecordGeneratorContinuation();
1952 __ jmp(&l_resume); 1961 __ Pop(rbx);
1962 __ SmiCompare(rbx, Smi::FromInt(JSGeneratorObject::RETURN));
1963 __ j(not_equal, &l_resume);
1964 __ Push(result_register());
1965 EmitCreateIteratorResult(true);
1966 EmitUnwindBeforeReturn();
1967 EmitReturnSequence();
Dan Ehrenberg 2016/01/20 23:48:21 Looks like you're supporting yield* here; what's t
1953 1968
1954 __ bind(&l_suspend); 1969 __ bind(&l_suspend);
1955 const int generator_object_depth = kPointerSize + try_block_size; 1970 const int generator_object_depth = kPointerSize + try_block_size;
1956 __ movp(rax, Operand(rsp, generator_object_depth)); 1971 __ movp(rax, Operand(rsp, generator_object_depth));
1957 __ Push(rax); // g 1972 __ Push(rax); // g
1958 __ Push(Smi::FromInt(handler_index)); // handler-index 1973 __ Push(Smi::FromInt(handler_index)); // handler-index
1959 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos())); 1974 DCHECK(l_continuation.pos() > 0 && Smi::IsValid(l_continuation.pos()));
1960 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset), 1975 __ Move(FieldOperand(rax, JSGeneratorObject::kContinuationOffset),
1961 Smi::FromInt(l_continuation.pos())); 1976 Smi::FromInt(l_continuation.pos()));
1962 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi); 1977 __ movp(FieldOperand(rax, JSGeneratorObject::kContextOffset), rsi);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
2017 __ Move(LoadDescriptor::SlotRegister(), 2032 __ Move(LoadDescriptor::SlotRegister(),
2018 SmiFromSlot(expr->ValueFeedbackSlot())); 2033 SmiFromSlot(expr->ValueFeedbackSlot()));
2019 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in rax 2034 CallLoadIC(NOT_INSIDE_TYPEOF); // result.value in rax
2020 context()->DropAndPlug(2, rax); // drop iter and g 2035 context()->DropAndPlug(2, rax); // drop iter and g
2021 break; 2036 break;
2022 } 2037 }
2023 } 2038 }
2024 } 2039 }
2025 2040
2026 2041
2027 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, 2042 void FullCodeGenerator::EmitGeneratorResume(
2028 Expression *value, 2043 Expression* generator, Expression* value,
2029 JSGeneratorObject::ResumeMode resume_mode) { 2044 JSGeneratorObject::ResumeMode resume_mode) {
2030 // The value stays in rax, and is ultimately read by the resumed generator, as 2045 // The value stays in rax, and is ultimately read by the resumed generator, as
2031 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it 2046 // if CallRuntime(Runtime::kSuspendJSGeneratorObject) returned it. Or it
2032 // is read to throw the value when the resumed generator is already closed. 2047 // is read to throw the value when the resumed generator is already closed.
2033 // rbx will hold the generator object until the activation has been resumed. 2048 // rbx will hold the generator object until the activation has been resumed.
2034 VisitForStackValue(generator); 2049 VisitForStackValue(generator);
2035 VisitForAccumulatorValue(value); 2050 VisitForAccumulatorValue(value);
2036 __ Pop(rbx); 2051 __ Pop(rbx);
2037 2052
2038 // Load suspended function and context. 2053 // Load suspended function and context.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 if (resume_mode == JSGeneratorObject::NEXT) { 2091 if (resume_mode == JSGeneratorObject::NEXT) {
2077 Label slow_resume; 2092 Label slow_resume;
2078 __ cmpp(rdx, Immediate(0)); 2093 __ cmpp(rdx, Immediate(0));
2079 __ j(not_zero, &slow_resume); 2094 __ j(not_zero, &slow_resume);
2080 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset)); 2095 __ movp(rdx, FieldOperand(rdi, JSFunction::kCodeEntryOffset));
2081 __ SmiToInteger64(rcx, 2096 __ SmiToInteger64(rcx,
2082 FieldOperand(rbx, JSGeneratorObject::kContinuationOffset)); 2097 FieldOperand(rbx, JSGeneratorObject::kContinuationOffset));
2083 __ addp(rdx, rcx); 2098 __ addp(rdx, rcx);
2084 __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset), 2099 __ Move(FieldOperand(rbx, JSGeneratorObject::kContinuationOffset),
2085 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); 2100 Smi::FromInt(JSGeneratorObject::kGeneratorExecuting));
2101 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation.
Benedikt Meurer 2016/01/21 05:09:02 I'd vote for dedicated continuations instead of th
2086 __ jmp(rdx); 2102 __ jmp(rdx);
2087 __ bind(&slow_resume); 2103 __ bind(&slow_resume);
2088 } 2104 }
2089 2105
2090 // Otherwise, we push holes for the operand stack and call the runtime to fix 2106 // Otherwise, we push holes for the operand stack and call the runtime to fix
2091 // up the stack and the handlers. 2107 // up the stack and the handlers.
2092 Label push_operand_holes, call_resume; 2108 Label push_operand_holes, call_resume;
2093 __ bind(&push_operand_holes); 2109 __ bind(&push_operand_holes);
2094 __ subp(rdx, Immediate(1)); 2110 __ subp(rdx, Immediate(1));
2095 __ j(carry, &call_resume); 2111 __ j(carry, &call_resume);
2096 __ Push(rcx); 2112 __ Push(rcx);
2097 __ jmp(&push_operand_holes); 2113 __ jmp(&push_operand_holes);
2098 __ bind(&call_resume); 2114 __ bind(&call_resume);
2115 __ Push(Smi::FromInt(resume_mode)); // Consumed in continuation.
2099 __ Push(rbx); 2116 __ Push(rbx);
2100 __ Push(result_register()); 2117 __ Push(result_register());
2101 __ Push(Smi::FromInt(resume_mode)); 2118 __ Push(Smi::FromInt(resume_mode));
2102 __ CallRuntime(Runtime::kResumeJSGeneratorObject); 2119 __ CallRuntime(Runtime::kResumeJSGeneratorObject);
2103 // Not reached: the runtime call returns elsewhere. 2120 // Not reached: the runtime call returns elsewhere.
2104 __ Abort(kGeneratorFailedToResume); 2121 __ Abort(kGeneratorFailedToResume);
2105 2122
2106 __ bind(&done); 2123 __ bind(&done);
2107 context()->Plug(result_register()); 2124 context()->Plug(result_register());
2108 } 2125 }
(...skipping 2642 matching lines...) Expand 10 before | Expand all | Expand 10 after
4751 Assembler::target_address_at(call_target_address, 4768 Assembler::target_address_at(call_target_address,
4752 unoptimized_code)); 4769 unoptimized_code));
4753 return OSR_AFTER_STACK_CHECK; 4770 return OSR_AFTER_STACK_CHECK;
4754 } 4771 }
4755 4772
4756 4773
4757 } // namespace internal 4774 } // namespace internal
4758 } // namespace v8 4775 } // namespace v8
4759 4776
4760 #endif // V8_TARGET_ARCH_X64 4777 #endif // V8_TARGET_ARCH_X64
OLDNEW
« no previous file with comments | « src/full-codegen/full-codegen.cc ('k') | src/js/generator.js » ('j') | src/js/generator.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698