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);
}
.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))
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;
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))
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();
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()); });
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;
}
.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))
.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);
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;
}
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);
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 {
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();
}
/// 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.
CalleeSaveBaseToFrameRecordOffset = Offset;
}
- bool shouldSignReturnAddress() const;
+ bool shouldSignReturnAddress(const MachineFunction &MF) const;
bool shouldSignReturnAddress(bool SpillsLR) const;
bool shouldSignWithBKey() const { return SignWithBKey; }
}
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.