[llvm] 588ecc1 - AArch64: Stop storing MachineFunction in MachineFunctionInfo
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 16 09:30:07 PST 2022
Author: Matt Arsenault
Date: 2022-12-16T12:30:03-05:00
New Revision: 588ecc11b8959b716cc5337a03064046eddb3a29
URL: https://github.com/llvm/llvm-project/commit/588ecc11b8959b716cc5337a03064046eddb3a29
DIFF: https://github.com/llvm/llvm-project/commit/588ecc11b8959b716cc5337a03064046eddb3a29.diff
LOG: AArch64: Stop storing MachineFunction in MachineFunctionInfo
The constructor should not depend on the MachineFunction
Added:
Modified:
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
index 7c969498c2f9..e4814612e768 100644
--- a/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
@@ -606,7 +606,7 @@ void AArch64FrameLowering::resetCFIToInitialState(
BuildMI(MBB, InsertPt, DL, CFIDesc).addCFIIndex(CFIIndex);
// Flip the RA sign state.
- if (MFI.shouldSignReturnAddress()) {
+ if (MFI.shouldSignReturnAddress(MF)) {
CFIIndex = MF.addFrameInst(MCCFIInstruction::createNegateRAState(nullptr));
BuildMI(MBB, InsertPt, DL, CFIDesc).addCFIIndex(CFIIndex);
}
@@ -1355,7 +1355,7 @@ static void emitShadowCallStackEpilogue(const TargetInstrInfo &TII,
.addImm(-8)
.setMIFlag(MachineInstr::FrameDestroy);
- if (MF.getInfo<AArch64FunctionInfo>()->needsAsyncDwarfUnwindInfo()) {
+ if (MF.getInfo<AArch64FunctionInfo>()->needsAsyncDwarfUnwindInfo(MF)) {
unsigned CFIIndex =
MF.addFrameInst(MCCFIInstruction::createRestore(nullptr, 18));
BuildMI(MBB, MBBI, DL, TII.get(TargetOpcode::CFI_INSTRUCTION))
@@ -1374,7 +1374,7 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
MachineModuleInfo &MMI = MF.getMMI();
AArch64FunctionInfo *AFI = MF.getInfo<AArch64FunctionInfo>();
- bool EmitCFI = AFI->needsDwarfUnwindInfo();
+ bool EmitCFI = AFI->needsDwarfUnwindInfo(MF);
bool HasFP = hasFP(MF);
bool NeedsWinCFI = needsWinCFI(MF);
bool HasWinCFI = false;
@@ -1394,9 +1394,9 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
const auto &MFnI = *MF.getInfo<AArch64FunctionInfo>();
if (needsShadowCallStackPrologueEpilogue(MF))
emitShadowCallStackPrologue(*TII, MF, MBB, MBBI, DL, NeedsWinCFI,
- MFnI.needsDwarfUnwindInfo());
+ MFnI.needsDwarfUnwindInfo(MF));
- if (MFnI.shouldSignReturnAddress()) {
+ if (MFnI.shouldSignReturnAddress(MF)) {
unsigned PACI;
if (MFnI.shouldSignWithBKey()) {
BuildMI(MBB, MBBI, DL, TII->get(AArch64::EMITBKEY))
@@ -1868,7 +1868,7 @@ void AArch64FrameLowering::emitPrologue(MachineFunction &MF,
static void InsertReturnAddressAuth(MachineFunction &MF, MachineBasicBlock &MBB,
bool NeedsWinCFI, bool *HasWinCFI) {
const auto &MFI = *MF.getInfo<AArch64FunctionInfo>();
- if (!MFI.shouldSignReturnAddress())
+ if (!MFI.shouldSignReturnAddress(MF))
return;
const AArch64Subtarget &Subtarget = MF.getSubtarget<AArch64Subtarget>();
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
@@ -1928,7 +1928,8 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
const TargetInstrInfo *TII = Subtarget.getInstrInfo();
DebugLoc DL;
bool NeedsWinCFI = needsWinCFI(MF);
- bool EmitCFI = MF.getInfo<AArch64FunctionInfo>()->needsAsyncDwarfUnwindInfo();
+ bool EmitCFI =
+ MF.getInfo<AArch64FunctionInfo>()->needsAsyncDwarfUnwindInfo(MF);
bool HasWinCFI = false;
bool IsFunclet = false;
auto WinCFI = make_scope_exit([&]() { assert(HasWinCFI == MF.hasWinCFI()); });
@@ -3744,11 +3745,11 @@ MachineBasicBlock::iterator tryMergeAdjacentSTG(MachineBasicBlock::iterator II,
EndOffset = Instr.Offset + Instr.Size;
}
+ const MachineFunction *MF = MBB->getParent();
// Multiple FP/SP updates in a loop cannot be described by CFI instructions.
- TSE.emitCode(InsertI, TFI, /*TryMergeSPUpdate = */
- !MBB->getParent()
- ->getInfo<AArch64FunctionInfo>()
- ->needsAsyncDwarfUnwindInfo());
+ TSE.emitCode(
+ InsertI, TFI, /*TryMergeSPUpdate = */
+ !MF->getInfo<AArch64FunctionInfo>()->needsAsyncDwarfUnwindInfo(*MF));
return InsertI;
}
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index d6f926d6a019..c0a8754a9cf8 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -7843,7 +7843,7 @@ static void signOutlinedFunction(MachineFunction &MF, MachineBasicBlock &MBB,
.addReg(AArch64::SP, RegState::InternalRead);
MI.setMIFlag(MachineInstr::FrameSetup);
- if (MF.getInfo<AArch64FunctionInfo>()->needsDwarfUnwindInfo()) {
+ if (MF.getInfo<AArch64FunctionInfo>()->needsDwarfUnwindInfo(MF)) {
unsigned CFIIndex =
MF.addFrameInst(MCCFIInstruction::createNegateRAState(nullptr));
BuildMI(MBB, MBBPAC, DebugLoc(), TII->get(AArch64::CFI_INSTRUCTION))
@@ -7942,7 +7942,7 @@ void AArch64InstrInfo::buildOutlinedFrame(
.addImm(-16);
It = MBB.insert(It, STRXpre);
- if (MF.getInfo<AArch64FunctionInfo>()->needsDwarfUnwindInfo()) {
+ if (MF.getInfo<AArch64FunctionInfo>()->needsDwarfUnwindInfo(MF)) {
const TargetSubtargetInfo &STI = MF.getSubtarget();
const MCRegisterInfo *MRI = STI.getRegisterInfo();
unsigned DwarfReg = MRI->getDwarfRegNum(AArch64::LR, true);
diff --git a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
index 469e1448602c..0f2c353e748b 100644
--- a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp
@@ -66,12 +66,12 @@ static std::pair<bool, bool> GetSignReturnAddress(const Function &F) {
return {true, false};
}
-static bool ShouldSignWithBKey(const Function &F, const MachineFunction &MF) {
+static bool ShouldSignWithBKey(const Function &F, const AArch64Subtarget &STI) {
if (!F.hasFnAttribute("sign-return-address-key")) {
if (const auto *BKey = mdconst::extract_or_null<ConstantInt>(
F.getParent()->getModuleFlag("sign-return-address-with-bkey")))
return BKey->getZExtValue();
- if (MF.getTarget().getTargetTriple().isOSWindows())
+ if (STI.getTargetTriple().isOSWindows())
return true;
return false;
}
@@ -82,15 +82,16 @@ static bool ShouldSignWithBKey(const Function &F, const MachineFunction &MF) {
return Key.equals_insensitive("b_key");
}
-AArch64FunctionInfo::AArch64FunctionInfo(MachineFunction &MF_) : MF(&MF_) {
+AArch64FunctionInfo::AArch64FunctionInfo(MachineFunction &MF) {
+ const Function &F = MF.getFunction();
+ const AArch64Subtarget &STI = MF.getSubtarget<AArch64Subtarget>();
+
// If we already know that the function doesn't have a redzone, set
// HasRedZone here.
- if (MF->getFunction().hasFnAttribute(Attribute::NoRedZone))
+ if (F.hasFnAttribute(Attribute::NoRedZone))
HasRedZone = false;
-
- const Function &F = MF->getFunction();
std::tie(SignReturnAddress, SignReturnAddressAll) = GetSignReturnAddress(F);
- SignWithBKey = ShouldSignWithBKey(F, *MF);
+ SignWithBKey = ShouldSignWithBKey(F, STI);
// TODO: skip functions that have no instrumented allocas for optimization
IsMTETagged = F.hasFnAttribute(Attribute::SanitizeMemTag);
@@ -112,9 +113,7 @@ MachineFunctionInfo *AArch64FunctionInfo::clone(
BumpPtrAllocator &Allocator, MachineFunction &DestMF,
const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &Src2DstMBB)
const {
- AArch64FunctionInfo *InfoClone = DestMF.cloneInfo<AArch64FunctionInfo>(*this);
- InfoClone->MF = &DestMF;
- return InfoClone;
+ return DestMF.cloneInfo<AArch64FunctionInfo>(*this);
}
bool AArch64FunctionInfo::shouldSignReturnAddress(bool SpillsLR) const {
@@ -125,27 +124,30 @@ bool AArch64FunctionInfo::shouldSignReturnAddress(bool SpillsLR) const {
return SpillsLR;
}
-bool AArch64FunctionInfo::shouldSignReturnAddress() const {
+bool AArch64FunctionInfo::shouldSignReturnAddress(
+ const MachineFunction &MF) const {
return shouldSignReturnAddress(llvm::any_of(
- MF->getFrameInfo().getCalleeSavedInfo(),
+ MF.getFrameInfo().getCalleeSavedInfo(),
[](const auto &Info) { return Info.getReg() == AArch64::LR; }));
}
-bool AArch64FunctionInfo::needsDwarfUnwindInfo() const {
+bool AArch64FunctionInfo::needsDwarfUnwindInfo(
+ const MachineFunction &MF) const {
if (!NeedsDwarfUnwindInfo)
- NeedsDwarfUnwindInfo = MF->needsFrameMoves() &&
- !MF->getTarget().getMCAsmInfo()->usesWindowsCFI();
+ NeedsDwarfUnwindInfo = MF.needsFrameMoves() &&
+ !MF.getTarget().getMCAsmInfo()->usesWindowsCFI();
return *NeedsDwarfUnwindInfo;
}
-bool AArch64FunctionInfo::needsAsyncDwarfUnwindInfo() const {
+bool AArch64FunctionInfo::needsAsyncDwarfUnwindInfo(
+ const MachineFunction &MF) const {
if (!NeedsAsyncDwarfUnwindInfo) {
- const Function &F = MF->getFunction();
+ const Function &F = MF.getFunction();
// The check got "minsize" is because epilogue unwind info is not emitted
// (yet) for homogeneous epilogues, outlined functions, and functions
// outlined from.
- NeedsAsyncDwarfUnwindInfo = needsDwarfUnwindInfo() &&
+ NeedsAsyncDwarfUnwindInfo = needsDwarfUnwindInfo(MF) &&
F.getUWTableKind() == UWTableKind::Async &&
!F.hasMinSize();
}
diff --git a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
index 164c9576b944..b3dbf04676f9 100644
--- a/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
+++ b/llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.h
@@ -36,9 +36,6 @@ class MachineInstr;
/// AArch64FunctionInfo - This class is derived from MachineFunctionInfo and
/// contains private AArch64-specific information for each MachineFunction.
class AArch64FunctionInfo final : public MachineFunctionInfo {
- /// Backreference to the machine function.
- MachineFunction *MF;
-
/// Number of bytes of arguments this function has on the stack. If the callee
/// is expected to restore the argument stack this should be a multiple of 16,
/// all usable during a tail call.
@@ -428,7 +425,7 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
CalleeSaveBaseToFrameRecordOffset = Offset;
}
- bool shouldSignReturnAddress() const;
+ bool shouldSignReturnAddress(const MachineFunction &MF) const;
bool shouldSignReturnAddress(bool SpillsLR) const;
bool shouldSignWithBKey() const { return SignWithBKey; }
@@ -446,8 +443,8 @@ class AArch64FunctionInfo final : public MachineFunctionInfo {
}
int getSwiftAsyncContextFrameIdx() const { return SwiftAsyncContextFrameIdx; }
- bool needsDwarfUnwindInfo() const;
- bool needsAsyncDwarfUnwindInfo() const;
+ bool needsDwarfUnwindInfo(const MachineFunction &MF) const;
+ bool needsAsyncDwarfUnwindInfo(const MachineFunction &MF) const;
private:
// Hold the lists of LOHs.
More information about the llvm-commits
mailing list