1 //===-- PPCFrameLowering.h - Define frame lowering for PowerPC --*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // 11 //===----------------------------------------------------------------------===// 12 13 #ifndef LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H 14 #define LLVM_LIB_TARGET_POWERPC_PPCFRAMELOWERING_H 15 16 #include "PPC.h" 17 #include "llvm/ADT/STLExtras.h" 18 #include "llvm/Target/TargetFrameLowering.h" 19 #include "llvm/Target/TargetMachine.h" 20 21 namespace llvm { 22 class PPCSubtarget; 23 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; 31 32 /** 33 * \brief Find a register that can be used in function prologue and epilogue 34 * 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. 39 * 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. 43 * 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. 51 */ 52 bool findScratchRegister(MachineBasicBlock *MBB, 53 bool UseAtEnd, 54 unsigned *ScratchRegister) const; 55 56 public: 57 PPCFrameLowering(const PPCSubtarget &STI); 58 59 unsigned determineFrameLayout(MachineFunction &MF, 60 bool UpdateMF = true, 61 bool UseEstimate = false) const; 62 63 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into 64 /// the function. 65 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 66 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 67 68 bool hasFP(const MachineFunction &MF) const override; 69 bool needsFP(const MachineFunction &MF) const; 70 void replaceFPWithRealFP(MachineFunction &MF) const; 71 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; 77 78 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, 79 MachineBasicBlock::iterator MI, 80 const std::vector<CalleeSavedInfo> &CSI, 81 const TargetRegisterInfo *TRI) const override; 82 83 void eliminateCallFramePseudoInstr(MachineFunction &MF, 84 MachineBasicBlock &MBB, 85 MachineBasicBlock::iterator I) const override; 86 87 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 88 MachineBasicBlock::iterator MI, 89 const std::vector<CalleeSavedInfo> &CSI, 90 const TargetRegisterInfo *TRI) const override; 91 92 /// targetHandlesStackFrameRounding - Returns true if the target is 93 /// responsible for rounding up the stack frame (probably at emitPrologue 94 /// time). targetHandlesStackFrameRounding()95 bool targetHandlesStackFrameRounding() const override { return true; } 96 97 /// getReturnSaveOffset - Return the previous frame offset to save the 98 /// return address. getReturnSaveOffset()99 unsigned getReturnSaveOffset() const { return ReturnSaveOffset; } 100 101 /// getTOCSaveOffset - Return the previous frame offset to save the 102 /// TOC register -- 64-bit SVR4 ABI only. getTOCSaveOffset()103 unsigned getTOCSaveOffset() const { return TOCSaveOffset; } 104 105 /// getFramePointerSaveOffset - Return the previous frame offset to save the 106 /// frame pointer. getFramePointerSaveOffset()107 unsigned getFramePointerSaveOffset() const { return FramePointerSaveOffset; } 108 109 /// getBasePointerSaveOffset - Return the previous frame offset to save the 110 /// base pointer. getBasePointerSaveOffset()111 unsigned getBasePointerSaveOffset() const { return BasePointerSaveOffset; } 112 113 /// getLinkageSize - Return the size of the PowerPC ABI linkage area. 114 /// getLinkageSize()115 unsigned getLinkageSize() const { return LinkageSize; } 116 117 const SpillSlot * 118 getCalleeSavedSpillSlots(unsigned &NumEntries) const override; 119 120 bool enableShrinkWrapping(const MachineFunction &MF) const override; 121 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; 126 }; 127 } // End llvm namespace 128 129 #endif 130