LLVM: lib/Target/AArch64/AArch64FrameLowering.cpp File Reference (original) (raw)

Go to the source code of this file.

Macros
#define DEBUG_TYPE "frame-info"
#define CASE(n)
#define CASE(n)
Functions
STATISTIC (NumRedZoneFunctions, "Number of functions using red zone")
static int64_t getArgumentStackToRestore (MachineFunction &MF, MachineBasicBlock &MBB)
Returns how much of the incoming argument stack area (in bytes) we should clean up in an epilogue.
static bool produceCompactUnwindFrame (MachineFunction &MF)
static bool needsWinCFI (const MachineFunction &MF)
static StackOffset getSVEStackSize (const MachineFunction &MF)
Returns the size of the entire SVE stackframe (calleesaves + spills).
static Register findScratchNonCalleeSaveRegister (MachineBasicBlock *MBB)
static unsigned estimateRSStackSizeLimit (MachineFunction &MF)
Look at each instruction that references stack frames and return the stack size limit beyond which some of these instructions will require a scratch register during their expansion later.
static unsigned getFixedObjectSize (const MachineFunction &MF, const AArch64FunctionInfo *AFI, bool IsWin64, bool IsFunclet)
Returns the size of the fixed object area (allocated next to sp on entry) On Win64 this may include a var args area and an UnwindHelp object for EH.
static void insertCFISameValue (const MCInstrDesc &Desc, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator InsertPt, unsigned DwarfReg)
static void emitCalleeSavedRestores (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, bool SVE)
static int64_t upperBound (StackOffset Size)
static MCRegister getRegisterOrZero (MCRegister Reg, bool HasSVE)
static void getLiveRegsForEntryMBB (LivePhysRegs &LiveRegs, const MachineBasicBlock &MBB)
static bool windowsRequiresStackProbe (MachineFunction &MF, uint64_t StackSizeInBytes)
static MachineBasicBlock::iterator InsertSEH (MachineBasicBlock::iterator MBBI, const TargetInstrInfo &TII, MachineInstr::MIFlag Flag)
static void fixupSEHOpcode (MachineBasicBlock::iterator MBBI, unsigned LocalStackSize)
bool requiresGetVGCall (MachineFunction &MF)
static bool requiresSaveVG (MachineFunction &MF)
bool isVGInstruction (MachineBasicBlock::iterator MBBI)
static MachineBasicBlock::iterator convertCalleeSaveRestoreToSPPrePostIncDec (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const TargetInstrInfo *TII, int CSStackSizeInc, bool NeedsWinCFI, bool *HasWinCFI, bool EmitCFI, MachineInstr::MIFlag FrameFlag=MachineInstr::FrameSetup, int CFAOffset=0)
static void fixupCalleeSaveRestoreStackOffset (MachineInstr &MI, uint64_t LocalStackSize, bool NeedsWinCFI, bool *HasWinCFI)
static bool isTargetWindows (const MachineFunction &MF)
static unsigned getStackHazardSize (const MachineFunction &MF)
static bool IsSVECalleeSave (MachineBasicBlock::iterator I)
static void emitShadowCallStackPrologue (const TargetInstrInfo &TII, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool NeedsWinCFI, bool NeedsUnwindInfo)
static void emitShadowCallStackEpilogue (const TargetInstrInfo &TII, MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL)
static void emitDefineCFAWithFP (MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, unsigned FixedObject)
static void getLivePhysRegsUpTo (MachineInstr &MI, const TargetRegisterInfo &TRI, LivePhysRegs &LiveRegs)
Collect live registers from the end of MI's parent up to (including) MI in LiveRegs.
static bool isFuncletReturnInstr (const MachineInstr &MI)
static StackOffset getFPOffset (const MachineFunction &MF, int64_t ObjectOffset)
static StackOffset getStackOffset (const MachineFunction &MF, int64_t ObjectOffset)
static unsigned getPrologueDeath (MachineFunction &MF, unsigned Reg)
static bool invalidateWindowsRegisterPairing (unsigned Reg1, unsigned Reg2, bool NeedsWinCFI, bool IsFirst, const TargetRegisterInfo *TRI)
static bool invalidateRegisterPairing (unsigned Reg1, unsigned Reg2, bool UsesWinAAPCS, bool NeedsWinCFI, bool NeedsFrameRecord, bool IsFirst, const TargetRegisterInfo *TRI)
Returns true if Reg1 and Reg2 cannot be paired using a ldp/stp instruction.
unsigned findFreePredicateReg (BitVector &SavedRegs)
bool enableMultiVectorSpillFill (const AArch64Subtarget &Subtarget, MachineFunction &MF)
static void computeCalleeSaveRegisterPairs (MachineFunction &MF, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI, SmallVectorImpl< RegPairInfo > &RegPairs, bool NeedsFrameRecord)
static std::optional< int > getMMOFrameID (MachineMemOperand *MMO, const MachineFrameInfo &MFI)
static std::optional< int > getLdStFrameID (const MachineInstr &MI, const MachineFrameInfo &MFI)
static bool getSVECalleeSaveSlotRange (const MachineFrameInfo &MFI, int &Min, int &Max)
returns true if there are any SVE callee saves.
static int64_t determineSVEStackObjectOffsets (MachineFrameInfo &MFI, int &MinCSFrameIndex, int &MaxCSFrameIndex, bool AssignOffsets)
MachineBasicBlock::iterator emitVGSaveRestore (MachineBasicBlock::iterator II, const AArch64FrameLowering *TFI)
static raw_ostream & operator<< (raw_ostream &OS, const StackAccess &SA)
Variables
static cl::opt< bool > EnableRedZone ("aarch64-redzone", cl::desc("enable use of redzone on AArch64"), cl::init(false), cl::Hidden)
static cl::opt< bool > StackTaggingMergeSetTag ("stack-tagging-merge-settag", cl::desc("merge settag instruction in function epilog"), cl::init(true), cl::Hidden)
static cl::opt< bool > OrderFrameObjects ("aarch64-order-frame-objects", cl::desc("sort stack allocations"), cl::init(true), cl::Hidden)
cl::opt< bool > EnableHomogeneousPrologEpilog ("homogeneous-prolog-epilog", cl::Hidden, cl::desc("Emit homogeneous prologue and epilogue for the size " "optimization (default = off)"))
static cl::opt< unsigned > StackHazardRemarkSize ("aarch64-stack-hazard-remark-size", cl::init(0), cl::Hidden)
static cl::opt< bool > StackHazardInNonStreaming ("aarch64-stack-hazard-in-non-streaming", cl::init(false), cl::Hidden)
static cl::opt< bool > DisableMultiVectorSpillFill ("aarch64-disable-multivector-spill-fill", cl::desc("Disable use of LD/ST pairs for SME2 or SVE2p1"), cl::init(false), cl::Hidden)
static const unsigned DefaultSafeSPDisplacement = 255
This is the biggest offset to the stack pointer we can encode in aarch64 instructions (without using a separate calculation and a temp register).

CASE [1/2]

Value:

case AArch64::W##n: \

case AArch64::X##n: \

return AArch64::X##n

CASE [2/2]

Value:

case AArch64::B##n: \

case AArch64::H##n: \

case AArch64::S##n: \

case AArch64::D##n: \

case AArch64::Q##n: \

return HasSVE ? AArch64::Z##n : AArch64::Q##n

DEBUG_TYPE

#define DEBUG_TYPE "frame-info"

computeCalleeSaveRegisterPairs()

Definition at line 2966 of file AArch64FrameLowering.cpp.

References assert(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), CC, contains(), llvm::CallingConv::CXX_FAST_TLS, llvm::ArrayRef< T >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::AArch64FunctionInfo::getCalleeSavedStackSize(), llvm::Function::getCallingConv(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::MachineFunction::getInfo(), llvm::MachineFrameInfo::getObjectAlign(), llvm::AArch64FunctionInfo::getPredicateRegForFillSpill(), getStackHazardSize(), llvm::AArch64FunctionInfo::getSVECalleeSavedStackSize(), llvm::AArch64FunctionInfo::hasCalleeSaveStackFreeSpace(), llvm::AArch64FunctionInfo::hasStackHazardSlotIndex(), llvm::AArch64FunctionInfo::hasSwiftAsyncContext(), invalidateRegisterPairing(), invalidateWindowsRegisterPairing(), llvm::AArch64InstrInfo::isFpOrNEON(), isTargetWindows(), llvm_unreachable, needsWinCFI(), llvm::Offset, llvm::CallingConv::PreserveAll, llvm::CallingConv::PreserveMost, produceCompactUnwindFrame(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::AArch64FunctionInfo::setCalleeSaveBaseToFrameRecordOffset(), llvm::MachineFrameInfo::setObjectAlignment(), llvm::ArrayRef< T >::size(), TRI, and llvm::CallingConv::Win64.

Referenced by llvm::AArch64FrameLowering::restoreCalleeSavedRegisters(), and llvm::AArch64FrameLowering::spillCalleeSavedRegisters().

convertCalleeSaveRestoreToSPPrePostIncDec()

Definition at line 1437 of file AArch64FrameLowering.cpp.

References llvm::MachineInstrBuilder::add(), llvm::MachineInstrBuilder::addCFIIndex(), llvm::MachineFunction::addFrameInst(), llvm::MachineInstrBuilder::addImm(), llvm::MachineInstrBuilder::addReg(), assert(), llvm::BuildMI(), llvm::MCCFIInstruction::cfiDefCfaOffset(), llvm::RegState::Define, DL, llvm::emitFrameOffset(), llvm::MachineBasicBlock::erase(), llvm::MachineInstr::FrameDestroy, llvm::StackOffset::getFixed(), llvm::TypeSize::getFixed(), llvm::details::FixedOrScalableQuantity< LeafTy, ValueTy >::getFixedValue(), llvm::MachineBasicBlock::getParent(), InsertSEH(), llvm::AArch64InstrInfo::isSEHInstruction(), isVGInstruction(), llvm_unreachable, MBB, MBBI, requiresSaveVG(), llvm::MachineInstrBuilder::setMemRefs(), llvm::MachineInstrBuilder::setMIFlags(), Success, and TII.

Referenced by llvm::AArch64FrameLowering::emitEpilogue(), and llvm::AArch64FrameLowering::emitPrologue().

determineSVEStackObjectOffsets()

static int64_t determineSVEStackObjectOffsets ( MachineFrameInfo & MFI, int & MinCSFrameIndex, int & MaxCSFrameIndex, bool AssignOffsets ) static

Definition at line 4070 of file AArch64FrameLowering.cpp.

References llvm::alignTo(), assert(), llvm::dbgs(), llvm::MachineFrameInfo::getObjectAlign(), llvm::MachineFrameInfo::getObjectIndexBegin(), llvm::MachineFrameInfo::getObjectIndexEnd(), llvm::MachineFrameInfo::getObjectSize(), llvm::MachineFrameInfo::getStackID(), llvm::MachineFrameInfo::getStackProtectorIndex(), getSVECalleeSaveSlotRange(), llvm::MachineFrameInfo::hasStackProtectorIndex(), I, llvm::MachineFrameInfo::isDeadObjectIndex(), LLVM_DEBUG, llvm::Offset, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::report_fatal_error(), llvm::TargetStackID::ScalableVector, and llvm::MachineFrameInfo::setObjectOffset().

emitCalleeSavedRestores()

Definition at line 727 of file AArch64FrameLowering.cpp.

References llvm::MachineInstrBuilder::addCFIIndex(), llvm::MachineFunction::addFrameInst(), llvm::BuildMI(), llvm::MCCFIInstruction::createRestore(), DL, llvm::MachineBasicBlock::findDebugLoc(), llvm::MachineInstr::FrameDestroy, llvm::MachineFrameInfo::getCalleeSavedInfo(), llvm::MachineFunction::getFrameInfo(), llvm::TargetSubtargetInfo::getInstrInfo(), llvm::MachineBasicBlock::getParent(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFrameInfo::getStackID(), llvm::MachineFunction::getSubtarget(), Info, MBB, MBBI, llvm::TargetStackID::ScalableVector, llvm::MachineInstrBuilder::setMIFlags(), llvm::SVE, TII, and TRI.

emitDefineCFAWithFP()

Definition at line 1700 of file AArch64FrameLowering.cpp.

References llvm::MachineInstrBuilder::addCFIIndex(), llvm::MachineFunction::addFrameInst(), llvm::BuildMI(), llvm::MCCFIInstruction::cfiDefCfa(), DL, FramePtr, llvm::MachineInstr::FrameSetup, llvm::AArch64FunctionInfo::getCalleeSaveBaseToFrameRecordOffset(), llvm::AArch64FunctionInfo::getCalleeSavedStackSize(), llvm::MachineFunction::getInfo(), llvm::AArch64Subtarget::getInstrInfo(), llvm::AArch64Subtarget::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), MBB, MBBI, llvm::MachineInstrBuilder::setMIFlags(), TII, and TRI.

Referenced by llvm::AArch64FrameLowering::emitPrologue().

emitShadowCallStackEpilogue()

Definition at line 1677 of file AArch64FrameLowering.cpp.

References llvm::MachineInstrBuilder::addCFIIndex(), llvm::MachineFunction::addFrameInst(), llvm::MachineInstrBuilder::addImm(), llvm::MachineInstrBuilder::addReg(), llvm::BuildMI(), llvm::MCCFIInstruction::createRestore(), llvm::RegState::Define, DL, llvm::MachineInstr::FrameDestroy, llvm::MachineFunction::getInfo(), MBB, MBBI, llvm::AArch64FunctionInfo::needsAsyncDwarfUnwindInfo(), llvm::MachineInstrBuilder::setMIFlag(), llvm::MachineInstrBuilder::setMIFlags(), and TII.

Referenced by llvm::AArch64FrameLowering::emitEpilogue().

emitShadowCallStackPrologue()

Definition at line 1638 of file AArch64FrameLowering.cpp.

References llvm::MachineInstrBuilder::addCFIIndex(), llvm::MachineFunction::addFrameInst(), llvm::MachineInstrBuilder::addImm(), llvm::MachineBasicBlock::addLiveIn(), llvm::MachineInstrBuilder::addReg(), llvm::BuildMI(), llvm::MCCFIInstruction::createEscape(), llvm::RegState::Define, DL, llvm::MachineInstr::FrameSetup, MBB, MBBI, llvm::MachineInstrBuilder::setMIFlag(), and TII.

Referenced by llvm::AArch64FrameLowering::emitPrologue().

emitVGSaveRestore()

Definition at line 4644 of file AArch64FrameLowering.cpp.

References llvm::MachineInstrBuilder::addCFIIndex(), llvm::MachineFunction::addFrameInst(), assert(), llvm::BuildMI(), llvm::MCCFIInstruction::createOffset(), llvm::MCCFIInstruction::createRestore(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::MachineFunction::getInfo(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::MachineFrameInfo::getObjectOffset(), llvm::TargetFrameLowering::getOffsetOfLocalArea(), llvm::MachineBasicBlock::getParent(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::AArch64FunctionInfo::getStreamingVGIdx(), llvm::MachineFunction::getSubtarget(), llvm::AArch64FunctionInfo::getVGIdx(), llvm::SMEAttrs::hasStreamingBody(), llvm::SMEAttrs::hasStreamingInterface(), II, MBB, MI, llvm::Offset, TII, and TRI.

Referenced by llvm::AArch64FrameLowering::processFunctionBeforeFrameIndicesReplaced().

enableMultiVectorSpillFill()

estimateRSStackSizeLimit()

findFreePredicateReg()

findScratchNonCalleeSaveRegister()

Definition at line 1069 of file AArch64FrameLowering.cpp.

References llvm::LivePhysRegs::available(), llvm::MachineFunction::front(), llvm::Function::getCallingConv(), llvm::MachineFunction::getFunction(), getLiveRegsForEntryMBB(), llvm::MachineBasicBlock::getParent(), llvm::MachineFunction::getRegInfo(), llvm::AArch64Subtarget::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), MBB, MRI, llvm::CallingConv::PreserveNone, and TRI.

Referenced by buildScratchExecCopy(), llvm::AArch64FrameLowering::canUseAsPrologue(), llvm::SIFrameLowering::emitEpilogue(), llvm::SIFrameLowering::emitPrologue(), and llvm::AArch64FrameLowering::spillCalleeSavedRegisters().

fixupCalleeSaveRestoreStackOffset()

fixupSEHOpcode()

getArgumentStackToRestore()

getFixedObjectSize()

Returns the size of the fixed object area (allocated next to sp on entry) On Win64 this may include a var args area and an UnwindHelp object for EH.

Definition at line 428 of file AArch64FrameLowering.cpp.

References llvm::alignTo(), llvm::Function::getAttributes(), llvm::MachineFunction::getFunction(), llvm::AArch64FunctionInfo::getTailCallReservedStack(), llvm::AArch64FunctionInfo::getVarArgsGPRSize(), llvm::AttributeList::hasAttrSomewhere(), llvm::MachineFunction::hasEHFunclets(), and llvm::report_fatal_error().

Referenced by llvm::AArch64FrameLowering::emitEpilogue(), llvm::AArch64FrameLowering::emitPrologue(), getFPOffset(), and llvm::AArch64FrameLowering::processFunctionBeforeFrameFinalized().

getFPOffset()

getLdStFrameID()

getLivePhysRegsUpTo()

getLiveRegsForEntryMBB()

getMMOFrameID()

getPrologueDeath()

getRegisterOrZero()

getStackHazardSize()

getStackOffset()

getSVECalleeSaveSlotRange()

getSVEStackSize()

insertCFISameValue()

InsertSEH()

Definition at line 1231 of file AArch64FrameLowering.cpp.

References llvm::MachineInstrBuilder::addImm(), llvm::BuildMI(), DL, llvm::MachineBasicBlock::getParent(), llvm::AArch64Subtarget::getRegisterInfo(), llvm::MachineFunction::getSubtarget(), I, llvm::MachineBasicBlock::insertAfter(), llvm_unreachable, MBB, MBBI, llvm::MachineInstrBuilder::setMIFlag(), and TII.

Referenced by convertCalleeSaveRestoreToSPPrePostIncDec(), llvm::AArch64FrameLowering::restoreCalleeSavedRegisters(), and llvm::AArch64FrameLowering::spillCalleeSavedRegisters().

invalidateRegisterPairing()

invalidateWindowsRegisterPairing()

isFuncletReturnInstr()

IsSVECalleeSave()

isTargetWindows()

isVGInstruction()

needsWinCFI()

Definition at line 1142 of file AArch64FrameLowering.cpp.

References F, llvm::MachineFunction::getFunction(), llvm::TargetMachine::getMCAsmInfo(), llvm::MachineFunction::getTarget(), and llvm::MCAsmInfo::usesWindowsCFI().

Referenced by llvm::AArch64FrameLowering::assignCalleeSavedSpillSlots(), computeCalleeSaveRegisterPairs(), llvm::AArch64FrameLowering::emitEpilogue(), llvm::AArch64FrameLowering::emitPrologue(), llvm::ARMFrameLowering::emitPrologue(), llvm::AArch64FrameLowering::restoreCalleeSavedRegisters(), and llvm::AArch64FrameLowering::spillCalleeSavedRegisters().

operator<<()

produceCompactUnwindFrame()

Definition at line 2861 of file AArch64FrameLowering.cpp.

References llvm::Function::getAttributes(), llvm::Function::getCallingConv(), llvm::MachineFunction::getFunction(), llvm::MachineFunction::getInfo(), llvm::MachineFunction::getSubtarget(), llvm::AArch64FunctionInfo::getSVECalleeSavedStackSize(), llvm::AArch64Subtarget::getTargetLowering(), llvm::AArch64Subtarget::isTargetMachO(), requiresSaveVG(), llvm::AArch64TargetLowering::supportSwiftError(), and llvm::CallingConv::SwiftTail.

Referenced by computeCalleeSaveRegisterPairs(), and llvm::AArch64FrameLowering::determineCalleeSaves().

requiresGetVGCall()

requiresSaveVG()

STATISTIC()

STATISTIC ( NumRedZoneFunctions ,
"Number of functions using red zone"
)

upperBound()

windowsRequiresStackProbe()

DefaultSafeSPDisplacement

DisableMultiVectorSpillFill

cl::opt< bool > DisableMultiVectorSpillFill("aarch64-disable-multivector-spill-fill", cl::desc("Disable use of LD/ST pairs for SME2 or SVE2p1"), cl::init(false), cl::Hidden) ( "aarch64-disable-multivector-spill-fill" , cl::desc("Disable use of LD/ST pairs for SME2 or SVE2p1") , cl::init(false) , cl::Hidden ) static

EnableHomogeneousPrologEpilog

cl::opt< bool > EnableHomogeneousPrologEpilog("homogeneous-prolog-epilog", cl::Hidden, cl::desc("Emit homogeneous prologue and epilogue for the size " "optimization (default = off)")) ( "homogeneous-prolog-epilog" ,
cl::Hidden ,
cl::desc("Emit homogeneous prologue and epilogue for the size " "optimization (default = off)")
)

EnableRedZone

cl::opt< bool > EnableRedZone("aarch64-redzone", cl::desc("enable use of redzone on AArch64"), cl::init(false), cl::Hidden) ( "aarch64-redzone" , cl::desc("enable use of redzone on AArch64") , cl::init(false) , cl::Hidden ) static

OrderFrameObjects

cl::opt< bool > OrderFrameObjects("aarch64-order-frame-objects", cl::desc("sort stack allocations"), cl::init(true), cl::Hidden) ( "aarch64-order-frame-objects" , cl::desc("sort stack allocations") , cl::init(true) , cl::Hidden ) static

StackHazardInNonStreaming

cl::opt< bool > StackHazardInNonStreaming("aarch64-stack-hazard-in-non-streaming", cl::init(false), cl::Hidden) ( "aarch64-stack-hazard-in-non-streaming" , cl::init(false) , cl::Hidden ) static

StackHazardRemarkSize

cl::opt< unsigned > StackHazardRemarkSize("aarch64-stack-hazard-remark-size", cl::init(0), cl::Hidden) ( "aarch64-stack-hazard-remark-size" , cl::init(0) , cl::Hidden ) static

StackTaggingMergeSetTag