]> granicus.if.org Git - llvm/commitdiff
[Alignment] Introduce llvm::Align to MCSection
authorGuillaume Chatelet <gchatelet@google.com>
Fri, 13 Sep 2019 09:29:59 +0000 (09:29 +0000)
committerGuillaume Chatelet <gchatelet@google.com>
Fri, 13 Sep 2019 09:29:59 +0000 (09:29 +0000)
Summary:
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790

Reviewers: courbet, JDevlieghere

Subscribers: arsenm, sdardis, jvesely, nhaehnle, sbc100, hiraditya, aheejin, jrtc27, atanasyan, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D67486

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@371831 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCSection.h
lib/MC/ELFObjectWriter.cpp
lib/MC/MCELFStreamer.cpp
lib/MC/MCObjectStreamer.cpp
lib/MC/MCWinCOFFStreamer.cpp
lib/Target/AMDGPU/AMDGPUAsmPrinter.cpp
lib/Target/Hexagon/MCTargetDesc/HexagonMCELFStreamer.cpp
lib/Target/Mips/MCTargetDesc/MipsOptionRecord.cpp
lib/Target/Mips/MCTargetDesc/MipsTargetStreamer.cpp
tools/dsymutil/DwarfStreamer.cpp

index 6fad1ec2069c96b0c7f5aeb4e98d58c8b71b70b4..e97274a960295aff91531ce1d8b4084667ae3e1e 100644 (file)
@@ -17,6 +17,7 @@
 #include "llvm/ADT/ilist.h"
 #include "llvm/MC/MCFragment.h"
 #include "llvm/MC/SectionKind.h"
+#include "llvm/Support/Alignment.h"
 #include <cassert>
 #include <utility>
 
@@ -58,7 +59,7 @@ private:
   MCSymbol *Begin;
   MCSymbol *End = nullptr;
   /// The alignment requirement of this section.
-  unsigned Alignment = 1;
+  llvm::Align Alignment;
   /// The section index in the assemblers section list.
   unsigned Ordinal = 0;
   /// The index of this section in the layout order.
@@ -117,8 +118,8 @@ public:
   MCSymbol *getEndSymbol(MCContext &Ctx);
   bool hasEnded() const;
 
-  unsigned getAlignment() const { return Alignment; }
-  void setAlignment(unsigned Value) { Alignment = Value; }
+  unsigned getAlignment() const { return Alignment.value(); }
+  void setAlignment(llvm::Align Value) { Alignment = Value; }
 
   unsigned getOrdinal() const { return Ordinal; }
   void setOrdinal(unsigned Value) { Ordinal = Value; }
index b70f1dc46f72fa3f9840696192e991ca2d75b98c..b237d5620bfced27a220605d81cb177638cc2ed8 100644 (file)
@@ -638,7 +638,7 @@ void ELFWriter::computeSymbolTable(
   unsigned EntrySize = is64Bit() ? ELF::SYMENTRY_SIZE64 : ELF::SYMENTRY_SIZE32;
   MCSectionELF *SymtabSection =
       Ctx.getELFSection(".symtab", ELF::SHT_SYMTAB, 0, EntrySize, "");
-  SymtabSection->setAlignment(is64Bit() ? 8 : 4);
+  SymtabSection->setAlignment(is64Bit() ? llvm::Align(8) : llvm::Align(4));
   SymbolTableIndex = addToSectionTable(SymtabSection);
 
   align(SymtabSection->getAlignment());
@@ -736,7 +736,7 @@ void ELFWriter::computeSymbolTable(
     MCSectionELF *SymtabShndxSection =
         Ctx.getELFSection(".symtab_shndx", ELF::SHT_SYMTAB_SHNDX, 0, 4, "");
     SymtabShndxSectionIndex = addToSectionTable(SymtabShndxSection);
-    SymtabShndxSection->setAlignment(4);
+    SymtabShndxSection->setAlignment(llvm::Align(4));
   }
 
   ArrayRef<std::string> FileNames = Asm.getFileNames();
@@ -824,7 +824,7 @@ MCSectionELF *ELFWriter::createRelocationSection(MCContext &Ctx,
   MCSectionELF *RelaSection = Ctx.createELFRelSection(
       RelaSectionName, hasRelocationAddend() ? ELF::SHT_RELA : ELF::SHT_REL,
       Flags, EntrySize, Sec.getGroup(), &Sec);
-  RelaSection->setAlignment(is64Bit() ? 8 : 4);
+  RelaSection->setAlignment(is64Bit() ? llvm::Align(8) : llvm::Align(4));
   return RelaSection;
 }
 
@@ -911,7 +911,7 @@ void ELFWriter::writeSectionData(const MCAssembler &Asm, MCSection &Sec,
     Section.setFlags(Section.getFlags() | ELF::SHF_COMPRESSED);
     // Alignment field should reflect the requirements of
     // the compressed section header.
-    Section.setAlignment(is64Bit() ? 8 : 4);
+    Section.setAlignment(is64Bit() ? llvm::Align(8) : llvm::Align(4));
   } else {
     // Add "z" prefix to section name. This is zlib-gnu style.
     MC.renameELFSection(&Section, (".z" + SectionName.drop_front(1)).str());
@@ -1135,7 +1135,7 @@ uint64_t ELFWriter::writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) {
       if (!GroupIdx) {
         MCSectionELF *Group = Ctx.createELFGroupSection(SignatureSymbol);
         GroupIdx = addToSectionTable(Group);
-        Group->setAlignment(4);
+        Group->setAlignment(llvm::Align(4));
         Groups.push_back(Group);
       }
       std::vector<const MCSectionELF *> &Members =
index 245dd063004f86c155d8b4ad86766eef1bd51bfd..816e742b2631acecb3908858ed5612d0411bea79 100644 (file)
@@ -139,7 +139,7 @@ static void setSectionAlignmentForBundling(const MCAssembler &Assembler,
                                            MCSection *Section) {
   if (Section && Assembler.isBundlingEnabled() && Section->hasInstructions() &&
       Section->getAlignment() < Assembler.getBundleAlignSize())
-    Section->setAlignment(Assembler.getBundleAlignSize());
+    Section->setAlignment(llvm::Align(Assembler.getBundleAlignSize()));
 }
 
 void MCELFStreamer::ChangeSection(MCSection *Section,
@@ -306,7 +306,7 @@ void MCELFStreamer::EmitCommonSymbol(MCSymbol *S, uint64_t Size,
 
     // Update the maximum alignment of the section if necessary.
     if (ByteAlignment > Section.getAlignment())
-      Section.setAlignment(ByteAlignment);
+      Section.setAlignment(llvm::Align(ByteAlignment));
 
     SwitchSection(P.first, P.second);
   } else {
index b418c2d33d9512273d12aac49183f8b6bfa2653f..1e7b5d711f2389b34079127b4e04af3103ff8688 100644 (file)
@@ -539,7 +539,7 @@ void MCObjectStreamer::EmitValueToAlignment(unsigned ByteAlignment,
   // Update the maximum alignment on the current section if necessary.
   MCSection *CurSec = getCurrentSectionOnly();
   if (ByteAlignment > CurSec->getAlignment())
-    CurSec->setAlignment(ByteAlignment);
+    CurSec->setAlignment(llvm::Align(ByteAlignment));
 }
 
 void MCObjectStreamer::EmitCodeAlignment(unsigned ByteAlignment,
index 40470452686600f73ef9fc452837d3f351d07e2a..fc79cab522cdf493038467b643962a3376224e41 100644 (file)
@@ -192,7 +192,7 @@ void MCWinCOFFStreamer::EmitCOFFSafeSEH(MCSymbol const *Symbol) {
   MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
   getAssembler().registerSection(*SXData);
   if (SXData->getAlignment() < 4)
-    SXData->setAlignment(4);
+    SXData->setAlignment(llvm::Align(4));
 
   new MCSymbolIdFragment(Symbol, SXData);
 
@@ -209,7 +209,7 @@ void MCWinCOFFStreamer::EmitCOFFSymbolIndex(MCSymbol const *Symbol) {
   MCSection *Sec = getCurrentSectionOnly();
   getAssembler().registerSection(*Sec);
   if (Sec->getAlignment() < 4)
-    Sec->setAlignment(4);
+    Sec->setAlignment(llvm::Align(4));
 
   new MCSymbolIdFragment(Symbol, getCurrentSectionOnly());
 
index 1e3c7edc63f9bbc2dbe9051fe63aa6fd1c04ca56..4b1d9cb5059f21237c54d1fe1ece82b1ace3228e 100644 (file)
@@ -229,7 +229,7 @@ void AMDGPUAsmPrinter::EmitFunctionBodyEnd() {
   // alignment.
   Streamer.EmitValueToAlignment(64, 0, 1, 0);
   if (ReadOnlySection.getAlignment() < 64)
-    ReadOnlySection.setAlignment(64);
+    ReadOnlySection.setAlignment(llvm::Align(64));
 
   const MCSubtargetInfo &STI = MF->getSubtarget();
 
index f2432883af6fff5ec69f3d850e9156299d8bf095..215af5b97a9f5a4bb01bf2166cf1bc1a64cbe4aa 100644 (file)
@@ -116,8 +116,8 @@ void HexagonMCELFStreamer::HexagonMCEmitCommonSymbol(MCSymbol *Symbol,
     }
 
     // Update the maximum alignment of the section if necessary.
-    if (ByteAlignment > Section.getAlignment())
-      Section.setAlignment(ByteAlignment);
+    if (llvm::Align(ByteAlignment) > Section.getAlignment())
+      Section.setAlignment(llvm::Align(ByteAlignment));
 
     SwitchSection(P.first, P.second);
   } else {
index b4ebb9d18b725c9aa4905d1a118dd03e41408b64..874341e4124740e6aeb8785e5329cc9bd9b74eec 100644 (file)
@@ -37,7 +37,7 @@ void MipsRegInfoRecord::EmitMipsOptionRecord() {
         Context.getELFSection(".MIPS.options", ELF::SHT_MIPS_OPTIONS,
                               ELF::SHF_ALLOC | ELF::SHF_MIPS_NOSTRIP, 1, "");
     MCA.registerSection(*Sec);
-    Sec->setAlignment(8);
+    Sec->setAlignment(llvm::Align(8));
     Streamer->SwitchSection(Sec);
 
     Streamer->EmitIntValue(ELF::ODK_REGINFO, 1);  // kind
@@ -55,7 +55,7 @@ void MipsRegInfoRecord::EmitMipsOptionRecord() {
     MCSectionELF *Sec = Context.getELFSection(".reginfo", ELF::SHT_MIPS_REGINFO,
                                               ELF::SHF_ALLOC, 24, "");
     MCA.registerSection(*Sec);
-    Sec->setAlignment(MTS->getABI().IsN32() ? 8 : 4);
+    Sec->setAlignment(MTS->getABI().IsN32() ? llvm::Align(8) : llvm::Align(4));
     Streamer->SwitchSection(Sec);
 
     Streamer->EmitIntValue(ri_gprmask, 4);
index 0d14bf21cf54d32eb59a505bf30e7b6e566e3849..d3cc29b8d6af9c91f97b8d7f79c6cff9fd19ad86 100644 (file)
@@ -901,9 +901,12 @@ void MipsTargetELFStreamer::finish() {
   MCSection &BSSSection = *OFI.getBSSSection();
   MCA.registerSection(BSSSection);
 
-  TextSection.setAlignment(std::max(16u, TextSection.getAlignment()));
-  DataSection.setAlignment(std::max(16u, DataSection.getAlignment()));
-  BSSSection.setAlignment(std::max(16u, BSSSection.getAlignment()));
+  TextSection.setAlignment(
+      llvm::Align(std::max(16u, TextSection.getAlignment())));
+  DataSection.setAlignment(
+      llvm::Align(std::max(16u, DataSection.getAlignment())));
+  BSSSection.setAlignment(
+      llvm::Align(std::max(16u, BSSSection.getAlignment())));
 
   if (RoundSectionSizes) {
     // Make sections sizes a multiple of the alignment. This is useful for
@@ -1026,7 +1029,7 @@ void MipsTargetELFStreamer::emitDirectiveEnd(StringRef Name) {
       MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, Context);
 
   MCA.registerSection(*Sec);
-  Sec->setAlignment(4);
+  Sec->setAlignment(llvm::Align(4));
 
   OS.PushSection();
 
@@ -1316,7 +1319,7 @@ void MipsTargetELFStreamer::emitMipsAbiFlags() {
   MCSectionELF *Sec = Context.getELFSection(
       ".MIPS.abiflags", ELF::SHT_MIPS_ABIFLAGS, ELF::SHF_ALLOC, 24, "");
   MCA.registerSection(*Sec);
-  Sec->setAlignment(8);
+  Sec->setAlignment(llvm::Align(8));
   OS.SwitchSection(Sec);
 
   OS << ABIFlagsSection;
index 7a4628b38a413a3c302879a210b74e46aabc8797..5d0f7c1067cd8d7f8574451f423308ecba71f34a 100644 (file)
@@ -260,7 +260,7 @@ void DwarfStreamer::emitAppleTypes(
 /// Emit the swift_ast section stored in \p Buffers.
 void DwarfStreamer::emitSwiftAST(StringRef Buffer) {
   MCSection *SwiftASTSection = MOFI->getDwarfSwiftASTSection();
-  SwiftASTSection->setAlignment(1 << 5);
+  SwiftASTSection->setAlignment(llvm::Align(32));
   MS->SwitchSection(SwiftASTSection);
   MS->EmitBytes(Buffer);
 }