| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/js-create-lowering.h" | 5 #include "src/compiler/js-create-lowering.h" |
| 6 | 6 |
| 7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
| 8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
| 9 #include "src/compilation-dependencies.h" | 9 #include "src/compilation-dependencies.h" |
| 10 #include "src/compiler/access-builder.h" | 10 #include "src/compiler/access-builder.h" |
| (...skipping 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 | 923 |
| 924 // Prepare an iterator over argument values recorded in the frame state. | 924 // Prepare an iterator over argument values recorded in the frame state. |
| 925 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); | 925 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); |
| 926 StateValuesAccess parameters_access(parameters); | 926 StateValuesAccess parameters_access(parameters); |
| 927 auto parameters_it = ++parameters_access.begin(); | 927 auto parameters_it = ++parameters_access.begin(); |
| 928 | 928 |
| 929 // Actually allocate the backing store. | 929 // Actually allocate the backing store. |
| 930 AllocationBuilder a(jsgraph(), effect, control); | 930 AllocationBuilder a(jsgraph(), effect, control); |
| 931 a.AllocateArray(argument_count, factory()->fixed_array_map()); | 931 a.AllocateArray(argument_count, factory()->fixed_array_map()); |
| 932 for (int i = 0; i < argument_count; ++i, ++parameters_it) { | 932 for (int i = 0; i < argument_count; ++i, ++parameters_it) { |
| 933 DCHECK_NOT_NULL((*parameters_it).node); |
| 933 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); | 934 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); |
| 934 } | 935 } |
| 935 return a.Finish(); | 936 return a.Finish(); |
| 936 } | 937 } |
| 937 | 938 |
| 938 // Helper that allocates a FixedArray holding argument values recorded in the | 939 // Helper that allocates a FixedArray holding argument values recorded in the |
| 939 // given {frame_state}. Serves as backing store for JSCreateArguments nodes. | 940 // given {frame_state}. Serves as backing store for JSCreateArguments nodes. |
| 940 Node* JSCreateLowering::AllocateRestArguments(Node* effect, Node* control, | 941 Node* JSCreateLowering::AllocateRestArguments(Node* effect, Node* control, |
| 941 Node* frame_state, | 942 Node* frame_state, |
| 942 int start_index) { | 943 int start_index) { |
| 943 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); | 944 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); |
| 944 int argument_count = state_info.parameter_count() - 1; // Minus receiver. | 945 int argument_count = state_info.parameter_count() - 1; // Minus receiver. |
| 945 int num_elements = std::max(0, argument_count - start_index); | 946 int num_elements = std::max(0, argument_count - start_index); |
| 946 if (num_elements == 0) return jsgraph()->EmptyFixedArrayConstant(); | 947 if (num_elements == 0) return jsgraph()->EmptyFixedArrayConstant(); |
| 947 | 948 |
| 948 // Prepare an iterator over argument values recorded in the frame state. | 949 // Prepare an iterator over argument values recorded in the frame state. |
| 949 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); | 950 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); |
| 950 StateValuesAccess parameters_access(parameters); | 951 StateValuesAccess parameters_access(parameters); |
| 951 auto parameters_it = ++parameters_access.begin(); | 952 auto parameters_it = ++parameters_access.begin(); |
| 952 | 953 |
| 953 // Skip unused arguments. | 954 // Skip unused arguments. |
| 954 for (int i = 0; i < start_index; i++) { | 955 for (int i = 0; i < start_index; i++) { |
| 955 ++parameters_it; | 956 ++parameters_it; |
| 956 } | 957 } |
| 957 | 958 |
| 958 // Actually allocate the backing store. | 959 // Actually allocate the backing store. |
| 959 AllocationBuilder a(jsgraph(), effect, control); | 960 AllocationBuilder a(jsgraph(), effect, control); |
| 960 a.AllocateArray(num_elements, factory()->fixed_array_map()); | 961 a.AllocateArray(num_elements, factory()->fixed_array_map()); |
| 961 for (int i = 0; i < num_elements; ++i, ++parameters_it) { | 962 for (int i = 0; i < num_elements; ++i, ++parameters_it) { |
| 963 DCHECK_NOT_NULL((*parameters_it).node); |
| 962 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); | 964 a.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); |
| 963 } | 965 } |
| 964 return a.Finish(); | 966 return a.Finish(); |
| 965 } | 967 } |
| 966 | 968 |
| 967 // Helper that allocates a FixedArray serving as a parameter map for values | 969 // Helper that allocates a FixedArray serving as a parameter map for values |
| 968 // recorded in the given {frame_state}. Some elements map to slots within the | 970 // recorded in the given {frame_state}. Some elements map to slots within the |
| 969 // given {context}. Serves as backing store for JSCreateArguments nodes. | 971 // given {context}. Serves as backing store for JSCreateArguments nodes. |
| 970 Node* JSCreateLowering::AllocateAliasedArguments( | 972 Node* JSCreateLowering::AllocateAliasedArguments( |
| 971 Node* effect, Node* control, Node* frame_state, Node* context, | 973 Node* effect, Node* control, Node* frame_state, Node* context, |
| 972 Handle<SharedFunctionInfo> shared, bool* has_aliased_arguments) { | 974 Handle<SharedFunctionInfo> shared, bool* has_aliased_arguments) { |
| 973 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); | 975 FrameStateInfo state_info = OpParameter<FrameStateInfo>(frame_state); |
| 974 int argument_count = state_info.parameter_count() - 1; // Minus receiver. | 976 int argument_count = state_info.parameter_count() - 1; // Minus receiver. |
| 975 if (argument_count == 0) return jsgraph()->EmptyFixedArrayConstant(); | 977 if (argument_count == 0) return jsgraph()->EmptyFixedArrayConstant(); |
| 976 | 978 |
| 977 // If there is no aliasing, the arguments object elements are not special in | 979 // If there is no aliasing, the arguments object elements are not special in |
| 978 // any way, we can just return an unmapped backing store instead. | 980 // any way, we can just return an unmapped backing store instead. |
| 979 int parameter_count = shared->internal_formal_parameter_count(); | 981 int parameter_count = shared->internal_formal_parameter_count(); |
| 980 if (parameter_count == 0) { | 982 if (parameter_count == 0) { |
| 981 return AllocateArguments(effect, control, frame_state); | 983 return AllocateArguments(effect, control, frame_state); |
| 982 } | 984 } |
| 983 | 985 |
| 984 // Calculate number of argument values being aliased/mapped. | 986 // Calculate number of argument values being aliased/mapped. |
| 985 int mapped_count = Min(argument_count, parameter_count); | 987 int mapped_count = Min(argument_count, parameter_count); |
| 986 *has_aliased_arguments = true; | 988 *has_aliased_arguments = true; |
| 987 | 989 |
| 988 // Prepare an iterator over argument values recorded in the frame state. | 990 // Prepare an iterator over argument values recorded in the frame state. |
| 989 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); | 991 Node* const parameters = frame_state->InputAt(kFrameStateParametersInput); |
| 990 StateValuesAccess parameters_access(parameters); | 992 StateValuesAccess parameters_access(parameters); |
| 991 auto paratemers_it = ++parameters_access.begin(); | 993 auto parameters_it = ++parameters_access.begin(); |
| 992 | 994 |
| 993 // The unmapped argument values recorded in the frame state are stored yet | 995 // The unmapped argument values recorded in the frame state are stored yet |
| 994 // another indirection away and then linked into the parameter map below, | 996 // another indirection away and then linked into the parameter map below, |
| 995 // whereas mapped argument values are replaced with a hole instead. | 997 // whereas mapped argument values are replaced with a hole instead. |
| 996 AllocationBuilder aa(jsgraph(), effect, control); | 998 AllocationBuilder aa(jsgraph(), effect, control); |
| 997 aa.AllocateArray(argument_count, factory()->fixed_array_map()); | 999 aa.AllocateArray(argument_count, factory()->fixed_array_map()); |
| 998 for (int i = 0; i < mapped_count; ++i, ++paratemers_it) { | 1000 for (int i = 0; i < mapped_count; ++i, ++parameters_it) { |
| 999 aa.Store(AccessBuilder::ForFixedArraySlot(i), jsgraph()->TheHoleConstant()); | 1001 aa.Store(AccessBuilder::ForFixedArraySlot(i), jsgraph()->TheHoleConstant()); |
| 1000 } | 1002 } |
| 1001 for (int i = mapped_count; i < argument_count; ++i, ++paratemers_it) { | 1003 for (int i = mapped_count; i < argument_count; ++i, ++parameters_it) { |
| 1002 aa.Store(AccessBuilder::ForFixedArraySlot(i), (*paratemers_it).node); | 1004 DCHECK_NOT_NULL((*parameters_it).node); |
| 1005 aa.Store(AccessBuilder::ForFixedArraySlot(i), (*parameters_it).node); |
| 1003 } | 1006 } |
| 1004 Node* arguments = aa.Finish(); | 1007 Node* arguments = aa.Finish(); |
| 1005 | 1008 |
| 1006 // Actually allocate the backing store. | 1009 // Actually allocate the backing store. |
| 1007 AllocationBuilder a(jsgraph(), arguments, control); | 1010 AllocationBuilder a(jsgraph(), arguments, control); |
| 1008 a.AllocateArray(mapped_count + 2, factory()->sloppy_arguments_elements_map()); | 1011 a.AllocateArray(mapped_count + 2, factory()->sloppy_arguments_elements_map()); |
| 1009 a.Store(AccessBuilder::ForFixedArraySlot(0), context); | 1012 a.Store(AccessBuilder::ForFixedArraySlot(0), context); |
| 1010 a.Store(AccessBuilder::ForFixedArraySlot(1), arguments); | 1013 a.Store(AccessBuilder::ForFixedArraySlot(1), arguments); |
| 1011 for (int i = 0; i < mapped_count; ++i) { | 1014 for (int i = 0; i < mapped_count; ++i) { |
| 1012 int idx = Context::MIN_CONTEXT_SLOTS + parameter_count - 1 - i; | 1015 int idx = Context::MIN_CONTEXT_SLOTS + parameter_count - 1 - i; |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 return jsgraph()->simplified(); | 1280 return jsgraph()->simplified(); |
| 1278 } | 1281 } |
| 1279 | 1282 |
| 1280 MachineOperatorBuilder* JSCreateLowering::machine() const { | 1283 MachineOperatorBuilder* JSCreateLowering::machine() const { |
| 1281 return jsgraph()->machine(); | 1284 return jsgraph()->machine(); |
| 1282 } | 1285 } |
| 1283 | 1286 |
| 1284 } // namespace compiler | 1287 } // namespace compiler |
| 1285 } // namespace internal | 1288 } // namespace internal |
| 1286 } // namespace v8 | 1289 } // namespace v8 |
| OLD | NEW |