141 Commits

Author SHA1 Message Date
Kai Nacke
7fd291b400
[GOFF] Set reference to ADA (#179734)
Function symbols must have a reference to the ADA, because this becomes
the value of the r5 register when the function is called. Simply get the
value from the begin symbol of the section.
2026-03-09 13:31:05 -04:00
Amy Kwan
25d709e72c
[SystemZ] Emit external aliases for indirect function descriptors in the ADA section (#183443)
This is the last of the three patches aimed to support indirect symbol
handling for the SystemZ backend.

An external alias is emitted for indirect function descriptors within
the ADA section, rather than a temporary alias, while also setting all
of the appropriate symbol attributes that are needed for the HLASM
streamer to emit the correct XATTR and ALIAS instructions for the
indirect symbols.

Moreover, this patch updates the
`CodeGen/SystemZ/zos-ada-relocations.ll` test as the ADA section is
currently the only user of indirect symbols on z/OS.

Depends on https://github.com/llvm/llvm-project/pull/183442.
2026-02-27 14:02:00 -05:00
Tony Tao
019ecdf7bb
[SystemZ][GOFF] Implement emitGlobalAlias for GOFF/HLASM (#180041)
HLASM has a requirement where aliasing labels need to be emitted at the
same time as the aliasee label, similar to AIX. I used their
implementation for reference with some modifications as we can only
alias functions and we must emit all symbol attributes before the label
is emitted to ensure the XATTR instruction contains the correct
attributes.

---------

Co-authored-by: Tony Tao <tonytao@ca.ibm.com>
2026-02-06 14:49:25 -05:00
Tony Tao
637a038c04
[SystemZ][GOFF] Implement lowerConstant (#179394)
Implement lowerConstants for SystemZ and handle special cases where
entries need to be created in the ADA for static functions or VCon for
externals.

---------

Co-authored-by: Tony Tao <tonytao@ca.ibm.com>
2026-02-04 10:03:34 -05:00
Jonas Paulsson
09f9a2892a
[SystemZ] Bugfix: Add VLR16 to SystemZInstrInfo::copyPhysReg(). (#178932)
Support COPYs involving higher FP16 regs (like F24H) with a new pseudo
instruction 'VLR16'.

This is needed with -O0/regalloc=fast, and probably in more cases as
well.

Fixes #178788.
2026-01-30 14:55:07 -06:00
Dominik Steenken
355898a6ce
[SystemZ] Enable -fpatchable-function-entry=M,N (#178191)
This PR enables the option `-fpatchable-function-entry` for SystemZ. It
utilizes existing common code and just adds the emission of nops after
the function label in the backend.

SystemZ provides multiple nop options of varying length, making the
semantics of this option somewhat ambiguous. In order to align with what
`gcc` does with that same option, we#re choosing `nopr` as the
canoonical nop for this purpose.

For test, this adapts an existing test file from aarch64.
2026-01-28 10:42:54 +01:00
Amy Kwan
41567d8ec2
[SystemZ] Implement ctor/dtor emission via @@SQINIT and .xtor sections (#171476)
This patch implements support for constructors/destructors by
introducing the
`@@SQINIT` section and emitting `.xtor.<priority>` sections within the
SystemZ
AsmPrinter and in the GOFF object lowering layer.
2026-01-23 13:29:08 -05:00
Kai Nacke
5f590ed706
[SystemZ][z/OS] Improve use of formatv (#174503)
Using a `raw_svector_ostream` object is not necessary, because this is
hidden in the conversion function. In addition, there is no need to
reason about a zero termination of the string. Declaring the ascii and
ebcdic version of the string variables at the same time makes sure that
both strings are allocated with the same size.
2026-01-08 09:34:44 -05:00
Amy Kwan
1671bb67e7
[SystemZ] Change default backend to ASCII (#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.
2026-01-07 14:27:25 -05:00
Kai Nacke
611a271e8d
[GOFF] Write out relocations in the GOFF writer (#167054)
Add support for writing relocations. Since the symbol numbering is only
available after the symbols are written, the relocations are collected
in a vector. At write time, the relocations are converted using the
symbols ids, compressed and written out. A relocation data record is
limited to 32K-1 bytes, which requires making sure that larger
relocation data is written into multiple records.
2025-12-20 15:51:46 -05:00
Kai Nacke
37545b80f7
[GOFF] Emit symbols for functions. (#144437)
A function entry is mapped to a LD symbol with an offset to the begin of
the section. HLASM syntax is emitted accordingly.
2025-12-20 13:22:04 -05:00
Kai Nacke
47efff777d
[SystemZ] Emit optional argument area length field (#169679)
The Language Environment (LE) reserves 128 byte for the argument area
when the optional field is not present. If the argument area is larger,
then the field must be present to guarantee that the space is reserved
on stack extension. Creating this field when alloca() is used may reduce
the needed stack space in case alloca() causes a stack extension.
2025-11-26 16:16:13 -05:00
Kai Nacke
ebcf7f91ff
[SystemZ][HLASM] Emit END instruction (#146110)
A HLASM source file must end with the END instruction. It is implemented
by adding a new function to the target streamer. This change also turns
SystemZHLASMSAsmString.h into a proper header file, and only uses the
SystemZTargetHLASMStreamer when HLASM output is generated.
2025-07-02 10:08:25 -04:00
Kai Nacke
33872f1218
[GOFF] Add writing of section symbols (#133799)
Unlike other formats, the GOFF object file format uses a 2 dimensional structure
to define the location of data. For example, the equivalent of the ELF .text
section is made up of a Section Definition (SD) and a class (Element Definition;
ED). The name of the SD symbol depends on the application, while the class has
the predefined name C_CODE/C_CODE64 in AMODE31 and AMODE64 respectively.

Data can be placed into this structure in 2 ways. First, the data (in a text
record) can be associated with an ED symbol. To refer to data, a Label
Definition (LD) is used to give an offset into the data a name. When binding,
the whole data is pulled into the resulting executable, and the addresses
given by the LD symbols are resolved.

The alternative is to use a Part Definition (PR). In this case, the data (in
a text record) is associated with the part. When binding, only the data of
referenced PRs is pulled into the resulting binary.

Both approaches are used. SD, ED, and PR elements are modeled by nested
MCSectionGOFF instances, while LD elements are associated with MCSymbolGOFF
instances.

At the binary level, a record called "External Symbol Definition" (ESD) is used. The
ESD has a type (SD, ED, PR, LD), and depending on the type a different subset of
the fields is used.
2025-06-26 11:52:14 -04:00
Andrew Rogers
19658d1474
[llvm] annotate interfaces in llvm/Target for DLL export (#143615)
## Purpose

This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `llvm/Target` library.
These annotations currently have no meaningful impact on the LLVM build;
however, they are a prerequisite to support an LLVM Windows DLL (shared
library) build.

## Background

This effort is tracked in #109483. Additional context is provided in
[this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307),
and documentation for `LLVM_ABI` and related annotations is found in the
LLVM repo
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst).

A sub-set of these changes were generated automatically using the
[Interface Definition Scanner (IDS)](https://github.com/compnerd/ids)
tool, followed formatting with `git clang-format`.

The bulk of this change is manual additions of `LLVM_ABI` to
`LLVMInitializeX` functions defined in .cpp files under llvm/lib/Target.
Adding `LLVM_ABI` to the function implementation is required here
because they do not `#include "llvm/Support/TargetSelect.h"`, which
contains the declarations for this functions and was already updated
with `LLVM_ABI` in a previous patch. I considered patching these files
with `#include "llvm/Support/TargetSelect.h"` instead, but since
TargetSelect.h is a large file with a bunch of preprocessor x-macro
stuff in it I was concerned it would unnecessarily impact compile times.

In addition, a number of unit tests under llvm/unittests/Target required
additional dependencies to make them build correctly against the LLVM
DLL on Windows using MSVC.

## Validation

Local builds and tests to validate cross-platform compatibility. This
included llvm, clang, and lldb on the following configurations:

- Windows with MSVC
- Windows with Clang
- Linux with GCC
- Linux with Clang
- Darwin with Clang
2025-06-17 13:28:45 -07:00
Fangrui Song
b591f6dad4 SystemZ: Migrate to newer relocation specifier representation
z/OS creates SystemZMCExpr objects (https://reviews.llvm.org/D153788)
while ELF doesn't. Define the SystemZMCAsmInfoGOFF hooks
instead of the legacy MCSpecifierExpr:: hooks.
2025-06-15 19:26:40 -07:00
Fangrui Song
cf679e66fa SystemZ: Rename SystemZMCExpr::VK_ to SystemZ::S_
Prepare for removing SystemZMCExpr. Adopt the newer naming convention
used by most other targets.
2025-06-15 18:59:16 -07:00
Fangrui Song
a7e5de4723 SystemZ: Replace deprecated MCExpr::print with MCAsmInfo::printExpr 2025-06-15 17:23:13 -07:00
Matthias Braun
675cb70641
Register assembly printer passes (#138348)
Register assembly printer passes in the pass registry.

This makes it possible to use `llc -start-before=<target>-asm-printer ...` in tests.

Adds a `char &ID` parameter to the AssemblyPrinter constructor to allow
targets to use the `INITIALIZE_PASS` macros and register the pass in the
pass registry. This currently has a default parameter so it won't break
any targets that have not been updated.
2025-05-06 18:01:17 -07:00
Jonas Paulsson
6d03f51f0c
[SystemZ] Add support for 16-bit floating point. (#109164)
- _Float16 is now accepted by Clang.

- The half IR type is fully handled by the backend.

- These values are passed in FP registers and converted to/from float around
  each operation.

- Compiler-rt conversion functions are now built for s390x including the missing
  extendhfdf2 which was added.

Fixes #50374
2025-04-16 20:02:56 +02:00
Fangrui Song
b19b6d9fab Move SystemZ-specific MCSymbolRefExpr::VariantKind to SystemZMCExpr::Specifier
Similar to previous migration done for other targets (PowerPC, X86, ARM,
etc). Switch from the confusing VariantKind to Specifier, which aligns
with Arm and IBM AIX's documentation.

In addition, rename *MCExpr::getKind, which confusingly shadows the base class getKind.

In the future, relocation specifiers should be encoded as part of
SystemZMCExpr instead of MCSymbolRefExpr.
2025-03-22 18:05:40 -07:00
Fangrui Song
687854aea8 [MC] Remove unneeded VK_None argument from MCSymbolRefExpr::create. NFC 2025-03-06 00:00:05 -08:00
Kazu Hirata
c9686d6904
[SystemZ] Avoid repeated hash lookups (NFC) (#126679) 2025-02-11 09:09:04 -08:00
anoopkg6
dc04d414df
SystemZ: Add support for __builtin_setjmp and __builtin_longjmp. (#119257)
This pr includes fixes for original pr##116642.
Implementation for __builtin_setjmp and __builtin_longjmp for SystemZ..
2024-12-10 19:50:51 +01:00
Ulrich Weigand
8787bc72a6 Revert "[SystemZ] Add support for __builtin_setjmp and __builtin_longjmp (#116642)"
This reverts commit 030bbc92a705758f1131fb29cab5be6d6a27dd1f.
2024-12-07 00:55:54 +01:00
anoopkg6
030bbc92a7
[SystemZ] Add support for __builtin_setjmp and __builtin_longjmp (#116642)
Implementation for __builtin_setjmp and __builtin_longjmp for SystemZ.
2024-12-06 23:33:33 +01:00
Kazu Hirata
ed8019d9fb
[Target] Remove unused includes (NFC) (#116577)
Identified with misc-include-cleaner.
2024-11-18 07:19:50 -08:00
Kai Nacke
4a37799a48
[SystemZ][XRay] Implement XRay instrumentation for SystemZ (#113253)
Expands pseudo instructions PATCHABLE_FUNCTION_ENTER and PATCHABLE_RET
into a small instruction sequence which calls into the XRay library.
2024-11-05 15:42:55 -05:00
tltao
6512a8dd8c
[SystemZ] Split SystemZInstPrinter to two classes based on Asm dialect (#112975)
In preparation for future work on separating the output of the GNU/HLASM
ASM dialects, we first separate the SystemZInstPrinter classes to two
versions, one for each ASM dialect.

The common code remains in a SystemZInstPrinterCommon class instead.

---------

Co-authored-by: Tony Tao <tonytao@ca.ibm.com>
2024-10-22 10:28:57 -04:00
tltao
bc747c3e13
[SystemZ][z/OS] Fix incorrect codegen for ADA_ENTRY pseudo instruction (#101415)
The current MCInstBuilder for generating an ALGFI when loading something
from the ADA is incorrect and will crash the compiler.

r0 must also be excluded from the registers returned as the result,
since it is treated as the value "0" on z/OS.

Also add some tests to properly test the paths where LLILF and ALGFI are
generated.

---------

Co-authored-by: Tony Tao <tonytao@ca.ibm.com>
2024-08-01 13:23:49 -04:00
Nikita Popov
4169338e75
[IR] Don't include Module.h in Analysis.h (NFC) (#97023)
Replace it with a forward declaration instead. Analysis.h is pulled in
by all passes, but not all passes need to access the module.
2024-06-28 14:30:47 +02:00
Neumann Hon
eccc71783c
[SystemZ] [z/OS] Emit offset to PPA2 in separate MCSection (#84043)
The ppa2list section isn't really part of the ppa2 section. The ppa2list
section contains the offset to the ppa2, and must be created with a
special section name (specifically, C_@@QPPA2). The binder searches for
a section with this name, then uses this value to locate the ppa2.

In GOFF terms, these are entirely separate sections; the PPA2 section
isn't even really a section but rather belongs to the code section. On
the other hand, the ppa2list section is a section in its own right and
resides in a separate TXT record.
2024-03-05 15:29:07 -05:00
Ilya Leoshkevich
9c75a98155
[SystemZ] Implement A, O and R inline assembly format flags (#80685)
Implement the following assembly format flags, which are already
supported by GCC:

	'A': On z14 or higher: If operand is a mem print the alignment
         hint usable with vl/vst prefixed by a comma.
	'O': print only the displacement of a memory reference or address.
	'R': print only the base register of a memory reference or address.

Implement 'A' conservatively, since the memory operand alignment
information is not available for INLINEASM at the moment.
2024-02-07 20:41:40 +01:00
Yusra Syeda
0768253c20
[SystemZ][z/OS] Add exception handling for XPLINK (#74638)
Adds emitting the exception table and the EH registers for XPLINK.

---------

Co-authored-by: Yusra Syeda <yusra.syeda@ibm.com>
2023-12-19 13:58:33 -05:00
Ulrich Weigand
901e484fda [SystemZ] Handle index-only addresses in (dis)assembler
Most addresses in SystemZ instructions take two registers,
an index register and a base register.  However, either of
those can be omitted.  If there is just a single register,
this usually is taken as the base register - however, there
are certain rare cases where you specifically want to use
an index register but no base register.  This is currently
not handled consistently by the assembler / disassembler.

Fix this by
 - always emitting a dummy 0 as base register for index-
   only addresses
 - correctly handle dummy 0 as indicating no base register
   when parsing an address

This is compatible with current GNU binutils behavior.
2023-12-04 17:03:00 +01:00
Yusra Syeda
9a38a72f1d
[SystemZ][z/OS] This change adds support for the PPA2 section in zOS (#68926)
This PR adds support for the PPA2 fields.

---------

Co-authored-by: Yusra Syeda <yusra.syeda@ibm.com>
2023-11-27 16:30:12 -05:00
Neumann Hon
d00f59893e [SystemZ][z/OS] Fix the entry point marker for leaf functions
The function emitFunctionEntryLabel does not look at whether or not a function is a leaf when setting the entry flags, and instead blindly marks all functions as non-leaf routines.

Differential Revision: https://reviews.llvm.org/D157701

Reviewed By: uweigand
2023-08-23 09:50:01 -04:00
Neumann Hon
43207225b6 Revert "[SystemZ][z/OS] Fix the entry point marker for leaf functions"
This reverts commit 8af297bbb8e97de8908b857eae1a44f46a0d5afe.

Testcase LLVM :: MC/GOFF/ppa1.ll needs to be updated to account for this.
2023-08-20 22:04:02 -04:00
Neumann Hon
8af297bbb8 [SystemZ][z/OS] Fix the entry point marker for leaf functions
The function emitFunctionEntryLabel does not look at whether or not a function is a leaf when setting the entry flags,
and instead blindly marks all functions as non-leaf routines. Change it to check if a function is a leaf function and
mark it accordingly.
2023-08-20 21:53:13 -04:00
Neumann Hon
3e139be29f [SystemZ][z/OS] Add support for function name field of PPA1
This PR causes the PPA1 to emit the function's name if it exists. This field is not emitted for unnamed functions.

Reviewed By: uweigand

Differential Revision: https://reviews.llvm.org/D157494
2023-08-10 04:40:19 -04:00
Yusra Syeda
c2964a597d [SystemZ][z/OS] Address single comment in ADA patch for EmittedBytes unused in -Asserts 2023-07-06 12:01:53 -04:00
Yusra Syeda
163aad6bcb [SystemZ][z/OS] z/OS ADA codegen and emission
This patch adds support for the ADA (associated data area), doing the following:

-Creates the ADA table to handle displacements
-Emits the ADA section in the SystemZAsmPrinter
-Lowers the ADA_ENTRY node into the appropriate load instruction

Differential Revision: https://reviews.llvm.org/D153788
2023-07-05 13:21:52 -04:00
Yusra Syeda
1bfdc534aa Revert "[SystemZ][z/OS] This patch adds support for the ADA (associated data area), doing the following:"
This reverts commit 9df0f66af5462e23216eae31aedbd4d2f459cc3d.
2023-06-28 11:18:12 -04:00
Yusra Syeda
9df0f66af5 [SystemZ][z/OS] This patch adds support for the ADA (associated data area), doing the following:
- Creates the ADA table to handle displacements
- Emits the ADA section in the SystemZAsmPrinter
- Lowers the ADA_ENTRY node into the appropriate load instruction

Differential Revision: https://reviews.llvm.org/D153788
2023-06-28 10:13:10 -04:00
Elliot Goodrich
b0abd4893f [llvm] Add missing StringExtras.h includes
In preparation for removing the `#include "llvm/ADT/StringExtras.h"`
from the header to source file of `llvm/Support/Error.h`, first add in
all the missing includes that were previously included transitively
through this header.
2023-06-25 15:42:22 +01:00
Neumann Hon
8a7a2da18f [SystemZ][z/OS] Correct value of length/4 of params field in PPA1.
The Length/4 of Params field in the PPA1 ought to be the length of the parameters for the current function. Currently we are storing the length of the parameter area in the current function's stack frame, which represents the length of the params of the longest callee in the current function.

Differential Revision: https://reviews.llvm.org/D152920

Reviewed By: uweigand
2023-06-14 13:37:46 -04:00
Neumann Hon
049324ac5e Revert "[SystemZ][z/OS] Correct value of length/4 of params field in PPA1."
This reverts commit e0f7b0e0f704dc3759925602e474b9e669270fcb.
2023-06-14 13:34:16 -04:00
Neumann Hon
e0f7b0e0f7 [SystemZ][z/OS] Correct value of length/4 of params field in PPA1.
The Length/4 of Params field in the PPA1 ought to be the length of the parameters for the current function. Currently we are storing the length of the parameter area in the current function's stack frame, which represents the length of the params of the longest callee in the current function.

Differential revision: https://reviews.llvm.org/D119049

Reviewed By: uweigand
2023-06-14 13:20:45 -04:00
Fangrui Song
432caca39a Simplify with hasFeature. NFC 2023-02-17 18:22:24 -08:00
Philip Reames
eb44226986 [CodeGen] Introduce a generic MEMBARRIER instruction [mostly-nfc]
This is a follow up to D141317 which extends the common code to include a target independent pseudo instruction. This is an alternative to (subset of) D92842 which tries to be as close to NFC as possible.

A couple things to call out.
* The test change in X86 is because we loose the scheduling information on the instruction. However, I think this was actually a bug in x86 since no instruction was emitted for a MEMBARRIER. Concluding that a meta instruction has latency just seems wrong?
* I intentionally left some parts of D92842 out. Specifically, several of the changes in the X86 code (data independence and outlining) appear functional, and likely worthy of their own review. Additionally, I'm not handling ARM/AArch64 at all. Those targets need the ordering whereas none of the others do. I want to get this in and tested before retrofitting in ordering to support those targets.

Differential Revision: https://reviews.llvm.org/D141408
2023-01-11 07:26:27 -08:00