Go to the documentation of this file.
38 TII(*STI.getInstrInfo()),
TRI(STI.getRegisterInfo()) {
61 (
hasFP(MF) && !TRI->hasStackRealignment(MF)) ||
85 else if (TRI->hasStackRealignment(MF))
97 bool HasFP =
hasFP(MF);
101 assert(HasFP &&
"VLAs and dynamic stack realign, but no FP?!");
110 if (TRI->hasStackRealignment(MF)) {
128 if (TailCallReturnAddrDelta < 0)
129 Offset -= TailCallReturnAddrDelta;
149 switch (
MBBI->getOpcode()) {
152 case TargetOpcode::PATCHABLE_RET:
156 for (
unsigned i = 0,
e =
MBBI->getNumOperands();
i !=
e; ++
i) {
167 for (
auto CS : AvailableRegs)
179 return RegMask.PhysReg == Reg;
184 M68kFrameLowering::calculateMaxStackAlign(
const MachineFunction &MF)
const {
191 else if (MaxAlign < SlotSize)
202 unsigned AndOp = M68k::AND32di;
203 unsigned MovOp = M68k::MOV32rr;
208 unsigned Tmp = M68k::D0;
220 MI->getOperand(3).setIsDead();
231 unsigned Opcode =
I->getOpcode();
234 uint64_t Amount = !ReserveCallFrame ?
I->getOperand(0).getImm() : 0;
235 uint64_t InternalAmt = (IsDestroy && Amount) ?
I->getOperand(1).getImm() : 0;
238 if (!ReserveCallFrame) {
262 if (HasDwarfEHHandlers && !IsDestroy &&
273 Amount -= InternalAmt;
318 if (IsDestroy && InternalAmt) {
327 while (CI !=
B && !std::prev(CI)->isCall())
329 BuildStackAdjustment(
MBB, CI,
DL, -InternalAmt,
false);
339 int64_t NumBytes,
bool InEpilogue)
const {
340 bool IsSub = NumBytes < 0;
341 uint64_t Offset = IsSub ? -NumBytes : NumBytes;
347 if (Offset > Chunk) {
358 unsigned Opc = M68k::MOV32ri;
360 Opc = IsSub ? M68k::SUB32ar : M68k::ADD32ar;
365 MI->getOperand(3).setIsDead();
374 MBB,
MBBI,
DL, IsSub ? -ThisVal : ThisVal, InEpilogue);
386 bool MergeWithPrevious)
const {
393 MergeWithPrevious ? nullptr : std::next(
MBBI);
394 unsigned Opc = PI->getOpcode();
397 if (!MergeWithPrevious && NI !=
MBB.
end() &&
398 NI->getOpcode() == TargetOpcode::CFI_INSTRUCTION) {
403 if (Opc == M68k::ADD32ai && PI->getOperand(0).getReg() == StackPtr) {
404 assert(PI->getOperand(1).getReg() == StackPtr);
405 Offset += PI->getOperand(2).getImm();
407 if (!MergeWithPrevious)
409 }
else if (Opc == M68k::SUB32ai && PI->getOperand(0).getReg() == StackPtr) {
410 assert(PI->getOperand(1).getReg() == StackPtr);
411 Offset -= PI->getOperand(2).getImm();
413 if (!MergeWithPrevious)
422 const DebugLoc &
DL, int64_t Offset,
bool InEpilogue)
const {
423 assert(Offset != 0 &&
"zero offset stack adjustment requested");
427 bool IsSub = Offset < 0;
428 uint64_t AbsOffset = IsSub ? -Offset : Offset;
429 unsigned Opc = IsSub ? M68k::SUB32ai : M68k::ADD32ai;
436 MI->getOperand(3).setIsDead();
450 void M68kFrameLowering::emitPrologueCalleeSavedFrameMoves(
464 for (
const auto &
I : CSI) {
468 unsigned DwarfReg =
MRI->getDwarfRegNum(
Reg,
true);
477 "MF used frame lowering for wrong subtarget");
484 uint64_t MaxAlign = calculateMaxStackAlign(MF);
486 bool HasFP =
hasFP(MF);
487 bool NeedsDwarfCFI = MMI.
hasDebugInfo() || Fn.needsUnwindTableEntry();
489 const unsigned MachineFramePtr = FramePtr;
499 if (TailCallReturnAddrDelta < 0) {
501 TailCallReturnAddrDelta);
507 if (TailCallReturnAddrDelta < 0) {
508 BuildStackAdjustment(
MBB,
MBBI,
DL, TailCallReturnAddrDelta,
528 int stackGrowth = -SlotSize;
532 uint64_t FrameSize = StackSize - SlotSize;
536 FrameSize += SlotSize;
541 if (TRI->hasStackRealignment(MF))
542 NumBytes =
alignTo(NumBytes, MaxAlign);
562 int DwarfFramePtr = TRI->getDwarfRegNum(MachineFramePtr,
true);
563 assert(DwarfFramePtr > 0);
577 unsigned DwarfFramePtr = TRI->getDwarfRegNum(MachineFramePtr,
true);
585 EveryMBB.addLiveIn(MachineFramePtr);
591 bool PushedRegs =
false;
595 MBBI->getOpcode() == M68k::PUSH32r) {
599 if (!HasFP && NeedsDwarfCFI) {
611 if (TRI->hasStackRealignment(MF)) {
612 assert(HasFP &&
"There should be a frame pointer if stack is realigned.");
613 BuildStackAlignAND(
MBB,
MBBI,
DL, StackPtr, MaxAlign);
624 unsigned SPOrEstablisher = StackPtr;
638 unsigned Opm = M68k::MOV32ja;
647 if (((!HasFP && NumBytes) || PushedRegs) && NeedsDwarfCFI) {
649 if (!HasFP && NumBytes) {
659 emitPrologueCalleeSavedFrameMoves(
MBB,
MBBI,
DL);
672 return Opc == M68k::TCRETURNj || Opc == M68k::TCRETURNq;
682 RetOpcode =
MBBI->getOpcode();
687 unsigned MachineFramePtr = FramePtr;
691 uint64_t MaxAlign = calculateMaxStackAlign(MF);
697 uint64_t FrameSize = StackSize - SlotSize;
698 NumBytes = FrameSize - CSSize;
702 if (TRI->hasStackRealignment(MF))
703 NumBytes =
alignTo(FrameSize, MaxAlign);
709 NumBytes = StackSize - CSSize;
715 unsigned Opc = PI->getOpcode();
718 Opc != M68k::DBG_VALUE && !PI->isTerminator())
738 if (TRI->hasStackRealignment(MF))
745 if (LEAAmount != 0) {
746 unsigned Opc = M68k::LEA32p;
752 unsigned Opc = (M68k::MOV32rr);
756 }
else if (NumBytes) {
765 assert(Offset >= 0 &&
"TCDelta should never be positive");
786 if (TailCallReturnAddrDelta < 0) {
797 TailCallReturnAddrDelta - SlotSize,
true);
808 std::vector<CalleeSavedInfo> &CSI)
const {
816 SpillSlotOffset -= SlotSize;
823 for (
unsigned i = 0,
e = CSI.size();
i <
e; ++
i) {
825 CSI.erase(CSI.begin() +
i);
843 for (
const auto &
Info : CSI) {
858 for (
const auto &
Info : CSI) {
878 for (
const auto &
Info : CSI) {
890 for (
const auto &
Info : CSI) {
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Insert epilog code into the function.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
This is an optimization pass for GlobalISel generic memory operations.
M68kFrameLowering(const M68kSubtarget &sti, Align Alignment)
Information about stack frame layout on the target.
bool getHasPushSequences() const
const MCContext & getContext() const
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, int64_t NumBytes, bool InEpilogue) const
Emit a series of instructions to increment / decrement the stack pointer by a constant value.
const MCRegisterInfo * getRegisterInfo() const
const MachineInstrBuilder & addCFIIndex(unsigned CFIIndex) const
static const MachineInstrBuilder & addMemOperand(const MachineInstrBuilder &MIB, int FI, int Offset=0)
static bool isTailCallOpcode(unsigned Opc)
Reg
All possible values of the reg field in the ModR/M byte.
int getTCReturnAddrDelta() const
bool hasDebugInfo() const
Returns true if valid debug info is present.
unsigned getStackRegister() const
DebugLoc findDebugLoc(instr_iterator MBBI)
Find the next valid DebugLoc starting at MBBI, skipping any DBG_VALUE and DBG_LABEL instructions.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
ScalarTy getFixed() const
iterator_range< livein_iterator > liveins() const
int getRestoreBasePointerOffset() const
SmallSet - This maintains a set of unique values, optimizing for the case when the set is small (less...
const M68kRegisterInfo * getRegisterInfo() const override
unsigned const TargetRegisterInfo * TRI
bool needsFrameIndexResolution(const MachineFunction &MF) const override
Register getFrameRegister(const MachineFunction &MF) const override
static MCCFIInstruction cfiDefCfaOffset(MCSymbol *L, int Offset)
.cfi_def_cfa_offset modifies a rule for computing CFA.
SmallPtrSet< MachineInstr *, 2 > Uses
instr_iterator erase(instr_iterator I)
Remove an instruction from the instruction list and delete it.
bool hasStackObjects() const
Return true if there are any stack objects in this function.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
unsigned getStackAlignment() const
getStackAlignment - This method returns the number of bytes to which the stack pointer must be aligne...
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
int getOffsetOfLocalArea() const
getOffsetOfLocalArea - This method returns the offset of the local area from the stack pointer on ent...
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const HexagonInstrInfo * TII
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
MachineOperand class - Representation of each machine instruction operand.
Pair of physical register and lane mask.
This class contains meta information specific to a module.
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
Issues instruction(s) to restore all callee saved registers and returns true if it isn't possible / p...
uint64_t getStackSize() const
Return the number of bytes that must be allocated to hold all of the fixed size frame objects.
int64_t getObjectOffset(int ObjectIdx) const
Return the assigned stack offset of the specified object from the incoming stack pointer.
Analysis containing CSE Info
static const MachineInstrBuilder & addFrameReference(const MachineInstrBuilder &MIB, int FI, int Offset=0)
addFrameReference - This function is used to add a reference to the base of an abstract object on the...
bool hasFP(const MachineFunction &MF) const override
Return true if the specified function should have a dedicated frame pointer register.
This struct is a compact representation of a valid (non-zero power of two) alignment.
static const MachineInstrBuilder & addRegIndirectWithDisp(const MachineInstrBuilder &MIB, Register Reg, bool IsKill, int Offset)
addRegIndirectWithDisp - This function is used to add a memory reference of the form (Offset,...
static MCCFIInstruction createDefCfaRegister(MCSymbol *L, unsigned Register)
.cfi_def_cfa_register modifies a rule for computing CFA.
@ Implicit
Not emitted register (e.g. carry, or temporary result).
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
MachineModuleInfo & getMMI() const
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
const MachineInstrBuilder & setMIFlag(MachineInstr::MIFlag Flag) const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
int CreateFixedSpillStackObject(uint64_t Size, int64_t SPOffset, bool IsImmutable=false)
Create a spill slot at a fixed location on the stack.
bool regsOverlap(Register RegA, Register RegB) const
Returns true if the two registers are equal or alias each other.
unsigned getCalleeSavedFrameSize() const
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
Issues instruction(s) to spill all callee saved registers and returns true if it isn't possible / pro...
bool isReg() const
isReg - Tests if this is a MO_Register operand.
Representation of each machine instruction.
bool callsEHReturn() const
static unsigned findDeadCallerSavedReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, const M68kRegisterInfo *TRI)
Return a caller-saved register that isn't live when it reaches the "return" instruction.
static MCCFIInstruction createGnuArgsSize(MCSymbol *L, int Size)
A special wrapper for .cfi_escape that indicates GNU_ARGS_SIZE.
static bool isRegLiveIn(MachineBasicBlock &MBB, unsigned Reg)
virtual Register getFrameRegister(const MachineFunction &MF) const =0
Debug information queries.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
int CreateFixedObject(uint64_t Size, int64_t SPOffset, bool IsImmutable, bool isAliased=false)
Create a new object at a fixed location on the stack.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
const std::vector< LandingPadInfo > & getLandingPads() const
Return a reference to the landing pad info for the current function.
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
Register getReg() const
getReg - Returns the register number.
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
This method should return the base register and offset used to reference a frame index location.
const std::vector< CalleeSavedInfo > & getCalleeSavedInfo() const
Returns a reference to call saved info vector for the current function.
iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
bool getRestoreBasePointer() const
MachineBasicBlock MachineBasicBlock::iterator MBBI
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
Allows target to override spill slot assignment logic.
StackOffset is a class to represent an offset with 2 dimensions, named fixed and scalable,...
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static MCCFIInstruction createAdjustCfaOffset(MCSymbol *L, int Adjustment)
.cfi_adjust_cfa_offset Same as .cfi_def_cfa_offset, but Offset is a relative value that is added/subt...
unsigned getSlotSize() const
getSlotSize - Stack slot size in bytes.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
unsigned const MachineRegisterInfo * MRI
Align getMaxAlign() const
Return the alignment in bytes that this function must be aligned to, which is greater than the defaul...
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 p...
Wrapper class representing virtual and physical registers.
void addLiveIn(MCRegister PhysReg, LaneBitmask LaneMask=LaneBitmask::getAll())
Adds the specified register as a live in.
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
bool hasCalls() const
Return true if the current function has any function calls.
unsigned getCallFrameDestroyOpcode() const
bool isLiveIn(Register Reg) const
void setCalleeSavedFrameSize(unsigned bytes)
Function & getFunction()
Return the LLVM function that this machine code represents.
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
If there is a reserved call frame, the call frame pseudos can be simplified.
bool hasBasePointer(const MachineFunction &MF) const
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
uint64_t value() const
This is a hole in the type system and should not be abused.
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
LLVM_NODISCARD unsigned addFrameInst(const MCCFIInstruction &Inst)
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool hasReservedCallFrame(const MachineFunction &MF) const override
Under normal circumstances, when a frame pointer is not required, we reserve argument space for call ...
uint16_t StackAdjustment(const RuntimeFunction &RF)
StackAdjustment - calculated stack adjustment in words.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
Align max(MaybeAlign Lhs, Align Rhs)
int mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI, bool doMergeWithPrevious) const
Check the instruction before/after the passed instruction.
void setOffsetAdjustment(int Adj)
Set the correction for frame offsets.
static MCCFIInstruction createOffset(MCSymbol *L, unsigned Register, int Offset)
.cfi_offset Previous value of Register is saved at offset Offset from CFA.
unsigned getBaseRegister() const
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode.
virtual void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS=nullptr) const
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Insert prolog code into the function.
@ Kill
The last use of a register.
MachineBasicBlock iterator that automatically skips over MIs that are inside bundles (i....
@ DwarfCFI
DWARF-like instruction based exceptions.
MCRegAliasIterator enumerates all registers aliasing Reg.