| 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 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 HValue(HType type = HType::Tagged()) | 632 HValue(HType type = HType::Tagged()) |
| 633 : block_(NULL), | 633 : block_(NULL), |
| 634 id_(kNoNumber), | 634 id_(kNoNumber), |
| 635 type_(type), | 635 type_(type), |
| 636 use_list_(NULL), | 636 use_list_(NULL), |
| 637 range_(NULL), | 637 range_(NULL), |
| 638 flags_(0) {} | 638 flags_(0) {} |
| 639 virtual ~HValue() {} | 639 virtual ~HValue() {} |
| 640 | 640 |
| 641 virtual int position() const { return RelocInfo::kNoPosition; } | 641 virtual int position() const { return RelocInfo::kNoPosition; } |
| 642 virtual int operand_position(int index) const { return position(); } |
| 642 | 643 |
| 643 HBasicBlock* block() const { return block_; } | 644 HBasicBlock* block() const { return block_; } |
| 644 void SetBlock(HBasicBlock* block); | 645 void SetBlock(HBasicBlock* block); |
| 645 int LoopWeight() const; | 646 int LoopWeight() const; |
| 646 | 647 |
| 647 // Note: Never call this method for an unlinked value. | 648 // Note: Never call this method for an unlinked value. |
| 648 Isolate* isolate() const; | 649 Isolate* isolate() const; |
| 649 | 650 |
| 650 int id() const { return id_; } | 651 int id() const { return id_; } |
| 651 void set_id(int id) { id_ = id; } | 652 void set_id(int id) { id_ = id; } |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1095 HValue* context, \ | 1096 HValue* context, \ |
| 1096 P1 p1, \ | 1097 P1 p1, \ |
| 1097 P2 p2, \ | 1098 P2 p2, \ |
| 1098 P3 p3, \ | 1099 P3 p3, \ |
| 1099 P4 p4, \ | 1100 P4 p4, \ |
| 1100 P5 p5) { \ | 1101 P5 p5) { \ |
| 1101 return new(zone) I(context, p1, p2, p3, p4, p5); \ | 1102 return new(zone) I(context, p1, p2, p3, p4, p5); \ |
| 1102 } | 1103 } |
| 1103 | 1104 |
| 1104 | 1105 |
| 1106 // A helper class to represent per-operand position information attached to |
| 1107 // the HInstruction in the compact form. Uses tagging to distinguish between |
| 1108 // case when only instruction's position is available and case when operands' |
| 1109 // positions are also available. |
| 1110 // In the first case it contains intruction's position as a tagged value. |
| 1111 // In the second case it points to an array which contains instruction's |
| 1112 // position and operands' positions. |
| 1113 // TODO(vegorov): what we really want to track here is a combination of |
| 1114 // source position and a script id because cross script inlining can easily |
| 1115 // result in optimized functions composed of several scripts. |
| 1116 class HPositionInfo { |
| 1117 public: |
| 1118 explicit HPositionInfo(int pos) : data_(TagPosition(pos)) { } |
| 1119 |
| 1120 int position() const { |
| 1121 if (has_operand_positions()) { |
| 1122 return operand_positions()[kInstructionPosIndex]; |
| 1123 } |
| 1124 return UntagPosition(data_); |
| 1125 } |
| 1126 |
| 1127 void set_position(int pos) { |
| 1128 if (has_operand_positions()) { |
| 1129 operand_positions()[kInstructionPosIndex] = pos; |
| 1130 } else { |
| 1131 data_ = TagPosition(pos); |
| 1132 } |
| 1133 } |
| 1134 |
| 1135 void ensure_storage_for_operand_positions(Zone* zone, int operand_count) { |
| 1136 if (has_operand_positions()) { |
| 1137 return; |
| 1138 } |
| 1139 |
| 1140 const int length = kFirstOperandPosIndex + operand_count; |
| 1141 intptr_t* positions = |
| 1142 zone->NewArray<intptr_t>(length); |
| 1143 for (int i = 0; i < length; i++) { |
| 1144 positions[i] = RelocInfo::kNoPosition; |
| 1145 } |
| 1146 |
| 1147 const int pos = position(); |
| 1148 data_ = reinterpret_cast<intptr_t>(positions); |
| 1149 set_position(pos); |
| 1150 |
| 1151 ASSERT(has_operand_positions()); |
| 1152 } |
| 1153 |
| 1154 int operand_position(int idx) const { |
| 1155 if (!has_operand_positions()) { |
| 1156 return position(); |
| 1157 } |
| 1158 return static_cast<int>(*operand_position_slot(idx)); |
| 1159 } |
| 1160 |
| 1161 void set_operand_position(int idx, int pos) { |
| 1162 *operand_position_slot(idx) = pos; |
| 1163 } |
| 1164 |
| 1165 private: |
| 1166 static const intptr_t kInstructionPosIndex = 0; |
| 1167 static const intptr_t kFirstOperandPosIndex = 1; |
| 1168 |
| 1169 intptr_t* operand_position_slot(int idx) const { |
| 1170 ASSERT(has_operand_positions()); |
| 1171 return &(operand_positions()[kFirstOperandPosIndex + idx]); |
| 1172 } |
| 1173 |
| 1174 bool has_operand_positions() const { |
| 1175 return !IsTaggedPosition(data_); |
| 1176 } |
| 1177 |
| 1178 intptr_t* operand_positions() const { |
| 1179 ASSERT(has_operand_positions()); |
| 1180 return reinterpret_cast<intptr_t*>(data_); |
| 1181 } |
| 1182 |
| 1183 static const intptr_t kPositionTag = 1; |
| 1184 static const intptr_t kPositionShift = 1; |
| 1185 static bool IsTaggedPosition(intptr_t val) { |
| 1186 return (val & kPositionTag) != 0; |
| 1187 } |
| 1188 static intptr_t UntagPosition(intptr_t val) { |
| 1189 ASSERT(IsTaggedPosition(val)); |
| 1190 return val >> kPositionShift; |
| 1191 } |
| 1192 static intptr_t TagPosition(intptr_t val) { |
| 1193 const intptr_t result = (val << kPositionShift) | kPositionTag; |
| 1194 ASSERT(UntagPosition(result) == val); |
| 1195 return result; |
| 1196 } |
| 1197 |
| 1198 intptr_t data_; |
| 1199 }; |
| 1200 |
| 1201 |
| 1105 class HInstruction : public HValue { | 1202 class HInstruction : public HValue { |
| 1106 public: | 1203 public: |
| 1107 HInstruction* next() const { return next_; } | 1204 HInstruction* next() const { return next_; } |
| 1108 HInstruction* previous() const { return previous_; } | 1205 HInstruction* previous() const { return previous_; } |
| 1109 | 1206 |
| 1110 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; | 1207 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; |
| 1111 virtual void PrintDataTo(StringStream* stream); | 1208 virtual void PrintDataTo(StringStream* stream); |
| 1112 | 1209 |
| 1113 bool IsLinked() const { return block() != NULL; } | 1210 bool IsLinked() const { return block() != NULL; } |
| 1114 void Unlink(); | 1211 void Unlink(); |
| 1115 void InsertBefore(HInstruction* next); | 1212 void InsertBefore(HInstruction* next); |
| 1116 void InsertAfter(HInstruction* previous); | 1213 void InsertAfter(HInstruction* previous); |
| 1117 | 1214 |
| 1118 // The position is a write-once variable. | 1215 // The position is a write-once variable. |
| 1119 virtual int position() const V8_OVERRIDE { return position_; } | 1216 virtual int position() const V8_OVERRIDE { |
| 1120 bool has_position() const { return position_ != RelocInfo::kNoPosition; } | 1217 return position_.position(); |
| 1218 } |
| 1219 bool has_position() const { |
| 1220 return position_.position() != RelocInfo::kNoPosition; |
| 1221 } |
| 1121 void set_position(int position) { | 1222 void set_position(int position) { |
| 1122 ASSERT(!has_position()); | 1223 ASSERT(!has_position()); |
| 1123 ASSERT(position != RelocInfo::kNoPosition); | 1224 ASSERT(position != RelocInfo::kNoPosition); |
| 1124 position_ = position; | 1225 position_.set_position(position); |
| 1226 } |
| 1227 |
| 1228 virtual int operand_position(int index) const V8_OVERRIDE { |
| 1229 const int pos = position_.operand_position(index); |
| 1230 return (pos != RelocInfo::kNoPosition) ? pos : position(); |
| 1231 } |
| 1232 void set_operand_position(Zone* zone, int index, int pos) { |
| 1233 ASSERT(0 <= index && index < OperandCount()); |
| 1234 position_.ensure_storage_for_operand_positions(zone, OperandCount()); |
| 1235 position_.set_operand_position(index, pos); |
| 1125 } | 1236 } |
| 1126 | 1237 |
| 1127 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } | 1238 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } |
| 1128 | 1239 |
| 1129 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; | 1240 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; |
| 1130 | 1241 |
| 1131 #ifdef DEBUG | 1242 #ifdef DEBUG |
| 1132 virtual void Verify() V8_OVERRIDE; | 1243 virtual void Verify() V8_OVERRIDE; |
| 1133 #endif | 1244 #endif |
| 1134 | 1245 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1150 private: | 1261 private: |
| 1151 void InitializeAsFirst(HBasicBlock* block) { | 1262 void InitializeAsFirst(HBasicBlock* block) { |
| 1152 ASSERT(!IsLinked()); | 1263 ASSERT(!IsLinked()); |
| 1153 SetBlock(block); | 1264 SetBlock(block); |
| 1154 } | 1265 } |
| 1155 | 1266 |
| 1156 void PrintMnemonicTo(StringStream* stream); | 1267 void PrintMnemonicTo(StringStream* stream); |
| 1157 | 1268 |
| 1158 HInstruction* next_; | 1269 HInstruction* next_; |
| 1159 HInstruction* previous_; | 1270 HInstruction* previous_; |
| 1160 int position_; | 1271 HPositionInfo position_; |
| 1161 | 1272 |
| 1162 friend class HBasicBlock; | 1273 friend class HBasicBlock; |
| 1163 }; | 1274 }; |
| 1164 | 1275 |
| 1165 | 1276 |
| 1166 template<int V> | 1277 template<int V> |
| 1167 class HTemplateInstruction : public HInstruction { | 1278 class HTemplateInstruction : public HInstruction { |
| 1168 public: | 1279 public: |
| 1169 virtual int OperandCount() V8_FINAL V8_OVERRIDE { return V; } | 1280 virtual int OperandCount() V8_FINAL V8_OVERRIDE { return V; } |
| 1170 virtual HValue* OperandAt(int i) const V8_FINAL V8_OVERRIDE { | 1281 virtual HValue* OperandAt(int i) const V8_FINAL V8_OVERRIDE { |
| (...skipping 2506 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3677 | 3788 |
| 3678 virtual bool IsCommutative() const { return false; } | 3789 virtual bool IsCommutative() const { return false; } |
| 3679 | 3790 |
| 3680 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 3791 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
| 3681 | 3792 |
| 3682 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 3793 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
| 3683 if (index == 0) return Representation::Tagged(); | 3794 if (index == 0) return Representation::Tagged(); |
| 3684 return representation(); | 3795 return representation(); |
| 3685 } | 3796 } |
| 3686 | 3797 |
| 3798 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { |
| 3799 set_operand_position(zone, 1, left_pos); |
| 3800 set_operand_position(zone, 2, right_pos); |
| 3801 } |
| 3802 |
| 3687 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) | 3803 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) |
| 3688 | 3804 |
| 3689 private: | 3805 private: |
| 3690 bool IgnoreObservedOutputRepresentation(Representation current_rep); | 3806 bool IgnoreObservedOutputRepresentation(Representation current_rep); |
| 3691 | 3807 |
| 3692 Representation observed_input_representation_[2]; | 3808 Representation observed_input_representation_[2]; |
| 3693 Representation observed_output_representation_; | 3809 Representation observed_output_representation_; |
| 3694 }; | 3810 }; |
| 3695 | 3811 |
| 3696 | 3812 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4100 HInferRepresentationPhase* h_infer) V8_OVERRIDE; | 4216 HInferRepresentationPhase* h_infer) V8_OVERRIDE; |
| 4101 | 4217 |
| 4102 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 4218 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
| 4103 return representation(); | 4219 return representation(); |
| 4104 } | 4220 } |
| 4105 virtual Representation observed_input_representation(int index) V8_OVERRIDE { | 4221 virtual Representation observed_input_representation(int index) V8_OVERRIDE { |
| 4106 return observed_input_representation_[index]; | 4222 return observed_input_representation_[index]; |
| 4107 } | 4223 } |
| 4108 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 4224 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
| 4109 | 4225 |
| 4226 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { |
| 4227 set_operand_position(zone, 0, left_pos); |
| 4228 set_operand_position(zone, 1, right_pos); |
| 4229 } |
| 4230 |
| 4110 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) | 4231 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) |
| 4111 | 4232 |
| 4112 private: | 4233 private: |
| 4113 HCompareNumericAndBranch(HValue* left, | 4234 HCompareNumericAndBranch(HValue* left, |
| 4114 HValue* right, | 4235 HValue* right, |
| 4115 Token::Value token, | 4236 Token::Value token, |
| 4116 HBasicBlock* true_target = NULL, | 4237 HBasicBlock* true_target = NULL, |
| 4117 HBasicBlock* false_target = NULL) | 4238 HBasicBlock* false_target = NULL) |
| 4118 : token_(token) { | 4239 : token_(token) { |
| 4119 SetFlag(kFlexibleRepresentation); | 4240 SetFlag(kFlexibleRepresentation); |
| (...skipping 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7151 virtual bool IsDeletable() const V8_OVERRIDE { return true; } | 7272 virtual bool IsDeletable() const V8_OVERRIDE { return true; } |
| 7152 }; | 7273 }; |
| 7153 | 7274 |
| 7154 | 7275 |
| 7155 #undef DECLARE_INSTRUCTION | 7276 #undef DECLARE_INSTRUCTION |
| 7156 #undef DECLARE_CONCRETE_INSTRUCTION | 7277 #undef DECLARE_CONCRETE_INSTRUCTION |
| 7157 | 7278 |
| 7158 } } // namespace v8::internal | 7279 } } // namespace v8::internal |
| 7159 | 7280 |
| 7160 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 7281 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
| OLD | NEW |