1 //===- ARMTargetFrameLowering.h - Define frame lowering for ARM -*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H 10 #define LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H 11 12 #include "llvm/CodeGen/MachineBasicBlock.h" 13 #include "llvm/CodeGen/TargetFrameLowering.h" 14 #include <vector> 15 16 namespace llvm { 17 18 class ARMSubtarget; 19 class CalleeSavedInfo; 20 class MachineFunction; 21 22 class ARMFrameLowering : public TargetFrameLowering { 23 protected: 24 const ARMSubtarget &STI; 25 26 public: 27 explicit ARMFrameLowering(const ARMSubtarget &sti); 28 29 /// emitProlog/emitEpilog - These methods insert prolog and epilog code into 30 /// the function. 31 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 32 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; 33 34 bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, 35 MachineBasicBlock::iterator MI, 36 ArrayRef<CalleeSavedInfo> CSI, 37 const TargetRegisterInfo *TRI) const override; 38 39 bool 40 restoreCalleeSavedRegisters(MachineBasicBlock &MBB, 41 MachineBasicBlock::iterator MI, 42 MutableArrayRef<CalleeSavedInfo> CSI, 43 const TargetRegisterInfo *TRI) const override; 44 45 bool keepFramePointer(const MachineFunction &MF) const override; 46 47 bool enableCalleeSaveSkip(const MachineFunction &MF) const override; 48 49 bool hasFP(const MachineFunction &MF) const override; 50 bool hasReservedCallFrame(const MachineFunction &MF) const override; 51 bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override; 52 int getFrameIndexReference(const MachineFunction &MF, int FI, 53 unsigned &FrameReg) const override; 54 int ResolveFrameIndexReference(const MachineFunction &MF, int FI, 55 unsigned &FrameReg, int SPAdj) const; 56 57 void getCalleeSaves(const MachineFunction &MF, 58 BitVector &SavedRegs) const override; 59 void findRegDefsOutsideSaveRestore(MachineFunction &MF, 60 BitVector &Regs) const; 61 unsigned spillExtraRegsForIPRA(MachineFunction &MF, BitVector &SavedRegs, 62 bool HasFPRegSaves) const; 63 void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, 64 RegScavenger *RS) const override; 65 66 void adjustForSegmentedStacks(MachineFunction &MF, 67 MachineBasicBlock &MBB) const override; 68 69 /// Returns true if the target will correctly handle shrink wrapping. 70 bool enableShrinkWrapping(const MachineFunction &MF) const override; 71 72 bool isProfitableForNoCSROpt(const Function &F) const override { 73 // The no-CSR optimisation is bad for code size on ARM, because we can save 74 // many registers with a single PUSH/POP pair. 75 return false; 76 } 77 78 private: 79 void emitPushInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, 80 ArrayRef<CalleeSavedInfo> CSI, unsigned StmOpc, 81 unsigned StrOpc, bool NoGap, bool (*Func)(unsigned, bool), 82 unsigned NumAlignedDPRCS2Regs, unsigned MIFlags = 0) const; 83 void emitPopInst(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, 84 MutableArrayRef<CalleeSavedInfo> CSI, unsigned LdmOpc, 85 unsigned LdrOpc, bool isVarArg, bool NoGap, 86 bool (*Func)(unsigned, bool), 87 unsigned NumAlignedDPRCS2Regs) const; 88 89 MachineBasicBlock::iterator 90 eliminateCallFramePseudoInstr(MachineFunction &MF, 91 MachineBasicBlock &MBB, 92 MachineBasicBlock::iterator MI) const override; 93 }; 94 95 } // end namespace llvm 96 97 #endif // LLVM_LIB_TARGET_ARM_ARMFRAMELOWERING_H 98