OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 HValue(HType type = HType::Tagged()) | 635 HValue(HType type = HType::Tagged()) |
636 : block_(NULL), | 636 : block_(NULL), |
637 id_(kNoNumber), | 637 id_(kNoNumber), |
638 type_(type), | 638 type_(type), |
639 use_list_(NULL), | 639 use_list_(NULL), |
640 range_(NULL), | 640 range_(NULL), |
641 flags_(0) {} | 641 flags_(0) {} |
642 virtual ~HValue() {} | 642 virtual ~HValue() {} |
643 | 643 |
644 virtual int position() const { return RelocInfo::kNoPosition; } | 644 virtual int position() const { return RelocInfo::kNoPosition; } |
| 645 virtual int operand_position(int index) const { return position(); } |
645 | 646 |
646 HBasicBlock* block() const { return block_; } | 647 HBasicBlock* block() const { return block_; } |
647 void SetBlock(HBasicBlock* block); | 648 void SetBlock(HBasicBlock* block); |
648 int LoopWeight() const; | 649 int LoopWeight() const; |
649 | 650 |
650 // Note: Never call this method for an unlinked value. | 651 // Note: Never call this method for an unlinked value. |
651 Isolate* isolate() const; | 652 Isolate* isolate() const; |
652 | 653 |
653 int id() const { return id_; } | 654 int id() const { return id_; } |
654 void set_id(int id) { id_ = id; } | 655 void set_id(int id) { id_ = id; } |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 HValue* context, \ | 1099 HValue* context, \ |
1099 P1 p1, \ | 1100 P1 p1, \ |
1100 P2 p2, \ | 1101 P2 p2, \ |
1101 P3 p3, \ | 1102 P3 p3, \ |
1102 P4 p4, \ | 1103 P4 p4, \ |
1103 P5 p5) { \ | 1104 P5 p5) { \ |
1104 return new(zone) I(context, p1, p2, p3, p4, p5); \ | 1105 return new(zone) I(context, p1, p2, p3, p4, p5); \ |
1105 } | 1106 } |
1106 | 1107 |
1107 | 1108 |
| 1109 // A helper class to represent per-operand position information attached to |
| 1110 // the HInstruction in the compact form. Uses tagging to distinguish between |
| 1111 // case when only instruction's position is available and case when operands' |
| 1112 // positions are also available. |
| 1113 // In the first case it contains intruction's position as a tagged value. |
| 1114 // In the second case it points to an array which contains instruction's |
| 1115 // position and operands' positions. |
| 1116 // TODO(vegorov): what we really want to track here is a combination of |
| 1117 // source position and a script id because cross script inlining can easily |
| 1118 // result in optimized functions composed of several scripts. |
| 1119 class HPositionInfo { |
| 1120 public: |
| 1121 explicit HPositionInfo(int pos) : data_(TagPosition(pos)) { } |
| 1122 |
| 1123 int position() const { |
| 1124 if (has_operand_positions()) { |
| 1125 return static_cast<int>(operand_positions()[kInstructionPosIndex]); |
| 1126 } |
| 1127 return static_cast<int>(UntagPosition(data_)); |
| 1128 } |
| 1129 |
| 1130 void set_position(int pos) { |
| 1131 if (has_operand_positions()) { |
| 1132 operand_positions()[kInstructionPosIndex] = pos; |
| 1133 } else { |
| 1134 data_ = TagPosition(pos); |
| 1135 } |
| 1136 } |
| 1137 |
| 1138 void ensure_storage_for_operand_positions(Zone* zone, int operand_count) { |
| 1139 if (has_operand_positions()) { |
| 1140 return; |
| 1141 } |
| 1142 |
| 1143 const int length = kFirstOperandPosIndex + operand_count; |
| 1144 intptr_t* positions = |
| 1145 zone->NewArray<intptr_t>(length); |
| 1146 for (int i = 0; i < length; i++) { |
| 1147 positions[i] = RelocInfo::kNoPosition; |
| 1148 } |
| 1149 |
| 1150 const int pos = position(); |
| 1151 data_ = reinterpret_cast<intptr_t>(positions); |
| 1152 set_position(pos); |
| 1153 |
| 1154 ASSERT(has_operand_positions()); |
| 1155 } |
| 1156 |
| 1157 int operand_position(int idx) const { |
| 1158 if (!has_operand_positions()) { |
| 1159 return position(); |
| 1160 } |
| 1161 return static_cast<int>(*operand_position_slot(idx)); |
| 1162 } |
| 1163 |
| 1164 void set_operand_position(int idx, int pos) { |
| 1165 *operand_position_slot(idx) = pos; |
| 1166 } |
| 1167 |
| 1168 private: |
| 1169 static const intptr_t kInstructionPosIndex = 0; |
| 1170 static const intptr_t kFirstOperandPosIndex = 1; |
| 1171 |
| 1172 intptr_t* operand_position_slot(int idx) const { |
| 1173 ASSERT(has_operand_positions()); |
| 1174 return &(operand_positions()[kFirstOperandPosIndex + idx]); |
| 1175 } |
| 1176 |
| 1177 bool has_operand_positions() const { |
| 1178 return !IsTaggedPosition(data_); |
| 1179 } |
| 1180 |
| 1181 intptr_t* operand_positions() const { |
| 1182 ASSERT(has_operand_positions()); |
| 1183 return reinterpret_cast<intptr_t*>(data_); |
| 1184 } |
| 1185 |
| 1186 static const intptr_t kPositionTag = 1; |
| 1187 static const intptr_t kPositionShift = 1; |
| 1188 static bool IsTaggedPosition(intptr_t val) { |
| 1189 return (val & kPositionTag) != 0; |
| 1190 } |
| 1191 static intptr_t UntagPosition(intptr_t val) { |
| 1192 ASSERT(IsTaggedPosition(val)); |
| 1193 return val >> kPositionShift; |
| 1194 } |
| 1195 static intptr_t TagPosition(intptr_t val) { |
| 1196 const intptr_t result = (val << kPositionShift) | kPositionTag; |
| 1197 ASSERT(UntagPosition(result) == val); |
| 1198 return result; |
| 1199 } |
| 1200 |
| 1201 intptr_t data_; |
| 1202 }; |
| 1203 |
| 1204 |
1108 class HInstruction : public HValue { | 1205 class HInstruction : public HValue { |
1109 public: | 1206 public: |
1110 HInstruction* next() const { return next_; } | 1207 HInstruction* next() const { return next_; } |
1111 HInstruction* previous() const { return previous_; } | 1208 HInstruction* previous() const { return previous_; } |
1112 | 1209 |
1113 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; | 1210 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; |
1114 virtual void PrintDataTo(StringStream* stream); | 1211 virtual void PrintDataTo(StringStream* stream); |
1115 | 1212 |
1116 bool IsLinked() const { return block() != NULL; } | 1213 bool IsLinked() const { return block() != NULL; } |
1117 void Unlink(); | 1214 void Unlink(); |
1118 void InsertBefore(HInstruction* next); | 1215 void InsertBefore(HInstruction* next); |
1119 void InsertAfter(HInstruction* previous); | 1216 void InsertAfter(HInstruction* previous); |
1120 | 1217 |
1121 // The position is a write-once variable. | 1218 // The position is a write-once variable. |
1122 virtual int position() const V8_OVERRIDE { return position_; } | 1219 virtual int position() const V8_OVERRIDE { |
1123 bool has_position() const { return position_ != RelocInfo::kNoPosition; } | 1220 return position_.position(); |
| 1221 } |
| 1222 bool has_position() const { |
| 1223 return position_.position() != RelocInfo::kNoPosition; |
| 1224 } |
1124 void set_position(int position) { | 1225 void set_position(int position) { |
1125 ASSERT(!has_position()); | 1226 ASSERT(!has_position()); |
1126 ASSERT(position != RelocInfo::kNoPosition); | 1227 ASSERT(position != RelocInfo::kNoPosition); |
1127 position_ = position; | 1228 position_.set_position(position); |
| 1229 } |
| 1230 |
| 1231 virtual int operand_position(int index) const V8_OVERRIDE { |
| 1232 const int pos = position_.operand_position(index); |
| 1233 return (pos != RelocInfo::kNoPosition) ? pos : position(); |
| 1234 } |
| 1235 void set_operand_position(Zone* zone, int index, int pos) { |
| 1236 ASSERT(0 <= index && index < OperandCount()); |
| 1237 position_.ensure_storage_for_operand_positions(zone, OperandCount()); |
| 1238 position_.set_operand_position(index, pos); |
1128 } | 1239 } |
1129 | 1240 |
1130 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } | 1241 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } |
1131 | 1242 |
1132 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; | 1243 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; |
1133 | 1244 |
1134 #ifdef DEBUG | 1245 #ifdef DEBUG |
1135 virtual void Verify() V8_OVERRIDE; | 1246 virtual void Verify() V8_OVERRIDE; |
1136 #endif | 1247 #endif |
1137 | 1248 |
(...skipping 15 matching lines...) Expand all Loading... |
1153 private: | 1264 private: |
1154 void InitializeAsFirst(HBasicBlock* block) { | 1265 void InitializeAsFirst(HBasicBlock* block) { |
1155 ASSERT(!IsLinked()); | 1266 ASSERT(!IsLinked()); |
1156 SetBlock(block); | 1267 SetBlock(block); |
1157 } | 1268 } |
1158 | 1269 |
1159 void PrintMnemonicTo(StringStream* stream); | 1270 void PrintMnemonicTo(StringStream* stream); |
1160 | 1271 |
1161 HInstruction* next_; | 1272 HInstruction* next_; |
1162 HInstruction* previous_; | 1273 HInstruction* previous_; |
1163 int position_; | 1274 HPositionInfo position_; |
1164 | 1275 |
1165 friend class HBasicBlock; | 1276 friend class HBasicBlock; |
1166 }; | 1277 }; |
1167 | 1278 |
1168 | 1279 |
1169 template<int V> | 1280 template<int V> |
1170 class HTemplateInstruction : public HInstruction { | 1281 class HTemplateInstruction : public HInstruction { |
1171 public: | 1282 public: |
1172 virtual int OperandCount() V8_FINAL V8_OVERRIDE { return V; } | 1283 virtual int OperandCount() V8_FINAL V8_OVERRIDE { return V; } |
1173 virtual HValue* OperandAt(int i) const V8_FINAL V8_OVERRIDE { | 1284 virtual HValue* OperandAt(int i) const V8_FINAL V8_OVERRIDE { |
(...skipping 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3697 | 3808 |
3698 virtual bool IsCommutative() const { return false; } | 3809 virtual bool IsCommutative() const { return false; } |
3699 | 3810 |
3700 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 3811 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
3701 | 3812 |
3702 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 3813 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
3703 if (index == 0) return Representation::Tagged(); | 3814 if (index == 0) return Representation::Tagged(); |
3704 return representation(); | 3815 return representation(); |
3705 } | 3816 } |
3706 | 3817 |
| 3818 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { |
| 3819 set_operand_position(zone, 1, left_pos); |
| 3820 set_operand_position(zone, 2, right_pos); |
| 3821 } |
| 3822 |
3707 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) | 3823 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) |
3708 | 3824 |
3709 private: | 3825 private: |
3710 bool IgnoreObservedOutputRepresentation(Representation current_rep); | 3826 bool IgnoreObservedOutputRepresentation(Representation current_rep); |
3711 | 3827 |
3712 Representation observed_input_representation_[2]; | 3828 Representation observed_input_representation_[2]; |
3713 Representation observed_output_representation_; | 3829 Representation observed_output_representation_; |
3714 }; | 3830 }; |
3715 | 3831 |
3716 | 3832 |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4130 HInferRepresentationPhase* h_infer) V8_OVERRIDE; | 4246 HInferRepresentationPhase* h_infer) V8_OVERRIDE; |
4131 | 4247 |
4132 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 4248 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
4133 return representation(); | 4249 return representation(); |
4134 } | 4250 } |
4135 virtual Representation observed_input_representation(int index) V8_OVERRIDE { | 4251 virtual Representation observed_input_representation(int index) V8_OVERRIDE { |
4136 return observed_input_representation_[index]; | 4252 return observed_input_representation_[index]; |
4137 } | 4253 } |
4138 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 4254 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
4139 | 4255 |
| 4256 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { |
| 4257 set_operand_position(zone, 0, left_pos); |
| 4258 set_operand_position(zone, 1, right_pos); |
| 4259 } |
| 4260 |
4140 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) | 4261 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) |
4141 | 4262 |
4142 private: | 4263 private: |
4143 HCompareNumericAndBranch(HValue* left, | 4264 HCompareNumericAndBranch(HValue* left, |
4144 HValue* right, | 4265 HValue* right, |
4145 Token::Value token, | 4266 Token::Value token, |
4146 HBasicBlock* true_target = NULL, | 4267 HBasicBlock* true_target = NULL, |
4147 HBasicBlock* false_target = NULL) | 4268 HBasicBlock* false_target = NULL) |
4148 : token_(token) { | 4269 : token_(token) { |
4149 SetFlag(kFlexibleRepresentation); | 4270 SetFlag(kFlexibleRepresentation); |
(...skipping 3182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7332 virtual bool IsDeletable() const V8_OVERRIDE { return true; } | 7453 virtual bool IsDeletable() const V8_OVERRIDE { return true; } |
7333 }; | 7454 }; |
7334 | 7455 |
7335 | 7456 |
7336 #undef DECLARE_INSTRUCTION | 7457 #undef DECLARE_INSTRUCTION |
7337 #undef DECLARE_CONCRETE_INSTRUCTION | 7458 #undef DECLARE_CONCRETE_INSTRUCTION |
7338 | 7459 |
7339 } } // namespace v8::internal | 7460 } } // namespace v8::internal |
7340 | 7461 |
7341 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 7462 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
OLD | NEW |