Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 1 | //===-- Mips16InstrInfo.h - Mips16 Instruction Information ------*- 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 | // This file contains the Mips16 implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef MIPS16INSTRUCTIONINFO_H |
| 15 | #define MIPS16INSTRUCTIONINFO_H |
| 16 | |
Akira Hatanaka | cb37e13 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 17 | #include "Mips16RegisterInfo.h" |
Chandler Carruth | 802d755 | 2012-12-04 07:12:27 +0000 | [diff] [blame] | 18 | #include "MipsInstrInfo.h" |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 19 | |
| 20 | namespace llvm { |
| 21 | |
| 22 | class Mips16InstrInfo : public MipsInstrInfo { |
Akira Hatanaka | cb37e13 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 23 | const Mips16RegisterInfo RI; |
| 24 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 25 | public: |
| 26 | explicit Mips16InstrInfo(MipsTargetMachine &TM); |
| 27 | |
Akira Hatanaka | cb37e13 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 28 | virtual const MipsRegisterInfo &getRegisterInfo() const; |
| 29 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 30 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 31 | /// load from a stack slot, return the virtual or physical register number of |
| 32 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 33 | /// not, return 0. This predicate must return 0 if the instruction has |
| 34 | /// any side effects other than loading from the stack slot. |
| 35 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 36 | int &FrameIndex) const; |
| 37 | |
| 38 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 39 | /// store to a stack slot, return the virtual or physical register number of |
| 40 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 41 | /// not, return 0. This predicate must return 0 if the instruction has |
| 42 | /// any side effects other than storing to the stack slot. |
| 43 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 44 | int &FrameIndex) const; |
| 45 | |
| 46 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 47 | MachineBasicBlock::iterator MI, DebugLoc DL, |
| 48 | unsigned DestReg, unsigned SrcReg, |
| 49 | bool KillSrc) const; |
| 50 | |
Akira Hatanaka | 465facca | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 51 | virtual void storeRegToStack(MachineBasicBlock &MBB, |
| 52 | MachineBasicBlock::iterator MBBI, |
| 53 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 54 | const TargetRegisterClass *RC, |
| 55 | const TargetRegisterInfo *TRI, |
| 56 | int64_t Offset) const; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 57 | |
Akira Hatanaka | 465facca | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 58 | virtual void loadRegFromStack(MachineBasicBlock &MBB, |
| 59 | MachineBasicBlock::iterator MBBI, |
| 60 | unsigned DestReg, int FrameIndex, |
| 61 | const TargetRegisterClass *RC, |
| 62 | const TargetRegisterInfo *TRI, |
| 63 | int64_t Offset) const; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 64 | |
| 65 | virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const; |
| 66 | |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 67 | virtual unsigned getOppositeBranchOpc(unsigned Opc) const; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 68 | |
Reed Kotler | d019dbf | 2012-12-20 04:07:42 +0000 | [diff] [blame] | 69 | // Adjust SP by FrameSize bytes. Save RA, S0, S1 |
| 70 | void makeFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, |
Reed Kotler | 30cedf6 | 2013-08-04 01:13:25 +0000 | [diff] [blame^] | 71 | MachineBasicBlock::iterator I) const; |
Reed Kotler | d019dbf | 2012-12-20 04:07:42 +0000 | [diff] [blame] | 72 | |
| 73 | // Adjust SP by FrameSize bytes. Restore RA, S0, S1 |
| 74 | void restoreFrame(unsigned SP, int64_t FrameSize, MachineBasicBlock &MBB, |
| 75 | MachineBasicBlock::iterator I) const; |
| 76 | |
| 77 | |
Reed Kotler | 27a7229 | 2012-10-31 05:21:10 +0000 | [diff] [blame] | 78 | /// Adjust SP by Amount bytes. |
| 79 | void adjustStackPtr(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, |
| 80 | MachineBasicBlock::iterator I) const; |
| 81 | |
Reed Kotler | 66165c8 | 2013-02-08 03:57:41 +0000 | [diff] [blame] | 82 | /// Emit a series of instructions to load an immediate. |
| 83 | // This is to adjust some FrameReg. We return the new register to be used |
| 84 | // in place of FrameReg and the adjusted immediate field (&NewImm) |
| 85 | // |
| 86 | unsigned loadImmediate(unsigned FrameReg, |
| 87 | int64_t Imm, MachineBasicBlock &MBB, |
Reed Kotler | d019dbf | 2012-12-20 04:07:42 +0000 | [diff] [blame] | 88 | MachineBasicBlock::iterator II, DebugLoc DL, |
Reed Kotler | 66165c8 | 2013-02-08 03:57:41 +0000 | [diff] [blame] | 89 | unsigned &NewImm) const; |
Reed Kotler | d019dbf | 2012-12-20 04:07:42 +0000 | [diff] [blame] | 90 | |
Reed Kotler | 30cedf6 | 2013-08-04 01:13:25 +0000 | [diff] [blame^] | 91 | unsigned basicLoadImmediate(unsigned FrameReg, |
| 92 | int64_t Imm, MachineBasicBlock &MBB, |
| 93 | MachineBasicBlock::iterator II, DebugLoc DL, |
| 94 | unsigned &NewImm) const; |
| 95 | |
| 96 | static bool validImmediate(unsigned Opcode, unsigned Reg, int64_t Amount); |
| 97 | |
Reed Kotler | f662cff | 2013-02-13 20:28:27 +0000 | [diff] [blame] | 98 | static bool validSpImm8(int offset) { |
| 99 | return ((offset & 7) == 0) && isInt<11>(offset); |
| 100 | } |
| 101 | |
| 102 | // |
| 103 | // build the proper one based on the Imm field |
| 104 | // |
Reed Kotler | f662cff | 2013-02-13 20:28:27 +0000 | [diff] [blame] | 105 | |
Reed Kotler | 8cf5103 | 2013-02-16 09:47:57 +0000 | [diff] [blame] | 106 | const MCInstrDesc& AddiuSpImm(int64_t Imm) const; |
Reed Kotler | f662cff | 2013-02-13 20:28:27 +0000 | [diff] [blame] | 107 | |
Reed Kotler | 188dad0 | 2013-02-16 19:04:29 +0000 | [diff] [blame] | 108 | void BuildAddiuSpImm |
| 109 | (MachineBasicBlock &MBB, MachineBasicBlock::iterator I, int64_t Imm) const; |
| 110 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 111 | private: |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 112 | virtual unsigned getAnalyzableBrOpc(unsigned Opc) const; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 113 | |
| 114 | void ExpandRetRA16(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 115 | unsigned Opc) const; |
Reed Kotler | d019dbf | 2012-12-20 04:07:42 +0000 | [diff] [blame] | 116 | |
| 117 | // Adjust SP by Amount bytes where bytes can be up to 32bit number. |
| 118 | void adjustStackPtrBig(unsigned SP, int64_t Amount, MachineBasicBlock &MBB, |
| 119 | MachineBasicBlock::iterator I, |
| 120 | unsigned Reg1, unsigned Reg2) const; |
| 121 | |
| 122 | // Adjust SP by Amount bytes where bytes can be up to 32bit number. |
Akira Hatanaka | e067e5a | 2013-01-04 19:38:05 +0000 | [diff] [blame] | 123 | void adjustStackPtrBigUnrestricted(unsigned SP, int64_t Amount, |
| 124 | MachineBasicBlock &MBB, |
| 125 | MachineBasicBlock::iterator I) const; |
Reed Kotler | d019dbf | 2012-12-20 04:07:42 +0000 | [diff] [blame] | 126 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | } |
| 130 | |
| 131 | #endif |