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 27 public: 28 PPCFrameLowering(const PPCSubtarget &STI); 29 30 unsigned determineFrameLayout(MachineFunction &MF, 31 bool UpdateMF = true, 32 bool UseEstimate = false) const; 33 34 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into 35 /// the function. 36 void emitPrologue(MachineFunction &MF) const override; 37 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 38 39 bool hasFP(const MachineFunction &MF) const override; 40 bool needsFP(const MachineFunction &MF) const; 41 void replaceFPWithRealFP(MachineFunction &MF) const; 42 43 void processFunctionBeforeCalleeSavedScan(MachineFunction &MF, 44 RegScavenger *RS = nullptr) const override; 45 void processFunctionBeforeFrameFinalized(MachineFunction &MF, 46 RegScavenger *RS = nullptr) const override; 47 void addScavengingSpillSlot(MachineFunction &MF, RegScavenger *RS) const; 48 49 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, 50 MachineBasicBlock::iterator MI, 51 const std::vector<CalleeSavedInfo> &CSI, 52 const TargetRegisterInfo *TRI) const override; 53 54 void eliminateCallFramePseudoInstr(MachineFunction &MF, 55 MachineBasicBlock &MBB, 56 MachineBasicBlock::iterator I) const override; 57 58 bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 59 MachineBasicBlock::iterator MI, 60 const std::vector<CalleeSavedInfo> &CSI, 61 const TargetRegisterInfo *TRI) const override; 62 63 /// targetHandlesStackFrameRounding - Returns true if the target is 64 /// responsible for rounding up the stack frame (probably at emitPrologue 65 /// time). targetHandlesStackFrameRounding()66 bool targetHandlesStackFrameRounding() const override { return true; } 67 68 /// getReturnSaveOffset - Return the previous frame offset to save the 69 /// return address. getReturnSaveOffset(bool isPPC64,bool isDarwinABI)70 static unsigned getReturnSaveOffset(bool isPPC64, bool isDarwinABI) { 71 if (isDarwinABI) 72 return isPPC64 ? 16 : 8; 73 // SVR4 ABI: 74 return isPPC64 ? 16 : 4; 75 } 76 77 /// getTOCSaveOffset - Return the previous frame offset to save the 78 /// TOC register -- 64-bit SVR4 ABI only. getTOCSaveOffset(bool isELFv2ABI)79 static unsigned getTOCSaveOffset(bool isELFv2ABI) { 80 return isELFv2ABI ? 24 : 40; 81 } 82 83 /// getFramePointerSaveOffset - Return the previous frame offset to save the 84 /// frame pointer. getFramePointerSaveOffset(bool isPPC64,bool isDarwinABI)85 static unsigned getFramePointerSaveOffset(bool isPPC64, bool isDarwinABI) { 86 // For the Darwin ABI: 87 // We cannot use the TOC save slot (offset +20) in the PowerPC linkage area 88 // for saving the frame pointer (if needed.) While the published ABI has 89 // not used this slot since at least MacOSX 10.2, there is older code 90 // around that does use it, and that needs to continue to work. 91 if (isDarwinABI) 92 return isPPC64 ? -8U : -4U; 93 94 // SVR4 ABI: First slot in the general register save area. 95 return isPPC64 ? -8U : -4U; 96 } 97 98 /// getBasePointerSaveOffset - Return the previous frame offset to save the 99 /// base pointer. getBasePointerSaveOffset(bool isPPC64,bool isDarwinABI,bool isPIC)100 static unsigned getBasePointerSaveOffset(bool isPPC64, 101 bool isDarwinABI, 102 bool isPIC) { 103 if (isDarwinABI) 104 return isPPC64 ? -16U : -8U; 105 106 // SVR4 ABI: First slot in the general register save area. 107 return isPPC64 ? -16U : isPIC ? -12U : -8U; 108 } 109 110 /// getLinkageSize - Return the size of the PowerPC ABI linkage area. 111 /// getLinkageSize(bool isPPC64,bool isDarwinABI,bool isELFv2ABI)112 static unsigned getLinkageSize(bool isPPC64, bool isDarwinABI, 113 bool isELFv2ABI) { 114 if (isDarwinABI || isPPC64) 115 return (isELFv2ABI ? 4 : 6) * (isPPC64 ? 8 : 4); 116 117 // SVR4 ABI: 118 return 8; 119 } 120 121 const SpillSlot * 122 getCalleeSavedSpillSlots(unsigned &NumEntries) const override; 123 }; 124 } // End llvm namespace 125 126 #endif 127