[llvm] [SystemZ] Split SystemZAsmPrinter into 2 classes - ELF and XPLink (PR #214343)

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 24 12:01:04 PDT 2026


================
@@ -0,0 +1,456 @@
+//===-- SystemZELFAsmPrinter.cpp - SystemZ ELF asm printer ----------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// This file implements the SystemZELFAsmPrinter class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "SystemZELFAsmPrinter.h"
+#include "MCTargetDesc/SystemZMCTargetDesc.h"
+#include "SystemZConstantPoolValue.h"
+#include "SystemZMCInstLower.h"
+#include "SystemZSubtarget.h"
+#include "llvm/BinaryFormat/ELF.h"
+#include "llvm/CodeGen/MachineConstantPool.h"
+#include "llvm/CodeGen/StackMaps.h"
+#include "llvm/IR/Module.h"
+#include "llvm/MC/MCExpr.h"
+#include "llvm/MC/MCInstBuilder.h"
+#include "llvm/MC/MCSectionELF.h"
+#include "llvm/MC/MCStreamer.h"
+
+using namespace llvm;
+
+// Emit the largest nop instruction smaller than or equal to NumBytes
+// bytes.  Return the size of nop emitted.
+static unsigned EmitNop(MCContext &OutContext, MCStreamer &OutStreamer,
+                        unsigned NumBytes, const MCSubtargetInfo &STI) {
+  if (NumBytes < 2) {
+    llvm_unreachable("Zero nops?");
+    return 0;
+  } else if (NumBytes < 4) {
+    OutStreamer.emitInstruction(
+        MCInstBuilder(SystemZ::BCRAsm).addImm(0).addReg(SystemZ::R0D), STI);
+    return 2;
+  } else if (NumBytes < 6) {
+    OutStreamer.emitInstruction(
+        MCInstBuilder(SystemZ::BCAsm).addImm(0).addReg(0).addImm(0).addReg(0),
+        STI);
+    return 4;
+  } else {
+    MCSymbol *DotSym = OutContext.createTempSymbol();
+    const MCSymbolRefExpr *Dot = MCSymbolRefExpr::create(DotSym, OutContext);
+    OutStreamer.emitLabel(DotSym);
+    OutStreamer.emitInstruction(
+        MCInstBuilder(SystemZ::BRCLAsm).addImm(0).addExpr(Dot), STI);
+    return 6;
+  }
+}
+
+static const MCSymbolRefExpr *getTLSGetOffset(MCContext &Context) {
+  StringRef Name = "__tls_get_offset";
+  return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name),
+                                 SystemZ::S_PLT, Context);
+}
+
+static const MCSymbolRefExpr *getGlobalOffsetTable(MCContext &Context) {
+  StringRef Name = "_GLOBAL_OFFSET_TABLE_";
+  return MCSymbolRefExpr::create(Context.getOrCreateSymbol(Name), Context);
+}
+
+SystemZELFAsmPrinter::SystemZELFAsmPrinter(TargetMachine &TM,
+                                           std::unique_ptr<MCStreamer> Streamer)
+    : SystemZAsmPrinter(TM, std::move(Streamer)) {}
+
+void SystemZELFAsmPrinter::emitInstruction(const MachineInstr *MI) {
+  SystemZMCInstLower Lower(MF->getContext(), *this);
+
+  switch (MI->getOpcode()) {
+  case TargetOpcode::FENTRY_CALL:
+    LowerFENTRY_CALL(*MI, Lower);
+    return;
+  case TargetOpcode::STACKMAP:
+    LowerSTACKMAP(*MI);
+    return;
+  case TargetOpcode::PATCHPOINT:
+    LowerPATCHPOINT(*MI, Lower);
+    return;
+  case TargetOpcode::PATCHABLE_FUNCTION_ENTER:
+    LowerPATCHABLE_FUNCTION_ENTER(*MI, Lower);
+    return;
+  case TargetOpcode::PATCHABLE_RET:
+    LowerPATCHABLE_RET(*MI, Lower);
+    return;
+  case SystemZ::CallBASR: {
----------------
uweigand wrote:

We don't need any of these braces here or below.

https://github.com/llvm/llvm-project/pull/214343


More information about the llvm-commits mailing list