Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Side by Side Diff: src/compiler/instruction.h

Issue 664683002: [turbofan] decouple register allocation from schedule and graph (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/compiler/instruction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 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 #ifndef V8_COMPILER_INSTRUCTION_H_ 5 #ifndef V8_COMPILER_INSTRUCTION_H_
6 #define V8_COMPILER_INSTRUCTION_H_ 6 #define V8_COMPILER_INSTRUCTION_H_
7 7
8 #include <deque> 8 #include <deque>
9 #include <iosfwd> 9 #include <iosfwd>
10 #include <map> 10 #include <map>
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 size_t parameters_count_; 746 size_t parameters_count_;
747 size_t locals_count_; 747 size_t locals_count_;
748 size_t stack_count_; 748 size_t stack_count_;
749 ZoneVector<MachineType> types_; 749 ZoneVector<MachineType> types_;
750 FrameStateDescriptor* outer_state_; 750 FrameStateDescriptor* outer_state_;
751 MaybeHandle<JSFunction> jsfunction_; 751 MaybeHandle<JSFunction> jsfunction_;
752 }; 752 };
753 753
754 std::ostream& operator<<(std::ostream& os, const Constant& constant); 754 std::ostream& operator<<(std::ostream& os, const Constant& constant);
755 755
756
757 // TODO(dcarney): this is a temporary hack. turn into an actual instruction.
758 class PhiInstruction : public ZoneObject {
759 public:
760 PhiInstruction(Zone* zone, int virtual_register)
761 : virtual_register_(virtual_register), operands_(zone) {}
762
763 int virtual_register() const { return virtual_register_; }
764 const IntVector& operands() const { return operands_; }
765 IntVector& operands() { return operands_; }
766
767 private:
768 const int virtual_register_;
769 IntVector operands_;
770 };
771
772
773 // Analogue of BasicBlock for Instructions instead of Nodes.
774 class InstructionBlock : public ZoneObject {
775 public:
776 explicit InstructionBlock(Zone* zone, const BasicBlock* block);
777
778 // Instruction indexes (used by the register allocator).
779 int first_instruction_index() const {
780 DCHECK(code_start_ >= 0);
781 DCHECK(code_end_ > 0);
782 DCHECK(code_end_ >= code_start_);
783 return code_start_;
784 }
785 int last_instruction_index() const {
786 DCHECK(code_start_ >= 0);
787 DCHECK(code_end_ > 0);
788 DCHECK(code_end_ >= code_start_);
789 return code_end_ - 1;
790 }
791
792 int32_t code_start() const { return code_start_; }
793 void set_code_start(int32_t start) { code_start_ = start; }
794
795 int32_t code_end() const { return code_end_; }
796 void set_code_end(int32_t end) { code_end_ = end; }
797
798 BasicBlock::RpoNumber rpo_number() const { return rpo_number_; }
799 BasicBlock::RpoNumber loop_header() const { return loop_header_; }
800 BasicBlock::RpoNumber loop_end() const {
801 DCHECK(IsLoopHeader());
802 return loop_end_;
803 }
804 inline bool IsLoopHeader() const { return loop_end_.IsValid(); }
805
806 typedef ZoneVector<BasicBlock::RpoNumber> Predecessors;
807 const Predecessors& predecessors() const { return predecessors_; }
808 size_t PredecessorCount() const { return predecessors_.size(); }
809 size_t PredecessorIndexOf(BasicBlock::RpoNumber rpo_number) const;
810
811 typedef ZoneVector<BasicBlock::RpoNumber> Successors;
812 const Successors& successors() const { return successors_; }
813 size_t SuccessorCount() const { return successors_.size(); }
814
815 typedef ZoneVector<PhiInstruction*> PhiInstructions;
816 const PhiInstructions& phis() const { return phis_; }
817 void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); }
818
819 private:
820 Successors successors_;
821 Predecessors predecessors_;
822 PhiInstructions phis_;
823 // TODO(dcarney): probably dont't need this.
824 BasicBlock::RpoNumber rpo_number_;
825 BasicBlock::RpoNumber loop_header_;
826 BasicBlock::RpoNumber loop_end_;
827 int32_t code_start_; // start index of arch-specific code.
828 int32_t code_end_; // end index of arch-specific code.
829 };
830
756 typedef ZoneDeque<Constant> ConstantDeque; 831 typedef ZoneDeque<Constant> ConstantDeque;
757 typedef std::map<int, Constant, std::less<int>, 832 typedef std::map<int, Constant, std::less<int>,
758 zone_allocator<std::pair<int, Constant> > > ConstantMap; 833 zone_allocator<std::pair<int, Constant> > > ConstantMap;
759 834
760 typedef ZoneDeque<Instruction*> InstructionDeque; 835 typedef ZoneDeque<Instruction*> InstructionDeque;
761 typedef ZoneDeque<PointerMap*> PointerMapDeque; 836 typedef ZoneDeque<PointerMap*> PointerMapDeque;
762 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; 837 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector;
838 typedef ZoneVector<InstructionBlock*> InstructionBlocks;
763 839
764 // Represents architecture-specific generated code before, during, and after 840 // Represents architecture-specific generated code before, during, and after
765 // register allocation. 841 // register allocation.
766 // TODO(titzer): s/IsDouble/IsFloat64/ 842 // TODO(titzer): s/IsDouble/IsFloat64/
767 class InstructionSequence FINAL { 843 class InstructionSequence FINAL {
768 public: 844 public:
769 InstructionSequence(Linkage* linkage, Graph* graph, Schedule* schedule); 845 InstructionSequence(Linkage* linkage, Graph* graph, Schedule* schedule);
770 846
771 int NextVirtualRegister() { return next_virtual_register_++; } 847 int NextVirtualRegister() { return next_virtual_register_++; }
772 int VirtualRegisterCount() const { return next_virtual_register_; } 848 int VirtualRegisterCount() const { return next_virtual_register_; }
773 849
774 int node_count() const { return node_count_; } 850 int node_count() const { return node_count_; }
775 851
776 int BasicBlockCount() const { 852 int BasicBlockCount() const {
777 return static_cast<int>(schedule_->rpo_order()->size()); 853 return static_cast<int>(instruction_blocks_.size());
778 } 854 }
779 855
780 BasicBlock* BlockAt(int rpo_number) const { 856 BasicBlock* BlockAt(int rpo_number) const {
781 return (*schedule_->rpo_order())[rpo_number]; 857 return (*schedule_->rpo_order())[rpo_number];
782 } 858 }
783 859
784 BasicBlock* GetContainingLoop(BasicBlock* block) { 860 InstructionBlock* InstructionBlockAt(BasicBlock::RpoNumber rpo_number) {
785 return block->loop_header(); 861 return GetBlock(rpo_number);
862 }
863
864 const InstructionBlock* InstructionBlockAt(
865 BasicBlock::RpoNumber rpo_number) const {
866 return GetBlock(rpo_number);
867 }
868
869 // TODO(dcarney): move to register allocator.
870 const InstructionBlock* GetContainingLoop(
871 const InstructionBlock* block) const {
872 BasicBlock::RpoNumber index = block->loop_header();
873 if (!index.IsValid()) return NULL;
874 return instruction_blocks_[index.ToInt()];
786 } 875 }
787 876
788 BasicBlock* GetBasicBlock(int instruction_index); 877 BasicBlock* GetBasicBlock(int instruction_index);
878 const InstructionBlock* GetInstructionBlock(int instruction_index) const;
789 879
790 int GetVirtualRegister(const Node* node); 880 int GetVirtualRegister(const Node* node);
791 // TODO(dcarney): find a way to remove this. 881 // TODO(dcarney): find a way to remove this.
792 const int* GetNodeMapForTesting() const { return node_map_; } 882 const int* GetNodeMapForTesting() const { return node_map_; }
793 883
794 bool IsReference(int virtual_register) const; 884 bool IsReference(int virtual_register) const;
795 bool IsDouble(int virtual_register) const; 885 bool IsDouble(int virtual_register) const;
796 886
797 void MarkAsReference(int virtual_register); 887 void MarkAsReference(int virtual_register);
798 void MarkAsDouble(int virtual_register); 888 void MarkAsDouble(int virtual_register);
(...skipping 22 matching lines...) Expand all
821 Linkage* linkage() const { return linkage_; } 911 Linkage* linkage() const { return linkage_; }
822 Schedule* schedule() const { return schedule_; } 912 Schedule* schedule() const { return schedule_; }
823 const PointerMapDeque* pointer_maps() const { return &pointer_maps_; } 913 const PointerMapDeque* pointer_maps() const { return &pointer_maps_; }
824 Zone* zone() const { return zone_; } 914 Zone* zone() const { return zone_; }
825 915
826 // Used by the instruction selector while adding instructions. 916 // Used by the instruction selector while adding instructions.
827 int AddInstruction(Instruction* instr); 917 int AddInstruction(Instruction* instr);
828 void StartBlock(BasicBlock* block); 918 void StartBlock(BasicBlock* block);
829 void EndBlock(BasicBlock* block); 919 void EndBlock(BasicBlock* block);
830 void set_code_start(BasicBlock* block, int start) { 920 void set_code_start(BasicBlock* block, int start) {
831 return GetBlockData(block->GetRpoNumber()).set_code_start(start); 921 return GetBlock(block->GetRpoNumber())->set_code_start(start);
832 } 922 }
833 void set_code_end(BasicBlock* block, int end) { 923 void set_code_end(BasicBlock* block, int end) {
834 return GetBlockData(block->GetRpoNumber()).set_code_end(end); 924 return GetBlock(block->GetRpoNumber())->set_code_end(end);
835 } 925 }
836 // TODO(dcarney): use RpoNumber for all of the below. 926 // TODO(dcarney): use RpoNumber for all of the below.
837 int code_start(BasicBlock::RpoNumber rpo_number) const { 927 int code_start(BasicBlock::RpoNumber rpo_number) const {
838 return GetBlockData(rpo_number).code_start(); 928 return GetBlock(rpo_number)->code_start();
839 } 929 }
840 int code_start(BasicBlock* block) const { 930 int code_start(BasicBlock* block) const {
841 return GetBlockData(block->GetRpoNumber()).code_start(); 931 return GetBlock(block->GetRpoNumber())->code_start();
842 } 932 }
843 int code_end(BasicBlock* block) const { 933 int code_end(BasicBlock* block) const {
844 return GetBlockData(block->GetRpoNumber()).code_end(); 934 return GetBlock(block->GetRpoNumber())->code_end();
845 } 935 }
846 int first_instruction_index(BasicBlock* block) const { 936 int first_instruction_index(BasicBlock* block) const {
847 return GetBlockData(block->GetRpoNumber()).first_instruction_index(); 937 return GetBlock(block->GetRpoNumber())->first_instruction_index();
848 } 938 }
849 int last_instruction_index(BasicBlock* block) const { 939 int last_instruction_index(BasicBlock* block) const {
850 return GetBlockData(block->GetRpoNumber()).last_instruction_index(); 940 return GetBlock(block->GetRpoNumber())->last_instruction_index();
941 }
942 int first_instruction_index(InstructionBlock* block) const {
943 return GetBlock(block->rpo_number())->first_instruction_index();
944 }
945 int last_instruction_index(InstructionBlock* block) const {
946 return GetBlock(block->rpo_number())->last_instruction_index();
851 } 947 }
852 948
853 int AddConstant(Node* node, Constant constant) { 949 int AddConstant(Node* node, Constant constant) {
854 int virtual_register = GetVirtualRegister(node); 950 int virtual_register = GetVirtualRegister(node);
855 DCHECK(constants_.find(virtual_register) == constants_.end()); 951 DCHECK(constants_.find(virtual_register) == constants_.end());
856 constants_.insert(std::make_pair(virtual_register, constant)); 952 constants_.insert(std::make_pair(virtual_register, constant));
857 return virtual_register; 953 return virtual_register;
858 } 954 }
859 Constant GetConstant(int virtual_register) const { 955 Constant GetConstant(int virtual_register) const {
860 ConstantMap::const_iterator it = constants_.find(virtual_register); 956 ConstantMap::const_iterator it = constants_.find(virtual_register);
(...skipping 24 matching lines...) Expand all
885 private: 981 private:
886 explicit StateId(int id) : id_(id) {} 982 explicit StateId(int id) : id_(id) {}
887 int id_; 983 int id_;
888 }; 984 };
889 985
890 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); 986 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor);
891 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); 987 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id);
892 int GetFrameStateDescriptorCount(); 988 int GetFrameStateDescriptorCount();
893 989
894 private: 990 private:
895 class BlockData { 991 InstructionBlock* GetBlock(BasicBlock::RpoNumber rpo_number) const {
896 public: 992 return instruction_blocks_[rpo_number.ToSize()];
897 BlockData() : code_start_(-1), code_end_(-1) {}
898 // Instruction indexes (used by the register allocator).
899 int first_instruction_index() const {
900 DCHECK(code_start_ >= 0);
901 DCHECK(code_end_ > 0);
902 DCHECK(code_end_ >= code_start_);
903 return code_start_;
904 }
905 int last_instruction_index() const {
906 DCHECK(code_start_ >= 0);
907 DCHECK(code_end_ > 0);
908 DCHECK(code_end_ >= code_start_);
909 return code_end_ - 1;
910 }
911
912 int32_t code_start() const { return code_start_; }
913 void set_code_start(int32_t start) { code_start_ = start; }
914
915 int32_t code_end() const { return code_end_; }
916 void set_code_end(int32_t end) { code_end_ = end; }
917
918 private:
919 int32_t code_start_; // start index of arch-specific code.
920 int32_t code_end_; // end index of arch-specific code.
921 };
922
923 const BlockData& GetBlockData(BasicBlock::RpoNumber rpo_number) const {
924 return block_data_[rpo_number.ToSize()];
925 }
926 BlockData& GetBlockData(BasicBlock::RpoNumber rpo_number) {
927 return block_data_[rpo_number.ToSize()];
928 } 993 }
929 994
930 friend std::ostream& operator<<(std::ostream& os, 995 friend std::ostream& operator<<(std::ostream& os,
931 const InstructionSequence& code); 996 const InstructionSequence& code);
932 997
933 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; 998 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet;
934 typedef ZoneVector<BlockData> BlockDataVector;
935 999
936 Zone* zone_; 1000 Zone* zone_;
937 int node_count_; 1001 int node_count_;
938 int* node_map_; 1002 int* node_map_;
939 BlockDataVector block_data_; 1003 InstructionBlocks instruction_blocks_;
940 Linkage* linkage_; 1004 Linkage* linkage_;
941 Schedule* schedule_; 1005 Schedule* schedule_;
942 ConstantMap constants_; 1006 ConstantMap constants_;
943 ConstantDeque immediates_; 1007 ConstantDeque immediates_;
944 InstructionDeque instructions_; 1008 InstructionDeque instructions_;
945 int next_virtual_register_; 1009 int next_virtual_register_;
946 PointerMapDeque pointer_maps_; 1010 PointerMapDeque pointer_maps_;
947 VirtualRegisterSet doubles_; 1011 VirtualRegisterSet doubles_;
948 VirtualRegisterSet references_; 1012 VirtualRegisterSet references_;
949 Frame frame_; 1013 Frame frame_;
950 DeoptimizationVector deoptimization_entries_; 1014 DeoptimizationVector deoptimization_entries_;
951 }; 1015 };
952 1016
953 std::ostream& operator<<(std::ostream& os, const InstructionSequence& code); 1017 std::ostream& operator<<(std::ostream& os, const InstructionSequence& code);
954 1018
955 } // namespace compiler 1019 } // namespace compiler
956 } // namespace internal 1020 } // namespace internal
957 } // namespace v8 1021 } // namespace v8
958 1022
959 #endif // V8_COMPILER_INSTRUCTION_H_ 1023 #endif // V8_COMPILER_INSTRUCTION_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler/instruction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698