Skip to content

Commit 77f2ba0

Browse files
Implement review suggestions
1 parent cab34b1 commit 77f2ba0

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
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))

llvm/lib/Transforms/Utils/EntryExitInstrumenter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,10 @@ static void insertCall(Function &CurFn, StringRef Func,
6464
CallInst *Call = CallInst::Create(Fn, RetAddr, "", InsertionPt);
6565
Call->setDebugLoc(DL);
6666
} else if (TargetTriple.isSystemZ()) {
67-
M.getOrInsertFunction(Func, Type::getVoidTy(C));
6867
// skip insertion for `mcount` on SystemZ. This will be handled later in
6968
// `emitPrologue`. Add custom attribute to denote this.
7069
CurFn.addFnAttr(
71-
llvm::Attribute::get(C, "systemz-backend", "insert-mcount"));
70+
llvm::Attribute::get(C, "systemz-instrument-function-entry", Func));
7271
} else {
7372
FunctionCallee Fn = M.getOrInsertFunction(Func, Type::getVoidTy(C));
7473
CallInst *Call = CallInst::Create(Fn, "", InsertionPt);

0 commit comments

Comments
 (0)