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