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 841 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 else | 852 else |
853 Str << ","; | 853 Str << ","; |
854 Var->emit(Func); | 854 Var->emit(Func); |
855 First = false; | 855 First = false; |
856 } | 856 } |
857 } | 857 } |
858 } | 858 } |
859 } | 859 } |
860 } | 860 } |
861 | 861 |
| 862 void updateStats(Cfg *Func, const Inst *I) { |
| 863 // Update emitted instruction count, plus fill/spill count for |
| 864 // Variable operands without a physical register. |
| 865 if (uint32_t Count = I->getEmitInstCount()) { |
| 866 Func->getContext()->statsUpdateEmitted(Count); |
| 867 if (Variable *Dest = I->getDest()) { |
| 868 if (!Dest->hasReg()) |
| 869 Func->getContext()->statsUpdateFills(); |
| 870 } |
| 871 for (SizeT S = 0; S < I->getSrcSize(); ++S) { |
| 872 if (Variable *Src = llvm::dyn_cast<Variable>(I->getSrc(S))) { |
| 873 if (!Src->hasReg()) |
| 874 Func->getContext()->statsUpdateSpills(); |
| 875 } |
| 876 } |
| 877 } |
| 878 } |
| 879 |
862 } // end of anonymous namespace | 880 } // end of anonymous namespace |
863 | 881 |
864 void CfgNode::emit(Cfg *Func) const { | 882 void CfgNode::emit(Cfg *Func) const { |
865 Func->setCurrentNode(this); | 883 Func->setCurrentNode(this); |
866 Ostream &Str = Func->getContext()->getStrEmit(); | 884 Ostream &Str = Func->getContext()->getStrEmit(); |
867 Liveness *Liveness = Func->getLiveness(); | 885 Liveness *Liveness = Func->getLiveness(); |
868 bool DecorateAsm = Liveness && Func->getContext()->getFlags().DecorateAsm; | 886 bool DecorateAsm = Liveness && Func->getContext()->getFlags().DecorateAsm; |
869 if (Func->getEntryNode() == this) { | |
870 Str << Func->getContext()->mangleName(Func->getFunctionName()) << ":\n"; | |
871 } | |
872 Str << getAsmName() << ":\n"; | 887 Str << getAsmName() << ":\n"; |
873 if (Func->useIntegratedAssembler()) { | |
874 Assembler *Asm = Func->getAssembler<Assembler>(); | |
875 Asm->BindCfgNodeLabel(getIndex()); | |
876 } | |
877 std::vector<SizeT> LiveRegCount(Func->getTarget()->getNumRegisters()); | 888 std::vector<SizeT> LiveRegCount(Func->getTarget()->getNumRegisters()); |
878 if (DecorateAsm) | 889 if (DecorateAsm) |
879 emitRegisterUsage(Str, Func, this, true, LiveRegCount); | 890 emitRegisterUsage(Str, Func, this, true, LiveRegCount); |
880 | 891 |
881 for (InstPhi *Phi : Phis) { | 892 for (InstPhi *Phi : Phis) { |
882 if (Phi->isDeleted()) | 893 if (Phi->isDeleted()) |
883 continue; | 894 continue; |
884 // Emitting a Phi instruction should cause an error. | 895 // Emitting a Phi instruction should cause an error. |
885 Inst *Instr = Phi; | 896 Inst *Instr = Phi; |
886 Instr->emit(Func); | 897 Instr->emit(Func); |
887 } | 898 } |
888 for (Inst *I : Insts) { | 899 for (Inst *I : Insts) { |
889 if (I->isDeleted()) | 900 if (I->isDeleted()) |
890 continue; | 901 continue; |
891 if (I->isRedundantAssign()) { | 902 if (I->isRedundantAssign()) { |
892 Variable *Dest = I->getDest(); | 903 Variable *Dest = I->getDest(); |
893 if (DecorateAsm && Dest->hasReg() && !I->isLastUse(I->getSrc(0))) | 904 if (DecorateAsm && Dest->hasReg() && !I->isLastUse(I->getSrc(0))) |
894 ++LiveRegCount[Dest->getRegNum()]; | 905 ++LiveRegCount[Dest->getRegNum()]; |
895 continue; | 906 continue; |
896 } | 907 } |
897 if (Func->useIntegratedAssembler()) { | 908 I->emit(Func); |
898 I->emitIAS(Func); | 909 if (DecorateAsm) |
899 } else { | 910 emitLiveRangesEnded(Str, Func, I, LiveRegCount); |
900 I->emit(Func); | 911 Str << "\n"; |
901 if (DecorateAsm) | 912 updateStats(Func, I); |
902 emitLiveRangesEnded(Str, Func, I, LiveRegCount); | |
903 Str << "\n"; | |
904 } | |
905 // Update emitted instruction count, plus fill/spill count for | |
906 // Variable operands without a physical register. | |
907 if (uint32_t Count = I->getEmitInstCount()) { | |
908 Func->getContext()->statsUpdateEmitted(Count); | |
909 if (Variable *Dest = I->getDest()) { | |
910 if (!Dest->hasReg()) | |
911 Func->getContext()->statsUpdateFills(); | |
912 } | |
913 for (SizeT S = 0; S < I->getSrcSize(); ++S) { | |
914 if (Variable *Src = llvm::dyn_cast<Variable>(I->getSrc(S))) { | |
915 if (!Src->hasReg()) | |
916 Func->getContext()->statsUpdateSpills(); | |
917 } | |
918 } | |
919 } | |
920 } | 913 } |
921 if (DecorateAsm) | 914 if (DecorateAsm) |
922 emitRegisterUsage(Str, Func, this, false, LiveRegCount); | 915 emitRegisterUsage(Str, Func, this, false, LiveRegCount); |
923 } | 916 } |
924 | 917 |
| 918 void CfgNode::emitIAS(Cfg *Func) const { |
| 919 Func->setCurrentNode(this); |
| 920 Assembler *Asm = Func->getAssembler<Assembler>(); |
| 921 Asm->BindCfgNodeLabel(getIndex()); |
| 922 for (InstPhi *Phi : Phis) { |
| 923 if (Phi->isDeleted()) |
| 924 continue; |
| 925 // Emitting a Phi instruction should cause an error. |
| 926 Inst *Instr = Phi; |
| 927 Instr->emitIAS(Func); |
| 928 } |
| 929 for (Inst *I : Insts) { |
| 930 if (I->isDeleted()) |
| 931 continue; |
| 932 if (I->isRedundantAssign()) |
| 933 continue; |
| 934 I->emitIAS(Func); |
| 935 updateStats(Func, I); |
| 936 } |
| 937 } |
| 938 |
925 void CfgNode::dump(Cfg *Func) const { | 939 void CfgNode::dump(Cfg *Func) const { |
926 Func->setCurrentNode(this); | 940 Func->setCurrentNode(this); |
927 Ostream &Str = Func->getContext()->getStrDump(); | 941 Ostream &Str = Func->getContext()->getStrDump(); |
928 Liveness *Liveness = Func->getLiveness(); | 942 Liveness *Liveness = Func->getLiveness(); |
929 if (Func->getContext()->isVerbose(IceV_Instructions)) { | 943 if (Func->getContext()->isVerbose(IceV_Instructions)) { |
930 Str << getName() << ":\n"; | 944 Str << getName() << ":\n"; |
931 } | 945 } |
932 // Dump list of predecessor nodes. | 946 // Dump list of predecessor nodes. |
933 if (Func->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) { | 947 if (Func->getContext()->isVerbose(IceV_Preds) && !InEdges.empty()) { |
934 Str << " // preds = "; | 948 Str << " // preds = "; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
992 if (!First) | 1006 if (!First) |
993 Str << ", "; | 1007 Str << ", "; |
994 First = false; | 1008 First = false; |
995 Str << "%" << I->getName(); | 1009 Str << "%" << I->getName(); |
996 } | 1010 } |
997 Str << "\n"; | 1011 Str << "\n"; |
998 } | 1012 } |
999 } | 1013 } |
1000 | 1014 |
1001 } // end of namespace Ice | 1015 } // end of namespace Ice |
OLD | NEW |