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 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 void inlineStackProbe(MachineFunction &MF,
59 MachineBasicBlock &PrologueMBB) const override;
60
61protected:
62 bool hasFPImpl(const MachineFunction &MF) const override;
63
64private:
65 void determineFrameLayout(MachineFunction &MF) const;
66 void allocateStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
67 MachineFunction &MF, uint64_t Offset,
68 uint64_t RealStackSize, bool EmitCFI, bool NeedProbe,
69 uint64_t ProbeSize, bool DynAllocation,
70 MachineInstr::MIFlag Flag) const;
71 void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
72 const DebugLoc &DL, Register DestReg, Register SrcReg,
73 int64_t Val, MachineInstr::MIFlag Flag) const;
74};
75} // end namespace llvm
76#endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H
77