[llvm-branch-commits] [clang] [llvm] [GOFF] Implement lowerConstant/emitGlobalVariables/emitGlobalAlias (PR #169362)
https://github.com/tltao created
https://github.com/llvm/llvm-project/pull/169362
Add additional functionality required on z/OS for `lowerConstant`,
`emitGlobalVariable`, and `emitGlobalAlias`. The main addition is to properly
apply the attribute to the various `MCSymbols` and also emit the correct
`MCExpr`.
>From d565c7d8c772cf1c66d57bd1db0387ad90bb1d9b Mon Sep 17 00:00:00 2001
From: Tony Tao
Date: Wed, 19 Nov 2025 19:55:35 +
Subject: [PATCH 1/4] Implement emitGlobalVariable and lowerConstant
---
clang/lib/Lex/HeaderMap.cpp | 1 +
llvm/lib/Support/VirtualOutputBackends.cpp| 23 +---
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 56 +++
llvm/lib/Target/SystemZ/SystemZAsmPrinter.h | 2 +
4 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index a7b670f00ac6e..588b32ee9ca8e 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
#include
#include
#include
diff --git a/llvm/lib/Support/VirtualOutputBackends.cpp
b/llvm/lib/Support/VirtualOutputBackends.cpp
index de59b8ab63a53..33a56c7f5f607 100644
--- a/llvm/lib/Support/VirtualOutputBackends.cpp
+++ b/llvm/lib/Support/VirtualOutputBackends.cpp
@@ -254,6 +254,18 @@ static Error createDirectoriesOnDemand(StringRef
OutputPath,
});
}
+static sys::fs::OpenFlags generateFlagsFromConfig(OutputConfig Config) {
+ sys::fs::OpenFlags OF = sys::fs::OF_None;
+ if (Config.getTextWithCRLF())
+ OF |= sys::fs::OF_TextWithCRLF;
+ else if (Config.getText())
+ OF |= sys::fs::OF_Text;
+ if (Config.getAppend())
+ OF |= sys::fs::OF_Append;
+
+ return OF;
+}
+
Error OnDiskOutputFile::tryToCreateTemporary(std::optional &FD) {
// Create a temporary file.
// Insert - before the extension (if any), and because some tools
@@ -268,9 +280,10 @@ Error
OnDiskOutputFile::tryToCreateTemporary(std::optional &FD) {
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
int NewFD;
+ sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
SmallString<128> UniquePath;
if (std::error_code EC =
-sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath))
+sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath, OF))
return make_error(ModelPath, OutputPath, EC);
if (Config.getDiscardOnSignal())
@@ -312,13 +325,7 @@ Error OnDiskOutputFile::initializeFile(std::optional
&FD) {
// Not using a temporary file. Open the final output file.
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
int NewFD;
-sys::fs::OpenFlags OF = sys::fs::OF_None;
-if (Config.getTextWithCRLF())
- OF |= sys::fs::OF_TextWithCRLF;
-else if (Config.getText())
- OF |= sys::fs::OF_Text;
-if (Config.getAppend())
- OF |= sys::fs::OF_Append;
+sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
if (std::error_code EC = sys::fs::openFileForWrite(
OutputPath, NewFD, sys::fs::CD_CreateAlways, OF))
return convertToOutputError(OutputPath, EC);
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 193e6ef6d1e64..151b59334cab1 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -1123,6 +1123,7 @@ void SystemZAsmPrinter::emitEndOfAsmFile(Module &M) {
: MCSA_Global);
OutStreamer->emitSymbolAttribute(Sym, isa(GO) ? MCSA_Code
: MCSA_Data);
+llvm::dbgs() << "TONY emitting " << Sym->getName() << "\n";
}
}
OutStreamer->switchSection(
@@ -1699,6 +1700,61 @@ void SystemZAsmPrinter::emitPPA2(Module &M) {
OutStreamer->popSection();
}
+void SystemZAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
+ if (TM.getTargetTriple().isOSzOS()) {
+auto *Sym = getSymbol(GV);
+OutStreamer->emitSymbolAttribute(Sym, MCSA_Data);
+ }
+
+ AsmPrinter::emitGlobalVariable(GV);
+}
+
+const MCExpr *SystemZAsmPrinter::lowerConstant(const Constant *CV,
+ const Constant *BaseCV,
+ uint64_t Offset) {
+ const Triple &TargetTriple = TM.getTargetTriple();
+
+ if (TargetTriple.isOSzOS()) {
+const GlobalAlias *GA = dyn_cast(CV);
+const GlobalVariable *GV = dyn_cast(CV);
+const Function *FV = dyn_cast(CV);
+bool IsFunc = !GV && (FV || (GA && isa(GA->getAliaseeObject(;
+
+MCSymbol *Sym = NULL;
+
+if (GA)
+ Sym = getSymbol(GA);
+else if (IsFunc)
+ Sym = getSymbol(FV);
+
[llvm-branch-commits] [clang] [llvm] [GOFF] Implement lowerConstant/emitGlobalVariables/emitGlobalAlias (PR #169362)
https://github.com/tltao updated
https://github.com/llvm/llvm-project/pull/169362
>From d565c7d8c772cf1c66d57bd1db0387ad90bb1d9b Mon Sep 17 00:00:00 2001
From: Tony Tao
Date: Wed, 19 Nov 2025 19:55:35 +
Subject: [PATCH 1/5] Implement emitGlobalVariable and lowerConstant
---
clang/lib/Lex/HeaderMap.cpp | 1 +
llvm/lib/Support/VirtualOutputBackends.cpp| 23 +---
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 56 +++
llvm/lib/Target/SystemZ/SystemZAsmPrinter.h | 2 +
4 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index a7b670f00ac6e..588b32ee9ca8e 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
#include
#include
#include
diff --git a/llvm/lib/Support/VirtualOutputBackends.cpp
b/llvm/lib/Support/VirtualOutputBackends.cpp
index de59b8ab63a53..33a56c7f5f607 100644
--- a/llvm/lib/Support/VirtualOutputBackends.cpp
+++ b/llvm/lib/Support/VirtualOutputBackends.cpp
@@ -254,6 +254,18 @@ static Error createDirectoriesOnDemand(StringRef
OutputPath,
});
}
+static sys::fs::OpenFlags generateFlagsFromConfig(OutputConfig Config) {
+ sys::fs::OpenFlags OF = sys::fs::OF_None;
+ if (Config.getTextWithCRLF())
+ OF |= sys::fs::OF_TextWithCRLF;
+ else if (Config.getText())
+ OF |= sys::fs::OF_Text;
+ if (Config.getAppend())
+ OF |= sys::fs::OF_Append;
+
+ return OF;
+}
+
Error OnDiskOutputFile::tryToCreateTemporary(std::optional &FD) {
// Create a temporary file.
// Insert - before the extension (if any), and because some tools
@@ -268,9 +280,10 @@ Error
OnDiskOutputFile::tryToCreateTemporary(std::optional &FD) {
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
int NewFD;
+ sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
SmallString<128> UniquePath;
if (std::error_code EC =
-sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath))
+sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath, OF))
return make_error(ModelPath, OutputPath, EC);
if (Config.getDiscardOnSignal())
@@ -312,13 +325,7 @@ Error OnDiskOutputFile::initializeFile(std::optional
&FD) {
// Not using a temporary file. Open the final output file.
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
int NewFD;
-sys::fs::OpenFlags OF = sys::fs::OF_None;
-if (Config.getTextWithCRLF())
- OF |= sys::fs::OF_TextWithCRLF;
-else if (Config.getText())
- OF |= sys::fs::OF_Text;
-if (Config.getAppend())
- OF |= sys::fs::OF_Append;
+sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
if (std::error_code EC = sys::fs::openFileForWrite(
OutputPath, NewFD, sys::fs::CD_CreateAlways, OF))
return convertToOutputError(OutputPath, EC);
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 193e6ef6d1e64..151b59334cab1 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -1123,6 +1123,7 @@ void SystemZAsmPrinter::emitEndOfAsmFile(Module &M) {
: MCSA_Global);
OutStreamer->emitSymbolAttribute(Sym, isa(GO) ? MCSA_Code
: MCSA_Data);
+llvm::dbgs() << "TONY emitting " << Sym->getName() << "\n";
}
}
OutStreamer->switchSection(
@@ -1699,6 +1700,61 @@ void SystemZAsmPrinter::emitPPA2(Module &M) {
OutStreamer->popSection();
}
+void SystemZAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
+ if (TM.getTargetTriple().isOSzOS()) {
+auto *Sym = getSymbol(GV);
+OutStreamer->emitSymbolAttribute(Sym, MCSA_Data);
+ }
+
+ AsmPrinter::emitGlobalVariable(GV);
+}
+
+const MCExpr *SystemZAsmPrinter::lowerConstant(const Constant *CV,
+ const Constant *BaseCV,
+ uint64_t Offset) {
+ const Triple &TargetTriple = TM.getTargetTriple();
+
+ if (TargetTriple.isOSzOS()) {
+const GlobalAlias *GA = dyn_cast(CV);
+const GlobalVariable *GV = dyn_cast(CV);
+const Function *FV = dyn_cast(CV);
+bool IsFunc = !GV && (FV || (GA && isa(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_Code);
+ if (FV->hasExternalLinkage()) {
+return MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym,
Out
[llvm-branch-commits] [clang] [llvm] [GOFF] Implement lowerConstant/emitGlobalVariables/emitGlobalAlias (PR #169362)
https://github.com/tltao updated
https://github.com/llvm/llvm-project/pull/169362
>From d565c7d8c772cf1c66d57bd1db0387ad90bb1d9b Mon Sep 17 00:00:00 2001
From: Tony Tao
Date: Wed, 19 Nov 2025 19:55:35 +
Subject: [PATCH 1/6] Implement emitGlobalVariable and lowerConstant
---
clang/lib/Lex/HeaderMap.cpp | 1 +
llvm/lib/Support/VirtualOutputBackends.cpp| 23 +---
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 56 +++
llvm/lib/Target/SystemZ/SystemZAsmPrinter.h | 2 +
4 files changed, 74 insertions(+), 8 deletions(-)
diff --git a/clang/lib/Lex/HeaderMap.cpp b/clang/lib/Lex/HeaderMap.cpp
index a7b670f00ac6e..588b32ee9ca8e 100644
--- a/clang/lib/Lex/HeaderMap.cpp
+++ b/clang/lib/Lex/HeaderMap.cpp
@@ -18,6 +18,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/SystemZ/zOSSupport.h"
#include
#include
#include
diff --git a/llvm/lib/Support/VirtualOutputBackends.cpp
b/llvm/lib/Support/VirtualOutputBackends.cpp
index de59b8ab63a53..33a56c7f5f607 100644
--- a/llvm/lib/Support/VirtualOutputBackends.cpp
+++ b/llvm/lib/Support/VirtualOutputBackends.cpp
@@ -254,6 +254,18 @@ static Error createDirectoriesOnDemand(StringRef
OutputPath,
});
}
+static sys::fs::OpenFlags generateFlagsFromConfig(OutputConfig Config) {
+ sys::fs::OpenFlags OF = sys::fs::OF_None;
+ if (Config.getTextWithCRLF())
+ OF |= sys::fs::OF_TextWithCRLF;
+ else if (Config.getText())
+ OF |= sys::fs::OF_Text;
+ if (Config.getAppend())
+ OF |= sys::fs::OF_Append;
+
+ return OF;
+}
+
Error OnDiskOutputFile::tryToCreateTemporary(std::optional &FD) {
// Create a temporary file.
// Insert - before the extension (if any), and because some tools
@@ -268,9 +280,10 @@ Error
OnDiskOutputFile::tryToCreateTemporary(std::optional &FD) {
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
int NewFD;
+ sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
SmallString<128> UniquePath;
if (std::error_code EC =
-sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath))
+sys::fs::createUniqueFile(ModelPath, NewFD, UniquePath, OF))
return make_error(ModelPath, OutputPath, EC);
if (Config.getDiscardOnSignal())
@@ -312,13 +325,7 @@ Error OnDiskOutputFile::initializeFile(std::optional
&FD) {
// Not using a temporary file. Open the final output file.
return createDirectoriesOnDemand(OutputPath, Config, [&]() -> Error {
int NewFD;
-sys::fs::OpenFlags OF = sys::fs::OF_None;
-if (Config.getTextWithCRLF())
- OF |= sys::fs::OF_TextWithCRLF;
-else if (Config.getText())
- OF |= sys::fs::OF_Text;
-if (Config.getAppend())
- OF |= sys::fs::OF_Append;
+sys::fs::OpenFlags OF = generateFlagsFromConfig(Config);
if (std::error_code EC = sys::fs::openFileForWrite(
OutputPath, NewFD, sys::fs::CD_CreateAlways, OF))
return convertToOutputError(OutputPath, EC);
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 193e6ef6d1e64..151b59334cab1 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -1123,6 +1123,7 @@ void SystemZAsmPrinter::emitEndOfAsmFile(Module &M) {
: MCSA_Global);
OutStreamer->emitSymbolAttribute(Sym, isa(GO) ? MCSA_Code
: MCSA_Data);
+llvm::dbgs() << "TONY emitting " << Sym->getName() << "\n";
}
}
OutStreamer->switchSection(
@@ -1699,6 +1700,61 @@ void SystemZAsmPrinter::emitPPA2(Module &M) {
OutStreamer->popSection();
}
+void SystemZAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
+ if (TM.getTargetTriple().isOSzOS()) {
+auto *Sym = getSymbol(GV);
+OutStreamer->emitSymbolAttribute(Sym, MCSA_Data);
+ }
+
+ AsmPrinter::emitGlobalVariable(GV);
+}
+
+const MCExpr *SystemZAsmPrinter::lowerConstant(const Constant *CV,
+ const Constant *BaseCV,
+ uint64_t Offset) {
+ const Triple &TargetTriple = TM.getTargetTriple();
+
+ if (TargetTriple.isOSzOS()) {
+const GlobalAlias *GA = dyn_cast(CV);
+const GlobalVariable *GV = dyn_cast(CV);
+const Function *FV = dyn_cast(CV);
+bool IsFunc = !GV && (FV || (GA && isa(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_Code);
+ if (FV->hasExternalLinkage()) {
+return MCSpecifierExpr::create(MCSymbolRefExpr::create(Sym,
Out
[llvm-branch-commits] [clang] [llvm] [GOFF] Implement lowerConstant/emitGlobalVariables/emitGlobalAlias for z/OS (PR #169362)
https://github.com/tltao edited https://github.com/llvm/llvm-project/pull/169362 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
