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 #include "src/compiler/instruction-selector.h" | 5 #include "src/compiler/instruction-selector.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/adapters.h" | 9 #include "src/base/adapters.h" |
10 #include "src/compiler/compiler-source-position-table.h" | 10 #include "src/compiler/compiler-source-position-table.h" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 120 |
121 void InstructionSelector::AddInstruction(Instruction* instr) { | 121 void InstructionSelector::AddInstruction(Instruction* instr) { |
122 if (UseInstructionScheduling()) { | 122 if (UseInstructionScheduling()) { |
123 DCHECK_NOT_NULL(scheduler_); | 123 DCHECK_NOT_NULL(scheduler_); |
124 scheduler_->AddInstruction(instr); | 124 scheduler_->AddInstruction(instr); |
125 } else { | 125 } else { |
126 sequence()->AddInstruction(instr); | 126 sequence()->AddInstruction(instr); |
127 } | 127 } |
128 } | 128 } |
129 | 129 |
130 | |
131 Instruction* InstructionSelector::Emit(InstructionCode opcode, | 130 Instruction* InstructionSelector::Emit(InstructionCode opcode, |
132 InstructionOperand output, | 131 InstructionOperand output, |
133 size_t temp_count, | 132 size_t temp_count, |
134 InstructionOperand* temps) { | 133 InstructionOperand* temps) { |
135 size_t output_count = output.IsInvalid() ? 0 : 1; | 134 size_t output_count = output.IsInvalid() ? 0 : 1; |
136 return Emit(opcode, output_count, &output, 0, nullptr, temp_count, temps); | 135 return Emit(opcode, output_count, &output, 0, nullptr, temp_count, temps); |
137 } | 136 } |
138 | 137 |
139 | 138 |
140 Instruction* InstructionSelector::Emit(InstructionCode opcode, | 139 Instruction* InstructionSelector::Emit(InstructionCode opcode, |
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 LinkageLocation saved_return_location = | 791 LinkageLocation saved_return_location = |
793 LinkageLocation::ForSavedCallerReturnAddress(); | 792 LinkageLocation::ForSavedCallerReturnAddress(); |
794 InstructionOperand return_address = | 793 InstructionOperand return_address = |
795 g.UsePointerLocation(LinkageLocation::ConvertToTailCallerLocation( | 794 g.UsePointerLocation(LinkageLocation::ConvertToTailCallerLocation( |
796 saved_return_location, stack_param_delta), | 795 saved_return_location, stack_param_delta), |
797 saved_return_location); | 796 saved_return_location); |
798 buffer->instruction_args.push_back(return_address); | 797 buffer->instruction_args.push_back(return_address); |
799 } | 798 } |
800 } | 799 } |
801 | 800 |
| 801 bool InstructionSelector::IsSourcePositionUsed(Node* node) { |
| 802 return (source_position_mode_ == kAllSourcePositions || |
| 803 node->opcode() == IrOpcode::kCall || |
| 804 node->opcode() == IrOpcode::kTrapIf || |
| 805 node->opcode() == IrOpcode::kTrapUnless); |
| 806 } |
| 807 |
802 void InstructionSelector::VisitBlock(BasicBlock* block) { | 808 void InstructionSelector::VisitBlock(BasicBlock* block) { |
803 DCHECK(!current_block_); | 809 DCHECK(!current_block_); |
804 current_block_ = block; | 810 current_block_ = block; |
805 int current_block_end = static_cast<int>(instructions_.size()); | 811 int current_block_end = static_cast<int>(instructions_.size()); |
806 | 812 |
807 int effect_level = 0; | 813 int effect_level = 0; |
808 for (Node* const node : *block) { | 814 for (Node* const node : *block) { |
809 if (node->opcode() == IrOpcode::kStore || | 815 if (node->opcode() == IrOpcode::kStore || |
810 node->opcode() == IrOpcode::kUnalignedStore || | 816 node->opcode() == IrOpcode::kUnalignedStore || |
811 node->opcode() == IrOpcode::kCheckedStore || | 817 node->opcode() == IrOpcode::kCheckedStore || |
(...skipping 21 matching lines...) Expand all Loading... |
833 if (!IsUsed(node) || IsDefined(node)) continue; | 839 if (!IsUsed(node) || IsDefined(node)) continue; |
834 // Generate code for this node "top down", but schedule the code "bottom | 840 // Generate code for this node "top down", but schedule the code "bottom |
835 // up". | 841 // up". |
836 size_t current_node_end = instructions_.size(); | 842 size_t current_node_end = instructions_.size(); |
837 VisitNode(node); | 843 VisitNode(node); |
838 if (instruction_selection_failed()) return; | 844 if (instruction_selection_failed()) return; |
839 std::reverse(instructions_.begin() + current_node_end, instructions_.end()); | 845 std::reverse(instructions_.begin() + current_node_end, instructions_.end()); |
840 if (instructions_.size() == current_node_end) continue; | 846 if (instructions_.size() == current_node_end) continue; |
841 // Mark source position on first instruction emitted. | 847 // Mark source position on first instruction emitted. |
842 SourcePosition source_position = source_positions_->GetSourcePosition(node); | 848 SourcePosition source_position = source_positions_->GetSourcePosition(node); |
843 if (source_position.IsKnown() && | 849 if (source_position.IsKnown() && IsSourcePositionUsed(node)) { |
844 (source_position_mode_ == kAllSourcePositions || | |
845 node->opcode() == IrOpcode::kCall)) { | |
846 sequence()->SetSourcePosition(instructions_[current_node_end], | 850 sequence()->SetSourcePosition(instructions_[current_node_end], |
847 source_position); | 851 source_position); |
848 } | 852 } |
849 } | 853 } |
850 | 854 |
851 // We're done with the block. | 855 // We're done with the block. |
852 InstructionBlock* instruction_block = | 856 InstructionBlock* instruction_block = |
853 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); | 857 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); |
854 instruction_block->set_code_start(static_cast<int>(instructions_.size())); | 858 instruction_block->set_code_start(static_cast<int>(instructions_.size())); |
855 instruction_block->set_code_end(current_block_end); | 859 instruction_block->set_code_end(current_block_end); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 double value = OpParameter<double>(node); | 1013 double value = OpParameter<double>(node); |
1010 if (!IsSmiDouble(value)) MarkAsReference(node); | 1014 if (!IsSmiDouble(value)) MarkAsReference(node); |
1011 return VisitConstant(node); | 1015 return VisitConstant(node); |
1012 } | 1016 } |
1013 case IrOpcode::kCall: | 1017 case IrOpcode::kCall: |
1014 return VisitCall(node); | 1018 return VisitCall(node); |
1015 case IrOpcode::kDeoptimizeIf: | 1019 case IrOpcode::kDeoptimizeIf: |
1016 return VisitDeoptimizeIf(node); | 1020 return VisitDeoptimizeIf(node); |
1017 case IrOpcode::kDeoptimizeUnless: | 1021 case IrOpcode::kDeoptimizeUnless: |
1018 return VisitDeoptimizeUnless(node); | 1022 return VisitDeoptimizeUnless(node); |
| 1023 case IrOpcode::kTrapIf: |
| 1024 return VisitTrapIf(node); |
| 1025 case IrOpcode::kTrapUnless: |
| 1026 return VisitTrapUnless(node); |
1019 case IrOpcode::kFrameState: | 1027 case IrOpcode::kFrameState: |
1020 case IrOpcode::kStateValues: | 1028 case IrOpcode::kStateValues: |
1021 case IrOpcode::kObjectState: | 1029 case IrOpcode::kObjectState: |
1022 return; | 1030 return; |
1023 case IrOpcode::kDebugBreak: | 1031 case IrOpcode::kDebugBreak: |
1024 VisitDebugBreak(node); | 1032 VisitDebugBreak(node); |
1025 return; | 1033 return; |
1026 case IrOpcode::kComment: | 1034 case IrOpcode::kComment: |
1027 VisitComment(node); | 1035 VisitComment(node); |
1028 return; | 1036 return; |
(...skipping 1101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2130 return new (instruction_zone()) FrameStateDescriptor( | 2138 return new (instruction_zone()) FrameStateDescriptor( |
2131 instruction_zone(), state_info.type(), state_info.bailout_id(), | 2139 instruction_zone(), state_info.type(), state_info.bailout_id(), |
2132 state_info.state_combine(), parameters, locals, stack, | 2140 state_info.state_combine(), parameters, locals, stack, |
2133 state_info.shared_info(), outer_state); | 2141 state_info.shared_info(), outer_state); |
2134 } | 2142 } |
2135 | 2143 |
2136 | 2144 |
2137 } // namespace compiler | 2145 } // namespace compiler |
2138 } // namespace internal | 2146 } // namespace internal |
2139 } // namespace v8 | 2147 } // namespace v8 |
OLD | NEW |