LLVM  5.0.0
HexagonFrameLowering.h
Go to the documentation of this file.
1 //=- HexagonFrameLowering.h - Define frame lowering for Hexagon --*- C++ -*--=//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H
11 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H
12 
13 #include "Hexagon.h"
14 #include "HexagonBlockRanges.h"
15 #include "llvm/ADT/STLExtras.h"
19 #include <vector>
20 
21 namespace llvm {
22 
23 class HexagonInstrInfo;
24 class HexagonRegisterInfo;
25 
27 public:
30 
31  // All of the prolog/epilog functionality, including saving and restoring
32  // callee-saved registers is handled in emitPrologue. This is to have the
33  // logic for shrink-wrapping in one place.
34  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const
35  override;
37  override {}
38 
40  MachineBasicBlock::iterator MI, const std::vector<CalleeSavedInfo> &CSI,
41  const TargetRegisterInfo *TRI) const override {
42  return true;
43  }
44 
46  MachineBasicBlock::iterator MI, const std::vector<CalleeSavedInfo> &CSI,
47  const TargetRegisterInfo *TRI) const override {
48  return true;
49  }
50 
51  bool hasReservedCallFrame(const MachineFunction &MF) const override {
52  // We always reserve call frame as a part of the initial stack allocation.
53  return true;
54  }
55  bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override {
56  // Override this function to avoid calling hasFP before CSI is set
57  // (the default implementation calls hasFP).
58  return true;
59  }
62  MachineBasicBlock::iterator I) const override;
64  RegScavenger *RS = nullptr) const override;
65  void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
66  RegScavenger *RS) const override;
67 
68  bool targetHandlesStackFrameRounding() const override {
69  return true;
70  }
71 
72  int getFrameIndexReference(const MachineFunction &MF, int FI,
73  unsigned &FrameReg) const override;
74  bool hasFP(const MachineFunction &MF) const override;
75 
76  const SpillSlot *getCalleeSavedSpillSlots(unsigned &NumEntries)
77  const override {
78  static const SpillSlot Offsets[] = {
79  { Hexagon::R17, -4 }, { Hexagon::R16, -8 }, { Hexagon::D8, -8 },
80  { Hexagon::R19, -12 }, { Hexagon::R18, -16 }, { Hexagon::D9, -16 },
81  { Hexagon::R21, -20 }, { Hexagon::R20, -24 }, { Hexagon::D10, -24 },
82  { Hexagon::R23, -28 }, { Hexagon::R22, -32 }, { Hexagon::D11, -32 },
83  { Hexagon::R25, -36 }, { Hexagon::R24, -40 }, { Hexagon::D12, -40 },
84  { Hexagon::R27, -44 }, { Hexagon::R26, -48 }, { Hexagon::D13, -48 }
85  };
86  NumEntries = array_lengthof(Offsets);
87  return Offsets;
88  }
89 
91  const TargetRegisterInfo *TRI, std::vector<CalleeSavedInfo> &CSI)
92  const override;
93 
94  bool needsAligna(const MachineFunction &MF) const;
95  const MachineInstr *getAlignaInstr(const MachineFunction &MF) const;
96 
97  void insertCFIInstructions(MachineFunction &MF) const;
98 
99 private:
100  typedef std::vector<CalleeSavedInfo> CSIVect;
101 
102  void expandAlloca(MachineInstr *AI, const HexagonInstrInfo &TII,
103  unsigned SP, unsigned CF) const;
104  void insertPrologueInBlock(MachineBasicBlock &MBB, bool PrologueStubs) const;
105  void insertEpilogueInBlock(MachineBasicBlock &MBB) const;
106  void insertAllocframe(MachineBasicBlock &MBB,
107  MachineBasicBlock::iterator InsertPt, unsigned NumBytes) const;
108  bool insertCSRSpillsInBlock(MachineBasicBlock &MBB, const CSIVect &CSI,
109  const HexagonRegisterInfo &HRI, bool &PrologueStubs) const;
110  bool insertCSRRestoresInBlock(MachineBasicBlock &MBB, const CSIVect &CSI,
111  const HexagonRegisterInfo &HRI) const;
112  void updateEntryPaths(MachineFunction &MF, MachineBasicBlock &SaveB) const;
113  bool updateExitPaths(MachineBasicBlock &MBB, MachineBasicBlock &RestoreB,
114  BitVector &DoneT, BitVector &DoneF, BitVector &Path) const;
115  void insertCFIInstructionsAt(MachineBasicBlock &MBB,
116  MachineBasicBlock::iterator At) const;
117 
118  void adjustForCalleeSavedRegsSpillCall(MachineFunction &MF) const;
119 
120  bool expandCopy(MachineBasicBlock &B, MachineBasicBlock::iterator It,
122  SmallVectorImpl<unsigned> &NewRegs) const;
123  bool expandStoreInt(MachineBasicBlock &B, MachineBasicBlock::iterator It,
125  SmallVectorImpl<unsigned> &NewRegs) const;
126  bool expandLoadInt(MachineBasicBlock &B, MachineBasicBlock::iterator It,
128  SmallVectorImpl<unsigned> &NewRegs) const;
129  bool expandStoreVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It,
131  SmallVectorImpl<unsigned> &NewRegs) const;
132  bool expandLoadVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It,
134  SmallVectorImpl<unsigned> &NewRegs) const;
135  bool expandStoreVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It,
137  SmallVectorImpl<unsigned> &NewRegs) const;
138  bool expandLoadVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It,
140  SmallVectorImpl<unsigned> &NewRegs) const;
141  bool expandStoreVec(MachineBasicBlock &B, MachineBasicBlock::iterator It,
143  SmallVectorImpl<unsigned> &NewRegs) const;
144  bool expandLoadVec(MachineBasicBlock &B, MachineBasicBlock::iterator It,
146  SmallVectorImpl<unsigned> &NewRegs) const;
147  bool expandSpillMacros(MachineFunction &MF,
148  SmallVectorImpl<unsigned> &NewRegs) const;
149 
150  unsigned findPhysReg(MachineFunction &MF, HexagonBlockRanges::IndexRange &FIR,
153  const TargetRegisterClass *RC) const;
154  void optimizeSpillSlots(MachineFunction &MF,
156 
157  void findShrunkPrologEpilog(MachineFunction &MF, MachineBasicBlock *&PrologB,
158  MachineBasicBlock *&EpilogB) const;
159 
160  void addCalleeSaveRegistersAsImpOperand(MachineInstr *MI, const CSIVect &CSI,
161  bool IsDef, bool IsKill) const;
162  bool shouldInlineCSR(const MachineFunction &MF, const CSIVect &CSI) const;
163  bool useSpillFunction(const MachineFunction &MF, const CSIVect &CSI) const;
164  bool useRestoreFunction(const MachineFunction &MF, const CSIVect &CSI) const;
165  bool mayOverflowFrameOffset(MachineFunction &MF) const;
166 };
167 
168 } // end namespace llvm
169 
170 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:864
static const MCPhysReg VRegs[32]
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const override
const HexagonInstrInfo * TII
MachineBasicBlock::iterator eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override
This method is called during prolog/epilog code insertion to eliminate call frame setup and destroy p...
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< 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, we reserve argument space for call sites in the function immediately on entry to the current function.
bool needsAligna(const MachineFunction &MF) const
void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, RegScavenger *RS) const override
This method determines which of the registers reported by TargetRegisterInfo::getCalleeSavedRegs() sh...
void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const override
Perform most of the PEI work here:
unsigned const MachineRegisterInfo * MRI
void insertCFIInstructions(MachineFunction &MF) const
void processFunctionBeforeFrameFinalized(MachineFunction &MF, RegScavenger *RS=nullptr) const override
processFunctionBeforeFrameFinalized - This method is called immediately before the specified function...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
#define B
Definition: LargeTest.cpp:24
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:731
Information about stack frame layout on the target.
int getFrameIndexReference(const MachineFunction &MF, int FI, unsigned &FrameReg) const override
getFrameIndexReference - This method should return the base register and offset used to reference a f...
bool assignCalleeSavedSpillSlots(MachineFunction &MF, const TargetRegisterInfo *TRI, std::vector< CalleeSavedInfo > &CSI) const override
assignCalleeSavedSpillSlots - Allows target to override spill slot assignment logic.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
Representation of each machine instruction.
Definition: MachineInstr.h:59
Basic Alias true
std::map< RegisterRef, RangeList > RegToRangeMap
#define I(x, y, z)
Definition: MD5.cpp:58
bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, const std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
spillCalleeSavedRegisters - Issues instruction(s) to spill all callee saved registers and returns tru...
bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override
canSimplifyCallFramePseudos - When possible, it's best to simplify the call frame pseudo ops before d...
bool targetHandlesStackFrameRounding() const override
targetHandlesStackFrameRounding - Returns true if the target is responsible for rounding up the stack...
bool hasFP(const MachineFunction &MF) const override
hasFP - Return true if the specified function should have a dedicated frame pointer register...
IRTranslator LLVM IR MI
const MachineInstr * getAlignaInstr(const MachineFunction &MF) const