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 780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
791 } | 791 } |
792 } | 792 } |
793 | 793 |
794 SizeT NodeIndex = 0; | 794 SizeT NodeIndex = 0; |
795 for (auto *Node : NewList) { | 795 for (auto *Node : NewList) { |
796 Node->resetIndex(NodeIndex++); | 796 Node->resetIndex(NodeIndex++); |
797 } | 797 } |
798 Nodes = NewList; | 798 Nodes = NewList; |
799 } | 799 } |
800 | 800 |
801 void Cfg::floatConstantCSE() { | |
802 // Load multiple uses of a floating point constant (between two call | |
803 // instructions or block start/end) into a variable before its first use. | |
804 // t1 = b + 1.0 | |
805 // t2 = c + 1.0 | |
806 // Gets transformed to: | |
807 // t0 = 1.0 | |
808 // t0_1 = t0 | |
809 // t1 = b + t0_1 | |
810 // t2 = c + t0_1 | |
811 // Call instructions reset the procedure, but uses the same variable, just in | |
Jim Stichnoth
2016/08/04 01:45:39
s/uses/use/
manasijm
2016/08/04 21:29:44
Done.
| |
812 // case it got a register. We are assuming floating point registers are not | |
813 // callee saved in general. Example, continuing from before: | |
814 // result = call <some function> | |
815 // t3 = d + 1.0 | |
816 // Gets transformed to: | |
817 // result = call <some function> | |
818 // t0_2 = t0 | |
819 // t3 = d + t0_2 | |
820 // TODO(manasijm, stichnot): Figure out how to 'link' t0 to the stack slot of | |
821 // 1.0. When t0 does not get a register, introducing an extra assignment | |
822 // statement does not make sense. The relevant portion is marked below. | |
823 | |
824 TimerMarker _(TimerStack::TT_floatConstantCse, this); | |
825 for (CfgNode *Node : getNodes()) { | |
826 | |
827 CfgUnorderedMap<Constant *, Variable *> ConstCache; | |
828 llvm::ilist_iterator<Inst> Current = Node->getInsts().begin(); | |
Jim Stichnoth
2016/08/04 01:45:39
I would just use "auto" here, I do that quite ofte
manasijm
2016/08/04 21:29:44
Done.
| |
829 auto End = Node->getInsts().end(); | |
830 while (Current != End) { | |
831 CfgUnorderedMap<Constant *, CfgVector<Inst *>> FloatUses; | |
832 if (llvm::isa<InstCall>(*Current)) { | |
Jim Stichnoth
2016/08/04 01:45:39
Instead of *Current, please use iteratorToInst(Cur
manasijm
2016/08/04 21:29:44
Done.
| |
833 Current++; | |
Jim Stichnoth
2016/08/04 01:45:39
++Current
manasijm
2016/08/04 21:29:44
Done.
| |
834 assert(Current); | |
Jim Stichnoth
2016/08/04 01:45:39
What exactly does this assert? With a quick searc
manasijm
2016/08/04 21:29:45
Changed to assert(Current != End)
This will be tri
| |
835 } | |
836 while (Current != End && !llvm::isa<InstCall>(*Current)) { | |
Jim Stichnoth
2016/08/04 01:45:39
iteratorToInst(Current)
manasijm
2016/08/04 21:29:45
Done.
| |
837 for (SizeT i = 0; i < Current->getSrcSize(); ++i) { | |
838 if (auto *Const = llvm::dyn_cast<Constant>(Current->getSrc(i))) { | |
839 if (Const->getType() == IceType_f32 || | |
840 Const->getType() == IceType_f64) { | |
841 FloatUses[Const].push_back(Current); | |
842 } | |
843 } | |
844 } | |
845 Current++; | |
846 } | |
847 for (auto &Pair : FloatUses) { | |
848 static constexpr SizeT MinUseThreshold = 3; | |
849 if (Pair.second.size() < MinUseThreshold) | |
850 continue; | |
851 // Only consider constants with at least `MinUseThreshold` uses | |
852 auto &Insts = Node->getInsts(); | |
853 | |
854 if (ConstCache.find(Pair.first) == ConstCache.end()) { | |
855 // Saw a constant (which is used at least twice) for the first time | |
856 auto *NewVar = makeVariable(Pair.first->getType()); | |
857 // NewVar->setLinkedTo(Pair.first); | |
858 // TODO(manasijm): Plumbing for linking to an Operand. | |
859 auto *Assign = InstAssign::create(Node->getCfg(), NewVar, Pair.first); | |
860 Insts.insert(Pair.second[0], Assign); | |
861 ConstCache[Pair.first] = NewVar; | |
862 } | |
863 | |
864 auto *NewVar = makeVariable(Pair.first->getType()); | |
865 NewVar->setLinkedTo(ConstCache[Pair.first]); | |
866 auto *Assign = | |
867 InstAssign::create(Node->getCfg(), NewVar, ConstCache[Pair.first]); | |
868 | |
869 Insts.insert(Pair.second[0], Assign); | |
870 for (auto *InstUse : Pair.second) { | |
871 for (SizeT i = 0; i < InstUse->getSrcSize(); ++i) { | |
872 if (auto *Const = llvm::dyn_cast<Constant>(InstUse->getSrc(i))) { | |
873 if (Const == Pair.first) { | |
874 InstUse->replaceSource(i, NewVar); | |
875 } | |
876 } | |
877 } | |
878 } | |
879 } | |
880 } | |
881 } | |
882 } | |
883 | |
801 void Cfg::doArgLowering() { | 884 void Cfg::doArgLowering() { |
802 TimerMarker T(TimerStack::TT_doArgLowering, this); | 885 TimerMarker T(TimerStack::TT_doArgLowering, this); |
803 getTarget()->lowerArguments(); | 886 getTarget()->lowerArguments(); |
804 } | 887 } |
805 | 888 |
806 void Cfg::sortAndCombineAllocas(CfgVector<InstAlloca *> &Allocas, | 889 void Cfg::sortAndCombineAllocas(CfgVector<InstAlloca *> &Allocas, |
807 uint32_t CombinedAlignment, InstList &Insts, | 890 uint32_t CombinedAlignment, InstList &Insts, |
808 AllocaBaseVariableType BaseVariableType) { | 891 AllocaBaseVariableType BaseVariableType) { |
809 if (Allocas.empty()) | 892 if (Allocas.empty()) |
810 return; | 893 return; |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1777 } | 1860 } |
1778 } | 1861 } |
1779 // Print each basic block | 1862 // Print each basic block |
1780 for (CfgNode *Node : Nodes) | 1863 for (CfgNode *Node : Nodes) |
1781 Node->dump(this); | 1864 Node->dump(this); |
1782 if (isVerbose(IceV_Instructions)) | 1865 if (isVerbose(IceV_Instructions)) |
1783 Str << "}\n"; | 1866 Str << "}\n"; |
1784 } | 1867 } |
1785 | 1868 |
1786 } // end of namespace Ice | 1869 } // end of namespace Ice |
OLD | NEW |