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 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { | 633 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { |
| 634 Dependency[Var].push_back(&Instr); | 634 Dependency[Var].push_back(&Instr); |
| 635 } | 635 } |
| 636 } | 636 } |
| 637 } | 637 } |
| 638 } | 638 } |
| 639 } | 639 } |
| 640 } | 640 } |
| 641 } | 641 } |
| 642 | 642 |
| 643 void Cfg::shortCircuitJumps() { | |
| 644 // Split Nodes whenever an early jump is possible. | |
| 645 // __N : | |
| 646 // a = <something> | |
| 647 // Instruction 1 without side effect | |
| 648 // ... b = <something> ... | |
| 649 // Instruction N without side effect | |
| 650 // t1 = or a b | |
| 651 // br t1 __X __Y | |
| 652 // | |
| 653 // is transformed into: | |
| 654 // __N : | |
| 655 // a = <something> | |
| 656 // br a __X __N_ext | |
| 657 // | |
| 658 // __N_ext : | |
| 659 // Instruction 1 without side effect | |
| 660 // ... b = <something> ... | |
| 661 // Instruction N without side effect | |
| 662 // br b __X __Y | |
| 663 //(Similar logic for AND, jump to false instead of true target.) | |
|
Jim Stichnoth
2016/06/27 22:41:59
Can you add a space after the "//"? I thought "ma
| |
| 664 | |
| 665 TimerMarker T(TimerStack::TT_shortCircuit, this); | |
| 666 getVMetadata()->init(VMK_Uses); | |
| 667 auto NodeStack = this->getNodes(); | |
| 668 CfgUnorderedMap<SizeT, CfgVector<CfgNode *>> Splits; | |
| 669 while (!NodeStack.empty()) { | |
| 670 auto *Node = NodeStack.back(); | |
| 671 NodeStack.pop_back(); | |
| 672 auto NewNode = Node->shortCircuit(); | |
| 673 if (NewNode) { | |
| 674 NodeStack.push_back(NewNode); | |
| 675 NodeStack.push_back(Node); | |
| 676 Splits[Node->getIndex()].push_back(NewNode); | |
| 677 } | |
| 678 } | |
| 679 | |
| 680 // Insert nodes in the right place | |
| 681 NodeList NewList; | |
| 682 NewList.reserve(Nodes.size()); | |
| 683 CfgUnorderedSet<SizeT> Inserted; | |
| 684 for (auto *Node : Nodes) { | |
| 685 if (Inserted.find(Node->getIndex()) != Inserted.end()) | |
| 686 continue; // already inserted | |
| 687 NodeList Stack{Node}; | |
| 688 while (!Stack.empty()) { | |
| 689 auto *Current = Stack.back(); | |
| 690 Stack.pop_back(); | |
| 691 Inserted.insert(Current->getIndex()); | |
| 692 NewList.push_back(Current); | |
| 693 for (auto *Next : Splits[Current->getIndex()]) { | |
| 694 Stack.push_back(Next); | |
| 695 } | |
| 696 } | |
| 697 } | |
| 698 | |
| 699 SizeT NodeIndex = 0; | |
| 700 for (auto *Node : NewList) { | |
| 701 Node->resetIndex(NodeIndex++); | |
| 702 } | |
| 703 Nodes = NewList; | |
| 704 } | |
| 705 | |
| 643 void Cfg::doArgLowering() { | 706 void Cfg::doArgLowering() { |
| 644 TimerMarker T(TimerStack::TT_doArgLowering, this); | 707 TimerMarker T(TimerStack::TT_doArgLowering, this); |
| 645 getTarget()->lowerArguments(); | 708 getTarget()->lowerArguments(); |
| 646 } | 709 } |
| 647 | 710 |
| 648 void Cfg::sortAndCombineAllocas(CfgVector<Inst *> &Allocas, | 711 void Cfg::sortAndCombineAllocas(CfgVector<Inst *> &Allocas, |
| 649 uint32_t CombinedAlignment, InstList &Insts, | 712 uint32_t CombinedAlignment, InstList &Insts, |
| 650 AllocaBaseVariableType BaseVariableType) { | 713 AllocaBaseVariableType BaseVariableType) { |
| 651 if (Allocas.empty()) | 714 if (Allocas.empty()) |
| 652 return; | 715 return; |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1611 } | 1674 } |
| 1612 } | 1675 } |
| 1613 // Print each basic block | 1676 // Print each basic block |
| 1614 for (CfgNode *Node : Nodes) | 1677 for (CfgNode *Node : Nodes) |
| 1615 Node->dump(this); | 1678 Node->dump(this); |
| 1616 if (isVerbose(IceV_Instructions)) | 1679 if (isVerbose(IceV_Instructions)) |
| 1617 Str << "}\n"; | 1680 Str << "}\n"; |
| 1618 } | 1681 } |
| 1619 | 1682 |
| 1620 } // end of namespace Ice | 1683 } // end of namespace Ice |
| OLD | NEW |