| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 1 | //===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===// |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
| Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains the Mips implementation of the TargetInstrInfo class. |
| 11 | // |
| Sasa Stankovic | 7b061a4 | 2014-04-30 15:06:25 +0000 | [diff] [blame] | 12 | // FIXME: We need to override TargetInstrInfo::getInlineAsmLength method in |
| 13 | // order for MipsLongBranch pass to work correctly when the code has inline |
| 14 | // assembly. The returned value doesn't have to be the asm instruction's exact |
| 15 | // size in bytes; MipsLongBranch only expects it to be the correct upper bound. |
| Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 17 | |
| Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 18 | #ifndef LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H |
| 19 | #define LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 20 | |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 21 | #include "MCTargetDesc/MipsMCTargetDesc.h" |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 22 | #include "Mips.h" |
| Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 23 | #include "MipsRegisterInfo.h" |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/ArrayRef.h" |
| 25 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| Akira Hatanaka | 310e26a | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/MachineMemOperand.h" |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 28 | #include "llvm/Target/TargetInstrInfo.h" |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 29 | #include <cstdint> |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 30 | |
| Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 31 | #define GET_INSTRINFO_HEADER |
| 32 | #include "MipsGenInstrInfo.inc" |
| 33 | |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 34 | namespace llvm { |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 35 | |
| 36 | class MachineInstr; |
| 37 | class MachineOperand; |
| Eric Christopher | a20c3cf | 2015-03-12 05:43:57 +0000 | [diff] [blame] | 38 | class MipsSubtarget; |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 39 | class TargetRegisterClass; |
| 40 | class TargetRegisterInfo; |
| 41 | |
| Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 42 | class MipsInstrInfo : public MipsGenInstrInfo { |
| Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 43 | virtual void anchor(); |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 44 | |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 45 | protected: |
| Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 46 | const MipsSubtarget &Subtarget; |
| Akira Hatanaka | 5d5e0d8 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 47 | unsigned UncondBrOpc; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 48 | |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 49 | public: |
| Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 50 | enum BranchType { |
| 51 | BT_None, // Couldn't analyze branch. |
| 52 | BT_NoBranch, // No branches found. |
| 53 | BT_Uncond, // One unconditional branch. |
| 54 | BT_Cond, // One conditional branch. |
| 55 | BT_CondUncond, // A conditional branch followed by an unconditional branch. |
| 56 | BT_Indirect // One indirct branch. |
| 57 | }; |
| 58 | |
| Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 59 | explicit MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc); |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 60 | |
| Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 61 | static const MipsInstrInfo *create(MipsSubtarget &STI); |
| Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 62 | |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 63 | /// Branch Analysis |
| Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 64 | bool analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 65 | MachineBasicBlock *&FBB, |
| 66 | SmallVectorImpl<MachineOperand> &Cond, |
| 67 | bool AllowModify) const override; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 68 | |
| Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 69 | unsigned removeBranch(MachineBasicBlock &MBB, |
| Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 70 | int *BytesRemoved = nullptr) const override; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 71 | |
| Matt Arsenault | e8e0f5c | 2016-09-14 17:24:15 +0000 | [diff] [blame] | 72 | unsigned insertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 73 | MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond, |
| Matt Arsenault | a2b036e | 2016-09-14 17:23:48 +0000 | [diff] [blame] | 74 | const DebugLoc &DL, |
| 75 | int *BytesAdded = nullptr) const override; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 76 | |
| Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 77 | bool |
| Matt Arsenault | 1b9fc8e | 2016-09-14 20:43:16 +0000 | [diff] [blame] | 78 | reverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 79 | |
| Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 80 | BranchType analyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 81 | MachineBasicBlock *&FBB, |
| 82 | SmallVectorImpl<MachineOperand> &Cond, |
| 83 | bool AllowModify, |
| Jacques Pienaar | 71c30a1 | 2016-07-15 14:41:04 +0000 | [diff] [blame] | 84 | SmallVectorImpl<MachineInstr *> &BranchInstrs) const; |
| Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 85 | |
| Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame] | 86 | /// Determine the opcode of a non-delay slot form for a branch if one exists. |
| 87 | unsigned getEquivalentCompactForm(const MachineBasicBlock::iterator I) const; |
| 88 | |
| 89 | /// Predicate to determine if an instruction can go in a forbidden slot. |
| 90 | bool SafeInForbiddenSlot(const MachineInstr &MI) const; |
| 91 | |
| 92 | /// Predicate to determine if an instruction has a forbidden slot. |
| 93 | bool HasForbiddenSlot(const MachineInstr &MI) const; |
| 94 | |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 95 | /// Insert nop instruction when hazard condition is found |
| Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 96 | void insertNoop(MachineBasicBlock &MBB, |
| 97 | MachineBasicBlock::iterator MI) const override; |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 98 | |
| 99 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 100 | /// such, whenever a client has an instance of instruction info, it should |
| 101 | /// always be able to get register info as well (through this method). |
| Akira Hatanaka | cb37e13 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 102 | virtual const MipsRegisterInfo &getRegisterInfo() const = 0; |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 103 | |
| Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 104 | virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0; |
| Akira Hatanaka | acd1a7d | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 105 | |
| 106 | /// Return the number of bytes of code the specified instruction may be. |
| Sjoerd Meijer | 0eb96ed | 2016-07-29 08:16:16 +0000 | [diff] [blame] | 107 | unsigned getInstSizeInBytes(const MachineInstr &MI) const override; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 108 | |
| Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 109 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 110 | MachineBasicBlock::iterator MBBI, |
| 111 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 112 | const TargetRegisterClass *RC, |
| 113 | const TargetRegisterInfo *TRI) const override { |
| Akira Hatanaka | 465facca | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 114 | storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0); |
| 115 | } |
| 116 | |
| Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 117 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 118 | MachineBasicBlock::iterator MBBI, |
| 119 | unsigned DestReg, int FrameIndex, |
| 120 | const TargetRegisterClass *RC, |
| 121 | const TargetRegisterInfo *TRI) const override { |
| Akira Hatanaka | 465facca | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 122 | loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0); |
| 123 | } |
| 124 | |
| 125 | virtual void storeRegToStack(MachineBasicBlock &MBB, |
| 126 | MachineBasicBlock::iterator MI, |
| 127 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 128 | const TargetRegisterClass *RC, |
| 129 | const TargetRegisterInfo *TRI, |
| 130 | int64_t Offset) const = 0; |
| 131 | |
| 132 | virtual void loadRegFromStack(MachineBasicBlock &MBB, |
| 133 | MachineBasicBlock::iterator MI, |
| 134 | unsigned DestReg, int FrameIndex, |
| 135 | const TargetRegisterClass *RC, |
| 136 | const TargetRegisterInfo *TRI, |
| 137 | int64_t Offset) const = 0; |
| 138 | |
| Vasileios Kalintiris | 6d68778 | 2015-04-02 10:42:44 +0000 | [diff] [blame] | 139 | virtual void adjustStackPtr(unsigned SP, int64_t Amount, |
| 140 | MachineBasicBlock &MBB, |
| 141 | MachineBasicBlock::iterator I) const = 0; |
| 142 | |
| Akira Hatanaka | 310e26a | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 143 | /// Create an instruction which has the same operands and memory operands |
| 144 | /// as MI but has a new opcode. |
| 145 | MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc, |
| 146 | MachineBasicBlock::iterator I) const; |
| 147 | |
| Petar Jovanovic | 9bff3b7 | 2017-03-31 14:31:55 +0000 | [diff] [blame] | 148 | bool findCommutedOpIndices(MachineInstr &MI, unsigned &SrcOpIdx1, |
| 149 | unsigned &SrcOpIdx2) const override; |
| 150 | |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 151 | protected: |
| 152 | bool isZeroImm(const MachineOperand &op) const; |
| 153 | |
| 154 | MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI, |
| Justin Lebar | 0af80cd | 2016-07-15 18:26:59 +0000 | [diff] [blame] | 155 | MachineMemOperand::Flags Flags) const; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 156 | |
| 157 | private: |
| Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 158 | virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0; |
| Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 159 | |
| 160 | void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, |
| 161 | MachineBasicBlock *&BB, |
| 162 | SmallVectorImpl<MachineOperand> &Cond) const; |
| 163 | |
| Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 164 | void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 165 | const DebugLoc &DL, ArrayRef<MachineOperand> Cond) const; |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
| Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 168 | /// Create MipsInstrInfo objects. |
| Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 169 | const MipsInstrInfo *createMips16InstrInfo(const MipsSubtarget &STI); |
| 170 | const MipsInstrInfo *createMipsSEInstrInfo(const MipsSubtarget &STI); |
| Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 171 | |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 172 | } // end namespace llvm |
| Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 173 | |
| Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 174 | #endif // LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H |