| OLD | NEW |
| 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// | 1 //===- subzero/src/IceTargetLoweringX8632.cpp - x86-32 lowering -----------===// |
| 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 TargetLoweringX8632 class, which | 10 // This file implements the TargetLoweringX8632 class, which |
| (...skipping 4999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5010 C->emitPoolLabel(Str); | 5010 C->emitPoolLabel(Str); |
| 5011 } | 5011 } |
| 5012 | 5012 |
| 5013 void TargetX8632::emit(const ConstantUndef *) const { | 5013 void TargetX8632::emit(const ConstantUndef *) const { |
| 5014 llvm::report_fatal_error("undef value encountered by emitter."); | 5014 llvm::report_fatal_error("undef value encountered by emitter."); |
| 5015 } | 5015 } |
| 5016 | 5016 |
| 5017 TargetDataX8632::TargetDataX8632(GlobalContext *Ctx) | 5017 TargetDataX8632::TargetDataX8632(GlobalContext *Ctx) |
| 5018 : TargetDataLowering(Ctx) {} | 5018 : TargetDataLowering(Ctx) {} |
| 5019 | 5019 |
| 5020 void TargetDataX8632::lowerGlobal(const VariableDeclaration &Var) { | |
| 5021 // If external and not initialized, this must be a cross test. | |
| 5022 // Don't generate a declaration for such cases. | |
| 5023 bool IsExternal = Var.isExternal() || Ctx->getFlags().getDisableInternal(); | |
| 5024 if (IsExternal && !Var.hasInitializer()) | |
| 5025 return; | |
| 5026 | |
| 5027 Ostream &Str = Ctx->getStrEmit(); | |
| 5028 const VariableDeclaration::InitializerListType &Initializers = | |
| 5029 Var.getInitializers(); | |
| 5030 bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); | |
| 5031 bool IsConstant = Var.getIsConstant(); | |
| 5032 uint32_t Align = Var.getAlignment(); | |
| 5033 SizeT Size = Var.getNumBytes(); | |
| 5034 IceString MangledName = Var.mangleName(Ctx); | |
| 5035 IceString SectionSuffix = ""; | |
| 5036 if (Ctx->getFlags().getDataSections()) | |
| 5037 SectionSuffix = "." + MangledName; | |
| 5038 | |
| 5039 Str << "\t.type\t" << MangledName << ",@object\n"; | |
| 5040 | |
| 5041 if (IsConstant) | |
| 5042 Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",@progbits\n"; | |
| 5043 else if (HasNonzeroInitializer) | |
| 5044 Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",@progbits\n"; | |
| 5045 else | |
| 5046 Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",@nobits\n"; | |
| 5047 | |
| 5048 if (IsExternal) | |
| 5049 Str << "\t.globl\t" << MangledName << "\n"; | |
| 5050 | |
| 5051 if (Align > 1) | |
| 5052 Str << "\t.align\t" << Align << "\n"; | |
| 5053 | |
| 5054 Str << MangledName << ":\n"; | |
| 5055 | |
| 5056 if (HasNonzeroInitializer) { | |
| 5057 for (VariableDeclaration::Initializer *Init : Initializers) { | |
| 5058 switch (Init->getKind()) { | |
| 5059 case VariableDeclaration::Initializer::DataInitializerKind: { | |
| 5060 const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init) | |
| 5061 ->getContents(); | |
| 5062 for (SizeT i = 0; i < Init->getNumBytes(); ++i) { | |
| 5063 Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; | |
| 5064 } | |
| 5065 break; | |
| 5066 } | |
| 5067 case VariableDeclaration::Initializer::ZeroInitializerKind: | |
| 5068 Str << "\t.zero\t" << Init->getNumBytes() << "\n"; | |
| 5069 break; | |
| 5070 case VariableDeclaration::Initializer::RelocInitializerKind: { | |
| 5071 const auto Reloc = | |
| 5072 llvm::cast<VariableDeclaration::RelocInitializer>(Init); | |
| 5073 Str << "\t.long\t"; | |
| 5074 Str << Reloc->getDeclaration()->mangleName(Ctx); | |
| 5075 if (RelocOffsetT Offset = Reloc->getOffset()) { | |
| 5076 if (Offset >= 0 || (Offset == INT32_MIN)) | |
| 5077 Str << " + " << Offset; | |
| 5078 else | |
| 5079 Str << " - " << -Offset; | |
| 5080 } | |
| 5081 Str << "\n"; | |
| 5082 break; | |
| 5083 } | |
| 5084 } | |
| 5085 } | |
| 5086 } else | |
| 5087 // NOTE: for non-constant zero initializers, this is BSS (no bits), | |
| 5088 // so an ELF writer would not write to the file, and only track | |
| 5089 // virtual offsets, but the .s writer still needs this .zero and | |
| 5090 // cannot simply use the .size to advance offsets. | |
| 5091 Str << "\t.zero\t" << Size << "\n"; | |
| 5092 | |
| 5093 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | |
| 5094 } | |
| 5095 | |
| 5096 void TargetDataX8632::lowerGlobals( | 5020 void TargetDataX8632::lowerGlobals( |
| 5097 std::unique_ptr<VariableDeclarationList> Vars) { | 5021 std::unique_ptr<VariableDeclarationList> Vars) { |
| 5098 switch (Ctx->getFlags().getOutFileType()) { | 5022 switch (Ctx->getFlags().getOutFileType()) { |
| 5099 case FT_Elf: { | 5023 case FT_Elf: { |
| 5100 ELFObjectWriter *Writer = Ctx->getObjectWriter(); | 5024 ELFObjectWriter *Writer = Ctx->getObjectWriter(); |
| 5101 Writer->writeDataSection(*Vars, llvm::ELF::R_386_32); | 5025 Writer->writeDataSection(*Vars, llvm::ELF::R_386_32); |
| 5102 } break; | 5026 } break; |
| 5103 case FT_Asm: | 5027 case FT_Asm: |
| 5104 case FT_Iasm: { | 5028 case FT_Iasm: { |
| 5105 const IceString &TranslateOnly = Ctx->getFlags().getTranslateOnly(); | 5029 const IceString &TranslateOnly = Ctx->getFlags().getTranslateOnly(); |
| 5106 OstreamLocker L(Ctx); | 5030 OstreamLocker L(Ctx); |
| 5107 for (const VariableDeclaration *Var : *Vars) { | 5031 for (const VariableDeclaration *Var : *Vars) { |
| 5108 if (GlobalContext::matchSymbolName(Var->getName(), TranslateOnly)) { | 5032 if (GlobalContext::matchSymbolName(Var->getName(), TranslateOnly)) { |
| 5109 lowerGlobal(*Var); | 5033 emitGlobal(*Var); |
| 5110 } | 5034 } |
| 5111 } | 5035 } |
| 5112 } break; | 5036 } break; |
| 5113 } | 5037 } |
| 5114 } | 5038 } |
| 5115 | 5039 |
| 5116 template <typename T> struct PoolTypeConverter {}; | 5040 template <typename T> struct PoolTypeConverter {}; |
| 5117 | 5041 |
| 5118 template <> struct PoolTypeConverter<float> { | 5042 template <> struct PoolTypeConverter<float> { |
| 5119 typedef uint32_t PrimitiveIntType; | 5043 typedef uint32_t PrimitiveIntType; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5187 emitConstantPool<PoolTypeConverter<float>>(Ctx); | 5111 emitConstantPool<PoolTypeConverter<float>>(Ctx); |
| 5188 emitConstantPool<PoolTypeConverter<double>>(Ctx); | 5112 emitConstantPool<PoolTypeConverter<double>>(Ctx); |
| 5189 } break; | 5113 } break; |
| 5190 } | 5114 } |
| 5191 } | 5115 } |
| 5192 | 5116 |
| 5193 TargetHeaderX8632::TargetHeaderX8632(GlobalContext *Ctx) | 5117 TargetHeaderX8632::TargetHeaderX8632(GlobalContext *Ctx) |
| 5194 : TargetHeaderLowering(Ctx) {} | 5118 : TargetHeaderLowering(Ctx) {} |
| 5195 | 5119 |
| 5196 } // end of namespace Ice | 5120 } // end of namespace Ice |
| OLD | NEW |