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 2697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2708 // Operations that operatate on bits are safe. | 2708 // Operations that operatate on bits are safe. |
2709 if (use->IsBitwise() || | 2709 if (use->IsBitwise() || |
2710 use->IsShl() || | 2710 use->IsShl() || |
2711 use->IsSar() || | 2711 use->IsSar() || |
2712 use->IsShr() || | 2712 use->IsShr() || |
2713 use->IsBitNot()) { | 2713 use->IsBitNot()) { |
2714 return true; | 2714 return true; |
2715 } else if (use->IsChange() || use->IsSimulate()) { | 2715 } else if (use->IsChange() || use->IsSimulate()) { |
2716 // Conversions and deoptimization have special support for unt32. | 2716 // Conversions and deoptimization have special support for unt32. |
2717 return true; | 2717 return true; |
2718 } else if (use->IsStoreKeyedSpecializedArrayElement()) { | 2718 } else if (use->IsStoreKeyed()) { |
2719 // Storing a value into an external integer array is a bit level operation. | 2719 HStoreKeyed* store = HStoreKeyed::cast(use); |
2720 HStoreKeyedSpecializedArrayElement* store = | 2720 if (store->is_external()) { |
2721 HStoreKeyedSpecializedArrayElement::cast(use); | 2721 // Storing a value into an external integer array is a |
2722 | 2722 // bit level operation. |
2723 if (store->value() == val) { | 2723 if (store->value() == val) { |
2724 // Clamping or a conversion to double should have beed inserted. | 2724 // Clamping or a conversion to double should have beed inserted. |
2725 ASSERT(store->elements_kind() != EXTERNAL_PIXEL_ELEMENTS); | 2725 ASSERT(store->elements_kind() != EXTERNAL_PIXEL_ELEMENTS); |
2726 ASSERT(store->elements_kind() != EXTERNAL_FLOAT_ELEMENTS); | 2726 ASSERT(store->elements_kind() != EXTERNAL_FLOAT_ELEMENTS); |
2727 ASSERT(store->elements_kind() != EXTERNAL_DOUBLE_ELEMENTS); | 2727 ASSERT(store->elements_kind() != EXTERNAL_DOUBLE_ELEMENTS); |
2728 return true; | 2728 return true; |
| 2729 } |
2729 } | 2730 } |
2730 } | 2731 } |
2731 | 2732 |
2732 return false; | 2733 return false; |
2733 } | 2734 } |
2734 | 2735 |
2735 | 2736 |
2736 // Iterate over all uses and verify that they are uint32 safe: either don't | 2737 // Iterate over all uses and verify that they are uint32 safe: either don't |
2737 // distinguish between int32 and uint32 due to their bitwise nature or | 2738 // distinguish between int32 and uint32 due to their bitwise nature or |
2738 // have special support for uint32 values. | 2739 // have special support for uint32 values. |
(...skipping 997 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3736 if (!constant->HasInteger32Value()) return; | 3737 if (!constant->HasInteger32Value()) return; |
3737 int32_t value = constant->Integer32Value() * sign; | 3738 int32_t value = constant->Integer32Value() * sign; |
3738 // We limit offset values to 30 bits because we want to avoid the risk of | 3739 // We limit offset values to 30 bits because we want to avoid the risk of |
3739 // overflows when the offset is added to the object header size. | 3740 // overflows when the offset is added to the object header size. |
3740 if (value >= 1 << 30 || value < 0) return; | 3741 if (value >= 1 << 30 || value < 0) return; |
3741 array_operation->SetKey(subexpression); | 3742 array_operation->SetKey(subexpression); |
3742 if (index->HasNoUses()) { | 3743 if (index->HasNoUses()) { |
3743 index->DeleteAndReplaceWith(NULL); | 3744 index->DeleteAndReplaceWith(NULL); |
3744 } | 3745 } |
3745 ASSERT(value >= 0); | 3746 ASSERT(value >= 0); |
| 3747 |
| 3748 // TODO(mvstanton): Now, realistically this is limited to 26 bits. |
| 3749 // What should be done about that? |
3746 array_operation->SetIndexOffset(static_cast<uint32_t>(value)); | 3750 array_operation->SetIndexOffset(static_cast<uint32_t>(value)); |
3747 array_operation->SetDehoisted(true); | 3751 array_operation->SetDehoisted(true); |
3748 } | 3752 } |
3749 | 3753 |
3750 | 3754 |
3751 void HGraph::DehoistSimpleArrayIndexComputations() { | 3755 void HGraph::DehoistSimpleArrayIndexComputations() { |
3752 if (!FLAG_array_index_dehoisting) return; | 3756 if (!FLAG_array_index_dehoisting) return; |
3753 | 3757 |
3754 HPhase phase("H_Dehoist index computations", this); | 3758 HPhase phase("H_Dehoist index computations", this); |
3755 for (int i = 0; i < blocks()->length(); ++i) { | 3759 for (int i = 0; i < blocks()->length(); ++i) { |
3756 for (HInstruction* instr = blocks()->at(i)->first(); | 3760 for (HInstruction* instr = blocks()->at(i)->first(); |
3757 instr != NULL; | 3761 instr != NULL; |
3758 instr = instr->next()) { | 3762 instr = instr->next()) { |
3759 ArrayInstructionInterface* array_instruction = NULL; | 3763 ArrayInstructionInterface* array_instruction = NULL; |
3760 if (instr->IsLoadKeyedFastElement()) { | 3764 if (instr->IsLoadKeyed()) { |
3761 HLoadKeyedFastElement* op = HLoadKeyedFastElement::cast(instr); | 3765 HLoadKeyed* op = HLoadKeyed::cast(instr); |
3762 array_instruction = static_cast<ArrayInstructionInterface*>(op); | 3766 array_instruction = static_cast<ArrayInstructionInterface*>(op); |
3763 } else if (instr->IsLoadKeyedFastDoubleElement()) { | 3767 } else if (instr->IsStoreKeyed()) { |
3764 HLoadKeyedFastDoubleElement* op = | 3768 HStoreKeyed* op = HStoreKeyed::cast(instr); |
3765 HLoadKeyedFastDoubleElement::cast(instr); | |
3766 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3767 } else if (instr->IsLoadKeyedSpecializedArrayElement()) { | |
3768 HLoadKeyedSpecializedArrayElement* op = | |
3769 HLoadKeyedSpecializedArrayElement::cast(instr); | |
3770 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3771 } else if (instr->IsStoreKeyedFastElement()) { | |
3772 HStoreKeyedFastElement* op = HStoreKeyedFastElement::cast(instr); | |
3773 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3774 } else if (instr->IsStoreKeyedFastDoubleElement()) { | |
3775 HStoreKeyedFastDoubleElement* op = | |
3776 HStoreKeyedFastDoubleElement::cast(instr); | |
3777 array_instruction = static_cast<ArrayInstructionInterface*>(op); | |
3778 } else if (instr->IsStoreKeyedSpecializedArrayElement()) { | |
3779 HStoreKeyedSpecializedArrayElement* op = | |
3780 HStoreKeyedSpecializedArrayElement::cast(instr); | |
3781 array_instruction = static_cast<ArrayInstructionInterface*>(op); | 3769 array_instruction = static_cast<ArrayInstructionInterface*>(op); |
3782 } else { | 3770 } else { |
3783 continue; | 3771 continue; |
3784 } | 3772 } |
3785 DehoistArrayIndex(array_instruction); | 3773 DehoistArrayIndex(array_instruction); |
3786 } | 3774 } |
3787 } | 3775 } |
3788 } | 3776 } |
3789 | 3777 |
3790 | 3778 |
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4610 compare_index->SetSuccessorAt(0, loop_body); | 4598 compare_index->SetSuccessorAt(0, loop_body); |
4611 compare_index->SetSuccessorAt(1, loop_successor); | 4599 compare_index->SetSuccessorAt(1, loop_successor); |
4612 current_block()->Finish(compare_index); | 4600 current_block()->Finish(compare_index); |
4613 | 4601 |
4614 set_current_block(loop_successor); | 4602 set_current_block(loop_successor); |
4615 Drop(5); | 4603 Drop(5); |
4616 | 4604 |
4617 set_current_block(loop_body); | 4605 set_current_block(loop_body); |
4618 | 4606 |
4619 HValue* key = AddInstruction( | 4607 HValue* key = AddInstruction( |
4620 new(zone()) HLoadKeyedFastElement( | 4608 new(zone()) HLoadKeyed( |
4621 environment()->ExpressionStackAt(2), // Enum cache. | 4609 environment()->ExpressionStackAt(2), // Enum cache. |
4622 environment()->ExpressionStackAt(0), // Iteration index. | 4610 environment()->ExpressionStackAt(0), // Iteration index. |
4623 environment()->ExpressionStackAt(0))); | 4611 environment()->ExpressionStackAt(0), |
| 4612 FAST_ELEMENTS)); |
4624 | 4613 |
4625 // Check if the expected map still matches that of the enumerable. | 4614 // Check if the expected map still matches that of the enumerable. |
4626 // If not just deoptimize. | 4615 // If not just deoptimize. |
4627 AddInstruction(new(zone()) HCheckMapValue( | 4616 AddInstruction(new(zone()) HCheckMapValue( |
4628 environment()->ExpressionStackAt(4), | 4617 environment()->ExpressionStackAt(4), |
4629 environment()->ExpressionStackAt(3))); | 4618 environment()->ExpressionStackAt(3))); |
4630 | 4619 |
4631 Bind(each_var, key); | 4620 Bind(each_var, key); |
4632 | 4621 |
4633 BreakAndContinueInfo break_info(stmt, 5); | 4622 BreakAndContinueInfo break_info(stmt, 5); |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5218 Representation::Integer32())); | 5207 Representation::Integer32())); |
5219 | 5208 |
5220 switch (boilerplate_elements_kind) { | 5209 switch (boilerplate_elements_kind) { |
5221 case FAST_SMI_ELEMENTS: | 5210 case FAST_SMI_ELEMENTS: |
5222 case FAST_HOLEY_SMI_ELEMENTS: | 5211 case FAST_HOLEY_SMI_ELEMENTS: |
5223 // Smi-only arrays need a smi check. | 5212 // Smi-only arrays need a smi check. |
5224 AddInstruction(new(zone()) HCheckSmi(value)); | 5213 AddInstruction(new(zone()) HCheckSmi(value)); |
5225 // Fall through. | 5214 // Fall through. |
5226 case FAST_ELEMENTS: | 5215 case FAST_ELEMENTS: |
5227 case FAST_HOLEY_ELEMENTS: | 5216 case FAST_HOLEY_ELEMENTS: |
5228 AddInstruction(new(zone()) HStoreKeyedFastElement( | 5217 case FAST_DOUBLE_ELEMENTS: |
| 5218 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 5219 AddInstruction(new(zone()) HStoreKeyed( |
5229 elements, | 5220 elements, |
5230 key, | 5221 key, |
5231 value, | 5222 value, |
5232 boilerplate_elements_kind)); | 5223 boilerplate_elements_kind)); |
5233 break; | 5224 break; |
5234 case FAST_DOUBLE_ELEMENTS: | |
5235 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
5236 AddInstruction(new(zone()) HStoreKeyedFastDoubleElement(elements, | |
5237 key, | |
5238 value)); | |
5239 break; | |
5240 default: | 5225 default: |
5241 UNREACHABLE(); | 5226 UNREACHABLE(); |
5242 break; | 5227 break; |
5243 } | 5228 } |
5244 | 5229 |
5245 AddSimulate(expr->GetIdForElement(i)); | 5230 AddSimulate(expr->GetIdForElement(i)); |
5246 } | 5231 } |
5247 return ast_context()->ReturnValue(Pop()); | 5232 return ast_context()->ReturnValue(Pop()); |
5248 } | 5233 } |
5249 | 5234 |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6078 case FAST_ELEMENTS: | 6063 case FAST_ELEMENTS: |
6079 case FAST_DOUBLE_ELEMENTS: | 6064 case FAST_DOUBLE_ELEMENTS: |
6080 case FAST_HOLEY_SMI_ELEMENTS: | 6065 case FAST_HOLEY_SMI_ELEMENTS: |
6081 case FAST_HOLEY_ELEMENTS: | 6066 case FAST_HOLEY_ELEMENTS: |
6082 case FAST_HOLEY_DOUBLE_ELEMENTS: | 6067 case FAST_HOLEY_DOUBLE_ELEMENTS: |
6083 case DICTIONARY_ELEMENTS: | 6068 case DICTIONARY_ELEMENTS: |
6084 case NON_STRICT_ARGUMENTS_ELEMENTS: | 6069 case NON_STRICT_ARGUMENTS_ELEMENTS: |
6085 UNREACHABLE(); | 6070 UNREACHABLE(); |
6086 break; | 6071 break; |
6087 } | 6072 } |
6088 return new(zone()) HStoreKeyedSpecializedArrayElement( | 6073 return new(zone()) HStoreKeyed(external_elements, |
6089 external_elements, checked_key, val, elements_kind); | 6074 checked_key, |
| 6075 val, |
| 6076 elements_kind); |
6090 } else { | 6077 } else { |
6091 ASSERT(val == NULL); | 6078 ASSERT(val == NULL); |
6092 HLoadKeyedSpecializedArrayElement* load = | 6079 HLoadKeyed* load = |
6093 new(zone()) HLoadKeyedSpecializedArrayElement( | 6080 new(zone()) HLoadKeyed( |
6094 external_elements, checked_key, dependency, elements_kind); | 6081 external_elements, checked_key, dependency, elements_kind); |
6095 if (FLAG_opt_safe_uint32_operations && | 6082 if (FLAG_opt_safe_uint32_operations && |
6096 elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) { | 6083 elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) { |
6097 graph()->RecordUint32Instruction(load); | 6084 graph()->RecordUint32Instruction(load); |
6098 } | 6085 } |
6099 return load; | 6086 return load; |
6100 } | 6087 } |
6101 } | 6088 } |
6102 | 6089 |
6103 | 6090 |
6104 HInstruction* HGraphBuilder::BuildFastElementAccess(HValue* elements, | 6091 HInstruction* HGraphBuilder::BuildFastElementAccess(HValue* elements, |
6105 HValue* checked_key, | 6092 HValue* checked_key, |
6106 HValue* val, | 6093 HValue* val, |
6107 HValue* load_dependency, | 6094 HValue* load_dependency, |
6108 ElementsKind elements_kind, | 6095 ElementsKind elements_kind, |
6109 bool is_store) { | 6096 bool is_store) { |
6110 if (is_store) { | 6097 if (is_store) { |
6111 ASSERT(val != NULL); | 6098 ASSERT(val != NULL); |
6112 switch (elements_kind) { | 6099 switch (elements_kind) { |
6113 case FAST_DOUBLE_ELEMENTS: | |
6114 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
6115 return new(zone()) HStoreKeyedFastDoubleElement( | |
6116 elements, checked_key, val); | |
6117 case FAST_SMI_ELEMENTS: | 6100 case FAST_SMI_ELEMENTS: |
6118 case FAST_HOLEY_SMI_ELEMENTS: | 6101 case FAST_HOLEY_SMI_ELEMENTS: |
6119 // Smi-only arrays need a smi check. | 6102 // Smi-only arrays need a smi check. |
6120 AddInstruction(new(zone()) HCheckSmi(val)); | 6103 AddInstruction(new(zone()) HCheckSmi(val)); |
6121 // Fall through. | 6104 // Fall through. |
6122 case FAST_ELEMENTS: | 6105 case FAST_ELEMENTS: |
6123 case FAST_HOLEY_ELEMENTS: | 6106 case FAST_HOLEY_ELEMENTS: |
6124 return new(zone()) HStoreKeyedFastElement( | 6107 case FAST_DOUBLE_ELEMENTS: |
| 6108 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 6109 return new(zone()) HStoreKeyed( |
6125 elements, checked_key, val, elements_kind); | 6110 elements, checked_key, val, elements_kind); |
6126 default: | 6111 default: |
6127 UNREACHABLE(); | 6112 UNREACHABLE(); |
6128 return NULL; | 6113 return NULL; |
6129 } | 6114 } |
6130 } | 6115 } |
6131 // It's an element load (!is_store). | 6116 // It's an element load (!is_store). |
6132 HoleCheckMode mode = IsFastPackedElementsKind(elements_kind) ? | 6117 return new(zone()) HLoadKeyed(elements, |
6133 OMIT_HOLE_CHECK : | 6118 checked_key, |
6134 PERFORM_HOLE_CHECK; | 6119 load_dependency, |
6135 if (IsFastDoubleElementsKind(elements_kind)) { | 6120 elements_kind); |
6136 return new(zone()) HLoadKeyedFastDoubleElement(elements, checked_key, | |
6137 load_dependency, mode); | |
6138 } else { // Smi or Object elements. | |
6139 return new(zone()) HLoadKeyedFastElement(elements, checked_key, | |
6140 load_dependency, elements_kind); | |
6141 } | |
6142 } | 6121 } |
6143 | 6122 |
6144 | 6123 |
6145 HInstruction* HGraphBuilder::BuildMonomorphicElementAccess(HValue* object, | 6124 HInstruction* HGraphBuilder::BuildMonomorphicElementAccess(HValue* object, |
6146 HValue* key, | 6125 HValue* key, |
6147 HValue* val, | 6126 HValue* val, |
6148 HValue* dependency, | 6127 HValue* dependency, |
6149 Handle<Map> map, | 6128 Handle<Map> map, |
6150 bool is_store) { | 6129 bool is_store) { |
6151 HCheckMaps* mapcheck = new(zone()) HCheckMaps(object, map, | 6130 HCheckMaps* mapcheck = new(zone()) HCheckMaps(object, map, |
(...skipping 3821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9973 } | 9952 } |
9974 } | 9953 } |
9975 | 9954 |
9976 #ifdef DEBUG | 9955 #ifdef DEBUG |
9977 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9956 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
9978 if (allocator_ != NULL) allocator_->Verify(); | 9957 if (allocator_ != NULL) allocator_->Verify(); |
9979 #endif | 9958 #endif |
9980 } | 9959 } |
9981 | 9960 |
9982 } } // namespace v8::internal | 9961 } } // namespace v8::internal |
OLD | NEW |