[all-commits] [llvm/llvm-project] 083b4a: [SystemZ] Add proper mcount handling (#135767)

Dominik Steenken via All-commits all-commits at lists.llvm.org
Fri May 2 03:43:19 PDT 2025


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 083b4a3d66c2d3e87b9b35104b59e07a004b5d3e
      https://github.com/llvm/llvm-project/commit/083b4a3d66c2d3e87b9b35104b59e07a004b5d3e
  Author: Dominik Steenken <dost at de.ibm.com>
  Date:   2025-05-02 (Fri, 02 May 2025)

  Changed paths:
    M llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
    M llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp
    A llvm/test/CodeGen/SystemZ/mcount.ll

  Log Message:
  -----------
  [SystemZ] Add proper mcount handling (#135767)

When compiling with `-pg`, the `EntryExitInstrumenterPass` will insert
calls to the glibc function `mcount` at the begining of each
`MachineFunction`.

On SystemZ, these calls require special handling:

- The call to `mcount` needs to happen at the beginning of the prologue.
- Prior to the call to `mcount`, register `%r14`, the return address of
the callee function, must be stored 8 bytes above the stack pointer
`%r15`. After the call to `mcount` returns, that register needs to be
restored.

This commit adds some special handling to the EntryExitInstrumenterPass
that keeps the insertion of the mcount function into the module, but
skips over insertion of the actual call in order to perform this
insertion in the `emitPrologue` function. There, a simple sequence of
store/call/load is inserted, which implements the above.

The desired change in the `EntryExitInstrumenterPass` necessitated the
addition of a new attribute and attribute kind to each function, which
is used to trigger the postprocessing, aka call insertion, in
`emitPrologue`. Note that the new attribute must be of a different kind
than the `mcount` atribute, since otherwise it would replace that
attribute and later be deleted by the code that intended to delete
`mcount`. The new attribnute is called `insert-mcount`, while the
attribute kind is `systemz-backend`, to clearly mark it as a
SystemZ-specific backend concern.

This PR should address issue #121137 . The test inserted here is derived
from the example given in that issue.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list