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/instruction-selector-impl.h" | 10 #include "src/compiler/instruction-selector-impl.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 sequence_(sequence), | 27 sequence_(sequence), |
28 source_positions_(source_positions), | 28 source_positions_(source_positions), |
29 source_position_mode_(source_position_mode), | 29 source_position_mode_(source_position_mode), |
30 features_(features), | 30 features_(features), |
31 schedule_(schedule), | 31 schedule_(schedule), |
32 current_block_(NULL), | 32 current_block_(NULL), |
33 instructions_(zone), | 33 instructions_(zone), |
34 defined_(node_count, false, zone), | 34 defined_(node_count, false, zone), |
35 used_(node_count, false, zone), | 35 used_(node_count, false, zone), |
36 virtual_registers_(node_count, | 36 virtual_registers_(node_count, |
37 InstructionOperand::kInvalidVirtualRegister, zone) { | 37 InstructionOperand::kInvalidVirtualRegister, zone), |
| 38 scheduler_(nullptr) { |
38 instructions_.reserve(node_count); | 39 instructions_.reserve(node_count); |
39 } | 40 } |
40 | 41 |
41 | 42 |
42 void InstructionSelector::SelectInstructions() { | 43 void InstructionSelector::SelectInstructions() { |
43 // Mark the inputs of all phis in loop headers as used. | 44 // Mark the inputs of all phis in loop headers as used. |
44 BasicBlockVector* blocks = schedule()->rpo_order(); | 45 BasicBlockVector* blocks = schedule()->rpo_order(); |
45 for (auto const block : *blocks) { | 46 for (auto const block : *blocks) { |
46 if (!block->IsLoopHeader()) continue; | 47 if (!block->IsLoopHeader()) continue; |
47 DCHECK_LE(2u, block->PredecessorCount()); | 48 DCHECK_LE(2u, block->PredecessorCount()); |
48 for (Node* const phi : *block) { | 49 for (Node* const phi : *block) { |
49 if (phi->opcode() != IrOpcode::kPhi) continue; | 50 if (phi->opcode() != IrOpcode::kPhi) continue; |
50 | 51 |
51 // Mark all inputs as used. | 52 // Mark all inputs as used. |
52 for (Node* const input : phi->inputs()) { | 53 for (Node* const input : phi->inputs()) { |
53 MarkAsUsed(input); | 54 MarkAsUsed(input); |
54 } | 55 } |
55 } | 56 } |
56 } | 57 } |
57 | 58 |
58 // Visit each basic block in post order. | 59 // Visit each basic block in post order. |
59 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { | 60 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { |
60 VisitBlock(*i); | 61 VisitBlock(*i); |
61 } | 62 } |
62 | 63 |
63 // Schedule the selected instructions. | 64 // Schedule the selected instructions. |
| 65 if (FLAG_turbo_instruction_scheduling) { |
| 66 scheduler_ = new (zone()) InstructionScheduler(zone(), sequence()); |
| 67 } |
| 68 |
64 for (auto const block : *blocks) { | 69 for (auto const block : *blocks) { |
65 InstructionBlock* instruction_block = | 70 InstructionBlock* instruction_block = |
66 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); | 71 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); |
67 size_t end = instruction_block->code_end(); | 72 size_t end = instruction_block->code_end(); |
68 size_t start = instruction_block->code_start(); | 73 size_t start = instruction_block->code_start(); |
69 DCHECK_LE(end, start); | 74 DCHECK_LE(end, start); |
70 sequence()->StartBlock(RpoNumber::FromInt(block->rpo_number())); | 75 StartBlock(RpoNumber::FromInt(block->rpo_number())); |
71 while (start-- > end) { | 76 while (start-- > end) { |
72 sequence()->AddInstruction(instructions_[start]); | 77 AddInstruction(instructions_[start]); |
73 } | 78 } |
74 sequence()->EndBlock(RpoNumber::FromInt(block->rpo_number())); | 79 EndBlock(RpoNumber::FromInt(block->rpo_number())); |
75 } | 80 } |
76 } | 81 } |
77 | 82 |
| 83 |
| 84 void InstructionSelector::StartBlock(RpoNumber rpo) { |
| 85 if (FLAG_turbo_instruction_scheduling) { |
| 86 scheduler_->StartBlock(rpo); |
| 87 } else { |
| 88 sequence()->StartBlock(rpo); |
| 89 } |
| 90 } |
| 91 |
| 92 |
| 93 void InstructionSelector::EndBlock(RpoNumber rpo) { |
| 94 if (FLAG_turbo_instruction_scheduling) { |
| 95 scheduler_->EndBlock(rpo); |
| 96 } else { |
| 97 sequence()->EndBlock(rpo); |
| 98 } |
| 99 } |
| 100 |
| 101 |
| 102 void InstructionSelector::AddInstruction(Instruction* instr) { |
| 103 if (FLAG_turbo_instruction_scheduling) { |
| 104 scheduler_->AddInstruction(instr); |
| 105 } else { |
| 106 sequence()->AddInstruction(instr); |
| 107 } |
| 108 } |
| 109 |
78 | 110 |
79 Instruction* InstructionSelector::Emit(InstructionCode opcode, | 111 Instruction* InstructionSelector::Emit(InstructionCode opcode, |
80 InstructionOperand output, | 112 InstructionOperand output, |
81 size_t temp_count, | 113 size_t temp_count, |
82 InstructionOperand* temps) { | 114 InstructionOperand* temps) { |
83 size_t output_count = output.IsInvalid() ? 0 : 1; | 115 size_t output_count = output.IsInvalid() ? 0 : 1; |
84 return Emit(opcode, output_count, &output, 0, NULL, temp_count, temps); | 116 return Emit(opcode, output_count, &output, 0, NULL, temp_count, temps); |
85 } | 117 } |
86 | 118 |
87 | 119 |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) { | 1176 for (StateValuesAccess::TypedNode input_node : StateValuesAccess(stack)) { |
1145 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); | 1177 inputs->push_back(OperandForDeopt(&g, input_node.node, kind)); |
1146 descriptor->SetType(value_index++, input_node.type); | 1178 descriptor->SetType(value_index++, input_node.type); |
1147 } | 1179 } |
1148 DCHECK(value_index == descriptor->GetSize()); | 1180 DCHECK(value_index == descriptor->GetSize()); |
1149 } | 1181 } |
1150 | 1182 |
1151 } // namespace compiler | 1183 } // namespace compiler |
1152 } // namespace internal | 1184 } // namespace internal |
1153 } // namespace v8 | 1185 } // namespace v8 |
OLD | NEW |