Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 1 | //===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 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 | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 7 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 9 | // |
| 10 | // This file contains the Mips implementation of the TargetInstrInfo class. |
| 11 | // |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 13 | |
| 14 | #ifndef MIPSINSTRUCTIONINFO_H |
| 15 | #define MIPSINSTRUCTIONINFO_H |
| 16 | |
| 17 | #include "Mips.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetInstrInfo.h" |
| 20 | #include "MipsRegisterInfo.h" |
| 21 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 22 | #define GET_INSTRINFO_HEADER |
| 23 | #include "MipsGenInstrInfo.inc" |
| 24 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 25 | namespace llvm { |
| 26 | |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 27 | namespace Mips { |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 28 | /// GetOppositeBranchOpc - Return the inverse of the specified |
| 29 | /// opcode, e.g. turning BEQ to BNE. |
| 30 | unsigned GetOppositeBranchOpc(unsigned Opc); |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 33 | /// MipsII - This namespace holds all of the target specific flags that |
| 34 | /// instruction info tracks. |
| 35 | /// |
| 36 | namespace MipsII { |
| 37 | /// Target Operand Flag enum. |
| 38 | enum TOF { |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 39 | //===------------------------------------------------------------------===// |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 40 | // Mips Specific MachineOperand flags. |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 41 | |
Dan Gohman | 01a76ce | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 42 | MO_NO_FLAG, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 43 | |
| 44 | /// MO_GOT - Represents the offset into the global offset table at which |
| 45 | /// the address the relocation entry symbol resides during execution. |
Dan Gohman | 01a76ce | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 46 | MO_GOT, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 47 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 48 | /// MO_GOT_CALL - Represents the offset into the global offset table at |
| 49 | /// which the address of a call site relocation entry symbol resides |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 50 | /// during execution. This is different from the above since this flag |
| 51 | /// can only be present in call instructions. |
Dan Gohman | 01a76ce | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 52 | MO_GOT_CALL, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 53 | |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 54 | /// MO_GPREL - Represents the offset from the current gp value to be used |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 55 | /// for the relocatable object file being produced. |
Dan Gohman | 01a76ce | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 56 | MO_GPREL, |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 57 | |
Akira Hatanaka | e2e436a | 2011-04-01 21:41:06 +0000 | [diff] [blame] | 58 | /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 59 | /// address. |
Akira Hatanaka | e2e436a | 2011-04-01 21:41:06 +0000 | [diff] [blame] | 60 | MO_ABS_HI, |
Bruno Cardoso Lopes | d979686 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 61 | MO_ABS_LO, |
| 62 | |
| 63 | /// MO_TLSGD - Represents the offset into the global offset table at which |
| 64 | // the module ID and TSL block offset reside during execution (General |
| 65 | // Dynamic TLS). |
| 66 | MO_TLSGD, |
| 67 | |
| 68 | /// MO_GOTTPREL - Represents the offset from the thread pointer (Initial |
| 69 | // Exec TLS). |
| 70 | MO_GOTTPREL, |
| 71 | |
| 72 | /// MO_TPREL_HI/LO - Represents the hi and low part of the offset from |
| 73 | // the thread pointer (Local Exec TLS). |
| 74 | MO_TPREL_HI, |
| 75 | MO_TPREL_LO |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 76 | }; |
Bruno Cardoso Lopes | c4cc40c | 2011-09-14 03:00:41 +0000 | [diff] [blame^] | 77 | |
| 78 | enum { |
| 79 | //===------------------------------------------------------------------===// |
| 80 | // Instruction encodings. These are the standard/most common forms for |
| 81 | // Mips instructions. |
| 82 | // |
| 83 | |
| 84 | // Pseudo - This represents an instruction that is a pseudo instruction |
| 85 | // or one that has not been implemented yet. It is illegal to code generate |
| 86 | // it, but tolerated for intermediate implementation stages. |
| 87 | Pseudo = 0, |
| 88 | |
| 89 | /// FrmR - This form is for instructions of the format R. |
| 90 | FrmR = 1, |
| 91 | /// FrmI - This form is for instructions of the format I. |
| 92 | FrmI = 2, |
| 93 | /// FrmJ - This form is for instructions of the format J. |
| 94 | FrmJ = 3, |
| 95 | /// FrmFR - This form is for instructions of the format FR. |
| 96 | FrmFR = 4, |
| 97 | /// FrmFI - This form is for instructions of the format FI. |
| 98 | FrmFI = 5, |
| 99 | /// FrmOther - This form is for instructions that have no specific format. |
| 100 | FrmOther = 6, |
| 101 | |
| 102 | FormMask = 15 |
| 103 | }; |
Bruno Cardoso Lopes | c517cb0 | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 106 | class MipsInstrInfo : public MipsGenInstrInfo { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 107 | MipsTargetMachine &TM; |
| 108 | const MipsRegisterInfo RI; |
| 109 | public: |
Dan Gohman | 950a4c4 | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 110 | explicit MipsInstrInfo(MipsTargetMachine &TM); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 111 | |
| 112 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 113 | /// such, whenever a client has an instance of instruction info, it should |
| 114 | /// always be able to get register info as well (through this method). |
| 115 | /// |
Akira Hatanaka | 794bf17 | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 116 | virtual const MipsRegisterInfo &getRegisterInfo() const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 117 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 118 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 119 | /// load from a stack slot, return the virtual or physical register number of |
| 120 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 121 | /// not, return 0. This predicate must return 0 if the instruction has |
| 122 | /// any side effects other than loading from the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 123 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 124 | int &FrameIndex) const; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 125 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 126 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 127 | /// store to a stack slot, return the virtual or physical register number of |
| 128 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 129 | /// not, return 0. This predicate must return 0 if the instruction has |
| 130 | /// any side effects other than storing to the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 131 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 132 | int &FrameIndex) const; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 133 | |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 134 | /// Branch Analysis |
| 135 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 136 | MachineBasicBlock *&FBB, |
Evan Cheng | dc54d31 | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 137 | SmallVectorImpl<MachineOperand> &Cond, |
| 138 | bool AllowModify) const; |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 139 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 140 | |
| 141 | private: |
| 142 | void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, |
| 143 | const SmallVectorImpl<MachineOperand>& Cond) const; |
| 144 | |
| 145 | public: |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 146 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 147 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 148 | const SmallVectorImpl<MachineOperand> &Cond, |
| 149 | DebugLoc DL) const; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 150 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 151 | MachineBasicBlock::iterator MI, DebugLoc DL, |
| 152 | unsigned DestReg, unsigned SrcReg, |
| 153 | bool KillSrc) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 154 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 155 | MachineBasicBlock::iterator MBBI, |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 156 | unsigned SrcReg, bool isKill, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 157 | const TargetRegisterClass *RC, |
| 158 | const TargetRegisterInfo *TRI) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 159 | |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 160 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 161 | MachineBasicBlock::iterator MBBI, |
| 162 | unsigned DestReg, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 163 | const TargetRegisterClass *RC, |
| 164 | const TargetRegisterInfo *TRI) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 165 | |
Akira Hatanaka | c4f24eb | 2011-07-01 01:04:43 +0000 | [diff] [blame] | 166 | virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF, |
| 167 | int FrameIx, uint64_t Offset, |
| 168 | const MDNode *MDPtr, |
| 169 | DebugLoc DL) const; |
| 170 | |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 171 | virtual |
| 172 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 173 | |
| 174 | /// Insert nop instruction when hazard condition is found |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 175 | virtual void insertNoop(MachineBasicBlock &MBB, |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 176 | MachineBasicBlock::iterator MI) const; |
Dan Gohman | 9911405 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 177 | |
| 178 | /// getGlobalBaseReg - Return a virtual register initialized with the |
| 179 | /// the global base register value. Output instructions required to |
| 180 | /// initialize the register in the function entry block, if necessary. |
| 181 | /// |
| 182 | unsigned getGlobalBaseReg(MachineFunction *MF) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | } |
| 186 | |
| 187 | #endif |