| 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 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 for (const InstJumpTable *JT : JumpTables) | 967 for (const InstJumpTable *JT : JumpTables) |
| 968 for (SizeT I = 0; I < JT->getNumTargets(); ++I) | 968 for (SizeT I = 0; I < JT->getNumTargets(); ++I) |
| 969 JT->getTarget(I)->setNeedsAlignment(); | 969 JT->getTarget(I)->setNeedsAlignment(); |
| 970 } | 970 } |
| 971 | 971 |
| 972 // ======================== Dump routines ======================== // | 972 // ======================== Dump routines ======================== // |
| 973 | 973 |
| 974 // emitTextHeader() is not target-specific (apart from what is abstracted by | 974 // emitTextHeader() is not target-specific (apart from what is abstracted by |
| 975 // the Assembler), so it is defined here rather than in the target lowering | 975 // the Assembler), so it is defined here rather than in the target lowering |
| 976 // class. | 976 // class. |
| 977 void Cfg::emitTextHeader(const IceString &MangledName, GlobalContext *Ctx, | 977 void Cfg::emitTextHeader(const IceString &Name, GlobalContext *Ctx, |
| 978 const Assembler *Asm) { | 978 const Assembler *Asm) { |
| 979 if (!BuildDefs::dump()) | 979 if (!BuildDefs::dump()) |
| 980 return; | 980 return; |
| 981 Ostream &Str = Ctx->getStrEmit(); | 981 Ostream &Str = Ctx->getStrEmit(); |
| 982 Str << "\t.text\n"; | 982 Str << "\t.text\n"; |
| 983 if (Ctx->getFlags().getFunctionSections()) | 983 if (Ctx->getFlags().getFunctionSections()) |
| 984 Str << "\t.section\t.text." << MangledName << ",\"ax\",%progbits\n"; | 984 Str << "\t.section\t.text." << Name << ",\"ax\",%progbits\n"; |
| 985 if (!Asm->getInternal() || Ctx->getFlags().getDisableInternal()) { | 985 if (!Asm->getInternal() || Ctx->getFlags().getDisableInternal()) { |
| 986 Str << "\t.globl\t" << MangledName << "\n"; | 986 Str << "\t.globl\t" << Name << "\n"; |
| 987 Str << "\t.type\t" << MangledName << ",%function\n"; | 987 Str << "\t.type\t" << Name << ",%function\n"; |
| 988 } | 988 } |
| 989 Str << "\t" << Asm->getAlignDirective() << " " | 989 Str << "\t" << Asm->getAlignDirective() << " " |
| 990 << Asm->getBundleAlignLog2Bytes() << ",0x"; | 990 << Asm->getBundleAlignLog2Bytes() << ",0x"; |
| 991 for (uint8_t I : Asm->getNonExecBundlePadding()) | 991 for (uint8_t I : Asm->getNonExecBundlePadding()) |
| 992 Str.write_hex(I); | 992 Str.write_hex(I); |
| 993 Str << "\n"; | 993 Str << "\n"; |
| 994 Str << MangledName << ":\n"; | 994 Str << Name << ":\n"; |
| 995 } | 995 } |
| 996 | 996 |
| 997 void Cfg::deleteJumpTableInsts() { | 997 void Cfg::deleteJumpTableInsts() { |
| 998 for (InstJumpTable *JumpTable : JumpTables) | 998 for (InstJumpTable *JumpTable : JumpTables) |
| 999 JumpTable->setDeleted(); | 999 JumpTable->setDeleted(); |
| 1000 } | 1000 } |
| 1001 | 1001 |
| 1002 void Cfg::emitJumpTables() { | 1002 void Cfg::emitJumpTables() { |
| 1003 switch (Ctx->getFlags().getOutFileType()) { | 1003 switch (Ctx->getFlags().getOutFileType()) { |
| 1004 case FT_Elf: | 1004 case FT_Elf: |
| 1005 case FT_Iasm: { | 1005 case FT_Iasm: { |
| 1006 // The emission needs to be delayed until the after the text section so | 1006 // The emission needs to be delayed until the after the text section so |
| 1007 // save the offsets in the global context. | 1007 // save the offsets in the global context. |
| 1008 IceString MangledName = Ctx->mangleName(getFunctionName()); | |
| 1009 for (const InstJumpTable *JumpTable : JumpTables) { | 1008 for (const InstJumpTable *JumpTable : JumpTables) { |
| 1010 SizeT NumTargets = JumpTable->getNumTargets(); | 1009 SizeT NumTargets = JumpTable->getNumTargets(); |
| 1011 JumpTableData::TargetList TargetList; | 1010 JumpTableData::TargetList TargetList; |
| 1012 for (SizeT I = 0; I < NumTargets; ++I) { | 1011 for (SizeT I = 0; I < NumTargets; ++I) { |
| 1013 SizeT Index = JumpTable->getTarget(I)->getIndex(); | 1012 SizeT Index = JumpTable->getTarget(I)->getIndex(); |
| 1014 TargetList.emplace_back( | 1013 TargetList.emplace_back( |
| 1015 getAssembler()->getCfgNodeLabel(Index)->getPosition()); | 1014 getAssembler()->getCfgNodeLabel(Index)->getPosition()); |
| 1016 } | 1015 } |
| 1017 Ctx->addJumpTable(MangledName, JumpTable->getId(), TargetList); | 1016 Ctx->addJumpTable(FunctionName, JumpTable->getId(), TargetList); |
| 1018 } | 1017 } |
| 1019 } break; | 1018 } break; |
| 1020 case FT_Asm: { | 1019 case FT_Asm: { |
| 1021 // Emit the assembly directly so we don't need to hang on to all the names | 1020 // Emit the assembly directly so we don't need to hang on to all the names |
| 1022 for (const InstJumpTable *JumpTable : JumpTables) | 1021 for (const InstJumpTable *JumpTable : JumpTables) |
| 1023 getTarget()->emitJumpTable(this, JumpTable); | 1022 getTarget()->emitJumpTable(this, JumpTable); |
| 1024 } break; | 1023 } break; |
| 1025 } | 1024 } |
| 1026 } | 1025 } |
| 1027 | 1026 |
| 1028 void Cfg::emit() { | 1027 void Cfg::emit() { |
| 1029 if (!BuildDefs::dump()) | 1028 if (!BuildDefs::dump()) |
| 1030 return; | 1029 return; |
| 1031 TimerMarker T(TimerStack::TT_emit, this); | 1030 TimerMarker T(TimerStack::TT_emit, this); |
| 1032 if (Ctx->getFlags().getDecorateAsm()) { | 1031 if (Ctx->getFlags().getDecorateAsm()) { |
| 1033 renumberInstructions(); | 1032 renumberInstructions(); |
| 1034 getVMetadata()->init(VMK_Uses); | 1033 getVMetadata()->init(VMK_Uses); |
| 1035 liveness(Liveness_Basic); | 1034 liveness(Liveness_Basic); |
| 1036 dump("After recomputing liveness for -decorate-asm"); | 1035 dump("After recomputing liveness for -decorate-asm"); |
| 1037 } | 1036 } |
| 1038 OstreamLocker L(Ctx); | 1037 OstreamLocker L(Ctx); |
| 1039 Ostream &Str = Ctx->getStrEmit(); | 1038 Ostream &Str = Ctx->getStrEmit(); |
| 1040 IceString MangledName = Ctx->mangleName(getFunctionName()); | |
| 1041 const Assembler *Asm = getAssembler<>(); | 1039 const Assembler *Asm = getAssembler<>(); |
| 1042 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); | 1040 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
| 1043 | 1041 |
| 1044 emitTextHeader(MangledName, Ctx, Asm); | 1042 emitTextHeader(FunctionName, Ctx, Asm); |
| 1045 deleteJumpTableInsts(); | 1043 deleteJumpTableInsts(); |
| 1046 if (Ctx->getFlags().getDecorateAsm()) { | 1044 if (Ctx->getFlags().getDecorateAsm()) { |
| 1047 for (Variable *Var : getVariables()) { | 1045 for (Variable *Var : getVariables()) { |
| 1048 if (Var->getStackOffset() && !Var->isRematerializable()) { | 1046 if (Var->getStackOffset() && !Var->isRematerializable()) { |
| 1049 Str << "\t" << Var->getSymbolicStackOffset(this) << " = " | 1047 Str << "\t" << Var->getSymbolicStackOffset(this) << " = " |
| 1050 << Var->getStackOffset() << "\n"; | 1048 << Var->getStackOffset() << "\n"; |
| 1051 } | 1049 } |
| 1052 } | 1050 } |
| 1053 } | 1051 } |
| 1054 for (CfgNode *Node : Nodes) { | 1052 for (CfgNode *Node : Nodes) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 Str << "================ " << Message << " ================\n"; | 1094 Str << "================ " << Message << " ================\n"; |
| 1097 if (isVerbose(IceV_Mem)) { | 1095 if (isVerbose(IceV_Mem)) { |
| 1098 Str << "Memory size = " << getTotalMemoryMB() << " MB\n"; | 1096 Str << "Memory size = " << getTotalMemoryMB() << " MB\n"; |
| 1099 } | 1097 } |
| 1100 setCurrentNode(getEntryNode()); | 1098 setCurrentNode(getEntryNode()); |
| 1101 // Print function name+args | 1099 // Print function name+args |
| 1102 if (isVerbose(IceV_Instructions)) { | 1100 if (isVerbose(IceV_Instructions)) { |
| 1103 Str << "define "; | 1101 Str << "define "; |
| 1104 if (getInternal() && !Ctx->getFlags().getDisableInternal()) | 1102 if (getInternal() && !Ctx->getFlags().getDisableInternal()) |
| 1105 Str << "internal "; | 1103 Str << "internal "; |
| 1106 Str << ReturnType << " @" << Ctx->mangleName(getFunctionName()) << "("; | 1104 Str << ReturnType << " @" << getFunctionName() << "("; |
| 1107 for (SizeT i = 0; i < Args.size(); ++i) { | 1105 for (SizeT i = 0; i < Args.size(); ++i) { |
| 1108 if (i > 0) | 1106 if (i > 0) |
| 1109 Str << ", "; | 1107 Str << ", "; |
| 1110 Str << Args[i]->getType() << " "; | 1108 Str << Args[i]->getType() << " "; |
| 1111 Args[i]->dump(this); | 1109 Args[i]->dump(this); |
| 1112 } | 1110 } |
| 1113 // Append an extra copy of the function name here, in order to print its | 1111 // Append an extra copy of the function name here, in order to print its |
| 1114 // size stats but not mess up lit tests. | 1112 // size stats but not mess up lit tests. |
| 1115 Str << ") { # " << getFunctionNameAndSize() << "\n"; | 1113 Str << ") { # " << getFunctionNameAndSize() << "\n"; |
| 1116 } | 1114 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1145 } | 1143 } |
| 1146 } | 1144 } |
| 1147 // Print each basic block | 1145 // Print each basic block |
| 1148 for (CfgNode *Node : Nodes) | 1146 for (CfgNode *Node : Nodes) |
| 1149 Node->dump(this); | 1147 Node->dump(this); |
| 1150 if (isVerbose(IceV_Instructions)) | 1148 if (isVerbose(IceV_Instructions)) |
| 1151 Str << "}\n"; | 1149 Str << "}\n"; |
| 1152 } | 1150 } |
| 1153 | 1151 |
| 1154 } // end of namespace Ice | 1152 } // end of namespace Ice |
| OLD | NEW |