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 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
999 Str << "\t.type\t" << Name << ",%function\n"; | 999 Str << "\t.type\t" << Name << ",%function\n"; |
1000 } | 1000 } |
1001 Str << "\t" << Asm->getAlignDirective() << " " | 1001 Str << "\t" << Asm->getAlignDirective() << " " |
1002 << Asm->getBundleAlignLog2Bytes() << ",0x"; | 1002 << Asm->getBundleAlignLog2Bytes() << ",0x"; |
1003 for (uint8_t I : Asm->getNonExecBundlePadding()) | 1003 for (uint8_t I : Asm->getNonExecBundlePadding()) |
1004 Str.write_hex(I); | 1004 Str.write_hex(I); |
1005 Str << "\n"; | 1005 Str << "\n"; |
1006 Str << Name << ":\n"; | 1006 Str << Name << ":\n"; |
1007 } | 1007 } |
1008 | 1008 |
1009 void Cfg::deleteJumpTableInsts() { | |
1010 for (InstJumpTable *JumpTable : JumpTables) | |
1011 JumpTable->setDeleted(); | |
1012 } | |
1013 | |
1014 void Cfg::emitJumpTables() { | 1009 void Cfg::emitJumpTables() { |
1015 switch (Ctx->getFlags().getOutFileType()) { | 1010 switch (Ctx->getFlags().getOutFileType()) { |
1016 case FT_Elf: | 1011 case FT_Elf: |
1017 case FT_Iasm: { | 1012 case FT_Iasm: { |
1018 // The emission needs to be delayed until the after the text section so | 1013 // The emission needs to be delayed until the after the text section so |
1019 // save the offsets in the global context. | 1014 // save the offsets in the global context. |
1020 for (const InstJumpTable *JumpTable : JumpTables) { | 1015 for (const InstJumpTable *JumpTable : JumpTables) { |
1021 SizeT NumTargets = JumpTable->getNumTargets(); | 1016 Ctx->addJumpTableData(JumpTable->toJumpTableData(getAssembler())); |
1022 JumpTableData::TargetList TargetList; | |
1023 for (SizeT I = 0; I < NumTargets; ++I) { | |
1024 SizeT Index = JumpTable->getTarget(I)->getIndex(); | |
1025 TargetList.emplace_back( | |
1026 getAssembler()->getCfgNodeLabel(Index)->getPosition()); | |
1027 } | |
1028 Ctx->addJumpTable(FunctionName, JumpTable->getId(), TargetList); | |
1029 } | 1017 } |
1030 } break; | 1018 } break; |
1031 case FT_Asm: { | 1019 case FT_Asm: { |
1032 // 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 |
1033 for (const InstJumpTable *JumpTable : JumpTables) | 1021 for (const InstJumpTable *JumpTable : JumpTables) |
1034 getTarget()->emitJumpTable(this, JumpTable); | 1022 getTarget()->emitJumpTable(this, JumpTable); |
1035 } break; | 1023 } break; |
1036 } | 1024 } |
1037 } | 1025 } |
1038 | 1026 |
1039 void Cfg::emit() { | 1027 void Cfg::emit() { |
1040 if (!BuildDefs::dump()) | 1028 if (!BuildDefs::dump()) |
1041 return; | 1029 return; |
1042 TimerMarker T(TimerStack::TT_emitAsm, this); | 1030 TimerMarker T(TimerStack::TT_emitAsm, this); |
1043 if (Ctx->getFlags().getDecorateAsm()) { | 1031 if (Ctx->getFlags().getDecorateAsm()) { |
1044 renumberInstructions(); | 1032 renumberInstructions(); |
1045 getVMetadata()->init(VMK_Uses); | 1033 getVMetadata()->init(VMK_Uses); |
1046 liveness(Liveness_Basic); | 1034 liveness(Liveness_Basic); |
1047 dump("After recomputing liveness for -decorate-asm"); | 1035 dump("After recomputing liveness for -decorate-asm"); |
1048 } | 1036 } |
1049 OstreamLocker L(Ctx); | 1037 OstreamLocker L(Ctx); |
1050 Ostream &Str = Ctx->getStrEmit(); | 1038 Ostream &Str = Ctx->getStrEmit(); |
1051 const Assembler *Asm = getAssembler<>(); | 1039 const Assembler *Asm = getAssembler<>(); |
1052 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); | 1040 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
1053 | 1041 |
1054 emitTextHeader(FunctionName, Ctx, Asm); | 1042 emitTextHeader(FunctionName, Ctx, Asm); |
1055 deleteJumpTableInsts(); | |
1056 if (Ctx->getFlags().getDecorateAsm()) { | 1043 if (Ctx->getFlags().getDecorateAsm()) { |
1057 for (Variable *Var : getVariables()) { | 1044 for (Variable *Var : getVariables()) { |
1058 if (Var->getStackOffset() && !Var->isRematerializable()) { | 1045 if (Var->getStackOffset() && !Var->isRematerializable()) { |
1059 Str << "\t" << Var->getSymbolicStackOffset(this) << " = " | 1046 Str << "\t" << Var->getSymbolicStackOffset(this) << " = " |
1060 << Var->getStackOffset() << "\n"; | 1047 << Var->getStackOffset() << "\n"; |
1061 } | 1048 } |
1062 } | 1049 } |
1063 } | 1050 } |
1064 for (CfgNode *Node : Nodes) { | 1051 for (CfgNode *Node : Nodes) { |
1065 if (NeedSandboxing && Node->needsAlignment()) { | 1052 if (NeedSandboxing && Node->needsAlignment()) { |
1066 Str << "\t" << Asm->getAlignDirective() << " " | 1053 Str << "\t" << Asm->getAlignDirective() << " " |
1067 << Asm->getBundleAlignLog2Bytes() << "\n"; | 1054 << Asm->getBundleAlignLog2Bytes() << "\n"; |
1068 } | 1055 } |
1069 Node->emit(this); | 1056 Node->emit(this); |
1070 } | 1057 } |
1071 emitJumpTables(); | 1058 emitJumpTables(); |
1072 Str << "\n"; | 1059 Str << "\n"; |
1073 } | 1060 } |
1074 | 1061 |
1075 void Cfg::emitIAS() { | 1062 void Cfg::emitIAS() { |
1076 TimerMarker T(TimerStack::TT_emitAsm, this); | 1063 TimerMarker T(TimerStack::TT_emitAsm, this); |
1077 // The emitIAS() routines emit into the internal assembler buffer, so there's | 1064 // The emitIAS() routines emit into the internal assembler buffer, so there's |
1078 // no need to lock the streams. | 1065 // no need to lock the streams. |
1079 deleteJumpTableInsts(); | |
1080 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); | 1066 const bool NeedSandboxing = Ctx->getFlags().getUseSandboxing(); |
1081 for (CfgNode *Node : Nodes) { | 1067 for (CfgNode *Node : Nodes) { |
1082 if (NeedSandboxing && Node->needsAlignment()) | 1068 if (NeedSandboxing && Node->needsAlignment()) |
1083 getAssembler()->alignCfgNode(); | 1069 getAssembler()->alignCfgNode(); |
1084 Node->emitIAS(this); | 1070 Node->emitIAS(this); |
1085 } | 1071 } |
1086 emitJumpTables(); | 1072 emitJumpTables(); |
1087 } | 1073 } |
1088 | 1074 |
1089 size_t Cfg::getTotalMemoryMB() const { | 1075 size_t Cfg::getTotalMemoryMB() const { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 } | 1148 } |
1163 } | 1149 } |
1164 // Print each basic block | 1150 // Print each basic block |
1165 for (CfgNode *Node : Nodes) | 1151 for (CfgNode *Node : Nodes) |
1166 Node->dump(this); | 1152 Node->dump(this); |
1167 if (isVerbose(IceV_Instructions)) | 1153 if (isVerbose(IceV_Instructions)) |
1168 Str << "}\n"; | 1154 Str << "}\n"; |
1169 } | 1155 } |
1170 | 1156 |
1171 } // end of namespace Ice | 1157 } // end of namespace Ice |
OLD | NEW |