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

Side by Side Diff: src/IceCfg.cpp

Issue 1246173003: Remove jumps over empty blocks. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Refactor to variable Created 5 years, 5 months 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
« no previous file with comments | « no previous file | src/IceCfgNode.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===// 1 //===- subzero/src/IceCfg.cpp - Control flow graph implementation ---------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 // list. This can invalidate iterators, so don't use an iterator. 252 // list. This can invalidate iterators, so don't use an iterator.
253 SizeT NumNodes = getNumNodes(); 253 SizeT NumNodes = getNumNodes();
254 for (SizeT I = 0; I < NumNodes; ++I) 254 for (SizeT I = 0; I < NumNodes; ++I)
255 Nodes[I]->advancedPhiLowering(); 255 Nodes[I]->advancedPhiLowering();
256 } 256 }
257 257
258 // Find a reasonable placement for nodes that have not yet been 258 // Find a reasonable placement for nodes that have not yet been
259 // placed, while maintaining the same relative ordering among already 259 // placed, while maintaining the same relative ordering among already
260 // placed nodes. 260 // placed nodes.
261 void Cfg::reorderNodes() { 261 void Cfg::reorderNodes() {
262 // TODO(ascull): it would be nice if the switch tests were always followed
263 // by the default case to allow for fall through.
262 typedef std::list<CfgNode *> PlacedList; 264 typedef std::list<CfgNode *> PlacedList;
263 PlacedList Placed; // Nodes with relative placement locked down 265 PlacedList Placed; // Nodes with relative placement locked down
264 PlacedList Unreachable; // Unreachable nodes 266 PlacedList Unreachable; // Unreachable nodes
265 PlacedList::iterator NoPlace = Placed.end(); 267 PlacedList::iterator NoPlace = Placed.end();
266 // Keep track of where each node has been tentatively placed so that 268 // Keep track of where each node has been tentatively placed so that
267 // we can manage insertions into the middle. 269 // we can manage insertions into the middle.
268 std::vector<PlacedList::iterator> PlaceIndex(Nodes.size(), NoPlace); 270 std::vector<PlacedList::iterator> PlaceIndex(Nodes.size(), NoPlace);
269 for (CfgNode *Node : Nodes) { 271 for (CfgNode *Node : Nodes) {
270 // The "do ... while(0);" construct is to factor out the 272 // The "do ... while(0);" construct is to factor out the
271 // --PlaceIndex and assert() statements before moving to the next 273 // --PlaceIndex and assert() statements before moving to the next
272 // node. 274 // node.
273 do { 275 do {
276 if (Node != getEntryNode() && Node->getInEdges().empty()) {
277 // The node has essentially been deleted since it is not a
278 // successor of any other node.
279 Unreachable.push_back(Node);
280 PlaceIndex[Node->getIndex()] = Unreachable.end();
281 Node->setNeedsPlacement(false);
282 continue;
283 }
274 if (!Node->needsPlacement()) { 284 if (!Node->needsPlacement()) {
275 // Add to the end of the Placed list. 285 // Add to the end of the Placed list.
276 Placed.push_back(Node); 286 Placed.push_back(Node);
277 PlaceIndex[Node->getIndex()] = Placed.end(); 287 PlaceIndex[Node->getIndex()] = Placed.end();
278 continue; 288 continue;
279 } 289 }
280 Node->setNeedsPlacement(false); 290 Node->setNeedsPlacement(false);
281 if (Node != getEntryNode() && Node->getInEdges().empty()) {
282 // The node has essentially been deleted since it is not a
283 // successor of any other node.
284 Unreachable.push_back(Node);
285 PlaceIndex[Node->getIndex()] = Unreachable.end();
286 continue;
287 }
288 // Assume for now that the unplaced node is from edge-splitting 291 // Assume for now that the unplaced node is from edge-splitting
289 // and therefore has 1 in-edge and 1 out-edge (actually, possibly 292 // and therefore has 1 in-edge and 1 out-edge (actually, possibly
290 // more than 1 in-edge if the predecessor node was contracted). 293 // more than 1 in-edge if the predecessor node was contracted).
291 // If this changes in the future, rethink the strategy. 294 // If this changes in the future, rethink the strategy.
292 assert(Node->getInEdges().size() >= 1); 295 assert(Node->getInEdges().size() >= 1);
293 assert(Node->getOutEdges().size() == 1); 296 assert(Node->getOutEdges().size() == 1);
294 297
295 // If it's a (non-critical) edge where the successor has a single 298 // If it's a (non-critical) edge where the successor has a single
296 // in-edge, then place it before the successor. 299 // in-edge, then place it before the successor.
297 CfgNode *Succ = Node->getOutEdges().front(); 300 CfgNode *Succ = Node->getOutEdges().front();
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 if (Ctx->getFlags().getDecorateAsm()) 517 if (Ctx->getFlags().getDecorateAsm())
515 return; 518 return;
516 for (CfgNode *Node : Nodes) { 519 for (CfgNode *Node : Nodes) {
517 Node->contractIfEmpty(); 520 Node->contractIfEmpty();
518 } 521 }
519 } 522 }
520 523
521 void Cfg::doBranchOpt() { 524 void Cfg::doBranchOpt() {
522 TimerMarker T(TimerStack::TT_doBranchOpt, this); 525 TimerMarker T(TimerStack::TT_doBranchOpt, this);
523 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) { 526 for (auto I = Nodes.begin(), E = Nodes.end(); I != E; ++I) {
524 auto NextNode = I; 527 auto NextNode = I + 1;
525 ++NextNode;
526 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode); 528 (*I)->doBranchOpt(NextNode == E ? nullptr : *NextNode);
527 } 529 }
528 } 530 }
529 531
530 // ======================== Dump routines ======================== // 532 // ======================== Dump routines ======================== //
531 533
532 // emitTextHeader() is not target-specific (apart from what is 534 // emitTextHeader() is not target-specific (apart from what is
533 // abstracted by the Assembler), so it is defined here rather than in 535 // abstracted by the Assembler), so it is defined here rather than in
534 // the target lowering class. 536 // the target lowering class.
535 void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx, 537 void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx,
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 } 621 }
620 } 622 }
621 // Print each basic block 623 // Print each basic block
622 for (CfgNode *Node : Nodes) 624 for (CfgNode *Node : Nodes)
623 Node->dump(this); 625 Node->dump(this);
624 if (isVerbose(IceV_Instructions)) 626 if (isVerbose(IceV_Instructions))
625 Str << "}\n"; 627 Str << "}\n";
626 } 628 }
627 629
628 } // end of namespace Ice 630 } // end of namespace Ice
OLDNEW
« no previous file with comments | « no previous file | src/IceCfgNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698