| 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(); } | |
| 646 | 645 |
| 647 HBasicBlock* block() const { return block_; } | 646 HBasicBlock* block() const { return block_; } |
| 648 void SetBlock(HBasicBlock* block); | 647 void SetBlock(HBasicBlock* block); |
| 649 int LoopWeight() const; | 648 int LoopWeight() const; |
| 650 | 649 |
| 651 // Note: Never call this method for an unlinked value. | 650 // Note: Never call this method for an unlinked value. |
| 652 Isolate* isolate() const; | 651 Isolate* isolate() const; |
| 653 | 652 |
| 654 int id() const { return id_; } | 653 int id() const { return id_; } |
| 655 void set_id(int id) { id_ = id; } | 654 void set_id(int id) { id_ = id; } |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 HValue* context, \ | 1098 HValue* context, \ |
| 1100 P1 p1, \ | 1099 P1 p1, \ |
| 1101 P2 p2, \ | 1100 P2 p2, \ |
| 1102 P3 p3, \ | 1101 P3 p3, \ |
| 1103 P4 p4, \ | 1102 P4 p4, \ |
| 1104 P5 p5) { \ | 1103 P5 p5) { \ |
| 1105 return new(zone) I(context, p1, p2, p3, p4, p5); \ | 1104 return new(zone) I(context, p1, p2, p3, p4, p5); \ |
| 1106 } | 1105 } |
| 1107 | 1106 |
| 1108 | 1107 |
| 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 operand_positions()[kInstructionPosIndex]; | |
| 1126 } | |
| 1127 return 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 | |
| 1205 class HInstruction : public HValue { | 1108 class HInstruction : public HValue { |
| 1206 public: | 1109 public: |
| 1207 HInstruction* next() const { return next_; } | 1110 HInstruction* next() const { return next_; } |
| 1208 HInstruction* previous() const { return previous_; } | 1111 HInstruction* previous() const { return previous_; } |
| 1209 | 1112 |
| 1210 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; | 1113 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; |
| 1211 virtual void PrintDataTo(StringStream* stream); | 1114 virtual void PrintDataTo(StringStream* stream); |
| 1212 | 1115 |
| 1213 bool IsLinked() const { return block() != NULL; } | 1116 bool IsLinked() const { return block() != NULL; } |
| 1214 void Unlink(); | 1117 void Unlink(); |
| 1215 void InsertBefore(HInstruction* next); | 1118 void InsertBefore(HInstruction* next); |
| 1216 void InsertAfter(HInstruction* previous); | 1119 void InsertAfter(HInstruction* previous); |
| 1217 | 1120 |
| 1218 // The position is a write-once variable. | 1121 // The position is a write-once variable. |
| 1219 virtual int position() const V8_OVERRIDE { | 1122 virtual int position() const V8_OVERRIDE { return position_; } |
| 1220 return position_.position(); | 1123 bool has_position() const { return position_ != RelocInfo::kNoPosition; } |
| 1221 } | |
| 1222 bool has_position() const { | |
| 1223 return position_.position() != RelocInfo::kNoPosition; | |
| 1224 } | |
| 1225 void set_position(int position) { | 1124 void set_position(int position) { |
| 1226 ASSERT(!has_position()); | 1125 ASSERT(!has_position()); |
| 1227 ASSERT(position != RelocInfo::kNoPosition); | 1126 ASSERT(position != RelocInfo::kNoPosition); |
| 1228 position_.set_position(position); | 1127 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); | |
| 1239 } | 1128 } |
| 1240 | 1129 |
| 1241 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } | 1130 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } |
| 1242 | 1131 |
| 1243 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; | 1132 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; |
| 1244 | 1133 |
| 1245 #ifdef DEBUG | 1134 #ifdef DEBUG |
| 1246 virtual void Verify() V8_OVERRIDE; | 1135 virtual void Verify() V8_OVERRIDE; |
| 1247 #endif | 1136 #endif |
| 1248 | 1137 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1264 private: | 1153 private: |
| 1265 void InitializeAsFirst(HBasicBlock* block) { | 1154 void InitializeAsFirst(HBasicBlock* block) { |
| 1266 ASSERT(!IsLinked()); | 1155 ASSERT(!IsLinked()); |
| 1267 SetBlock(block); | 1156 SetBlock(block); |
| 1268 } | 1157 } |
| 1269 | 1158 |
| 1270 void PrintMnemonicTo(StringStream* stream); | 1159 void PrintMnemonicTo(StringStream* stream); |
| 1271 | 1160 |
| 1272 HInstruction* next_; | 1161 HInstruction* next_; |
| 1273 HInstruction* previous_; | 1162 HInstruction* previous_; |
| 1274 HPositionInfo position_; | 1163 int position_; |
| 1275 | 1164 |
| 1276 friend class HBasicBlock; | 1165 friend class HBasicBlock; |
| 1277 }; | 1166 }; |
| 1278 | 1167 |
| 1279 | 1168 |
| 1280 template<int V> | 1169 template<int V> |
| 1281 class HTemplateInstruction : public HInstruction { | 1170 class HTemplateInstruction : public HInstruction { |
| 1282 public: | 1171 public: |
| 1283 virtual int OperandCount() V8_FINAL V8_OVERRIDE { return V; } | 1172 virtual int OperandCount() V8_FINAL V8_OVERRIDE { return V; } |
| 1284 virtual HValue* OperandAt(int i) const V8_FINAL V8_OVERRIDE { | 1173 virtual HValue* OperandAt(int i) const V8_FINAL V8_OVERRIDE { |
| (...skipping 2507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3792 | 3681 |
| 3793 virtual bool IsCommutative() const { return false; } | 3682 virtual bool IsCommutative() const { return false; } |
| 3794 | 3683 |
| 3795 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 3684 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
| 3796 | 3685 |
| 3797 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 3686 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
| 3798 if (index == 0) return Representation::Tagged(); | 3687 if (index == 0) return Representation::Tagged(); |
| 3799 return representation(); | 3688 return representation(); |
| 3800 } | 3689 } |
| 3801 | 3690 |
| 3802 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { | |
| 3803 set_operand_position(zone, 1, left_pos); | |
| 3804 set_operand_position(zone, 2, right_pos); | |
| 3805 } | |
| 3806 | |
| 3807 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) | 3691 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) |
| 3808 | 3692 |
| 3809 private: | 3693 private: |
| 3810 bool IgnoreObservedOutputRepresentation(Representation current_rep); | 3694 bool IgnoreObservedOutputRepresentation(Representation current_rep); |
| 3811 | 3695 |
| 3812 Representation observed_input_representation_[2]; | 3696 Representation observed_input_representation_[2]; |
| 3813 Representation observed_output_representation_; | 3697 Representation observed_output_representation_; |
| 3814 }; | 3698 }; |
| 3815 | 3699 |
| 3816 | 3700 |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4230 HInferRepresentationPhase* h_infer) V8_OVERRIDE; | 4114 HInferRepresentationPhase* h_infer) V8_OVERRIDE; |
| 4231 | 4115 |
| 4232 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 4116 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
| 4233 return representation(); | 4117 return representation(); |
| 4234 } | 4118 } |
| 4235 virtual Representation observed_input_representation(int index) V8_OVERRIDE { | 4119 virtual Representation observed_input_representation(int index) V8_OVERRIDE { |
| 4236 return observed_input_representation_[index]; | 4120 return observed_input_representation_[index]; |
| 4237 } | 4121 } |
| 4238 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 4122 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
| 4239 | 4123 |
| 4240 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { | |
| 4241 set_operand_position(zone, 0, left_pos); | |
| 4242 set_operand_position(zone, 1, right_pos); | |
| 4243 } | |
| 4244 | |
| 4245 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) | 4124 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) |
| 4246 | 4125 |
| 4247 private: | 4126 private: |
| 4248 HCompareNumericAndBranch(HValue* left, | 4127 HCompareNumericAndBranch(HValue* left, |
| 4249 HValue* right, | 4128 HValue* right, |
| 4250 Token::Value token, | 4129 Token::Value token, |
| 4251 HBasicBlock* true_target = NULL, | 4130 HBasicBlock* true_target = NULL, |
| 4252 HBasicBlock* false_target = NULL) | 4131 HBasicBlock* false_target = NULL) |
| 4253 : token_(token) { | 4132 : token_(token) { |
| 4254 SetFlag(kFlexibleRepresentation); | 4133 SetFlag(kFlexibleRepresentation); |
| (...skipping 3166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7421 virtual bool IsDeletable() const V8_OVERRIDE { return true; } | 7300 virtual bool IsDeletable() const V8_OVERRIDE { return true; } |
| 7422 }; | 7301 }; |
| 7423 | 7302 |
| 7424 | 7303 |
| 7425 #undef DECLARE_INSTRUCTION | 7304 #undef DECLARE_INSTRUCTION |
| 7426 #undef DECLARE_CONCRETE_INSTRUCTION | 7305 #undef DECLARE_CONCRETE_INSTRUCTION |
| 7427 | 7306 |
| 7428 } } // namespace v8::internal | 7307 } } // namespace v8::internal |
| 7429 | 7308 |
| 7430 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 7309 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
| OLD | NEW |