1717#include " llvm/CodeGen/MachineRegisterInfo.h"
1818#include " llvm/CodeGen/RegisterScavenging.h"
1919#include " llvm/CodeGen/TargetLoweringObjectFileImpl.h"
20+ #include " llvm/IR/CallingConv.h"
2021#include " llvm/IR/Function.h"
2122#include " llvm/IR/Module.h"
2223#include " llvm/Target/TargetMachine.h"
@@ -558,10 +559,10 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction &MF,
558559 // Debug location must be unknown since the first debug location is used
559560 // to determine the end of the prologue.
560561 DebugLoc DL;
561-
562562 // Add mcount instrumentation if necessary.
563- if (MF.getFunction ().getFnAttribute (" systemz-backend" ).getValueAsString () ==
564- " insert-mcount" ) {
563+ if (MF.getFunction ()
564+ .getFnAttribute (" systemz-instrument-function-entry" )
565+ .getValueAsString () == " mcount" ) {
565566
566567 // Store return address 8 bytes above stack pointer.
567568 BuildMI (MBB, MBBI, DL, ZII->get (SystemZ::STG))
@@ -570,12 +571,16 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction &MF,
570571 .addImm (8 )
571572 .addReg (0 );
572573
573- // Call mcount (Regmask 0 to ensure this will not be moved by the
574- // scheduler.).
575- const uint32_t Mask = 0 ;
574+ // Call mcount (Regmask from CC AnyReg since mcount preserves all normal
575+ // argument registers.
576+ FunctionCallee FC = MF.getFunction ().getParent ()->getOrInsertFunction (
577+ " mcount" , Type::getVoidTy (MF.getFunction ().getContext ()));
578+ const uint32_t *Mask = MF.getSubtarget <SystemZSubtarget>()
579+ .getSpecialRegisters ()
580+ ->getCallPreservedMask (MF, CallingConv::AnyReg);
576581 BuildMI (MBB, MBBI, DL, ZII->get (SystemZ::CallBRASL))
577- .addGlobalAddress (MF. getFunction (). getParent ()-> getFunction ( " mcount " ))
578- .addRegMask (& Mask);
582+ .addGlobalAddress (dyn_cast<Function>(FC. getCallee () ))
583+ .addRegMask (Mask);
579584
580585 // Reload return address drom 8 bytes above stack pointer.
581586 BuildMI (MBB, MBBI, DL, ZII->get (SystemZ::LG))
0 commit comments