#include "RISCVFrameLowering.h"
#include "RISCVMachineFunctionInfo.h"
#include "RISCVSubtarget.h"
#include "llvm/BinaryFormat/Dwarf.h"
#include "llvm/CodeGen/MachineFrameInfo.h"
#include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineInstrBuilder.h"
#include "llvm/CodeGen/MachineRegisterInfo.h"
#include "llvm/CodeGen/RegisterScavenging.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/Support/LEB128.h"
#include <algorithm>
usingnamespacellvm;
static Align getABIStackAlignment(RISCVABI::ABI ABI) { … }
RISCVFrameLowering::RISCVFrameLowering(const RISCVSubtarget &STI)
: … { … }
static const std::pair<MCPhysReg, int8_t> FixedCSRFIMap[] = …;
static void emitSCSPrologue(MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
const DebugLoc &DL) { … }
static void emitSCSEpilogue(MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI,
const DebugLoc &DL) { … }
static int getLibCallID(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI) { … }
static const char *
getSpillLibCallName(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI) { … }
static const char *
getRestoreLibCallName(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI) { … }
static std::pair<unsigned, unsigned>
getPushPopEncodingAndNum(const Register MaxReg) { … }
static Register getMaxPushPopReg(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI) { … }
bool RISCVFrameLowering::hasFP(const MachineFunction &MF) const { … }
bool RISCVFrameLowering::hasBP(const MachineFunction &MF) const { … }
void RISCVFrameLowering::determineFrameLayout(MachineFunction &MF) const { … }
uint64_t RISCVFrameLowering::getStackSizeWithRVVPadding(
const MachineFunction &MF) const { … }
static Register getFPReg(const RISCVSubtarget &STI) { … }
static Register getSPReg(const RISCVSubtarget &STI) { … }
static SmallVector<CalleeSavedInfo, 8>
getUnmanagedCSI(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI) { … }
static SmallVector<CalleeSavedInfo, 8>
getRVVCalleeSavedInfo(const MachineFunction &MF,
const std::vector<CalleeSavedInfo> &CSI) { … }
void RISCVFrameLowering::adjustStackForRVV(MachineFunction &MF,
MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
const DebugLoc &DL, int64_t Amount,
MachineInstr::MIFlag Flag) const { … }
static void appendScalableVectorExpression(const TargetRegisterInfo &TRI,
SmallVectorImpl<char> &Expr,
int FixedOffset, int ScalableOffset,
llvm::raw_string_ostream &Comment) { … }
static MCCFIInstruction createDefCFAExpression(const TargetRegisterInfo &TRI,
Register Reg,
uint64_t FixedOffset,
uint64_t ScalableOffset) { … }
static MCCFIInstruction createDefCFAOffset(const TargetRegisterInfo &TRI,
Register Reg, uint64_t FixedOffset,
uint64_t ScalableOffset) { … }
void RISCVFrameLowering::emitPrologue(MachineFunction &MF,
MachineBasicBlock &MBB) const { … }
void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
MachineBasicBlock &MBB) const { … }
StackOffset
RISCVFrameLowering::getFrameIndexReference(const MachineFunction &MF, int FI,
Register &FrameReg) const { … }
void RISCVFrameLowering::determineCalleeSaves(MachineFunction &MF,
BitVector &SavedRegs,
RegScavenger *RS) const { … }
std::pair<int64_t, Align>
RISCVFrameLowering::assignRVVStackObjectOffsets(MachineFunction &MF) const { … }
static unsigned getScavSlotsNumForRVV(MachineFunction &MF) { … }
static bool hasRVVFrameObject(const MachineFunction &MF) { … }
static unsigned estimateFunctionSizeInBytes(const MachineFunction &MF,
const RISCVInstrInfo &TII) { … }
void RISCVFrameLowering::processFunctionBeforeFrameFinalized(
MachineFunction &MF, RegScavenger *RS) const { … }
bool RISCVFrameLowering::hasReservedCallFrame(const MachineFunction &MF) const { … }
MachineBasicBlock::iterator RISCVFrameLowering::eliminateCallFramePseudoInstr(
MachineFunction &MF, MachineBasicBlock &MBB,
MachineBasicBlock::iterator MI) const { … }
uint64_t
RISCVFrameLowering::getFirstSPAdjustAmount(const MachineFunction &MF) const { … }
bool RISCVFrameLowering::assignCalleeSavedSpillSlots(
MachineFunction &MF, const TargetRegisterInfo *TRI,
std::vector<CalleeSavedInfo> &CSI, unsigned &MinCSFrameIndex,
unsigned &MaxCSFrameIndex) const { … }
bool RISCVFrameLowering::spillCalleeSavedRegisters(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
ArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const { … }
void RISCVFrameLowering::emitCalleeSavedRVVPrologCFI(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, bool HasFP) const { … }
bool RISCVFrameLowering::restoreCalleeSavedRegisters(
MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
MutableArrayRef<CalleeSavedInfo> CSI, const TargetRegisterInfo *TRI) const { … }
bool RISCVFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const { … }
bool RISCVFrameLowering::canUseAsPrologue(const MachineBasicBlock &MBB) const { … }
bool RISCVFrameLowering::canUseAsEpilogue(const MachineBasicBlock &MBB) const { … }
bool RISCVFrameLowering::isSupportedStackID(TargetStackID::Value ID) const { … }
TargetStackID::Value RISCVFrameLowering::getStackIDForScalableVectors() const { … }