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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
537 | 537 |
538 HValue* base_; | 538 HValue* base_; |
539 int offset_; | 539 int offset_; |
540 int scale_; | 540 int scale_; |
541 }; | 541 }; |
542 | 542 |
543 | 543 |
544 typedef EnumSet<GVNFlag, int64_t> GVNFlagSet; | 544 typedef EnumSet<GVNFlag, int64_t> GVNFlagSet; |
545 | 545 |
546 | 546 |
547 // This class encapsulates encoding and decoding of sources positions from | |
548 // which hydrogen values originated. | |
549 // When FLAG_track_hydrogen_positions is set this object encodes the | |
550 // identifier of the inlining and absolute offset from the start of the | |
551 // inlined function. | |
552 // When the flag is not set we simply track absolute offset from the | |
553 // script start. | |
554 class HSourcePosition { | |
555 public: | |
556 HSourcePosition(const HSourcePosition& other) : value_(other.value_) { } | |
557 | |
558 static HSourcePosition Unknown() { | |
559 return HSourcePosition(RelocInfo::kNoPosition); | |
560 } | |
561 | |
562 bool IsUnknown() const { return value_ == RelocInfo::kNoPosition; } | |
563 | |
564 int position() const { return PositionField::decode(value_); } | |
565 void set_position(int position) { | |
566 if (FLAG_hydrogen_track_positions) { | |
567 value_ = static_cast<int>(PositionField::update(value_, position)); | |
568 } else { | |
569 value_ = position; | |
570 } | |
571 } | |
572 | |
573 int inlining_id() const { return InliningIdField::decode(value_); } | |
574 void set_inlining_id(int inlining_id) { | |
575 if (FLAG_hydrogen_track_positions) { | |
576 value_ = static_cast<int>(InliningIdField::update(value_, inlining_id)); | |
577 } | |
578 } | |
579 | |
580 int raw() const { return value_; } | |
581 | |
582 void PrintTo(FILE* f); | |
583 | |
584 private: | |
585 typedef BitField<int, 0, 9> InliningIdField; | |
586 | |
587 // Offset from the start of the inlined function. | |
588 typedef BitField<int, 9, 23> PositionField; | |
589 | |
590 // On HPositionInfo can use this constructor. | |
591 explicit HSourcePosition(int value) : value_(value) { } | |
592 | |
593 friend class HPositionInfo; | |
594 | |
595 // If FLAG_hydrogen_track_positions is set contains bitfields InliningIdField | |
596 // and PositionField. | |
597 // Otherwise contains absolute offset from the script start. | |
598 int value_; | |
599 }; | |
600 | |
601 | |
547 class HValue : public ZoneObject { | 602 class HValue : public ZoneObject { |
548 public: | 603 public: |
549 static const int kNoNumber = -1; | 604 static const int kNoNumber = -1; |
550 | 605 |
551 enum Flag { | 606 enum Flag { |
552 kFlexibleRepresentation, | 607 kFlexibleRepresentation, |
553 kCannotBeTagged, | 608 kCannotBeTagged, |
554 // Participate in Global Value Numbering, i.e. elimination of | 609 // Participate in Global Value Numbering, i.e. elimination of |
555 // unnecessary recomputations. If an instruction sets this flag, it must | 610 // unnecessary recomputations. If an instruction sets this flag, it must |
556 // implement DataEquals(), which will be used to determine if other | 611 // implement DataEquals(), which will be used to determine if other |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 | 685 |
631 HValue(HType type = HType::Tagged()) | 686 HValue(HType type = HType::Tagged()) |
632 : block_(NULL), | 687 : block_(NULL), |
633 id_(kNoNumber), | 688 id_(kNoNumber), |
634 type_(type), | 689 type_(type), |
635 use_list_(NULL), | 690 use_list_(NULL), |
636 range_(NULL), | 691 range_(NULL), |
637 flags_(0) {} | 692 flags_(0) {} |
638 virtual ~HValue() {} | 693 virtual ~HValue() {} |
639 | 694 |
640 virtual int position() const { return RelocInfo::kNoPosition; } | 695 virtual HSourcePosition position() const { |
641 virtual int operand_position(int index) const { return position(); } | 696 return HSourcePosition::Unknown(); |
697 } | |
698 virtual HSourcePosition operand_position(int index) const { | |
699 return position(); | |
700 } | |
642 | 701 |
643 HBasicBlock* block() const { return block_; } | 702 HBasicBlock* block() const { return block_; } |
644 void SetBlock(HBasicBlock* block); | 703 void SetBlock(HBasicBlock* block); |
645 | 704 |
646 // Note: Never call this method for an unlinked value. | 705 // Note: Never call this method for an unlinked value. |
647 Isolate* isolate() const; | 706 Isolate* isolate() const; |
648 | 707 |
649 int id() const { return id_; } | 708 int id() const { return id_; } |
650 void set_id(int id) { id_ = id; } | 709 void set_id(int id) { id_ = id; } |
651 | 710 |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1101 } | 1160 } |
1102 | 1161 |
1103 | 1162 |
1104 // A helper class to represent per-operand position information attached to | 1163 // A helper class to represent per-operand position information attached to |
1105 // the HInstruction in the compact form. Uses tagging to distinguish between | 1164 // the HInstruction in the compact form. Uses tagging to distinguish between |
1106 // case when only instruction's position is available and case when operands' | 1165 // case when only instruction's position is available and case when operands' |
1107 // positions are also available. | 1166 // positions are also available. |
1108 // In the first case it contains intruction's position as a tagged value. | 1167 // In the first case it contains intruction's position as a tagged value. |
1109 // In the second case it points to an array which contains instruction's | 1168 // In the second case it points to an array which contains instruction's |
1110 // position and operands' positions. | 1169 // position and operands' positions. |
1111 // TODO(vegorov): what we really want to track here is a combination of | 1170 // TODO(vegorov): what we really want to track here is a combination of |
Yang
2014/02/12 17:32:06
Is this still a TODO?
Vyacheslav Egorov (Chromium)
2014/02/13 16:17:43
Done.
| |
1112 // source position and a script id because cross script inlining can easily | 1171 // source position and a script id because cross script inlining can easily |
1113 // result in optimized functions composed of several scripts. | 1172 // result in optimized functions composed of several scripts. |
1114 class HPositionInfo { | 1173 class HPositionInfo { |
1115 public: | 1174 public: |
1116 explicit HPositionInfo(int pos) : data_(TagPosition(pos)) { } | 1175 explicit HPositionInfo(int pos) : data_(TagPosition(pos)) { } |
1117 | 1176 |
1118 int position() const { | 1177 HSourcePosition position() const { |
1119 if (has_operand_positions()) { | 1178 if (has_operand_positions()) { |
1120 return static_cast<int>(operand_positions()[kInstructionPosIndex]); | 1179 return operand_positions()[kInstructionPosIndex]; |
1121 } | 1180 } |
1122 return static_cast<int>(UntagPosition(data_)); | 1181 return HSourcePosition(static_cast<int>(UntagPosition(data_))); |
1123 } | 1182 } |
1124 | 1183 |
1125 void set_position(int pos) { | 1184 void set_position(HSourcePosition pos) { |
1126 if (has_operand_positions()) { | 1185 if (has_operand_positions()) { |
1127 operand_positions()[kInstructionPosIndex] = pos; | 1186 operand_positions()[kInstructionPosIndex] = pos; |
1128 } else { | 1187 } else { |
1129 data_ = TagPosition(pos); | 1188 data_ = TagPosition(pos.raw()); |
1130 } | 1189 } |
1131 } | 1190 } |
1132 | 1191 |
1133 void ensure_storage_for_operand_positions(Zone* zone, int operand_count) { | 1192 void ensure_storage_for_operand_positions(Zone* zone, int operand_count) { |
1134 if (has_operand_positions()) { | 1193 if (has_operand_positions()) { |
1135 return; | 1194 return; |
1136 } | 1195 } |
1137 | 1196 |
1138 const int length = kFirstOperandPosIndex + operand_count; | 1197 const int length = kFirstOperandPosIndex + operand_count; |
1139 intptr_t* positions = | 1198 HSourcePosition* positions = |
1140 zone->NewArray<intptr_t>(length); | 1199 zone->NewArray<HSourcePosition>(length); |
1141 for (int i = 0; i < length; i++) { | 1200 for (int i = 0; i < length; i++) { |
1142 positions[i] = RelocInfo::kNoPosition; | 1201 positions[i] = HSourcePosition::Unknown(); |
1143 } | 1202 } |
1144 | 1203 |
1145 const int pos = position(); | 1204 const HSourcePosition pos = position(); |
1146 data_ = reinterpret_cast<intptr_t>(positions); | 1205 data_ = reinterpret_cast<intptr_t>(positions); |
1147 set_position(pos); | 1206 set_position(pos); |
1148 | 1207 |
1149 ASSERT(has_operand_positions()); | 1208 ASSERT(has_operand_positions()); |
1150 } | 1209 } |
1151 | 1210 |
1152 int operand_position(int idx) const { | 1211 HSourcePosition operand_position(int idx) const { |
1153 if (!has_operand_positions()) { | 1212 if (!has_operand_positions()) { |
1154 return position(); | 1213 return position(); |
1155 } | 1214 } |
1156 return static_cast<int>(*operand_position_slot(idx)); | 1215 return *operand_position_slot(idx); |
1157 } | 1216 } |
1158 | 1217 |
1159 void set_operand_position(int idx, int pos) { | 1218 void set_operand_position(int idx, HSourcePosition pos) { |
1160 *operand_position_slot(idx) = pos; | 1219 *operand_position_slot(idx) = pos; |
1161 } | 1220 } |
1162 | 1221 |
1163 private: | 1222 private: |
1164 static const intptr_t kInstructionPosIndex = 0; | 1223 static const intptr_t kInstructionPosIndex = 0; |
1165 static const intptr_t kFirstOperandPosIndex = 1; | 1224 static const intptr_t kFirstOperandPosIndex = 1; |
1166 | 1225 |
1167 intptr_t* operand_position_slot(int idx) const { | 1226 HSourcePosition* operand_position_slot(int idx) const { |
1168 ASSERT(has_operand_positions()); | 1227 ASSERT(has_operand_positions()); |
1169 return &(operand_positions()[kFirstOperandPosIndex + idx]); | 1228 return &(operand_positions()[kFirstOperandPosIndex + idx]); |
1170 } | 1229 } |
1171 | 1230 |
1172 bool has_operand_positions() const { | 1231 bool has_operand_positions() const { |
1173 return !IsTaggedPosition(data_); | 1232 return !IsTaggedPosition(data_); |
1174 } | 1233 } |
1175 | 1234 |
1176 intptr_t* operand_positions() const { | 1235 HSourcePosition* operand_positions() const { |
1177 ASSERT(has_operand_positions()); | 1236 ASSERT(has_operand_positions()); |
1178 return reinterpret_cast<intptr_t*>(data_); | 1237 return reinterpret_cast<HSourcePosition*>(data_); |
1179 } | 1238 } |
1180 | 1239 |
1181 static const intptr_t kPositionTag = 1; | 1240 static const intptr_t kPositionTag = 1; |
1182 static const intptr_t kPositionShift = 1; | 1241 static const intptr_t kPositionShift = 1; |
1183 static bool IsTaggedPosition(intptr_t val) { | 1242 static bool IsTaggedPosition(intptr_t val) { |
1184 return (val & kPositionTag) != 0; | 1243 return (val & kPositionTag) != 0; |
1185 } | 1244 } |
1186 static intptr_t UntagPosition(intptr_t val) { | 1245 static intptr_t UntagPosition(intptr_t val) { |
1187 ASSERT(IsTaggedPosition(val)); | 1246 ASSERT(IsTaggedPosition(val)); |
1188 return val >> kPositionShift; | 1247 return val >> kPositionShift; |
1189 } | 1248 } |
1190 static intptr_t TagPosition(intptr_t val) { | 1249 static intptr_t TagPosition(intptr_t val) { |
1191 const intptr_t result = (val << kPositionShift) | kPositionTag; | 1250 const intptr_t result = (val << kPositionShift) | kPositionTag; |
Yang
2014/02/12 17:32:06
The way the bit fields in HSourcePosition are defi
Vyacheslav Egorov (Chromium)
2014/02/13 16:17:43
Good catch!
I was using 31 bits originally to avo
| |
1192 ASSERT(UntagPosition(result) == val); | 1251 ASSERT(UntagPosition(result) == val); |
1193 return result; | 1252 return result; |
1194 } | 1253 } |
1195 | 1254 |
1196 intptr_t data_; | 1255 intptr_t data_; |
1197 }; | 1256 }; |
1198 | 1257 |
1199 | 1258 |
1200 class HInstruction : public HValue { | 1259 class HInstruction : public HValue { |
1201 public: | 1260 public: |
1202 HInstruction* next() const { return next_; } | 1261 HInstruction* next() const { return next_; } |
1203 HInstruction* previous() const { return previous_; } | 1262 HInstruction* previous() const { return previous_; } |
1204 | 1263 |
1205 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; | 1264 virtual void PrintTo(StringStream* stream) V8_OVERRIDE; |
1206 virtual void PrintDataTo(StringStream* stream); | 1265 virtual void PrintDataTo(StringStream* stream); |
1207 | 1266 |
1208 bool IsLinked() const { return block() != NULL; } | 1267 bool IsLinked() const { return block() != NULL; } |
1209 void Unlink(); | 1268 void Unlink(); |
1210 void InsertBefore(HInstruction* next); | 1269 void InsertBefore(HInstruction* next); |
1211 void InsertAfter(HInstruction* previous); | 1270 void InsertAfter(HInstruction* previous); |
1212 | 1271 |
1213 // The position is a write-once variable. | 1272 // The position is a write-once variable. |
1214 virtual int position() const V8_OVERRIDE { | 1273 virtual HSourcePosition position() const V8_OVERRIDE { |
1215 return position_.position(); | 1274 return HSourcePosition(position_.position()); |
1216 } | 1275 } |
1217 bool has_position() const { | 1276 bool has_position() const { |
1218 return position_.position() != RelocInfo::kNoPosition; | 1277 return !position().IsUnknown(); |
1219 } | 1278 } |
1220 void set_position(int position) { | 1279 void set_position(HSourcePosition position) { |
1221 ASSERT(!has_position()); | 1280 ASSERT(!has_position()); |
1222 ASSERT(position != RelocInfo::kNoPosition); | 1281 ASSERT(!position.IsUnknown()); |
1223 position_.set_position(position); | 1282 position_.set_position(position); |
1224 } | 1283 } |
1225 | 1284 |
1226 virtual int operand_position(int index) const V8_OVERRIDE { | 1285 virtual HSourcePosition operand_position(int index) const V8_OVERRIDE { |
1227 const int pos = position_.operand_position(index); | 1286 const HSourcePosition pos = position_.operand_position(index); |
1228 return (pos != RelocInfo::kNoPosition) ? pos : position(); | 1287 return pos.IsUnknown() ? position() : pos; |
1229 } | 1288 } |
1230 void set_operand_position(Zone* zone, int index, int pos) { | 1289 void set_operand_position(Zone* zone, int index, HSourcePosition pos) { |
1231 ASSERT(0 <= index && index < OperandCount()); | 1290 ASSERT(0 <= index && index < OperandCount()); |
1232 position_.ensure_storage_for_operand_positions(zone, OperandCount()); | 1291 position_.ensure_storage_for_operand_positions(zone, OperandCount()); |
1233 position_.set_operand_position(index, pos); | 1292 position_.set_operand_position(index, pos); |
1234 } | 1293 } |
1235 | 1294 |
1236 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } | 1295 bool CanTruncateToInt32() const { return CheckFlag(kTruncatingToInt32); } |
1237 | 1296 |
1238 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; | 1297 virtual LInstruction* CompileToLithium(LChunkBuilder* builder) = 0; |
1239 | 1298 |
1240 #ifdef DEBUG | 1299 #ifdef DEBUG |
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3271 virtual HValue* OperandAt(int index) const V8_OVERRIDE { | 3330 virtual HValue* OperandAt(int index) const V8_OVERRIDE { |
3272 return inputs_[index]; | 3331 return inputs_[index]; |
3273 } | 3332 } |
3274 HValue* GetRedundantReplacement(); | 3333 HValue* GetRedundantReplacement(); |
3275 void AddInput(HValue* value); | 3334 void AddInput(HValue* value); |
3276 bool HasRealUses(); | 3335 bool HasRealUses(); |
3277 | 3336 |
3278 bool IsReceiver() const { return merged_index_ == 0; } | 3337 bool IsReceiver() const { return merged_index_ == 0; } |
3279 bool HasMergedIndex() const { return merged_index_ != kInvalidMergedIndex; } | 3338 bool HasMergedIndex() const { return merged_index_ != kInvalidMergedIndex; } |
3280 | 3339 |
3281 virtual int position() const V8_OVERRIDE; | 3340 virtual HSourcePosition position() const V8_OVERRIDE; |
3282 | 3341 |
3283 int merged_index() const { return merged_index_; } | 3342 int merged_index() const { return merged_index_; } |
3284 | 3343 |
3285 InductionVariableData* induction_variable_data() { | 3344 InductionVariableData* induction_variable_data() { |
3286 return induction_variable_data_; | 3345 return induction_variable_data_; |
3287 } | 3346 } |
3288 bool IsInductionVariable() { | 3347 bool IsInductionVariable() { |
3289 return induction_variable_data_ != NULL; | 3348 return induction_variable_data_ != NULL; |
3290 } | 3349 } |
3291 bool IsLimitedInductionVariable() { | 3350 bool IsLimitedInductionVariable() { |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3808 | 3867 |
3809 virtual bool IsCommutative() const { return false; } | 3868 virtual bool IsCommutative() const { return false; } |
3810 | 3869 |
3811 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 3870 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
3812 | 3871 |
3813 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 3872 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
3814 if (index == 0) return Representation::Tagged(); | 3873 if (index == 0) return Representation::Tagged(); |
3815 return representation(); | 3874 return representation(); |
3816 } | 3875 } |
3817 | 3876 |
3818 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { | 3877 void SetOperandPositions(Zone* zone, |
3878 HSourcePosition left_pos, | |
3879 HSourcePosition right_pos) { | |
3819 set_operand_position(zone, 1, left_pos); | 3880 set_operand_position(zone, 1, left_pos); |
3820 set_operand_position(zone, 2, right_pos); | 3881 set_operand_position(zone, 2, right_pos); |
3821 } | 3882 } |
3822 | 3883 |
3823 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) | 3884 DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation) |
3824 | 3885 |
3825 private: | 3886 private: |
3826 bool IgnoreObservedOutputRepresentation(Representation current_rep); | 3887 bool IgnoreObservedOutputRepresentation(Representation current_rep); |
3827 | 3888 |
3828 Representation observed_input_representation_[2]; | 3889 Representation observed_input_representation_[2]; |
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4248 HInferRepresentationPhase* h_infer) V8_OVERRIDE; | 4309 HInferRepresentationPhase* h_infer) V8_OVERRIDE; |
4249 | 4310 |
4250 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { | 4311 virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE { |
4251 return representation(); | 4312 return representation(); |
4252 } | 4313 } |
4253 virtual Representation observed_input_representation(int index) V8_OVERRIDE { | 4314 virtual Representation observed_input_representation(int index) V8_OVERRIDE { |
4254 return observed_input_representation_[index]; | 4315 return observed_input_representation_[index]; |
4255 } | 4316 } |
4256 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; | 4317 virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; |
4257 | 4318 |
4258 void SetOperandPositions(Zone* zone, int left_pos, int right_pos) { | 4319 void SetOperandPositions(Zone* zone, |
4320 HSourcePosition left_pos, | |
4321 HSourcePosition right_pos) { | |
4259 set_operand_position(zone, 0, left_pos); | 4322 set_operand_position(zone, 0, left_pos); |
4260 set_operand_position(zone, 1, right_pos); | 4323 set_operand_position(zone, 1, right_pos); |
4261 } | 4324 } |
4262 | 4325 |
4263 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) | 4326 DECLARE_CONCRETE_INSTRUCTION(CompareNumericAndBranch) |
4264 | 4327 |
4265 private: | 4328 private: |
4266 HCompareNumericAndBranch(HValue* left, | 4329 HCompareNumericAndBranch(HValue* left, |
4267 HValue* right, | 4330 HValue* right, |
4268 Token::Value token, | 4331 Token::Value token, |
(...skipping 3286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7555 virtual bool IsDeletable() const V8_OVERRIDE { return true; } | 7618 virtual bool IsDeletable() const V8_OVERRIDE { return true; } |
7556 }; | 7619 }; |
7557 | 7620 |
7558 | 7621 |
7559 #undef DECLARE_INSTRUCTION | 7622 #undef DECLARE_INSTRUCTION |
7560 #undef DECLARE_CONCRETE_INSTRUCTION | 7623 #undef DECLARE_CONCRETE_INSTRUCTION |
7561 | 7624 |
7562 } } // namespace v8::internal | 7625 } } // namespace v8::internal |
7563 | 7626 |
7564 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ | 7627 #endif // V8_HYDROGEN_INSTRUCTIONS_H_ |
OLD | NEW |