diff --git a/llvm/include/llvm/MC/MCDXContainerStreamer.h b/llvm/include/llvm/MC/MCDXContainerStreamer.h --- a/llvm/include/llvm/MC/MCDXContainerStreamer.h +++ b/llvm/include/llvm/MC/MCDXContainerStreamer.h @@ -36,7 +36,8 @@ bool emitSymbolAttribute(MCSymbol *, MCSymbolAttr) override { return false; } void emitCommonSymbol(MCSymbol *, uint64_t, unsigned) override {} void emitZerofill(MCSection *, MCSymbol *Symbol = nullptr, uint64_t Size = 0, - unsigned ByteAlignment = 0, SMLoc Loc = SMLoc()) override {} + Align ByteAlignment = Align(1), + SMLoc Loc = SMLoc()) override {} private: void emitInstToData(const MCInst &, const MCSubtargetInfo &) override; diff --git a/llvm/include/llvm/MC/MCELFStreamer.h b/llvm/include/llvm/MC/MCELFStreamer.h --- a/llvm/include/llvm/MC/MCELFStreamer.h +++ b/llvm/include/llvm/MC/MCELFStreamer.h @@ -64,10 +64,10 @@ bool KeepOriginalSym) override; void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) override; + Align ByteAlignment) override; void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc L = SMLoc()) override; void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment = 0) override; diff --git a/llvm/include/llvm/MC/MCSPIRVStreamer.h b/llvm/include/llvm/MC/MCSPIRVStreamer.h --- a/llvm/include/llvm/MC/MCSPIRVStreamer.h +++ b/llvm/include/llvm/MC/MCSPIRVStreamer.h @@ -36,7 +36,7 @@ void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override {} void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) override {} private: diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -679,7 +679,7 @@ /// \param Size - The size of the common symbol. /// \param ByteAlignment - The alignment of the common symbol in bytes. virtual void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment); + Align ByteAlignment); /// Emit the zerofill section and an optional symbol. /// @@ -689,7 +689,7 @@ /// \param ByteAlignment - The alignment of the zerofill symbol if /// non-zero. This must be a power of 2 on some targets. virtual void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) = 0; /// Emit a thread local bss (.tbss) symbol. diff --git a/llvm/include/llvm/MC/MCWasmStreamer.h b/llvm/include/llvm/MC/MCWasmStreamer.h --- a/llvm/include/llvm/MC/MCWasmStreamer.h +++ b/llvm/include/llvm/MC/MCWasmStreamer.h @@ -55,10 +55,10 @@ void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override; void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) override; + Align ByteAlignment) override; void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) override; void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment = 0) override; diff --git a/llvm/include/llvm/MC/MCWinCOFFStreamer.h b/llvm/include/llvm/MC/MCWinCOFFStreamer.h --- a/llvm/include/llvm/MC/MCWinCOFFStreamer.h +++ b/llvm/include/llvm/MC/MCWinCOFFStreamer.h @@ -57,10 +57,10 @@ void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) override; + Align ByteAlignment) override; void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; void emitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment, SMLoc Loc = SMLoc()) override; + Align ByteAlignment, SMLoc Loc = SMLoc()) override; void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; void emitIdent(StringRef IdentString) override; diff --git a/llvm/include/llvm/MC/MCXCOFFStreamer.h b/llvm/include/llvm/MC/MCXCOFFStreamer.h --- a/llvm/include/llvm/MC/MCXCOFFStreamer.h +++ b/llvm/include/llvm/MC/MCXCOFFStreamer.h @@ -23,7 +23,7 @@ void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) override; void emitInstToData(const MCInst &Inst, const MCSubtargetInfo &) override; void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size, diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -769,7 +769,7 @@ Size = 1; // zerofill of 0 bytes is undefined. emitLinkage(GV, GVSym); // .zerofill __DATA, __bss, _foo, 400, 5 - OutStreamer->emitZerofill(TheSection, GVSym, Size, Alignment.value()); + OutStreamer->emitZerofill(TheSection, GVSym, Size, Alignment); return; } @@ -788,7 +788,7 @@ // Prefer to simply fall back to .local / .comm in this case. if (MAI->getLCOMMDirectiveAlignmentType() != LCOMM::NoAlignment) { // .lcomm _foo, 42 - OutStreamer->emitLocalCommonSymbol(GVSym, Size, Alignment.value()); + OutStreamer->emitLocalCommonSymbol(GVSym, Size, Alignment); return; } diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -211,10 +211,10 @@ /// @param Size - The size of the common symbol. /// @param ByteAlignment - The alignment of the common symbol in bytes. void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) override; + Align ByteAlignment) override; void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) override; void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, @@ -975,12 +975,10 @@ Symbol->print(OS, MAI); OS << ',' << Size; - if (ByteAlignment != 0) { - if (MAI->getCOMMDirectiveAlignmentIsInBytes()) - OS << ',' << ByteAlignment; - else - OS << ',' << Log2_32(ByteAlignment); - } + if (MAI->getCOMMDirectiveAlignmentIsInBytes()) + OS << ',' << ByteAlignment; + else + OS << ',' << Log2_32(ByteAlignment); EmitEOL(); // Print symbol's rename (original name contains invalid character(s)) if @@ -992,7 +990,7 @@ } void MCAsmStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlign) { + Align ByteAlign) { OS << "\t.lcomm\t"; Symbol->print(OS, MAI); OS << ',' << Size; @@ -1002,11 +1000,10 @@ case LCOMM::NoAlignment: llvm_unreachable("alignment not supported on .lcomm!"); case LCOMM::ByteAlignment: - OS << ',' << ByteAlign; + OS << ',' << ByteAlign.value(); break; case LCOMM::Log2Alignment: - assert(isPowerOf2_32(ByteAlign) && "alignment must be a power of 2"); - OS << ',' << Log2_32(ByteAlign); + OS << ',' << Log2(ByteAlign); break; } } @@ -1014,7 +1011,7 @@ } void MCAsmStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment, + uint64_t Size, Align ByteAlignment, SMLoc Loc) { if (Symbol) assignFragment(Symbol, &Section->getDummyFragment()); @@ -1033,8 +1030,7 @@ OS << ','; Symbol->print(OS, MAI); OS << ',' << Size; - if (ByteAlignment != 0) - OS << ',' << Log2_32(ByteAlignment); + OS << ',' << Log2(ByteAlignment); } EmitEOL(); } diff --git a/llvm/lib/MC/MCELFStreamer.cpp b/llvm/lib/MC/MCELFStreamer.cpp --- a/llvm/lib/MC/MCELFStreamer.cpp +++ b/llvm/lib/MC/MCELFStreamer.cpp @@ -352,12 +352,12 @@ } void MCELFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size, - unsigned ByteAlignment) { + Align ByteAlignment) { auto *Symbol = cast(S); // FIXME: Should this be caught and done earlier? getAssembler().registerSymbol(*Symbol); Symbol->setBinding(ELF::STB_LOCAL); - emitCommonSymbol(Symbol, Size, ByteAlignment); + emitCommonSymbol(Symbol, Size, ByteAlignment.value()); } void MCELFStreamer::emitValueImpl(const MCExpr *Value, unsigned Size, @@ -727,7 +727,7 @@ } void MCELFStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment, + uint64_t Size, Align ByteAlignment, SMLoc Loc) { llvm_unreachable("ELF doesn't support this directive"); } diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -107,9 +107,9 @@ unsigned ByteAlignment) override; void emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) override; + Align ByteAlignment) override; void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) override; void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment = 0) override; @@ -441,14 +441,14 @@ } void MCMachOStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) { + Align ByteAlignment) { // '.lcomm' is equivalent to '.zerofill'. return emitZerofill(getContext().getObjectFileInfo()->getDataBSSSection(), Symbol, Size, ByteAlignment); } void MCMachOStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment, + uint64_t Size, Align ByteAlignment, SMLoc Loc) { // On darwin all virtual sections have zerofill type. Disallow the usage of // .zerofill in non-virtual functions. If something similar is needed, use @@ -466,7 +466,7 @@ // The symbol may not be present, which only creates the section. if (Symbol) { - emitValueToAlignment(Align(ByteAlignment), 0, 1, 0); + emitValueToAlignment(ByteAlignment, 0, 1, 0); emitLabel(Symbol); emitZeros(Size); } @@ -477,7 +477,7 @@ // .zerofill directive this doesn't actually switch sections on us. void MCMachOStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) { - emitZerofill(Section, Symbol, Size, ByteAlignment); + emitZerofill(Section, Symbol, Size, Align(ByteAlignment)); } void MCMachOStreamer::emitInstToData(const MCInst &Inst, diff --git a/llvm/lib/MC/MCNullStreamer.cpp b/llvm/lib/MC/MCNullStreamer.cpp --- a/llvm/lib/MC/MCNullStreamer.cpp +++ b/llvm/lib/MC/MCNullStreamer.cpp @@ -39,7 +39,7 @@ void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override {} void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) override {} void emitGPRel32Value(const MCExpr *Value) override {} void beginCOFFSymbolDef(const MCSymbol *Symbol) override {} diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -5059,7 +5059,7 @@ // Create the Symbol as a common or local common with Size and Pow2Alignment if (IsLocal) { - getStreamer().emitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment); + getStreamer().emitLocalCommonSymbol(Sym, Size, Align(1 << Pow2Alignment)); return false; } diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp --- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp +++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp @@ -902,7 +902,7 @@ getStreamer().emitZerofill( getContext().getMachOSection(Segment, Section, MachO::S_ZEROFILL, 0, SectionKind::getBSS()), - /*Symbol=*/nullptr, /*Size=*/0, /*ByteAlignment=*/0, SectionLoc); + /*Symbol=*/nullptr, /*Size=*/0, Align(1), SectionLoc); return false; } @@ -958,10 +958,10 @@ // Create the zerofill Symbol with Size and Pow2Alignment // // FIXME: Arch specific. - getStreamer().emitZerofill(getContext().getMachOSection( - Segment, Section, MachO::S_ZEROFILL, - 0, SectionKind::getBSS()), - Sym, Size, 1 << Pow2Alignment, SectionLoc); + getStreamer().emitZerofill( + getContext().getMachOSection(Segment, Section, MachO::S_ZEROFILL, 0, + SectionKind::getBSS()), + Sym, Size, Align(1 << Pow2Alignment), SectionLoc); return false; } diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -6120,7 +6120,7 @@ // Create the Symbol as a common or local common with Size and Pow2Alignment. if (IsLocal) { - getStreamer().emitLocalCommonSymbol(Sym, Size, 1 << Pow2Alignment); + getStreamer().emitLocalCommonSymbol(Sym, Size, Align(1 << Pow2Alignment)); return false; } diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -1202,7 +1202,7 @@ void MCStreamer::emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name, bool KeepOriginalSym) {} void MCStreamer::emitLocalCommonSymbol(MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment) {} + Align ByteAlignment) {} void MCStreamer::emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) {} void MCStreamer::changeSection(MCSection *, const MCExpr *) {} diff --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp --- a/llvm/lib/MC/MCWasmStreamer.cpp +++ b/llvm/lib/MC/MCWasmStreamer.cpp @@ -173,7 +173,7 @@ } void MCWasmStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size, - unsigned ByteAlignment) { + Align ByteAlignment) { llvm_unreachable("Local common symbols are not yet implemented for Wasm"); } @@ -263,7 +263,7 @@ } void MCWasmStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment, + uint64_t Size, Align ByteAlignment, SMLoc Loc) { llvm_unreachable("Wasm doesn't support this directive"); } diff --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp --- a/llvm/lib/MC/MCWinCOFFStreamer.cpp +++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp @@ -292,13 +292,13 @@ } void MCWinCOFFStreamer::emitLocalCommonSymbol(MCSymbol *S, uint64_t Size, - unsigned ByteAlignment) { + Align ByteAlignment) { auto *Symbol = cast(S); MCSection *Section = getContext().getObjectFileInfo()->getBSSSection(); pushSection(); switchSection(Section); - emitValueToAlignment(Align(ByteAlignment), 0, 1, 0); + emitValueToAlignment(ByteAlignment, 0, 1, 0); emitLabel(Symbol); Symbol->setExternal(false); emitZeros(Size); @@ -316,7 +316,7 @@ } void MCWinCOFFStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment, + uint64_t Size, Align ByteAlignment, SMLoc Loc) { llvm_unreachable("not implemented"); } diff --git a/llvm/lib/MC/MCXCOFFStreamer.cpp b/llvm/lib/MC/MCXCOFFStreamer.cpp --- a/llvm/lib/MC/MCXCOFFStreamer.cpp +++ b/llvm/lib/MC/MCXCOFFStreamer.cpp @@ -108,7 +108,7 @@ } void MCXCOFFStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment, + uint64_t Size, Align ByteAlignment, SMLoc Loc) { report_fatal_error("Zero fill not implemented for XCOFF."); } diff --git a/llvm/lib/Object/RecordStreamer.h b/llvm/lib/Object/RecordStreamer.h --- a/llvm/lib/Object/RecordStreamer.h +++ b/llvm/lib/Object/RecordStreamer.h @@ -50,7 +50,7 @@ void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override; void emitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment, SMLoc Loc = SMLoc()) override; + Align ByteAlignment, SMLoc Loc = SMLoc()) override; void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override; diff --git a/llvm/lib/Object/RecordStreamer.cpp b/llvm/lib/Object/RecordStreamer.cpp --- a/llvm/lib/Object/RecordStreamer.cpp +++ b/llvm/lib/Object/RecordStreamer.cpp @@ -106,7 +106,7 @@ } void RecordStreamer::emitZerofill(MCSection *Section, MCSymbol *Symbol, - uint64_t Size, unsigned ByteAlignment, + uint64_t Size, Align ByteAlignment, SMLoc Loc) { markDefined(*Symbol); } diff --git a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp --- a/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp +++ b/llvm/tools/llvm-exegesis/lib/SnippetFile.cpp @@ -96,7 +96,7 @@ void emitValueToAlignment(Align Alignment, int64_t Value, unsigned ValueSize, unsigned MaxBytesToEmit) override {} void emitZerofill(MCSection *Section, MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment, SMLoc Loc) override {} + Align ByteAlignment, SMLoc Loc) override {} unsigned findRegisterByName(const StringRef RegName) const { // FIXME: Can we do better than this ? diff --git a/llvm/tools/llvm-mca/CodeRegionGenerator.cpp b/llvm/tools/llvm-mca/CodeRegionGenerator.cpp --- a/llvm/tools/llvm-mca/CodeRegionGenerator.cpp +++ b/llvm/tools/llvm-mca/CodeRegionGenerator.cpp @@ -50,7 +50,7 @@ void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment) override {} void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, unsigned ByteAlignment = 0, + uint64_t Size = 0, Align ByteAlignment = Align(1), SMLoc Loc = SMLoc()) override {} void emitGPRel32Value(const MCExpr *Value) override {} void beginCOFFSymbolDef(const MCSymbol *Symbol) override {} diff --git a/llvm/unittests/CodeGen/TestAsmPrinter.h b/llvm/unittests/CodeGen/TestAsmPrinter.h --- a/llvm/unittests/CodeGen/TestAsmPrinter.h +++ b/llvm/unittests/CodeGen/TestAsmPrinter.h @@ -34,7 +34,7 @@ void(MCSymbol *Symbol, uint64_t Size, unsigned ByteAlignment)); MOCK_METHOD5(emitZerofill, void(MCSection *Section, MCSymbol *Symbol, uint64_t Size, - unsigned ByteAlignment, SMLoc Loc)); + Align ByteAlignment, SMLoc Loc)); // The following are mock methods to be used in tests.