Path: blob/main/contrib/llvm-project/llvm/lib/Target/Hexagon/HexagonFrameLowering.h
35269 views
//==- HexagonFrameLowering.h - Define frame lowering for Hexagon -*- C++ -*-==//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H9#define LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H1011#include "Hexagon.h"12#include "HexagonBlockRanges.h"13#include "MCTargetDesc/HexagonMCTargetDesc.h"14#include "llvm/ADT/STLExtras.h"15#include "llvm/CodeGen/MachineBasicBlock.h"16#include "llvm/CodeGen/MachineFrameInfo.h"17#include "llvm/CodeGen/TargetFrameLowering.h"18#include <vector>1920namespace llvm {2122class BitVector;23class HexagonInstrInfo;24class HexagonRegisterInfo;25class MachineFunction;26class MachineInstr;27class MachineRegisterInfo;28class TargetRegisterClass;2930class HexagonFrameLowering : public TargetFrameLowering {31public:32// First register which could possibly hold a variable argument.33int FirstVarArgSavedReg;34explicit HexagonFrameLowering()35: TargetFrameLowering(StackGrowsDown, Align(8), 0, Align(1), true) {}3637void38orderFrameObjects(const MachineFunction &MF,39SmallVectorImpl<int> &ObjectsToAllocate) const override;4041// All of the prolog/epilog functionality, including saving and restoring42// callee-saved registers is handled in emitPrologue. This is to have the43// logic for shrink-wrapping in one place.44void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const45override;46void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const47override {}4849bool enableCalleeSaveSkip(const MachineFunction &MF) const override;5051bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,52MachineBasicBlock::iterator MI,53ArrayRef<CalleeSavedInfo> CSI,54const TargetRegisterInfo *TRI) const override {55return true;56}5758bool59restoreCalleeSavedRegisters(MachineBasicBlock &MBB,60MachineBasicBlock::iterator MI,61MutableArrayRef<CalleeSavedInfo> CSI,62const TargetRegisterInfo *TRI) const override {63return true;64}6566bool hasReservedCallFrame(const MachineFunction &MF) const override {67// We always reserve call frame as a part of the initial stack allocation.68return true;69}7071bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override {72// Override this function to avoid calling hasFP before CSI is set73// (the default implementation calls hasFP).74return true;75}7677MachineBasicBlock::iterator78eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB,79MachineBasicBlock::iterator I) const override;80void processFunctionBeforeFrameFinalized(MachineFunction &MF,81RegScavenger *RS = nullptr) const override;82void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,83RegScavenger *RS) const override;8485bool targetHandlesStackFrameRounding() const override {86return true;87}8889StackOffset getFrameIndexReference(const MachineFunction &MF, int FI,90Register &FrameReg) const override;91bool hasFP(const MachineFunction &MF) const override;9293const SpillSlot *getCalleeSavedSpillSlots(unsigned &NumEntries)94const override {95static const SpillSlot Offsets[] = {96{ Hexagon::R17, -4 }, { Hexagon::R16, -8 }, { Hexagon::D8, -8 },97{ Hexagon::R19, -12 }, { Hexagon::R18, -16 }, { Hexagon::D9, -16 },98{ Hexagon::R21, -20 }, { Hexagon::R20, -24 }, { Hexagon::D10, -24 },99{ Hexagon::R23, -28 }, { Hexagon::R22, -32 }, { Hexagon::D11, -32 },100{ Hexagon::R25, -36 }, { Hexagon::R24, -40 }, { Hexagon::D12, -40 },101{ Hexagon::R27, -44 }, { Hexagon::R26, -48 }, { Hexagon::D13, -48 }102};103NumEntries = std::size(Offsets);104return Offsets;105}106107bool assignCalleeSavedSpillSlots(MachineFunction &MF,108const TargetRegisterInfo *TRI, std::vector<CalleeSavedInfo> &CSI)109const override;110111bool needsAligna(const MachineFunction &MF) const;112const MachineInstr *getAlignaInstr(const MachineFunction &MF) const;113114void insertCFIInstructions(MachineFunction &MF) const;115116private:117using CSIVect = std::vector<CalleeSavedInfo>;118119void expandAlloca(MachineInstr *AI, const HexagonInstrInfo &TII,120Register SP, unsigned CF) const;121void insertPrologueInBlock(MachineBasicBlock &MBB, bool PrologueStubs) const;122void insertEpilogueInBlock(MachineBasicBlock &MBB) const;123void insertAllocframe(MachineBasicBlock &MBB,124MachineBasicBlock::iterator InsertPt, unsigned NumBytes) const;125bool insertCSRSpillsInBlock(MachineBasicBlock &MBB, const CSIVect &CSI,126const HexagonRegisterInfo &HRI, bool &PrologueStubs) const;127bool insertCSRRestoresInBlock(MachineBasicBlock &MBB, const CSIVect &CSI,128const HexagonRegisterInfo &HRI) const;129void updateEntryPaths(MachineFunction &MF, MachineBasicBlock &SaveB) const;130bool updateExitPaths(MachineBasicBlock &MBB, MachineBasicBlock &RestoreB,131BitVector &DoneT, BitVector &DoneF, BitVector &Path) const;132void insertCFIInstructionsAt(MachineBasicBlock &MBB,133MachineBasicBlock::iterator At) const;134135bool expandCopy(MachineBasicBlock &B, MachineBasicBlock::iterator It,136MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,137SmallVectorImpl<Register> &NewRegs) const;138bool expandStoreInt(MachineBasicBlock &B, MachineBasicBlock::iterator It,139MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,140SmallVectorImpl<Register> &NewRegs) const;141bool expandLoadInt(MachineBasicBlock &B, MachineBasicBlock::iterator It,142MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,143SmallVectorImpl<Register> &NewRegs) const;144bool expandStoreVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It,145MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,146SmallVectorImpl<Register> &NewRegs) const;147bool expandLoadVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It,148MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,149SmallVectorImpl<Register> &NewRegs) const;150bool expandStoreVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It,151MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,152SmallVectorImpl<Register> &NewRegs) const;153bool expandLoadVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It,154MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,155SmallVectorImpl<Register> &NewRegs) const;156bool expandStoreVec(MachineBasicBlock &B, MachineBasicBlock::iterator It,157MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,158SmallVectorImpl<Register> &NewRegs) const;159bool expandLoadVec(MachineBasicBlock &B, MachineBasicBlock::iterator It,160MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,161SmallVectorImpl<Register> &NewRegs) const;162bool expandSpillMacros(MachineFunction &MF,163SmallVectorImpl<Register> &NewRegs) const;164165Register findPhysReg(MachineFunction &MF, HexagonBlockRanges::IndexRange &FIR,166HexagonBlockRanges::InstrIndexMap &IndexMap,167HexagonBlockRanges::RegToRangeMap &DeadMap,168const TargetRegisterClass *RC) const;169void optimizeSpillSlots(MachineFunction &MF,170SmallVectorImpl<Register> &VRegs) const;171172void findShrunkPrologEpilog(MachineFunction &MF, MachineBasicBlock *&PrologB,173MachineBasicBlock *&EpilogB) const;174175void addCalleeSaveRegistersAsImpOperand(MachineInstr *MI, const CSIVect &CSI,176bool IsDef, bool IsKill) const;177bool shouldInlineCSR(const MachineFunction &MF, const CSIVect &CSI) const;178bool useSpillFunction(const MachineFunction &MF, const CSIVect &CSI) const;179bool useRestoreFunction(const MachineFunction &MF, const CSIVect &CSI) const;180bool mayOverflowFrameOffset(MachineFunction &MF) const;181};182183} // end namespace llvm184185#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H186187188