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

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

Issue 2232313002: [interpreter] Simplify hole check condition for variable assignments. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase on top of my other CL. Created 4 years, 4 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/interpreter/bytecode-generator.h" 5 #include "src/interpreter/bytecode-generator.h"
6 6
7 #include "src/ast/scopes.h" 7 #include "src/ast/scopes.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/interpreter/bytecode-flags.h" 10 #include "src/interpreter/bytecode-flags.h"
(...skipping 1850 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 } 1861 }
1862 1862
1863 void BytecodeGenerator::VisitVariableLoad(Variable* variable, 1863 void BytecodeGenerator::VisitVariableLoad(Variable* variable,
1864 FeedbackVectorSlot slot, 1864 FeedbackVectorSlot slot,
1865 TypeofMode typeof_mode) { 1865 TypeofMode typeof_mode) {
1866 switch (variable->location()) { 1866 switch (variable->location()) {
1867 case VariableLocation::LOCAL: { 1867 case VariableLocation::LOCAL: {
1868 Register source(Register(variable->index())); 1868 Register source(Register(variable->index()));
1869 builder()->LoadAccumulatorWithRegister(source); 1869 builder()->LoadAccumulatorWithRegister(source);
1870 BuildHoleCheckForVariableLoad(variable); 1870 BuildHoleCheckForVariableLoad(variable);
1871 execution_result()->SetResultInAccumulator();
1872 break; 1871 break;
1873 } 1872 }
1874 case VariableLocation::PARAMETER: { 1873 case VariableLocation::PARAMETER: {
1875 // The parameter indices are shifted by 1 (receiver is variable 1874 // The parameter indices are shifted by 1 (receiver is variable
1876 // index -1 but is parameter index 0 in BytecodeArrayBuilder). 1875 // index -1 but is parameter index 0 in BytecodeArrayBuilder).
1877 Register source = builder()->Parameter(variable->index() + 1); 1876 Register source = builder()->Parameter(variable->index() + 1);
1878 builder()->LoadAccumulatorWithRegister(source); 1877 builder()->LoadAccumulatorWithRegister(source);
1879 BuildHoleCheckForVariableLoad(variable); 1878 BuildHoleCheckForVariableLoad(variable);
1880 execution_result()->SetResultInAccumulator();
1881 break; 1879 break;
1882 } 1880 }
1883 case VariableLocation::GLOBAL: 1881 case VariableLocation::GLOBAL:
1884 case VariableLocation::UNALLOCATED: { 1882 case VariableLocation::UNALLOCATED: {
1885 builder()->LoadGlobal(feedback_index(slot), typeof_mode); 1883 builder()->LoadGlobal(feedback_index(slot), typeof_mode);
1886 execution_result()->SetResultInAccumulator();
1887 break; 1884 break;
1888 } 1885 }
1889 case VariableLocation::CONTEXT: { 1886 case VariableLocation::CONTEXT: {
1890 int depth = execution_context()->ContextChainDepth(variable->scope()); 1887 int depth = execution_context()->ContextChainDepth(variable->scope());
1891 ContextScope* context = execution_context()->Previous(depth); 1888 ContextScope* context = execution_context()->Previous(depth);
1892 Register context_reg; 1889 Register context_reg;
1893 if (context) { 1890 if (context) {
1894 context_reg = context->reg(); 1891 context_reg = context->reg();
1895 } else { 1892 } else {
1896 context_reg = register_allocator()->NewRegister(); 1893 context_reg = register_allocator()->NewRegister();
1897 // Walk the context chain to find the context at the given depth. 1894 // Walk the context chain to find the context at the given depth.
1898 // TODO(rmcilroy): Perform this work in a bytecode handler once we have 1895 // TODO(rmcilroy): Perform this work in a bytecode handler once we have
1899 // a generic mechanism for performing jumps in interpreter.cc. 1896 // a generic mechanism for performing jumps in interpreter.cc.
1900 // TODO(mythria): Also update bytecode graph builder with correct depth 1897 // TODO(mythria): Also update bytecode graph builder with correct depth
1901 // when this changes. 1898 // when this changes.
1902 builder() 1899 builder()
1903 ->LoadAccumulatorWithRegister(execution_context()->reg()) 1900 ->LoadAccumulatorWithRegister(execution_context()->reg())
1904 .StoreAccumulatorInRegister(context_reg); 1901 .StoreAccumulatorInRegister(context_reg);
1905 for (int i = 0; i < depth; ++i) { 1902 for (int i = 0; i < depth; ++i) {
1906 builder() 1903 builder()
1907 ->LoadContextSlot(context_reg, Context::PREVIOUS_INDEX) 1904 ->LoadContextSlot(context_reg, Context::PREVIOUS_INDEX)
1908 .StoreAccumulatorInRegister(context_reg); 1905 .StoreAccumulatorInRegister(context_reg);
1909 } 1906 }
1910 } 1907 }
1911 1908
1912 builder()->LoadContextSlot(context_reg, variable->index()); 1909 builder()->LoadContextSlot(context_reg, variable->index());
1913 BuildHoleCheckForVariableLoad(variable); 1910 BuildHoleCheckForVariableLoad(variable);
1914 execution_result()->SetResultInAccumulator();
1915 break; 1911 break;
1916 } 1912 }
1917 case VariableLocation::LOOKUP: { 1913 case VariableLocation::LOOKUP: {
1918 builder()->LoadLookupSlot(variable->name(), typeof_mode); 1914 builder()->LoadLookupSlot(variable->name(), typeof_mode);
1919 execution_result()->SetResultInAccumulator();
1920 break; 1915 break;
1921 } 1916 }
1922 case VariableLocation::MODULE: 1917 case VariableLocation::MODULE:
1923 UNREACHABLE(); 1918 UNREACHABLE();
1924 } 1919 }
1920 execution_result()->SetResultInAccumulator();
1925 } 1921 }
1926 1922
1927 void BytecodeGenerator::VisitVariableLoadForAccumulatorValue( 1923 void BytecodeGenerator::VisitVariableLoadForAccumulatorValue(
1928 Variable* variable, FeedbackVectorSlot slot, TypeofMode typeof_mode) { 1924 Variable* variable, FeedbackVectorSlot slot, TypeofMode typeof_mode) {
1929 AccumulatorResultScope accumulator_result(this); 1925 AccumulatorResultScope accumulator_result(this);
1930 VisitVariableLoad(variable, slot, typeof_mode); 1926 VisitVariableLoad(variable, slot, typeof_mode);
1931 } 1927 }
1932 1928
1933 Register BytecodeGenerator::VisitVariableLoadForRegisterValue( 1929 Register BytecodeGenerator::VisitVariableLoadForRegisterValue(
1934 Variable* variable, FeedbackVectorSlot slot, TypeofMode typeof_mode) { 1930 Variable* variable, FeedbackVectorSlot slot, TypeofMode typeof_mode) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 } 2024 }
2029 2025
2030 void BytecodeGenerator::VisitVariableAssignment(Variable* variable, 2026 void BytecodeGenerator::VisitVariableAssignment(Variable* variable,
2031 Token::Value op, 2027 Token::Value op,
2032 FeedbackVectorSlot slot) { 2028 FeedbackVectorSlot slot) {
2033 VariableMode mode = variable->mode(); 2029 VariableMode mode = variable->mode();
2034 RegisterAllocationScope assignment_register_scope(this); 2030 RegisterAllocationScope assignment_register_scope(this);
2035 BytecodeLabel end_label; 2031 BytecodeLabel end_label;
2036 bool hole_check_required = 2032 bool hole_check_required =
2037 variable->binding_needs_init() && 2033 variable->binding_needs_init() &&
2038 ((IsLexicalVariableMode(mode) && op != Token::INIT) || 2034 (op != Token::INIT || (mode == CONST && variable->is_this()));
2039 (mode == CONST && op == Token::INIT && variable->is_this()));
2040 switch (variable->location()) { 2035 switch (variable->location()) {
2041 case VariableLocation::PARAMETER: 2036 case VariableLocation::PARAMETER:
2042 case VariableLocation::LOCAL: { 2037 case VariableLocation::LOCAL: {
2043 Register destination; 2038 Register destination;
2044 if (VariableLocation::PARAMETER == variable->location()) { 2039 if (VariableLocation::PARAMETER == variable->location()) {
2045 destination = Register(builder()->Parameter(variable->index() + 1)); 2040 destination = Register(builder()->Parameter(variable->index() + 1));
2046 } else { 2041 } else {
2047 destination = Register(variable->index()); 2042 destination = Register(variable->index());
2048 } 2043 }
2049 2044
(...skipping 1235 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 return execution_context()->scope()->language_mode(); 3280 return execution_context()->scope()->language_mode();
3286 } 3281 }
3287 3282
3288 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { 3283 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const {
3289 return TypeFeedbackVector::GetIndex(slot); 3284 return TypeFeedbackVector::GetIndex(slot);
3290 } 3285 }
3291 3286
3292 } // namespace interpreter 3287 } // namespace interpreter
3293 } // namespace internal 3288 } // namespace internal
3294 } // namespace v8 3289 } // 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