Chromium Code Reviews| 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? | |
|
danno
2012/10/21 20:44:41
Why has the limitation changed?
mvstanton
2012/10/23 23:44:20
Because elements_kind was encoded in 5 bits, but b
| |
| 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, | |
| 4613 false)); | |
| 4624 | 4614 |
| 4625 // Check if the expected map still matches that of the enumerable. | 4615 // Check if the expected map still matches that of the enumerable. |
| 4626 // If not just deoptimize. | 4616 // If not just deoptimize. |
| 4627 AddInstruction(new(zone()) HCheckMapValue( | 4617 AddInstruction(new(zone()) HCheckMapValue( |
| 4628 environment()->ExpressionStackAt(4), | 4618 environment()->ExpressionStackAt(4), |
| 4629 environment()->ExpressionStackAt(3))); | 4619 environment()->ExpressionStackAt(3))); |
| 4630 | 4620 |
| 4631 Bind(each_var, key); | 4621 Bind(each_var, key); |
| 4632 | 4622 |
| 4633 BreakAndContinueInfo break_info(stmt, 5); | 4623 BreakAndContinueInfo break_info(stmt, 5); |
| (...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5218 Representation::Integer32())); | 5208 Representation::Integer32())); |
| 5219 | 5209 |
| 5220 switch (boilerplate_elements_kind) { | 5210 switch (boilerplate_elements_kind) { |
| 5221 case FAST_SMI_ELEMENTS: | 5211 case FAST_SMI_ELEMENTS: |
| 5222 case FAST_HOLEY_SMI_ELEMENTS: | 5212 case FAST_HOLEY_SMI_ELEMENTS: |
| 5223 // Smi-only arrays need a smi check. | 5213 // Smi-only arrays need a smi check. |
| 5224 AddInstruction(new(zone()) HCheckSmi(value)); | 5214 AddInstruction(new(zone()) HCheckSmi(value)); |
| 5225 // Fall through. | 5215 // Fall through. |
| 5226 case FAST_ELEMENTS: | 5216 case FAST_ELEMENTS: |
| 5227 case FAST_HOLEY_ELEMENTS: | 5217 case FAST_HOLEY_ELEMENTS: |
| 5228 AddInstruction(new(zone()) HStoreKeyedFastElement( | 5218 case FAST_DOUBLE_ELEMENTS: |
| 5219 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
| 5220 AddInstruction(new(zone()) HStoreKeyed( | |
| 5229 elements, | 5221 elements, |
| 5230 key, | 5222 key, |
| 5231 value, | 5223 value, |
| 5232 boilerplate_elements_kind)); | 5224 boilerplate_elements_kind, false)); |
| 5233 break; | |
| 5234 case FAST_DOUBLE_ELEMENTS: | |
| 5235 case FAST_HOLEY_DOUBLE_ELEMENTS: | |
| 5236 AddInstruction(new(zone()) HStoreKeyedFastDoubleElement(elements, | |
| 5237 key, | |
| 5238 value)); | |
| 5239 break; | 5225 break; |
| 5240 default: | 5226 default: |
| 5241 UNREACHABLE(); | 5227 UNREACHABLE(); |
| 5242 break; | 5228 break; |
| 5243 } | 5229 } |
| 5244 | 5230 |
| 5245 AddSimulate(expr->GetIdForElement(i)); | 5231 AddSimulate(expr->GetIdForElement(i)); |
| 5246 } | 5232 } |
| 5247 return ast_context()->ReturnValue(Pop()); | 5233 return ast_context()->ReturnValue(Pop()); |
| 5248 } | 5234 } |
| (...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6078 case FAST_ELEMENTS: | 6064 case FAST_ELEMENTS: |
| 6079 case FAST_DOUBLE_ELEMENTS: | 6065 case FAST_DOUBLE_ELEMENTS: |
| 6080 case FAST_HOLEY_SMI_ELEMENTS: | 6066 case FAST_HOLEY_SMI_ELEMENTS: |
| 6081 case FAST_HOLEY_ELEMENTS: | 6067 case FAST_HOLEY_ELEMENTS: |
| 6082 case FAST_HOLEY_DOUBLE_ELEMENTS: | 6068 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 6083 case DICTIONARY_ELEMENTS: | 6069 case DICTIONARY_ELEMENTS: |
| 6084 case NON_STRICT_ARGUMENTS_ELEMENTS: | 6070 case NON_STRICT_ARGUMENTS_ELEMENTS: |
| 6085 UNREACHABLE(); | 6071 UNREACHABLE(); |
| 6086 break; | 6072 break; |
| 6087 } | 6073 } |
| 6088 return new(zone()) HStoreKeyedSpecializedArrayElement( | 6074 return new(zone()) HStoreKeyed(external_elements, |
| 6089 external_elements, checked_key, val, elements_kind); | 6075 checked_key, |
| 6076 val, | |
| 6077 elements_kind, | |
| 6078 true); | |
| 6090 } else { | 6079 } else { |
| 6091 ASSERT(val == NULL); | 6080 ASSERT(val == NULL); |
| 6092 HLoadKeyedSpecializedArrayElement* load = | 6081 HLoadKeyed* load = |
| 6093 new(zone()) HLoadKeyedSpecializedArrayElement( | 6082 new(zone()) HLoadKeyed( |
| 6094 external_elements, checked_key, dependency, elements_kind); | 6083 external_elements, checked_key, dependency, elements_kind, true); |
| 6095 if (FLAG_opt_safe_uint32_operations && | 6084 if (FLAG_opt_safe_uint32_operations && |
| 6096 elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) { | 6085 elements_kind == EXTERNAL_UNSIGNED_INT_ELEMENTS) { |
| 6097 graph()->RecordUint32Instruction(load); | 6086 graph()->RecordUint32Instruction(load); |
| 6098 } | 6087 } |
| 6099 return load; | 6088 return load; |
| 6100 } | 6089 } |
| 6101 } | 6090 } |
| 6102 | 6091 |
| 6103 | 6092 |
| 6104 HInstruction* HGraphBuilder::BuildFastElementAccess(HValue* elements, | 6093 HInstruction* HGraphBuilder::BuildFastElementAccess(HValue* elements, |
| 6105 HValue* checked_key, | 6094 HValue* checked_key, |
| 6106 HValue* val, | 6095 HValue* val, |
| 6107 HValue* load_dependency, | 6096 HValue* load_dependency, |
| 6108 ElementsKind elements_kind, | 6097 ElementsKind elements_kind, |
| 6109 bool is_store) { | 6098 bool is_store) { |
| 6110 if (is_store) { | 6099 if (is_store) { |
| 6111 ASSERT(val != NULL); | 6100 ASSERT(val != NULL); |
| 6112 switch (elements_kind) { | 6101 switch (elements_kind) { |
| 6113 case FAST_DOUBLE_ELEMENTS: | 6102 case FAST_DOUBLE_ELEMENTS: |
| 6114 case FAST_HOLEY_DOUBLE_ELEMENTS: | 6103 case FAST_HOLEY_DOUBLE_ELEMENTS: |
| 6115 return new(zone()) HStoreKeyedFastDoubleElement( | 6104 return new(zone()) HStoreKeyed( |
| 6116 elements, checked_key, val); | 6105 elements, checked_key, val, elements_kind, false); |
| 6117 case FAST_SMI_ELEMENTS: | 6106 case FAST_SMI_ELEMENTS: |
| 6118 case FAST_HOLEY_SMI_ELEMENTS: | 6107 case FAST_HOLEY_SMI_ELEMENTS: |
| 6119 // Smi-only arrays need a smi check. | 6108 // Smi-only arrays need a smi check. |
| 6120 AddInstruction(new(zone()) HCheckSmi(val)); | 6109 AddInstruction(new(zone()) HCheckSmi(val)); |
| 6121 // Fall through. | 6110 // Fall through. |
| 6122 case FAST_ELEMENTS: | 6111 case FAST_ELEMENTS: |
| 6123 case FAST_HOLEY_ELEMENTS: | 6112 case FAST_HOLEY_ELEMENTS: |
| 6124 return new(zone()) HStoreKeyedFastElement( | 6113 return new(zone()) HStoreKeyed( |
| 6125 elements, checked_key, val, elements_kind); | 6114 elements, checked_key, val, elements_kind, false); |
| 6126 default: | 6115 default: |
| 6127 UNREACHABLE(); | 6116 UNREACHABLE(); |
| 6128 return NULL; | 6117 return NULL; |
| 6129 } | 6118 } |
| 6130 } | 6119 } |
| 6131 // It's an element load (!is_store). | 6120 // It's an element load (!is_store). |
| 6132 HoleCheckMode mode = IsFastPackedElementsKind(elements_kind) ? | 6121 return new(zone()) HLoadKeyed(elements, |
| 6133 OMIT_HOLE_CHECK : | 6122 checked_key, |
| 6134 PERFORM_HOLE_CHECK; | 6123 load_dependency, |
| 6135 if (IsFastDoubleElementsKind(elements_kind)) { | 6124 elements_kind, |
| 6136 return new(zone()) HLoadKeyedFastDoubleElement(elements, checked_key, | 6125 false); |
| 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 } | 6126 } |
| 6143 | 6127 |
| 6144 | 6128 |
| 6145 HInstruction* HGraphBuilder::BuildMonomorphicElementAccess(HValue* object, | 6129 HInstruction* HGraphBuilder::BuildMonomorphicElementAccess(HValue* object, |
| 6146 HValue* key, | 6130 HValue* key, |
| 6147 HValue* val, | 6131 HValue* val, |
| 6148 HValue* dependency, | 6132 HValue* dependency, |
| 6149 Handle<Map> map, | 6133 Handle<Map> map, |
| 6150 bool is_store) { | 6134 bool is_store) { |
| 6151 HCheckMaps* mapcheck = new(zone()) HCheckMaps(object, map, | 6135 HCheckMaps* mapcheck = new(zone()) HCheckMaps(object, map, |
| (...skipping 3821 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9973 } | 9957 } |
| 9974 } | 9958 } |
| 9975 | 9959 |
| 9976 #ifdef DEBUG | 9960 #ifdef DEBUG |
| 9977 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 9961 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
| 9978 if (allocator_ != NULL) allocator_->Verify(); | 9962 if (allocator_ != NULL) allocator_->Verify(); |
| 9979 #endif | 9963 #endif |
| 9980 } | 9964 } |
| 9981 | 9965 |
| 9982 } } // namespace v8::internal | 9966 } } // namespace v8::internal |
| OLD | NEW |