Jia Liu | f54f60f | 2012-02-28 07:46:26 +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 | |
| 21 | #include "Mips.h" |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 22 | #include "MipsRegisterInfo.h" |
Akira Hatanaka | 310e26a | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 23 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Torok Edwin | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 25 | #include "llvm/Target/TargetInstrInfo.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 26 | |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 27 | #define GET_INSTRINFO_HEADER |
| 28 | #include "MipsGenInstrInfo.inc" |
| 29 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 30 | namespace llvm { |
Eric Christopher | a20c3cf | 2015-03-12 05:43:57 +0000 | [diff] [blame] | 31 | class MipsSubtarget; |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 32 | class MipsInstrInfo : public MipsGenInstrInfo { |
Juergen Ributzka | d12ccbd | 2013-11-19 00:57:56 +0000 | [diff] [blame] | 33 | virtual void anchor(); |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 34 | protected: |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 35 | const MipsSubtarget &Subtarget; |
Akira Hatanaka | 5d5e0d8 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 36 | unsigned UncondBrOpc; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 37 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 38 | public: |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 39 | enum BranchType { |
| 40 | BT_None, // Couldn't analyze branch. |
| 41 | BT_NoBranch, // No branches found. |
| 42 | BT_Uncond, // One unconditional branch. |
| 43 | BT_Cond, // One conditional branch. |
| 44 | BT_CondUncond, // A conditional branch followed by an unconditional branch. |
| 45 | BT_Indirect // One indirct branch. |
| 46 | }; |
| 47 | |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 48 | explicit MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc); |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 49 | |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 50 | static const MipsInstrInfo *create(MipsSubtarget &STI); |
Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 51 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 52 | /// Branch Analysis |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 53 | bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 54 | MachineBasicBlock *&FBB, |
| 55 | SmallVectorImpl<MachineOperand> &Cond, |
| 56 | bool AllowModify) const override; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 57 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 58 | unsigned RemoveBranch(MachineBasicBlock &MBB) const override; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 59 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 60 | unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 61 | MachineBasicBlock *FBB, ArrayRef<MachineOperand> Cond, |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 62 | DebugLoc DL) const override; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 63 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 64 | bool |
| 65 | ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 66 | |
Akira Hatanaka | 7320b23 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 67 | BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 68 | MachineBasicBlock *&FBB, |
| 69 | SmallVectorImpl<MachineOperand> &Cond, |
| 70 | bool AllowModify, |
| 71 | SmallVectorImpl<MachineInstr*> &BranchInstrs) const; |
| 72 | |
Daniel Sanders | e8efff3 | 2016-03-14 16:24:05 +0000 | [diff] [blame^] | 73 | /// Determine the opcode of a non-delay slot form for a branch if one exists. |
| 74 | unsigned getEquivalentCompactForm(const MachineBasicBlock::iterator I) const; |
| 75 | |
| 76 | /// Predicate to determine if an instruction can go in a forbidden slot. |
| 77 | bool SafeInForbiddenSlot(const MachineInstr &MI) const; |
| 78 | |
| 79 | /// Predicate to determine if an instruction has a forbidden slot. |
| 80 | bool HasForbiddenSlot(const MachineInstr &MI) const; |
| 81 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 82 | /// Insert nop instruction when hazard condition is found |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 83 | void insertNoop(MachineBasicBlock &MBB, |
| 84 | MachineBasicBlock::iterator MI) const override; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 85 | |
| 86 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 87 | /// such, whenever a client has an instance of instruction info, it should |
| 88 | /// always be able to get register info as well (through this method). |
| 89 | /// |
Akira Hatanaka | cb37e13 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 90 | virtual const MipsRegisterInfo &getRegisterInfo() const = 0; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 91 | |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 92 | virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0; |
Akira Hatanaka | acd1a7d | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 93 | |
| 94 | /// Return the number of bytes of code the specified instruction may be. |
| 95 | unsigned GetInstSizeInBytes(const MachineInstr *MI) const; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 96 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 97 | void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 98 | MachineBasicBlock::iterator MBBI, |
| 99 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 100 | const TargetRegisterClass *RC, |
| 101 | const TargetRegisterInfo *TRI) const override { |
Akira Hatanaka | 465facca | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 102 | storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0); |
| 103 | } |
| 104 | |
Craig Topper | 56c590a | 2014-04-29 07:58:02 +0000 | [diff] [blame] | 105 | void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 106 | MachineBasicBlock::iterator MBBI, |
| 107 | unsigned DestReg, int FrameIndex, |
| 108 | const TargetRegisterClass *RC, |
| 109 | const TargetRegisterInfo *TRI) const override { |
Akira Hatanaka | 465facca | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 110 | loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0); |
| 111 | } |
| 112 | |
| 113 | virtual void storeRegToStack(MachineBasicBlock &MBB, |
| 114 | MachineBasicBlock::iterator MI, |
| 115 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 116 | const TargetRegisterClass *RC, |
| 117 | const TargetRegisterInfo *TRI, |
| 118 | int64_t Offset) const = 0; |
| 119 | |
| 120 | virtual void loadRegFromStack(MachineBasicBlock &MBB, |
| 121 | MachineBasicBlock::iterator MI, |
| 122 | unsigned DestReg, int FrameIndex, |
| 123 | const TargetRegisterClass *RC, |
| 124 | const TargetRegisterInfo *TRI, |
| 125 | int64_t Offset) const = 0; |
| 126 | |
Vasileios Kalintiris | 6d68778 | 2015-04-02 10:42:44 +0000 | [diff] [blame] | 127 | virtual void adjustStackPtr(unsigned SP, int64_t Amount, |
| 128 | MachineBasicBlock &MBB, |
| 129 | MachineBasicBlock::iterator I) const = 0; |
| 130 | |
Akira Hatanaka | 310e26a | 2013-05-13 17:57:42 +0000 | [diff] [blame] | 131 | /// Create an instruction which has the same operands and memory operands |
| 132 | /// as MI but has a new opcode. |
| 133 | MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc, |
| 134 | MachineBasicBlock::iterator I) const; |
| 135 | |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 136 | protected: |
| 137 | bool isZeroImm(const MachineOperand &op) const; |
| 138 | |
| 139 | MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI, |
| 140 | unsigned Flag) const; |
| 141 | |
| 142 | private: |
Akira Hatanaka | 067d815 | 2013-05-13 17:43:19 +0000 | [diff] [blame] | 143 | virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0; |
Akira Hatanaka | b7fa3c9 | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 144 | |
| 145 | void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, |
| 146 | MachineBasicBlock *&BB, |
| 147 | SmallVectorImpl<MachineOperand> &Cond) const; |
| 148 | |
| 149 | void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, |
Ahmed Bougacha | c88bf54 | 2015-06-11 19:30:37 +0000 | [diff] [blame] | 150 | ArrayRef<MachineOperand> Cond) const; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 151 | }; |
| 152 | |
Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 153 | /// Create MipsInstrInfo objects. |
Eric Christopher | 675cb4d | 2014-07-18 23:25:00 +0000 | [diff] [blame] | 154 | const MipsInstrInfo *createMips16InstrInfo(const MipsSubtarget &STI); |
| 155 | const MipsInstrInfo *createMipsSEInstrInfo(const MipsSubtarget &STI); |
Akira Hatanaka | fab8929 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 156 | |
Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 157 | } |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 158 | |
| 159 | #endif |