Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: src/compiler/scheduler.cc

Issue 681263004: Run ControlReducer early after graph building, then again later. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/pipeline.cc ('k') | test/cctest/compiler/test-scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <deque> 5 #include <deque>
6 #include <queue> 6 #include <queue>
7 7
8 #include "src/compiler/scheduler.h" 8 #include "src/compiler/scheduler.h"
9 9
10 #include "src/compiler/graph.h" 10 #include "src/compiler/graph.h"
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 queue_(zone), 234 queue_(zone),
235 control_(zone), 235 control_(zone),
236 component_head_(NULL), 236 component_head_(NULL),
237 component_start_(NULL), 237 component_start_(NULL),
238 component_end_(NULL) {} 238 component_end_(NULL) {}
239 239
240 // Run the control flow graph construction algorithm by walking the graph 240 // Run the control flow graph construction algorithm by walking the graph
241 // backwards from end through control edges, building and connecting the 241 // backwards from end through control edges, building and connecting the
242 // basic blocks for control nodes. 242 // basic blocks for control nodes.
243 void Run() { 243 void Run() {
244 Graph* graph = scheduler_->graph_; 244 Queue(scheduler_->graph_->end());
245 FixNode(schedule_->start(), graph->start());
246 Queue(graph->end());
247 245
248 while (!queue_.empty()) { // Breadth-first backwards traversal. 246 while (!queue_.empty()) { // Breadth-first backwards traversal.
249 Node* node = queue_.front(); 247 Node* node = queue_.front();
250 queue_.pop(); 248 queue_.pop();
251 int max = NodeProperties::PastControlIndex(node); 249 int max = NodeProperties::PastControlIndex(node);
252 for (int i = NodeProperties::FirstControlIndex(node); i < max; i++) { 250 for (int i = NodeProperties::FirstControlIndex(node); i < max; i++) {
253 Queue(node->InputAt(i)); 251 Queue(node->InputAt(i));
254 } 252 }
255 } 253 }
256 254
257 for (NodeVector::iterator i = control_.begin(); i != control_.end(); ++i) { 255 for (NodeVector::iterator i = control_.begin(); i != control_.end(); ++i) {
258 ConnectBlocks(*i); // Connect block to its predecessor/successors. 256 ConnectBlocks(*i); // Connect block to its predecessor/successors.
259 } 257 }
260 258
261 FixNode(schedule_->end(), graph->end()); 259 FixNode(schedule_->end(), scheduler_->graph_->end());
Michael Starzinger 2014/10/29 15:23:21 nit: Can we fix the end node in BuildBlocks as wel
titzer 2014/10/29 15:24:04 Done.
262 } 260 }
263 261
264 // Run the control flow graph construction for a minimal control-connected 262 // Run the control flow graph construction for a minimal control-connected
265 // component ending in {node} and merge that component into an existing 263 // component ending in {node} and merge that component into an existing
266 // control flow graph at the bottom of {block}. 264 // control flow graph at the bottom of {block}.
267 void Run(BasicBlock* block, Node* node) { 265 void Run(BasicBlock* block, Node* node) {
268 Queue(node); 266 Queue(node);
269 267
270 component_start_ = block; 268 component_start_ = block;
271 component_end_ = schedule_->block(node); 269 component_end_ = schedule_->block(node);
(...skipping 14 matching lines...) Expand all
286 284
287 for (NodeVector::iterator i = control_.begin(); i != control_.end(); ++i) { 285 for (NodeVector::iterator i = control_.begin(); i != control_.end(); ++i) {
288 scheduler_->GetData(*i)->is_floating_control_ = false; 286 scheduler_->GetData(*i)->is_floating_control_ = false;
289 ConnectBlocks(*i); // Connect block to its predecessor/successors. 287 ConnectBlocks(*i); // Connect block to its predecessor/successors.
290 } 288 }
291 } 289 }
292 290
293 private: 291 private:
294 void FixNode(BasicBlock* block, Node* node) { 292 void FixNode(BasicBlock* block, Node* node) {
295 schedule_->AddNode(block, node); 293 schedule_->AddNode(block, node);
296 scheduler_->GetData(node)->is_connected_control_ = true;
297 scheduler_->UpdatePlacement(node, Scheduler::kFixed); 294 scheduler_->UpdatePlacement(node, Scheduler::kFixed);
298 } 295 }
299 296
300 void Queue(Node* node) { 297 void Queue(Node* node) {
301 // Mark the connected control nodes as they queued. 298 // Mark the connected control nodes as they queued.
302 Scheduler::SchedulerData* data = scheduler_->GetData(node); 299 Scheduler::SchedulerData* data = scheduler_->GetData(node);
303 if (!data->is_connected_control_) { 300 if (!data->is_connected_control_) {
301 data->is_connected_control_ = true;
304 BuildBlocks(node); 302 BuildBlocks(node);
305 queue_.push(node); 303 queue_.push(node);
306 control_.push_back(node); 304 control_.push_back(node);
307 data->is_connected_control_ = true;
308 } 305 }
309 } 306 }
310 307
311 308
312 void BuildBlocks(Node* node) { 309 void BuildBlocks(Node* node) {
313 switch (node->opcode()) { 310 switch (node->opcode()) {
311 case IrOpcode::kStart:
312 FixNode(schedule_->start(), node);
313 break;
314 case IrOpcode::kLoop: 314 case IrOpcode::kLoop:
315 case IrOpcode::kMerge: 315 case IrOpcode::kMerge:
316 case IrOpcode::kTerminate:
317 BuildBlockForNode(node); 316 BuildBlockForNode(node);
318 break; 317 break;
318 case IrOpcode::kTerminate: {
319 // Put Terminate in the loop to which it refers.
320 Node* loop = NodeProperties::GetControlInput(node);
321 BasicBlock* block = BuildBlockForNode(loop);
322 FixNode(block, node);
323 break;
324 }
319 case IrOpcode::kBranch: 325 case IrOpcode::kBranch:
320 BuildBlocksForSuccessors(node, IrOpcode::kIfTrue, IrOpcode::kIfFalse); 326 BuildBlocksForSuccessors(node, IrOpcode::kIfTrue, IrOpcode::kIfFalse);
321 break; 327 break;
322 default: 328 default:
323 break; 329 break;
324 } 330 }
325 } 331 }
326 332
327 void ConnectBlocks(Node* node) { 333 void ConnectBlocks(Node* node) {
328 switch (node->opcode()) { 334 switch (node->opcode()) {
329 case IrOpcode::kLoop: 335 case IrOpcode::kLoop:
330 case IrOpcode::kMerge: 336 case IrOpcode::kMerge:
331 ConnectMerge(node); 337 ConnectMerge(node);
332 break; 338 break;
333 case IrOpcode::kBranch: 339 case IrOpcode::kBranch:
334 scheduler_->UpdatePlacement(node, Scheduler::kFixed); 340 scheduler_->UpdatePlacement(node, Scheduler::kFixed);
335 ConnectBranch(node); 341 ConnectBranch(node);
336 break; 342 break;
337 case IrOpcode::kReturn: 343 case IrOpcode::kReturn:
338 scheduler_->UpdatePlacement(node, Scheduler::kFixed); 344 scheduler_->UpdatePlacement(node, Scheduler::kFixed);
339 ConnectReturn(node); 345 ConnectReturn(node);
340 break; 346 break;
341 default: 347 default:
342 break; 348 break;
343 } 349 }
344 } 350 }
345 351
346 void BuildBlockForNode(Node* node) { 352 BasicBlock* BuildBlockForNode(Node* node) {
347 if (schedule_->block(node) == NULL) { 353 BasicBlock* block = schedule_->block(node);
348 BasicBlock* block = schedule_->NewBasicBlock(); 354 if (block == NULL) {
355 block = schedule_->NewBasicBlock();
349 Trace("Create block B%d for #%d:%s\n", block->id().ToInt(), node->id(), 356 Trace("Create block B%d for #%d:%s\n", block->id().ToInt(), node->id(),
350 node->op()->mnemonic()); 357 node->op()->mnemonic());
351 FixNode(block, node); 358 FixNode(block, node);
352 } 359 }
360 return block;
353 } 361 }
354 362
355 void BuildBlocksForSuccessors(Node* node, IrOpcode::Value a, 363 void BuildBlocksForSuccessors(Node* node, IrOpcode::Value a,
356 IrOpcode::Value b) { 364 IrOpcode::Value b) {
357 Node* successors[2]; 365 Node* successors[2];
358 CollectSuccessorProjections(node, successors, a, b); 366 CollectSuccessorProjections(node, successors, a, b);
359 BuildBlockForNode(successors[0]); 367 BuildBlockForNode(successors[0]);
360 BuildBlockForNode(successors[1]); 368 BuildBlockForNode(successors[1]);
361 } 369 }
362 370
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after
1356 for (NodeVectorIter i = nodes->begin(); i != nodes->end(); ++i) { 1364 for (NodeVectorIter i = nodes->begin(); i != nodes->end(); ++i) {
1357 schedule_->SetBlockForNode(to, *i); 1365 schedule_->SetBlockForNode(to, *i);
1358 scheduled_nodes_[to->id().ToSize()].push_back(*i); 1366 scheduled_nodes_[to->id().ToSize()].push_back(*i);
1359 } 1367 }
1360 nodes->clear(); 1368 nodes->clear();
1361 } 1369 }
1362 1370
1363 } // namespace compiler 1371 } // namespace compiler
1364 } // namespace internal 1372 } // namespace internal
1365 } // namespace v8 1373 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/pipeline.cc ('k') | test/cctest/compiler/test-scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698