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