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 4542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4553 if (!ALLOW_DUMP) | 4553 if (!ALLOW_DUMP) |
4554 return; | 4554 return; |
4555 Ostream &Str = Ctx->getStrEmit(); | 4555 Ostream &Str = Ctx->getStrEmit(); |
4556 emitPoolLabel(Str); | 4556 emitPoolLabel(Str); |
4557 } | 4557 } |
4558 | 4558 |
4559 void ConstantUndef::emit(GlobalContext *) const { | 4559 void ConstantUndef::emit(GlobalContext *) const { |
4560 llvm_unreachable("undef value encountered by emitter."); | 4560 llvm_unreachable("undef value encountered by emitter."); |
4561 } | 4561 } |
4562 | 4562 |
4563 TargetGlobalX8632::TargetGlobalX8632(GlobalContext *Ctx) | 4563 TargetDataX8632::TargetDataX8632(GlobalContext *Ctx) |
4564 : TargetGlobalLowering(Ctx) {} | 4564 : TargetDataLowering(Ctx) {} |
4565 | 4565 |
4566 void TargetGlobalX8632::lowerInit(const VariableDeclaration &Var) const { | 4566 void TargetDataX8632::lowerGlobal(const VariableDeclaration &Var) const { |
4567 // TODO(jvoung): handle this without text. | |
4568 if (Ctx->getFlags().UseELFWriter) | |
4569 return; | |
4570 | |
4571 Ostream &Str = Ctx->getStrEmit(); | |
4572 | |
4573 const VariableDeclaration::InitializerListType &Initializers = | |
4574 Var.getInitializers(); | |
4575 | |
4576 // If external and not initialized, this must be a cross test. | 4567 // If external and not initialized, this must be a cross test. |
4577 // Don't generate a declaration for such cases. | 4568 // Don't generate a declaration for such cases. |
4578 bool IsExternal = Var.isExternal() || Ctx->getFlags().DisableInternal; | 4569 bool IsExternal = Var.isExternal() || Ctx->getFlags().DisableInternal; |
4579 if (IsExternal && !Var.hasInitializer()) | 4570 if (IsExternal && !Var.hasInitializer()) |
4580 return; | 4571 return; |
4581 | 4572 |
| 4573 Ostream &Str = Ctx->getStrEmit(); |
| 4574 const VariableDeclaration::InitializerListType &Initializers = |
| 4575 Var.getInitializers(); |
4582 bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); | 4576 bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); |
4583 bool IsConstant = Var.getIsConstant(); | 4577 bool IsConstant = Var.getIsConstant(); |
4584 uint32_t Align = Var.getAlignment(); | 4578 uint32_t Align = Var.getAlignment(); |
4585 SizeT Size = Var.getNumBytes(); | 4579 SizeT Size = Var.getNumBytes(); |
4586 IceString MangledName = Var.mangleName(Ctx); | 4580 IceString MangledName = Var.mangleName(Ctx); |
4587 IceString SectionSuffix = ""; | 4581 IceString SectionSuffix = ""; |
4588 if (Ctx->getFlags().DataSections) | 4582 if (Ctx->getFlags().DataSections) |
4589 SectionSuffix = "." + MangledName; | 4583 SectionSuffix = "." + MangledName; |
4590 | 4584 |
4591 Str << "\t.type\t" << MangledName << ",@object\n"; | 4585 Str << "\t.type\t" << MangledName << ",@object\n"; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4638 } else | 4632 } else |
4639 // NOTE: for non-constant zero initializers, this is BSS (no bits), | 4633 // NOTE: for non-constant zero initializers, this is BSS (no bits), |
4640 // so an ELF writer would not write to the file, and only track | 4634 // so an ELF writer would not write to the file, and only track |
4641 // virtual offsets, but the .s writer still needs this .zero and | 4635 // virtual offsets, but the .s writer still needs this .zero and |
4642 // cannot simply use the .size to advance offsets. | 4636 // cannot simply use the .size to advance offsets. |
4643 Str << "\t.zero\t" << Size << "\n"; | 4637 Str << "\t.zero\t" << Size << "\n"; |
4644 | 4638 |
4645 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; | 4639 Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
4646 } | 4640 } |
4647 | 4641 |
| 4642 void |
| 4643 TargetDataX8632::lowerGlobalsELF(const VariableDeclarationList &Vars) const { |
| 4644 ELFObjectWriter *Writer = Ctx->getObjectWriter(); |
| 4645 Writer->writeDataSection(Vars, llvm::ELF::R_386_32); |
| 4646 } |
| 4647 |
4648 template <typename T> struct PoolTypeConverter {}; | 4648 template <typename T> struct PoolTypeConverter {}; |
4649 | 4649 |
4650 template <> struct PoolTypeConverter<float> { | 4650 template <> struct PoolTypeConverter<float> { |
4651 typedef uint32_t PrimitiveIntType; | 4651 typedef uint32_t PrimitiveIntType; |
4652 typedef ConstantFloat IceType; | 4652 typedef ConstantFloat IceType; |
4653 static const Type Ty = IceType_f32; | 4653 static const Type Ty = IceType_f32; |
4654 static const char *TypeName; | 4654 static const char *TypeName; |
4655 static const char *AsmTag; | 4655 static const char *AsmTag; |
4656 static const char *PrintfString; | 4656 static const char *PrintfString; |
4657 }; | 4657 }; |
4658 const char *PoolTypeConverter<float>::TypeName = "float"; | 4658 const char *PoolTypeConverter<float>::TypeName = "float"; |
4659 const char *PoolTypeConverter<float>::AsmTag = ".long"; | 4659 const char *PoolTypeConverter<float>::AsmTag = ".long"; |
4660 const char *PoolTypeConverter<float>::PrintfString = "0x%x"; | 4660 const char *PoolTypeConverter<float>::PrintfString = "0x%x"; |
4661 | 4661 |
4662 template <> struct PoolTypeConverter<double> { | 4662 template <> struct PoolTypeConverter<double> { |
4663 typedef uint64_t PrimitiveIntType; | 4663 typedef uint64_t PrimitiveIntType; |
4664 typedef ConstantDouble IceType; | 4664 typedef ConstantDouble IceType; |
4665 static const Type Ty = IceType_f64; | 4665 static const Type Ty = IceType_f64; |
4666 static const char *TypeName; | 4666 static const char *TypeName; |
4667 static const char *AsmTag; | 4667 static const char *AsmTag; |
4668 static const char *PrintfString; | 4668 static const char *PrintfString; |
4669 }; | 4669 }; |
4670 const char *PoolTypeConverter<double>::TypeName = "double"; | 4670 const char *PoolTypeConverter<double>::TypeName = "double"; |
4671 const char *PoolTypeConverter<double>::AsmTag = ".quad"; | 4671 const char *PoolTypeConverter<double>::AsmTag = ".quad"; |
4672 const char *PoolTypeConverter<double>::PrintfString = "0x%llx"; | 4672 const char *PoolTypeConverter<double>::PrintfString = "0x%llx"; |
4673 | 4673 |
4674 template <typename T> | 4674 template <typename T> |
4675 void TargetGlobalX8632::emitConstantPool(GlobalContext *Ctx) { | 4675 void TargetDataX8632::emitConstantPool(GlobalContext *Ctx) { |
4676 // Note: Still used by emit IAS. | 4676 // Note: Still used by emit IAS. |
4677 Ostream &Str = Ctx->getStrEmit(); | 4677 Ostream &Str = Ctx->getStrEmit(); |
4678 Type Ty = T::Ty; | 4678 Type Ty = T::Ty; |
4679 SizeT Align = typeAlignInBytes(Ty); | 4679 SizeT Align = typeAlignInBytes(Ty); |
4680 ConstantList Pool = Ctx->getConstantPool(Ty); | 4680 ConstantList Pool = Ctx->getConstantPool(Ty); |
4681 | 4681 |
4682 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align | 4682 Str << "\t.section\t.rodata.cst" << Align << ",\"aM\",@progbits," << Align |
4683 << "\n"; | 4683 << "\n"; |
4684 Str << "\t.align\t" << Align << "\n"; | 4684 Str << "\t.align\t" << Align << "\n"; |
4685 for (Constant *C : Pool) { | 4685 for (Constant *C : Pool) { |
4686 typename T::IceType *Const = llvm::cast<typename T::IceType>(C); | 4686 typename T::IceType *Const = llvm::cast<typename T::IceType>(C); |
4687 typename T::IceType::PrimType Value = Const->getValue(); | 4687 typename T::IceType::PrimType Value = Const->getValue(); |
4688 // Use memcpy() to copy bits from Value into RawValue in a way | 4688 // Use memcpy() to copy bits from Value into RawValue in a way |
4689 // that avoids breaking strict-aliasing rules. | 4689 // that avoids breaking strict-aliasing rules. |
4690 typename T::PrimitiveIntType RawValue; | 4690 typename T::PrimitiveIntType RawValue; |
4691 memcpy(&RawValue, &Value, sizeof(Value)); | 4691 memcpy(&RawValue, &Value, sizeof(Value)); |
4692 char buf[30]; | 4692 char buf[30]; |
4693 int CharsPrinted = | 4693 int CharsPrinted = |
4694 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue); | 4694 snprintf(buf, llvm::array_lengthof(buf), T::PrintfString, RawValue); |
4695 assert(CharsPrinted >= 0 && | 4695 assert(CharsPrinted >= 0 && |
4696 (size_t)CharsPrinted < llvm::array_lengthof(buf)); | 4696 (size_t)CharsPrinted < llvm::array_lengthof(buf)); |
4697 (void)CharsPrinted; // avoid warnings if asserts are disabled | 4697 (void)CharsPrinted; // avoid warnings if asserts are disabled |
4698 Const->emitPoolLabel(Str); | 4698 Const->emitPoolLabel(Str); |
4699 Str << ":\n\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " " | 4699 Str << ":\n\t" << T::AsmTag << "\t" << buf << "\t# " << T::TypeName << " " |
4700 << Value << "\n"; | 4700 << Value << "\n"; |
4701 } | 4701 } |
4702 } | 4702 } |
4703 | 4703 |
4704 void TargetGlobalX8632::lowerConstants(GlobalContext *Ctx) const { | 4704 void TargetDataX8632::lowerConstants(GlobalContext *Ctx) const { |
4705 if (Ctx->getFlags().DisableTranslation) | 4705 if (Ctx->getFlags().DisableTranslation) |
4706 return; | 4706 return; |
4707 // No need to emit constants from the int pool since (for x86) they | 4707 // No need to emit constants from the int pool since (for x86) they |
4708 // are embedded as immediates in the instructions, just emit float/double. | 4708 // are embedded as immediates in the instructions, just emit float/double. |
4709 if (Ctx->getFlags().UseELFWriter) { | 4709 if (Ctx->getFlags().UseELFWriter) { |
4710 ELFObjectWriter *Writer = Ctx->getObjectWriter(); | 4710 ELFObjectWriter *Writer = Ctx->getObjectWriter(); |
4711 Writer->writeConstantPool<ConstantFloat>(IceType_f32); | 4711 Writer->writeConstantPool<ConstantFloat>(IceType_f32); |
4712 Writer->writeConstantPool<ConstantDouble>(IceType_f64); | 4712 Writer->writeConstantPool<ConstantDouble>(IceType_f64); |
4713 } else { | 4713 } else { |
4714 OstreamLocker L(Ctx); | 4714 OstreamLocker L(Ctx); |
4715 emitConstantPool<PoolTypeConverter<float>>(Ctx); | 4715 emitConstantPool<PoolTypeConverter<float>>(Ctx); |
4716 emitConstantPool<PoolTypeConverter<double>>(Ctx); | 4716 emitConstantPool<PoolTypeConverter<double>>(Ctx); |
4717 } | 4717 } |
4718 } | 4718 } |
4719 | 4719 |
4720 } // end of namespace Ice | 4720 } // end of namespace Ice |
OLD | NEW |