 Chromium Code Reviews
 Chromium Code Reviews Issue 2069923004:
  Short Circuit Evaluation  (Closed) 
  Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
    
  
    Issue 2069923004:
  Short Circuit Evaluation  (Closed) 
  Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master| 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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { | 626 if (auto *Var = llvm::dyn_cast<Variable>(Opnd)) { | 
| 627 Dependency[Var].push_back(&Instr); | 627 Dependency[Var].push_back(&Instr); | 
| 628 } | 628 } | 
| 629 } | 629 } | 
| 630 } | 630 } | 
| 631 } | 631 } | 
| 632 } | 632 } | 
| 633 } | 633 } | 
| 634 } | 634 } | 
| 635 | 635 | 
| 636 void Cfg::shortCircuitJumps() { | |
| 637 // Split Nodes whenever an early jump is possible. | |
| 638 // __N : | |
| 639 // a = <something> | |
| 640 // Instruction 1 without side effect | |
| 641 // ... b = <something> ... | |
| 642 // Instruction N without side effect | |
| 643 // t1 = or a b | |
| 644 // br t1 __X __Y | |
| 645 // | |
| 646 // is transformed into: | |
| 647 // __N : | |
| 648 // a = <something> | |
| 649 // br a __X __N_ext | |
| 650 // | |
| 651 // __N_ext : | |
| 652 // Instruction 1 without side effect | |
| 653 // ... b = <something> ... | |
| 654 // Instruction N without side effect | |
| 655 // br b __X __Y | |
| 656 //(Similar logic for AND, jump to false instead of true target.) | |
| 657 | |
| 658 TimerMarker T(TimerStack::TT_shortCircuit, this); | |
| 659 getVMetadata()->init(VMK_Uses); | |
| 660 auto NodeStack = this->getNodes(); | |
| 661 CfgUnorderedMap<SizeT, CfgVector<CfgNode*>> Splits; | |
| 662 while (!NodeStack.empty()) { | |
| 663 auto *Node = NodeStack.back(); | |
| 664 NodeStack.pop_back(); | |
| 665 auto NewNode = Node->shortCircuit(); | |
| 666 if (NewNode) { | |
| 667 NodeStack.push_back(NewNode); | |
| 668 NodeStack.push_back(Node); | |
| 669 Splits[Node->getIndex()].push_back(NewNode); | |
| 670 } | |
| 671 } | |
| 672 | |
| 673 // Insert nodes in the right place | |
| 674 NodeList NewList; | |
| 675 NewList.reserve(Nodes.size()); | |
| 676 CfgUnorderedSet<SizeT> Inserted; | |
| 677 for (auto *Node : Nodes) { | |
| 678 if (Inserted.find(Node->getIndex()) != Inserted.end()) | |
| 679 continue; // already inserted | |
| 680 CfgVector<CfgNode *> Stack{Node}; | |
| 
Jim Stichnoth
2016/06/27 19:44:40
Can you use NodeList instead of CfgVector<CfgNode
 
manasijm
2016/06/27 22:00:40
Done.
 | |
| 681 while(!Stack.empty()) { | |
| 
Jim Stichnoth
2016/06/27 19:44:40
Please run "make format"...
 
manasijm
2016/06/27 22:00:40
Acknowledged.
 | |
| 682 auto *Current = Stack.back(); | |
| 683 Stack.pop_back(); | |
| 684 Inserted.insert(Current->getIndex()); | |
| 685 NewList.push_back(Current); | |
| 686 for (auto *Next : Splits[Current->getIndex()]) { | |
| 687 Stack.push_back(Next); | |
| 688 } | |
| 689 } | |
| 690 } | |
| 691 for (SizeT i = 0; i < NewList.size(); ++i) { | |
| 
Jim Stichnoth
2016/06/27 19:44:41
I think it would be better to use a range-based fo
 
manasijm
2016/06/27 22:00:40
Done.
 | |
| 692 NewList[i]->resetIndex(i); | |
| 693 } | |
| 694 Nodes = NewList; | |
| 695 } | |
| 696 | |
| 
Jim Stichnoth
2016/06/27 19:44:40
just one blank line here
 
manasijm
2016/06/27 22:00:40
Done.
 | |
| 697 | |
| 636 void Cfg::doArgLowering() { | 698 void Cfg::doArgLowering() { | 
| 637 TimerMarker T(TimerStack::TT_doArgLowering, this); | 699 TimerMarker T(TimerStack::TT_doArgLowering, this); | 
| 638 getTarget()->lowerArguments(); | 700 getTarget()->lowerArguments(); | 
| 639 } | 701 } | 
| 640 | 702 | 
| 641 void Cfg::sortAndCombineAllocas(CfgVector<Inst *> &Allocas, | 703 void Cfg::sortAndCombineAllocas(CfgVector<Inst *> &Allocas, | 
| 642 uint32_t CombinedAlignment, InstList &Insts, | 704 uint32_t CombinedAlignment, InstList &Insts, | 
| 643 AllocaBaseVariableType BaseVariableType) { | 705 AllocaBaseVariableType BaseVariableType) { | 
| 644 if (Allocas.empty()) | 706 if (Allocas.empty()) | 
| 645 return; | 707 return; | 
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1604 } | 1666 } | 
| 1605 } | 1667 } | 
| 1606 // Print each basic block | 1668 // Print each basic block | 
| 1607 for (CfgNode *Node : Nodes) | 1669 for (CfgNode *Node : Nodes) | 
| 1608 Node->dump(this); | 1670 Node->dump(this); | 
| 1609 if (isVerbose(IceV_Instructions)) | 1671 if (isVerbose(IceV_Instructions)) | 
| 1610 Str << "}\n"; | 1672 Str << "}\n"; | 
| 1611 } | 1673 } | 
| 1612 | 1674 | 
| 1613 } // end of namespace Ice | 1675 } // end of namespace Ice | 
| OLD | NEW |