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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 | 214 |
215 void HBasicBlock::SetJoinId(BailoutId ast_id) { | 215 void HBasicBlock::SetJoinId(BailoutId ast_id) { |
216 int length = predecessors_.length(); | 216 int length = predecessors_.length(); |
217 ASSERT(length > 0); | 217 ASSERT(length > 0); |
218 for (int i = 0; i < length; i++) { | 218 for (int i = 0; i < length; i++) { |
219 HBasicBlock* predecessor = predecessors_[i]; | 219 HBasicBlock* predecessor = predecessors_[i]; |
220 ASSERT(predecessor->end()->IsGoto()); | 220 ASSERT(predecessor->end()->IsGoto()); |
221 HSimulate* simulate = HSimulate::cast(predecessor->end()->previous()); | 221 HSimulate* simulate = HSimulate::cast(predecessor->end()->previous()); |
222 // We only need to verify the ID once. | 222 // We only need to verify the ID once. |
223 ASSERT(i != 0 || | 223 ASSERT(i != 0 || |
224 predecessor->last_environment()->closure()->shared() | 224 (predecessor->last_environment()->closure().is_null() || |
225 ->VerifyBailoutId(ast_id)); | 225 predecessor->last_environment()->closure()->shared() |
226 ->VerifyBailoutId(ast_id))); | |
226 simulate->set_ast_id(ast_id); | 227 simulate->set_ast_id(ast_id); |
227 } | 228 } |
228 } | 229 } |
229 | 230 |
230 | 231 |
231 bool HBasicBlock::Dominates(HBasicBlock* other) const { | 232 bool HBasicBlock::Dominates(HBasicBlock* other) const { |
232 HBasicBlock* current = other->dominator(); | 233 HBasicBlock* current = other->dominator(); |
233 while (current != NULL) { | 234 while (current != NULL) { |
234 if (current == this) return true; | 235 if (current == this) return true; |
235 current = current->dominator(); | 236 current = current->dominator(); |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 if (!pointer->is_set()) { | 596 if (!pointer->is_set()) { |
596 HConstant* constant = | 597 HConstant* constant = |
597 new(zone()) HConstant(value, Representation::Integer32()); | 598 new(zone()) HConstant(value, Representation::Integer32()); |
598 constant->InsertAfter(GetConstantUndefined()); | 599 constant->InsertAfter(GetConstantUndefined()); |
599 pointer->set(constant); | 600 pointer->set(constant); |
600 } | 601 } |
601 return pointer->get(); | 602 return pointer->get(); |
602 } | 603 } |
603 | 604 |
604 | 605 |
606 HConstant* HGraph::GetConstant0() { | |
607 return GetConstantInt32(&constant_0_, 0); | |
608 } | |
609 | |
610 | |
605 HConstant* HGraph::GetConstant1() { | 611 HConstant* HGraph::GetConstant1() { |
606 return GetConstantInt32(&constant_1_, 1); | 612 return GetConstantInt32(&constant_1_, 1); |
607 } | 613 } |
608 | 614 |
609 | 615 |
610 HConstant* HGraph::GetConstantMinus1() { | 616 HConstant* HGraph::GetConstantMinus1() { |
611 return GetConstantInt32(&constant_minus1_, -1); | 617 return GetConstantInt32(&constant_minus1_, -1); |
612 } | 618 } |
613 | 619 |
614 | 620 |
615 HConstant* HGraph::GetConstantTrue() { | 621 HConstant* HGraph::GetConstantTrue() { |
616 return GetConstant(&constant_true_, isolate()->factory()->true_value()); | 622 return GetConstant(&constant_true_, isolate()->factory()->true_value()); |
617 } | 623 } |
618 | 624 |
619 | 625 |
620 HConstant* HGraph::GetConstantFalse() { | 626 HConstant* HGraph::GetConstantFalse() { |
621 return GetConstant(&constant_false_, isolate()->factory()->false_value()); | 627 return GetConstant(&constant_false_, isolate()->factory()->false_value()); |
622 } | 628 } |
623 | 629 |
624 | 630 |
625 HConstant* HGraph::GetConstantHole() { | 631 HConstant* HGraph::GetConstantHole() { |
626 return GetConstant(&constant_hole_, isolate()->factory()->the_hole_value()); | 632 return GetConstant(&constant_hole_, isolate()->factory()->the_hole_value()); |
627 } | 633 } |
628 | 634 |
629 | 635 |
636 HGraphBuilder::IfBuilder::IfBuilder(HGraphBuilder* builder, BailoutId id) | |
637 : builder_(builder), | |
638 finished_(false), | |
639 id_(id) { | |
640 HEnvironment* env = builder->environment(); | |
641 true_env_ = env->Copy(); | |
Michael Starzinger
2013/02/01 13:15:08
I think it is safer not to preserve these environm
danno
2013/02/02 17:56:21
Done.
| |
642 false_env_ = env->Copy(); | |
643 merge_env_ = env->Copy(); | |
644 true_block_ = builder->CreateBasicBlock(true_env_); | |
645 false_block_ = builder->CreateBasicBlock(false_env_); | |
646 merge_block_ = builder->CreateBasicBlock(merge_env_); | |
647 } | |
648 | |
649 | |
650 void HGraphBuilder::IfBuilder::BeginTrue(HValue* left, | |
651 HValue* right, | |
652 Token::Value token) { | |
653 HCompareIDAndBranch* compare = | |
654 new(zone()) HCompareIDAndBranch(left, right, token); | |
655 compare->ChangeRepresentation(Representation::Integer32()); | |
656 compare->SetSuccessorAt(0, true_block_); | |
657 compare->SetSuccessorAt(1, false_block_); | |
658 builder_->current_block()->Finish(compare); | |
659 builder_->set_current_block(true_block_); | |
660 } | |
661 | |
662 | |
663 void HGraphBuilder::IfBuilder::BeginFalse() { | |
664 builder_->current_block()->Goto(merge_block_); | |
665 builder_->set_current_block(false_block_); | |
666 } | |
667 | |
668 | |
669 void HGraphBuilder::IfBuilder::End() { | |
670 ASSERT(!finished_); | |
671 builder_->current_block()->Goto(merge_block_); | |
672 builder_->set_current_block(merge_block_); | |
673 merge_block_->SetJoinId(id_); | |
674 finished_ = true; | |
675 } | |
676 | |
677 | |
678 HGraphBuilder::LoopBuilder::LoopBuilder(HGraphBuilder* builder, | |
679 HValue* context, | |
680 LoopBuilder::Direction direction, | |
681 BailoutId id) | |
682 : builder_(builder), | |
683 context_(context), | |
684 direction_(direction), | |
685 id_(id), | |
686 finished_(false) { | |
687 HEnvironment* env = builder_->environment(); | |
688 body_env_ = env->Copy(); | |
Michael Starzinger
2013/02/01 13:15:08
Likewise.
danno
2013/02/02 17:56:21
Done.
| |
689 exit_env_ = env->Copy(); | |
690 header_block_ = builder->CreateLoopHeaderBlock(); | |
691 body_block_ = builder->CreateBasicBlock(body_env_); | |
692 exit_block_ = builder->CreateBasicBlock(exit_env_); | |
693 } | |
694 | |
695 | |
696 HValue* HGraphBuilder::LoopBuilder::BeginBody(HValue* initial, | |
697 HValue* terminating, | |
698 Token::Value token) { | |
699 phi_ = new(zone()) HPhi(0, zone()); | |
700 header_block_->AddPhi(phi_); | |
701 phi_->AddInput(initial); | |
702 phi_->ChangeRepresentation(Representation::Integer32()); | |
703 HEnvironment* env = builder_->environment(); | |
704 env->Push(initial); | |
705 builder_->current_block()->Goto(header_block_); | |
706 builder_->set_current_block(header_block_); | |
707 | |
708 builder_->set_current_block(header_block_); | |
709 HCompareIDAndBranch* compare = | |
710 new(zone()) HCompareIDAndBranch(phi_, terminating, token); | |
711 compare->ChangeRepresentation(Representation::Integer32()); | |
712 compare->SetSuccessorAt(0, body_block_); | |
713 compare->SetSuccessorAt(1, exit_block_); | |
714 builder_->current_block()->Finish(compare); | |
715 | |
716 builder_->set_current_block(body_block_); | |
717 if (direction_ == kPreIncrement || direction_ == kPreDecrement) { | |
718 HValue* one = builder_->graph()->GetConstant1(); | |
719 if (direction_ == kPreIncrement) { | |
720 increment_ = new(zone()) HAdd(context_, phi_, one); | |
721 } else { | |
722 increment_ = new(zone()) HSub(context_, phi_, one); | |
723 } | |
724 increment_->ClearFlag(HValue::kCanOverflow); | |
725 increment_->ChangeRepresentation(Representation::Integer32()); | |
726 builder_->AddInstruction(increment_); | |
727 return increment_; | |
728 } else { | |
729 return phi_; | |
730 } | |
731 } | |
732 | |
733 | |
734 void HGraphBuilder::LoopBuilder::EndBody() { | |
735 ASSERT(!finished_); | |
736 | |
737 if (direction_ == kPostIncrement || direction_ == kPostDecrement) { | |
738 HValue* one = builder_->graph()->GetConstant1(); | |
739 if (direction_ == kPostIncrement) { | |
740 increment_ = new(zone()) HAdd(context_, phi_, one); | |
741 } else { | |
742 increment_ = new(zone()) HSub(context_, phi_, one); | |
743 } | |
744 increment_->ClearFlag(HValue::kCanOverflow); | |
745 increment_->ChangeRepresentation(Representation::Integer32()); | |
746 builder_->AddInstruction(increment_); | |
747 } | |
748 | |
749 body_env_->Push(increment_); | |
Michael Starzinger
2013/02/01 13:15:08
The body_env_ might be a stale environment in case
danno
2013/02/02 17:56:21
Done.
| |
750 builder_->current_block()->Goto(header_block_); | |
751 header_block_->loop_information()->RegisterBackEdge(body_block_); | |
752 header_block_->SetJoinId(BailoutId::StubEntry()); | |
753 builder_->set_current_block(exit_block_); | |
754 finished_ = true; | |
755 } | |
756 | |
757 | |
630 HGraph* HGraphBuilder::CreateGraph() { | 758 HGraph* HGraphBuilder::CreateGraph() { |
631 graph_ = new(zone()) HGraph(info_); | 759 graph_ = new(zone()) HGraph(info_); |
632 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_); | 760 if (FLAG_hydrogen_stats) HStatistics::Instance()->Initialize(info_); |
633 HPhase phase("H_Block building"); | 761 HPhase phase("H_Block building"); |
634 set_current_block(graph()->entry_block()); | 762 set_current_block(graph()->entry_block()); |
635 if (!BuildGraph()) return NULL; | 763 if (!BuildGraph()) return NULL; |
636 return graph_; | 764 return graph_; |
637 } | 765 } |
638 | 766 |
639 | 767 |
640 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { | 768 HInstruction* HGraphBuilder::AddInstruction(HInstruction* instr) { |
641 ASSERT(current_block() != NULL); | 769 ASSERT(current_block() != NULL); |
642 current_block()->AddInstruction(instr); | 770 current_block()->AddInstruction(instr); |
643 return instr; | 771 return instr; |
644 } | 772 } |
645 | 773 |
646 | 774 |
647 void HGraphBuilder::AddSimulate(BailoutId id, | 775 void HGraphBuilder::AddSimulate(BailoutId id, |
648 RemovableSimulate removable) { | 776 RemovableSimulate removable) { |
649 ASSERT(current_block() != NULL); | 777 ASSERT(current_block() != NULL); |
650 current_block()->AddSimulate(id, removable); | 778 current_block()->AddSimulate(id, removable); |
651 } | 779 } |
652 | 780 |
653 | 781 |
782 HBasicBlock* HGraphBuilder::CreateBasicBlock(HEnvironment* env) { | |
783 HBasicBlock* b = graph()->CreateBasicBlock(); | |
784 b->SetInitialEnvironment(env); | |
785 return b; | |
786 } | |
787 | |
788 | |
789 HBasicBlock* HGraphBuilder::CreateLoopHeaderBlock() { | |
790 HBasicBlock* header = graph()->CreateBasicBlock(); | |
791 HEnvironment* entry_env = environment()->CopyAsLoopHeader(header); | |
792 header->SetInitialEnvironment(entry_env); | |
793 header->AttachLoopInformation(); | |
794 return header; | |
795 } | |
796 | |
797 | |
654 HInstruction* HGraphBuilder::BuildExternalArrayElementAccess( | 798 HInstruction* HGraphBuilder::BuildExternalArrayElementAccess( |
655 HValue* external_elements, | 799 HValue* external_elements, |
656 HValue* checked_key, | 800 HValue* checked_key, |
657 HValue* val, | 801 HValue* val, |
658 HValue* dependency, | 802 HValue* dependency, |
659 ElementsKind elements_kind, | 803 ElementsKind elements_kind, |
660 bool is_store) { | 804 bool is_store) { |
661 Zone* zone = this->zone(); | 805 Zone* zone = this->zone(); |
662 if (is_store) { | 806 if (is_store) { |
663 ASSERT(val != NULL); | 807 ASSERT(val != NULL); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 } else { | 936 } else { |
793 length = AddInstruction(new(zone) HFixedArrayBaseLength(elements)); | 937 length = AddInstruction(new(zone) HFixedArrayBaseLength(elements)); |
794 } | 938 } |
795 checked_key = AddInstruction(new(zone) HBoundsCheck( | 939 checked_key = AddInstruction(new(zone) HBoundsCheck( |
796 key, length, ALLOW_SMI_KEY, checked_index_representation)); | 940 key, length, ALLOW_SMI_KEY, checked_index_representation)); |
797 return BuildFastElementAccess(elements, checked_key, val, mapcheck, | 941 return BuildFastElementAccess(elements, checked_key, val, mapcheck, |
798 elements_kind, is_store); | 942 elements_kind, is_store); |
799 } | 943 } |
800 | 944 |
801 | 945 |
946 HValue* HGraphBuilder::BuildAllocateElements(HContext* context, | |
947 ElementsKind kind, | |
948 HValue* capacity) { | |
949 Zone* zone = this->zone(); | |
950 | |
951 int elements_size = IsFastDoubleElementsKind(kind) | |
952 ? kDoubleSize : kPointerSize; | |
953 HConstant* elements_size_value = | |
954 new(zone) HConstant(elements_size, Representation::Integer32()); | |
955 AddInstruction(elements_size_value); | |
956 HValue* mul = AddInstruction( | |
957 new(zone) HMul(context, capacity, elements_size_value)); | |
958 mul->ChangeRepresentation(Representation::Integer32()); | |
959 mul->ClearFlag(HValue::kCanOverflow); | |
960 | |
961 HConstant* header_size = | |
962 new(zone) HConstant(FixedArray::kHeaderSize, Representation::Integer32()); | |
963 AddInstruction(header_size); | |
964 HValue* total_size = AddInstruction( | |
965 new(zone) HAdd(context, mul, header_size)); | |
966 total_size->ChangeRepresentation(Representation::Integer32()); | |
967 total_size->ClearFlag(HValue::kCanOverflow); | |
968 | |
969 HAllocate::Flags flags = HAllocate::CAN_ALLOCATE_IN_NEW_SPACE; | |
970 if (IsFastDoubleElementsKind(kind)) { | |
971 flags = static_cast<HAllocate::Flags>( | |
972 flags | HAllocate::ALLOCATE_DOUBLE_ALIGNED); | |
973 } | |
974 | |
975 HValue* elements = | |
976 AddInstruction(new(zone) HAllocate(context, total_size, | |
977 HType::JSArray(), flags)); | |
978 Isolate* isolate = graph()->isolate(); | |
979 | |
980 Factory* factory = isolate->factory(); | |
981 Handle<String> map_field_name = factory->map_field_symbol(); | |
982 Handle<Map> map = IsFastDoubleElementsKind(kind) | |
983 ? factory->fixed_double_array_map() | |
984 : factory->fixed_array_map(); | |
985 HValue* map_constant = | |
986 AddInstruction(new(zone) HConstant(map, Representation::Tagged())); | |
987 HInstruction* store_map = | |
988 new(zone) HStoreNamedField(elements, map_field_name, map_constant, | |
Michael Starzinger
2013/02/01 13:15:08
Strictly speaking this store needs to have the kCh
danno
2013/02/02 17:56:21
Done.
| |
989 true, JSObject::kMapOffset); | |
990 AddInstruction(store_map); | |
991 AddSimulate(BailoutId::StubEntry(), FIXED_SIMULATE); | |
992 | |
993 Handle<String> fixed_array_length_field_name = | |
994 isolate->factory()->length_field_symbol(); | |
995 HInstruction* store_length = | |
996 new(zone) HStoreNamedField(elements, fixed_array_length_field_name, | |
997 capacity, true, FixedArray::kLengthOffset); | |
998 AddInstruction(store_length); | |
999 AddSimulate(BailoutId::StubEntry(), FIXED_SIMULATE); | |
1000 | |
1001 return elements; | |
1002 } | |
1003 | |
1004 | |
1005 void HGraphBuilder::BuildCopyElements(HContext* context, | |
Michael Starzinger
2013/02/01 13:15:08
Beautifully simple, me gusta!
danno
2013/02/02 17:56:21
Done.
| |
1006 HValue* from_elements, | |
1007 ElementsKind from_elements_kind, | |
1008 HValue* to_elements, | |
1009 ElementsKind to_elements_kind, | |
1010 HValue* length) { | |
1011 LoopBuilder builder(this, context, LoopBuilder::kPostIncrement); | |
1012 | |
1013 HValue* key = builder.BeginBody(graph()->GetConstant0(), | |
1014 length, Token::LT); | |
1015 | |
1016 HValue* element = | |
1017 AddInstruction(new(zone()) HLoadKeyed(from_elements, key, NULL, | |
1018 from_elements_kind, | |
1019 ALLOW_RETURN_HOLE)); | |
1020 | |
1021 AddInstruction(new(zone()) HStoreKeyed(to_elements, key, element, | |
1022 to_elements_kind)); | |
1023 AddSimulate(BailoutId::StubEntry(), REMOVABLE_SIMULATE); | |
1024 | |
1025 builder.EndBody(); | |
1026 } | |
1027 | |
1028 | |
802 HOptimizedGraphBuilder::HOptimizedGraphBuilder(CompilationInfo* info, | 1029 HOptimizedGraphBuilder::HOptimizedGraphBuilder(CompilationInfo* info, |
803 TypeFeedbackOracle* oracle) | 1030 TypeFeedbackOracle* oracle) |
804 : HGraphBuilder(info), | 1031 : HGraphBuilder(info), |
805 function_state_(NULL), | 1032 function_state_(NULL), |
806 initial_function_state_(this, info, oracle, NORMAL_RETURN), | 1033 initial_function_state_(this, info, oracle, NORMAL_RETURN), |
807 ast_context_(NULL), | 1034 ast_context_(NULL), |
808 break_scope_(NULL), | 1035 break_scope_(NULL), |
809 inlined_count_(0), | 1036 inlined_count_(0), |
810 globals_(10, info->zone()), | 1037 globals_(10, info->zone()), |
811 inline_bailout_(false) { | 1038 inline_bailout_(false) { |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2251 TRACE_GVN_1("Updated first-time accumulated %s\n", | 2478 TRACE_GVN_1("Updated first-time accumulated %s\n", |
2252 *GetGVNFlagsString(*first_time_changes)); | 2479 *GetGVNFlagsString(*first_time_changes)); |
2253 } | 2480 } |
2254 } | 2481 } |
2255 instr = next; | 2482 instr = next; |
2256 } | 2483 } |
2257 } | 2484 } |
2258 | 2485 |
2259 | 2486 |
2260 bool HGlobalValueNumberer::AllowCodeMotion() { | 2487 bool HGlobalValueNumberer::AllowCodeMotion() { |
2261 return info()->opt_count() + 1 < FLAG_max_opt_count; | 2488 return info()->IsStub() || info()->opt_count() + 1 < FLAG_max_opt_count; |
2262 } | 2489 } |
2263 | 2490 |
2264 | 2491 |
2265 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, | 2492 bool HGlobalValueNumberer::ShouldMove(HInstruction* instr, |
2266 HBasicBlock* loop_header) { | 2493 HBasicBlock* loop_header) { |
2267 // If we've disabled code motion or we're in a block that unconditionally | 2494 // If we've disabled code motion or we're in a block that unconditionally |
2268 // deoptimizes, don't move any instructions. | 2495 // deoptimizes, don't move any instructions. |
2269 return AllowCodeMotion() && !instr->block()->IsDeoptimizing(); | 2496 return AllowCodeMotion() && !instr->block()->IsDeoptimizing(); |
2270 } | 2497 } |
2271 | 2498 |
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3503 int checksum = type_info->own_type_change_checksum(); | 3730 int checksum = type_info->own_type_change_checksum(); |
3504 int composite_checksum = graph()->update_type_change_checksum(checksum); | 3731 int composite_checksum = graph()->update_type_change_checksum(checksum); |
3505 graph()->set_use_optimistic_licm( | 3732 graph()->set_use_optimistic_licm( |
3506 !type_info->matches_inlined_type_change_checksum(composite_checksum)); | 3733 !type_info->matches_inlined_type_change_checksum(composite_checksum)); |
3507 type_info->set_inlined_type_change_checksum(composite_checksum); | 3734 type_info->set_inlined_type_change_checksum(composite_checksum); |
3508 | 3735 |
3509 return true; | 3736 return true; |
3510 } | 3737 } |
3511 | 3738 |
3512 | 3739 |
3740 void HGraph::GlobalValueNumbering() { | |
3741 // Perform common subexpression elimination and loop-invariant code motion. | |
3742 if (FLAG_use_gvn) { | |
3743 HPhase phase("H_Global value numbering", this); | |
3744 HGlobalValueNumberer gvn(this, info()); | |
3745 bool removed_side_effects = gvn.Analyze(); | |
3746 // Trigger a second analysis pass to further eliminate duplicate values that | |
3747 // could only be discovered by removing side-effect-generating instructions | |
3748 // during the first pass. | |
3749 if (FLAG_smi_only_arrays && removed_side_effects) { | |
3750 removed_side_effects = gvn.Analyze(); | |
3751 ASSERT(!removed_side_effects); | |
3752 } | |
3753 } | |
3754 } | |
3755 | |
3756 | |
3513 bool HGraph::Optimize(SmartArrayPointer<char>* bailout_reason) { | 3757 bool HGraph::Optimize(SmartArrayPointer<char>* bailout_reason) { |
3514 *bailout_reason = SmartArrayPointer<char>(); | 3758 *bailout_reason = SmartArrayPointer<char>(); |
3515 OrderBlocks(); | 3759 OrderBlocks(); |
3516 AssignDominators(); | 3760 AssignDominators(); |
3517 | 3761 |
3518 #ifdef DEBUG | 3762 #ifdef DEBUG |
3519 // Do a full verify after building the graph and computing dominators. | 3763 // Do a full verify after building the graph and computing dominators. |
3520 Verify(true); | 3764 Verify(true); |
3521 #endif | 3765 #endif |
3522 | 3766 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3556 | 3800 |
3557 InitializeInferredTypes(); | 3801 InitializeInferredTypes(); |
3558 | 3802 |
3559 // Must be performed before canonicalization to ensure that Canonicalize | 3803 // Must be performed before canonicalization to ensure that Canonicalize |
3560 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with | 3804 // will not remove semantically meaningful ToInt32 operations e.g. BIT_OR with |
3561 // zero. | 3805 // zero. |
3562 ComputeSafeUint32Operations(); | 3806 ComputeSafeUint32Operations(); |
3563 | 3807 |
3564 Canonicalize(); | 3808 Canonicalize(); |
3565 | 3809 |
3566 // Perform common subexpression elimination and loop-invariant code motion. | 3810 GlobalValueNumbering(); |
3567 if (FLAG_use_gvn) { | |
3568 HPhase phase("H_Global value numbering", this); | |
3569 HGlobalValueNumberer gvn(this, info()); | |
3570 bool removed_side_effects = gvn.Analyze(); | |
3571 // Trigger a second analysis pass to further eliminate duplicate values that | |
3572 // could only be discovered by removing side-effect-generating instructions | |
3573 // during the first pass. | |
3574 if (FLAG_smi_only_arrays && removed_side_effects) { | |
3575 removed_side_effects = gvn.Analyze(); | |
3576 ASSERT(!removed_side_effects); | |
3577 } | |
3578 } | |
3579 | 3811 |
3580 if (FLAG_use_range) { | 3812 if (FLAG_use_range) { |
3581 HRangeAnalysis rangeAnalysis(this); | 3813 HRangeAnalysis rangeAnalysis(this); |
3582 rangeAnalysis.Analyze(); | 3814 rangeAnalysis.Analyze(); |
3583 } | 3815 } |
3584 ComputeMinusZeroChecks(); | 3816 ComputeMinusZeroChecks(); |
3585 | 3817 |
3586 // Eliminate redundant stack checks on backwards branches. | 3818 // Eliminate redundant stack checks on backwards branches. |
3587 HStackCheckEliminator sce(this); | 3819 HStackCheckEliminator sce(this); |
3588 sce.Process(); | 3820 sce.Process(); |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4158 } | 4390 } |
4159 | 4391 |
4160 | 4392 |
4161 void HOptimizedGraphBuilder::VisitStatements(ZoneList<Statement*>* statements) { | 4393 void HOptimizedGraphBuilder::VisitStatements(ZoneList<Statement*>* statements) { |
4162 for (int i = 0; i < statements->length(); i++) { | 4394 for (int i = 0; i < statements->length(); i++) { |
4163 CHECK_ALIVE(Visit(statements->at(i))); | 4395 CHECK_ALIVE(Visit(statements->at(i))); |
4164 } | 4396 } |
4165 } | 4397 } |
4166 | 4398 |
4167 | 4399 |
4168 HBasicBlock* HOptimizedGraphBuilder::CreateBasicBlock(HEnvironment* env) { | |
4169 HBasicBlock* b = graph()->CreateBasicBlock(); | |
4170 b->SetInitialEnvironment(env); | |
4171 return b; | |
4172 } | |
4173 | |
4174 | |
4175 HBasicBlock* HOptimizedGraphBuilder::CreateLoopHeaderBlock() { | |
4176 HBasicBlock* header = graph()->CreateBasicBlock(); | |
4177 HEnvironment* entry_env = environment()->CopyAsLoopHeader(header); | |
4178 header->SetInitialEnvironment(entry_env); | |
4179 header->AttachLoopInformation(); | |
4180 return header; | |
4181 } | |
4182 | |
4183 | |
4184 void HOptimizedGraphBuilder::VisitBlock(Block* stmt) { | 4400 void HOptimizedGraphBuilder::VisitBlock(Block* stmt) { |
4185 ASSERT(!HasStackOverflow()); | 4401 ASSERT(!HasStackOverflow()); |
4186 ASSERT(current_block() != NULL); | 4402 ASSERT(current_block() != NULL); |
4187 ASSERT(current_block()->HasPredecessor()); | 4403 ASSERT(current_block()->HasPredecessor()); |
4188 if (stmt->scope() != NULL) { | 4404 if (stmt->scope() != NULL) { |
4189 return Bailout("ScopedBlock"); | 4405 return Bailout("ScopedBlock"); |
4190 } | 4406 } |
4191 BreakAndContinueInfo break_info(stmt); | 4407 BreakAndContinueInfo break_info(stmt); |
4192 { BreakAndContinueScope push(&break_info, this); | 4408 { BreakAndContinueScope push(&break_info, this); |
4193 CHECK_BAILOUT(VisitStatements(stmt->statements())); | 4409 CHECK_BAILOUT(VisitStatements(stmt->statements())); |
(...skipping 2301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6495 int num_untransitionable_maps = 0; | 6711 int num_untransitionable_maps = 0; |
6496 Handle<Map> untransitionable_map; | 6712 Handle<Map> untransitionable_map; |
6497 HTransitionElementsKind* transition = NULL; | 6713 HTransitionElementsKind* transition = NULL; |
6498 for (int i = 0; i < maps->length(); ++i) { | 6714 for (int i = 0; i < maps->length(); ++i) { |
6499 Handle<Map> map = maps->at(i); | 6715 Handle<Map> map = maps->at(i); |
6500 ASSERT(map->IsMap()); | 6716 ASSERT(map->IsMap()); |
6501 if (!transition_target.at(i).is_null()) { | 6717 if (!transition_target.at(i).is_null()) { |
6502 ASSERT(Map::IsValidElementsTransition( | 6718 ASSERT(Map::IsValidElementsTransition( |
6503 map->elements_kind(), | 6719 map->elements_kind(), |
6504 transition_target.at(i)->elements_kind())); | 6720 transition_target.at(i)->elements_kind())); |
6721 HValue* context = environment()->LookupContext(); | |
6505 transition = new(zone()) HTransitionElementsKind( | 6722 transition = new(zone()) HTransitionElementsKind( |
6506 object, map, transition_target.at(i)); | 6723 context, object, map, transition_target.at(i)); |
6507 AddInstruction(transition); | 6724 AddInstruction(transition); |
6508 } else { | 6725 } else { |
6509 type_todo[map->elements_kind()] = true; | 6726 type_todo[map->elements_kind()] = true; |
6510 if (IsExternalArrayElementsKind(map->elements_kind())) { | 6727 if (IsExternalArrayElementsKind(map->elements_kind())) { |
6511 todo_external_array = true; | 6728 todo_external_array = true; |
6512 } | 6729 } |
6513 num_untransitionable_maps++; | 6730 num_untransitionable_maps++; |
6514 untransitionable_map = map; | 6731 untransitionable_map = map; |
6515 } | 6732 } |
6516 } | 6733 } |
(...skipping 3231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9748 ast_id_(BailoutId::None()), | 9965 ast_id_(BailoutId::None()), |
9749 zone_(zone) { | 9966 zone_(zone) { |
9750 Initialize(0, 0, 0); | 9967 Initialize(0, 0, 0); |
9751 } | 9968 } |
9752 | 9969 |
9753 | 9970 |
9754 HEnvironment::HEnvironment(const HEnvironment* other, Zone* zone) | 9971 HEnvironment::HEnvironment(const HEnvironment* other, Zone* zone) |
9755 : values_(0, zone), | 9972 : values_(0, zone), |
9756 frame_type_(JS_FUNCTION), | 9973 frame_type_(JS_FUNCTION), |
9757 parameter_count_(0), | 9974 parameter_count_(0), |
9758 specials_count_(1), | 9975 specials_count_(0), |
9759 local_count_(0), | 9976 local_count_(0), |
9760 outer_(NULL), | 9977 outer_(NULL), |
9761 entry_(NULL), | 9978 entry_(NULL), |
9762 pop_count_(0), | 9979 pop_count_(0), |
9763 push_count_(0), | 9980 push_count_(0), |
9764 ast_id_(other->ast_id()), | 9981 ast_id_(other->ast_id()), |
9765 zone_(zone) { | 9982 zone_(zone) { |
9766 Initialize(other); | 9983 Initialize(other); |
9767 } | 9984 } |
9768 | 9985 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9803 closure_ = other->closure(); | 10020 closure_ = other->closure(); |
9804 values_.AddAll(other->values_, zone()); | 10021 values_.AddAll(other->values_, zone()); |
9805 assigned_variables_.Union(other->assigned_variables_, zone()); | 10022 assigned_variables_.Union(other->assigned_variables_, zone()); |
9806 frame_type_ = other->frame_type_; | 10023 frame_type_ = other->frame_type_; |
9807 parameter_count_ = other->parameter_count_; | 10024 parameter_count_ = other->parameter_count_; |
9808 local_count_ = other->local_count_; | 10025 local_count_ = other->local_count_; |
9809 if (other->outer_ != NULL) outer_ = other->outer_->Copy(); // Deep copy. | 10026 if (other->outer_ != NULL) outer_ = other->outer_->Copy(); // Deep copy. |
9810 entry_ = other->entry_; | 10027 entry_ = other->entry_; |
9811 pop_count_ = other->pop_count_; | 10028 pop_count_ = other->pop_count_; |
9812 push_count_ = other->push_count_; | 10029 push_count_ = other->push_count_; |
10030 specials_count_ = other->specials_count_; | |
9813 ast_id_ = other->ast_id_; | 10031 ast_id_ = other->ast_id_; |
9814 } | 10032 } |
9815 | 10033 |
9816 | 10034 |
9817 void HEnvironment::AddIncomingEdge(HBasicBlock* block, HEnvironment* other) { | 10035 void HEnvironment::AddIncomingEdge(HBasicBlock* block, HEnvironment* other) { |
9818 ASSERT(!block->IsLoopHeader()); | 10036 ASSERT(!block->IsLoopHeader()); |
9819 ASSERT(values_.length() == other->values_.length()); | 10037 ASSERT(values_.length() == other->values_.length()); |
9820 | 10038 |
9821 int length = values_.length(); | 10039 int length = values_.length(); |
9822 for (int i = 0; i < length; ++i) { | 10040 for (int i = 0; i < length; ++i) { |
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
10348 } | 10566 } |
10349 } | 10567 } |
10350 | 10568 |
10351 #ifdef DEBUG | 10569 #ifdef DEBUG |
10352 if (graph_ != NULL) graph_->Verify(false); // No full verify. | 10570 if (graph_ != NULL) graph_->Verify(false); // No full verify. |
10353 if (allocator_ != NULL) allocator_->Verify(); | 10571 if (allocator_ != NULL) allocator_->Verify(); |
10354 #endif | 10572 #endif |
10355 } | 10573 } |
10356 | 10574 |
10357 } } // namespace v8::internal | 10575 } } // namespace v8::internal |
OLD | NEW |