From 9586e1afae73ba67b290dc32e2d309131a9b62b4 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Mon, 24 Nov 2025 14:48:42 -0500 Subject: [PATCH 1/3] [SystemZ] Serialize ada entry flags Adding support for serializing the ada entry flags helps with mir based test cases. Without this change, the flags are simple displayed as being "unkmown". --- llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp | 16 ++++++++++++++++ llvm/lib/Target/SystemZ/SystemZInstrInfo.h | 6 ++++++ llvm/test/CodeGen/SystemZ/zos-target-flags.ll | 17 +++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 llvm/test/CodeGen/SystemZ/zos-target-flags.ll diff --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp index eb1ce4a2101d7..db4f9a15d6497 100644 --- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp +++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.cpp @@ -2360,3 +2360,19 @@ SystemZInstrInfo::isCopyInstrImpl(const MachineInstr &MI) const { return std::nullopt; } + +std::pair +SystemZInstrInfo::decomposeMachineOperandsTargetFlags(unsigned TF) const { + return std::make_pair(TF, 0u); +} + +ArrayRef> +SystemZInstrInfo::getSerializableDirectMachineOperandTargetFlags() const { + using namespace SystemZII; + + static const std::pair TargetFlags[] = { + {MO_ADA_DATA_SYMBOL_ADDR, "systemz-ada-datasymboladdr"}, + {MO_ADA_INDIRECT_FUNC_DESC, "systemz-ada-indirectfuncdesc"}, + {MO_ADA_DIRECT_FUNC_DESC, "systemz-ada-directfuncdesc"}}; + return ArrayRef(TargetFlags); +} diff --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.h b/llvm/lib/Target/SystemZ/SystemZInstrInfo.h index 4aecdd7498018..ba42aa6e10a59 100644 --- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.h +++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.h @@ -391,6 +391,12 @@ class SystemZInstrInfo : public SystemZGenInstrInfo { std::optional isCopyInstrImpl(const MachineInstr &MI) const override; + + std::pair + decomposeMachineOperandsTargetFlags(unsigned TF) const override; + + ArrayRef> + getSerializableDirectMachineOperandTargetFlags() const override; }; } // end namespace llvm diff --git a/llvm/test/CodeGen/SystemZ/zos-target-flags.ll b/llvm/test/CodeGen/SystemZ/zos-target-flags.ll new file mode 100644 index 0000000000000..968337d87811d --- /dev/null +++ b/llvm/test/CodeGen/SystemZ/zos-target-flags.ll @@ -0,0 +1,17 @@ +; RUN: llc -mtriple=s390x-ibm-zos -stop-after=systemz-isel --simplify-mir < %s | FileCheck %s + + +declare i64 @calc(i64 noundef, ptr noundef) +declare i64 @morework(i64 noundef) + +@i = external local_unnamed_addr global i64, align 8 + +define i64 @work() { +entry: +; CHECK: %{{.*}}:addr64bit = ADA_ENTRY_VALUE target-flags(systemz-ada-datasymboladdr) @i, +; CHECK: %{{.*}}:addr64bit = ADA_ENTRY_VALUE target-flags(systemz-ada-directfuncdesc) @calc, +; CHECK: %{{.*}}:addr64bit = ADA_ENTRY_VALUE target-flags(systemz-ada-indirectfuncdesc) @morework, + %0 = load i64, ptr @i, align 8 + %call = tail call i64 @calc(i64 noundef %0, ptr noundef nonnull @morework) #2 + ret i64 %call +} From 879f6c59a0e295951b2576313473b0db1d03e80c Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Wed, 26 Nov 2025 13:39:36 -0500 Subject: [PATCH 2/3] Change enum values to be distinct from Linux on Z flags. --- llvm/lib/Target/SystemZ/SystemZInstrInfo.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.h b/llvm/lib/Target/SystemZ/SystemZInstrInfo.h index ba42aa6e10a59..b5c6fea485fc1 100644 --- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.h +++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.h @@ -76,13 +76,11 @@ enum { // z/OS XPLink specific: classifies the types of // accesses to the ADA (Associated Data Area). -// These enums contains values that overlap with the above MO_ enums, -// but that's fine since the above enums are used with ELF, -// while these values are used with z/OS. +// These enum values should not overlap with the above MO_ enums. enum { - MO_ADA_DATA_SYMBOL_ADDR = 1, - MO_ADA_INDIRECT_FUNC_DESC, - MO_ADA_DIRECT_FUNC_DESC, + MO_ADA_DATA_SYMBOL_ADDR = (1 << 2), + MO_ADA_INDIRECT_FUNC_DESC = (2 << 2), + MO_ADA_DIRECT_FUNC_DESC = (3 << 2), }; // Classifies a branch. From 7bcd815bfb6241eaa866fb453578e6b71ce129a9 Mon Sep 17 00:00:00 2001 From: Kai Nacke Date: Wed, 26 Nov 2025 16:19:00 -0500 Subject: [PATCH 3/3] Join the 2 enums --- llvm/lib/Target/SystemZ/SystemZInstrInfo.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/llvm/lib/Target/SystemZ/SystemZInstrInfo.h b/llvm/lib/Target/SystemZ/SystemZInstrInfo.h index b5c6fea485fc1..9fadf7bfb6d2b 100644 --- a/llvm/lib/Target/SystemZ/SystemZInstrInfo.h +++ b/llvm/lib/Target/SystemZ/SystemZInstrInfo.h @@ -71,13 +71,10 @@ enum { MO_GOT = (1 << 0), // @INDNTPOFF - MO_INDNTPOFF = (2 << 0) -}; + MO_INDNTPOFF = (2 << 0), -// z/OS XPLink specific: classifies the types of -// accesses to the ADA (Associated Data Area). -// These enum values should not overlap with the above MO_ enums. -enum { + // z/OS XPLink specific: classifies the types of + // accesses to the ADA (Associated Data Area). MO_ADA_DATA_SYMBOL_ADDR = (1 << 2), MO_ADA_INDIRECT_FUNC_DESC = (2 << 2), MO_ADA_DIRECT_FUNC_DESC = (3 << 2),