From b8040080d80c798672c99e4d39c165ffb4df8ba6 Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 21 May 2020 15:23:00 -0700 Subject: [PATCH] [Target] Use Align in TargetLoweringObjectFile::getSectionForConstant. Differential Revision: https://reviews.llvm.org/D80363 --- .../CodeGen/TargetLoweringObjectFileImpl.h | 8 +++--- .../llvm/Target/TargetLoweringObjectFile.h | 5 ++-- lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 25 +++++++++-------- lib/CodeGen/TargetLoweringObjectFileImpl.cpp | 28 +++++++++---------- lib/Target/Lanai/LanaiTargetObjectFile.cpp | 10 +++---- lib/Target/Lanai/LanaiTargetObjectFile.h | 2 +- lib/Target/Mips/MipsTargetObjectFile.cpp | 5 ++-- lib/Target/Mips/MipsTargetObjectFile.h | 2 +- lib/Target/NVPTX/NVPTXTargetObjectFile.h | 2 +- lib/Target/RISCV/RISCVTargetObjectFile.cpp | 5 ++-- lib/Target/RISCV/RISCVTargetObjectFile.h | 2 +- lib/Target/TargetLoweringObjectFile.cpp | 6 ++-- lib/Target/XCore/XCoreTargetObjectFile.cpp | 7 ++--- lib/Target/XCore/XCoreTargetObjectFile.h | 2 +- 14 files changed, 55 insertions(+), 54 deletions(-) diff --git a/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h b/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h index 3abae7bc721..21a4635ca0c 100644 --- a/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h +++ b/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h @@ -53,7 +53,7 @@ public: /// placed in. MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override; @@ -116,7 +116,7 @@ public: MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; /// The mach-o version of this method defaults to returning a stub reference. const MCExpr *getTTypeGlobalReference(const GlobalValue *GV, @@ -182,7 +182,7 @@ public: /// information, return a section that it should be placed in. MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; }; class TargetLoweringObjectFileWasm : public TargetLoweringObjectFile { @@ -244,7 +244,7 @@ public: /// placed in. MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; static XCOFF::StorageClass getStorageClassForGlobal(const GlobalObject *GO); diff --git a/include/llvm/Target/TargetLoweringObjectFile.h b/include/llvm/Target/TargetLoweringObjectFile.h index f642977e3d8..774b4470ca4 100644 --- a/include/llvm/Target/TargetLoweringObjectFile.h +++ b/include/llvm/Target/TargetLoweringObjectFile.h @@ -87,9 +87,8 @@ public: /// Given a constant with the SectionKind, return a section that it should be /// placed in. virtual MCSection *getSectionForConstant(const DataLayout &DL, - SectionKind Kind, - const Constant *C, - unsigned &Align) const; + SectionKind Kind, const Constant *C, + Align &Alignment) const; virtual MCSection * getSectionForMachineBasicBlock(const Function &F, diff --git a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 22d67d75ce8..db458e2b8a9 100644 --- a/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1639,10 +1639,10 @@ bool AsmPrinter::doFinalization(Module &M) { // Emit __morestack address if needed for indirect calls. if (MMI->usesMorestackAddr()) { - unsigned Align = 1; + Align Alignment(1); MCSection *ReadOnlySection = getObjFileLowering().getSectionForConstant( getDataLayout(), SectionKind::getReadOnly(), - /*C=*/nullptr, Align); + /*C=*/nullptr, Alignment); OutStreamer->SwitchSection(ReadOnlySection); MCSymbol *AddrSymbol = @@ -1809,10 +1809,10 @@ namespace { // Keep track the alignment, constpool entries per Section. struct SectionCPs { MCSection *S; - unsigned Alignment; + Align Alignment; SmallVector CPEs; - SectionCPs(MCSection *s, unsigned a) : S(s), Alignment(a) {} + SectionCPs(MCSection *s, Align a) : S(s), Alignment(a) {} }; } // end anonymous namespace @@ -1831,7 +1831,7 @@ void AsmPrinter::emitConstantPool() { SmallVector CPSections; for (unsigned i = 0, e = CP.size(); i != e; ++i) { const MachineConstantPoolEntry &CPE = CP[i]; - unsigned Align = CPE.getAlign().value(); + Align Alignment = CPE.getAlign(); SectionKind Kind = CPE.getSectionKind(&getDataLayout()); @@ -1839,8 +1839,8 @@ void AsmPrinter::emitConstantPool() { if (!CPE.isMachineConstantPoolEntry()) C = CPE.Val.ConstVal; - MCSection *S = getObjFileLowering().getSectionForConstant(getDataLayout(), - Kind, C, Align); + MCSection *S = getObjFileLowering().getSectionForConstant( + getDataLayout(), Kind, C, Alignment); // The number of sections are small, just do a linear search from the // last section to the first. @@ -1854,11 +1854,11 @@ void AsmPrinter::emitConstantPool() { } if (!Found) { SecIdx = CPSections.size(); - CPSections.push_back(SectionCPs(S, Align)); + CPSections.push_back(SectionCPs(S, Alignment)); } - if (Align > CPSections[SecIdx].Alignment) - CPSections[SecIdx].Alignment = Align; + if (Alignment > CPSections[SecIdx].Alignment) + CPSections[SecIdx].Alignment = Alignment; CPSections[SecIdx].CPEs.push_back(i); } @@ -2903,9 +2903,10 @@ MCSymbol *AsmPrinter::GetCPISymbol(unsigned CPID) const { const DataLayout &DL = MF->getDataLayout(); SectionKind Kind = CPE.getSectionKind(&DL); const Constant *C = CPE.Val.ConstVal; - unsigned Align = CPE.Alignment.value(); + Align Alignment = CPE.Alignment; if (const MCSectionCOFF *S = dyn_cast( - getObjFileLowering().getSectionForConstant(DL, Kind, C, Align))) { + getObjFileLowering().getSectionForConstant(DL, Kind, C, + Alignment))) { if (MCSymbol *Sym = S->getCOMDATSymbol()) { if (Sym->isUndefined()) OutStreamer->emitSymbolAttribute(Sym, MCSA_Global); diff --git a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp index a3bfd650d4b..5a5cde4b8c5 100644 --- a/lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ b/lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -842,7 +842,7 @@ bool TargetLoweringObjectFileELF::shouldPutJumpTableInFunctionSection( /// information, return a section that it should be placed in. MCSection *TargetLoweringObjectFileELF::getSectionForConstant( const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const { + Align &Alignment) const { if (Kind.isMergeableConst4() && MergeableConst4Section) return MergeableConst4Section; if (Kind.isMergeableConst8() && MergeableConst8Section) @@ -1194,7 +1194,7 @@ MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal( MCSection *TargetLoweringObjectFileMachO::getSectionForConstant( const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const { + Align &Alignment) const { // If this constant requires a relocation, we have to put it in the data // segment, not in the text segment. if (Kind.isData() || Kind.isReadOnlyWithRel()) @@ -1777,7 +1777,7 @@ static std::string scalarConstantToHexString(const Constant *C) { MCSection *TargetLoweringObjectFileCOFF::getSectionForConstant( const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const { + Align &Alignment) const { if (Kind.isMergeableConst() && C && getContext().getAsmInfo()->hasCOFFComdatConstants()) { // This creates comdat sections with the given symbol name, but unless @@ -1789,25 +1789,25 @@ MCSection *TargetLoweringObjectFileCOFF::getSectionForConstant( COFF::IMAGE_SCN_LNK_COMDAT; std::string COMDATSymName; if (Kind.isMergeableConst4()) { - if (Align <= 4) { + if (Alignment <= 4) { COMDATSymName = "__real@" + scalarConstantToHexString(C); - Align = 4; + Alignment = Align(4); } } else if (Kind.isMergeableConst8()) { - if (Align <= 8) { + if (Alignment <= 8) { COMDATSymName = "__real@" + scalarConstantToHexString(C); - Align = 8; + Alignment = Align(8); } } else if (Kind.isMergeableConst16()) { // FIXME: These may not be appropriate for non-x86 architectures. - if (Align <= 16) { + if (Alignment <= 16) { COMDATSymName = "__xmm@" + scalarConstantToHexString(C); - Align = 16; + Alignment = Align(16); } } else if (Kind.isMergeableConst32()) { - if (Align <= 32) { + if (Alignment <= 32) { COMDATSymName = "__ymm@" + scalarConstantToHexString(C); - Align = 32; + Alignment = Align(32); } } @@ -1817,10 +1817,10 @@ MCSection *TargetLoweringObjectFileCOFF::getSectionForConstant( COFF::IMAGE_COMDAT_SELECT_ANY); } - return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C, Align); + return TargetLoweringObjectFile::getSectionForConstant(DL, Kind, C, + Alignment); } - //===----------------------------------------------------------------------===// // Wasm //===----------------------------------------------------------------------===// @@ -2096,7 +2096,7 @@ bool TargetLoweringObjectFileXCOFF::shouldPutJumpTableInFunctionSection( /// information, return a section that it should be placed in. MCSection *TargetLoweringObjectFileXCOFF::getSectionForConstant( const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const { + Align &Alignment) const { //TODO: Enable emiting constant pool to unique sections when we support it. return ReadOnlySection; } diff --git a/lib/Target/Lanai/LanaiTargetObjectFile.cpp b/lib/Target/Lanai/LanaiTargetObjectFile.cpp index d47306c55ba..a421f315615 100644 --- a/lib/Target/Lanai/LanaiTargetObjectFile.cpp +++ b/lib/Target/Lanai/LanaiTargetObjectFile.cpp @@ -116,13 +116,13 @@ bool LanaiTargetObjectFile::isConstantInSmallSection(const DataLayout &DL, return isInSmallSection(DL.getTypeAllocSize(CN->getType())); } -MCSection *LanaiTargetObjectFile::getSectionForConstant(const DataLayout &DL, - SectionKind Kind, - const Constant *C, - unsigned &Align) const { +MCSection *LanaiTargetObjectFile::getSectionForConstant( + const DataLayout &DL, SectionKind Kind, const Constant *C, + Align &Alignment) const { if (isConstantInSmallSection(DL, C)) return SmallDataSection; // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, Align); + return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, + Alignment); } diff --git a/lib/Target/Lanai/LanaiTargetObjectFile.h b/lib/Target/Lanai/LanaiTargetObjectFile.h index 25c0eadb978..404349465db 100644 --- a/lib/Target/Lanai/LanaiTargetObjectFile.h +++ b/lib/Target/Lanai/LanaiTargetObjectFile.h @@ -37,7 +37,7 @@ public: MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; }; } // end namespace llvm diff --git a/lib/Target/Mips/MipsTargetObjectFile.cpp b/lib/Target/Mips/MipsTargetObjectFile.cpp index ffd7a057bf0..481157a8aa8 100644 --- a/lib/Target/Mips/MipsTargetObjectFile.cpp +++ b/lib/Target/Mips/MipsTargetObjectFile.cpp @@ -176,12 +176,13 @@ bool MipsTargetObjectFile::IsConstantInSmallSection( MCSection *MipsTargetObjectFile::getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const { + Align &Alignment) const { if (IsConstantInSmallSection(DL, C, *TM)) return SmallDataSection; // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, Align); + return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, + Alignment); } const MCExpr * diff --git a/lib/Target/Mips/MipsTargetObjectFile.h b/lib/Target/Mips/MipsTargetObjectFile.h index bdf485f8326..07e9caf0dd0 100644 --- a/lib/Target/Mips/MipsTargetObjectFile.h +++ b/lib/Target/Mips/MipsTargetObjectFile.h @@ -40,7 +40,7 @@ class MipsTargetMachine; MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; /// Describe a TLS variable address within debug info. const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override; }; diff --git a/lib/Target/NVPTX/NVPTXTargetObjectFile.h b/lib/Target/NVPTX/NVPTXTargetObjectFile.h index ab2a93b7592..366d92a5a80 100644 --- a/lib/Target/NVPTX/NVPTXTargetObjectFile.h +++ b/lib/Target/NVPTX/NVPTXTargetObjectFile.h @@ -27,7 +27,7 @@ public: MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override { + Align &Alignment) const override { return ReadOnlySection; } diff --git a/lib/Target/RISCV/RISCVTargetObjectFile.cpp b/lib/Target/RISCV/RISCVTargetObjectFile.cpp index 0d1480170fd..fba86b46376 100644 --- a/lib/Target/RISCV/RISCVTargetObjectFile.cpp +++ b/lib/Target/RISCV/RISCVTargetObjectFile.cpp @@ -104,10 +104,11 @@ bool RISCVELFTargetObjectFile::isConstantInSmallSection( MCSection *RISCVELFTargetObjectFile::getSectionForConstant( const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const { + Align &Alignment) const { if (isConstantInSmallSection(DL, C)) return SmallDataSection; // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, Align); + return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, + Alignment); } diff --git a/lib/Target/RISCV/RISCVTargetObjectFile.h b/lib/Target/RISCV/RISCVTargetObjectFile.h index a5d343e569a..830a7d813c1 100644 --- a/lib/Target/RISCV/RISCVTargetObjectFile.h +++ b/lib/Target/RISCV/RISCVTargetObjectFile.h @@ -35,7 +35,7 @@ public: MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; void getModuleMetadata(Module &M) override; diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp index d48efef874a..bd256600c5f 100644 --- a/lib/Target/TargetLoweringObjectFile.cpp +++ b/lib/Target/TargetLoweringObjectFile.cpp @@ -284,10 +284,10 @@ TargetLoweringObjectFile::SectionForGlobal(const GlobalObject *GO, MCSection *TargetLoweringObjectFile::getSectionForJumpTable( const Function &F, const TargetMachine &TM) const { - unsigned Align = 0; + Align Alignment(1); return getSectionForConstant(F.getParent()->getDataLayout(), SectionKind::getReadOnly(), /*C=*/nullptr, - Align); + Alignment); } bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection( @@ -309,7 +309,7 @@ bool TargetLoweringObjectFile::shouldPutJumpTableInFunctionSection( /// information, return a section that it should be placed in. MCSection *TargetLoweringObjectFile::getSectionForConstant( const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const { + Align &Alignment) const { if (Kind.isReadOnly() && ReadOnlySection != nullptr) return ReadOnlySection; diff --git a/lib/Target/XCore/XCoreTargetObjectFile.cpp b/lib/Target/XCore/XCoreTargetObjectFile.cpp index fe743b28b4b..9fec74a372f 100644 --- a/lib/Target/XCore/XCoreTargetObjectFile.cpp +++ b/lib/Target/XCore/XCoreTargetObjectFile.cpp @@ -140,10 +140,9 @@ MCSection *XCoreTargetObjectFile::SelectSectionForGlobal( report_fatal_error("Target does not support TLS or Common sections"); } -MCSection *XCoreTargetObjectFile::getSectionForConstant(const DataLayout &DL, - SectionKind Kind, - const Constant *C, - unsigned &Align) const { +MCSection *XCoreTargetObjectFile::getSectionForConstant( + const DataLayout &DL, SectionKind Kind, const Constant *C, + Align &Alignment) const { if (Kind.isMergeableConst4()) return MergeableConst4Section; if (Kind.isMergeableConst8()) return MergeableConst8Section; if (Kind.isMergeableConst16()) return MergeableConst16Section; diff --git a/lib/Target/XCore/XCoreTargetObjectFile.h b/lib/Target/XCore/XCoreTargetObjectFile.h index fd172c55919..73cc6686d77 100644 --- a/lib/Target/XCore/XCoreTargetObjectFile.h +++ b/lib/Target/XCore/XCoreTargetObjectFile.h @@ -32,7 +32,7 @@ static const unsigned CodeModelLargeSize = 256; MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind, const Constant *C, - unsigned &Align) const override; + Align &Alignment) const override; }; } // end namespace llvm