| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 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 |  | 
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 10 | #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H | 
|  | 11 | #define LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 12 |  | 
|  | 13 | #include "Hexagon.h" | 
| Krzysztof Parzyszek | 7793ddb | 2016-02-12 22:53:35 +0000 | [diff] [blame] | 14 | #include "HexagonBlockRanges.h" | 
| Eugene Zelenko | 26e8c7d | 2016-12-16 01:00:40 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/STLExtras.h" | 
|  | 16 | #include "llvm/CodeGen/MachineBasicBlock.h" | 
|  | 17 | #include "llvm/CodeGen/MachineFrameInfo.h" | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetFrameLowering.h" | 
| Eugene Zelenko | 26e8c7d | 2016-12-16 01:00:40 +0000 | [diff] [blame] | 19 | #include <vector> | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 20 |  | 
|  | 21 | namespace llvm { | 
|  | 22 |  | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 23 | class HexagonInstrInfo; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 24 | class HexagonRegisterInfo; | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 25 |  | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 26 | class HexagonFrameLowering : public TargetFrameLowering { | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 27 | public: | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 28 | explicit HexagonFrameLowering() | 
|  | 29 | : TargetFrameLowering(StackGrowsDown, 8, 0, 1, true) {} | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 30 |  | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 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. | 
| Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 34 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const | 
|  | 35 | override; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 36 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const | 
|  | 37 | override {} | 
| Eugene Zelenko | 26e8c7d | 2016-12-16 01:00:40 +0000 | [diff] [blame] | 38 |  | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 39 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, | 
|  | 40 | MachineBasicBlock::iterator MI, const std::vector<CalleeSavedInfo> &CSI, | 
|  | 41 | const TargetRegisterInfo *TRI) const override { | 
|  | 42 | return true; | 
|  | 43 | } | 
| Eugene Zelenko | 26e8c7d | 2016-12-16 01:00:40 +0000 | [diff] [blame] | 44 |  | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 45 | bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, | 
|  | 46 | MachineBasicBlock::iterator MI, const std::vector<CalleeSavedInfo> &CSI, | 
|  | 47 | const TargetRegisterInfo *TRI) const override { | 
|  | 48 | return true; | 
|  | 49 | } | 
|  | 50 |  | 
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 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 | } | 
| Hans Wennborg | e1a2e90 | 2016-03-31 18:33:38 +0000 | [diff] [blame] | 60 | MachineBasicBlock::iterator | 
|  | 61 | eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, | 
|  | 62 | MachineBasicBlock::iterator I) const override; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 63 | void processFunctionBeforeFrameFinalized(MachineFunction &MF, | 
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 64 | RegScavenger *RS = nullptr) const override; | 
| Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 65 | void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, | 
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 66 | RegScavenger *RS) const override; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 67 |  | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 68 | bool targetHandlesStackFrameRounding() const override { | 
|  | 69 | return true; | 
|  | 70 | } | 
| Eugene Zelenko | 26e8c7d | 2016-12-16 01:00:40 +0000 | [diff] [blame] | 71 |  | 
| James Y Knight | 5567baf | 2015-08-15 02:32:35 +0000 | [diff] [blame] | 72 | int getFrameIndexReference(const MachineFunction &MF, int FI, | 
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 73 | unsigned &FrameReg) const override; | 
| Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 74 | bool hasFP(const MachineFunction &MF) const override; | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 75 |  | 
|  | 76 | const SpillSlot *getCalleeSavedSpillSlots(unsigned &NumEntries) | 
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 77 | const override { | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 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 | }; | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 86 | NumEntries = array_lengthof(Offsets); | 
|  | 87 | return Offsets; | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 | bool assignCalleeSavedSpillSlots(MachineFunction &MF, | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 91 | const TargetRegisterInfo *TRI, std::vector<CalleeSavedInfo> &CSI) | 
|  | 92 | const override; | 
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 93 |  | 
|  | 94 | bool needsAligna(const MachineFunction &MF) const; | 
| Krzysztof Parzyszek | 23920ec | 2015-10-19 18:30:27 +0000 | [diff] [blame] | 95 | const MachineInstr *getAlignaInstr(const MachineFunction &MF) const; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 96 |  | 
| Krzysztof Parzyszek | db86770 | 2015-10-19 17:46:01 +0000 | [diff] [blame] | 97 | void insertCFIInstructions(MachineFunction &MF) const; | 
|  | 98 |  | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 99 | private: | 
|  | 100 | typedef std::vector<CalleeSavedInfo> CSIVect; | 
|  | 101 |  | 
|  | 102 | void expandAlloca(MachineInstr *AI, const HexagonInstrInfo &TII, | 
|  | 103 | unsigned SP, unsigned CF) const; | 
| Krzysztof Parzyszek | c9d4caa | 2016-03-24 20:20:07 +0000 | [diff] [blame] | 104 | void insertPrologueInBlock(MachineBasicBlock &MBB, bool PrologueStubs) const; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 105 | void insertEpilogueInBlock(MachineBasicBlock &MBB) const; | 
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 106 | void insertAllocframe(MachineBasicBlock &MBB, | 
|  | 107 | MachineBasicBlock::iterator InsertPt, unsigned NumBytes) const; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 108 | bool insertCSRSpillsInBlock(MachineBasicBlock &MBB, const CSIVect &CSI, | 
| Krzysztof Parzyszek | c9d4caa | 2016-03-24 20:20:07 +0000 | [diff] [blame] | 109 | const HexagonRegisterInfo &HRI, bool &PrologueStubs) const; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 110 | bool insertCSRRestoresInBlock(MachineBasicBlock &MBB, const CSIVect &CSI, | 
|  | 111 | const HexagonRegisterInfo &HRI) const; | 
| Krzysztof Parzyszek | a34d639 | 2016-07-27 16:26:39 +0000 | [diff] [blame] | 112 | void updateEntryPaths(MachineFunction &MF, MachineBasicBlock &SaveB) const; | 
|  | 113 | bool updateExitPaths(MachineBasicBlock &MBB, MachineBasicBlock &RestoreB, | 
| Krzysztof Parzyszek | da0b9a9 | 2016-05-26 19:44:28 +0000 | [diff] [blame] | 114 | BitVector &DoneT, BitVector &DoneF, BitVector &Path) const; | 
| Krzysztof Parzyszek | db86770 | 2015-10-19 17:46:01 +0000 | [diff] [blame] | 115 | void insertCFIInstructionsAt(MachineBasicBlock &MBB, | 
|  | 116 | MachineBasicBlock::iterator At) const; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 117 |  | 
|  | 118 | void adjustForCalleeSavedRegsSpillCall(MachineFunction &MF) const; | 
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 119 |  | 
|  | 120 | bool expandCopy(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 121 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 122 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 123 | bool expandStoreInt(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 124 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 125 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 126 | bool expandLoadInt(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 127 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 128 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 129 | bool expandStoreVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 130 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 131 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 132 | bool expandLoadVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 133 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 134 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 135 | bool expandStoreVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 136 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 137 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 138 | bool expandLoadVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 139 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 140 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 141 | bool expandStoreVec(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 142 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 143 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 144 | bool expandLoadVec(MachineBasicBlock &B, MachineBasicBlock::iterator It, | 
|  | 145 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, | 
|  | 146 | SmallVectorImpl<unsigned> &NewRegs) const; | 
|  | 147 | bool expandSpillMacros(MachineFunction &MF, | 
|  | 148 | SmallVectorImpl<unsigned> &NewRegs) const; | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 149 |  | 
| Krzysztof Parzyszek | 7793ddb | 2016-02-12 22:53:35 +0000 | [diff] [blame] | 150 | unsigned findPhysReg(MachineFunction &MF, HexagonBlockRanges::IndexRange &FIR, | 
|  | 151 | HexagonBlockRanges::InstrIndexMap &IndexMap, | 
|  | 152 | HexagonBlockRanges::RegToRangeMap &DeadMap, | 
|  | 153 | const TargetRegisterClass *RC) const; | 
|  | 154 | void optimizeSpillSlots(MachineFunction &MF, | 
|  | 155 | SmallVectorImpl<unsigned> &VRegs) const; | 
|  | 156 |  | 
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 157 | void findShrunkPrologEpilog(MachineFunction &MF, MachineBasicBlock *&PrologB, | 
|  | 158 | MachineBasicBlock *&EpilogB) const; | 
|  | 159 |  | 
| Krzysztof Parzyszek | e8e754d | 2016-04-25 17:49:44 +0000 | [diff] [blame] | 160 | void addCalleeSaveRegistersAsImpOperand(MachineInstr *MI, const CSIVect &CSI, | 
|  | 161 | bool IsDef, bool IsKill) const; | 
| Krzysztof Parzyszek | 9eb75c4 | 2017-06-30 21:21:40 +0000 | [diff] [blame] | 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; | 
| Krzysztof Parzyszek | ddafa2c | 2016-08-01 17:15:30 +0000 | [diff] [blame] | 165 | bool mayOverflowFrameOffset(MachineFunction &MF) const; | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 166 | }; | 
|  | 167 |  | 
| Eugene Zelenko | 26e8c7d | 2016-12-16 01:00:40 +0000 | [diff] [blame] | 168 | } // end namespace llvm | 
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 169 |  | 
| Eugene Zelenko | 26e8c7d | 2016-12-16 01:00:40 +0000 | [diff] [blame] | 170 | #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONFRAMELOWERING_H |