1 //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
14 #define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/Target/TargetFrameLowering.h"
19 #include "llvm/Target/TargetMachine.h"
24 class PPCFrameLowering: public TargetFrameLowering {
25 const PPCSubtarget &Subtarget;
26 const unsigned ReturnSaveOffset;
27 const unsigned TOCSaveOffset;
28 const unsigned FramePointerSaveOffset;
29 const unsigned LinkageSize;
30 const unsigned BasePointerSaveOffset;
33 * \brief Find a register that can be used in function prologue and epilogue
35 * Find a register that can be use as the scratch register in function
36 * prologue and epilogue to save various registers (Link Register, Base
37 * Pointer, etc.). Prefer R0, if it is available. If it is not available,
38 * then choose a different register.
40 * This method will return true if an available register was found (including
41 * R0). If no available registers are found, the method returns false and sets
42 * ScratchRegister to R0, as per the recommendation in the ABI.
44 * \param[in] MBB The machine basic block to find an available register for
45 * \param[in] UseAtEnd Specify whether the scratch register will be used at
46 * the end of the basic block (i.e., will the scratch
47 * register kill a register defined in the basic block)
48 * \param[out] ScratchRegister The scratch register to use
49 * \return true if a scratch register was found. false of a scratch register
50 * was not found and R0 is being used as the default.
52 bool findScratchRegister(MachineBasicBlock *MBB,
54 unsigned *ScratchRegister) const;
57 PPCFrameLowering(const PPCSubtarget &STI);
59 unsigned determineFrameLayout(MachineFunction &MF,
61 bool UseEstimate = false) const;
63 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into
65 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
66 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
68 bool hasFP(const MachineFunction &MF) const override;
69 bool needsFP(const MachineFunction &MF) const;
70 void replaceFPWithRealFP(MachineFunction &MF) const;
72 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
73 RegScavenger *RS = nullptr) const override;
74 void processFunctionBeforeFrameFinalized(MachineFunction &MF,
75 RegScavenger *RS = nullptr) const override;
76 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const;
78 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
79 MachineBasicBlock::iterator MI,
80 const std::vector<CalleeSavedInfo> &CSI,
81 const TargetRegisterInfo *TRI) const override;
83 void eliminateCallFramePseudoInstr(MachineFunction &MF,
84 MachineBasicBlock &MBB,
85 MachineBasicBlock::iterator I) const override;
87 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
88 MachineBasicBlock::iterator MI,
89 const std::vector<CalleeSavedInfo> &CSI,
90 const TargetRegisterInfo *TRI) const override;
92 /// targetHandlesStackFrameRounding - Returns true if the target is
93 /// responsible for rounding up the stack frame (probably at emitPrologue
95 bool targetHandlesStackFrameRounding() const override { return true; }
97 /// getReturnSaveOffset - Return the previous frame offset to save the
99 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; }
101 /// getTOCSaveOffset - Return the previous frame offset to save the
102 /// TOC register -- 64-bit SVR4 ABI only.
103 unsigned getTOCSaveOffset() const { return TOCSaveOffset; }
105 /// getFramePointerSaveOffset - Return the previous frame offset to save the
107 unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; }
109 /// getBasePointerSaveOffset - Return the previous frame offset to save the
111 unsigned getBasePointerSaveOffset() const { return BasePointerSaveOffset; }
113 /// getLinkageSize - Return the size of the PowerPC ABI linkage area.
115 unsigned getLinkageSize() const { return LinkageSize; }
118 getCalleeSavedSpillSlots(unsigned &NumEntries) const override;
120 bool enableShrinkWrapping(const MachineFunction &MF) const override;
122 /// Methods used by shrink wrapping to determine if MBB can be used for the
123 /// function prologue/epilogue.
124 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
125 bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
127 } // End llvm namespace