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" |
11 #include "src/compiler/node-matchers.h" | 11 #include "src/compiler/node-matchers.h" |
12 #include "src/compiler/pipeline.h" | 12 #include "src/compiler/pipeline.h" |
13 #include "src/compiler/schedule.h" | 13 #include "src/compiler/schedule.h" |
14 #include "src/compiler/state-values-utils.h" | 14 #include "src/compiler/state-values-utils.h" |
15 #include "src/deoptimizer.h" | 15 #include "src/deoptimizer.h" |
16 | 16 |
17 namespace v8 { | 17 namespace v8 { |
18 namespace internal { | 18 namespace internal { |
19 namespace compiler { | 19 namespace compiler { |
20 | 20 |
21 InstructionSelector::InstructionSelector( | 21 InstructionSelector::InstructionSelector( |
22 Zone* zone, size_t node_count, Linkage* linkage, | 22 Zone* zone, size_t node_count, Linkage* linkage, |
23 InstructionSequence* sequence, Schedule* schedule, | 23 InstructionSequence* sequence, Schedule* schedule, |
24 SourcePositionTable* source_positions, Frame* frame, | 24 SourcePositionTable* source_positions, Frame* frame, |
25 SourcePositionMode source_position_mode, Features features) | 25 SourcePositionMode source_position_mode, Features features, |
| 26 EnableScheduling enable_scheduling) |
26 : zone_(zone), | 27 : zone_(zone), |
27 linkage_(linkage), | 28 linkage_(linkage), |
28 sequence_(sequence), | 29 sequence_(sequence), |
29 source_positions_(source_positions), | 30 source_positions_(source_positions), |
30 source_position_mode_(source_position_mode), | 31 source_position_mode_(source_position_mode), |
31 features_(features), | 32 features_(features), |
32 schedule_(schedule), | 33 schedule_(schedule), |
33 current_block_(nullptr), | 34 current_block_(nullptr), |
34 instructions_(zone), | 35 instructions_(zone), |
35 defined_(node_count, false, zone), | 36 defined_(node_count, false, zone), |
36 used_(node_count, false, zone), | 37 used_(node_count, false, zone), |
37 effect_level_(node_count, 0, zone), | 38 effect_level_(node_count, 0, zone), |
38 virtual_registers_(node_count, | 39 virtual_registers_(node_count, |
39 InstructionOperand::kInvalidVirtualRegister, zone), | 40 InstructionOperand::kInvalidVirtualRegister, zone), |
40 scheduler_(nullptr), | 41 scheduler_(nullptr), |
| 42 enable_scheduling_(enable_scheduling), |
41 frame_(frame) { | 43 frame_(frame) { |
42 instructions_.reserve(node_count); | 44 instructions_.reserve(node_count); |
43 } | 45 } |
44 | 46 |
45 | 47 |
46 void InstructionSelector::SelectInstructions() { | 48 void InstructionSelector::SelectInstructions() { |
47 // Mark the inputs of all phis in loop headers as used. | 49 // Mark the inputs of all phis in loop headers as used. |
48 BasicBlockVector* blocks = schedule()->rpo_order(); | 50 BasicBlockVector* blocks = schedule()->rpo_order(); |
49 for (auto const block : *blocks) { | 51 for (auto const block : *blocks) { |
50 if (!block->IsLoopHeader()) continue; | 52 if (!block->IsLoopHeader()) continue; |
51 DCHECK_LE(2u, block->PredecessorCount()); | 53 DCHECK_LE(2u, block->PredecessorCount()); |
52 for (Node* const phi : *block) { | 54 for (Node* const phi : *block) { |
53 if (phi->opcode() != IrOpcode::kPhi) continue; | 55 if (phi->opcode() != IrOpcode::kPhi) continue; |
54 | 56 |
55 // Mark all inputs as used. | 57 // Mark all inputs as used. |
56 for (Node* const input : phi->inputs()) { | 58 for (Node* const input : phi->inputs()) { |
57 MarkAsUsed(input); | 59 MarkAsUsed(input); |
58 } | 60 } |
59 } | 61 } |
60 } | 62 } |
61 | 63 |
62 // Visit each basic block in post order. | 64 // Visit each basic block in post order. |
63 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { | 65 for (auto i = blocks->rbegin(); i != blocks->rend(); ++i) { |
64 VisitBlock(*i); | 66 VisitBlock(*i); |
65 } | 67 } |
66 | 68 |
67 // Schedule the selected instructions. | 69 // Schedule the selected instructions. |
68 if (FLAG_turbo_instruction_scheduling && | 70 if (UseInstructionScheduling()) { |
69 InstructionScheduler::SchedulerSupported()) { | |
70 scheduler_ = new (zone()) InstructionScheduler(zone(), sequence()); | 71 scheduler_ = new (zone()) InstructionScheduler(zone(), sequence()); |
71 } | 72 } |
72 | 73 |
73 for (auto const block : *blocks) { | 74 for (auto const block : *blocks) { |
74 InstructionBlock* instruction_block = | 75 InstructionBlock* instruction_block = |
75 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); | 76 sequence()->InstructionBlockAt(RpoNumber::FromInt(block->rpo_number())); |
76 size_t end = instruction_block->code_end(); | 77 size_t end = instruction_block->code_end(); |
77 size_t start = instruction_block->code_start(); | 78 size_t start = instruction_block->code_start(); |
78 DCHECK_LE(end, start); | 79 DCHECK_LE(end, start); |
79 StartBlock(RpoNumber::FromInt(block->rpo_number())); | 80 StartBlock(RpoNumber::FromInt(block->rpo_number())); |
80 while (start-- > end) { | 81 while (start-- > end) { |
81 AddInstruction(instructions_[start]); | 82 AddInstruction(instructions_[start]); |
82 } | 83 } |
83 EndBlock(RpoNumber::FromInt(block->rpo_number())); | 84 EndBlock(RpoNumber::FromInt(block->rpo_number())); |
84 } | 85 } |
85 #if DEBUG | 86 #if DEBUG |
86 sequence()->ValidateSSA(); | 87 sequence()->ValidateSSA(); |
87 #endif | 88 #endif |
88 } | 89 } |
89 | 90 |
90 void InstructionSelector::StartBlock(RpoNumber rpo) { | 91 void InstructionSelector::StartBlock(RpoNumber rpo) { |
91 if (FLAG_turbo_instruction_scheduling && | 92 if (UseInstructionScheduling()) { |
92 InstructionScheduler::SchedulerSupported()) { | |
93 DCHECK_NOT_NULL(scheduler_); | 93 DCHECK_NOT_NULL(scheduler_); |
94 scheduler_->StartBlock(rpo); | 94 scheduler_->StartBlock(rpo); |
95 } else { | 95 } else { |
96 sequence()->StartBlock(rpo); | 96 sequence()->StartBlock(rpo); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 | 100 |
101 void InstructionSelector::EndBlock(RpoNumber rpo) { | 101 void InstructionSelector::EndBlock(RpoNumber rpo) { |
102 if (FLAG_turbo_instruction_scheduling && | 102 if (UseInstructionScheduling()) { |
103 InstructionScheduler::SchedulerSupported()) { | |
104 DCHECK_NOT_NULL(scheduler_); | 103 DCHECK_NOT_NULL(scheduler_); |
105 scheduler_->EndBlock(rpo); | 104 scheduler_->EndBlock(rpo); |
106 } else { | 105 } else { |
107 sequence()->EndBlock(rpo); | 106 sequence()->EndBlock(rpo); |
108 } | 107 } |
109 } | 108 } |
110 | 109 |
111 | 110 |
112 void InstructionSelector::AddInstruction(Instruction* instr) { | 111 void InstructionSelector::AddInstruction(Instruction* instr) { |
113 if (FLAG_turbo_instruction_scheduling && | 112 if (UseInstructionScheduling()) { |
114 InstructionScheduler::SchedulerSupported()) { | |
115 DCHECK_NOT_NULL(scheduler_); | 113 DCHECK_NOT_NULL(scheduler_); |
116 scheduler_->AddInstruction(instr); | 114 scheduler_->AddInstruction(instr); |
117 } else { | 115 } else { |
118 sequence()->AddInstruction(instr); | 116 sequence()->AddInstruction(instr); |
119 } | 117 } |
120 } | 118 } |
121 | 119 |
122 | 120 |
123 Instruction* InstructionSelector::Emit(InstructionCode opcode, | 121 Instruction* InstructionSelector::Emit(InstructionCode opcode, |
124 InstructionOperand output, | 122 InstructionOperand output, |
(...skipping 1954 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2079 return new (instruction_zone()) FrameStateDescriptor( | 2077 return new (instruction_zone()) FrameStateDescriptor( |
2080 instruction_zone(), state_info.type(), state_info.bailout_id(), | 2078 instruction_zone(), state_info.type(), state_info.bailout_id(), |
2081 state_info.state_combine(), parameters, locals, stack, | 2079 state_info.state_combine(), parameters, locals, stack, |
2082 state_info.shared_info(), outer_state); | 2080 state_info.shared_info(), outer_state); |
2083 } | 2081 } |
2084 | 2082 |
2085 | 2083 |
2086 } // namespace compiler | 2084 } // namespace compiler |
2087 } // namespace internal | 2085 } // namespace internal |
2088 } // namespace v8 | 2086 } // namespace v8 |
OLD | NEW |