[llvm] [SystemZ] Change default backend to ASCII (PR #174470)
Amy Kwan via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 5 11:56:02 PST 2026
https://github.com/amy-kwan created https://github.com/llvm/llvm-project/pull/174470
The current (and default) backend on z/OS is EBCDIC.
This patch updates the default backend to be ASCII, which is beneficial when porting new languages. With this change, ASCII is the default when no special metadata nodes (such as `zos_le_char_mode`) are present.
>From 37f8caf7e237b0c10033db4a602585ee041f3be1 Mon Sep 17 00:00:00 2001
From: Amy Kwan <amy.kwan1 at ibm.com>
Date: Sat, 3 Jan 2026 00:58:08 -0500
Subject: [PATCH] [SystemZ] Change default backend to ASCII
The current (and default) backend on z/OS is EBCDIC. This patch updates the
default backend to be ASCII, which is beneficial when porting new languages.
With this change, ASCII is the default when no special metadata nodes
(such as `zos_le_char_mode`) are present.
---
llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp | 17 +++++++++--------
llvm/test/CodeGen/SystemZ/zos-hlasm-out.ll | 3 +++
llvm/test/CodeGen/SystemZ/zos-ppa2.ll | 14 ++++++++++++--
3 files changed, 24 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
index 444bc578a3fab..6aa6af0b6cd9a 100644
--- a/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZAsmPrinter.cpp
@@ -1668,17 +1668,18 @@ void SystemZAsmPrinter::emitPPA2(Module &M) {
uint8_t Flgs = static_cast<uint8_t>(PPA2Flags::CompileForBinaryFloatingPoint);
Flgs |= static_cast<uint8_t>(PPA2Flags::CompiledWithXPLink);
+ bool IsASCII = true;
if (auto *MD = M.getModuleFlag("zos_le_char_mode")) {
const StringRef &CharMode = cast<MDString>(MD)->getString();
- if (CharMode == "ascii") {
- Flgs |= static_cast<uint8_t>(
- PPA2Flags::CompiledUnitASCII); // Setting bit for ASCII char. mode.
- } else if (CharMode != "ebcdic") {
- report_fatal_error(
- "Only ascii or ebcdic are valid values for zos_le_char_mode "
- "metadata");
- }
+ if (CharMode == "ebcdic")
+ IsASCII = false;
+ else if (CharMode != "ascii")
+ OutContext.reportError(
+ {}, "Only ascii or ebcdic are allowed for zos_le_char_mode");
}
+ if (IsASCII)
+ Flgs |= static_cast<uint8_t>(
+ PPA2Flags::CompiledUnitASCII); // Setting bit for ASCII char. mode.
OutStreamer->emitInt8(Flgs);
OutStreamer->emitInt8(0x00); // Reserved.
diff --git a/llvm/test/CodeGen/SystemZ/zos-hlasm-out.ll b/llvm/test/CodeGen/SystemZ/zos-hlasm-out.ll
index a82be947f8deb..4415cbfee833d 100644
--- a/llvm/test/CodeGen/SystemZ/zos-hlasm-out.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-hlasm-out.ll
@@ -58,3 +58,6 @@ entry:
}
declare void @outs(ptr noundef, ...)
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"zos_le_char_mode", !"ebcdic"}
diff --git a/llvm/test/CodeGen/SystemZ/zos-ppa2.ll b/llvm/test/CodeGen/SystemZ/zos-ppa2.ll
index 8f3847da32e31..bf059f9083df0 100644
--- a/llvm/test/CodeGen/SystemZ/zos-ppa2.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-ppa2.ll
@@ -1,4 +1,10 @@
-; RUN: llc -mtriple s390x-ibm-zos -mcpu=z15 -asm-verbose=true < %s | FileCheck %s
+; RUN: sed -e 's/!"MODE"/!"ascii"/' -e 's/BYTE/133/' %s > %t.ascii.ll
+; RUN: llc -mtriple s390x-ibm-zos -mcpu=z15 -asm-verbose=true < %t.ascii.ll | \
+; RUN: FileCheck %t.ascii.ll
+
+; RUN: sed -e 's/!"MODE"/!"ebcdic"/' -e 's/BYTE/129/' %s > %t.ebcdic.ll
+; RUN: llc -mtriple s390x-ibm-zos -mcpu=z15 -asm-verbose=true < %t.ebcdic.ll | \
+; RUN: FileCheck %t.ebcdic.ll
; CHECK: C_CODE64 CATTR
; CHECK: L#PPA2:
@@ -10,7 +16,7 @@
; CHECK: .long 0
; CHECK: .long L#DVS-L#PPA2
; CHECK: .long 0
-; CHECK: .byte 129
+; CHECK: .byte BYTE
; CHECK: .byte 0
; CHECK: .short 0
; CHECK: L#DVS:
@@ -24,6 +30,10 @@
; CHECK: .byte 3
; CHECK: .short 30
; CHECK: .ascii "\323\323\345\324@@@@@@{{((\\3[0-7]{2}){4})}}\361\371\367\360\360\361\360\361\360\360\360\360\360\360\360\360"
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"zos_le_char_mode", !"MODE"}
+
define void @void_test() {
entry:
ret void
More information about the llvm-commits
mailing list