| 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 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 434 } |
| 435 | 435 |
| 436 bool HasOutput() const { return OutputCount() == 1; } | 436 bool HasOutput() const { return OutputCount() == 1; } |
| 437 InstructionOperand* Output() const { return OutputAt(0); } | 437 InstructionOperand* Output() const { return OutputAt(0); } |
| 438 | 438 |
| 439 size_t InputCount() const { return InputCountField::decode(bit_field_); } | 439 size_t InputCount() const { return InputCountField::decode(bit_field_); } |
| 440 InstructionOperand* InputAt(size_t i) const { | 440 InstructionOperand* InputAt(size_t i) const { |
| 441 DCHECK(i < InputCount()); | 441 DCHECK(i < InputCount()); |
| 442 return operands_[OutputCount() + i]; | 442 return operands_[OutputCount() + i]; |
| 443 } | 443 } |
| 444 void SetInputAt(size_t i, InstructionOperand* operand) { |
| 445 DCHECK(i < InputCount()); |
| 446 operands_[OutputCount() + i] = operand; |
| 447 } |
| 444 | 448 |
| 445 size_t TempCount() const { return TempCountField::decode(bit_field_); } | 449 size_t TempCount() const { return TempCountField::decode(bit_field_); } |
| 446 InstructionOperand* TempAt(size_t i) const { | 450 InstructionOperand* TempAt(size_t i) const { |
| 447 DCHECK(i < TempCount()); | 451 DCHECK(i < TempCount()); |
| 448 return operands_[OutputCount() + InputCount() + i]; | 452 return operands_[OutputCount() + InputCount() + i]; |
| 449 } | 453 } |
| 450 | 454 |
| 451 InstructionCode opcode() const { return opcode_; } | 455 InstructionCode opcode() const { return opcode_; } |
| 452 ArchOpcode arch_opcode() const { return ArchOpcodeField::decode(opcode()); } | 456 ArchOpcode arch_opcode() const { return ArchOpcodeField::decode(opcode()); } |
| 453 AddressingMode addressing_mode() const { | 457 AddressingMode addressing_mode() const { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 DCHECK_EQ(NULL, pointer_map_); | 517 DCHECK_EQ(NULL, pointer_map_); |
| 514 pointer_map_ = map; | 518 pointer_map_ = map; |
| 515 } | 519 } |
| 516 | 520 |
| 517 // Placement new operator so that we can smash instructions into | 521 // Placement new operator so that we can smash instructions into |
| 518 // zone-allocated memory. | 522 // zone-allocated memory. |
| 519 void* operator new(size_t, void* location) { return location; } | 523 void* operator new(size_t, void* location) { return location; } |
| 520 | 524 |
| 521 void operator delete(void* pointer, void* location) { UNREACHABLE(); } | 525 void operator delete(void* pointer, void* location) { UNREACHABLE(); } |
| 522 | 526 |
| 527 void OverwriteWithNop() { |
| 528 opcode_ = ArchOpcodeField::encode(kArchNop); |
| 529 bit_field_ = 0; |
| 530 pointer_map_ = NULL; |
| 531 } |
| 532 |
| 523 protected: | 533 protected: |
| 524 explicit Instruction(InstructionCode opcode) | 534 explicit Instruction(InstructionCode opcode) |
| 525 : opcode_(opcode), | 535 : opcode_(opcode), |
| 526 bit_field_(OutputCountField::encode(0) | InputCountField::encode(0) | | 536 bit_field_(OutputCountField::encode(0) | InputCountField::encode(0) | |
| 527 TempCountField::encode(0) | IsCallField::encode(false) | | 537 TempCountField::encode(0) | IsCallField::encode(false) | |
| 528 IsControlField::encode(false)), | 538 IsControlField::encode(false)), |
| 529 pointer_map_(NULL) {} | 539 pointer_map_(NULL) {} |
| 530 | 540 |
| 531 Instruction(InstructionCode opcode, size_t output_count, | 541 Instruction(InstructionCode opcode, size_t output_count, |
| 532 InstructionOperand** outputs, size_t input_count, | 542 InstructionOperand** outputs, size_t input_count, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 } | 602 } |
| 593 | 603 |
| 594 ParallelMove* GetParallelMove(InnerPosition pos) { | 604 ParallelMove* GetParallelMove(InnerPosition pos) { |
| 595 return parallel_moves_[pos]; | 605 return parallel_moves_[pos]; |
| 596 } | 606 } |
| 597 | 607 |
| 598 const ParallelMove* GetParallelMove(InnerPosition pos) const { | 608 const ParallelMove* GetParallelMove(InnerPosition pos) const { |
| 599 return parallel_moves_[pos]; | 609 return parallel_moves_[pos]; |
| 600 } | 610 } |
| 601 | 611 |
| 612 bool IsRedundant() const; |
| 613 |
| 602 static GapInstruction* New(Zone* zone) { | 614 static GapInstruction* New(Zone* zone) { |
| 603 void* buffer = zone->New(sizeof(GapInstruction)); | 615 void* buffer = zone->New(sizeof(GapInstruction)); |
| 604 return new (buffer) GapInstruction(kGapInstruction); | 616 return new (buffer) GapInstruction(kGapInstruction); |
| 605 } | 617 } |
| 606 | 618 |
| 607 static GapInstruction* cast(Instruction* instr) { | 619 static GapInstruction* cast(Instruction* instr) { |
| 608 DCHECK(instr->IsGapMoves()); | 620 DCHECK(instr->IsGapMoves()); |
| 609 return static_cast<GapInstruction*>(instr); | 621 return static_cast<GapInstruction*>(instr); |
| 610 } | 622 } |
| 611 | 623 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 878 | 890 |
| 879 typedef ZoneVector<BasicBlock::RpoNumber> Successors; | 891 typedef ZoneVector<BasicBlock::RpoNumber> Successors; |
| 880 Successors& successors() { return successors_; } | 892 Successors& successors() { return successors_; } |
| 881 const Successors& successors() const { return successors_; } | 893 const Successors& successors() const { return successors_; } |
| 882 size_t SuccessorCount() const { return successors_.size(); } | 894 size_t SuccessorCount() const { return successors_.size(); } |
| 883 | 895 |
| 884 typedef ZoneVector<PhiInstruction*> PhiInstructions; | 896 typedef ZoneVector<PhiInstruction*> PhiInstructions; |
| 885 const PhiInstructions& phis() const { return phis_; } | 897 const PhiInstructions& phis() const { return phis_; } |
| 886 void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); } | 898 void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); } |
| 887 | 899 |
| 900 void set_ao_number(BasicBlock::RpoNumber ao_number) { |
| 901 ao_number_ = ao_number; |
| 902 } |
| 903 |
| 888 private: | 904 private: |
| 889 Successors successors_; | 905 Successors successors_; |
| 890 Predecessors predecessors_; | 906 Predecessors predecessors_; |
| 891 PhiInstructions phis_; | 907 PhiInstructions phis_; |
| 892 const BasicBlock::Id id_; | 908 const BasicBlock::Id id_; |
| 893 const BasicBlock::RpoNumber ao_number_; // Assembly order number. | 909 BasicBlock::RpoNumber ao_number_; // Assembly order number. |
| 894 // TODO(dcarney): probably dont't need this. | 910 // TODO(dcarney): probably dont't need this. |
| 895 const BasicBlock::RpoNumber rpo_number_; | 911 const BasicBlock::RpoNumber rpo_number_; |
| 896 const BasicBlock::RpoNumber loop_header_; | 912 const BasicBlock::RpoNumber loop_header_; |
| 897 const BasicBlock::RpoNumber loop_end_; | 913 const BasicBlock::RpoNumber loop_end_; |
| 898 int32_t code_start_; // start index of arch-specific code. | 914 int32_t code_start_; // start index of arch-specific code. |
| 899 int32_t code_end_; // end index of arch-specific code. | 915 int32_t code_end_; // end index of arch-specific code. |
| 900 const bool deferred_; // Block contains deferred code. | 916 const bool deferred_; // Block contains deferred code. |
| 901 }; | 917 }; |
| 902 | 918 |
| 903 typedef ZoneDeque<Constant> ConstantDeque; | 919 typedef ZoneDeque<Constant> ConstantDeque; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 | 1033 |
| 1018 private: | 1034 private: |
| 1019 explicit StateId(int id) : id_(id) {} | 1035 explicit StateId(int id) : id_(id) {} |
| 1020 int id_; | 1036 int id_; |
| 1021 }; | 1037 }; |
| 1022 | 1038 |
| 1023 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); | 1039 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); |
| 1024 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); | 1040 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); |
| 1025 int GetFrameStateDescriptorCount(); | 1041 int GetFrameStateDescriptorCount(); |
| 1026 | 1042 |
| 1043 BasicBlock::RpoNumber InputRpo(Instruction* instr, int index) { |
| 1044 InstructionOperand* operand = instr->InputAt(index); |
| 1045 Constant constant = operand->IsImmediate() ? GetImmediate(operand->index()) |
| 1046 : GetConstant(operand->index()); |
| 1047 int rpo = constant.ToInt32(); |
| 1048 DCHECK(rpo >= 0 && rpo < static_cast<int>(instruction_blocks_->size())); |
| 1049 return BasicBlock::RpoNumber::FromInt(rpo); |
| 1050 } |
| 1051 |
| 1027 private: | 1052 private: |
| 1028 friend std::ostream& operator<<(std::ostream& os, | 1053 friend std::ostream& operator<<(std::ostream& os, |
| 1029 const PrintableInstructionSequence& code); | 1054 const PrintableInstructionSequence& code); |
| 1030 | 1055 |
| 1031 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; | 1056 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; |
| 1032 | 1057 |
| 1033 Zone* const zone_; | 1058 Zone* const zone_; |
| 1034 InstructionBlocks* const instruction_blocks_; | 1059 InstructionBlocks* const instruction_blocks_; |
| 1035 IntVector block_starts_; | 1060 IntVector block_starts_; |
| 1036 ConstantMap constants_; | 1061 ConstantMap constants_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1053 | 1078 |
| 1054 | 1079 |
| 1055 std::ostream& operator<<(std::ostream& os, | 1080 std::ostream& operator<<(std::ostream& os, |
| 1056 const PrintableInstructionSequence& code); | 1081 const PrintableInstructionSequence& code); |
| 1057 | 1082 |
| 1058 } // namespace compiler | 1083 } // namespace compiler |
| 1059 } // namespace internal | 1084 } // namespace internal |
| 1060 } // namespace v8 | 1085 } // namespace v8 |
| 1061 | 1086 |
| 1062 #endif // V8_COMPILER_INSTRUCTION_H_ | 1087 #endif // V8_COMPILER_INSTRUCTION_H_ |
| OLD | NEW |