| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
| 6 | 6 |
| 7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
| 8 #include "src/compiler/control-builders.h" | 8 #include "src/compiler/control-builders.h" |
| 9 #include "src/compiler/machine-operator.h" | |
| 10 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
| 11 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
| 12 #include "src/full-codegen.h" | 11 #include "src/full-codegen.h" |
| 13 #include "src/parser.h" | 12 #include "src/parser.h" |
| 14 #include "src/scopes.h" | 13 #include "src/scopes.h" |
| 15 | 14 |
| 16 namespace v8 { | 15 namespace v8 { |
| 17 namespace internal { | 16 namespace internal { |
| 18 namespace compiler { | 17 namespace compiler { |
| 19 | 18 |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 environment()->Push(value); | 730 environment()->Push(value); |
| 732 { | 731 { |
| 733 // Test if FILTER_KEY needs to be called. | 732 // Test if FILTER_KEY needs to be called. |
| 734 IfBuilder test_should_filter(this); | 733 IfBuilder test_should_filter(this); |
| 735 Node* should_filter_cond = | 734 Node* should_filter_cond = |
| 736 NewNode(javascript()->StrictEqual(), should_filter, | 735 NewNode(javascript()->StrictEqual(), should_filter, |
| 737 jsgraph()->TrueConstant()); | 736 jsgraph()->TrueConstant()); |
| 738 test_should_filter.If(should_filter_cond); | 737 test_should_filter.If(should_filter_cond); |
| 739 test_should_filter.Then(); | 738 test_should_filter.Then(); |
| 740 value = environment()->Pop(); | 739 value = environment()->Pop(); |
| 741 Node* builtins = BuildLoadBuiltinsObject(); | 740 // TODO(dcarney): Better load from function context. |
| 742 Node* function = BuildLoadObjectField( | 741 // See comment in BuildLoadBuiltinsObject. |
| 743 builtins, | 742 Handle<JSFunction> function(JSFunction::cast( |
| 744 JSBuiltinsObject::OffsetOfFunctionWithId(Builtins::FILTER_KEY)); | 743 info()->context()->builtins()->javascript_builtin( |
| 744 Builtins::FILTER_KEY))); |
| 745 // Callee. | 745 // Callee. |
| 746 environment()->Push(function); | 746 environment()->Push(jsgraph()->HeapConstant(function)); |
| 747 // Receiver. | 747 // Receiver. |
| 748 environment()->Push(obj); | 748 environment()->Push(obj); |
| 749 // Args. | 749 // Args. |
| 750 environment()->Push(value); | 750 environment()->Push(value); |
| 751 // result is either the string key or Smi(0) indicating the property | 751 // result is either the string key or Smi(0) indicating the property |
| 752 // is gone. | 752 // is gone. |
| 753 Node* res = ProcessArguments( | 753 Node* res = ProcessArguments( |
| 754 javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 3); | 754 javascript()->Call(3, NO_CALL_FUNCTION_FLAGS), 3); |
| 755 // TODO(jarin): provide real bailout id. | 755 // TODO(jarin): provide real bailout id. |
| 756 BuildLazyBailout(res, BailoutId::None()); | 756 BuildLazyBailout(res, BailoutId::None()); |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 } | 868 } |
| 869 | 869 |
| 870 | 870 |
| 871 void AstGraphBuilder::VisitLiteral(Literal* expr) { | 871 void AstGraphBuilder::VisitLiteral(Literal* expr) { |
| 872 Node* value = jsgraph()->Constant(expr->value()); | 872 Node* value = jsgraph()->Constant(expr->value()); |
| 873 ast_context()->ProduceValue(value); | 873 ast_context()->ProduceValue(value); |
| 874 } | 874 } |
| 875 | 875 |
| 876 | 876 |
| 877 void AstGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { | 877 void AstGraphBuilder::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 878 Node* closure = GetFunctionClosure(); | 878 Handle<JSFunction> closure = info()->closure(); |
| 879 | 879 |
| 880 // Create node to materialize a regular expression literal. | 880 // Create node to materialize a regular expression literal. |
| 881 Node* literals_array = | 881 Node* literals_array = jsgraph()->Constant(handle(closure->literals())); |
| 882 BuildLoadObjectField(closure, JSFunction::kLiteralsOffset); | |
| 883 Node* literal_index = jsgraph()->Constant(expr->literal_index()); | 882 Node* literal_index = jsgraph()->Constant(expr->literal_index()); |
| 884 Node* pattern = jsgraph()->Constant(expr->pattern()); | 883 Node* pattern = jsgraph()->Constant(expr->pattern()); |
| 885 Node* flags = jsgraph()->Constant(expr->flags()); | 884 Node* flags = jsgraph()->Constant(expr->flags()); |
| 886 Operator* op = javascript()->Runtime(Runtime::kMaterializeRegExpLiteral, 4); | 885 Operator* op = javascript()->Runtime(Runtime::kMaterializeRegExpLiteral, 4); |
| 887 Node* literal = NewNode(op, literals_array, literal_index, pattern, flags); | 886 Node* literal = NewNode(op, literals_array, literal_index, pattern, flags); |
| 888 ast_context()->ProduceValue(literal); | 887 ast_context()->ProduceValue(literal); |
| 889 } | 888 } |
| 890 | 889 |
| 891 | 890 |
| 892 void AstGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { | 891 void AstGraphBuilder::VisitObjectLiteral(ObjectLiteral* expr) { |
| 893 Node* closure = GetFunctionClosure(); | 892 Handle<JSFunction> closure = info()->closure(); |
| 894 | 893 |
| 895 // Create node to deep-copy the literal boilerplate. | 894 // Create node to deep-copy the literal boilerplate. |
| 896 expr->BuildConstantProperties(isolate()); | 895 expr->BuildConstantProperties(isolate()); |
| 897 Node* literals_array = | 896 Node* literals_array = jsgraph()->Constant(handle(closure->literals())); |
| 898 BuildLoadObjectField(closure, JSFunction::kLiteralsOffset); | |
| 899 Node* literal_index = jsgraph()->Constant(expr->literal_index()); | 897 Node* literal_index = jsgraph()->Constant(expr->literal_index()); |
| 900 Node* constants = jsgraph()->Constant(expr->constant_properties()); | 898 Node* constants = jsgraph()->Constant(expr->constant_properties()); |
| 901 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); | 899 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); |
| 902 Operator* op = javascript()->Runtime(Runtime::kCreateObjectLiteral, 4); | 900 Operator* op = javascript()->Runtime(Runtime::kCreateObjectLiteral, 4); |
| 903 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); | 901 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); |
| 904 | 902 |
| 905 // The object is expected on the operand stack during computation of the | 903 // The object is expected on the operand stack during computation of the |
| 906 // property values and is the value of the entire expression. | 904 // property values and is the value of the entire expression. |
| 907 environment()->Push(literal); | 905 environment()->Push(literal); |
| 908 | 906 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 if (expr->has_function()) { | 991 if (expr->has_function()) { |
| 994 Operator* op = javascript()->Runtime(Runtime::kToFastProperties, 1); | 992 Operator* op = javascript()->Runtime(Runtime::kToFastProperties, 1); |
| 995 NewNode(op, literal); | 993 NewNode(op, literal); |
| 996 } | 994 } |
| 997 | 995 |
| 998 ast_context()->ProduceValue(environment()->Pop()); | 996 ast_context()->ProduceValue(environment()->Pop()); |
| 999 } | 997 } |
| 1000 | 998 |
| 1001 | 999 |
| 1002 void AstGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { | 1000 void AstGraphBuilder::VisitArrayLiteral(ArrayLiteral* expr) { |
| 1003 Node* closure = GetFunctionClosure(); | 1001 Handle<JSFunction> closure = info()->closure(); |
| 1004 | 1002 |
| 1005 // Create node to deep-copy the literal boilerplate. | 1003 // Create node to deep-copy the literal boilerplate. |
| 1006 expr->BuildConstantElements(isolate()); | 1004 expr->BuildConstantElements(isolate()); |
| 1007 Node* literals_array = | 1005 Node* literals_array = jsgraph()->Constant(handle(closure->literals())); |
| 1008 BuildLoadObjectField(closure, JSFunction::kLiteralsOffset); | |
| 1009 Node* literal_index = jsgraph()->Constant(expr->literal_index()); | 1006 Node* literal_index = jsgraph()->Constant(expr->literal_index()); |
| 1010 Node* constants = jsgraph()->Constant(expr->constant_elements()); | 1007 Node* constants = jsgraph()->Constant(expr->constant_elements()); |
| 1011 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); | 1008 Node* flags = jsgraph()->Constant(expr->ComputeFlags()); |
| 1012 Operator* op = javascript()->Runtime(Runtime::kCreateArrayLiteral, 4); | 1009 Operator* op = javascript()->Runtime(Runtime::kCreateArrayLiteral, 4); |
| 1013 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); | 1010 Node* literal = NewNode(op, literals_array, literal_index, constants, flags); |
| 1014 | 1011 |
| 1015 // The array and the literal index are both expected on the operand stack | 1012 // The array and the literal index are both expected on the operand stack |
| 1016 // during computation of the element values. | 1013 // during computation of the element values. |
| 1017 environment()->Push(literal); | 1014 environment()->Push(literal); |
| 1018 environment()->Push(literal_index); | 1015 environment()->Push(literal_index); |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1934 // initializations of const declarations. | 1931 // initializations of const declarations. |
| 1935 Operator* op = javascript()->Runtime(Runtime::kStoreLookupSlot, 4); | 1932 Operator* op = javascript()->Runtime(Runtime::kStoreLookupSlot, 4); |
| 1936 return NewNode(op, value, current_context(), name, strict); | 1933 return NewNode(op, value, current_context(), name, strict); |
| 1937 } | 1934 } |
| 1938 } | 1935 } |
| 1939 UNREACHABLE(); | 1936 UNREACHABLE(); |
| 1940 return NULL; | 1937 return NULL; |
| 1941 } | 1938 } |
| 1942 | 1939 |
| 1943 | 1940 |
| 1944 Node* AstGraphBuilder::BuildLoadObjectField(Node* object, int offset) { | |
| 1945 // TODO(sigurds) Use simplified load here once it is ready. | |
| 1946 MachineOperatorBuilder machine(zone()); | |
| 1947 Node* field_load = NewNode(machine.Load(kMachAnyTagged), object, | |
| 1948 jsgraph_->Int32Constant(offset - kHeapObjectTag)); | |
| 1949 return field_load; | |
| 1950 } | |
| 1951 | |
| 1952 | |
| 1953 Node* AstGraphBuilder::BuildLoadBuiltinsObject() { | 1941 Node* AstGraphBuilder::BuildLoadBuiltinsObject() { |
| 1954 Node* global = BuildLoadGlobalObject(); | 1942 // TODO(mstarzinger): Better load from function context, otherwise optimized |
| 1955 Node* builtins = | 1943 // code cannot be shared across native contexts. |
| 1956 BuildLoadObjectField(global, JSGlobalObject::kBuiltinsOffset); | 1944 return jsgraph()->Constant(handle(info()->context()->builtins())); |
| 1957 return builtins; | |
| 1958 } | 1945 } |
| 1959 | 1946 |
| 1960 | 1947 |
| 1961 Node* AstGraphBuilder::BuildLoadGlobalObject() { | 1948 Node* AstGraphBuilder::BuildLoadGlobalObject() { |
| 1949 #if 0 |
| 1962 Node* context = GetFunctionContext(); | 1950 Node* context = GetFunctionContext(); |
| 1963 Operator* load_op = | 1951 // TODO(mstarzinger): Use mid-level operator on FixedArray instead of the |
| 1964 javascript()->LoadContext(0, Context::GLOBAL_OBJECT_INDEX, true); | 1952 // JS-level operator that targets JSObject. |
| 1965 return NewNode(load_op, context); | 1953 Node* index = jsgraph()->Constant(Context::GLOBAL_OBJECT_INDEX); |
| 1954 return NewNode(javascript()->LoadProperty(), context, index); |
| 1955 #else |
| 1956 // TODO(mstarzinger): Better load from function context, otherwise optimized |
| 1957 // code cannot be shared across native contexts. See unused code above. |
| 1958 return jsgraph()->Constant(handle(info()->context()->global_object())); |
| 1959 #endif |
| 1966 } | 1960 } |
| 1967 | 1961 |
| 1968 | 1962 |
| 1969 Node* AstGraphBuilder::BuildToBoolean(Node* value) { | 1963 Node* AstGraphBuilder::BuildToBoolean(Node* value) { |
| 1970 // TODO(mstarzinger): Possible optimization is to NOP for boolean values. | 1964 // TODO(mstarzinger): Possible optimization is to NOP for boolean values. |
| 1971 return NewNode(javascript()->ToBoolean(), value); | 1965 return NewNode(javascript()->ToBoolean(), value); |
| 1972 } | 1966 } |
| 1973 | 1967 |
| 1974 | 1968 |
| 1975 Node* AstGraphBuilder::BuildThrowReferenceError(Variable* variable) { | 1969 Node* AstGraphBuilder::BuildThrowReferenceError(Variable* variable) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2057 | 2051 |
| 2058 void AstGraphBuilder::BuildLazyBailoutWithPushedNode(Node* node, | 2052 void AstGraphBuilder::BuildLazyBailoutWithPushedNode(Node* node, |
| 2059 BailoutId ast_id) { | 2053 BailoutId ast_id) { |
| 2060 environment()->Push(node); | 2054 environment()->Push(node); |
| 2061 BuildLazyBailout(node, ast_id); | 2055 BuildLazyBailout(node, ast_id); |
| 2062 environment()->Pop(); | 2056 environment()->Pop(); |
| 2063 } | 2057 } |
| 2064 } | 2058 } |
| 2065 } | 2059 } |
| 2066 } // namespace v8::internal::compiler | 2060 } // namespace v8::internal::compiler |
| OLD | NEW |