LLVM 20.0.0git
RISCVFrameLowering.h
Go to the documentation of this file.
1//===-- RISCVFrameLowering.h - Define frame lowering for RISC-V -*- 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 RISC-V specific bits of TargetFrameLowering class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H
14#define LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H
15
18
19namespace llvm {
20class RISCVSubtarget;
21
23public:
24 explicit RISCVFrameLowering(const RISCVSubtarget &STI);
25
26 void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
27 void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;
28
30
32 Register &FrameReg) const override;
33
35 RegScavenger *RS) const override;
36
38 RegScavenger *RS) const override;
39
40 bool hasBP(const MachineFunction &MF) const;
41
42 bool hasReservedCallFrame(const MachineFunction &MF) const override;
45 MachineBasicBlock::iterator MI) const override;
46
49 std::vector<CalleeSavedInfo> &CSI,
50 unsigned &MinCSFrameIndex,
51 unsigned &MaxCSFrameIndex) const override;
55 const TargetRegisterInfo *TRI) const override;
56 bool
60 const TargetRegisterInfo *TRI) const override;
61
62 // Get the first stack adjustment amount for SplitSPAdjust.
63 // Return 0 if we don't want to split the SP adjustment in prologue and
64 // epilogue.
66
67 bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
68 bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
69
70 bool enableShrinkWrapping(const MachineFunction &MF) const override;
71
72 bool isSupportedStackID(TargetStackID::Value ID) const override;
74
75 bool isStackIdSafeForLocalArea(unsigned StackId) const override {
76 // We don't support putting RISC-V Vector objects into the pre-allocated
77 // local frame block at the moment.
78 return StackId != TargetStackID::ScalableVector;
79 }
80
83 uint64_t RealStackSize, bool EmitCFI, bool NeedProbe,
84 uint64_t ProbeSize) const;
85
86protected:
88
89 bool hasFPImpl(const MachineFunction &MF) const override;
90
91private:
92 void determineFrameLayout(MachineFunction &MF) const;
93 void emitCalleeSavedRVVPrologCFI(MachineBasicBlock &MBB,
95 bool HasFP) const;
96 void emitCalleeSavedRVVEpilogCFI(MachineBasicBlock &MBB,
98 template <typename Emitter>
100 const SmallVector<CalleeSavedInfo, 8> &CSI) const;
101 void deallocateStack(MachineFunction &MF, MachineBasicBlock &MBB,
103 uint64_t &StackSize, int64_t CFAOffset) const;
104
105 std::pair<int64_t, Align>
106 assignRVVStackObjectOffsets(MachineFunction &MF) const;
107 // Replace a StackProbe stub (if any) with the actual probe code inline
108 void inlineStackProbe(MachineFunction &MF,
109 MachineBasicBlock &PrologueMBB) const override;
110};
111} // namespace llvm
112#endif
MachineBasicBlock & MBB
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
MachineBasicBlock MachineBasicBlock::iterator MBBI
IRTranslator LLVM IR MI
unsigned const TargetRegisterInfo * TRI
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
A debug info location.
Definition: DebugLoc.h:33
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:310
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
emitProlog/emitEpilog - These methods insert prolog and epilog code into the function.
uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const
bool enableShrinkWrapping(const MachineFunction &MF) const override
Returns true if the target will correctly handle shrink wrapping.
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, ArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
bool hasBP(const MachineFunction &MF) const
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a epilogue for the target.
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI, unsigned &MinCSFrameIndex, unsigned &MaxCSFrameIndex) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
bool hasFPImpl(const MachineFunction &MF) const override
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, MutableArrayRef< CalleeSavedInfo > CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
bool hasReservedCallFrame(const MachineFunction &MF) const override
hasReservedCallFrame - Under normal circumstances, when a frame pointer is not required,...
void allocateStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI, MachineFunction &MF, uint64_t Offset, uint64_t RealStackSize, bool EmitCFI, bool NeedProbe, uint64_t ProbeSize) const
const RISCVSubtarget & STI
StackOffset getFrameIndexReference(const MachineFunction &MF, int FI, Register &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool isSupportedStackID(TargetStackID::Value ID) const override
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
TargetStackID::Value getStackIDForScalableVectors() const override
Returns the StackID that scalable vectors should be associated with.
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator MI) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool isStackIdSafeForLocalArea(unsigned StackId) const override
This method returns whether or not it is safe for an object with the given stack id to be bundled int...
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override
Check whether or not the given MBB can be used as a prologue for the target.
uint64_t getStackSizeWithRVVPadding(const MachineFunction &MF) const
Wrapper class representing virtual and physical registers.
Definition: Register.h:19
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StackOffset holds a fixed and a scalable offset in bytes.
Definition: TypeSize.h:33
Information about stack frame layout on the target.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480