| 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" |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetFrameLowering.h" |
| 16 | |
| 17 | namespace llvm { |
| 18 | |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 19 | class HexagonInstrInfo; |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 20 | class HexagonRegisterInfo; |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 21 | |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 22 | class HexagonFrameLowering : public TargetFrameLowering { |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 23 | public: |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 24 | explicit HexagonFrameLowering() |
| 25 | : TargetFrameLowering(StackGrowsDown, 8, 0, 1, true) {} |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 26 | |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 27 | // All of the prolog/epilog functionality, including saving and restoring |
| 28 | // callee-saved registers is handled in emitPrologue. This is to have the |
| 29 | // logic for shrink-wrapping in one place. |
| Quentin Colombet | 61b305e | 2015-05-05 17:38:16 +0000 | [diff] [blame] | 30 | void emitPrologue(MachineFunction &MF, MachineBasicBlock &MBB) const |
| 31 | override; |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 32 | void emitEpilogue(MachineFunction &MF, MachineBasicBlock &MBB) const |
| 33 | override {} |
| 34 | bool spillCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 35 | MachineBasicBlock::iterator MI, const std::vector<CalleeSavedInfo> &CSI, |
| 36 | const TargetRegisterInfo *TRI) const override { |
| 37 | return true; |
| 38 | } |
| 39 | bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB, |
| 40 | MachineBasicBlock::iterator MI, const std::vector<CalleeSavedInfo> &CSI, |
| 41 | const TargetRegisterInfo *TRI) const override { |
| 42 | return true; |
| 43 | } |
| 44 | |
| 45 | void eliminateCallFramePseudoInstr(MachineFunction &MF, |
| 46 | MachineBasicBlock &MBB, MachineBasicBlock::iterator I) const override; |
| 47 | void processFunctionBeforeFrameFinalized(MachineFunction &MF, |
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 48 | RegScavenger *RS = nullptr) const override; |
| Matthias Braun | 0256486 | 2015-07-14 17:17:13 +0000 | [diff] [blame] | 49 | void determineCalleeSaves(MachineFunction &MF, BitVector &SavedRegs, |
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 50 | RegScavenger *RS) const override; |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 51 | |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 52 | bool targetHandlesStackFrameRounding() const override { |
| 53 | return true; |
| 54 | } |
| James Y Knight | 5567baf | 2015-08-15 02:32:35 +0000 | [diff] [blame] | 55 | int getFrameIndexReference(const MachineFunction &MF, int FI, |
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 56 | unsigned &FrameReg) const override; |
| Craig Topper | 906c2cd | 2014-04-29 07:58:16 +0000 | [diff] [blame] | 57 | bool hasFP(const MachineFunction &MF) const override; |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 58 | |
| 59 | const SpillSlot *getCalleeSavedSpillSlots(unsigned &NumEntries) |
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 60 | const override { |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 61 | static const SpillSlot Offsets[] = { |
| 62 | { Hexagon::R17, -4 }, { Hexagon::R16, -8 }, { Hexagon::D8, -8 }, |
| 63 | { Hexagon::R19, -12 }, { Hexagon::R18, -16 }, { Hexagon::D9, -16 }, |
| 64 | { Hexagon::R21, -20 }, { Hexagon::R20, -24 }, { Hexagon::D10, -24 }, |
| 65 | { Hexagon::R23, -28 }, { Hexagon::R22, -32 }, { Hexagon::D11, -32 }, |
| 66 | { Hexagon::R25, -36 }, { Hexagon::R24, -40 }, { Hexagon::D12, -40 }, |
| 67 | { Hexagon::R27, -44 }, { Hexagon::R26, -48 }, { Hexagon::D13, -48 } |
| 68 | }; |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 69 | NumEntries = array_lengthof(Offsets); |
| 70 | return Offsets; |
| 71 | } |
| 72 | |
| 73 | bool assignCalleeSavedSpillSlots(MachineFunction &MF, |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 74 | const TargetRegisterInfo *TRI, std::vector<CalleeSavedInfo> &CSI) |
| 75 | const override; |
| Krzysztof Parzyszek | 4fa2a9f | 2015-04-22 16:43:53 +0000 | [diff] [blame] | 76 | |
| 77 | bool needsAligna(const MachineFunction &MF) const; |
| Krzysztof Parzyszek | 23920ec | 2015-10-19 18:30:27 +0000 | [diff] [blame] | 78 | const MachineInstr *getAlignaInstr(const MachineFunction &MF) const; |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 79 | |
| Krzysztof Parzyszek | db86770 | 2015-10-19 17:46:01 +0000 | [diff] [blame] | 80 | void insertCFIInstructions(MachineFunction &MF) const; |
| 81 | |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 82 | private: |
| 83 | typedef std::vector<CalleeSavedInfo> CSIVect; |
| 84 | |
| 85 | void expandAlloca(MachineInstr *AI, const HexagonInstrInfo &TII, |
| 86 | unsigned SP, unsigned CF) const; |
| 87 | void insertPrologueInBlock(MachineBasicBlock &MBB) const; |
| 88 | void insertEpilogueInBlock(MachineBasicBlock &MBB) const; |
| 89 | bool insertCSRSpillsInBlock(MachineBasicBlock &MBB, const CSIVect &CSI, |
| 90 | const HexagonRegisterInfo &HRI) const; |
| 91 | bool insertCSRRestoresInBlock(MachineBasicBlock &MBB, const CSIVect &CSI, |
| 92 | const HexagonRegisterInfo &HRI) const; |
| Krzysztof Parzyszek | db86770 | 2015-10-19 17:46:01 +0000 | [diff] [blame] | 93 | void insertCFIInstructionsAt(MachineBasicBlock &MBB, |
| 94 | MachineBasicBlock::iterator At) const; |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 95 | |
| 96 | void adjustForCalleeSavedRegsSpillCall(MachineFunction &MF) const; |
| Krzysztof Parzyszek | 996ad1f | 2016-02-12 18:19:53 +0000 | [diff] [blame] | 97 | |
| 98 | bool expandCopy(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 99 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 100 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 101 | bool expandStoreInt(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 102 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 103 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 104 | bool expandLoadInt(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 105 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 106 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 107 | bool expandStoreVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 108 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 109 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 110 | bool expandLoadVecPred(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 111 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 112 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 113 | bool expandStoreVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 114 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 115 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 116 | bool expandLoadVec2(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 117 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 118 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 119 | bool expandStoreVec(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 120 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 121 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 122 | bool expandLoadVec(MachineBasicBlock &B, MachineBasicBlock::iterator It, |
| 123 | MachineRegisterInfo &MRI, const HexagonInstrInfo &HII, |
| 124 | SmallVectorImpl<unsigned> &NewRegs) const; |
| 125 | bool expandSpillMacros(MachineFunction &MF, |
| 126 | SmallVectorImpl<unsigned> &NewRegs) const; |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 127 | |
| Krzysztof Parzyszek | 7793ddb | 2016-02-12 22:53:35 +0000 | [diff] [blame] | 128 | unsigned findPhysReg(MachineFunction &MF, HexagonBlockRanges::IndexRange &FIR, |
| 129 | HexagonBlockRanges::InstrIndexMap &IndexMap, |
| 130 | HexagonBlockRanges::RegToRangeMap &DeadMap, |
| 131 | const TargetRegisterClass *RC) const; |
| 132 | void optimizeSpillSlots(MachineFunction &MF, |
| 133 | SmallVectorImpl<unsigned> &VRegs) const; |
| 134 | |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 135 | void findShrunkPrologEpilog(MachineFunction &MF, MachineBasicBlock *&PrologB, |
| 136 | MachineBasicBlock *&EpilogB) const; |
| 137 | |
| Krzysztof Parzyszek | db86770 | 2015-10-19 17:46:01 +0000 | [diff] [blame] | 138 | bool shouldInlineCSR(llvm::MachineFunction &MF, const CSIVect &CSI) const; |
| Krzysztof Parzyszek | 876a19d | 2015-04-23 16:05:39 +0000 | [diff] [blame] | 139 | bool useSpillFunction(MachineFunction &MF, const CSIVect &CSI) const; |
| 140 | bool useRestoreFunction(MachineFunction &MF, const CSIVect &CSI) const; |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
| Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 143 | } // End llvm namespace |
| Tony Linthicum | 1213a7a | 2011-12-12 21:14:40 +0000 | [diff] [blame] | 144 | |
| 145 | #endif |