[llvm] [SystemZ] Add proper mcount handling (PR #135767)

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 25 06:27:38 PDT 2025


================
@@ -558,6 +559,32 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction &MF,
   // to determine the end of the prologue.
   DebugLoc DL;
 
+  // Add mcount instrumentation if necessary.
+  if (MF.getFunction().getFnAttribute("systemz-backend").getValueAsString() ==
+      "insert-mcount") {
+
+    // Store return address 8 bytes above stack pointer.
+    BuildMI(MBB, MBBI, DL, ZII->get(SystemZ::STG))
+        .addReg(SystemZ::R14D)
+        .addReg(SystemZ::R15D)
+        .addImm(8)
+        .addReg(0);
+
+    // Call mcount (Regmask 0 to ensure this will not be moved by the
+    // scheduler.).
----------------
uweigand wrote:

Is this regmask 0 really necessary?  The memory access patterns should already prevent moving this call.  In general, it would be preferable to model the special mcount ABI correctly (i.e. mcount preserves *more* registers than the normal ABI, not less).

https://github.com/llvm/llvm-project/pull/135767


More information about the llvm-commits mailing list