Path: blob/main/contrib/llvm-project/llvm/lib/Target/M68k/M68kFrameLowering.h
35268 views
//===-- M68kFrameLowering.h - Define frame lowering for M68k ----*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file contains the M68k declaration of TargetFrameLowering class.10///11//===----------------------------------------------------------------------===//1213#ifndef LLVM_LIB_TARGET_M68K_M68KFRAMELOWERING_H14#define LLVM_LIB_TARGET_M68K_M68KFRAMELOWERING_H1516#include "M68k.h"1718#include "llvm/CodeGen/TargetFrameLowering.h"1920namespace llvm {21class MachineInstrBuilder;22class MCCFIInstruction;23class M68kSubtarget;24class M68kRegisterInfo;25struct Align;2627class M68kFrameLowering : public TargetFrameLowering {28// Cached subtarget predicates.29const M68kSubtarget &STI;30const TargetInstrInfo &TII;31const M68kRegisterInfo *TRI;3233/// Stack slot size in bytes.34unsigned SlotSize;3536unsigned StackPtr;3738/// If we're forcing a stack realignment we can't rely on just the frame39/// info, we need to know the ABI stack alignment as well in case we have a40/// call out. Otherwise just make sure we have some alignment - we'll go41/// with the minimum SlotSize.42uint64_t calculateMaxStackAlign(const MachineFunction &MF) const;4344/// Adjusts the stack pointer using LEA, SUB, or ADD.45MachineInstrBuilder BuildStackAdjustment(MachineBasicBlock &MBB,46MachineBasicBlock::iterator MBBI,47const DebugLoc &DL, int64_t Offset,48bool InEpilogue) const;4950/// Aligns the stack pointer by ANDing it with -MaxAlign.51void BuildStackAlignAND(MachineBasicBlock &MBB,52MachineBasicBlock::iterator MBBI, const DebugLoc &DL,53unsigned Reg, uint64_t MaxAlign) const;5455/// Wraps up getting a CFI index and building a MachineInstr for it.56void BuildCFI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,57const DebugLoc &DL, const MCCFIInstruction &CFIInst) const;5859void emitPrologueCalleeSavedFrameMoves(MachineBasicBlock &MBB,60MachineBasicBlock::iterator MBBI,61const DebugLoc &DL) const;6263unsigned getPSPSlotOffsetFromSP(const MachineFunction &MF) const;6465public:66explicit M68kFrameLowering(const M68kSubtarget &sti, Align Alignment);6768static const M68kFrameLowering *create(const M68kSubtarget &ST);6970/// This method is called during prolog/epilog code insertion to eliminate71/// call frame setup and destroy pseudo instructions (but only if the Target72/// is using them). It is responsible for eliminating these instructions,73/// replacing them with concrete instructions. This method need only be74/// implemented if using call frame setup/destroy pseudo instructions.75/// Returns an iterator pointing to the instruction after the replaced one.76MachineBasicBlock::iterator77eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,78MachineBasicBlock::iterator MI) const override;7980/// Insert prolog code into the function.81void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;8283/// Insert epilog code into the function.84void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;8586/// This method determines which of the registers reported by87/// TargetRegisterInfo::getCalleeSavedRegs() should actually get saved.88/// The default implementation checks populates the \p SavedRegs bitset with89/// all registers which are modified in the function, targets may override90/// this function to save additional registers.91/// This method also sets up the register scavenger ensuring there is a free92/// register or a frameindex available.93void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,94RegScavenger *RS = nullptr) const override;9596/// Allows target to override spill slot assignment logic. If implemented,97/// assignCalleeSavedSpillSlots() should assign frame slots to all CSI98/// entries and return true. If this method returns false, spill slots will99/// be assigned using generic implementation. assignCalleeSavedSpillSlots()100/// may add, delete or rearrange elements of CSI.101bool102assignCalleeSavedSpillSlots(MachineFunction &MF,103const TargetRegisterInfo *TRI,104std::vector<CalleeSavedInfo> &CSI) const override;105106/// Issues instruction(s) to spill all callee saved registers and returns107/// true if it isn't possible / profitable to do so by issuing a series of108/// store instructions via storeRegToStackSlot(). Returns false otherwise.109bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,110MachineBasicBlock::iterator MI,111ArrayRef<CalleeSavedInfo> CSI,112const TargetRegisterInfo *TRI) const override;113114/// Issues instruction(s) to restore all callee saved registers and returns115/// true if it isn't possible / profitable to do so by issuing a series of116/// load instructions via loadRegToStackSlot(). Returns false otherwise.117bool118restoreCalleeSavedRegisters(MachineBasicBlock &MBB,119MachineBasicBlock::iterator MI,120MutableArrayRef<CalleeSavedInfo> CSI,121const TargetRegisterInfo *TRI) const override;122123/// Return true if the specified function should have a dedicated frame124/// pointer register. This is true if the function has variable sized125/// allocas, if it needs dynamic stack realignment, if frame pointer126/// elimination is disabled, or if the frame address is taken.127bool hasFP(const MachineFunction &MF) const override;128129/// Under normal circumstances, when a frame pointer is not required, we130/// reserve argument space for call sites in the function immediately on131/// entry to the current function. This eliminates the need for add/sub sp132/// brackets around call sites. Returns true if the call frame is included as133/// part of the stack frame.134bool hasReservedCallFrame(const MachineFunction &MF) const override;135136/// If there is a reserved call frame, the call frame pseudos can be137/// simplified. Having a FP, as in the default implementation, is not138/// sufficient here since we can't always use it. Use a more nuanced139/// condition.140bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override;141142// Do we need to perform FI resolution for this function. Normally, this is143// required only when the function has any stack objects. However, FI144// resolution actually has another job, not apparent from the title - it145// resolves callframe setup/destroy that were not simplified earlier.146//147// So, this is required for M68k functions that have push sequences even148// when there are no stack objects.149bool needsFrameIndexResolution(const MachineFunction &MF) const override;150151/// This method should return the base register and offset used to reference152/// a frame index location. The offset is returned directly, and the base153/// register is returned via FrameReg.154StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,155Register &FrameReg) const override;156157/// Check the instruction before/after the passed instruction. If158/// it is an ADD/SUB/LEA instruction it is deleted argument and the159/// stack adjustment is returned as a positive value for ADD/LEA and160/// a negative for SUB.161int mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,162bool doMergeWithPrevious) const;163164/// Emit a series of instructions to increment / decrement the stack165/// pointer by a constant value.166void emitSPUpdate(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI,167int64_t NumBytes, bool InEpilogue) const;168};169} // namespace llvm170171#endif // LLVM_LIB_TARGET_M68K_M68KFRAMELOWERING_H172173174