| 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 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 511 |
| 512 struct PrintableParallelMove { | 512 struct PrintableParallelMove { |
| 513 const RegisterConfiguration* register_configuration_; | 513 const RegisterConfiguration* register_configuration_; |
| 514 const ParallelMove* parallel_move_; | 514 const ParallelMove* parallel_move_; |
| 515 }; | 515 }; |
| 516 | 516 |
| 517 | 517 |
| 518 std::ostream& operator<<(std::ostream& os, const PrintableParallelMove& pm); | 518 std::ostream& operator<<(std::ostream& os, const PrintableParallelMove& pm); |
| 519 | 519 |
| 520 | 520 |
| 521 class PointerMap FINAL : public ZoneObject { | 521 class ReferenceMap FINAL : public ZoneObject { |
| 522 public: | 522 public: |
| 523 explicit PointerMap(Zone* zone) | 523 explicit ReferenceMap(Zone* zone) |
| 524 : pointer_operands_(8, zone), | 524 : reference_operands_(8, zone), instruction_position_(-1) {} |
| 525 untagged_operands_(0, zone), | |
| 526 instruction_position_(-1) {} | |
| 527 | 525 |
| 528 const ZoneList<InstructionOperand*>* GetNormalizedOperands() { | 526 const ZoneVector<InstructionOperand>& reference_operands() const { |
| 529 for (int i = 0; i < untagged_operands_.length(); ++i) { | 527 return reference_operands_; |
| 530 RemovePointer(untagged_operands_[i]); | |
| 531 } | |
| 532 untagged_operands_.Clear(); | |
| 533 return &pointer_operands_; | |
| 534 } | 528 } |
| 535 int instruction_position() const { return instruction_position_; } | 529 int instruction_position() const { return instruction_position_; } |
| 536 | 530 |
| 537 void set_instruction_position(int pos) { | 531 void set_instruction_position(int pos) { |
| 538 DCHECK(instruction_position_ == -1); | 532 DCHECK(instruction_position_ == -1); |
| 539 instruction_position_ = pos; | 533 instruction_position_ = pos; |
| 540 } | 534 } |
| 541 | 535 |
| 542 void RecordPointer(InstructionOperand* op, Zone* zone); | 536 void RecordReference(const InstructionOperand& op); |
| 543 void RemovePointer(InstructionOperand* op); | |
| 544 void RecordUntagged(InstructionOperand* op, Zone* zone); | |
| 545 | 537 |
| 546 private: | 538 private: |
| 547 friend std::ostream& operator<<(std::ostream& os, const PointerMap& pm); | 539 friend std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm); |
| 548 | 540 |
| 549 ZoneList<InstructionOperand*> pointer_operands_; | 541 ZoneVector<InstructionOperand> reference_operands_; |
| 550 ZoneList<InstructionOperand*> untagged_operands_; | |
| 551 int instruction_position_; | 542 int instruction_position_; |
| 552 }; | 543 }; |
| 553 | 544 |
| 554 std::ostream& operator<<(std::ostream& os, const PointerMap& pm); | 545 std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm); |
| 555 | 546 |
| 556 // TODO(titzer): s/PointerMap/ReferenceMap/ | |
| 557 class Instruction { | 547 class Instruction { |
| 558 public: | 548 public: |
| 559 size_t OutputCount() const { return OutputCountField::decode(bit_field_); } | 549 size_t OutputCount() const { return OutputCountField::decode(bit_field_); } |
| 560 const InstructionOperand* OutputAt(size_t i) const { | 550 const InstructionOperand* OutputAt(size_t i) const { |
| 561 DCHECK(i < OutputCount()); | 551 DCHECK(i < OutputCount()); |
| 562 return &operands_[i]; | 552 return &operands_[i]; |
| 563 } | 553 } |
| 564 InstructionOperand* OutputAt(size_t i) { | 554 InstructionOperand* OutputAt(size_t i) { |
| 565 DCHECK(i < OutputCount()); | 555 DCHECK(i < OutputCount()); |
| 566 return &operands_[i]; | 556 return &operands_[i]; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 total_extra_ops * sizeof(InstructionOperand)); | 610 total_extra_ops * sizeof(InstructionOperand)); |
| 621 return new (zone->New(size)) Instruction( | 611 return new (zone->New(size)) Instruction( |
| 622 opcode, output_count, outputs, input_count, inputs, temp_count, temps); | 612 opcode, output_count, outputs, input_count, inputs, temp_count, temps); |
| 623 } | 613 } |
| 624 | 614 |
| 625 Instruction* MarkAsCall() { | 615 Instruction* MarkAsCall() { |
| 626 bit_field_ = IsCallField::update(bit_field_, true); | 616 bit_field_ = IsCallField::update(bit_field_, true); |
| 627 return this; | 617 return this; |
| 628 } | 618 } |
| 629 bool IsCall() const { return IsCallField::decode(bit_field_); } | 619 bool IsCall() const { return IsCallField::decode(bit_field_); } |
| 630 bool NeedsPointerMap() const { return IsCall(); } | 620 bool NeedsReferenceMap() const { return IsCall(); } |
| 631 bool HasPointerMap() const { return pointer_map_ != NULL; } | 621 bool HasReferenceMap() const { return reference_map_ != NULL; } |
| 632 | 622 |
| 633 bool IsSourcePosition() const { | 623 bool IsSourcePosition() const { |
| 634 return opcode() == kSourcePositionInstruction; | 624 return opcode() == kSourcePositionInstruction; |
| 635 } | 625 } |
| 636 | 626 |
| 637 bool ClobbersRegisters() const { return IsCall(); } | 627 bool ClobbersRegisters() const { return IsCall(); } |
| 638 bool ClobbersTemps() const { return IsCall(); } | 628 bool ClobbersTemps() const { return IsCall(); } |
| 639 bool ClobbersDoubleRegisters() const { return IsCall(); } | 629 bool ClobbersDoubleRegisters() const { return IsCall(); } |
| 640 PointerMap* pointer_map() const { return pointer_map_; } | 630 ReferenceMap* reference_map() const { return reference_map_; } |
| 641 | 631 |
| 642 void set_pointer_map(PointerMap* map) { | 632 void set_reference_map(ReferenceMap* map) { |
| 643 DCHECK(NeedsPointerMap()); | 633 DCHECK(NeedsReferenceMap()); |
| 644 DCHECK(!pointer_map_); | 634 DCHECK(!reference_map_); |
| 645 pointer_map_ = map; | 635 reference_map_ = map; |
| 646 } | 636 } |
| 647 | 637 |
| 648 void OverwriteWithNop() { | 638 void OverwriteWithNop() { |
| 649 opcode_ = ArchOpcodeField::encode(kArchNop); | 639 opcode_ = ArchOpcodeField::encode(kArchNop); |
| 650 bit_field_ = 0; | 640 bit_field_ = 0; |
| 651 pointer_map_ = NULL; | 641 reference_map_ = NULL; |
| 652 } | 642 } |
| 653 | 643 |
| 654 bool IsNop() const { | 644 bool IsNop() const { |
| 655 return arch_opcode() == kArchNop && InputCount() == 0 && | 645 return arch_opcode() == kArchNop && InputCount() == 0 && |
| 656 OutputCount() == 0 && TempCount() == 0; | 646 OutputCount() == 0 && TempCount() == 0; |
| 657 } | 647 } |
| 658 | 648 |
| 659 enum GapPosition { | 649 enum GapPosition { |
| 660 START, | 650 START, |
| 661 END, | 651 END, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 InstructionOperand* temps); | 683 InstructionOperand* temps); |
| 694 | 684 |
| 695 typedef BitField<size_t, 0, 8> OutputCountField; | 685 typedef BitField<size_t, 0, 8> OutputCountField; |
| 696 typedef BitField<size_t, 8, 16> InputCountField; | 686 typedef BitField<size_t, 8, 16> InputCountField; |
| 697 typedef BitField<size_t, 24, 6> TempCountField; | 687 typedef BitField<size_t, 24, 6> TempCountField; |
| 698 typedef BitField<bool, 30, 1> IsCallField; | 688 typedef BitField<bool, 30, 1> IsCallField; |
| 699 | 689 |
| 700 InstructionCode opcode_; | 690 InstructionCode opcode_; |
| 701 uint32_t bit_field_; | 691 uint32_t bit_field_; |
| 702 ParallelMove* parallel_moves_[2]; | 692 ParallelMove* parallel_moves_[2]; |
| 703 PointerMap* pointer_map_; | 693 ReferenceMap* reference_map_; |
| 704 InstructionOperand operands_[1]; | 694 InstructionOperand operands_[1]; |
| 705 | 695 |
| 706 private: | 696 private: |
| 707 DISALLOW_COPY_AND_ASSIGN(Instruction); | 697 DISALLOW_COPY_AND_ASSIGN(Instruction); |
| 708 }; | 698 }; |
| 709 | 699 |
| 710 | 700 |
| 711 struct PrintableInstruction { | 701 struct PrintableInstruction { |
| 712 const RegisterConfiguration* register_configuration_; | 702 const RegisterConfiguration* register_configuration_; |
| 713 const Instruction* instr_; | 703 const Instruction* instr_; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 int32_t code_start_; // start index of arch-specific code. | 970 int32_t code_start_; // start index of arch-specific code. |
| 981 int32_t code_end_; // end index of arch-specific code. | 971 int32_t code_end_; // end index of arch-specific code. |
| 982 const bool deferred_; // Block contains deferred code. | 972 const bool deferred_; // Block contains deferred code. |
| 983 }; | 973 }; |
| 984 | 974 |
| 985 typedef ZoneDeque<Constant> ConstantDeque; | 975 typedef ZoneDeque<Constant> ConstantDeque; |
| 986 typedef std::map<int, Constant, std::less<int>, | 976 typedef std::map<int, Constant, std::less<int>, |
| 987 zone_allocator<std::pair<int, Constant> > > ConstantMap; | 977 zone_allocator<std::pair<int, Constant> > > ConstantMap; |
| 988 | 978 |
| 989 typedef ZoneDeque<Instruction*> InstructionDeque; | 979 typedef ZoneDeque<Instruction*> InstructionDeque; |
| 990 typedef ZoneDeque<PointerMap*> PointerMapDeque; | 980 typedef ZoneDeque<ReferenceMap*> ReferenceMapDeque; |
| 991 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; | 981 typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector; |
| 992 typedef ZoneVector<InstructionBlock*> InstructionBlocks; | 982 typedef ZoneVector<InstructionBlock*> InstructionBlocks; |
| 993 | 983 |
| 994 struct PrintableInstructionSequence; | 984 struct PrintableInstructionSequence; |
| 995 | 985 |
| 996 | 986 |
| 997 // Represents architecture-specific generated code before, during, and after | 987 // Represents architecture-specific generated code before, during, and after |
| 998 // register allocation. | 988 // register allocation. |
| 999 // TODO(titzer): s/IsDouble/IsFloat64/ | 989 // TODO(titzer): s/IsDouble/IsFloat64/ |
| 1000 class InstructionSequence FINAL : public ZoneObject { | 990 class InstructionSequence FINAL : public ZoneObject { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1046 const_iterator end() const { return instructions_.end(); } | 1036 const_iterator end() const { return instructions_.end(); } |
| 1047 const InstructionDeque& instructions() const { return instructions_; } | 1037 const InstructionDeque& instructions() const { return instructions_; } |
| 1048 | 1038 |
| 1049 Instruction* InstructionAt(int index) const { | 1039 Instruction* InstructionAt(int index) const { |
| 1050 DCHECK(index >= 0); | 1040 DCHECK(index >= 0); |
| 1051 DCHECK(index < static_cast<int>(instructions_.size())); | 1041 DCHECK(index < static_cast<int>(instructions_.size())); |
| 1052 return instructions_[index]; | 1042 return instructions_[index]; |
| 1053 } | 1043 } |
| 1054 | 1044 |
| 1055 Isolate* isolate() const { return isolate_; } | 1045 Isolate* isolate() const { return isolate_; } |
| 1056 const PointerMapDeque* pointer_maps() const { return &pointer_maps_; } | 1046 const ReferenceMapDeque* reference_maps() const { return &reference_maps_; } |
| 1057 Zone* zone() const { return zone_; } | 1047 Zone* zone() const { return zone_; } |
| 1058 | 1048 |
| 1059 // Used by the instruction selector while adding instructions. | 1049 // Used by the instruction selector while adding instructions. |
| 1060 int AddInstruction(Instruction* instr); | 1050 int AddInstruction(Instruction* instr); |
| 1061 void StartBlock(RpoNumber rpo); | 1051 void StartBlock(RpoNumber rpo); |
| 1062 void EndBlock(RpoNumber rpo); | 1052 void EndBlock(RpoNumber rpo); |
| 1063 | 1053 |
| 1064 int AddConstant(int virtual_register, Constant constant) { | 1054 int AddConstant(int virtual_register, Constant constant) { |
| 1065 // TODO(titzer): allow RPO numbers as constants? | 1055 // TODO(titzer): allow RPO numbers as constants? |
| 1066 DCHECK(constant.type() != Constant::kRpoNumber); | 1056 DCHECK(constant.type() != Constant::kRpoNumber); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; | 1116 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; |
| 1127 | 1117 |
| 1128 Isolate* isolate_; | 1118 Isolate* isolate_; |
| 1129 Zone* const zone_; | 1119 Zone* const zone_; |
| 1130 InstructionBlocks* const instruction_blocks_; | 1120 InstructionBlocks* const instruction_blocks_; |
| 1131 IntVector block_starts_; | 1121 IntVector block_starts_; |
| 1132 ConstantMap constants_; | 1122 ConstantMap constants_; |
| 1133 Immediates immediates_; | 1123 Immediates immediates_; |
| 1134 InstructionDeque instructions_; | 1124 InstructionDeque instructions_; |
| 1135 int next_virtual_register_; | 1125 int next_virtual_register_; |
| 1136 PointerMapDeque pointer_maps_; | 1126 ReferenceMapDeque reference_maps_; |
| 1137 VirtualRegisterSet doubles_; | 1127 VirtualRegisterSet doubles_; |
| 1138 VirtualRegisterSet references_; | 1128 VirtualRegisterSet references_; |
| 1139 DeoptimizationVector deoptimization_entries_; | 1129 DeoptimizationVector deoptimization_entries_; |
| 1140 | 1130 |
| 1141 DISALLOW_COPY_AND_ASSIGN(InstructionSequence); | 1131 DISALLOW_COPY_AND_ASSIGN(InstructionSequence); |
| 1142 }; | 1132 }; |
| 1143 | 1133 |
| 1144 | 1134 |
| 1145 struct PrintableInstructionSequence { | 1135 struct PrintableInstructionSequence { |
| 1146 const RegisterConfiguration* register_configuration_; | 1136 const RegisterConfiguration* register_configuration_; |
| 1147 const InstructionSequence* sequence_; | 1137 const InstructionSequence* sequence_; |
| 1148 }; | 1138 }; |
| 1149 | 1139 |
| 1150 | 1140 |
| 1151 std::ostream& operator<<(std::ostream& os, | 1141 std::ostream& operator<<(std::ostream& os, |
| 1152 const PrintableInstructionSequence& code); | 1142 const PrintableInstructionSequence& code); |
| 1153 | 1143 |
| 1154 } // namespace compiler | 1144 } // namespace compiler |
| 1155 } // namespace internal | 1145 } // namespace internal |
| 1156 } // namespace v8 | 1146 } // namespace v8 |
| 1157 | 1147 |
| 1158 #endif // V8_COMPILER_INSTRUCTION_H_ | 1148 #endif // V8_COMPILER_INSTRUCTION_H_ |
| OLD | NEW |