brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.4 KiB · 87980df Raw
122 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8//9// This class implements RISC-V specific bits of TargetFrameLowering class.10//11//===----------------------------------------------------------------------===//12 13#ifndef LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H14#define LLVM_LIB_TARGET_RISCV_RISCVFRAMELOWERING_H15 16#include "llvm/CodeGen/TargetFrameLowering.h"17#include "llvm/Support/TypeSize.h"18 19namespace llvm {20class RISCVSubtarget;21 22class RISCVFrameLowering : public TargetFrameLowering {23public:24  explicit RISCVFrameLowering(const RISCVSubtarget &STI);25 26  int getInitialCFAOffset(const MachineFunction &MF) const override;27  Register getInitialCFARegister(const MachineFunction &MF) const override;28 29  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override;30  void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override;31 32  uint64_t getStackSizeWithRVVPadding(const MachineFunction &MF) const;33 34  StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,35                                     Register &FrameReg) const override;36 37  void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,38                            RegScavenger *RS) const override;39 40  void processFunctionBeforeFrameFinalized(MachineFunction &MF,41                                           RegScavenger *RS) const override;42 43  bool hasBP(const MachineFunction &MF) const;44 45  bool hasReservedCallFrame(const MachineFunction &MF) const override;46  MachineBasicBlock::iterator47  eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,48                                MachineBasicBlock::iterator MI) const override;49 50  bool assignCalleeSavedSpillSlots(MachineFunction &MF,51                                   const TargetRegisterInfo *TRI,52                                   std::vector<CalleeSavedInfo> &CSI,53                                   unsigned &MinCSFrameIndex,54                                   unsigned &MaxCSFrameIndex) const override;55  bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,56                                 MachineBasicBlock::iterator MI,57                                 ArrayRef<CalleeSavedInfo> CSI,58                                 const TargetRegisterInfo *TRI) const override;59  bool60  restoreCalleeSavedRegisters(MachineBasicBlock &MBB,61                              MachineBasicBlock::iterator MI,62                              MutableArrayRef<CalleeSavedInfo> CSI,63                              const TargetRegisterInfo *TRI) const override;64 65  // Get the first stack adjustment amount for SplitSPAdjust.66  // Return 0 if we don't want to split the SP adjustment in prologue and67  // epilogue.68  uint64_t getFirstSPAdjustAmount(const MachineFunction &MF) const;69 70  bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;71  bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;72 73  bool enableShrinkWrapping(const MachineFunction &MF) const override;74 75  bool isSupportedStackID(TargetStackID::Value ID) const override;76  TargetStackID::Value getStackIDForScalableVectors() const override;77 78  bool isStackIdSafeForLocalArea(unsigned StackId) const override {79    // We don't support putting RISC-V Vector objects into the pre-allocated80    // local frame block at the moment.81    return StackId != TargetStackID::ScalableVector;82  }83 84  void allocateStack(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,85                     MachineFunction &MF, uint64_t Offset,86                     uint64_t RealStackSize, bool EmitCFI, bool NeedProbe,87                     uint64_t ProbeSize, bool DynAllocation,88                     MachineInstr::MIFlag Flag) const;89 90protected:91  const RISCVSubtarget &STI;92 93  bool hasFPImpl(const MachineFunction &MF) const override;94 95private:96  void determineFrameLayout(MachineFunction &MF) const;97  void emitCalleeSavedRVVPrologCFI(MachineBasicBlock &MBB,98                                   MachineBasicBlock::iterator MI,99                                   bool HasFP) const;100  void emitCalleeSavedRVVEpilogCFI(MachineBasicBlock &MBB,101                                   MachineBasicBlock::iterator MI) const;102  template <typename Emitter>103  void emitCFIForCSI(MachineBasicBlock &MBB, MachineBasicBlock::iterator MBBI,104                     const SmallVector<CalleeSavedInfo, 8> &CSI) const;105  void deallocateStack(MachineFunction &MF, MachineBasicBlock &MBB,106                       MachineBasicBlock::iterator MBBI, const DebugLoc &DL,107                       uint64_t &StackSize, int64_t CFAOffset) const;108 109  std::pair<int64_t, Align>110  assignRVVStackObjectOffsets(MachineFunction &MF) const;111  // Replace a StackProbe stub (if any) with the actual probe code inline112  void inlineStackProbe(MachineFunction &MF,113                        MachineBasicBlock &PrologueMBB) const override;114  void allocateAndProbeStackForRVV(MachineFunction &MF, MachineBasicBlock &MBB,115                                   MachineBasicBlock::iterator MBBI,116                                   const DebugLoc &DL, int64_t Amount,117                                   MachineInstr::MIFlag Flag, bool EmitCFI,118                                   bool DynAllocation) const;119};120} // namespace llvm121#endif122