Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 return false; | 565 return false; |
| 566 } | 566 } |
| 567 // Does not enter loop if different kind or number of operands | 567 // Does not enter loop if different kind or number of operands |
| 568 for (SizeT i = 0; i < InstrA->getSrcSize(); ++i) { | 568 for (SizeT i = 0; i < InstrA->getSrcSize(); ++i) { |
| 569 if (!srcEq(InstrA->getSrc(i), InstrB->getSrc(i))) | 569 if (!srcEq(InstrA->getSrc(i), InstrB->getSrc(i))) |
| 570 return false; | 570 return false; |
| 571 } | 571 } |
| 572 return true; | 572 return true; |
| 573 } | 573 } |
| 574 }; | 574 }; |
| 575 | 575 bool NoSSA = getFlags().getLocalCSENoSSA(); |
|
John
2016/07/28 14:21:50
const bool
manasijm
2016/07/28 19:43:34
Done.
| |
| 576 for (CfgNode *Node : getNodes()) { | 576 for (CfgNode *Node : getNodes()) { |
| 577 CfgUnorderedSet<Inst *, InstHash, InstEq> Seen; | 577 CfgUnorderedSet<Inst *, InstHash, InstEq> Seen; |
| 578 | 578 |
| 579 CfgUnorderedMap<Variable *, Variable *, VariableHash> Replacements; | 579 CfgUnorderedMap<Variable *, Variable *, VariableHash> Replacements; |
| 580 // Combining the above two into a single data structure might consume less | 580 // Combining the above two into a single data structure might consume less |
| 581 // memory but will be slower i.e map of Instruction -> Set of Variables | 581 // memory but will be slower i.e map of Instruction -> Set of Variables |
| 582 | 582 |
| 583 CfgUnorderedMap<Variable *, std::vector<Inst *>, VariableHash> Dependency; | 583 CfgUnorderedMap<Variable *, std::vector<Inst *>, VariableHash> Dependency; |
| 584 // Not necessary for SSA, still keeping it in case this pass is not run at | 584 // Not necessary for SSA |
| 585 // the beginning. Remove to improve performace. | |
| 586 | 585 |
| 587 int IterCount = getFlags().getLocalCseMaxIterations(); | 586 int IterCount = getFlags().getLocalCseMaxIterations(); |
| 588 | 587 |
| 589 while (IterCount--) { | 588 while (IterCount--) { |
| 590 // TODO : Stats on IterCount -> performance | 589 // TODO : Stats on IterCount -> performance |
|
John
2016/07/28 14:21:50
TODO(manasijm):
manasijm
2016/07/28 19:43:33
Done.
| |
| 591 for (Inst &Instr : Node->getInsts()) { | 590 for (Inst &Instr : Node->getInsts()) { |
| 592 if (Instr.isDeleted() || !llvm::isa<InstArithmetic>(&Instr)) | 591 if (Instr.isDeleted() || !llvm::isa<InstArithmetic>(&Instr)) |
| 593 continue; | 592 continue; |
| 593 if (NoSSA) { | |
|
John
2016/07/28 14:21:50
document what's going on here. why is this needed
manasijm
2016/07/28 15:24:44
This is needed if this pass is moved to a point la
manasijm
2016/07/28 19:43:33
Done.
| |
| 594 // Invalidate replacements | |
| 595 auto Iter = Replacements.find(Instr.getDest()); | |
| 596 if (Iter != Replacements.end()) { | |
| 597 Replacements.erase(Iter); | |
| 598 } | |
| 594 | 599 |
| 595 // Invalidate replacements | 600 // Invalidate 'seen' instructions whose operands were just updated. |
| 596 auto Iter = Replacements.find(Instr.getDest()); | 601 auto DepIter = Dependency.find(Instr.getDest()); |
| 597 if (Iter != Replacements.end()) { | 602 if (DepIter != Dependency.end()) { |
| 598 Replacements.erase(Iter); | 603 for (auto DepInst : DepIter->second) { |
|
John
2016/07/28 14:21:50
auto *
manasijm
2016/07/28 19:43:34
Done.
| |
| 604 Seen.erase(DepInst); | |
| 605 } | |
| 606 } | |
| 599 } | 607 } |
| 600 | 608 |
| 601 // Invalidate 'seen' instructions whose operands were just updated. | |
| 602 auto DepIter = Dependency.find(Instr.getDest()); | |
| 603 if (DepIter != Dependency.end()) { | |
| 604 for (auto DepInst : DepIter->second) { | |
| 605 Seen.erase(DepInst); | |
| 606 } | |
| 607 } | |
| 608 // The above two can be removed if SSA is assumed. | |
| 609 | |
| 610 // Replace - doing this before checking for repetitions might enable | 609 // Replace - doing this before checking for repetitions might enable |
| 611 // more | 610 // more optimizations |
| 612 // optimizations | |
| 613 for (SizeT i = 0; i < Instr.getSrcSize(); ++i) { | 611 for (SizeT i = 0; i < Instr.getSrcSize(); ++i) { |
| 614 auto *Opnd = Instr.getSrc(i); | 612 auto *Opnd = Instr.getSrc(i); |
| 615 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { | 613 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { |
| 616 if (Replacements.find(Var) != Replacements.end()) { | 614 if (Replacements.find(Var) != Replacements.end()) { |
| 617 Instr.replaceSource(i, Replacements[Var]); | 615 Instr.replaceSource(i, Replacements[Var]); |
| 618 } | 616 } |
| 619 } | 617 } |
| 620 } | 618 } |
| 621 | 619 |
| 622 // Check for repetitions | 620 // Check for repetitions |
| 623 auto SeenIter = Seen.find(&Instr); | 621 auto SeenIter = Seen.find(&Instr); |
| 624 if (SeenIter != Seen.end()) { // seen before | 622 if (SeenIter != Seen.end()) { // seen before |
| 625 const Inst *Found = *SeenIter; | 623 const Inst *Found = *SeenIter; |
| 626 Replacements[Instr.getDest()] = Found->getDest(); | 624 Replacements[Instr.getDest()] = Found->getDest(); |
| 627 } else { // new | 625 } else { // new |
| 628 Seen.insert(&Instr); | 626 Seen.insert(&Instr); |
| 629 | 627 |
| 630 // Update dependencies | 628 if (NoSSA) { |
| 631 for (SizeT i = 0; i < Instr.getSrcSize(); ++i) { | 629 // Update dependencies |
| 632 auto *Opnd = Instr.getSrc(i); | 630 for (SizeT i = 0; i < Instr.getSrcSize(); ++i) { |
| 633 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { | 631 auto *Opnd = Instr.getSrc(i); |
| 634 Dependency[Var].push_back(&Instr); | 632 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { |
| 633 Dependency[Var].push_back(&Instr); | |
| 634 } | |
| 635 } | 635 } |
| 636 } | 636 } |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 } | 640 } |
| 641 } | 641 } |
| 642 | 642 |
| 643 void Cfg::loopInvariantCodeMotion() { | 643 void Cfg::loopInvariantCodeMotion() { |
| 644 TimerMarker T(TimerStack::TT_loopInvariantCodeMotion, this); | 644 TimerMarker T(TimerStack::TT_loopInvariantCodeMotion, this); |
| (...skipping 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1767 } | 1767 } |
| 1768 } | 1768 } |
| 1769 // Print each basic block | 1769 // Print each basic block |
| 1770 for (CfgNode *Node : Nodes) | 1770 for (CfgNode *Node : Nodes) |
| 1771 Node->dump(this); | 1771 Node->dump(this); |
| 1772 if (isVerbose(IceV_Instructions)) | 1772 if (isVerbose(IceV_Instructions)) |
| 1773 Str << "}\n"; | 1773 Str << "}\n"; |
| 1774 } | 1774 } |
| 1775 | 1775 |
| 1776 } // end of namespace Ice | 1776 } // end of namespace Ice |
| OLD | NEW |