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