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 1086 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 #endif | 1097 #endif |
1098 }; | 1098 }; |
1099 | 1099 |
1100 | 1100 |
1101 std::ostream& operator<<(std::ostream& os, const Constant& constant); | 1101 std::ostream& operator<<(std::ostream& os, const Constant& constant); |
1102 | 1102 |
1103 | 1103 |
1104 // Forward declarations. | 1104 // Forward declarations. |
1105 class FrameStateDescriptor; | 1105 class FrameStateDescriptor; |
1106 | 1106 |
1107 | 1107 enum class StateValueKind : uint8_t { |
1108 enum class StateValueKind { kPlain, kNested, kDuplicate }; | 1108 kPlain, |
1109 | 1109 kOptimizedOut, |
| 1110 kNested, |
| 1111 kDuplicate |
| 1112 }; |
1110 | 1113 |
1111 class StateValueDescriptor { | 1114 class StateValueDescriptor { |
1112 public: | 1115 public: |
1113 explicit StateValueDescriptor(Zone* zone) | 1116 StateValueDescriptor() |
1114 : kind_(StateValueKind::kPlain), | 1117 : kind_(StateValueKind::kPlain), |
1115 type_(MachineType::AnyTagged()), | 1118 type_(MachineType::AnyTagged()), |
1116 id_(0), | 1119 id_(0) {} |
1117 fields_(zone) {} | |
1118 | 1120 |
1119 static StateValueDescriptor Plain(Zone* zone, MachineType type) { | 1121 static StateValueDescriptor Plain(MachineType type) { |
1120 return StateValueDescriptor(StateValueKind::kPlain, zone, type, 0); | 1122 return StateValueDescriptor(StateValueKind::kPlain, type, 0); |
1121 } | 1123 } |
1122 static StateValueDescriptor Recursive(Zone* zone, size_t id) { | 1124 static StateValueDescriptor OptimizedOut() { |
1123 return StateValueDescriptor(StateValueKind::kNested, zone, | 1125 return StateValueDescriptor(StateValueKind::kOptimizedOut, |
| 1126 MachineType::AnyTagged(), 0); |
| 1127 } |
| 1128 static StateValueDescriptor Recursive(size_t id) { |
| 1129 return StateValueDescriptor(StateValueKind::kNested, |
1124 MachineType::AnyTagged(), id); | 1130 MachineType::AnyTagged(), id); |
1125 } | 1131 } |
1126 static StateValueDescriptor Duplicate(Zone* zone, size_t id) { | 1132 static StateValueDescriptor Duplicate(size_t id) { |
1127 return StateValueDescriptor(StateValueKind::kDuplicate, zone, | 1133 return StateValueDescriptor(StateValueKind::kDuplicate, |
1128 MachineType::AnyTagged(), id); | 1134 MachineType::AnyTagged(), id); |
1129 } | 1135 } |
1130 | 1136 |
1131 size_t size() { return fields_.size(); } | |
1132 ZoneVector<StateValueDescriptor>& fields() { return fields_; } | |
1133 int IsPlain() { return kind_ == StateValueKind::kPlain; } | 1137 int IsPlain() { return kind_ == StateValueKind::kPlain; } |
| 1138 int IsOptimizedOut() { return kind_ == StateValueKind::kOptimizedOut; } |
1134 int IsNested() { return kind_ == StateValueKind::kNested; } | 1139 int IsNested() { return kind_ == StateValueKind::kNested; } |
1135 int IsDuplicate() { return kind_ == StateValueKind::kDuplicate; } | 1140 int IsDuplicate() { return kind_ == StateValueKind::kDuplicate; } |
1136 MachineType type() const { return type_; } | 1141 MachineType type() const { return type_; } |
1137 MachineType GetOperandType(size_t index) const { | |
1138 return fields_[index].type_; | |
1139 } | |
1140 size_t id() const { return id_; } | 1142 size_t id() const { return id_; } |
1141 | 1143 |
1142 private: | 1144 private: |
1143 StateValueDescriptor(StateValueKind kind, Zone* zone, MachineType type, | 1145 StateValueDescriptor(StateValueKind kind, MachineType type, size_t id) |
1144 size_t id) | 1146 : kind_(kind), type_(type), id_(id) {} |
1145 : kind_(kind), type_(type), id_(id), fields_(zone) {} | |
1146 | 1147 |
1147 StateValueKind kind_; | 1148 StateValueKind kind_; |
1148 MachineType type_; | 1149 MachineType type_; |
1149 size_t id_; | 1150 size_t id_; |
1150 ZoneVector<StateValueDescriptor> fields_; | |
1151 }; | 1151 }; |
1152 | 1152 |
| 1153 class StateValueList { |
| 1154 public: |
| 1155 explicit StateValueList(Zone* zone) : fields_(zone), nested_(zone) {} |
| 1156 |
| 1157 size_t size() { return fields_.size(); } |
| 1158 |
| 1159 struct Value { |
| 1160 StateValueDescriptor* desc; |
| 1161 StateValueList* nested; |
| 1162 |
| 1163 Value(StateValueDescriptor* desc, StateValueList* nested) |
| 1164 : desc(desc), nested(nested) {} |
| 1165 }; |
| 1166 |
| 1167 class iterator { |
| 1168 public: |
| 1169 // Bare minimum of operators needed for range iteration. |
| 1170 bool operator!=(const iterator& other) const { |
| 1171 return field_iterator != other.field_iterator; |
| 1172 } |
| 1173 bool operator==(const iterator& other) const { |
| 1174 return field_iterator == other.field_iterator; |
| 1175 } |
| 1176 iterator& operator++() { |
| 1177 if (field_iterator->IsNested()) { |
| 1178 nested_iterator++; |
| 1179 } |
| 1180 ++field_iterator; |
| 1181 return *this; |
| 1182 } |
| 1183 Value operator*() { |
| 1184 StateValueDescriptor* desc = &(*field_iterator); |
| 1185 StateValueList* nested = desc->IsNested() ? *nested_iterator : nullptr; |
| 1186 return Value(desc, nested); |
| 1187 } |
| 1188 |
| 1189 private: |
| 1190 friend class StateValueList; |
| 1191 |
| 1192 iterator(ZoneVector<StateValueDescriptor>::iterator it, |
| 1193 ZoneVector<StateValueList*>::iterator nested) |
| 1194 : field_iterator(it), nested_iterator(nested) {} |
| 1195 |
| 1196 ZoneVector<StateValueDescriptor>::iterator field_iterator; |
| 1197 ZoneVector<StateValueList*>::iterator nested_iterator; |
| 1198 }; |
| 1199 |
| 1200 StateValueList* PushRecursiveField(Zone* zone, size_t id) { |
| 1201 fields_.push_back(StateValueDescriptor::Recursive(id)); |
| 1202 StateValueList* nested = |
| 1203 new (zone->New(sizeof(StateValueList))) StateValueList(zone); |
| 1204 nested_.push_back(nested); |
| 1205 return nested; |
| 1206 } |
| 1207 void PushDuplicate(size_t id) { |
| 1208 fields_.push_back(StateValueDescriptor::Duplicate(id)); |
| 1209 } |
| 1210 void PushPlain(MachineType type) { |
| 1211 fields_.push_back(StateValueDescriptor::Plain(type)); |
| 1212 } |
| 1213 void PushOptimizedOut() { |
| 1214 fields_.push_back(StateValueDescriptor::OptimizedOut()); |
| 1215 } |
| 1216 |
| 1217 iterator begin() { return iterator(fields_.begin(), nested_.begin()); } |
| 1218 iterator end() { return iterator(fields_.end(), nested_.end()); } |
| 1219 |
| 1220 private: |
| 1221 ZoneVector<StateValueDescriptor> fields_; |
| 1222 ZoneVector<StateValueList*> nested_; |
| 1223 }; |
1153 | 1224 |
1154 class FrameStateDescriptor : public ZoneObject { | 1225 class FrameStateDescriptor : public ZoneObject { |
1155 public: | 1226 public: |
1156 FrameStateDescriptor(Zone* zone, FrameStateType type, BailoutId bailout_id, | 1227 FrameStateDescriptor(Zone* zone, FrameStateType type, BailoutId bailout_id, |
1157 OutputFrameStateCombine state_combine, | 1228 OutputFrameStateCombine state_combine, |
1158 size_t parameters_count, size_t locals_count, | 1229 size_t parameters_count, size_t locals_count, |
1159 size_t stack_count, | 1230 size_t stack_count, |
1160 MaybeHandle<SharedFunctionInfo> shared_info, | 1231 MaybeHandle<SharedFunctionInfo> shared_info, |
1161 FrameStateDescriptor* outer_state = nullptr); | 1232 FrameStateDescriptor* outer_state = nullptr); |
1162 | 1233 |
1163 FrameStateType type() const { return type_; } | 1234 FrameStateType type() const { return type_; } |
1164 BailoutId bailout_id() const { return bailout_id_; } | 1235 BailoutId bailout_id() const { return bailout_id_; } |
1165 OutputFrameStateCombine state_combine() const { return frame_state_combine_; } | 1236 OutputFrameStateCombine state_combine() const { return frame_state_combine_; } |
1166 size_t parameters_count() const { return parameters_count_; } | 1237 size_t parameters_count() const { return parameters_count_; } |
1167 size_t locals_count() const { return locals_count_; } | 1238 size_t locals_count() const { return locals_count_; } |
1168 size_t stack_count() const { return stack_count_; } | 1239 size_t stack_count() const { return stack_count_; } |
1169 MaybeHandle<SharedFunctionInfo> shared_info() const { return shared_info_; } | 1240 MaybeHandle<SharedFunctionInfo> shared_info() const { return shared_info_; } |
1170 FrameStateDescriptor* outer_state() const { return outer_state_; } | 1241 FrameStateDescriptor* outer_state() const { return outer_state_; } |
1171 bool HasContext() const { | 1242 bool HasContext() const { |
1172 return FrameStateFunctionInfo::IsJSFunctionType(type_); | 1243 return FrameStateFunctionInfo::IsJSFunctionType(type_); |
1173 } | 1244 } |
1174 | 1245 |
1175 size_t GetSize(OutputFrameStateCombine combine = | 1246 size_t GetSize(OutputFrameStateCombine combine = |
1176 OutputFrameStateCombine::Ignore()) const; | 1247 OutputFrameStateCombine::Ignore()) const; |
1177 size_t GetTotalSize() const; | 1248 size_t GetTotalSize() const; |
1178 size_t GetFrameCount() const; | 1249 size_t GetFrameCount() const; |
1179 size_t GetJSFrameCount() const; | 1250 size_t GetJSFrameCount() const; |
1180 | 1251 |
1181 MachineType GetType(size_t index) const { | 1252 StateValueList* GetStateValueDescriptors() { return &values_; } |
1182 return values_.GetOperandType(index); | |
1183 } | |
1184 StateValueDescriptor* GetStateValueDescriptor() { return &values_; } | |
1185 | 1253 |
1186 static const int kImpossibleValue = 0xdead; | 1254 static const int kImpossibleValue = 0xdead; |
1187 | 1255 |
1188 private: | 1256 private: |
1189 FrameStateType type_; | 1257 FrameStateType type_; |
1190 BailoutId bailout_id_; | 1258 BailoutId bailout_id_; |
1191 OutputFrameStateCombine frame_state_combine_; | 1259 OutputFrameStateCombine frame_state_combine_; |
1192 size_t parameters_count_; | 1260 size_t parameters_count_; |
1193 size_t locals_count_; | 1261 size_t locals_count_; |
1194 size_t stack_count_; | 1262 size_t stack_count_; |
1195 StateValueDescriptor values_; | 1263 StateValueList values_; |
1196 MaybeHandle<SharedFunctionInfo> const shared_info_; | 1264 MaybeHandle<SharedFunctionInfo> const shared_info_; |
1197 FrameStateDescriptor* outer_state_; | 1265 FrameStateDescriptor* outer_state_; |
1198 }; | 1266 }; |
1199 | 1267 |
1200 // A deoptimization entry is a pair of the reason why we deoptimize and the | 1268 // A deoptimization entry is a pair of the reason why we deoptimize and the |
1201 // frame state descriptor that we have to go back to. | 1269 // frame state descriptor that we have to go back to. |
1202 class DeoptimizationEntry final { | 1270 class DeoptimizationEntry final { |
1203 public: | 1271 public: |
1204 DeoptimizationEntry() {} | 1272 DeoptimizationEntry() {} |
1205 DeoptimizationEntry(FrameStateDescriptor* descriptor, DeoptimizeReason reason) | 1273 DeoptimizationEntry(FrameStateDescriptor* descriptor, DeoptimizeReason reason) |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1534 }; | 1602 }; |
1535 | 1603 |
1536 V8_EXPORT_PRIVATE std::ostream& operator<<( | 1604 V8_EXPORT_PRIVATE std::ostream& operator<<( |
1537 std::ostream& os, const PrintableInstructionSequence& code); | 1605 std::ostream& os, const PrintableInstructionSequence& code); |
1538 | 1606 |
1539 } // namespace compiler | 1607 } // namespace compiler |
1540 } // namespace internal | 1608 } // namespace internal |
1541 } // namespace v8 | 1609 } // namespace v8 |
1542 | 1610 |
1543 #endif // V8_COMPILER_INSTRUCTION_H_ | 1611 #endif // V8_COMPILER_INSTRUCTION_H_ |
OLD | NEW |