LLVM  8.0.1
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 BitVector;
24 class HexagonInstrInfo;
25 class HexagonRegisterInfo;
26 class MachineFunction;
27 class MachineInstr;
28 class MachineRegisterInfo;
29 class TargetRegisterClass;
30 
32 public:
35 
36  // All of the prolog/epilog functionality, including saving and restoring
37  // callee-saved registers is handled in emitPrologue. This is to have the
38  // logic for shrink-wrapping in one place.
39  void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const
40  override;
42  override {}
43 
44  bool enableCalleeSaveSkip(const MachineFunction &MF) const override;
45 
47  MachineBasicBlock::iterator MI, const std::vector<CalleeSavedInfo> &CSI,
48  const TargetRegisterInfo *TRI) const override {
49  return true;
50  }
51 
53  MachineBasicBlock::iterator MI, std::vector<CalleeSavedInfo> &CSI,
54  const TargetRegisterInfo *TRI) const override {
55  return true;
56  }
57 
58  bool hasReservedCallFrame(const MachineFunction &MF) const override {
59  // We always reserve call frame as a part of the initial stack allocation.
60  return true;
61  }
62 
63  bool canSimplifyCallFramePseudos(const MachineFunction &MF) const override {
64  // Override this function to avoid calling hasFP before CSI is set
65  // (the default implementation calls hasFP).
66  return true;
67  }
68 
71  MachineBasicBlock::iterator I) const override;
73  RegScavenger *RS = nullptr) const override;
74  void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs,
75  RegScavenger *RS) const override;
76 
77  bool targetHandlesStackFrameRounding() const override {
78  return true;
79  }
80 
81  int getFrameIndexReference(const MachineFunction &MF, int FI,
82  unsigned &FrameReg) const override;
83  bool hasFP(const MachineFunction &MF) const override;
84 
85  const SpillSlot *getCalleeSavedSpillSlots(unsigned &NumEntries)
86  const override {
87  static const SpillSlot Offsets[] = {
88  { Hexagon::R17, -4 }, { Hexagon::R16, -8 }, { Hexagon::D8, -8 },
89  { Hexagon::R19, -12 }, { Hexagon::R18, -16 }, { Hexagon::D9, -16 },
90  { Hexagon::R21, -20 }, { Hexagon::R20, -24 }, { Hexagon::D10, -24 },
91  { Hexagon::R23, -28 }, { Hexagon::R22, -32 }, { Hexagon::D11, -32 },
92  { Hexagon::R25, -36 }, { Hexagon::R24, -40 }, { Hexagon::D12, -40 },
93  { Hexagon::R27, -44 }, { Hexagon::R26, -48 }, { Hexagon::D13, -48 }
94  };
95  NumEntries = array_lengthof(Offsets);
96  return Offsets;
97  }
98 
100  const TargetRegisterInfo *TRI, std::vector<CalleeSavedInfo> &CSI)
101  const override;
102 
103  bool needsAligna(const MachineFunction &MF) const;
104  const MachineInstr *getAlignaInstr(const MachineFunction &MF) const;
105 
106  void insertCFIInstructions(MachineFunction &MF) const;
107 
108 private:
109  using CSIVect = std::vector<CalleeSavedInfo>;
110 
111  void expandAlloca(MachineInstr *AI, const HexagonInstrInfo &TII,
112  unsigned SP, unsigned CF) const;
113  void insertPrologueInBlock(MachineBasicBlock &MBB, bool PrologueStubs) const;
114  void insertEpilogueInBlock(MachineBasicBlock &MBB) const;
115  void insertAllocframe(MachineBasicBlock &MBB,
116  MachineBasicBlock::iterator InsertPt, unsigned NumBytes) const;
117  bool insertCSRSpillsInBlock(MachineBasicBlock &MBB, const CSIVect &CSI,
118  const HexagonRegisterInfo &HRI, bool &PrologueStubs) const;
119  bool insertCSRRestoresInBlock(MachineBasicBlock &MBB, const CSIVect &CSI,
120  const HexagonRegisterInfo &HRI) const;
121  void updateEntryPaths(MachineFunction &MF, MachineBasicBlock &SaveB) const;
122  bool updateExitPaths(MachineBasicBlock &MBB, MachineBasicBlock &RestoreB,
123  BitVector &DoneT, BitVector &DoneF, BitVector &Path) const;
124  void insertCFIInstructionsAt(MachineBasicBlock &MBB,
125  MachineBasicBlock::iterator At) const;
126 
127  void adjustForCalleeSavedRegsSpillCall(MachineFunction &MF) const;
128 
129  bool expandCopy(MachineBasicBlock &B, MachineBasicBlock::iterator It,
131  SmallVectorImpl<unsigned> &NewRegs) const;
132  bool expandStoreInt(MachineBasicBlock &B, MachineBasicBlock::iterator It,
133  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
134  SmallVectorImpl<unsigned> &NewRegs) const;
135  bool expandLoadInt(MachineBasicBlock &B, MachineBasicBlock::iterator It,
136  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
137  SmallVectorImpl<unsigned> &NewRegs) const;
138  bool expandStoreVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It,
139  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
140  SmallVectorImpl<unsigned> &NewRegs) const;
141  bool expandLoadVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It,
142  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
143  SmallVectorImpl<unsigned> &NewRegs) const;
144  bool expandStoreVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It,
145  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
146  SmallVectorImpl<unsigned> &NewRegs) const;
147  bool expandLoadVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It,
148  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
149  SmallVectorImpl<unsigned> &NewRegs) const;
150  bool expandStoreVec(MachineBasicBlock &B, MachineBasicBlock::iterator It,
151  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
152  SmallVectorImpl<unsigned> &NewRegs) const;
153  bool expandLoadVec(MachineBasicBlock &B, MachineBasicBlock::iterator It,
154  MachineRegisterInfo &MRI, const HexagonInstrInfo &HII,
155  SmallVectorImpl<unsigned> &NewRegs) const;
156  bool expandSpillMacros(MachineFunction &MF,
157  SmallVectorImpl<unsigned> &NewRegs) const;
158 
159  unsigned findPhysReg(MachineFunction &MF, HexagonBlockRanges::IndexRange &FIR,
162  const TargetRegisterClass *RC) const;
163  void optimizeSpillSlots(MachineFunction &MF,
164  SmallVectorImpl<unsigned> &VRegs) const;
165 
166  void findShrunkPrologEpilog(MachineFunction &MF, MachineBasicBlock *&PrologB,
167  MachineBasicBlock *&EpilogB) const;
168 
169  void addCalleeSaveRegistersAsImpOperand(MachineInstr *MI, const CSIVect &CSI,
170  bool IsDef, bool IsKill) const;
171  bool shouldInlineCSR(const MachineFunction &MF, const CSIVect &CSI) const;
172  bool useSpillFunction(const MachineFunction &MF, const CSIVect &CSI) const;
173  bool useRestoreFunction(const MachineFunction &MF, const CSIVect &CSI) const;
174  bool mayOverflowFrameOffset(MachineFunction &MF) const;
175 };
176 
177 } // end namespace llvm
178 
179 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H
This class represents lattice values for constants.
Definition: AllocatorList.h:24
Offsets
Offsets in bytes from the start of the input buffer.
Definition: SIInstrInfo.h:1025
const SpillSlot * getCalleeSavedSpillSlots(unsigned &NumEntries) const override
getCalleeSavedSpillSlots - This method returns a pointer to an array of pairs, that contains an entry...
unsigned const TargetRegisterInfo * TRI
block Block Frequency true
std::map< RegisterRef, RangeList > RegToRangeMap
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...
const MachineInstr * getAlignaInstr(const MachineFunction &MF) const
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.
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:
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
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...
constexpr size_t array_lengthof(T(&)[N])
Find the length of an array.
Definition: STLExtras.h:1044
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:64
bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI, std::vector< CalleeSavedInfo > &CSI, const TargetRegisterInfo *TRI) const override
restoreCalleeSavedRegisters - Issues instruction(s) to restore all callee saved registers and returns...
#define I(x, y, z)
Definition: MD5.cpp:58
void insertCFIInstructions(MachineFunction &MF) const
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&#39;s best to simplify the call frame pseudo ops before d...
bool enableCalleeSaveSkip(const MachineFunction &MF) const override
Returns true if the target can safely skip saving callee-saved registers for noreturn nounwind functi...
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
bool needsAligna(const MachineFunction &MF) const