17
17
#include " llvm/CodeGen/MachineRegisterInfo.h"
18
18
#include " llvm/CodeGen/RegisterScavenging.h"
19
19
#include " llvm/CodeGen/TargetLoweringObjectFileImpl.h"
20
+ #include " llvm/IR/CallingConv.h"
20
21
#include " llvm/IR/Function.h"
21
22
#include " llvm/IR/Module.h"
22
23
#include " llvm/Target/TargetMachine.h"
@@ -558,10 +559,10 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction &MF,
558
559
// Debug location must be unknown since the first debug location is used
559
560
// to determine the end of the prologue.
560
561
DebugLoc DL;
561
-
562
562
// 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" ) {
565
566
566
567
// Store return address 8 bytes above stack pointer.
567
568
BuildMI (MBB, MBBI, DL, ZII->get (SystemZ::STG))
@@ -570,12 +571,16 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction &MF,
570
571
.addImm (8 )
571
572
.addReg (0 );
572
573
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);
576
581
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);
579
584
580
585
// Reload return address drom 8 bytes above stack pointer.
581
586
BuildMI (MBB, MBBI, DL, ZII->get (SystemZ::LG))
0 commit comments