xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArchFrameLowering.h (revision 06c3fb2749bda94cb5201f81ffdb8fa6c3161b2e)
181ad6265SDimitry Andric //=- LoongArchFrameLowering.h - TargetFrameLowering for LoongArch -*- C++ -*--//
281ad6265SDimitry Andric //
381ad6265SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
481ad6265SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
581ad6265SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
681ad6265SDimitry Andric //
781ad6265SDimitry Andric //===----------------------------------------------------------------------===//
881ad6265SDimitry Andric //
981ad6265SDimitry Andric // This class implements LoongArch-specific bits of TargetFrameLowering class.
1081ad6265SDimitry Andric //
1181ad6265SDimitry Andric //===----------------------------------------------------------------------===//
1281ad6265SDimitry Andric 
1381ad6265SDimitry Andric #ifndef LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H
1481ad6265SDimitry Andric #define LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H
1581ad6265SDimitry Andric 
1681ad6265SDimitry Andric #include "llvm/CodeGen/TargetFrameLowering.h"
1781ad6265SDimitry Andric 
1881ad6265SDimitry Andric namespace llvm {
1981ad6265SDimitry Andric class LoongArchSubtarget;
2081ad6265SDimitry Andric 
2181ad6265SDimitry Andric class LoongArchFrameLowering : public TargetFrameLowering {
2281ad6265SDimitry Andric   const LoongArchSubtarget &STI;
2381ad6265SDimitry Andric 
2481ad6265SDimitry Andric public:
2581ad6265SDimitry Andric   explicit LoongArchFrameLowering(const LoongArchSubtarget &STI)
2681ad6265SDimitry Andric       : TargetFrameLowering(StackGrowsDown,
2781ad6265SDimitry Andric                             /*StackAlignment=*/Align(16),
2881ad6265SDimitry Andric                             /*LocalAreaOffset=*/0),
2981ad6265SDimitry Andric         STI(STI) {}
3081ad6265SDimitry Andric 
3181ad6265SDimitry Andric   void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
3281ad6265SDimitry Andric   void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
3381ad6265SDimitry Andric 
34753f127fSDimitry Andric   void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
35753f127fSDimitry Andric                             RegScavenger *RS) const override;
36753f127fSDimitry Andric 
37bdd1243dSDimitry Andric   void processFunctionBeforeFrameFinalized(MachineFunction &MF,
38bdd1243dSDimitry Andric                                            RegScavenger *RS) const override;
39bdd1243dSDimitry Andric 
40bdd1243dSDimitry Andric   bool hasReservedCallFrame(const MachineFunction &MF) const override;
41753f127fSDimitry Andric   MachineBasicBlock::iterator
42753f127fSDimitry Andric   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
43bdd1243dSDimitry Andric                                 MachineBasicBlock::iterator MI) const override;
44bdd1243dSDimitry Andric   bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
45bdd1243dSDimitry Andric                                  MachineBasicBlock::iterator MI,
46bdd1243dSDimitry Andric                                  ArrayRef<CalleeSavedInfo> CSI,
47bdd1243dSDimitry Andric                                  const TargetRegisterInfo *TRI) const override;
48753f127fSDimitry Andric 
49753f127fSDimitry Andric   StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
50753f127fSDimitry Andric                                      Register &FrameReg) const override;
51753f127fSDimitry Andric 
5281ad6265SDimitry Andric   bool hasFP(const MachineFunction &MF) const override;
5381ad6265SDimitry Andric   bool hasBP(const MachineFunction &MF) const;
54753f127fSDimitry Andric 
55bdd1243dSDimitry Andric   uint64_t getFirstSPAdjustAmount(const MachineFunction &MF,
56bdd1243dSDimitry Andric                                   bool IsPrologue = false) const;
57bdd1243dSDimitry Andric 
58*06c3fb27SDimitry Andric   bool enableShrinkWrapping(const MachineFunction &MF) const override;
59*06c3fb27SDimitry Andric 
60753f127fSDimitry Andric private:
61753f127fSDimitry Andric   void determineFrameLayout(MachineFunction &MF) const;
62753f127fSDimitry Andric   void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
63753f127fSDimitry Andric                  const DebugLoc &DL, Register DestReg, Register SrcReg,
64753f127fSDimitry Andric                  int64_t Val, MachineInstr::MIFlag Flag) const;
6581ad6265SDimitry Andric };
66972a253aSDimitry Andric } // end namespace llvm
6781ad6265SDimitry Andric #endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H
68