OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 932 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
943 hydrogen_env->closure(), | 943 hydrogen_env->closure(), |
944 hydrogen_env->frame_type(), | 944 hydrogen_env->frame_type(), |
945 ast_id, | 945 ast_id, |
946 hydrogen_env->parameter_count(), | 946 hydrogen_env->parameter_count(), |
947 argument_count_, | 947 argument_count_, |
948 value_count, | 948 value_count, |
949 outer, | 949 outer, |
950 hydrogen_env->entry(), | 950 hydrogen_env->entry(), |
951 zone()); | 951 zone()); |
952 int argument_index = *argument_index_accumulator; | 952 int argument_index = *argument_index_accumulator; |
953 int object_index = objects_to_materialize->length(); | 953 |
| 954 // Store the environment description into the environment |
| 955 // (with holes for nested objects) |
954 for (int i = 0; i < hydrogen_env->length(); ++i) { | 956 for (int i = 0; i < hydrogen_env->length(); ++i) { |
955 if (hydrogen_env->is_special_index(i)) continue; | 957 if (hydrogen_env->is_special_index(i)) continue; |
956 | 958 |
957 LOperand* op; | 959 LOperand* op; |
958 HValue* value = hydrogen_env->values()->at(i); | 960 HValue* value = hydrogen_env->values()->at(i); |
959 if (value->IsArgumentsObject() || value->IsCapturedObject()) { | 961 if (value->IsArgumentsObject() || value->IsCapturedObject()) { |
960 objects_to_materialize->Add(value, zone()); | |
961 op = LEnvironment::materialization_marker(); | 962 op = LEnvironment::materialization_marker(); |
962 } else if (value->IsPushArgument()) { | 963 } else if (value->IsPushArgument()) { |
963 op = new(zone()) LArgument(argument_index++); | 964 op = new(zone()) LArgument(argument_index++); |
964 } else { | 965 } else { |
965 op = UseAny(value); | 966 op = UseAny(value); |
966 } | 967 } |
967 result->AddValue(op, | 968 result->AddValue(op, |
968 value->representation(), | 969 value->representation(), |
969 value->CheckFlag(HInstruction::kUint32)); | 970 value->CheckFlag(HInstruction::kUint32)); |
970 } | 971 } |
971 | 972 |
972 for (int i = object_index; i < objects_to_materialize->length(); ++i) { | 973 // Recursively store the nested objects into the environment |
973 HValue* object_to_materialize = objects_to_materialize->at(i); | 974 for (int i = 0; i < hydrogen_env->length(); ++i) { |
974 int previously_materialized_object = -1; | 975 if (hydrogen_env->is_special_index(i)) continue; |
975 for (int prev = 0; prev < i; ++prev) { | 976 |
976 if (objects_to_materialize->at(prev) == objects_to_materialize->at(i)) { | 977 HValue* value = hydrogen_env->values()->at(i); |
977 previously_materialized_object = prev; | 978 if (value->IsArgumentsObject() || value->IsCapturedObject()) { |
978 break; | 979 AddObjectToMaterialize(value, objects_to_materialize, result); |
979 } | |
980 } | |
981 int length = object_to_materialize->OperandCount(); | |
982 bool is_arguments = object_to_materialize->IsArgumentsObject(); | |
983 if (previously_materialized_object >= 0) { | |
984 result->AddDuplicateObject(previously_materialized_object); | |
985 continue; | |
986 } else { | |
987 result->AddNewObject(is_arguments ? length - 1 : length, is_arguments); | |
988 } | |
989 for (int i = is_arguments ? 1 : 0; i < length; ++i) { | |
990 LOperand* op; | |
991 HValue* value = object_to_materialize->OperandAt(i); | |
992 if (value->IsArgumentsObject() || value->IsCapturedObject()) { | |
993 objects_to_materialize->Add(value, zone()); | |
994 op = LEnvironment::materialization_marker(); | |
995 } else { | |
996 ASSERT(!value->IsPushArgument()); | |
997 op = UseAny(value); | |
998 } | |
999 result->AddValue(op, | |
1000 value->representation(), | |
1001 value->CheckFlag(HInstruction::kUint32)); | |
1002 } | 980 } |
1003 } | 981 } |
1004 | 982 |
1005 if (hydrogen_env->frame_type() == JS_FUNCTION) { | 983 if (hydrogen_env->frame_type() == JS_FUNCTION) { |
1006 *argument_index_accumulator = argument_index; | 984 *argument_index_accumulator = argument_index; |
1007 } | 985 } |
1008 | 986 |
1009 return result; | 987 return result; |
1010 } | 988 } |
1011 | 989 |
1012 | 990 |
| 991 // Add an object to the supplied environment and object materialization list. |
| 992 // |
| 993 // Notes: |
| 994 // |
| 995 // We are building three lists here: |
| 996 // |
| 997 // 1. In the result->object_mapping_ list (added to by the |
| 998 // LEnvironment::Add*Object methods), we store the lengths (number |
| 999 // of fields) of the captured objects in depth-first traversal order, or |
| 1000 // in case of duplicated objects, we store the index to the duplicate object |
| 1001 // (with a tag to differentiate between captured and duplicated objects). |
| 1002 // |
| 1003 // 2. The object fields are stored in the result->values_ list |
| 1004 // (added to by the LEnvironment.AddValue method) sequentially as lists |
| 1005 // of fields with holes for nested objects (the holes will be expanded |
| 1006 // later by LCodegen::AddToTranslation according to the |
| 1007 // LEnvironment.object_mapping_ list). |
| 1008 // |
| 1009 // 3. The auxiliary objects_to_materialize array stores the hydrogen values |
| 1010 // in the same order as result->object_mapping_ list. This is used |
| 1011 // to detect duplicate values and calculate the corresponding object index. |
| 1012 void LChunkBuilder::AddObjectToMaterialize(HValue* value, |
| 1013 ZoneList<HValue*>* objects_to_materialize, LEnvironment* result) { |
| 1014 int object_index = objects_to_materialize->length(); |
| 1015 // Store the hydrogen value into the de-duplication array |
| 1016 objects_to_materialize->Add(value, zone()); |
| 1017 // Find out whether we are storing a duplicated value |
| 1018 int previously_materialized_object = -1; |
| 1019 for (int prev = 0; prev < object_index; ++prev) { |
| 1020 if (objects_to_materialize->at(prev) == value) { |
| 1021 previously_materialized_object = prev; |
| 1022 break; |
| 1023 } |
| 1024 } |
| 1025 // Store the captured object length (or duplicated object index) |
| 1026 // into the environment. For duplicated objects, we stop here. |
| 1027 int length = value->OperandCount(); |
| 1028 bool is_arguments = value->IsArgumentsObject(); |
| 1029 if (previously_materialized_object >= 0) { |
| 1030 result->AddDuplicateObject(previously_materialized_object); |
| 1031 return; |
| 1032 } else { |
| 1033 result->AddNewObject(is_arguments ? length - 1 : length, is_arguments); |
| 1034 } |
| 1035 // Store the captured object's fields into the environment |
| 1036 for (int i = is_arguments ? 1 : 0; i < length; ++i) { |
| 1037 LOperand* op; |
| 1038 HValue* arg_value = value->OperandAt(i); |
| 1039 if (arg_value->IsArgumentsObject() || arg_value->IsCapturedObject()) { |
| 1040 // Insert a hole for nested objects |
| 1041 op = LEnvironment::materialization_marker(); |
| 1042 } else { |
| 1043 ASSERT(!arg_value->IsPushArgument()); |
| 1044 // For ordinary values, tell the register allocator we need the value |
| 1045 // to be alive here |
| 1046 op = UseAny(arg_value); |
| 1047 } |
| 1048 result->AddValue(op, |
| 1049 arg_value->representation(), |
| 1050 arg_value->CheckFlag(HInstruction::kUint32)); |
| 1051 } |
| 1052 // Recursively store all the nested captured objects into the environment |
| 1053 for (int i = is_arguments ? 1 : 0; i < length; ++i) { |
| 1054 HValue* arg_value = value->OperandAt(i); |
| 1055 if (arg_value->IsArgumentsObject() || arg_value->IsCapturedObject()) { |
| 1056 AddObjectToMaterialize(arg_value, objects_to_materialize, result); |
| 1057 } |
| 1058 } |
| 1059 } |
| 1060 |
| 1061 |
1013 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { | 1062 LInstruction* LChunkBuilder::DoGoto(HGoto* instr) { |
1014 return new(zone()) LGoto(instr->FirstSuccessor()); | 1063 return new(zone()) LGoto(instr->FirstSuccessor()); |
1015 } | 1064 } |
1016 | 1065 |
1017 | 1066 |
1018 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) { | 1067 LInstruction* LChunkBuilder::DoBranch(HBranch* instr) { |
1019 LInstruction* goto_instr = CheckElideControlInstruction(instr); | 1068 LInstruction* goto_instr = CheckElideControlInstruction(instr); |
1020 if (goto_instr != NULL) return goto_instr; | 1069 if (goto_instr != NULL) return goto_instr; |
1021 | 1070 |
1022 HValue* value = instr->value(); | 1071 HValue* value = instr->value(); |
(...skipping 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2648 } | 2697 } |
2649 | 2698 |
2650 | 2699 |
2651 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2700 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2652 LOperand* object = UseRegister(instr->object()); | 2701 LOperand* object = UseRegister(instr->object()); |
2653 LOperand* index = UseRegister(instr->index()); | 2702 LOperand* index = UseRegister(instr->index()); |
2654 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); | 2703 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); |
2655 } | 2704 } |
2656 | 2705 |
2657 } } // namespace v8::internal | 2706 } } // namespace v8::internal |
OLD | NEW |