Chromium Code Reviews| Index: src/IceTargetLowering.cpp |
| diff --git a/src/IceTargetLowering.cpp b/src/IceTargetLowering.cpp |
| index 4bb035a80294140b41964f6b08c7cdc00d39ffbd..daf4aa56197177c500fd5b77f9e13795c421e108 100644 |
| --- a/src/IceTargetLowering.cpp |
| +++ b/src/IceTargetLowering.cpp |
| @@ -15,6 +15,8 @@ |
| // |
| //===----------------------------------------------------------------------===// |
| +#include <sstream> |
|
Jim Stichnoth
2015/06/16 17:03:25
http://llvm.org/docs/CodingStandards.html#use-raw-
John
2015/06/16 17:30:55
no longer relevant here, but Done for IceELFObject
|
| + |
| #include "IceAssemblerARM32.h" |
| #include "IceAssemblerX8632.h" |
| #include "assembler_mips32.h" |
| @@ -446,40 +448,66 @@ TargetDataLowering::createLowering(GlobalContext *Ctx) { |
| TargetDataLowering::~TargetDataLowering() {} |
| -void TargetDataLowering::emitGlobal(const VariableDeclaration &Var) { |
| +namespace { |
| + |
| +IceString dataSectionSuffix(const IceString &SectionSuffix, |
|
Jim Stichnoth
2015/06/16 17:03:24
I realize that -fdata-sections hasn't been impleme
John
2015/06/16 17:30:55
Well, with -fdata-sections we don't need the Secti
|
| + const IceString &MangledVarName, |
| + const bool DataSections) { |
| + if (SectionSuffix.empty() && !DataSections) { |
| + // Early optimizing the simple case. If no suffix is needed then we should |
| + // avoid constructing the ostringstream below. |
| + return ""; |
| + } |
| + |
| + std::ostringstream MangledName; |
| + |
| + if (!SectionSuffix.empty()) { |
| + MangledName << "." << SectionSuffix; |
| + } |
| + |
| + if (DataSections) { |
| + MangledName << "." << MangledVarName; |
| + } |
| + |
| + return MangledName.str(); |
| +} |
| + |
| +} // end of anonymous namespace |
| + |
| +void TargetDataLowering::emitGlobal(const VariableDeclaration &Var, |
| + const IceString &SectionSuffix) { |
| if (!ALLOW_DUMP) |
| return; |
| // If external and not initialized, this must be a cross test. |
| // Don't generate a declaration for such cases. |
| - bool IsExternal = Var.isExternal() || Ctx->getFlags().getDisableInternal(); |
| + const bool IsExternal = |
| + Var.isExternal() || Ctx->getFlags().getDisableInternal(); |
| if (IsExternal && !Var.hasInitializer()) |
| return; |
| Ostream &Str = Ctx->getStrEmit(); |
| - const VariableDeclaration::InitializerListType &Initializers = |
| - Var.getInitializers(); |
| - bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); |
| - bool IsConstant = Var.getIsConstant(); |
| - uint32_t Align = Var.getAlignment(); |
| - SizeT Size = Var.getNumBytes(); |
| - IceString MangledName = Var.mangleName(Ctx); |
| - IceString SectionSuffix = ""; |
| - if (Ctx->getFlags().getDataSections()) |
| - SectionSuffix = "." + MangledName; |
| + const bool HasNonzeroInitializer = Var.hasNonzeroInitializer(); |
| + const bool IsConstant = Var.getIsConstant(); |
| + const SizeT Size = Var.getNumBytes(); |
| + const IceString MangledName = Var.mangleName(Ctx); |
| Str << "\t.type\t" << MangledName << ",%object\n"; |
| + const bool UseDataSections = Ctx->getFlags().getDataSections(); |
| + const IceString Suffix = |
| + dataSectionSuffix(SectionSuffix, MangledName, UseDataSections); |
| if (IsConstant) |
| - Str << "\t.section\t.rodata" << SectionSuffix << ",\"a\",%progbits\n"; |
| + Str << "\t.section\t.rodata" << Suffix << ",\"a\",%progbits\n"; |
| else if (HasNonzeroInitializer) |
| - Str << "\t.section\t.data" << SectionSuffix << ",\"aw\",%progbits\n"; |
| + Str << "\t.section\t.data" << Suffix << ",\"aw\",%progbits\n"; |
| else |
| - Str << "\t.section\t.bss" << SectionSuffix << ",\"aw\",%nobits\n"; |
| + Str << "\t.section\t.bss" << Suffix << ",\"aw\",%nobits\n"; |
| if (IsExternal) |
| Str << "\t.globl\t" << MangledName << "\n"; |
| + const uint32_t Align = Var.getAlignment(); |
| if (Align > 1) { |
| assert(llvm::isPowerOf2_32(Align)); |
| // Use the .p2align directive, since the .align N directive can either |
| @@ -490,11 +518,11 @@ void TargetDataLowering::emitGlobal(const VariableDeclaration &Var) { |
| Str << MangledName << ":\n"; |
| if (HasNonzeroInitializer) { |
| - for (VariableDeclaration::Initializer *Init : Initializers) { |
| + for (VariableDeclaration::Initializer *Init : Var.getInitializers()) { |
| switch (Init->getKind()) { |
| case VariableDeclaration::Initializer::DataInitializerKind: { |
| - const auto Data = llvm::cast<VariableDeclaration::DataInitializer>(Init) |
| - ->getContents(); |
| + const auto &Data = llvm::cast<VariableDeclaration::DataInitializer>( |
| + Init)->getContents(); |
| for (SizeT i = 0; i < Init->getNumBytes(); ++i) { |
| Str << "\t.byte\t" << (((unsigned)Data[i]) & 0xff) << "\n"; |
| } |
| @@ -504,7 +532,7 @@ void TargetDataLowering::emitGlobal(const VariableDeclaration &Var) { |
| Str << "\t.zero\t" << Init->getNumBytes() << "\n"; |
| break; |
| case VariableDeclaration::Initializer::RelocInitializerKind: { |
| - const auto Reloc = |
| + const auto *Reloc = |
| llvm::cast<VariableDeclaration::RelocInitializer>(Init); |
| Str << "\t" << getEmit32Directive() << "\t"; |
| Str << Reloc->getDeclaration()->mangleName(Ctx); |
| @@ -519,12 +547,13 @@ void TargetDataLowering::emitGlobal(const VariableDeclaration &Var) { |
| } |
| } |
| } |
| - } else |
| + } else { |
| // NOTE: for non-constant zero initializers, this is BSS (no bits), |
| // so an ELF writer would not write to the file, and only track |
| // virtual offsets, but the .s writer still needs this .zero and |
| // cannot simply use the .size to advance offsets. |
| Str << "\t.zero\t" << Size << "\n"; |
| + } |
| Str << "\t.size\t" << MangledName << ", " << Size << "\n"; |
| } |