LLVM  15.0.0git
LoongArchFrameLowering.cpp
Go to the documentation of this file.
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"
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.
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 
41  const MachineFrameInfo &MFI = MF.getFrameInfo();
42  const TargetRegisterInfo *TRI = STI.getRegisterInfo();
43 
44  return MFI.hasVarSizedObjects() && TRI->hasStackRealignment(MF);
45 }
46 
48  MachineBasicBlock &MBB) const {
49  // TODO: Implement this when we have function calls
50 }
51 
53  MachineBasicBlock &MBB) const {
54  // TODO: Implement this when we have function calls
55 }
llvm::LoongArchSubtarget::getRegisterInfo
const LoongArchRegisterInfo * getRegisterInfo() const override
Definition: LoongArchSubtarget.h:70
llvm::MachineFrameInfo::hasVarSizedObjects
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
Definition: MachineFrameInfo.h:354
MCDwarf.h
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::TargetSubtargetInfo::getRegisterInfo
virtual const TargetRegisterInfo * getRegisterInfo() const
getRegisterInfo - If register information is available, return it.
Definition: TargetSubtargetInfo.h:125
llvm::LoongArchFrameLowering::emitPrologue
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
Definition: LoongArchFrameLowering.cpp:47
llvm::TargetRegisterInfo
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
Definition: TargetRegisterInfo.h:234
LoongArchFrameLowering.h
LoongArchSubtarget.h
TRI
unsigned const TargetRegisterInfo * TRI
Definition: MachineSink.cpp:1628
MachineRegisterInfo.h
llvm::MachineBasicBlock
Definition: MachineBasicBlock.h:94
llvm::TargetOptions::DisableFramePointerElim
bool DisableFramePointerElim(const MachineFunction &MF) const
DisableFramePointerElim - This returns true if frame pointer elimination optimization should be disab...
Definition: TargetOptionsImpl.cpp:23
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:656
llvm::TargetMachine::Options
TargetOptions Options
Definition: TargetMachine.h:118
llvm::MachineFunction::getFrameInfo
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
Definition: MachineFunction.h:672
llvm::LoongArchFrameLowering::hasBP
bool hasBP(const MachineFunction &MF) const
Definition: LoongArchFrameLowering.cpp:40
llvm::MachineFunction
Definition: MachineFunction.h:257
llvm::MachineFrameInfo::isFrameAddressTaken
bool isFrameAddressTaken() const
This method may be called any time after instruction selection is complete to determine if there is a...
Definition: MachineFrameInfo.h:370
MBB
MachineBasicBlock & MBB
Definition: AArch64SLSHardening.cpp:74
llvm::LoongArchFrameLowering::emitEpilogue
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Definition: LoongArchFrameLowering.cpp:52
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:652
MachineFrameInfo.h
DiagnosticInfo.h
llvm::TargetRegisterInfo::hasStackRealignment
bool hasStackRealignment(const MachineFunction &MF) const
True if stack realignment is required and still possible.
Definition: TargetRegisterInfo.h:947
llvm::MachineFrameInfo
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
Definition: MachineFrameInfo.h:105
MachineInstrBuilder.h
RegisterScavenging.h
MachineFunction.h
llvm::LoongArchFrameLowering::hasFP
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register.
Definition: LoongArchFrameLowering.cpp:31