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> |
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/source-position.h" | 17 #include "src/compiler/source-position.h" |
18 #include "src/macro-assembler.h" | 18 #include "src/macro-assembler.h" |
19 #include "src/register-configuration.h" | 19 #include "src/register-configuration.h" |
20 #include "src/zone-allocator.h" | 20 #include "src/zone-allocator.h" |
21 | 21 |
22 namespace v8 { | 22 namespace v8 { |
23 namespace internal { | 23 namespace internal { |
24 namespace compiler { | 24 namespace compiler { |
25 | 25 |
| 26 // Forward declarations. |
26 class Schedule; | 27 class Schedule; |
27 | 28 |
| 29 |
28 class InstructionOperand { | 30 class InstructionOperand { |
29 public: | 31 public: |
30 static const int kInvalidVirtualRegister = -1; | 32 static const int kInvalidVirtualRegister = -1; |
31 | 33 |
32 // TODO(dcarney): recover bit. INVALID can be represented as UNALLOCATED with | 34 // TODO(dcarney): recover bit. INVALID can be represented as UNALLOCATED with |
33 // kInvalidVirtualRegister and some DCHECKS. | 35 // kInvalidVirtualRegister and some DCHECKS. |
34 enum Kind { INVALID, UNALLOCATED, CONSTANT, IMMEDIATE, EXPLICIT, ALLOCATED }; | 36 enum Kind { INVALID, UNALLOCATED, CONSTANT, IMMEDIATE, EXPLICIT, ALLOCATED }; |
35 | 37 |
36 InstructionOperand() : InstructionOperand(INVALID) {} | 38 InstructionOperand() : InstructionOperand(INVALID) {} |
37 | 39 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {} | 103 explicit InstructionOperand(Kind kind) : value_(KindField::encode(kind)) {} |
102 | 104 |
103 inline uint64_t GetCanonicalizedValue() const; | 105 inline uint64_t GetCanonicalizedValue() const; |
104 | 106 |
105 class KindField : public BitField64<Kind, 0, 3> {}; | 107 class KindField : public BitField64<Kind, 0, 3> {}; |
106 | 108 |
107 uint64_t value_; | 109 uint64_t value_; |
108 }; | 110 }; |
109 | 111 |
110 | 112 |
| 113 typedef ZoneVector<InstructionOperand> InstructionOperandVector; |
| 114 |
| 115 |
111 struct PrintableInstructionOperand { | 116 struct PrintableInstructionOperand { |
112 const RegisterConfiguration* register_configuration_; | 117 const RegisterConfiguration* register_configuration_; |
113 InstructionOperand op_; | 118 InstructionOperand op_; |
114 }; | 119 }; |
115 | 120 |
116 | 121 |
117 std::ostream& operator<<(std::ostream& os, | 122 std::ostream& operator<<(std::ostream& os, |
118 const PrintableInstructionOperand& op); | 123 const PrintableInstructionOperand& op); |
119 | 124 |
120 | 125 |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 DCHECK_EQ(kHeapObject, type()); | 939 DCHECK_EQ(kHeapObject, type()); |
935 return bit_cast<Handle<HeapObject> >(static_cast<intptr_t>(value_)); | 940 return bit_cast<Handle<HeapObject> >(static_cast<intptr_t>(value_)); |
936 } | 941 } |
937 | 942 |
938 private: | 943 private: |
939 Type type_; | 944 Type type_; |
940 int64_t value_; | 945 int64_t value_; |
941 }; | 946 }; |
942 | 947 |
943 | 948 |
| 949 std::ostream& operator<<(std::ostream& os, const Constant& constant); |
| 950 |
| 951 |
| 952 // Forward declarations. |
| 953 class FrameStateDescriptor; |
| 954 |
| 955 |
| 956 enum class StateValueKind { kPlain, kNested, kDuplicate }; |
| 957 |
| 958 |
| 959 class StateValueDescriptor { |
| 960 public: |
| 961 explicit StateValueDescriptor(Zone* zone) |
| 962 : kind_(StateValueKind::kPlain), |
| 963 type_(MachineType::AnyTagged()), |
| 964 id_(0), |
| 965 fields_(zone) {} |
| 966 |
| 967 static StateValueDescriptor Plain(Zone* zone, MachineType type) { |
| 968 return StateValueDescriptor(StateValueKind::kPlain, zone, type, 0); |
| 969 } |
| 970 static StateValueDescriptor Recursive(Zone* zone, size_t id) { |
| 971 return StateValueDescriptor(StateValueKind::kNested, zone, |
| 972 MachineType::AnyTagged(), id); |
| 973 } |
| 974 static StateValueDescriptor Duplicate(Zone* zone, size_t id) { |
| 975 return StateValueDescriptor(StateValueKind::kDuplicate, zone, |
| 976 MachineType::AnyTagged(), id); |
| 977 } |
| 978 |
| 979 size_t size() { return fields_.size(); } |
| 980 ZoneVector<StateValueDescriptor>& fields() { return fields_; } |
| 981 int IsPlain() { return kind_ == StateValueKind::kPlain; } |
| 982 int IsNested() { return kind_ == StateValueKind::kNested; } |
| 983 int IsDuplicate() { return kind_ == StateValueKind::kDuplicate; } |
| 984 MachineType type() const { return type_; } |
| 985 MachineType GetOperandType(size_t index) const { |
| 986 return fields_[index].type_; |
| 987 } |
| 988 size_t id() const { return id_; } |
| 989 |
| 990 private: |
| 991 StateValueDescriptor(StateValueKind kind, Zone* zone, MachineType type, |
| 992 size_t id) |
| 993 : kind_(kind), type_(type), id_(id), fields_(zone) {} |
| 994 |
| 995 StateValueKind kind_; |
| 996 MachineType type_; |
| 997 size_t id_; |
| 998 ZoneVector<StateValueDescriptor> fields_; |
| 999 }; |
| 1000 |
| 1001 |
944 class FrameStateDescriptor : public ZoneObject { | 1002 class FrameStateDescriptor : public ZoneObject { |
945 public: | 1003 public: |
946 FrameStateDescriptor(Zone* zone, FrameStateType type, BailoutId bailout_id, | 1004 FrameStateDescriptor(Zone* zone, FrameStateType type, BailoutId bailout_id, |
947 OutputFrameStateCombine state_combine, | 1005 OutputFrameStateCombine state_combine, |
948 size_t parameters_count, size_t locals_count, | 1006 size_t parameters_count, size_t locals_count, |
949 size_t stack_count, | 1007 size_t stack_count, |
950 MaybeHandle<SharedFunctionInfo> shared_info, | 1008 MaybeHandle<SharedFunctionInfo> shared_info, |
951 FrameStateDescriptor* outer_state = nullptr); | 1009 FrameStateDescriptor* outer_state = nullptr); |
952 | 1010 |
953 FrameStateType type() const { return type_; } | 1011 FrameStateType type() const { return type_; } |
954 BailoutId bailout_id() const { return bailout_id_; } | 1012 BailoutId bailout_id() const { return bailout_id_; } |
955 OutputFrameStateCombine state_combine() const { return frame_state_combine_; } | 1013 OutputFrameStateCombine state_combine() const { return frame_state_combine_; } |
956 size_t parameters_count() const { return parameters_count_; } | 1014 size_t parameters_count() const { return parameters_count_; } |
957 size_t locals_count() const { return locals_count_; } | 1015 size_t locals_count() const { return locals_count_; } |
958 size_t stack_count() const { return stack_count_; } | 1016 size_t stack_count() const { return stack_count_; } |
959 MaybeHandle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 1017 MaybeHandle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
960 FrameStateDescriptor* outer_state() const { return outer_state_; } | 1018 FrameStateDescriptor* outer_state() const { return outer_state_; } |
961 bool HasContext() const { | 1019 bool HasContext() const { |
962 return FrameStateFunctionInfo::IsJSFunctionType(type_); | 1020 return FrameStateFunctionInfo::IsJSFunctionType(type_); |
963 } | 1021 } |
964 | 1022 |
965 size_t GetSize(OutputFrameStateCombine combine = | 1023 size_t GetSize(OutputFrameStateCombine combine = |
966 OutputFrameStateCombine::Ignore()) const; | 1024 OutputFrameStateCombine::Ignore()) const; |
967 size_t GetTotalSize() const; | 1025 size_t GetTotalSize() const; |
968 size_t GetFrameCount() const; | 1026 size_t GetFrameCount() const; |
969 size_t GetJSFrameCount() const; | 1027 size_t GetJSFrameCount() const; |
970 | 1028 |
971 MachineType GetType(size_t index) const; | 1029 MachineType GetType(size_t index) const { |
972 void SetType(size_t index, MachineType type); | 1030 return values_.GetOperandType(index); |
| 1031 } |
| 1032 StateValueDescriptor* GetStateValueDescriptor() { return &values_; } |
973 | 1033 |
974 private: | 1034 private: |
975 FrameStateType type_; | 1035 FrameStateType type_; |
976 BailoutId bailout_id_; | 1036 BailoutId bailout_id_; |
977 OutputFrameStateCombine frame_state_combine_; | 1037 OutputFrameStateCombine frame_state_combine_; |
978 size_t parameters_count_; | 1038 size_t parameters_count_; |
979 size_t locals_count_; | 1039 size_t locals_count_; |
980 size_t stack_count_; | 1040 size_t stack_count_; |
981 ZoneVector<MachineType> types_; | 1041 StateValueDescriptor values_; |
982 MaybeHandle<SharedFunctionInfo> const shared_info_; | 1042 MaybeHandle<SharedFunctionInfo> const shared_info_; |
983 FrameStateDescriptor* outer_state_; | 1043 FrameStateDescriptor* outer_state_; |
984 }; | 1044 }; |
985 | 1045 |
986 std::ostream& operator<<(std::ostream& os, const Constant& constant); | 1046 |
| 1047 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; |
987 | 1048 |
988 | 1049 |
989 class PhiInstruction final : public ZoneObject { | 1050 class PhiInstruction final : public ZoneObject { |
990 public: | 1051 public: |
991 typedef ZoneVector<InstructionOperand> Inputs; | 1052 typedef ZoneVector<InstructionOperand> Inputs; |
992 | 1053 |
993 PhiInstruction(Zone* zone, int virtual_register, size_t input_count); | 1054 PhiInstruction(Zone* zone, int virtual_register, size_t input_count); |
994 | 1055 |
995 void SetInput(size_t offset, int virtual_register); | 1056 void SetInput(size_t offset, int virtual_register); |
996 | 1057 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1093 bool must_deconstruct_frame_; | 1154 bool must_deconstruct_frame_; |
1094 RpoNumber last_deferred_; | 1155 RpoNumber last_deferred_; |
1095 }; | 1156 }; |
1096 | 1157 |
1097 typedef ZoneDeque<Constant> ConstantDeque; | 1158 typedef ZoneDeque<Constant> ConstantDeque; |
1098 typedef std::map<int, Constant, std::less<int>, | 1159 typedef std::map<int, Constant, std::less<int>, |
1099 zone_allocator<std::pair<const int, Constant> > > ConstantMap; | 1160 zone_allocator<std::pair<const int, Constant> > > ConstantMap; |
1100 | 1161 |
1101 typedef ZoneDeque<Instruction*> InstructionDeque; | 1162 typedef ZoneDeque<Instruction*> InstructionDeque; |
1102 typedef ZoneDeque<ReferenceMap*> ReferenceMapDeque; | 1163 typedef ZoneDeque<ReferenceMap*> ReferenceMapDeque; |
1103 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; | |
1104 typedef ZoneVector<InstructionBlock*> InstructionBlocks; | 1164 typedef ZoneVector<InstructionBlock*> InstructionBlocks; |
1105 | 1165 |
| 1166 |
| 1167 // Forward declarations. |
1106 struct PrintableInstructionSequence; | 1168 struct PrintableInstructionSequence; |
1107 | 1169 |
1108 | 1170 |
1109 // Represents architecture-specific generated code before, during, and after | 1171 // Represents architecture-specific generated code before, during, and after |
1110 // register allocation. | 1172 // register allocation. |
1111 class InstructionSequence final : public ZoneObject { | 1173 class InstructionSequence final : public ZoneObject { |
1112 public: | 1174 public: |
1113 static InstructionBlocks* InstructionBlocksFor(Zone* zone, | 1175 static InstructionBlocks* InstructionBlocksFor(Zone* zone, |
1114 const Schedule* schedule); | 1176 const Schedule* schedule); |
1115 // Puts the deferred blocks last. | 1177 // Puts the deferred blocks last. |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 | 1349 |
1288 | 1350 |
1289 std::ostream& operator<<(std::ostream& os, | 1351 std::ostream& operator<<(std::ostream& os, |
1290 const PrintableInstructionSequence& code); | 1352 const PrintableInstructionSequence& code); |
1291 | 1353 |
1292 } // namespace compiler | 1354 } // namespace compiler |
1293 } // namespace internal | 1355 } // namespace internal |
1294 } // namespace v8 | 1356 } // namespace v8 |
1295 | 1357 |
1296 #endif // V8_COMPILER_INSTRUCTION_H_ | 1358 #endif // V8_COMPILER_INSTRUCTION_H_ |
OLD | NEW |