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 |
| 533 bool IsNop() const { |
| 534 return arch_opcode() == kArchNop && InputCount() == 0 && |
| 535 OutputCount() == 0 && TempCount() == 0; |
| 536 } |
| 537 |
523 protected: | 538 protected: |
524 explicit Instruction(InstructionCode opcode) | 539 explicit Instruction(InstructionCode opcode) |
525 : opcode_(opcode), | 540 : opcode_(opcode), |
526 bit_field_(OutputCountField::encode(0) | InputCountField::encode(0) | | 541 bit_field_(OutputCountField::encode(0) | InputCountField::encode(0) | |
527 TempCountField::encode(0) | IsCallField::encode(false) | | 542 TempCountField::encode(0) | IsCallField::encode(false) | |
528 IsControlField::encode(false)), | 543 IsControlField::encode(false)), |
529 pointer_map_(NULL) {} | 544 pointer_map_(NULL) {} |
530 | 545 |
531 Instruction(InstructionCode opcode, size_t output_count, | 546 Instruction(InstructionCode opcode, size_t output_count, |
532 InstructionOperand** outputs, size_t input_count, | 547 InstructionOperand** outputs, size_t input_count, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } | 607 } |
593 | 608 |
594 ParallelMove* GetParallelMove(InnerPosition pos) { | 609 ParallelMove* GetParallelMove(InnerPosition pos) { |
595 return parallel_moves_[pos]; | 610 return parallel_moves_[pos]; |
596 } | 611 } |
597 | 612 |
598 const ParallelMove* GetParallelMove(InnerPosition pos) const { | 613 const ParallelMove* GetParallelMove(InnerPosition pos) const { |
599 return parallel_moves_[pos]; | 614 return parallel_moves_[pos]; |
600 } | 615 } |
601 | 616 |
| 617 bool IsRedundant() const; |
| 618 |
602 static GapInstruction* New(Zone* zone) { | 619 static GapInstruction* New(Zone* zone) { |
603 void* buffer = zone->New(sizeof(GapInstruction)); | 620 void* buffer = zone->New(sizeof(GapInstruction)); |
604 return new (buffer) GapInstruction(kGapInstruction); | 621 return new (buffer) GapInstruction(kGapInstruction); |
605 } | 622 } |
606 | 623 |
607 static GapInstruction* cast(Instruction* instr) { | 624 static GapInstruction* cast(Instruction* instr) { |
608 DCHECK(instr->IsGapMoves()); | 625 DCHECK(instr->IsGapMoves()); |
609 return static_cast<GapInstruction*>(instr); | 626 return static_cast<GapInstruction*>(instr); |
610 } | 627 } |
611 | 628 |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 895 |
879 typedef ZoneVector<BasicBlock::RpoNumber> Successors; | 896 typedef ZoneVector<BasicBlock::RpoNumber> Successors; |
880 Successors& successors() { return successors_; } | 897 Successors& successors() { return successors_; } |
881 const Successors& successors() const { return successors_; } | 898 const Successors& successors() const { return successors_; } |
882 size_t SuccessorCount() const { return successors_.size(); } | 899 size_t SuccessorCount() const { return successors_.size(); } |
883 | 900 |
884 typedef ZoneVector<PhiInstruction*> PhiInstructions; | 901 typedef ZoneVector<PhiInstruction*> PhiInstructions; |
885 const PhiInstructions& phis() const { return phis_; } | 902 const PhiInstructions& phis() const { return phis_; } |
886 void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); } | 903 void AddPhi(PhiInstruction* phi) { phis_.push_back(phi); } |
887 | 904 |
| 905 void set_ao_number(BasicBlock::RpoNumber ao_number) { |
| 906 ao_number_ = ao_number; |
| 907 } |
| 908 |
888 private: | 909 private: |
889 Successors successors_; | 910 Successors successors_; |
890 Predecessors predecessors_; | 911 Predecessors predecessors_; |
891 PhiInstructions phis_; | 912 PhiInstructions phis_; |
892 const BasicBlock::Id id_; | 913 const BasicBlock::Id id_; |
893 const BasicBlock::RpoNumber ao_number_; // Assembly order number. | 914 BasicBlock::RpoNumber ao_number_; // Assembly order number. |
894 // TODO(dcarney): probably dont't need this. | 915 // TODO(dcarney): probably dont't need this. |
895 const BasicBlock::RpoNumber rpo_number_; | 916 const BasicBlock::RpoNumber rpo_number_; |
896 const BasicBlock::RpoNumber loop_header_; | 917 const BasicBlock::RpoNumber loop_header_; |
897 const BasicBlock::RpoNumber loop_end_; | 918 const BasicBlock::RpoNumber loop_end_; |
898 int32_t code_start_; // start index of arch-specific code. | 919 int32_t code_start_; // start index of arch-specific code. |
899 int32_t code_end_; // end index of arch-specific code. | 920 int32_t code_end_; // end index of arch-specific code. |
900 const bool deferred_; // Block contains deferred code. | 921 const bool deferred_; // Block contains deferred code. |
901 }; | 922 }; |
902 | 923 |
903 typedef ZoneDeque<Constant> ConstantDeque; | 924 typedef ZoneDeque<Constant> ConstantDeque; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1017 | 1038 |
1018 private: | 1039 private: |
1019 explicit StateId(int id) : id_(id) {} | 1040 explicit StateId(int id) : id_(id) {} |
1020 int id_; | 1041 int id_; |
1021 }; | 1042 }; |
1022 | 1043 |
1023 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); | 1044 StateId AddFrameStateDescriptor(FrameStateDescriptor* descriptor); |
1024 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); | 1045 FrameStateDescriptor* GetFrameStateDescriptor(StateId deoptimization_id); |
1025 int GetFrameStateDescriptorCount(); | 1046 int GetFrameStateDescriptorCount(); |
1026 | 1047 |
| 1048 BasicBlock::RpoNumber InputRpo(Instruction* instr, size_t index) { |
| 1049 InstructionOperand* operand = instr->InputAt(index); |
| 1050 Constant constant = operand->IsImmediate() ? GetImmediate(operand->index()) |
| 1051 : GetConstant(operand->index()); |
| 1052 int rpo = constant.ToInt32(); |
| 1053 DCHECK(rpo >= 0 && rpo < static_cast<int>(instruction_blocks_->size())); |
| 1054 return BasicBlock::RpoNumber::FromInt(rpo); |
| 1055 } |
| 1056 |
1027 private: | 1057 private: |
1028 friend std::ostream& operator<<(std::ostream& os, | 1058 friend std::ostream& operator<<(std::ostream& os, |
1029 const PrintableInstructionSequence& code); | 1059 const PrintableInstructionSequence& code); |
1030 | 1060 |
1031 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; | 1061 typedef std::set<int, std::less<int>, ZoneIntAllocator> VirtualRegisterSet; |
1032 | 1062 |
1033 Zone* const zone_; | 1063 Zone* const zone_; |
1034 InstructionBlocks* const instruction_blocks_; | 1064 InstructionBlocks* const instruction_blocks_; |
1035 IntVector block_starts_; | 1065 IntVector block_starts_; |
1036 ConstantMap constants_; | 1066 ConstantMap constants_; |
(...skipping 16 matching lines...) Expand all Loading... |
1053 | 1083 |
1054 | 1084 |
1055 std::ostream& operator<<(std::ostream& os, | 1085 std::ostream& operator<<(std::ostream& os, |
1056 const PrintableInstructionSequence& code); | 1086 const PrintableInstructionSequence& code); |
1057 | 1087 |
1058 } // namespace compiler | 1088 } // namespace compiler |
1059 } // namespace internal | 1089 } // namespace internal |
1060 } // namespace v8 | 1090 } // namespace v8 |
1061 | 1091 |
1062 #endif // V8_COMPILER_INSTRUCTION_H_ | 1092 #endif // V8_COMPILER_INSTRUCTION_H_ |
OLD | NEW |