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

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

Issue 951553005: [turbofan] remove dependence of InstructionBlock on BasicBlock (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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
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>
11 #include <set> 11 #include <set>
12 12
13 #include "src/compiler/common-operator.h" 13 #include "src/compiler/common-operator.h"
14 #include "src/compiler/frame.h" 14 #include "src/compiler/frame.h"
15 #include "src/compiler/instruction-codes.h" 15 #include "src/compiler/instruction-codes.h"
16 #include "src/compiler/opcodes.h" 16 #include "src/compiler/opcodes.h"
17 #include "src/compiler/register-configuration.h" 17 #include "src/compiler/register-configuration.h"
18 #include "src/compiler/schedule.h"
19 #include "src/compiler/source-position.h" 18 #include "src/compiler/source-position.h"
20 #include "src/zone-allocator.h" 19 #include "src/zone-allocator.h"
21 20
22 namespace v8 { 21 namespace v8 {
23 namespace internal { 22 namespace internal {
24 namespace compiler { 23 namespace compiler {
25 24
25 class Schedule;
26
26 // A couple of reserved opcodes are used for internal use. 27 // A couple of reserved opcodes are used for internal use.
27 const InstructionCode kGapInstruction = -1; 28 const InstructionCode kGapInstruction = -1;
28 const InstructionCode kSourcePositionInstruction = -2; 29 const InstructionCode kSourcePositionInstruction = -2;
29 30
30 #define INSTRUCTION_OPERAND_LIST(V) \ 31 #define INSTRUCTION_OPERAND_LIST(V) \
31 V(Constant, CONSTANT) \ 32 V(Constant, CONSTANT) \
32 V(Immediate, IMMEDIATE) \ 33 V(Immediate, IMMEDIATE) \
33 V(StackSlot, STACK_SLOT) \ 34 V(StackSlot, STACK_SLOT) \
34 V(DoubleStackSlot, DOUBLE_STACK_SLOT) \ 35 V(DoubleStackSlot, DOUBLE_STACK_SLOT) \
35 V(Register, REGISTER) \ 36 V(Register, REGISTER) \
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 : Instruction(kSourcePositionInstruction), 685 : Instruction(kSourcePositionInstruction),
685 source_position_(source_position) { 686 source_position_(source_position) {
686 DCHECK(!source_position_.IsInvalid()); 687 DCHECK(!source_position_.IsInvalid());
687 DCHECK(!source_position_.IsUnknown()); 688 DCHECK(!source_position_.IsUnknown());
688 } 689 }
689 690
690 SourcePosition source_position_; 691 SourcePosition source_position_;
691 }; 692 };
692 693
693 694
695 // TODO(dcarney): remove this class and just use an uint32_t.
Michael Starzinger 2015/02/25 14:59:37 suggestion: Not sure about this TODO, better ask B
dcarney 2015/02/25 16:08:25 removed TODO for now.
696 class RpoNumber FINAL {
697 public:
698 static const int kInvalidRpoNumber = -1;
699 int ToInt() const {
700 DCHECK(IsValid());
701 return index_;
702 }
703 size_t ToSize() const {
704 DCHECK(IsValid());
705 return static_cast<size_t>(index_);
706 }
707 bool IsValid() const { return index_ >= 0; }
708 static RpoNumber FromInt(int index) { return RpoNumber(index); }
709 static RpoNumber Invalid() { return RpoNumber(kInvalidRpoNumber); }
710
711 bool IsNext(const RpoNumber other) const {
712 DCHECK(IsValid());
713 return other.index_ == this->index_ + 1;
714 }
715
716 bool operator==(RpoNumber other) const {
717 return this->index_ == other.index_;
718 }
719
720 private:
721 explicit RpoNumber(int32_t index) : index_(index) {}
722 int32_t index_;
723 };
724
725
726 std::ostream& operator<<(std::ostream&, const RpoNumber&);
727
728
694 class Constant FINAL { 729 class Constant FINAL {
695 public: 730 public:
696 enum Type { 731 enum Type {
697 kInt32, 732 kInt32,
698 kInt64, 733 kInt64,
699 kFloat32, 734 kFloat32,
700 kFloat64, 735 kFloat64,
701 kExternalReference, 736 kExternalReference,
702 kHeapObject, 737 kHeapObject,
703 kRpoNumber 738 kRpoNumber
704 }; 739 };
705 740
706 explicit Constant(int32_t v) : type_(kInt32), value_(v) {} 741 explicit Constant(int32_t v) : type_(kInt32), value_(v) {}
707 explicit Constant(int64_t v) : type_(kInt64), value_(v) {} 742 explicit Constant(int64_t v) : type_(kInt64), value_(v) {}
708 explicit Constant(float v) : type_(kFloat32), value_(bit_cast<int32_t>(v)) {} 743 explicit Constant(float v) : type_(kFloat32), value_(bit_cast<int32_t>(v)) {}
709 explicit Constant(double v) : type_(kFloat64), value_(bit_cast<int64_t>(v)) {} 744 explicit Constant(double v) : type_(kFloat64), value_(bit_cast<int64_t>(v)) {}
710 explicit Constant(ExternalReference ref) 745 explicit Constant(ExternalReference ref)
711 : type_(kExternalReference), value_(bit_cast<intptr_t>(ref)) {} 746 : type_(kExternalReference), value_(bit_cast<intptr_t>(ref)) {}
712 explicit Constant(Handle<HeapObject> obj) 747 explicit Constant(Handle<HeapObject> obj)
713 : type_(kHeapObject), value_(bit_cast<intptr_t>(obj)) {} 748 : type_(kHeapObject), value_(bit_cast<intptr_t>(obj)) {}
714 explicit Constant(BasicBlock::RpoNumber rpo) 749 explicit Constant(RpoNumber rpo) : type_(kRpoNumber), value_(rpo.ToInt()) {}
715 : type_(kRpoNumber), value_(rpo.ToInt()) {}
716 750
717 Type type() const { return type_; } 751 Type type() const { return type_; }
718 752
719 int32_t ToInt32() const { 753 int32_t ToInt32() const {
720 DCHECK(type() == kInt32 || type() == kInt64); 754 DCHECK(type() == kInt32 || type() == kInt64);
721 const int32_t value = static_cast<int32_t>(value_); 755 const int32_t value = static_cast<int32_t>(value_);
722 DCHECK_EQ(value_, static_cast<int64_t>(value)); 756 DCHECK_EQ(value_, static_cast<int64_t>(value));
723 return value; 757 return value;
724 } 758 }
725 759
(...skipping 12 matching lines...) Expand all
738 if (type() == kInt32) return ToInt32(); 772 if (type() == kInt32) return ToInt32();
739 DCHECK_EQ(kFloat64, type()); 773 DCHECK_EQ(kFloat64, type());
740 return bit_cast<double>(value_); 774 return bit_cast<double>(value_);
741 } 775 }
742 776
743 ExternalReference ToExternalReference() const { 777 ExternalReference ToExternalReference() const {
744 DCHECK_EQ(kExternalReference, type()); 778 DCHECK_EQ(kExternalReference, type());
745 return bit_cast<ExternalReference>(static_cast<intptr_t>(value_)); 779 return bit_cast<ExternalReference>(static_cast<intptr_t>(value_));
746 } 780 }
747 781
748 BasicBlock::RpoNumber ToRpoNumber() const { 782 RpoNumber ToRpoNumber() const {
749 DCHECK_EQ(kRpoNumber, type()); 783 DCHECK_EQ(kRpoNumber, type());
750 return BasicBlock::RpoNumber::FromInt(static_cast<int>(value_)); 784 return RpoNumber::FromInt(static_cast<int>(value_));
751 } 785 }
752 786
753 Handle<HeapObject> ToHeapObject() const { 787 Handle<HeapObject> ToHeapObject() const {
754 DCHECK_EQ(kHeapObject, type()); 788 DCHECK_EQ(kHeapObject, type());
755 return bit_cast<Handle<HeapObject> >(static_cast<intptr_t>(value_)); 789 return bit_cast<Handle<HeapObject> >(static_cast<intptr_t>(value_));
756 } 790 }
757 791
758 private: 792 private:
759 Type type_; 793 Type type_;
760 int64_t value_; 794 int64_t value_;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 const int virtual_register_; 858 const int virtual_register_;
825 InstructionOperand output_; 859 InstructionOperand output_;
826 IntVector operands_; 860 IntVector operands_;
827 Inputs inputs_; 861 Inputs inputs_;
828 }; 862 };
829 863
830 864
831 // Analogue of BasicBlock for Instructions instead of Nodes. 865 // Analogue of BasicBlock for Instructions instead of Nodes.
832 class InstructionBlock FINAL : public ZoneObject { 866 class InstructionBlock FINAL : public ZoneObject {
833 public: 867 public:
834 InstructionBlock(Zone* zone, BasicBlock::Id id, 868 InstructionBlock(Zone* zone, RpoNumber rpo_number, RpoNumber loop_header,
835 BasicBlock::RpoNumber rpo_number, 869 RpoNumber loop_end, bool deferred);
836 BasicBlock::RpoNumber loop_header,
837 BasicBlock::RpoNumber loop_end, bool deferred);
838 870
839 // Instruction indexes (used by the register allocator). 871 // Instruction indexes (used by the register allocator).
840 int first_instruction_index() const { 872 int first_instruction_index() const {
841 DCHECK(code_start_ >= 0); 873 DCHECK(code_start_ >= 0);
842 DCHECK(code_end_ > 0); 874 DCHECK(code_end_ > 0);
843 DCHECK(code_end_ >= code_start_); 875 DCHECK(code_end_ >= code_start_);
844 return code_start_; 876 return code_start_;
845 } 877 }
846 int last_instruction_index() const { 878 int last_instruction_index() const {
847 DCHECK(code_start_ >= 0); 879 DCHECK(code_start_ >= 0);
848 DCHECK(code_end_ > 0); 880 DCHECK(code_end_ > 0);
849 DCHECK(code_end_ >= code_start_); 881 DCHECK(code_end_ >= code_start_);
850 return code_end_ - 1; 882 return code_end_ - 1;
851 } 883 }
852 884
853 int32_t code_start() const { return code_start_; } 885 int32_t code_start() const { return code_start_; }
854 void set_code_start(int32_t start) { code_start_ = start; } 886 void set_code_start(int32_t start) { code_start_ = start; }
855 887
856 int32_t code_end() const { return code_end_; } 888 int32_t code_end() const { return code_end_; }
857 void set_code_end(int32_t end) { code_end_ = end; } 889 void set_code_end(int32_t end) { code_end_ = end; }
858 890
859 bool IsDeferred() const { return deferred_; } 891 bool IsDeferred() const { return deferred_; }
860 892
861 BasicBlock::Id id() const { return id_; } 893 RpoNumber ao_number() const { return ao_number_; }
862 BasicBlock::RpoNumber ao_number() const { return ao_number_; } 894 RpoNumber rpo_number() const { return rpo_number_; }
863 BasicBlock::RpoNumber rpo_number() const { return rpo_number_; } 895 RpoNumber loop_header() const { return loop_header_; }
864 BasicBlock::RpoNumber loop_header() const { return loop_header_; } 896 RpoNumber loop_end() const {
865 BasicBlock::RpoNumber loop_end() const {
866 DCHECK(IsLoopHeader()); 897 DCHECK(IsLoopHeader());
867 return loop_end_; 898 return loop_end_;
868 } 899 }
869 inline bool IsLoopHeader() const { return loop_end_.IsValid(); } 900 inline bool IsLoopHeader() const { return loop_end_.IsValid(); }
870 901
871 typedef ZoneVector<BasicBlock::RpoNumber> Predecessors; 902 typedef ZoneVector<RpoNumber> Predecessors;
872 Predecessors& predecessors() { return predecessors_; } 903 Predecessors& predecessors() { return predecessors_; }
873 const Predecessors& predecessors() const { return predecessors_; } 904 const Predecessors& predecessors() const { return predecessors_; }
874 size_t PredecessorCount() const { return predecessors_.size(); } 905 size_t PredecessorCount() const { return predecessors_.size(); }
875 size_t PredecessorIndexOf(BasicBlock::RpoNumber rpo_number) const; 906 size_t PredecessorIndexOf(RpoNumber rpo_number) const;
876 907
877 typedef ZoneVector<BasicBlock::RpoNumber> Successors; 908 typedef ZoneVector<RpoNumber> Successors;
878 Successors& successors() { return successors_; } 909 Successors& successors() { return successors_; }
879 const Successors& successors() const { return successors_; } 910 const Successors& successors() const { return successors_; }
880 size_t SuccessorCount() const { return successors_.size(); } 911 size_t SuccessorCount() const { return successors_.size(); }
881 912
882 typedef ZoneVector<PhiInstruction*> PhiInstructions; 913 typedef ZoneVector<PhiInstruction*> PhiInstructions;
883 const PhiInstructions& phis() const { return phis_; } 914 const PhiInstructions& phis() const { return phis_; }
884 void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); } 915 void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); }
885 916
886 void set_ao_number(BasicBlock::RpoNumber ao_number) { 917 void set_ao_number(RpoNumber ao_number) { ao_number_ = ao_number; }
887 ao_number_ = ao_number;
888 }
889 918
890 private: 919 private:
891 Successors successors_; 920 Successors successors_;
892 Predecessors predecessors_; 921 Predecessors predecessors_;
893 PhiInstructions phis_; 922 PhiInstructions phis_;
894 const BasicBlock::Id id_; 923 RpoNumber ao_number_; // Assembly order number.
895 BasicBlock::RpoNumber ao_number_; // Assembly order number. 924 const RpoNumber rpo_number_;
896 const BasicBlock::RpoNumber rpo_number_; 925 const RpoNumber loop_header_;
897 const BasicBlock::RpoNumber loop_header_; 926 const RpoNumber loop_end_;
898 const BasicBlock::RpoNumber loop_end_;
899 int32_t code_start_; // start index of arch-specific code. 927 int32_t code_start_; // start index of arch-specific code.
900 int32_t code_end_; // end index of arch-specific code. 928 int32_t code_end_; // end index of arch-specific code.
901 const bool deferred_; // Block contains deferred code. 929 const bool deferred_; // Block contains deferred code.
902 }; 930 };
903 931
904 typedef ZoneDeque<Constant> ConstantDeque; 932 typedef ZoneDeque<Constant> ConstantDeque;
905 typedef std::map<int, Constant, std::less<int>, 933 typedef std::map<int, Constant, std::less<int>,
906 zone_allocator<std::pair<int, Constant> > > ConstantMap; 934 zone_allocator<std::pair<int, Constant> > > ConstantMap;
907 935
908 typedef ZoneDeque<Instruction*> InstructionDeque; 936 typedef ZoneDeque<Instruction*> InstructionDeque;
(...skipping 21 matching lines...) Expand all
930 int VirtualRegisterCount() const { return next_virtual_register_; } 958 int VirtualRegisterCount() const { return next_virtual_register_; }
931 959
932 const InstructionBlocks& instruction_blocks() const { 960 const InstructionBlocks& instruction_blocks() const {
933 return *instruction_blocks_; 961 return *instruction_blocks_;
934 } 962 }
935 963
936 int InstructionBlockCount() const { 964 int InstructionBlockCount() const {
937 return static_cast<int>(instruction_blocks_->size()); 965 return static_cast<int>(instruction_blocks_->size());
938 } 966 }
939 967
940 InstructionBlock* InstructionBlockAt(BasicBlock::RpoNumber rpo_number) { 968 InstructionBlock* InstructionBlockAt(RpoNumber rpo_number) {
941 return instruction_blocks_->at(rpo_number.ToSize()); 969 return instruction_blocks_->at(rpo_number.ToSize());
942 } 970 }
943 971
944 int LastLoopInstructionIndex(const InstructionBlock* block) { 972 int LastLoopInstructionIndex(const InstructionBlock* block) {
945 return instruction_blocks_->at(block->loop_end().ToSize() - 1) 973 return instruction_blocks_->at(block->loop_end().ToSize() - 1)
946 ->last_instruction_index(); 974 ->last_instruction_index();
947 } 975 }
948 976
949 const InstructionBlock* InstructionBlockAt( 977 const InstructionBlock* InstructionBlockAt(RpoNumber rpo_number) const {
950 BasicBlock::RpoNumber rpo_number) const {
951 return instruction_blocks_->at(rpo_number.ToSize()); 978 return instruction_blocks_->at(rpo_number.ToSize());
952 } 979 }
953 980
954 const InstructionBlock* GetInstructionBlock(int instruction_index) const; 981 const InstructionBlock* GetInstructionBlock(int instruction_index) const;
955 982
956 bool IsReference(int virtual_register) const; 983 bool IsReference(int virtual_register) const;
957 bool IsDouble(int virtual_register) const; 984 bool IsDouble(int virtual_register) const;
958 985
959 void MarkAsReference(int virtual_register); 986 void MarkAsReference(int virtual_register);
960 void MarkAsDouble(int virtual_register); 987 void MarkAsDouble(int virtual_register);
961 988
962 void AddGapMove(int index, InstructionOperand* from, InstructionOperand* to); 989 void AddGapMove(int index, InstructionOperand* from, InstructionOperand* to);
963 990
964 GapInstruction* GetBlockStart(BasicBlock::RpoNumber rpo) const; 991 GapInstruction* GetBlockStart(RpoNumber rpo) const;
965 992
966 typedef InstructionDeque::const_iterator const_iterator; 993 typedef InstructionDeque::const_iterator const_iterator;
967 const_iterator begin() const { return instructions_.begin(); } 994 const_iterator begin() const { return instructions_.begin(); }
968 const_iterator end() const { return instructions_.end(); } 995 const_iterator end() const { return instructions_.end(); }
969 const InstructionDeque& instructions() const { return instructions_; } 996 const InstructionDeque& instructions() const { return instructions_; }
970 997
971 GapInstruction* GapAt(int index) const { 998 GapInstruction* GapAt(int index) const {
972 return GapInstruction::cast(InstructionAt(index)); 999 return GapInstruction::cast(InstructionAt(index));
973 } 1000 }
974 bool IsGapAt(int index) const { return InstructionAt(index)->IsGapMoves(); } 1001 bool IsGapAt(int index) const { return InstructionAt(index)->IsGapMoves(); }
975 Instruction* InstructionAt(int index) const { 1002 Instruction* InstructionAt(int index) const {
976 DCHECK(index >= 0); 1003 DCHECK(index >= 0);
977 DCHECK(index < static_cast<int>(instructions_.size())); 1004 DCHECK(index < static_cast<int>(instructions_.size()));
978 return instructions_[index]; 1005 return instructions_[index];
979 } 1006 }
980 1007
981 Isolate* isolate() const { return isolate_; } 1008 Isolate* isolate() const { return isolate_; }
982 const PointerMapDeque* pointer_maps() const { return &pointer_maps_; } 1009 const PointerMapDeque* pointer_maps() const { return &pointer_maps_; }
983 Zone* zone() const { return zone_; } 1010 Zone* zone() const { return zone_; }
984 1011
985 // Used by the instruction selector while adding instructions. 1012 // Used by the instruction selector while adding instructions.
986 int AddInstruction(Instruction* instr); 1013 int AddInstruction(Instruction* instr);
987 void StartBlock(BasicBlock::RpoNumber rpo); 1014 void StartBlock(RpoNumber rpo);
988 void EndBlock(BasicBlock::RpoNumber rpo); 1015 void EndBlock(RpoNumber rpo);
989 1016
990 int AddConstant(int virtual_register, Constant constant) { 1017 int AddConstant(int virtual_register, Constant constant) {
991 // TODO(titzer): allow RPO numbers as constants? 1018 // TODO(titzer): allow RPO numbers as constants?
992 DCHECK(constant.type() != Constant::kRpoNumber); 1019 DCHECK(constant.type() != Constant::kRpoNumber);
993 DCHECK(virtual_register >= 0 && virtual_register < next_virtual_register_); 1020 DCHECK(virtual_register >= 0 && virtual_register < next_virtual_register_);
994 DCHECK(constants_.find(virtual_register) == constants_.end()); 1021 DCHECK(constants_.find(virtual_register) == constants_.end());
995 constants_.insert(std::make_pair(virtual_register, constant)); 1022 constants_.insert(std::make_pair(virtual_register, constant));
996 return virtual_register; 1023 return virtual_register;
997 } 1024 }
998 Constant GetConstant(int virtual_register) const { 1025 Constant GetConstant(int virtual_register) const {
(...skipping 24 matching lines...) Expand all
1023 1050
1024 private: 1051 private:
1025 explicit StateId(int id) : id_(id) {} 1052 explicit StateId(int id) : id_(id) {}
1026 int id_; 1053 int id_;
1027 }; 1054 };
1028 1055
1029 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); 1056 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor);
1030 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); 1057 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id);
1031 int GetFrameStateDescriptorCount(); 1058 int GetFrameStateDescriptorCount();
1032 1059
1033 BasicBlock::RpoNumber InputRpo(Instruction* instr, size_t index) { 1060 RpoNumber InputRpo(Instruction* instr, size_t index) {
1034 InstructionOperand* operand = instr->InputAt(index); 1061 InstructionOperand* operand = instr->InputAt(index);
1035 Constant constant = operand->IsImmediate() ? GetImmediate(operand->index()) 1062 Constant constant = operand->IsImmediate() ? GetImmediate(operand->index())
1036 : GetConstant(operand->index()); 1063 : GetConstant(operand->index());
1037 return constant.ToRpoNumber(); 1064 return constant.ToRpoNumber();
1038 } 1065 }
1039 1066
1040 private: 1067 private:
1041 friend std::ostream& operator<<(std::ostream& os, 1068 friend std::ostream& operator<<(std::ostream& os,
1042 const PrintableInstructionSequence& code); 1069 const PrintableInstructionSequence& code);
1043 1070
(...skipping 23 matching lines...) Expand all
1067 1094
1068 1095
1069 std::ostream& operator<<(std::ostream& os, 1096 std::ostream& operator<<(std::ostream& os,
1070 const PrintableInstructionSequence& code); 1097 const PrintableInstructionSequence& code);
1071 1098
1072 } // namespace compiler 1099 } // namespace compiler
1073 } // namespace internal 1100 } // namespace internal
1074 } // namespace v8 1101 } // namespace v8
1075 1102
1076 #endif // V8_COMPILER_INSTRUCTION_H_ 1103 #endif // V8_COMPILER_INSTRUCTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698