1 //===-- LoongArchFrameLowering.cpp - LoongArch Frame Information -*- 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 file contains the LoongArch implementation of TargetFrameLowering class.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "LoongArchFrameLowering.h"
14 #include "LoongArchSubtarget.h"
15 #include "llvm/CodeGen/MachineFrameInfo.h"
16 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineInstrBuilder.h"
18 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 #include "llvm/CodeGen/RegisterScavenging.h"
20 #include "llvm/IR/DiagnosticInfo.h"
21 #include "llvm/MC/MCDwarf.h"
22 
23 using namespace llvm;
24 
25 #define DEBUG_TYPE "loongarch-frame-lowering"
26 
27 // Return true if the specified function should have a dedicated frame
28 // pointer register.  This is true if frame pointer elimination is
29 // disabled, if it needs dynamic stack realignment, if the function has
30 // variable sized allocas, or if the frame address is taken.
31 bool LoongArchFrameLowering::hasFP(const MachineFunction &MF) const {
32   const TargetRegisterInfo *RegInfo = MF.getSubtarget().getRegisterInfo();
33 
34   const MachineFrameInfo &MFI = MF.getFrameInfo();
35   return MF.getTarget().Options.DisableFramePointerElim(MF) ||
36          RegInfo->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
37          MFI.isFrameAddressTaken();
38 }
39 
40 bool LoongArchFrameLowering::hasBP(const MachineFunction &MF) const {
41   const MachineFrameInfo &MFI = MF.getFrameInfo();
42   const TargetRegisterInfo *TRI = STI.getRegisterInfo();
43 
44   return MFI.hasVarSizedObjects() && TRI->hasStackRealignment(MF);
45 }
46 
47 void LoongArchFrameLowering::emitPrologue(MachineFunction &MF,
48                                           MachineBasicBlock &MBB) const {
49   // TODO: Implement this when we have function calls
50 }
51 
52 void LoongArchFrameLowering::emitEpilogue(MachineFunction &MF,
53                                           MachineBasicBlock &MBB) const {
54   // TODO: Implement this when we have function calls
55 }
56