xref: /freebsd/contrib/llvm-project/llvm/lib/Target/LoongArch/LoongArchFrameLowering.h (revision 972a253a57b6f144b0e4a3e2080a2a0076ec55a0)
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 
37753f127fSDimitry Andric   MachineBasicBlock::iterator
38753f127fSDimitry Andric   eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,
39753f127fSDimitry Andric                                 MachineBasicBlock::iterator MI) const override {
40753f127fSDimitry Andric     return MBB.erase(MI);
41753f127fSDimitry Andric   }
42753f127fSDimitry Andric 
43753f127fSDimitry Andric   StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,
44753f127fSDimitry Andric                                      Register &FrameReg) const override;
45753f127fSDimitry Andric 
4681ad6265SDimitry Andric   bool hasFP(const MachineFunction &MF) const override;
4781ad6265SDimitry Andric   bool hasBP(const MachineFunction &MF) const;
48753f127fSDimitry Andric 
49753f127fSDimitry Andric private:
50753f127fSDimitry Andric   void determineFrameLayout(MachineFunction &MF) const;
51753f127fSDimitry Andric   void adjustReg(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,
52753f127fSDimitry Andric                  const DebugLoc &DL, Register DestReg, Register SrcReg,
53753f127fSDimitry Andric                  int64_t Val, MachineInstr::MIFlag Flag) const;
5481ad6265SDimitry Andric };
55*972a253aSDimitry Andric } // end namespace llvm
5681ad6265SDimitry Andric #endif // LLVM_LIB_TARGET_LOONGARCH_LOONGARCHFRAMELOWERING_H
57