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
18namespace llvm {
19class LoongArchSubtarget;
20
21class LoongArchFrameLowering : public TargetFrameLowering {
22 const LoongArchSubtarget &STI;
23
24public:
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 hasFP(const MachineFunction &MF) const override;
53 bool hasBP(const MachineFunction &MF) const;
54
55 uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;
56
57 bool enableShrinkWrapping(const MachineFunction &MF) const override;
58
59private:
60 void determineFrameLayout(MachineFunction &MF) const;
61 void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
62 const DebugLoc &DL, Register DestReg, Register SrcReg,
63 int64_t Val, MachineInstr::MIFlag Flag) const;
64};
65} // end namespace llvm
66#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H
67