OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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/schedule.h" | 5 #include "src/compiler/schedule.h" |
6 | 6 |
7 #include "src/compiler/node.h" | 7 #include "src/compiler/node.h" |
8 #include "src/compiler/node-properties.h" | 8 #include "src/compiler/node-properties.h" |
9 #include "src/ostreams.h" | 9 #include "src/ostreams.h" |
10 | 10 |
(...skipping 16 matching lines...) Expand all Loading... |
27 nodes_(zone), | 27 nodes_(zone), |
28 successors_(zone), | 28 successors_(zone), |
29 predecessors_(zone), | 29 predecessors_(zone), |
30 id_(id) {} | 30 id_(id) {} |
31 | 31 |
32 | 32 |
33 bool BasicBlock::LoopContains(BasicBlock* block) const { | 33 bool BasicBlock::LoopContains(BasicBlock* block) const { |
34 // RPO numbers must be initialized. | 34 // RPO numbers must be initialized. |
35 DCHECK(rpo_number_ >= 0); | 35 DCHECK(rpo_number_ >= 0); |
36 DCHECK(block->rpo_number_ >= 0); | 36 DCHECK(block->rpo_number_ >= 0); |
37 if (loop_end_ == NULL) return false; // This is not a loop. | 37 if (loop_end_ == nullptr) return false; // This is not a loop. |
38 return block->rpo_number_ >= rpo_number_ && | 38 return block->rpo_number_ >= rpo_number_ && |
39 block->rpo_number_ < loop_end_->rpo_number_; | 39 block->rpo_number_ < loop_end_->rpo_number_; |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 void BasicBlock::AddSuccessor(BasicBlock* successor) { | 43 void BasicBlock::AddSuccessor(BasicBlock* successor) { |
44 successors_.push_back(successor); | 44 successors_.push_back(successor); |
45 } | 45 } |
46 | 46 |
47 | 47 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 start_(NewBasicBlock()), | 133 start_(NewBasicBlock()), |
134 end_(NewBasicBlock()) { | 134 end_(NewBasicBlock()) { |
135 nodeid_to_block_.reserve(node_count_hint); | 135 nodeid_to_block_.reserve(node_count_hint); |
136 } | 136 } |
137 | 137 |
138 | 138 |
139 BasicBlock* Schedule::block(Node* node) const { | 139 BasicBlock* Schedule::block(Node* node) const { |
140 if (node->id() < static_cast<NodeId>(nodeid_to_block_.size())) { | 140 if (node->id() < static_cast<NodeId>(nodeid_to_block_.size())) { |
141 return nodeid_to_block_[node->id()]; | 141 return nodeid_to_block_[node->id()]; |
142 } | 142 } |
143 return NULL; | 143 return nullptr; |
144 } | 144 } |
145 | 145 |
146 | 146 |
147 bool Schedule::IsScheduled(Node* node) { | 147 bool Schedule::IsScheduled(Node* node) { |
148 if (node->id() >= nodeid_to_block_.size()) return false; | 148 if (node->id() >= nodeid_to_block_.size()) return false; |
149 return nodeid_to_block_[node->id()] != NULL; | 149 return nodeid_to_block_[node->id()] != nullptr; |
150 } | 150 } |
151 | 151 |
152 | 152 |
153 BasicBlock* Schedule::GetBlockById(BasicBlock::Id block_id) { | 153 BasicBlock* Schedule::GetBlockById(BasicBlock::Id block_id) { |
154 DCHECK(block_id.ToSize() < all_blocks_.size()); | 154 DCHECK(block_id.ToSize() < all_blocks_.size()); |
155 return all_blocks_[block_id.ToSize()]; | 155 return all_blocks_[block_id.ToSize()]; |
156 } | 156 } |
157 | 157 |
158 | 158 |
159 bool Schedule::SameBasicBlock(Node* a, Node* b) const { | 159 bool Schedule::SameBasicBlock(Node* a, Node* b) const { |
160 BasicBlock* block = this->block(a); | 160 BasicBlock* block = this->block(a); |
161 return block != NULL && block == this->block(b); | 161 return block != nullptr && block == this->block(b); |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 BasicBlock* Schedule::NewBasicBlock() { | 165 BasicBlock* Schedule::NewBasicBlock() { |
166 BasicBlock* block = new (zone_) | 166 BasicBlock* block = new (zone_) |
167 BasicBlock(zone_, BasicBlock::Id::FromSize(all_blocks_.size())); | 167 BasicBlock(zone_, BasicBlock::Id::FromSize(all_blocks_.size())); |
168 all_blocks_.push_back(block); | 168 all_blocks_.push_back(block); |
169 return block; | 169 return block; |
170 } | 170 } |
171 | 171 |
172 | 172 |
173 void Schedule::PlanNode(BasicBlock* block, Node* node) { | 173 void Schedule::PlanNode(BasicBlock* block, Node* node) { |
174 if (FLAG_trace_turbo_scheduler) { | 174 if (FLAG_trace_turbo_scheduler) { |
175 OFStream os(stdout); | 175 OFStream os(stdout); |
176 os << "Planning #" << node->id() << ":" << node->op()->mnemonic() | 176 os << "Planning #" << node->id() << ":" << node->op()->mnemonic() |
177 << " for future add to B" << block->id() << "\n"; | 177 << " for future add to B" << block->id() << "\n"; |
178 } | 178 } |
179 DCHECK(this->block(node) == NULL); | 179 DCHECK(this->block(node) == nullptr); |
180 SetBlockForNode(block, node); | 180 SetBlockForNode(block, node); |
181 } | 181 } |
182 | 182 |
183 | 183 |
184 void Schedule::AddNode(BasicBlock* block, Node* node) { | 184 void Schedule::AddNode(BasicBlock* block, Node* node) { |
185 if (FLAG_trace_turbo_scheduler) { | 185 if (FLAG_trace_turbo_scheduler) { |
186 OFStream os(stdout); | 186 OFStream os(stdout); |
187 os << "Adding #" << node->id() << ":" << node->op()->mnemonic() << " to B" | 187 os << "Adding #" << node->id() << ":" << node->op()->mnemonic() << " to B" |
188 << block->id() << "\n"; | 188 << block->id() << "\n"; |
189 } | 189 } |
190 DCHECK(this->block(node) == NULL || this->block(node) == block); | 190 DCHECK(this->block(node) == nullptr || this->block(node) == block); |
191 block->AddNode(node); | 191 block->AddNode(node); |
192 SetBlockForNode(block, node); | 192 SetBlockForNode(block, node); |
193 } | 193 } |
194 | 194 |
195 | 195 |
196 void Schedule::AddGoto(BasicBlock* block, BasicBlock* succ) { | 196 void Schedule::AddGoto(BasicBlock* block, BasicBlock* succ) { |
197 DCHECK_EQ(BasicBlock::kNone, block->control()); | 197 DCHECK_EQ(BasicBlock::kNone, block->control()); |
198 block->set_control(BasicBlock::kGoto); | 198 block->set_control(BasicBlock::kGoto); |
199 AddSuccessor(block, succ); | 199 AddSuccessor(block, succ); |
200 } | 200 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (NodeProperties::IsTyped(node)) { | 347 if (NodeProperties::IsTyped(node)) { |
348 Type* type = NodeProperties::GetType(node); | 348 Type* type = NodeProperties::GetType(node); |
349 os << " : "; | 349 os << " : "; |
350 type->PrintTo(os); | 350 type->PrintTo(os); |
351 } | 351 } |
352 os << "\n"; | 352 os << "\n"; |
353 } | 353 } |
354 BasicBlock::Control control = block->control(); | 354 BasicBlock::Control control = block->control(); |
355 if (control != BasicBlock::kNone) { | 355 if (control != BasicBlock::kNone) { |
356 os << " "; | 356 os << " "; |
357 if (block->control_input() != NULL) { | 357 if (block->control_input() != nullptr) { |
358 os << *block->control_input(); | 358 os << *block->control_input(); |
359 } else { | 359 } else { |
360 os << "Goto"; | 360 os << "Goto"; |
361 } | 361 } |
362 os << " -> "; | 362 os << " -> "; |
363 comma = false; | 363 comma = false; |
364 for (BasicBlock const* successor : block->successors()) { | 364 for (BasicBlock const* successor : block->successors()) { |
365 if (comma) os << ", "; | 365 if (comma) os << ", "; |
366 comma = true; | 366 comma = true; |
367 os << "B" << successor->rpo_number(); | 367 os << "B" << successor->rpo_number(); |
368 } | 368 } |
369 os << "\n"; | 369 os << "\n"; |
370 } | 370 } |
371 } | 371 } |
372 return os; | 372 return os; |
373 } | 373 } |
374 | 374 |
375 } // namespace compiler | 375 } // namespace compiler |
376 } // namespace internal | 376 } // namespace internal |
377 } // namespace v8 | 377 } // namespace v8 |
OLD | NEW |