[llvm-branch-commits] [llvm] [GOFF] Implement lowerConstant/emitGlobalVariables/emitGlobalAlias for z/OS (PR #169362)
Tony Tao via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Jan 14 11:58:35 PST 2026
https://github.com/tltao updated https://github.com/llvm/llvm-project/pull/169362
>From 7cc2062db8da1160313c5c2afeb81409d76ea7f7 Mon Sep 17 00:00:00 2001
From: Tony Tao <tonytao at ca.ibm.com>
Date: Wed, 14 Jan 2026 14:58:12 -0500
Subject: [PATCH] Implement emitGlobalAlias and lowerConstant
---
.../CodeGen/TargetLoweringObjectFileImpl.cpp | 4 +
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 87 +++++++++++++++++++
llvm/lib/Target/SystemZ/SystemZAsmPrinter.h | 3 +
3 files changed, 94 insertions(+)
diff --git a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
index 5edbc4caf3fae..0e9bea767608b 100644
--- a/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -2794,6 +2794,10 @@ void TargetLoweringObjectFileGOFF::getModuleMetadata(Module &M) {
TextLD->setWeak(false);
TextLD->setADA(ADAPR);
TextSection->setBeginSymbol(TextLD);
+ // Initialize the label for the ADA section.
+ MCSymbolGOFF *ADASym = static_cast<MCSymbolGOFF *>(
+ getContext().getOrCreateSymbol(ADAPR->getName()));
+ ADAPR->setBeginSymbol(ADASym);
}
MCSection *TargetLoweringObjectFileGOFF::getExplicitSectionGlobal(
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index b36605ec54374..2f25dac9cd1ce 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -1712,6 +1712,93 @@ void SystemZAsmPrinter::emitPPA2(Module &M) {
OutStreamer->popSection();
}
+void SystemZAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
+ auto *Sym = getSymbol(GV);
+ // This is currently done in the base emitGlobalVariable implementation
+ // but is guarded by hasDotTypeDotSizeDirective() which is set to false
+ // for z/OS
+ OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
+ AsmPrinter::emitGlobalVariable(GV);
+}
+
+void SystemZAsmPrinter::emitGlobalAlias(const Module &M, const GlobalAlias &GA) {
+ MCSymbol *Name = getSymbol(&GA);
+ bool IsFunc = isa<Function>(GA.getAliasee()->stripPointerCasts());
+ llvm::dbgs() << "TONY emitting alias for " << Name->getName() << "\n";
+
+ if (GA.hasExternalLinkage() || !MAI->getWeakRefDirective()) {
+ llvm::dbgs() << "TONY set global linkage\n";
+ OutStreamer->emitSymbolAttribute(Name, MCSA_Global);
+ }
+ else if (GA.hasWeakLinkage() || GA.hasLinkOnceLinkage()) {
+ llvm::dbgs() << "TONY set weak linkage\n";
+ OutStreamer->emitSymbolAttribute(Name, MCSA_WeakReference);
+ }
+ else
+ assert(GA.hasLocalLinkage() && "Invalid alias linkage");
+
+ emitVisibility(Name, GA.getVisibility());
+
+ const MCExpr *Expr;
+
+ // For XPLINK, create a VCON relocation in case of a function, and
+ // a direct reference else.
+ MCSymbol *Sym = getSymbol(GA.getAliaseeObject());
+ if (IsFunc) {
+ Expr = MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
+ SystemZ::S_VCon, OutContext);
+ llvm::dbgs() << "TONY create svcon\n";
+ }
+ else
+ Expr = MCSymbolRefExpr::create(Sym, OutContext);
+
+ OutStreamer->emitAssignment(Name, Expr);
+}
+
+const MCExpr *SystemZAsmPrinter::lowerConstant(const Constant *CV,
+ const Constant *BaseCV,
+ uint64_t Offset) {
+ const GlobalAlias *GA = dyn_cast<GlobalAlias>(CV);
+ const GlobalVariable *GV = dyn_cast<GlobalVariable>(CV);
+ const Function *FV = dyn_cast<Function>(CV);
+ bool IsFunc = !GV && (FV || (GA && isa<Function>(GA->getAliaseeObject())));
+
+ MCSymbol *Sym = NULL;
+
+ if (GA)
+ Sym = getSymbol(GA);
+ else if (IsFunc)
+ Sym = getSymbol(FV);
+ else if (GV)
+ Sym = getSymbol(GV);
+
+ if (IsFunc) {
+ OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeFunction);
+ if (FV->hasExternalLinkage()) {
+ llvm::dbgs() << "TONY generating lower constant ext func for " << Sym->getName() << "\n";
+ return MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym, OutContext),
+ SystemZ::S_VCon, OutContext);
+ }
+ // Trigger creation of function descriptor in ADA for internal
+ // functions.
+ unsigned Disp = ADATable.insert(Sym, SystemZII::MO_ADA_DIRECT_FUNC_DESC).second;
+ llvm::dbgs() << "TONY generating lower constant static func for " << Sym->getName() << "\n";
+ return MCBinaryExpr::createAdd(
+ MCSpecifierExpr::create(
+ MCSymbolRefExpr::create(
+ getObjFileLowering().getADASection()->getBeginSymbol(),
+ OutContext),
+ SystemZ::S_None, OutContext),
+ MCConstantExpr::create(Disp, OutContext), OutContext);
+ }
+ if (Sym) {
+ llvm::dbgs() << "TONY generating lower constant sym for " << Sym->getName() << "\n";
+ OutStreamer->emitSymbolAttribute(Sym, MCSA_ELF_TypeObject);
+ return MCSymbolRefExpr::create(Sym, OutContext);
+ }
+ return AsmPrinter::lowerConstant(CV);
+}
+
void SystemZAsmPrinter::emitFunctionEntryLabel() {
const SystemZSubtarget &Subtarget = MF->getSubtarget<SystemZSubtarget>();
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
index 0611179ee7262..ab2a9754cfac1 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.h
@@ -131,6 +131,9 @@ class LLVM_LIBRARY_VISIBILITY SystemZAsmPrinter : public AsmPrinter {
void emitFunctionEntryLabel() override;
void emitFunctionBodyEnd() override;
void emitStartOfAsmFile(Module &M) override;
+ void emitGlobalVariable(const GlobalVariable *GV) override;
+ void emitGlobalAlias(const Module &M, const GlobalAlias &GA) override;
+ const MCExpr *lowerConstant(const Constant *CV, const Constant *BaseCV = nullptr, uint64_t Offset = 0) override;
private:
void emitCallInformation(CallType CT);
More information about the llvm-branch-commits
mailing list