| OLD | NEW |
| 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 824 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 }; | 835 }; |
| 836 | 836 |
| 837 typedef ZoneDeque<Constant> ConstantDeque; | 837 typedef ZoneDeque<Constant> ConstantDeque; |
| 838 typedef std::map<int, Constant, std::less<int>, | 838 typedef std::map<int, Constant, std::less<int>, |
| 839 zone_allocator<std::pair<int, Constant> > > ConstantMap; | 839 zone_allocator<std::pair<int, Constant> > > ConstantMap; |
| 840 | 840 |
| 841 typedef ZoneDeque<Instruction*> InstructionDeque; | 841 typedef ZoneDeque<Instruction*> InstructionDeque; |
| 842 typedef ZoneDeque<PointerMap*> PointerMapDeque; | 842 typedef ZoneDeque<PointerMap*> PointerMapDeque; |
| 843 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; | 843 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; |
| 844 typedef ZoneVector<InstructionBlock*> InstructionBlocks; | 844 typedef ZoneVector<InstructionBlock*> InstructionBlocks; |
| 845 typedef IntVector NodeToVregMap; | |
| 846 | 845 |
| 847 // Represents architecture-specific generated code before, during, and after | 846 // Represents architecture-specific generated code before, during, and after |
| 848 // register allocation. | 847 // register allocation. |
| 849 // TODO(titzer): s/IsDouble/IsFloat64/ | 848 // TODO(titzer): s/IsDouble/IsFloat64/ |
| 850 class InstructionSequence FINAL { | 849 class InstructionSequence FINAL { |
| 851 public: | 850 public: |
| 852 static const int kNodeUnmapped = -1; | 851 InstructionSequence(Zone* zone, const Schedule* schedule); |
| 853 | |
| 854 InstructionSequence(Zone* zone, const Graph* graph, const Schedule* schedule); | |
| 855 | 852 |
| 856 int NextVirtualRegister() { return next_virtual_register_++; } | 853 int NextVirtualRegister() { return next_virtual_register_++; } |
| 857 int VirtualRegisterCount() const { return next_virtual_register_; } | 854 int VirtualRegisterCount() const { return next_virtual_register_; } |
| 858 | 855 |
| 859 int node_count() const { return static_cast<int>(node_map_.size()); } | |
| 860 | |
| 861 const InstructionBlocks& instruction_blocks() const { | 856 const InstructionBlocks& instruction_blocks() const { |
| 862 return instruction_blocks_; | 857 return instruction_blocks_; |
| 863 } | 858 } |
| 864 | 859 |
| 865 int InstructionBlockCount() const { | 860 int InstructionBlockCount() const { |
| 866 return static_cast<int>(instruction_blocks_.size()); | 861 return static_cast<int>(instruction_blocks_.size()); |
| 867 } | 862 } |
| 868 | 863 |
| 869 InstructionBlock* InstructionBlockAt(BasicBlock::RpoNumber rpo_number) { | 864 InstructionBlock* InstructionBlockAt(BasicBlock::RpoNumber rpo_number) { |
| 870 return instruction_blocks_[rpo_number.ToSize()]; | 865 return instruction_blocks_[rpo_number.ToSize()]; |
| 871 } | 866 } |
| 872 | 867 |
| 873 int LastLoopInstructionIndex(const InstructionBlock* block) { | 868 int LastLoopInstructionIndex(const InstructionBlock* block) { |
| 874 return instruction_blocks_[block->loop_end().ToSize() - 1] | 869 return instruction_blocks_[block->loop_end().ToSize() - 1] |
| 875 ->last_instruction_index(); | 870 ->last_instruction_index(); |
| 876 } | 871 } |
| 877 | 872 |
| 878 const InstructionBlock* InstructionBlockAt( | 873 const InstructionBlock* InstructionBlockAt( |
| 879 BasicBlock::RpoNumber rpo_number) const { | 874 BasicBlock::RpoNumber rpo_number) const { |
| 880 return instruction_blocks_[rpo_number.ToSize()]; | 875 return instruction_blocks_[rpo_number.ToSize()]; |
| 881 } | 876 } |
| 882 | 877 |
| 883 const InstructionBlock* GetInstructionBlock(int instruction_index) const; | 878 const InstructionBlock* GetInstructionBlock(int instruction_index) const; |
| 884 | 879 |
| 885 int GetVirtualRegister(const Node* node); | |
| 886 const NodeToVregMap& GetNodeMapForTesting() const { return node_map_; } | |
| 887 | |
| 888 bool IsReference(int virtual_register) const; | 880 bool IsReference(int virtual_register) const; |
| 889 bool IsDouble(int virtual_register) const; | 881 bool IsDouble(int virtual_register) const; |
| 890 | 882 |
| 891 void MarkAsReference(int virtual_register); | 883 void MarkAsReference(int virtual_register); |
| 892 void MarkAsDouble(int virtual_register); | 884 void MarkAsDouble(int virtual_register); |
| 893 | 885 |
| 894 void AddGapMove(int index, InstructionOperand* from, InstructionOperand* to); | 886 void AddGapMove(int index, InstructionOperand* from, InstructionOperand* to); |
| 895 | 887 |
| 896 Label* GetLabel(BasicBlock::RpoNumber rpo); | 888 Label* GetLabel(BasicBlock::RpoNumber rpo); |
| 897 BlockStartInstruction* GetBlockStart(BasicBlock::RpoNumber rpo); | 889 BlockStartInstruction* GetBlockStart(BasicBlock::RpoNumber rpo); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 912 | 904 |
| 913 Isolate* isolate() const { return zone()->isolate(); } | 905 Isolate* isolate() const { return zone()->isolate(); } |
| 914 const PointerMapDeque* pointer_maps() const { return &pointer_maps_; } | 906 const PointerMapDeque* pointer_maps() const { return &pointer_maps_; } |
| 915 Zone* zone() const { return zone_; } | 907 Zone* zone() const { return zone_; } |
| 916 | 908 |
| 917 // Used by the instruction selector while adding instructions. | 909 // Used by the instruction selector while adding instructions. |
| 918 int AddInstruction(Instruction* instr); | 910 int AddInstruction(Instruction* instr); |
| 919 void StartBlock(BasicBlock* block); | 911 void StartBlock(BasicBlock* block); |
| 920 void EndBlock(BasicBlock* block); | 912 void EndBlock(BasicBlock* block); |
| 921 | 913 |
| 922 int AddConstant(Node* node, Constant constant) { | 914 int AddConstant(int virtual_register, Constant constant) { |
| 923 int virtual_register = GetVirtualRegister(node); | 915 DCHECK(virtual_register >= 0 && virtual_register < next_virtual_register_); |
| 924 DCHECK(constants_.find(virtual_register) == constants_.end()); | 916 DCHECK(constants_.find(virtual_register) == constants_.end()); |
| 925 constants_.insert(std::make_pair(virtual_register, constant)); | 917 constants_.insert(std::make_pair(virtual_register, constant)); |
| 926 return virtual_register; | 918 return virtual_register; |
| 927 } | 919 } |
| 928 Constant GetConstant(int virtual_register) const { | 920 Constant GetConstant(int virtual_register) const { |
| 929 ConstantMap::const_iterator it = constants_.find(virtual_register); | 921 ConstantMap::const_iterator it = constants_.find(virtual_register); |
| 930 DCHECK(it != constants_.end()); | 922 DCHECK(it != constants_.end()); |
| 931 DCHECK_EQ(virtual_register, it->first); | 923 DCHECK_EQ(virtual_register, it->first); |
| 932 return it->second; | 924 return it->second; |
| 933 } | 925 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 960 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); | 952 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); |
| 961 int GetFrameStateDescriptorCount(); | 953 int GetFrameStateDescriptorCount(); |
| 962 | 954 |
| 963 private: | 955 private: |
| 964 friend std::ostream& operator<<(std::ostream& os, | 956 friend std::ostream& operator<<(std::ostream& os, |
| 965 const InstructionSequence& code); | 957 const InstructionSequence& code); |
| 966 | 958 |
| 967 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; | 959 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; |
| 968 | 960 |
| 969 Zone* const zone_; | 961 Zone* const zone_; |
| 970 NodeToVregMap node_map_; | |
| 971 InstructionBlocks instruction_blocks_; | 962 InstructionBlocks instruction_blocks_; |
| 972 ConstantMap constants_; | 963 ConstantMap constants_; |
| 973 ConstantDeque immediates_; | 964 ConstantDeque immediates_; |
| 974 InstructionDeque instructions_; | 965 InstructionDeque instructions_; |
| 975 int next_virtual_register_; | 966 int next_virtual_register_; |
| 976 PointerMapDeque pointer_maps_; | 967 PointerMapDeque pointer_maps_; |
| 977 VirtualRegisterSet doubles_; | 968 VirtualRegisterSet doubles_; |
| 978 VirtualRegisterSet references_; | 969 VirtualRegisterSet references_; |
| 979 DeoptimizationVector deoptimization_entries_; | 970 DeoptimizationVector deoptimization_entries_; |
| 980 }; | 971 }; |
| 981 | 972 |
| 982 std::ostream& operator<<(std::ostream& os, const InstructionSequence& code); | 973 std::ostream& operator<<(std::ostream& os, const InstructionSequence& code); |
| 983 | 974 |
| 984 } // namespace compiler | 975 } // namespace compiler |
| 985 } // namespace internal | 976 } // namespace internal |
| 986 } // namespace v8 | 977 } // namespace v8 |
| 987 | 978 |
| 988 #endif // V8_COMPILER_INSTRUCTION_H_ | 979 #endif // V8_COMPILER_INSTRUCTION_H_ |
| OLD | NEW |