[llvm] 4ad89d1 - [SystemZ][z/OS] Remove temporary gnu as output on z/OS (#181906)

via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 6 08:47:11 PDT 2026


Author: Kai Nacke
Date: 2026-07-06T11:47:07-04:00
New Revision: 4ad89d11db9e4048328de408af5ae0503861fe4c

URL: https://github.com/llvm/llvm-project/commit/4ad89d11db9e4048328de408af5ae0503861fe4c
DIFF: https://github.com/llvm/llvm-project/commit/4ad89d11db9e4048328de408af5ae0503861fe4c.diff

LOG: [SystemZ][z/OS] Remove temporary gnu as output on z/OS (#181906)

On z/OS, there is only HLASM as system assembler available. Since all
LIT tests are migrated, the temporary option can now be removed.

Added: 
    

Modified: 
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h
    llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
index 3999534fac1b8..6d6b25efbf525 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.cpp
@@ -115,6 +115,12 @@ void SystemZHLASMAsmStreamer::emitAlignmentDS(uint64_t ByteAlignment,
   EmitEOL();
 }
 
+raw_ostream &SystemZHLASMAsmStreamer::getCommentOS() {
+  if (!IsVerboseAsm)
+    return nulls(); // Discard comments unless in verbose asm mode.
+  return CommentStream;
+}
+
 void SystemZHLASMAsmStreamer::AddComment(const Twine &T, bool EOL) {
   if (!IsVerboseAsm)
     return;
@@ -186,6 +192,99 @@ void SystemZHLASMAsmStreamer::emitBytes(StringRef Data) {
   EmitEOL();
 }
 
+void SystemZHLASMAsmStreamer::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);
+
+  // 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;
+    }
+  }
+
+  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 = 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";
+  }
+}
+
 void SystemZHLASMAsmStreamer::emitInstruction(const MCInst &Inst,
                                               const MCSubtargetInfo &STI) {
   // Show the encoding in a comment if we have a code emitter.

diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h
index 7a0eab9b940c3..41f388ca8dcce 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZHLASMAsmStreamer.h
@@ -71,6 +71,8 @@ class SystemZHLASMAsmStreamer final : public MCAsmBaseStreamer {
   /// and only when verbose assembly output is enabled.
   void AddComment(const Twine &T, bool EOL = true) override;
 
+  raw_ostream &getCommentOS() override;
+
   void emitBytes(StringRef Data) override;
 
   void emitAlignmentDS(uint64_t ByteAlignment, std::optional<int64_t> Value,
@@ -87,6 +89,8 @@ class SystemZHLASMAsmStreamer final : public MCAsmBaseStreamer {
   /// Do we support EmitRawText?
   bool hasRawTextSupport() const override { return true; }
 
+  void addEncodingComment(const MCInst &Inst, const MCSubtargetInfo &STI);
+
   /// @name MCStreamer Interface
   /// @{
   void visitUsedSymbol(const MCSymbol &Sym) override;

diff  --git a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
index 5d605964cf2c0..a0de6949f343e 100644
--- a/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
+++ b/llvm/lib/Target/SystemZ/MCTargetDesc/SystemZMCTargetDesc.cpp
@@ -37,12 +37,6 @@ using namespace llvm;
 #define GET_REGINFO_MC_DESC
 #include "SystemZGenRegisterInfo.inc"
 
-// Temporary option to assist with the migration to a new HLASMAsmStreamer on
-// z/OS
-static cl::opt<bool> GNUAsOnzOSCL("emit-gnuas-syntax-on-zos",
-                                  cl::desc("Emit GNU Assembly Syntax on z/OS."),
-                                  cl::init(false));
-
 const unsigned SystemZMC::GR32Regs[16] = {
     SystemZ::R0L,  SystemZ::R1L,  SystemZ::R2L,  SystemZ::R3L,
     SystemZ::R4L,  SystemZ::R5L,  SystemZ::R6L,  SystemZ::R7L,
@@ -203,7 +197,7 @@ static MCInstPrinter *createSystemZMCInstPrinter(const Triple &T,
 static MCTargetStreamer *createAsmTargetStreamer(MCStreamer &S,
                                                  formatted_raw_ostream &OS,
                                                  MCInstPrinter *InstPrint) {
-  if (S.getContext().getTargetTriple().isOSzOS() && !GNUAsOnzOSCL)
+  if (S.getContext().getTargetTriple().isOSzOS())
     return new SystemZTargetHLASMStreamer(S, OS);
   else
     return new SystemZTargetGNUStreamer(S, OS);
@@ -215,7 +209,7 @@ static MCStreamer *createSystemZAsmStreamer(
     std::unique_ptr<MCAsmBackend> TAB) {
 
   auto TT = Ctx.getTargetTriple();
-  if (TT.isOSzOS() && !GNUAsOnzOSCL)
+  if (TT.isOSzOS())
     return new SystemZHLASMAsmStreamer(Ctx, std::move(OS), std::move(IP),
                                        std::move(CE), std::move(TAB));
 


        


More information about the llvm-commits mailing list