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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 CfgNode *EntryNode = getEntryNode(); | 740 CfgNode *EntryNode = getEntryNode(); |
741 assert(EntryNode); | 741 assert(EntryNode); |
742 // LLVM enforces power of 2 alignment. | 742 // LLVM enforces power of 2 alignment. |
743 assert(llvm::isPowerOf2_32(StackAlignment)); | 743 assert(llvm::isPowerOf2_32(StackAlignment)); |
744 // Determine if there are large alignment allocations in the entry block or | 744 // Determine if there are large alignment allocations in the entry block or |
745 // dynamic allocations (variable size in the entry block). | 745 // dynamic allocations (variable size in the entry block). |
746 bool HasLargeAlignment = false; | 746 bool HasLargeAlignment = false; |
747 bool HasDynamicAllocation = false; | 747 bool HasDynamicAllocation = false; |
748 for (Inst &Instr : EntryNode->getInsts()) { | 748 for (Inst &Instr : EntryNode->getInsts()) { |
749 if (auto *Alloca = llvm::dyn_cast<InstAlloca>(&Instr)) { | 749 if (auto *Alloca = llvm::dyn_cast<InstAlloca>(&Instr)) { |
| 750 if (Instr.isDeleted()) |
| 751 continue; |
750 uint32_t AlignmentParam = Alloca->getAlignInBytes(); | 752 uint32_t AlignmentParam = Alloca->getAlignInBytes(); |
751 if (AlignmentParam > StackAlignment) | 753 if (AlignmentParam > StackAlignment) |
752 HasLargeAlignment = true; | 754 HasLargeAlignment = true; |
753 if (llvm::isa<Constant>(Alloca->getSizeInBytes())) | 755 if (llvm::isa<Constant>(Alloca->getSizeInBytes())) |
754 Alloca->setKnownFrameOffset(); | 756 Alloca->setKnownFrameOffset(); |
755 else { | 757 else { |
756 HasDynamicAllocation = true; | 758 HasDynamicAllocation = true; |
757 // If Allocas are not sorted, the first dynamic allocation causes | 759 // If Allocas are not sorted, the first dynamic allocation causes |
758 // later Allocas to be at unknown offsets relative to the stack/frame. | 760 // later Allocas to be at unknown offsets relative to the stack/frame. |
759 if (!SortAndCombine) | 761 if (!SortAndCombine) |
760 break; | 762 break; |
761 } | 763 } |
762 } | 764 } |
763 } | 765 } |
764 // Don't do the heavyweight sorting and layout for low optimization levels. | 766 // Don't do the heavyweight sorting and layout for low optimization levels. |
765 if (!SortAndCombine) | 767 if (!SortAndCombine) |
766 return; | 768 return; |
767 // Any alloca outside the entry block is a dynamic allocation. | 769 // Any alloca outside the entry block is a dynamic allocation. |
768 for (CfgNode *Node : Nodes) { | 770 for (CfgNode *Node : Nodes) { |
769 if (Node == EntryNode) | 771 if (Node == EntryNode) |
770 continue; | 772 continue; |
771 for (Inst &Instr : Node->getInsts()) { | 773 for (Inst &Instr : Node->getInsts()) { |
772 if (llvm::isa<InstAlloca>(&Instr)) { | 774 if (llvm::isa<InstAlloca>(&Instr) && !Instr.isDeleted()) { |
773 // Allocations outside the entry block require a frame pointer. | 775 // Allocations outside the entry block require a frame pointer. |
774 HasDynamicAllocation = true; | 776 HasDynamicAllocation = true; |
775 break; | 777 break; |
776 } | 778 } |
777 } | 779 } |
778 if (HasDynamicAllocation) | 780 if (HasDynamicAllocation) |
779 break; | 781 break; |
780 } | 782 } |
781 // Mark the target as requiring a frame pointer. | 783 // Mark the target as requiring a frame pointer. |
782 if (HasLargeAlignment || HasDynamicAllocation) | 784 if (HasLargeAlignment || HasDynamicAllocation) |
783 getTarget()->setHasFramePointer(); | 785 getTarget()->setHasFramePointer(); |
784 // Collect the Allocas into the two vectors. | 786 // Collect the Allocas into the two vectors. |
785 // Allocas in the entry block that have constant size and alignment less | 787 // Allocas in the entry block that have constant size and alignment less |
786 // than or equal to the function's stack alignment. | 788 // than or equal to the function's stack alignment. |
787 CfgVector<Inst *> FixedAllocas; | 789 CfgVector<Inst *> FixedAllocas; |
788 // Allocas in the entry block that have constant size and alignment greater | 790 // Allocas in the entry block that have constant size and alignment greater |
789 // than the function's stack alignment. | 791 // than the function's stack alignment. |
790 CfgVector<Inst *> AlignedAllocas; | 792 CfgVector<Inst *> AlignedAllocas; |
791 // Maximum alignment used by any alloca. | 793 // Maximum alignment used by any alloca. |
792 uint32_t MaxAlignment = StackAlignment; | 794 uint32_t MaxAlignment = StackAlignment; |
793 for (Inst &Instr : EntryNode->getInsts()) { | 795 for (Inst &Instr : EntryNode->getInsts()) { |
794 if (auto *Alloca = llvm::dyn_cast<InstAlloca>(&Instr)) { | 796 if (auto *Alloca = llvm::dyn_cast<InstAlloca>(&Instr)) { |
795 if (!llvm::isa<Constant>(Alloca->getSizeInBytes())) | 797 if (!llvm::isa<Constant>(Alloca->getSizeInBytes()) || Alloca->isDeleted()) |
796 continue; | 798 continue; |
797 uint32_t AlignmentParam = Alloca->getAlignInBytes(); | 799 uint32_t AlignmentParam = Alloca->getAlignInBytes(); |
798 // For default align=0, set it to the real value 1, to avoid any | 800 // For default align=0, set it to the real value 1, to avoid any |
799 // bit-manipulation problems below. | 801 // bit-manipulation problems below. |
800 AlignmentParam = std::max(AlignmentParam, 1u); | 802 AlignmentParam = std::max(AlignmentParam, 1u); |
801 assert(llvm::isPowerOf2_32(AlignmentParam)); | 803 assert(llvm::isPowerOf2_32(AlignmentParam)); |
802 if (HasDynamicAllocation && AlignmentParam > StackAlignment) { | 804 if (HasDynamicAllocation && AlignmentParam > StackAlignment) { |
803 // If we have both dynamic allocations and large stack alignments, | 805 // If we have both dynamic allocations and large stack alignments, |
804 // high-alignment allocations are pulled out with their own base. | 806 // high-alignment allocations are pulled out with their own base. |
805 AlignedAllocas.push_back(Alloca); | 807 AlignedAllocas.push_back(Alloca); |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1611 } | 1613 } |
1612 } | 1614 } |
1613 // Print each basic block | 1615 // Print each basic block |
1614 for (CfgNode *Node : Nodes) | 1616 for (CfgNode *Node : Nodes) |
1615 Node->dump(this); | 1617 Node->dump(this); |
1616 if (isVerbose(IceV_Instructions)) | 1618 if (isVerbose(IceV_Instructions)) |
1617 Str << "}\n"; | 1619 Str << "}\n"; |
1618 } | 1620 } |
1619 | 1621 |
1620 } // end of namespace Ice | 1622 } // end of namespace Ice |
OLD | NEW |