| 1 | //=- LoongArchFrameLowering.h - TargetFrameLowering for LoongArch -*- 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 | // This class implements LoongArch-specific bits of TargetFrameLowering class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H |
| 14 | #define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H |
| 15 | |
| 16 | #include "llvm/CodeGen/TargetFrameLowering.h" |
| 17 | |
| 18 | namespace llvm { |
| 19 | class LoongArchSubtarget; |
| 20 | |
| 21 | class LoongArchFrameLowering : public TargetFrameLowering { |
| 22 | const LoongArchSubtarget &STI; |
| 23 | |
| 24 | public: |
| 25 | explicit LoongArchFrameLowering(const LoongArchSubtarget &STI) |
| 26 | : TargetFrameLowering(StackGrowsDown, |
| 27 | /*StackAlignment=*/Align(16), |
| 28 | /*LocalAreaOffset=*/0), |
| 29 | STI(STI) {} |
| 30 | |
| 31 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
| 32 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override; |
| 33 | |
| 34 | void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, |
| 35 | RegScavenger *RS) const override; |
| 36 | |
| 37 | void processFunctionBeforeFrameFinalized(MachineFunction &MF, |
| 38 | RegScavenger *RS) const override; |
| 39 | |
| 40 | bool hasReservedCallFrame(const MachineFunction &MF) const override; |
| 41 | MachineBasicBlock::iterator |
| 42 | eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, |
| 43 | MachineBasicBlock::iterator MI) const override; |
| 44 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 45 | MachineBasicBlock::iterator MI, |
| 46 | ArrayRef<CalleeSavedInfo> CSI, |
| 47 | const TargetRegisterInfo *TRI) const override; |
| 48 | |
| 49 | StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, |
| 50 | Register &FrameReg) const override; |
| 51 | |
| 52 | bool hasBP(const MachineFunction &MF) const; |
| 53 | |
| 54 | uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const; |
| 55 | |
| 56 | bool enableShrinkWrapping(const MachineFunction &MF) const override; |
| 57 | |
| 58 | protected: |
| 59 | bool hasFPImpl(const MachineFunction &MF) const override; |
| 60 | |
| 61 | private: |
| 62 | void determineFrameLayout(MachineFunction &MF) const; |
| 63 | void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, |
| 64 | const DebugLoc &DL, Register DestReg, Register SrcReg, |
| 65 | int64_t Val, MachineInstr::MIFlag Flag) const; |
| 66 | }; |
| 67 | } // end namespace llvm |
| 68 | #endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H |
| 69 | |