| 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 1007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 Str << "\t.type\t" << Name << ",%function\n"; | 1018 Str << "\t.type\t" << Name << ",%function\n"; |
| 1019 } | 1019 } |
| 1020 Str << "\t" << Asm->getAlignDirective() << " " | 1020 Str << "\t" << Asm->getAlignDirective() << " " |
| 1021 << Asm->getBundleAlignLog2Bytes() << ",0x"; | 1021 << Asm->getBundleAlignLog2Bytes() << ",0x"; |
| 1022 for (uint8_t I : Asm->getNonExecBundlePadding()) | 1022 for (uint8_t I : Asm->getNonExecBundlePadding()) |
| 1023 Str.write_hex(I); | 1023 Str.write_hex(I); |
| 1024 Str << "\n"; | 1024 Str << "\n"; |
| 1025 Str << Name << ":\n"; | 1025 Str << Name << ":\n"; |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 void Cfg::deleteJumpTableInsts() { | |
| 1029 for (InstJumpTable *JumpTable : JumpTables) | |
| 1030 JumpTable->setDeleted(); | |
| 1031 } | |
| 1032 | |
| 1033 void Cfg::emitJumpTables() { | 1028 void Cfg::emitJumpTables() { |
| 1034 switch (getFlags().getOutFileType()) { | 1029 switch (getFlags().getOutFileType()) { |
| 1035 case FT_Elf: | 1030 case FT_Elf: |
| 1036 case FT_Iasm: { | 1031 case FT_Iasm: { |
| 1037 // The emission needs to be delayed until the after the text section so | 1032 // The emission needs to be delayed until the after the text section so |
| 1038 // save the offsets in the global context. | 1033 // save the offsets in the global context. |
| 1039 for (const InstJumpTable *JumpTable : JumpTables) { | 1034 for (const InstJumpTable *JumpTable : JumpTables) { |
| 1040 SizeT NumTargets = JumpTable->getNumTargets(); | 1035 Ctx->addJumpTableData(JumpTable->toJumpTableData(getAssembler())); |
| 1041 JumpTableData::TargetList TargetList; | |
| 1042 for (SizeT I = 0; I < NumTargets; ++I) { | |
| 1043 SizeT Index = JumpTable->getTarget(I)->getIndex(); | |
| 1044 TargetList.emplace_back( | |
| 1045 getAssembler()->getCfgNodeLabel(Index)->getPosition()); | |
| 1046 } | |
| 1047 Ctx->addJumpTable(FunctionName, JumpTable->getId(), TargetList); | |
| 1048 } | 1036 } |
| 1049 } break; | 1037 } break; |
| 1050 case FT_Asm: { | 1038 case FT_Asm: { |
| 1051 // Emit the assembly directly so we don't need to hang on to all the names | 1039 // Emit the assembly directly so we don't need to hang on to all the names |
| 1052 for (const InstJumpTable *JumpTable : JumpTables) | 1040 for (const InstJumpTable *JumpTable : JumpTables) |
| 1053 getTarget()->emitJumpTable(this, JumpTable); | 1041 getTarget()->emitJumpTable(this, JumpTable); |
| 1054 } break; | 1042 } break; |
| 1055 } | 1043 } |
| 1056 } | 1044 } |
| 1057 | 1045 |
| 1058 void Cfg::emit() { | 1046 void Cfg::emit() { |
| 1059 if (!BuildDefs::dump()) | 1047 if (!BuildDefs::dump()) |
| 1060 return; | 1048 return; |
| 1061 TimerMarker T(TimerStack::TT_emitAsm, this); | 1049 TimerMarker T(TimerStack::TT_emitAsm, this); |
| 1062 if (getFlags().getDecorateAsm()) { | 1050 if (getFlags().getDecorateAsm()) { |
| 1063 renumberInstructions(); | 1051 renumberInstructions(); |
| 1064 getVMetadata()->init(VMK_Uses); | 1052 getVMetadata()->init(VMK_Uses); |
| 1065 liveness(Liveness_Basic); | 1053 liveness(Liveness_Basic); |
| 1066 dump("After recomputing liveness for -decorate-asm"); | 1054 dump("After recomputing liveness for -decorate-asm"); |
| 1067 } | 1055 } |
| 1068 OstreamLocker L(Ctx); | 1056 OstreamLocker L(Ctx); |
| 1069 Ostream &Str = Ctx->getStrEmit(); | 1057 Ostream &Str = Ctx->getStrEmit(); |
| 1070 const Assembler *Asm = getAssembler<>(); | 1058 const Assembler *Asm = getAssembler<>(); |
| 1071 const bool NeedSandboxing = getFlags().getUseSandboxing(); | 1059 const bool NeedSandboxing = getFlags().getUseSandboxing(); |
| 1072 | 1060 |
| 1073 emitTextHeader(FunctionName, Ctx, Asm); | 1061 emitTextHeader(FunctionName, Ctx, Asm); |
| 1074 deleteJumpTableInsts(); | 1062 if (Ctx->getFlags().getDecorateAsm()) { |
| 1075 if (getFlags().getDecorateAsm()) { | |
| 1076 for (Variable *Var : getVariables()) { | 1063 for (Variable *Var : getVariables()) { |
| 1077 if (Var->getStackOffset() && !Var->isRematerializable()) { | 1064 if (Var->getStackOffset() && !Var->isRematerializable()) { |
| 1078 Str << "\t" << Var->getSymbolicStackOffset(this) << " = " | 1065 Str << "\t" << Var->getSymbolicStackOffset(this) << " = " |
| 1079 << Var->getStackOffset() << "\n"; | 1066 << Var->getStackOffset() << "\n"; |
| 1080 } | 1067 } |
| 1081 } | 1068 } |
| 1082 } | 1069 } |
| 1083 for (CfgNode *Node : Nodes) { | 1070 for (CfgNode *Node : Nodes) { |
| 1084 if (NeedSandboxing && Node->needsAlignment()) { | 1071 if (NeedSandboxing && Node->needsAlignment()) { |
| 1085 Str << "\t" << Asm->getAlignDirective() << " " | 1072 Str << "\t" << Asm->getAlignDirective() << " " |
| 1086 << Asm->getBundleAlignLog2Bytes() << "\n"; | 1073 << Asm->getBundleAlignLog2Bytes() << "\n"; |
| 1087 } | 1074 } |
| 1088 Node->emit(this); | 1075 Node->emit(this); |
| 1089 } | 1076 } |
| 1090 emitJumpTables(); | 1077 emitJumpTables(); |
| 1091 Str << "\n"; | 1078 Str << "\n"; |
| 1092 } | 1079 } |
| 1093 | 1080 |
| 1094 void Cfg::emitIAS() { | 1081 void Cfg::emitIAS() { |
| 1095 TimerMarker T(TimerStack::TT_emitAsm, this); | 1082 TimerMarker T(TimerStack::TT_emitAsm, this); |
| 1096 // The emitIAS() routines emit into the internal assembler buffer, so there's | 1083 // The emitIAS() routines emit into the internal assembler buffer, so there's |
| 1097 // no need to lock the streams. | 1084 // no need to lock the streams. |
| 1098 deleteJumpTableInsts(); | 1085 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
| 1099 const bool NeedSandboxing = getFlags().getUseSandboxing(); | |
| 1100 for (CfgNode *Node : Nodes) { | 1086 for (CfgNode *Node : Nodes) { |
| 1101 if (NeedSandboxing && Node->needsAlignment()) | 1087 if (NeedSandboxing && Node->needsAlignment()) |
| 1102 getAssembler()->alignCfgNode(); | 1088 getAssembler()->alignCfgNode(); |
| 1103 Node->emitIAS(this); | 1089 Node->emitIAS(this); |
| 1104 } | 1090 } |
| 1105 emitJumpTables(); | 1091 emitJumpTables(); |
| 1106 } | 1092 } |
| 1107 | 1093 |
| 1108 size_t Cfg::getTotalMemoryMB() const { | 1094 size_t Cfg::getTotalMemoryMB() const { |
| 1109 constexpr size_t _1MB = 1024 * 1024; | 1095 constexpr size_t _1MB = 1024 * 1024; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1181 } | 1167 } |
| 1182 } | 1168 } |
| 1183 // Print each basic block | 1169 // Print each basic block |
| 1184 for (CfgNode *Node : Nodes) | 1170 for (CfgNode *Node : Nodes) |
| 1185 Node->dump(this); | 1171 Node->dump(this); |
| 1186 if (isVerbose(IceV_Instructions)) | 1172 if (isVerbose(IceV_Instructions)) |
| 1187 Str << "}\n"; | 1173 Str << "}\n"; |
| 1188 } | 1174 } |
| 1189 | 1175 |
| 1190 } // end of namespace Ice | 1176 } // end of namespace Ice |
| OLD | NEW |