OLD | NEW |
1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) implementation -----===// | 1 //===- subzero/src/IceCfgNode.cpp - Basic block (node) 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 // This file implements the CfgNode class, including the complexities | 10 // This file implements the CfgNode class, including the complexities |
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 Liveness *Liveness = Func->getLiveness(); | 787 Liveness *Liveness = Func->getLiveness(); |
788 const LivenessBV *Live; | 788 const LivenessBV *Live; |
789 if (IsLiveIn) { | 789 if (IsLiveIn) { |
790 Live = &Liveness->getLiveIn(Node); | 790 Live = &Liveness->getLiveIn(Node); |
791 Str << "\t\t\t\t# LiveIn="; | 791 Str << "\t\t\t\t# LiveIn="; |
792 } else { | 792 } else { |
793 Live = &Liveness->getLiveOut(Node); | 793 Live = &Liveness->getLiveOut(Node); |
794 Str << "\t\t\t\t# LiveOut="; | 794 Str << "\t\t\t\t# LiveOut="; |
795 } | 795 } |
796 if (!Live->empty()) { | 796 if (!Live->empty()) { |
797 bool First = true; | 797 std::vector<Variable *> LiveRegs; |
798 for (SizeT i = 0; i < Live->size(); ++i) { | 798 for (SizeT i = 0; i < Live->size(); ++i) { |
799 if ((*Live)[i]) { | 799 if ((*Live)[i]) { |
800 Variable *Var = Liveness->getVariable(i, Node); | 800 Variable *Var = Liveness->getVariable(i, Node); |
801 if (Var->hasReg()) { | 801 if (Var->hasReg()) { |
802 if (IsLiveIn) | 802 if (IsLiveIn) |
803 ++LiveRegCount[Var->getRegNum()]; | 803 ++LiveRegCount[Var->getRegNum()]; |
804 if (!First) | 804 LiveRegs.push_back(Var); |
805 Str << ","; | |
806 First = false; | |
807 Var->emit(Func); | |
808 } | 805 } |
809 } | 806 } |
810 } | 807 } |
| 808 // Sort the variables by regnum so they are always printed in a |
| 809 // familiar order. |
| 810 std::sort(LiveRegs.begin(), LiveRegs.end(), |
| 811 [](const Variable *V1, const Variable *V2) { |
| 812 return V1->getRegNum() < V2->getRegNum(); |
| 813 }); |
| 814 bool First = true; |
| 815 for (Variable *Var : LiveRegs) { |
| 816 if (!First) |
| 817 Str << ","; |
| 818 First = false; |
| 819 Var->emit(Func); |
| 820 } |
811 } | 821 } |
812 Str << "\n"; | 822 Str << "\n"; |
813 } | 823 } |
814 | 824 |
815 void emitLiveRangesEnded(Ostream &Str, const Cfg *Func, const Inst *Instr, | 825 void emitLiveRangesEnded(Ostream &Str, const Cfg *Func, const Inst *Instr, |
816 std::vector<SizeT> &LiveRegCount) { | 826 std::vector<SizeT> &LiveRegCount) { |
817 if (!ALLOW_DUMP) | 827 if (!ALLOW_DUMP) |
818 return; | 828 return; |
819 bool First = true; | 829 bool First = true; |
820 Variable *Dest = Instr->getDest(); | 830 Variable *Dest = Instr->getDest(); |
821 if (Dest && Dest->hasReg()) | 831 if (Dest && Dest->hasReg()) |
822 ++LiveRegCount[Dest->getRegNum()]; | 832 ++LiveRegCount[Dest->getRegNum()]; |
823 for (SizeT I = 0; I < Instr->getSrcSize(); ++I) { | 833 for (SizeT I = 0; I < Instr->getSrcSize(); ++I) { |
824 Operand *Src = Instr->getSrc(I); | 834 Operand *Src = Instr->getSrc(I); |
825 SizeT NumVars = Src->getNumVars(); | 835 SizeT NumVars = Src->getNumVars(); |
826 for (SizeT J = 0; J < NumVars; ++J) { | 836 for (SizeT J = 0; J < NumVars; ++J) { |
827 const Variable *Var = Src->getVar(J); | 837 const Variable *Var = Src->getVar(J); |
828 if (Instr->isLastUse(Var) && | 838 bool ShouldEmit = Instr->isLastUse(Var); |
829 (!Var->hasReg() || --LiveRegCount[Var->getRegNum()] == 0)) { | 839 if (Var->hasReg()) { |
| 840 // Don't report end of live range until the live count reaches 0. |
| 841 SizeT NewCount = --LiveRegCount[Var->getRegNum()]; |
| 842 if (NewCount) |
| 843 ShouldEmit = false; |
| 844 } |
| 845 if (ShouldEmit) { |
830 if (First) | 846 if (First) |
831 Str << " \t# END="; | 847 Str << " \t# END="; |
832 else | 848 else |
833 Str << ","; | 849 Str << ","; |
834 Var->emit(Func); | 850 Var->emit(Func); |
835 First = false; | 851 First = false; |
836 } | 852 } |
837 } | 853 } |
838 } | 854 } |
839 } | 855 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 | 893 |
878 for (const Inst &I : Phis) { | 894 for (const Inst &I : Phis) { |
879 if (I.isDeleted()) | 895 if (I.isDeleted()) |
880 continue; | 896 continue; |
881 // Emitting a Phi instruction should cause an error. | 897 // Emitting a Phi instruction should cause an error. |
882 I.emit(Func); | 898 I.emit(Func); |
883 } | 899 } |
884 for (const Inst &I : Insts) { | 900 for (const Inst &I : Insts) { |
885 if (I.isDeleted()) | 901 if (I.isDeleted()) |
886 continue; | 902 continue; |
887 if (I.isRedundantAssign()) { | 903 if (I.isRedundantAssign()) |
888 Variable *Dest = I.getDest(); | |
889 if (DecorateAsm && Dest->hasReg() && !I.isLastUse(I.getSrc(0))) | |
890 ++LiveRegCount[Dest->getRegNum()]; | |
891 continue; | 904 continue; |
892 } | |
893 I.emit(Func); | 905 I.emit(Func); |
894 if (DecorateAsm) | 906 if (DecorateAsm) |
895 emitLiveRangesEnded(Str, Func, &I, LiveRegCount); | 907 emitLiveRangesEnded(Str, Func, &I, LiveRegCount); |
896 Str << "\n"; | 908 Str << "\n"; |
897 updateStats(Func, &I); | 909 updateStats(Func, &I); |
898 } | 910 } |
899 if (DecorateAsm) { | 911 if (DecorateAsm) { |
900 const bool IsLiveIn = false; | 912 const bool IsLiveIn = false; |
901 emitRegisterUsage(Str, Func, this, IsLiveIn, LiveRegCount); | 913 emitRegisterUsage(Str, Func, this, IsLiveIn, LiveRegCount); |
902 } | 914 } |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 if (!First) | 1215 if (!First) |
1204 Str << ", "; | 1216 Str << ", "; |
1205 First = false; | 1217 First = false; |
1206 Str << "%" << I->getName(); | 1218 Str << "%" << I->getName(); |
1207 } | 1219 } |
1208 Str << "\n"; | 1220 Str << "\n"; |
1209 } | 1221 } |
1210 } | 1222 } |
1211 | 1223 |
1212 } // end of namespace Ice | 1224 } // end of namespace Ice |
OLD | NEW |