Path: blob/main/contrib/llvm-project/llvm/lib/Target/PowerPC/PPCFrameLowering.h
35294 views
//===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- 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//9//===----------------------------------------------------------------------===//1011#ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H12#define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H1314#include "llvm/ADT/STLExtras.h"15#include "llvm/CodeGen/TargetFrameLowering.h"16#include "llvm/Target/TargetMachine.h"1718namespace llvm {19class PPCSubtarget;2021class PPCFrameLowering: public TargetFrameLowering {22const PPCSubtarget &Subtarget;23const uint64_t ReturnSaveOffset;24const uint64_t TOCSaveOffset;25const uint64_t FramePointerSaveOffset;26const unsigned LinkageSize;27const uint64_t BasePointerSaveOffset;28const uint64_t CRSaveOffset;2930// Map each group of one or two GPRs to corresponding VSR for spilling.31// TODO: Use local table in methods to avoid this mutable member.32mutable DenseMap<unsigned, std::pair<Register, Register>> VSRContainingGPRs;3334/**35* Find register[s] that can be used in function prologue and epilogue36*37* Find register[s] that can be use as scratch register[s] in function38* prologue and epilogue to save various registers (Link Register, Base39* Pointer, etc.). Prefer R0/R12, if available. Otherwise choose whatever40* register[s] are available.41*42* This method will return true if it is able to find enough unique scratch43* registers (1 or 2 depending on the requirement). If it is unable to find44* enough available registers in the block, it will return false and set45* any passed output parameter that corresponds to a required unique register46* to PPC::NoRegister.47*48* \param[in] MBB The machine basic block to find an available register for49* \param[in] UseAtEnd Specify whether the scratch register will be used at50* the end of the basic block (i.e., will the scratch51* register kill a register defined in the basic block)52* \param[in] TwoUniqueRegsRequired Specify whether this basic block will53* require two unique scratch registers.54* \param[out] SR1 The scratch register to use55* \param[out] SR2 The second scratch register. If this pointer is not null56* the function will attempt to set it to an available57* register regardless of whether there is a hard requirement58* for two unique scratch registers.59* \return true if the required number of registers was found.60* false if the required number of scratch register weren't available.61* If either output parameter refers to a required scratch register62* that isn't available, it will be set to an invalid value.63*/64bool findScratchRegister(MachineBasicBlock *MBB,65bool UseAtEnd,66bool TwoUniqueRegsRequired = false,67Register *SR1 = nullptr,68Register *SR2 = nullptr) const;69bool twoUniqueScratchRegsRequired(MachineBasicBlock *MBB) const;7071/**72* Create branch instruction for PPC::TCRETURN* (tail call return)73*74* \param[in] MBB that is terminated by PPC::TCRETURN*75*/76void createTailCallBranchInstr(MachineBasicBlock &MBB) const;7778/**79* Check if the conditions are correct to allow for the stack update80* to be moved past the CSR save/restore code.81*/82bool stackUpdateCanBeMoved(MachineFunction &MF) const;8384public:85PPCFrameLowering(const PPCSubtarget &STI);8687/**88* Determine the frame layout and update the machine function.89*/90uint64_t determineFrameLayoutAndUpdate(MachineFunction &MF,91bool UseEstimate = false) const;9293/**94* Determine the frame layout but do not update the machine function.95* The MachineFunction object can be const in this case as it is not96* modified.97*/98uint64_t determineFrameLayout(const MachineFunction &MF,99bool UseEstimate = false,100unsigned *NewMaxCallFrameSize = nullptr) const;101102/// emitProlog/emitEpilog - These methods insert prolog and epilog code into103/// the function.104void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;105void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;106void inlineStackProbe(MachineFunction &MF,107MachineBasicBlock &PrologMBB) const override;108109bool hasFP(const MachineFunction &MF) const override;110bool needsFP(const MachineFunction &MF) const;111void replaceFPWithRealFP(MachineFunction &MF) const;112113void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,114RegScavenger *RS = nullptr) const override;115void processFunctionBeforeFrameFinalized(MachineFunction &MF,116RegScavenger *RS = nullptr) const override;117void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;118119bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,120MachineBasicBlock::iterator MI,121ArrayRef<CalleeSavedInfo> CSI,122const TargetRegisterInfo *TRI) const override;123/// This function will assign callee saved gprs to volatile vector registers124/// for prologue spills when applicable. It returns false if there are any125/// registers which were not spilled to volatile vector registers.126bool127assignCalleeSavedSpillSlots(MachineFunction &MF,128const TargetRegisterInfo *TRI,129std::vector<CalleeSavedInfo> &CSI) const override;130131MachineBasicBlock::iterator132eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,133MachineBasicBlock::iterator I) const override;134135bool136restoreCalleeSavedRegisters(MachineBasicBlock &MBB,137MachineBasicBlock::iterator MI,138MutableArrayRef<CalleeSavedInfo> CSI,139const TargetRegisterInfo *TRI) const override;140141/// targetHandlesStackFrameRounding - Returns true if the target is142/// responsible for rounding up the stack frame (probably at emitPrologue143/// time).144bool targetHandlesStackFrameRounding() const override { return true; }145146/// getReturnSaveOffset - Return the previous frame offset to save the147/// return address.148uint64_t getReturnSaveOffset() const { return ReturnSaveOffset; }149150/// getTOCSaveOffset - Return the previous frame offset to save the151/// TOC register -- 64-bit SVR4 ABI only.152uint64_t getTOCSaveOffset() const;153154/// getFramePointerSaveOffset - Return the previous frame offset to save the155/// frame pointer.156uint64_t getFramePointerSaveOffset() const;157158/// getBasePointerSaveOffset - Return the previous frame offset to save the159/// base pointer.160uint64_t getBasePointerSaveOffset() const;161162/// getLinkageSize - Return the size of the PowerPC ABI linkage area.163///164unsigned getLinkageSize() const { return LinkageSize; }165166const SpillSlot *167getCalleeSavedSpillSlots(unsigned &NumEntries) const override;168169bool enableShrinkWrapping(const MachineFunction &MF) const override;170171/// Methods used by shrink wrapping to determine if MBB can be used for the172/// function prologue/epilogue.173bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;174bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;175void updateCalleeSaves(const MachineFunction &MF, BitVector &SavedRegs) const;176177uint64_t getStackThreshold() const override;178};179} // End llvm namespace180181#endif182183184