LLVM: llvm::X86FrameLowering Class Reference (original) (raw)

#include "[Target/X86/X86FrameLowering.h](X86FrameLowering%5F8h%5Fsource.html)"

Public Member Functions
X86FrameLowering (const X86Subtarget &STI, MaybeAlign StackAlignOverride)
void emitStackProbe (MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool InProlog, std::optional< MachineFunction::DebugInstrOperandPair > InstrNum=std::nullopt) const
Emit target stack probe code.
bool stackProbeFunctionModifiesSP () const override
Does the stack probe function call return with a modified stack pointer?
void inlineStackProbe (MachineFunction &MF, MachineBasicBlock &PrologMBB) const override
Replace a StackProbe inline-stub with the actual probe code inline.
void emitCalleeSavedFrameMovesFullCFA (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI) const override
Emits Dwarf Info specifying offsets of callee saved registers and frame pointer.
void emitCalleeSavedFrameMoves (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool IsPrologue) const
void emitPrologue (MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
void emitEpilogue (MachineFunction &MF, MachineBasicBlock &MBB) const override
void adjustForSegmentedStacks (MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Adjust the prologue to have the function use segmented stacks.
void adjustForHiPEPrologue (MachineFunction &MF, MachineBasicBlock &PrologueMBB) const override
Erlang programs may need a special prologue to handle the stack size they might need at runtime.
void determineCalleeSaves (MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() should actually get saved.
bool assignCalleeSavedSpillSlots (MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
bool spillCalleeSavedRegisters (MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns true if it isn't possible / profitable to do so by issuing a series of store instructions via storeRegToStackSlot().
bool restoreCalleeSavedRegisters (MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns true if it isn't possible / profitable to do so by issuing a series of load instructions via loadRegToStackSlot().
void spillFPBP (MachineFunction &MF) const override
If a function uses base pointer and the base pointer is clobbered by inline asm, RA doesn't detect this case, and after the inline asm, the base pointer contains garbage value.
bool hasReservedCallFrame (const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required, we reserve argument space for call sites in the function immediately on entry to the current function.
bool canSimplifyCallFramePseudos (const MachineFunction &MF) const override
canSimplifyCallFramePseudos - If there is a reserved call frame, the call frame pseudos can be simplified.
bool needsFrameIndexResolution (const MachineFunction &MF) const override
StackOffset getFrameIndexReference (const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a frame index location.
int getWin64EHFrameIndexRef (const MachineFunction &MF, int FI, Register &SPReg) const
StackOffset getFrameIndexReferenceSP (const MachineFunction &MF, int FI, Register &SPReg, int Adjustment) const
StackOffset getFrameIndexReferencePreferSP (const MachineFunction &MF, int FI, Register &FrameReg, bool IgnoreSPUpdates) const override
Same as getFrameIndexReference, except that the stack pointer (as opposed to the frame pointer) will be the preferred value for FrameReg.
MachineBasicBlock::iterator eliminateCallFramePseudoInstr (MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy pseudo instructions (but only if the Target is using them).
unsigned getWinEHParentFrameOffset (const MachineFunction &MF) const override
void processFunctionBeforeFrameFinalized (MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function's frame layout (MF.getFrameInfo()) is finalized.
void processFunctionBeforeFrameIndicesReplaced (MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameIndicesReplaced - This method is called immediately before MO_FrameIndex operands are eliminated, but after the frame is finalized.
int64_t mergeSPAdd (MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, int64_t AddOffset, bool doMergeWithPrevious) const
Equivalent to: mergeSPUpdates(MBB, MBBI, [AddOffset](int64_t Offset) { return AddOffset + Offset; }, doMergeWithPrevious);.
void emitSPUpdate (MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const DebugLoc &DL, int64_t NumBytes, bool InEpilogue) const
Emit a series of instructions to increment / decrement the stack pointer by a constant value.
bool canUseLEAForSPInEpilogue (const MachineFunction &MF) const
Check that LEA can be used on SP in an epilogue sequence for MF.
bool canUseAsPrologue (const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
bool canUseAsEpilogue (const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
bool enableShrinkWrapping (const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
void orderFrameObjects (const MachineFunction &MF, SmallVectorImpl< int > &ObjectsToAllocate) const override
Order the symbols in the local stack.
void BuildCFI (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, const MCCFIInstruction &CFIInst, MachineInstr::MIFlag Flag=MachineInstr::NoFlags) const
Wraps up getting a CFI index and building a MachineInstr for it.
MachineBasicBlock::iterator restoreWin32EHStackPointers (MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, const DebugLoc &DL, bool RestoreSP=false) const
Sets up EBP and optionally ESI based on the incoming EBP value.
void restoreWinEHStackPointersInParent (MachineFunction &MF) const
int getInitialCFAOffset (const MachineFunction &MF) const override
Return initial CFA offset value i.e.
Register getInitialCFARegister (const MachineFunction &MF) const override
Return initial CFA register value i.e.
DwarfFrameBase getDwarfFrameBase (const MachineFunction &MF) const override
Return the frame base information to be encoded in the DWARF subprogram debug info.
bool has128ByteRedZone (const MachineFunction &MF) const
Return true if the function has a redzone (accessible bytes past the frame of the top of stack function) as part of it's ABI.
Public Member Functions inherited from llvm::TargetFrameLowering
TargetFrameLowering (StackDirection D, Align StackAl, int LAO, Align TransAl=Align(1), bool StackReal=true)
virtual ~TargetFrameLowering ()
StackDirection getStackGrowthDirection () const
getStackGrowthDirection - Return the direction the stack grows
unsigned getStackAlignment () const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligned on entry to a function.
Align getStackAlign () const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligned on entry to a function.
virtual uint64_t getStackThreshold () const
getStackThreshold - Return the maximum stack size
int alignSPAdjust (int SPAdj) const
alignSPAdjust - This method aligns the stack adjustment to the correct alignment.
Align getTransientStackAlign () const
getTransientStackAlignment - This method returns the number of bytes to which the stack pointer must be aligned at all times, even between calls.
bool isStackRealignable () const
isStackRealignable - This method returns whether the stack can be realigned.
virtual bool isStackIdSafeForLocalArea (unsigned StackId) const
This method returns whether or not it is safe for an object with the given stack id to be bundled into the local area.
int getOffsetOfLocalArea () const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on entrance to a function.
virtual bool allocateScavengingFrameIndexesNearIncomingSP (const MachineFunction &MF) const
Control the placement of special register scavenging spill slots when allocating a stack frame.
virtual const SpillSlot * getCalleeSavedSpillSlots (unsigned &NumEntries) const
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry for each callee saved register that must be spilled to a particular stack location if it is spilled.
virtual bool targetHandlesStackFrameRounding () const
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack frame (probably at emitPrologue time).
virtual bool enableStackSlotScavenging (const MachineFunction &MF) const
Returns true if the stack slot holes in the fixed and callee-save stack area should be used when allocating other stack locations to reduce stack size.
virtual bool enableCalleeSaveSkip (const MachineFunction &MF) const
Returns true if the target can safely skip saving callee-saved registers for noreturn nounwind functions.
virtual bool enableCFIFixup (const MachineFunction &MF) const
Returns true if we may need to fix the unwind information for the function.
virtual bool enableFullCFIFixup (const MachineFunction &MF) const
enableFullCFIFixup - Returns true if we may need to fix the unwind information such that it is accurate for every instruction in the function (e.g.
virtual void resetCFIToInitialState (MachineBasicBlock &MBB) const
Emit CFI instructions that recreate the state of the unwind information upon function entry.
void spillCalleeSavedRegister (MachineBasicBlock &SaveBlock, MachineBasicBlock::iterator MI, const CalleeSavedInfo &CS, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
spillCalleeSavedRegister - Default implementation for spilling a single callee saved register.
void restoreCalleeSavedRegister (MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const CalleeSavedInfo &CS, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) const
bool hasFP (const MachineFunction &MF) const
hasFP - Return true if the specified function should have a dedicated frame pointer register.
virtual StackOffset getNonLocalFrameIndexReference (const MachineFunction &MF, int FI) const
getNonLocalFrameIndexReference - This method returns the offset used to reference a frame index location.
virtual StackOffset getFrameIndexReferenceFromSP (const MachineFunction &MF, int FI) const
getFrameIndexReferenceFromSP - This method returns the offset from the stack pointer to the slot of the specified index.
virtual void getCalleeSaves (const MachineFunction &MF, BitVector &SavedRegs) const
Returns the callee-saved registers as computed by determineCalleeSaves in the BitVector SavedRegs.
virtual TargetStackID::Value getStackIDForScalableVectors () const
Returns the StackID that scalable vectors should be associated with.
virtual bool isSupportedStackID (TargetStackID::Value ID) const
virtual bool isProfitableForNoCSROpt (const Function &F) const
Check if the no-CSR optimisation is profitable for the given function.
virtual void emitRemarks (const MachineFunction &MF, MachineOptimizationRemarkEmitter *ORE) const
This method is called at the end of prolog/epilog code insertion, so targets can emit remarks based on the final frame layout.
Public Attributes
const X86Subtarget & STI
const X86InstrInfo & TII
const X86RegisterInfo * TRI
unsigned SlotSize
bool Is64Bit
Is64Bit implies that x86_64 instructions are available.
bool IsLP64
bool Uses64BitFramePtr
True if the 64-bit frame or stack pointer should be used.
Register StackPtr
Protected Member Functions
bool hasFPImpl (const MachineFunction &MF) const override
hasFPImpl - Return true if the specified function should have a dedicated frame pointer register.
Additional Inherited Members
Public Types inherited from llvm::TargetFrameLowering
enum StackDirection { StackGrowsUp, StackGrowsDown }
Static Public Member Functions inherited from llvm::TargetFrameLowering
static bool isSafeForNoCSROpt (const Function &F)
Check if given function is safe for not having callee saved registers.

Definition at line 28 of file X86FrameLowering.h.

Definition at line 49 of file X86FrameLowering.cpp.

References assert(), Is64Bit, is64Bit(), IsLP64, SlotSize, llvm::TargetFrameLowering::StackGrowsDown, StackPtr, STI, llvm::TargetFrameLowering::TargetFrameLowering(), TII, TRI, and Uses64BitFramePtr.

adjustForHiPEPrologue()

Erlang programs may need a special prologue to handle the stack size they might need at runtime.

That is because Erlang/OTP does not implement a C stack but uses a custom implementation of hybrid stack/heap architecture. (for more information see Eric Stenman's Ph.D. thesis: http://publications.uu.se/uu/fulltext/nbn_se_uu_diva-2688.pdf)

CheckStack: temp0 = sp - MaxStack if( temp0 < SP_LIMIT(P) ) goto IncStack else goto OldStart OldStart: ... IncStack: call inc_stack # doubles the stack space temp0 = sp - MaxStack if( temp0 < SP_LIMIT(P) ) goto IncStack else goto OldStart

Reimplemented from llvm::TargetFrameLowering.

Definition at line 3576 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addExternalSymbol(), llvm::MachineInstrBuilder::addImm(), llvm::MachineBasicBlock::addLiveIn(), llvm::MachineInstrBuilder::addMBB(), llvm::MachineInstrBuilder::addReg(), llvm::addRegOffset(), llvm::MachineBasicBlock::addSuccessor(), llvm::Function::arg_size(), assert(), llvm::MachineFunction::begin(), llvm::BuildMI(), llvm::X86::COND_AE, llvm::X86::COND_LE, llvm::MachineFunction::CreateMachineBasicBlock(), DL, llvm::dyn_cast(), F, llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::MachineOperand::getGlobal(), getHiPELiteral(), llvm::Module::getNamedMetadata(), llvm::GlobalValue::getParent(), llvm::MachineFunction::getRegInfo(), GetScratchRegister(), llvm::MachineFrameInfo::getStackSize(), llvm::MachineFrameInfo::hasCalls(), Is64Bit, llvm::MachineOperand::isGlobal(), llvm::MachineRegisterInfo::isLiveIn(), IsLP64, llvm::MachineBasicBlock::liveins(), MBB, MI, llvm::StringRef::npos, llvm::MachineFunction::push_front(), llvm::report_fatal_error(), SlotSize, SPReg, STI, TII, and llvm::MachineFunction::verify().

adjustForSegmentedStacks()

Adjust the prologue to have the function use segmented stacks.

This works by adding a check even before the "normal" function prologue.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 3268 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addExternalSymbol(), llvm::MachineInstrBuilder::addImm(), llvm::MachineBasicBlock::addLiveIn(), llvm::MachineInstrBuilder::addMBB(), llvm::MachineInstrBuilder::addReg(), llvm::MachineBasicBlock::addSuccessor(), assert(), llvm::MachineFunction::begin(), llvm::BuildMI(), llvm::X86::COND_A, llvm::MachineFunction::CreateMachineBasicBlock(), DL, llvm::X86MachineFunctionInfo::getArgumentStackSize(), llvm::TargetMachine::getCodeModel(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::MachineFunction::getInfo(), getMOVriOpcode(), llvm::BranchProbability::getOne(), llvm::MachineFunction::getRegInfo(), GetScratchRegister(), llvm::MachineFrameInfo::getStackSize(), llvm::MachineFunction::getTarget(), llvm::BranchProbability::getZero(), HasNestArgument(), Is64Bit, llvm::MachineRegisterInfo::isLiveIn(), IsLP64, llvm::Function::isVarArg(), llvm::RegState::Kill, kSplitStackAvailable, llvm::CodeModel::Large, llvm::MachineBasicBlock::liveins(), llvm::MachineFrameInfo::needsSplitStackProlog(), llvm::MachineFunction::push_front(), llvm::report_fatal_error(), STI, TII, and llvm::MachineFunction::verify().

assignCalleeSavedSpillSlots()

assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.

If implemented, assignCalleeSavedSpillSlots() should assign frame slots to all CSI entries and return true. If this method returns false, spill slots will be assigned using generic implementation. assignCalleeSavedSpillSlots() may add, delete or rearrange elements of CSI.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 2853 of file X86FrameLowering.cpp.

References llvm::X86MachineFunctionInfo::addCandidateForPush2Pop2(), llvm::alignDown(), llvm::alignTo(), assert(), contains(), llvm::count_if(), llvm::MachineFrameInfo::CreateFixedObject(), llvm::MachineFrameInfo::CreateFixedSpillStackObject(), llvm::MachineFrameInfo::CreateSpillStackObject(), llvm::MachineFrameInfo::ensureMaxAlignment(), FPReg, llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getInfo(), llvm::X86MachineFunctionInfo::getNumCandidatesForPush2Pop2(), llvm::TargetFrameLowering::getOffsetOfLocalArea(), llvm::X86MachineFunctionInfo::getRestoreBasePointer(), llvm::TargetFrameLowering::getStackAlignment(), llvm::X86MachineFunctionInfo::getTCReturnAddrDelta(), llvm::X86MachineFunctionInfo::getWinEHXMMSlotInfo(), llvm::MachineFunction::hasEHFunclets(), llvm::TargetFrameLowering::hasFP(), llvm::X86MachineFunctionInfo::hasSwiftAsyncContext(), I, llvm::X86MachineFunctionInfo::padForPush2Pop2(), llvm::reverse(), llvm::X86MachineFunctionInfo::setCalleeSavedFrameSize(), llvm::MachineFrameInfo::setCVBytesOfCalleeSavedRegisters(), llvm::X86MachineFunctionInfo::setHasSEHFramePtrSave(), llvm::X86MachineFunctionInfo::setPadForPush2Pop2(), llvm::X86MachineFunctionInfo::setRestoreBasePointer(), llvm::X86MachineFunctionInfo::setSEHFramePtrSaveIndex(), Size, SlotSize, STI, and TRI.

BuildCFI()

Wraps up getting a CFI index and building a MachineInstr for it.

Definition at line 479 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addCFIIndex(), llvm::MachineFunction::addFrameInst(), llvm::BuildMI(), DL, llvm::MachineFunction::getInfo(), llvm::MCCFIInstruction::getOperation(), MBB, MBBI, llvm::MCCFIInstruction::OpAdjustCfaOffset, llvm::MachineInstrBuilder::setMIFlag(), and TII.

Referenced by eliminateCallFramePseudoInstr(), emitCalleeSavedFrameMoves(), emitCalleeSavedFrameMovesFullCFA(), emitEpilogue(), emitPrologue(), and ExpandMOVImmSExti8().

canSimplifyCallFramePseudos()

canUseAsEpilogue()

canUseAsPrologue()

canUseLEAForSPInEpilogue()

determineCalleeSaves()

eliminateCallFramePseudoInstr()

This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy pseudo instructions (but only if the Target is using them).

It is responsible for eliminating these instructions, replacing them with concrete instructions. This method need only be implemented if using call frame setup/destroy pseudo instructions. Returns an iterator pointing to the instruction after the replaced one.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 3789 of file X86FrameLowering.cpp.

References llvm::alignTo(), B(), blockEndIsUnreachable(), BuildCFI(), llvm::MCCFIInstruction::createAdjustCfaOffset(), llvm::MCCFIInstruction::createGnuArgsSize(), DL, llvm::DwarfCFI, F, llvm::MachineFunction::getFunction(), llvm::X86MachineFunctionInfo::getHasPushSequences(), llvm::MachineFunction::getInfo(), llvm::MachineFunction::getLandingPads(), llvm::TargetMachine::getMCAsmInfo(), llvm::TargetFrameLowering::getStackAlign(), llvm::MachineFunction::getTarget(), llvm::TargetFrameLowering::hasFP(), hasReservedCallFrame(), I, MBB, llvm::MachineFunction::needsFrameMoves(), llvm::Offset, llvm::skipDebugInstructionsForward(), TII, and llvm::MCAsmInfo::usesWindowsCFI().

emitCalleeSavedFrameMoves()

Definition at line 517 of file X86FrameLowering.cpp.

References llvm::SmallString< InternalLen >::append(), BuildCFI(), llvm::MCCFIInstruction::createEscape(), llvm::MCCFIInstruction::createOffset(), llvm::MCCFIInstruction::createRestore(), DL, llvm::encodeSLEB128(), llvm::encodeULEB128(), FramePtr, llvm::MachineInstr::FrameSetup, llvm::MachineFrameInfo::getCalleeSavedInfo(), llvm::MachineFunction::getContext(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getInfo(), llvm::MachineFrameInfo::getObjectOffset(), llvm::MCContext::getRegisterInfo(), llvm::X86MachineFunctionInfo::getStackPtrSaveMI(), llvm::getX86SubSuperRegister(), I, MBB, MBBI, MI, MRI, llvm::Offset, llvm::SmallVectorTemplateBase< T, bool >::push_back(), Register, llvm::SmallVectorTemplateCommon< T, typename >::size(), SlotSize, STI, llvm::SmallString< InternalLen >::str(), and TRI.

Referenced by emitCalleeSavedFrameMovesFullCFA(), emitEpilogue(), and emitPrologue().

emitCalleeSavedFrameMovesFullCFA()

Emits Dwarf Info specifying offsets of callee saved registers and frame pointer.

This is called only when basic block sections are enabled.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 497 of file X86FrameLowering.cpp.

References BuildCFI(), llvm::MCCFIInstruction::createOffset(), emitCalleeSavedFrameMoves(), FramePtr, llvm::MachineFunction::getContext(), llvm::MCContext::getRegisterInfo(), llvm::getX86SubSuperRegister(), llvm::TargetFrameLowering::hasFP(), Is64Bit, MBB, MBBI, MRI, llvm::Offset, Register, STI, TRI, and Uses64BitFramePtr.

emitEpilogue()

Implements llvm::TargetFrameLowering.

Definition at line 2407 of file X86FrameLowering.cpp.

References llvm::addFrameReference(), llvm::MachineInstrBuilder::addImm(), llvm::MachineInstrBuilder::addReg(), llvm::addRegOffset(), llvm::MachineInstrBuilder::addUse(), llvm::alignTo(), assert(), BuildCFI(), llvm::BuildMI(), calculateSetFPREG(), llvm::MCCFIInstruction::cfiDefCfa(), llvm::MCCFIInstruction::cfiDefCfaOffset(), llvm::MCCFIInstruction::createRestore(), DL, emitCalleeSavedFrameMoves(), emitSPUpdate(), llvm::MachineInstr::FrameDestroy, FramePtr, llvm::X86MachineFunctionInfo::getAMXProgModel(), llvm::X86MachineFunctionInfo::getCalleeSavedFrameSize(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::MachineFunction::getInfo(), getLEArOpcode(), llvm::TargetMachine::getMCAsmInfo(), getPOPOpcode(), llvm::X86MachineFunctionInfo::getStackPtrSaveMI(), llvm::MachineFrameInfo::getStackSize(), llvm::MachineFunction::getSubtarget(), llvm::MachineFunction::getTarget(), llvm::TargetMachine::getTargetTriple(), llvm::X86MachineFunctionInfo::getTCReturnAddrDelta(), llvm::getX86SubSuperRegister(), llvm::TargetFrameLowering::hasFP(), llvm::X86MachineFunctionInfo::hasSwiftAsyncContext(), llvm::MachineFrameInfo::hasVarSizedObjects(), llvm::MachineFunction::hasWinCFI(), Is64Bit, llvm::isFuncletReturnInstr(), llvm::Triple::isOSWindows(), isTailCallOpcode(), llvm::Triple::isUEFI(), llvm::Register::isValid(), llvm::ManagedRA, MBB, MBBI, mergeSPAdd(), MI, llvm::MachineFunction::needsFrameMoves(), llvm::Function::needsUnwindTableEntry(), llvm::Offset, Opc, Register, llvm::MachineInstrBuilder::setMIFlag(), SlotSize, StackPtr, STI, TII, TRI, Uses64BitFramePtr, and llvm::MCAsmInfo::usesWindowsCFI().

emitPrologue()

emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.

emitPrologue - Push callee-saved registers onto the stack, which automatically adjust the stack pointer.

Adjust the stack pointer to allocate space for local variables. Also emit labels used by the exception handler to generate the exception handling frames.

Implements llvm::TargetFrameLowering.

Definition at line 1587 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addExternalSymbol(), llvm::addFrameReference(), llvm::MachineInstrBuilder::addImm(), llvm::MachineInstrBuilder::addMemOperand(), llvm::MachineInstrBuilder::addReg(), llvm::addRegOffset(), llvm::MachineInstrBuilder::addUse(), llvm::MachineFrameInfo::adjustsStack(), llvm::alignTo(), llvm::Alloc, llvm::Always, llvm::SmallString< InternalLen >::append(), llvm::Function::arg_size(), assert(), B(), BuildCFI(), llvm::BuildMI(), calculateSetFPREG(), llvm::MCCFIInstruction::cfiDefCfa(), llvm::MCCFIInstruction::cfiDefCfaOffset(), llvm::classifyEHPersonality(), contains(), llvm::CoreCLR, llvm::MCCFIInstruction::createDefCfaRegister(), llvm::MCCFIInstruction::createEscape(), llvm::MCCFIInstruction::createOffset(), llvm::DeploymentBased, DL, llvm::WinEHFuncInfo::EHRegNodeFrameIndex, emitCalleeSavedFrameMoves(), emitSPUpdate(), emitStackProbe(), llvm::encodeULEB128(), FramePtr, llvm::MachineInstr::FrameSetup, llvm::Function::getAttributes(), llvm::X86MachineFunctionInfo::getCalleeSavedFrameSize(), llvm::Function::getCallingConv(), llvm::Module::getCodeViewFlag(), llvm::StackOffset::getFixed(), llvm::MachinePointerInfo::getFixedStack(), getFrameIndexReference(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::X86MachineFunctionInfo::getHasSEHFramePtrSave(), llvm::MachineFunction::getInfo(), llvm::MachineFunction::getMachineMemOperand(), getMOVriOpcode(), llvm::GlobalValue::getParent(), llvm::Function::getPersonalityFn(), getPUSHOpcode(), llvm::MachineFunction::getRegInfo(), llvm::X86MachineFunctionInfo::getRestoreBasePointer(), llvm::X86MachineFunctionInfo::getRestoreBasePointerOffset(), llvm::X86MachineFunctionInfo::getSEHFramePtrSaveIndex(), llvm::X86MachineFunctionInfo::getStackPtrSaveMI(), llvm::MachineFrameInfo::getStackSize(), llvm::MachineFunction::getSubtarget(), llvm::MachineFunction::getTarget(), llvm::X86MachineFunctionInfo::getTCReturnAddrDelta(), llvm::X86MachineFunctionInfo::getUsesRedZone(), getWin64EHFrameIndexRef(), llvm::MachineFunction::getWinEHFuncInfo(), llvm::getX86SubSuperRegister(), has128ByteRedZone(), llvm::MachineFrameInfo::hasCopyImplyingStackAdjustment(), llvm::MachineFunction::hasEHFunclets(), llvm::TargetFrameLowering::hasFP(), llvm::Function::hasPersonalityFn(), llvm::X86MachineFunctionInfo::hasSwiftAsyncContext(), llvm::MachineFrameInfo::hasVarSizedObjects(), Is64Bit, llvm::isAsynchronousEHPersonality(), isEAXLiveIn(), isOpcodeRep(), llvm::MachineRegisterInfo::isReserved(), llvm::Register::isValid(), llvm::RegState::Kill, MBB, MBBI, MI, llvm::X86II::MO_GOTPCREL, llvm::MachineMemOperand::MOLoad, llvm::MachineMemOperand::MOStore, llvm::MachineMemOperand::MOVolatile, llvm::MSVC_CXX, llvm::Function::needsUnwindTableEntry(), llvm::Never, llvm::Offset, Opc, llvm::TargetMachine::Options, llvm::WinEHFuncInfo::PSPSymFrameIdx, llvm::SmallVectorTemplateBase< T, bool >::push_back(), Register, llvm::report_fatal_error(), restoreWin32EHStackPointers(), llvm::WinEHFuncInfo::SEHSetFrameOffset, llvm::MachineFunction::setHasWinCFI(), llvm::MachineInstrBuilder::setMIFlag(), llvm::MachineFrameInfo::setOffsetAdjustment(), llvm::MachineFrameInfo::setStackSize(), llvm::X86MachineFunctionInfo::setUsesRedZone(), llvm::MachineFunction::shouldSplitStack(), SlotSize, StackPtr, STI, llvm::SmallString< InternalLen >::str(), llvm::TargetOptions::SwiftAsyncFramePointer, TII, TRI, llvm::RegState::Undef, llvm::Unknown, Uses64BitFramePtr, and llvm::CallingConv::X86_INTR.

emitSPUpdate()

Emit a series of instructions to increment / decrement the stack pointer by a constant value.

emitSPUpdate - Emit a series of instructions to increment / decrement the stack pointer by a constant value.

Definition at line 232 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addImm(), llvm::MachineInstrBuilder::addReg(), llvm::addRegOffset(), assert(), llvm::BuildMI(), DL, llvm::MachineInstr::FrameDestroy, llvm::MachineInstr::FrameSetup, getADDrrOpcode(), llvm::getDefRegState(), getMOVriOpcode(), getSUBrrOpcode(), llvm::MachineFunction::getSubtarget(), llvm::getUndefRegState(), llvm::getX86SubSuperRegister(), Is64Bit, isEAXLiveIn(), llvm::isUInt(), llvm::RegState::Kill, MaxSPChunk, MBB, MBBI, MI, llvm::Offset, Opc, llvm::MachineInstrBuilder::setMIFlag(), SlotSize, StackPtr, STI, TII, TRI, and Uses64BitFramePtr.

Referenced by emitEpilogue(), emitPrologue(), and restoreCalleeSavedRegisters().

emitStackProbe()

enableShrinkWrapping()

getDwarfFrameBase()

Return the frame base information to be encoded in the DWARF subprogram debug info.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 4039 of file X86FrameLowering.cpp.

References llvm::MachineFunction::getFrameInfo(), llvm::TargetRegisterInfo::getFrameRegister(), llvm::MachineFunction::getInfo(), getInitialCFAOffset(), getInitialCFARegister(), llvm::TargetSubtargetInfo::getRegisterInfo(), llvm::MachineFrameInfo::getStackSize(), llvm::MachineFunction::getSubtarget(), llvm::X86MachineFunctionInfo::hasCFIAdjustCfa(), llvm::TargetFrameLowering::DwarfFrameBase::Kind, llvm::TargetFrameLowering::DwarfFrameBase::Location, and llvm::TargetFrameLowering::DwarfFrameBase::Offset.

getFrameIndexReference()

getFrameIndexReference - This method should return the base register and offset used to reference a frame index location.

Returns the displacement from the frame register to the stack frame of the specified index, along with the frame register used (in output arg FrameReg).

The offset is returned directly, and the base register is returned via FrameReg.

This is the default implementation which is overridden for some targets.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 2662 of file X86FrameLowering.cpp.

References assert(), calculateSetFPREG(), llvm::X86MachineFunctionInfo::getCalleeSavedFrameSize(), llvm::Function::getCallingConv(), llvm::X86MachineFunctionInfo::getFAIndex(), llvm::StackOffset::getFixed(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::MachineFunction::getInfo(), llvm::TargetMachine::getMCAsmInfo(), llvm::MachineFrameInfo::getObjectAlign(), llvm::MachineFrameInfo::getObjectOffset(), llvm::TargetFrameLowering::getOffsetOfLocalArea(), llvm::X86MachineFunctionInfo::getRestoreBasePointer(), llvm::MachineFrameInfo::getStackSize(), llvm::MachineFunction::getTarget(), llvm::X86MachineFunctionInfo::getTCReturnAddrDelta(), llvm::MachineFrameInfo::hasCalls(), llvm::isAligned(), llvm::MachineFrameInfo::isFixedObjectIndex(), llvm::Offset, SlotSize, TRI, llvm::MCAsmInfo::usesWindowsCFI(), and llvm::CallingConv::X86_INTR.

Referenced by llvm::X86RegisterInfo::eliminateFrameIndex(), emitPrologue(), getFrameIndexReferencePreferSP(), getWin64EHFrameIndexRef(), and restoreWin32EHStackPointers().

getFrameIndexReferencePreferSP()

Same as getFrameIndexReference, except that the stack pointer (as opposed to the frame pointer) will be the preferred value for FrameReg.

This is generally used for emitting statepoint or EH tables that use offsets from RSP. If IgnoreSPUpdates is true, the returned offset is only guaranteed to be valid with respect to the value of SP at the end of the prologue.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 2771 of file X86FrameLowering.cpp.

References assert(), getFrameIndexReference(), getFrameIndexReferenceSP(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getInfo(), llvm::MachineFrameInfo::getStackSize(), llvm::X86MachineFunctionInfo::getTCReturnAddrDelta(), hasReservedCallFrame(), llvm::MachineFrameInfo::isFixedObjectIndex(), STI, and TRI.

getFrameIndexReferenceSP()

getInitialCFAOffset()

getInitialCFARegister()

getWin64EHFrameIndexRef()

getWinEHParentFrameOffset()

has128ByteRedZone()

hasFPImpl()

hasFPImpl - Return true if the specified function should have a dedicated frame pointer register.

This is true if the function has variable sized allocas or if frame pointer elimination is disabled.

Implements llvm::TargetFrameLowering.

Definition at line 98 of file X86FrameLowering.cpp.

References llvm::MachineFunction::callsEHReturn(), llvm::MachineFunction::callsUnwindInit(), llvm::TargetOptions::DisableFramePointerElim(), llvm::X86MachineFunctionInfo::getForceFramePointer(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getInfo(), llvm::MachineFunction::getTarget(), llvm::MachineFrameInfo::hasCopyImplyingStackAdjustment(), llvm::MachineFunction::hasEHFunclets(), llvm::MachineFrameInfo::hasOpaqueSPAdjustment(), llvm::MachineFrameInfo::hasPatchPoint(), llvm::X86MachineFunctionInfo::hasPreallocatedCall(), llvm::MachineFrameInfo::hasStackMap(), llvm::MachineFrameInfo::hasVarSizedObjects(), llvm::MachineFrameInfo::isFrameAddressTaken(), llvm::TargetMachine::Options, and TRI.

hasReservedCallFrame()

inlineStackProbe()

mergeSPAdd()

needsFrameIndexResolution()

orderFrameObjects()

Order the symbols in the local stack.

We want to place the local stack objects in some sort of sensible order. The heuristic we use is to try and pack them according to static number of uses and size in order to minimize code size.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 4125 of file X86FrameLowering.cpp.

References llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::SmallVectorTemplateCommon< T, typename >::end(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFrameInfo::getObjectAlign(), llvm::MachineFrameInfo::getObjectIndexEnd(), llvm::MachineFrameInfo::getObjectSize(), llvm::TargetFrameLowering::hasFP(), MBB, MI, llvm::stable_sort(), and TRI.

processFunctionBeforeFrameFinalized()

processFunctionBeforeFrameFinalized - This method is called immediately before the specified function's frame layout (MF.getFrameInfo()) is finalized.

Once the frame is finalized, MO_FrameIndex operands are replaced with direct constants. This method is optional.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 4209 of file X86FrameLowering.cpp.

References llvm::classifyEHPersonality(), llvm::MachineFrameInfo::CreateStackObject(), llvm::MachineFrameInfo::ensureMaxAlignment(), llvm::MachineFrameInfo::estimateStackSize(), llvm::MachineFunction::getFrameInfo(), llvm::MachineFunction::getFunction(), llvm::TargetMachine::getMCAsmInfo(), llvm::Function::getPersonalityFn(), llvm::MachineFunction::getTarget(), llvm::MachineFunction::hasEHFunclets(), llvm::isInt(), llvm::MSVC_CXX, llvm::MachineFunction::setHasWinCFI(), SlotSize, STI, and llvm::MCAsmInfo::usesWindowsCFI().

processFunctionBeforeFrameIndicesReplaced()

restoreCalleeSavedRegisters()

restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns true if it isn't possible / profitable to do so by issuing a series of load instructions via loadRegToStackSlot().

If it returns true, and any of the registers in CSI is not restored, it sets the corresponding Restored flag in CSI to false. Returns false otherwise.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 3133 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addReg(), llvm::MutableArrayRef< T >::begin(), llvm::BuildMI(), llvm::classifyEHPersonality(), contains(), llvm::RegState::Define, DL, emitSPUpdate(), llvm::ArrayRef< T >::empty(), llvm::MutableArrayRef< T >::end(), F, llvm::MachineInstr::FrameDestroy, llvm::MachineFunction::getInfo(), getPOP2Opcode(), getPOPOpcode(), getReg(), llvm::X86MachineFunctionInfo::getRestoreBasePointer(), I, llvm::isAsynchronousEHPersonality(), llvm::X86MachineFunctionInfo::isCandidateForPush2Pop2(), llvm::isFuncletReturnInstr(), MBB, MI, Opc, llvm::X86MachineFunctionInfo::padForPush2Pop2(), llvm::MachineInstrBuilder::setMIFlag(), SlotSize, STI, TII, and TRI.

restoreWin32EHStackPointers()

Sets up EBP and optionally ESI based on the incoming EBP value.

Only needed for 32-bit. Used in funclet prologues and at catchret destinations.

Definition at line 3966 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addImm(), llvm::MachineInstrBuilder::addReg(), llvm::addRegOffset(), assert(), llvm::BuildMI(), DL, llvm::WinEHFuncInfo::EHRegNodeEndOffset, llvm::WinEHFuncInfo::EHRegNodeFrameIndex, FramePtr, llvm::MachineInstr::FrameSetup, getADDriOpcode(), llvm::StackOffset::getFixed(), getFrameIndexReference(), llvm::MachineFunction::getFrameInfo(), llvm::X86MachineFunctionInfo::getHasSEHFramePtrSave(), llvm::MachineFunction::getInfo(), llvm::MachineInstr::getOperand(), llvm::X86MachineFunctionInfo::getSEHFramePtrSaveIndex(), llvm::MachineFunction::getWinEHFuncInfo(), llvm_unreachable, MBB, MBBI, llvm::Offset, llvm::MachineOperand::setIsDead(), llvm::MachineInstrBuilder::setMIFlag(), STI, TII, TRI, and Uses64BitFramePtr.

Referenced by emitPrologue(), and restoreWinEHStackPointersInParent().

restoreWinEHStackPointersInParent()

void X86FrameLowering::restoreWinEHStackPointersInParent ( MachineFunction & MF ) const

spillCalleeSavedRegisters()

spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns true if it isn't possible / profitable to do so by issuing a series of store instructions via storeRegToStackSlot().

Returns false otherwise.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 3012 of file X86FrameLowering.cpp.

References llvm::MachineInstrBuilder::addReg(), assert(), llvm::BuildMI(), contains(), DL, llvm::MachineInstr::FrameSetup, llvm::MachineFunction::getInfo(), llvm::getKillRegState(), getPUSH2Opcode(), getPUSHOpcode(), getReg(), llvm::MachineFunction::getRegInfo(), llvm::X86MachineFunctionInfo::getRestoreBasePointer(), I, llvm::X86MachineFunctionInfo::isCandidateForPush2Pop2(), llvm::MCRegAliasIterator::isValid(), MBB, MI, MRI, Opc, llvm::X86MachineFunctionInfo::padForPush2Pop2(), llvm::ArrayRef< T >::rbegin(), llvm::ArrayRef< T >::rend(), llvm::reverse(), llvm::MachineInstrBuilder::setMIFlag(), SlotSize, STI, TII, TRI, and llvm::RegState::Undef.

spillFPBP()

void X86FrameLowering::spillFPBP ( MachineFunction & MF) const overridevirtual

If a function uses base pointer and the base pointer is clobbered by inline asm, RA doesn't detect this case, and after the inline asm, the base pointer contains garbage value.

For example if a 32b x86 function uses base pointer esi, and esi is clobbered by following inline asm asm("rep movsb" : "+D"(ptr), "+S"(x), "+c"(c)::"memory"); We need to save esi before the asm and restore it after the asm.

The problem can also occur to frame pointer if there is a function call, and the callee uses a different calling convention and clobbers the fp.

Because normal frame objects (spill slots) are accessed through fp/bp register, so we can't spill fp/bp to normal spill slots.

FIXME: There are 2 possible enhancements:

  1. In many cases there are different physical registers not clobbered by inline asm, we can use one of them as base pointer. Or use a virtual register as base pointer and let RA allocate a physical register to it.
  2. If there is no other instructions access stack with fp/bp from the inline asm to the epilog, and no cfi requirement for a correct fp, we can skip the save and restore operations.

Reimplemented from llvm::TargetFrameLowering.

Definition at line 4561 of file X86FrameLowering.cpp.

References DefMI, FP, llvm::MachineInstr::FrameDestroy, llvm::MachineInstr::FrameSetup, llvm::X86MachineFunctionInfo::getBPClobberedByCall(), llvm::X86MachineFunctionInfo::getFPClobberedByCall(), llvm::TargetSubtargetInfo::getFrameLowering(), llvm::MachineFunction::getInfo(), llvm::MachineFunction::getSubtarget(), llvm::TargetFrameLowering::hasFP(), llvm::MachineFunction::hasInlineAsm(), isFPBPAccess(), isInvoke(), MBB, MI, llvm::TargetFrameLowering::TargetFrameLowering(), TII, and TRI.

stackProbeFunctionModifiesSP()

bool X86FrameLowering::stackProbeFunctionModifiesSP ( ) const overridevirtual

Is64Bit

bool llvm::X86FrameLowering::Is64Bit

IsLP64

bool llvm::X86FrameLowering::IsLP64

SlotSize

unsigned llvm::X86FrameLowering::SlotSize

Definition at line 38 of file X86FrameLowering.h.

Referenced by adjustForHiPEPrologue(), assignCalleeSavedSpillSlots(), emitCalleeSavedFrameMoves(), emitEpilogue(), emitPrologue(), emitSPUpdate(), getFrameIndexReference(), getWinEHParentFrameOffset(), processFunctionBeforeFrameFinalized(), restoreCalleeSavedRegisters(), spillCalleeSavedRegisters(), and X86FrameLowering().

StackPtr

Register llvm::X86FrameLowering::StackPtr

STI

Definition at line 34 of file X86FrameLowering.h.

Referenced by adjustForHiPEPrologue(), adjustForSegmentedStacks(), assignCalleeSavedSpillSlots(), canUseAsEpilogue(), canUseAsPrologue(), determineCalleeSaves(), emitCalleeSavedFrameMoves(), emitCalleeSavedFrameMovesFullCFA(), emitEpilogue(), emitPrologue(), emitSPUpdate(), emitStackProbe(), getFrameIndexReferencePreferSP(), has128ByteRedZone(), processFunctionBeforeFrameFinalized(), processFunctionBeforeFrameIndicesReplaced(), restoreCalleeSavedRegisters(), restoreWin32EHStackPointers(), spillCalleeSavedRegisters(), stackProbeFunctionModifiesSP(), and X86FrameLowering().

TII

Definition at line 35 of file X86FrameLowering.h.

Referenced by adjustForHiPEPrologue(), adjustForSegmentedStacks(), BuildCFI(), eliminateCallFramePseudoInstr(), emitEpilogue(), emitPrologue(), emitSPUpdate(), emitStackProbe(), restoreCalleeSavedRegisters(), restoreWin32EHStackPointers(), spillCalleeSavedRegisters(), spillFPBP(), and X86FrameLowering().

TRI

Definition at line 36 of file X86FrameLowering.h.

Referenced by assignCalleeSavedSpillSlots(), canSimplifyCallFramePseudos(), canUseAsPrologue(), determineCalleeSaves(), emitCalleeSavedFrameMoves(), emitCalleeSavedFrameMovesFullCFA(), emitEpilogue(), emitPrologue(), emitSPUpdate(), getFrameIndexReference(), getFrameIndexReferencePreferSP(), getFrameIndexReferenceSP(), getInitialCFAOffset(), getWin64EHFrameIndexRef(), hasFPImpl(), orderFrameObjects(), restoreCalleeSavedRegisters(), restoreWin32EHStackPointers(), spillCalleeSavedRegisters(), spillFPBP(), and X86FrameLowering().

Uses64BitFramePtr

bool llvm::X86FrameLowering::Uses64BitFramePtr


The documentation for this class was generated from the following files: