llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-backend-systemz @llvm/pr-subscribers-llvm-mc Author: Kai Nacke (redstar) <details> <summary>Changes</summary> Also rename MCBaseAsmStreamer to MCAsmStreamer. --- Patch is 192.40 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/183763.diff 6 Files Affected: - (renamed) llvm/include/llvm/MC/MCAsmStreamer.h (+8-8) - (modified) llvm/lib/MC/CMakeLists.txt (+1-1) - (removed) llvm/lib/MC/MCAsmBaseStreamer.cpp (-143) - (modified) llvm/lib/MC/MCAsmStreamer.cpp (+100-2560) - (added) llvm/lib/MC/MCGNUAsmStreamer.cpp (+2605) - (modified) llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h (+3-3) ``````````diff diff --git a/llvm/include/llvm/MC/MCAsmBaseStreamer.h b/llvm/include/llvm/MC/MCAsmStreamer.h similarity index 77% rename from llvm/include/llvm/MC/MCAsmBaseStreamer.h rename to llvm/include/llvm/MC/MCAsmStreamer.h index f034c9501bb6b..1acad32ac2fc3 100644 --- a/llvm/include/llvm/MC/MCAsmBaseStreamer.h +++ b/llvm/include/llvm/MC/MCAsmStreamer.h @@ -1,4 +1,4 @@ -//===- MCAsmBaseStreamer.h - Base Class for Asm Streamers -------*- C++ -*-===// +//===- MCAsmStreamer.h - Base Class for Asm Streamers -----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,13 +6,13 @@ // //===----------------------------------------------------------------------===// // -// This file declares the MCAsmBaseStreamer class, a base class for streamers +// This file declares the MCAsmStreamer class, a base class for streamers // which emits assembly text. // //===----------------------------------------------------------------------===// -#ifndef LLVM_MC_MCASMBASESTREAMER_H -#define LLVM_MC_MCASMBASESTREAMER_H +#ifndef LLVM_MC_MCASMSTREAMER_H +#define LLVM_MC_MCASMSTREAMER_H #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAssembler.h" @@ -28,15 +28,15 @@ class MCContext; class MCInst; class MCSubtargetInfo; -class MCAsmBaseStreamer : public MCStreamer { +class MCAsmStreamer : public MCStreamer { protected: std::unique_ptr<MCAssembler> Assembler; SmallString<128> CommentToEmit; raw_svector_ostream CommentStream; raw_null_ostream NullStream; - MCAsmBaseStreamer(MCContext &Context, std::unique_ptr<MCCodeEmitter> Emitter, - std::unique_ptr<MCAsmBackend> AsmBackend); + MCAsmStreamer(MCContext &Context, std::unique_ptr<MCCodeEmitter> Emitter, + std::unique_ptr<MCAsmBackend> AsmBackend); public: /// Return a raw_ostream that comments can be written to. @@ -58,4 +58,4 @@ class MCAsmBaseStreamer : public MCStreamer { } // end namespace llvm -#endif // LLVM_MC_MCASMBASESTREAMER_H +#endif // LLVM_MC_MCASMSTREAMER_H diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt index d42b735f1b130..653962f9c7937 100644 --- a/llvm/lib/MC/CMakeLists.txt +++ b/llvm/lib/MC/CMakeLists.txt @@ -5,7 +5,6 @@ add_llvm_component_library(LLVMMC ELFObjectWriter.cpp GOFFObjectWriter.cpp MCAsmBackend.cpp - MCAsmBaseStreamer.cpp MCAsmInfo.cpp MCAsmInfoCOFF.cpp MCAsmInfoDarwin.cpp @@ -26,6 +25,7 @@ add_llvm_component_library(LLVMMC MCELFStreamer.cpp MCExpr.cpp MCFragment.cpp + MCGNUAsmStreamer.cpp MCGOFFStreamer.cpp MCInst.cpp MCInstPrinter.cpp diff --git a/llvm/lib/MC/MCAsmBaseStreamer.cpp b/llvm/lib/MC/MCAsmBaseStreamer.cpp deleted file mode 100644 index c05b80e8f9d83..0000000000000 --- a/llvm/lib/MC/MCAsmBaseStreamer.cpp +++ /dev/null @@ -1,143 +0,0 @@ -//===- MCAsmBaseStreamer.cpp - Base Class for Asm Streamers -----*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "llvm/MC/MCAsmBaseStreamer.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/ADT/SmallVector.h" -#include "llvm/ADT/StringRef.h" -#include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmInfo.h" -#include "llvm/MC/MCAssembler.h" -#include "llvm/MC/MCCodeEmitter.h" -#include "llvm/MC/MCContext.h" -#include "llvm/MC/MCFixup.h" -#include "llvm/MC/MCInst.h" -#include "llvm/MC/MCObjectWriter.h" -#include "llvm/MC/MCSubtargetInfo.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/raw_ostream.h" - -using namespace llvm; - -MCAsmBaseStreamer::MCAsmBaseStreamer(MCContext &Context, - std::unique_ptr<MCCodeEmitter> Emitter, - std::unique_ptr<MCAsmBackend> AsmBackend) - : MCStreamer(Context), - Assembler(std::make_unique<MCAssembler>( - Context, std::move(AsmBackend), std::move(Emitter), - (AsmBackend) ? AsmBackend->createObjectWriter(NullStream) : nullptr)), - CommentStream(CommentToEmit) {} - -void MCAsmBaseStreamer::addEncodingComment(const MCInst &Inst, - const MCSubtargetInfo &STI) { - raw_ostream &OS = getCommentOS(); - SmallString<256> Code; - SmallVector<MCFixup, 4> Fixups; - - // If we have no code emitter, don't emit code. - if (!getAssembler().getEmitterPtr()) - return; - - getAssembler().getEmitter().encodeInstruction(Inst, Code, Fixups, STI); - - // RISC-V instructions are always little-endian, even on BE systems. - bool ForceLE = getContext().getTargetTriple().isRISCV(); - - const MCAsmInfo *MAI = getContext().getAsmInfo(); - - // If we are showing fixups, create symbolic markers in the encoded - // representation. We do this by making a per-bit map to the fixup item index, - // then trying to display it as nicely as possible. - SmallVector<uint8_t, 64> FixupMap; - FixupMap.resize(Code.size() * 8); - for (unsigned I = 0, E = Code.size() * 8; I != E; ++I) - FixupMap[I] = 0; - - for (unsigned I = 0, E = Fixups.size(); I != E; ++I) { - MCFixup &F = Fixups[I]; - MCFixupKindInfo Info = - getAssembler().getBackend().getFixupKindInfo(F.getKind()); - for (unsigned J = 0; J != Info.TargetSize; ++J) { - unsigned Index = F.getOffset() * 8 + Info.TargetOffset + J; - assert(Index < Code.size() * 8 && "Invalid offset in fixup!"); - FixupMap[Index] = 1 + I; - } - } - - // FIXME: Note the fixup comments for Thumb2 are completely bogus since the - // high order halfword of a 32-bit Thumb2 instruction is emitted first. - OS << "encoding: ["; - for (unsigned I = 0, E = Code.size(); I != E; ++I) { - if (I) - OS << ','; - - // See if all bits are the same map entry. - uint8_t MapEntry = FixupMap[I * 8 + 0]; - for (unsigned J = 1; J != 8; ++J) { - if (FixupMap[I * 8 + J] == MapEntry) - continue; - - MapEntry = uint8_t(~0U); - break; - } - - if (MapEntry != uint8_t(~0U)) { - if (MapEntry == 0) { - OS << format("0x%02x", uint8_t(Code[I])); - } else { - if (Code[I]) { - // FIXME: Some of the 8 bits require fix up. - OS << format("0x%02x", uint8_t(Code[I])) << '\'' - << char('A' + MapEntry - 1) << '\''; - } else - OS << char('A' + MapEntry - 1); - } - } else { - // Otherwise, write out in binary. - OS << "0b"; - for (unsigned J = 8; J--;) { - unsigned Bit = (Code[I] >> J) & 1; - - unsigned FixupBit; - // RISC-V instructions are always little-endian. - // The FixupMap is indexed by actual bit positions in the LE - // instruction. - if (MAI->isLittleEndian() || ForceLE) - FixupBit = I * 8 + J; - else - FixupBit = I * 8 + (7 - J); - - if (uint8_t MapEntry = FixupMap[FixupBit]) { - assert(Bit == 0 && "Encoder wrote into fixed up bit!"); - OS << char('A' + MapEntry - 1); - } else - OS << Bit; - } - } - } - OS << "]\n"; - - for (unsigned I = 0, E = Fixups.size(); I != E; ++I) { - MCFixup &F = Fixups[I]; - OS << " fixup " << char('A' + I) << " - " - << "offset: " << F.getOffset() << ", value: "; - MAI->printExpr(OS, *F.getValue()); - auto Kind = F.getKind(); - if (mc::isRelocation(Kind)) - OS << ", relocation type: " << Kind; - else { - OS << ", kind: "; - auto Info = getAssembler().getBackend().getFixupKindInfo(Kind); - if (F.isPCRel() && StringRef(Info.Name).starts_with("FK_Data_")) - OS << "FK_PCRel_" << (Info.TargetSize / 8); - else - OS << Info.Name; - } - OS << '\n'; - } -} diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index b451abba2e70c..f3ab3f0c48ac3 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -1,4 +1,4 @@ -//===- lib/MC/MCAsmStreamer.cpp - Text Assembly Output ----------*- C++ -*-===// +//===- MCAsmStreamer.cpp - Base Class for Asm Streamers ---------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,2598 +6,138 @@ // //===----------------------------------------------------------------------===// +#include "llvm/MC/MCAsmStreamer.h" #include "llvm/ADT/SmallString.h" -#include "llvm/ADT/StringExtras.h" -#include "llvm/ADT/Twine.h" -#include "llvm/DebugInfo/CodeView/SymbolRecord.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" #include "llvm/MC/MCAsmBackend.h" -#include "llvm/MC/MCAsmBaseStreamer.h" #include "llvm/MC/MCAsmInfo.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCCodeEmitter.h" -#include "llvm/MC/MCCodeView.h" #include "llvm/MC/MCContext.h" -#include "llvm/MC/MCExpr.h" +#include "llvm/MC/MCFixup.h" #include "llvm/MC/MCInst.h" -#include "llvm/MC/MCInstPrinter.h" -#include "llvm/MC/MCLFIRewriter.h" -#include "llvm/MC/MCObjectFileInfo.h" #include "llvm/MC/MCObjectWriter.h" -#include "llvm/MC/MCPseudoProbe.h" -#include "llvm/MC/MCRegister.h" -#include "llvm/MC/MCRegisterInfo.h" -#include "llvm/MC/MCSectionMachO.h" -#include "llvm/MC/MCStreamer.h" -#include "llvm/MC/MCSymbolXCOFF.h" -#include "llvm/MC/TargetRegistry.h" -#include "llvm/Support/ErrorHandling.h" +#include "llvm/MC/MCSubtargetInfo.h" #include "llvm/Support/Format.h" -#include "llvm/Support/FormattedStream.h" -#include "llvm/Support/LEB128.h" -#include "llvm/Support/MathExtras.h" -#include "llvm/Support/Path.h" -#include <algorithm> -#include <optional> +#include "llvm/Support/raw_ostream.h" using namespace llvm; -namespace { +MCAsmStreamer::MCAsmStreamer(MCContext &Context, + std::unique_ptr<MCCodeEmitter> Emitter, + std::unique_ptr<MCAsmBackend> AsmBackend) + : MCStreamer(Context), + Assembler(std::make_unique<MCAssembler>( + Context, std::move(AsmBackend), std::move(Emitter), + (AsmBackend) ? AsmBackend->createObjectWriter(NullStream) : nullptr)), + CommentStream(CommentToEmit) {} -class MCAsmStreamer final : public MCAsmBaseStreamer { - std::unique_ptr<formatted_raw_ostream> OSOwner; - formatted_raw_ostream &OS; - const MCAsmInfo *MAI; - std::unique_ptr<MCInstPrinter> InstPrinter; +void MCAsmStreamer::addEncodingComment(const MCInst &Inst, + const MCSubtargetInfo &STI) { + raw_ostream &OS = getCommentOS(); + SmallString<256> Code; + SmallVector<MCFixup, 4> Fixups; - SmallString<128> ExplicitCommentToEmit; - - bool EmittedSectionDirective = false; - - bool IsVerboseAsm = false; - bool ShowInst = false; - bool UseDwarfDirectory = false; - - void EmitRegisterName(int64_t Register); - void PrintQuotedString(StringRef Data, raw_ostream &OS) const; - void printDwarfFileDirective(unsigned FileNo, StringRef Directory, - StringRef Filename, - std::optional<MD5::MD5Result> Checksum, - std::optional<StringRef> Source, - bool UseDwarfDirectory, - raw_svector_ostream &OS) const; - void emitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override; - void emitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override; - - /// Helper to emit common .loc directive flags, isa, and discriminator. - void emitDwarfLocDirectiveFlags(unsigned Flags, unsigned Isa, - unsigned Discriminator); - - /// Helper to emit the common suffix of .loc directives (flags, comment, EOL, - /// parent call). - void emitDwarfLocDirectiveSuffix(unsigned FileNo, unsigned Line, - unsigned Column, unsigned Flags, - unsigned Isa, unsigned Discriminator, - StringRef FileName, StringRef Comment); - -public: - MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> OS, - std::unique_ptr<MCInstPrinter> Printer, - std::unique_ptr<MCCodeEmitter> Emitter, - std::unique_ptr<MCAsmBackend> AsmBackend) - : MCAsmBaseStreamer(Context, std::move(Emitter), std::move(AsmBackend)), - OSOwner(std::move(OS)), OS(*OSOwner), MAI(Context.getAsmInfo()), - InstPrinter(std::move(Printer)) { - assert(InstPrinter); - if (Assembler->getBackendPtr()) - setAllowAutoPadding(Assembler->getBackend().allowAutoPadding()); - - Context.setUseNamesOnTempLabels(true); - - auto *TO = Context.getTargetOptions(); - if (!TO) - return; - IsVerboseAsm = TO->AsmVerbose; - if (IsVerboseAsm) - InstPrinter->setCommentStream(CommentStream); - ShowInst = TO->ShowMCInst; - switch (TO->MCUseDwarfDirectory) { - case MCTargetOptions::DisableDwarfDirectory: - UseDwarfDirectory = false; - break; - case MCTargetOptions::EnableDwarfDirectory: - UseDwarfDirectory = true; - break; - case MCTargetOptions::DefaultDwarfDirectory: - UseDwarfDirectory = - Context.getAsmInfo()->enableDwarfFileDirectoryDefault(); - break; - } - } - - inline void EmitEOL() { - // Dump Explicit Comments here. - emitExplicitComments(); - // If we don't have any comments, just emit a \n. - if (!IsVerboseAsm) { - OS << '\n'; - return; - } - EmitCommentsAndEOL(); - } - - void emitSyntaxDirective(StringRef Syntax, StringRef Options) override; - - void EmitCommentsAndEOL(); - - /// Return true if this streamer supports verbose assembly at all. - bool isVerboseAsm() const override { return IsVerboseAsm; } - - /// Do we support EmitRawText? - bool hasRawTextSupport() const override { return true; } - - /// Add a comment that can be emitted to the generated .s file to make the - /// output of the compiler more readable. This only affects the MCAsmStreamer - /// and only when verbose assembly output is enabled. - void AddComment(const Twine &T, bool EOL = true) override; - - void emitRawComment(const Twine &T, bool TabPrefix = true) override; - - void addExplicitComment(const Twine &T) override; - void emitExplicitComments() override; - - /// Emit a blank line to a .s file to pretty it up. - void addBlankLine() override { EmitEOL(); } - - /// @name MCStreamer Interface - /// @{ - - void switchSection(MCSection *Section, uint32_t Subsection) override; - bool popSection() override; - - void emitELFSymverDirective(const MCSymbol *OriginalSym, StringRef Name, - bool KeepOriginalSym) override; - - void emitLOHDirective(MCLOHType Kind, const MCLOHArgs &Args) override; - - void emitGNUAttribute(unsigned Tag, unsigned Value) override; - - StringRef getMnemonic(const MCInst &MI) const override { - auto [Ptr, Bits] = InstPrinter->getMnemonic(MI); - assert((Bits != 0 || Ptr == nullptr) && - "Invalid char pointer for instruction with no mnemonic"); - return Ptr; - } - - void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override; - - void emitSubsectionsViaSymbols() override; - void emitLinkerOptions(ArrayRef<std::string> Options) override; - void emitDataRegion(MCDataRegionType Kind) override; - void emitVersionMin(MCVersionMinType Kind, unsigned Major, unsigned Minor, - unsigned Update, VersionTuple SDKVersion) override; - void emitBuildVersion(unsigned Platform, unsigned Major, unsigned Minor, - unsigned Update, VersionTuple SDKVersion) override; - void emitDarwinTargetVariantBuildVersion(unsigned Platform, unsigned Major, - unsigned Minor, unsigned Update, - VersionTuple SDKVersion) override; - - void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override; - void emitConditionalAssignment(MCSymbol *Symbol, - const MCExpr *Value) override; - void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override; - bool emitSymbolAttribute(MCSymbol *Symbol, MCSymbolAttr Attribute) override; - - void emitSymbolDesc(MCSymbol *Symbol, unsigned DescValue) override; - void beginCOFFSymbolDef(const MCSymbol *Symbol) override; - void emitCOFFSymbolStorageClass(int StorageClass) override; - void emitCOFFSymbolType(int Type) override; - void endCOFFSymbolDef() override; - void emitCOFFSafeSEH(MCSymbol const *Symbol) override; - void emitCOFFSymbolIndex(MCSymbol const *Symbol) override; - void emitCOFFSectionIndex(MCSymbol const *Symbol) override; - void emitCOFFSecRel32(MCSymbol const *Symbol, uint64_t Offset) override; - void emitCOFFImgRel32(MCSymbol const *Symbol, int64_t Offset) override; - void emitCOFFSecNumber(MCSymbol const *Symbol) override; - void emitCOFFSecOffset(MCSymbol const *Symbol) override; - void emitXCOFFLocalCommonSymbol(MCSymbol *LabelSym, uint64_t Size, - MCSymbol *CsectSym, Align Alignment) override; - void emitXCOFFSymbolLinkageWithVisibility(MCSymbol *Symbol, - MCSymbolAttr Linkage, - MCSymbolAttr Visibility) override; - void emitXCOFFRenameDirective(const MCSymbol *Name, - StringRef Rename) override; - - void emitXCOFFRefDirective(const MCSymbol *Symbol) override; - - void emitXCOFFExceptDirective(const MCSymbol *Symbol, - const MCSymbol *Trap, - unsigned Lang, unsigned Reason, - unsigned FunctionSize, bool hasDebug) override; - void emitXCOFFCInfoSym(StringRef Name, StringRef Metadata) override; - - void emitELFSize(MCSymbol *Symbol, const MCExpr *Value) override; - void emitCommonSymbol(MCSymbol *Symbol, uint64_t Size, - Align ByteAlignment) override; - - /// Emit a local common (.lcomm) symbol. - /// - /// @param Symbol - The common symbol to emit. - /// @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, - Align ByteAlignment) override; - - void emitZerofill(MCSection *Section, MCSymbol *Symbol = nullptr, - uint64_t Size = 0, Align ByteAlignment = Align(1), - SMLoc Loc = SMLoc()) override; - - void emitTBSSSymbol(MCSection *Section, MCSymbol *Symbol, uint64_t Size, - Align ByteAlignment = Align(1)) override; - - void emitBinaryData(StringRef Data) override; - - void emitBytes(StringRef Data) override; - - void emitValueImpl(const MCExpr *Value, unsigned Size, - SMLoc Loc = SMLoc()) override; - void emitIntValue(uint64_t Value, unsigned Size) override; - void emitIntValueInHex(uint64_t Value, unsigned Size) override; - void emitIntValueInHexWithPadding(uint64_t Value, unsigned Size) override; - - void emitULEB128Value(const MCExpr *Value) override; - - void emitSLEB128Value(const MCExpr *Value) override; - - void emitFill(const MCExpr &NumBytes, uint64_t FillValue, - SMLoc Loc = SMLoc()) override; - - void emitFill(const MCExpr &NumValues, int64_t Size, int64_t Expr, - SMLoc Loc = SMLoc()) override; - - void emitAlignmentDirective(uint64_t ByteAlignment, - std::optional<int64_t> Value, unsigned ValueSize, - unsigned MaxBytesToEmit); - - void emitValueToAlignment(Align Alignment, int64_t Fill = 0, - uint8_t FillLen = 1, - unsigned MaxBytesToEmit = 0) override; - - void emitCodeAlignment(Align Alignment, const MCSubtargetInfo *STI, - unsigned MaxBytesToEmit = 0) override; - void emitPrefAlign(Align Alignment) override; - - void emitValueToOffset(const MCExpr *Offset, - unsigned char Value, - SMLoc Loc) override; - - void emitFileDirective(StringRef Filename) override; ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/183763 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
