Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +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 | // |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 12 | //===----------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 35e43c4 | 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 | 56d0659 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 18 | #include "llvm/Support/ErrorHandling.h" |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetInstrInfo.h" |
| 20 | #include "MipsRegisterInfo.h" |
| 21 | |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame^] | 22 | #define GET_INSTRINFO_HEADER |
| 23 | #include "MipsGenInstrInfo.inc" |
| 24 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 25 | namespace llvm { |
| 26 | |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 27 | namespace Mips { |
| 28 | |
Bruno Cardoso Lopes | bcaf6e5 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 29 | // Mips Branch Codes |
| 30 | enum FPBranchCode { |
| 31 | BRANCH_F, |
| 32 | BRANCH_T, |
| 33 | BRANCH_FL, |
| 34 | BRANCH_TL, |
| 35 | BRANCH_INVALID |
| 36 | }; |
| 37 | |
Bruno Cardoso Lopes | cfd1638 | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 38 | // Mips Condition Codes |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 39 | enum CondCode { |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 40 | // To be used with float branch True |
| 41 | FCOND_F, |
| 42 | FCOND_UN, |
Akira Hatanaka | a535270 | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 43 | FCOND_OEQ, |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 44 | FCOND_UEQ, |
| 45 | FCOND_OLT, |
| 46 | FCOND_ULT, |
| 47 | FCOND_OLE, |
| 48 | FCOND_ULE, |
| 49 | FCOND_SF, |
| 50 | FCOND_NGLE, |
| 51 | FCOND_SEQ, |
| 52 | FCOND_NGL, |
| 53 | FCOND_LT, |
| 54 | FCOND_NGE, |
| 55 | FCOND_LE, |
| 56 | FCOND_NGT, |
| 57 | |
| 58 | // To be used with float branch False |
| 59 | // This conditions have the same mnemonic as the |
| 60 | // above ones, but are used with a branch False; |
| 61 | FCOND_T, |
| 62 | FCOND_OR, |
Akira Hatanaka | a535270 | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 63 | FCOND_UNE, |
| 64 | FCOND_ONE, |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 65 | FCOND_UGE, |
| 66 | FCOND_OGE, |
| 67 | FCOND_UGT, |
| 68 | FCOND_OGT, |
| 69 | FCOND_ST, |
| 70 | FCOND_GLE, |
| 71 | FCOND_SNE, |
| 72 | FCOND_GL, |
| 73 | FCOND_NLT, |
| 74 | FCOND_GE, |
| 75 | FCOND_NLE, |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 76 | FCOND_GT |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 77 | }; |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 78 | |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 79 | /// GetOppositeBranchOpc - Return the inverse of the specified |
| 80 | /// opcode, e.g. turning BEQ to BNE. |
| 81 | unsigned GetOppositeBranchOpc(unsigned Opc); |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 82 | |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 83 | /// MipsCCToString - Map each FP condition code to its string |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 84 | inline static const char *MipsFCCToString(Mips::CondCode CC) |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 85 | { |
| 86 | switch (CC) { |
Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 87 | default: llvm_unreachable("Unknown condition code"); |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 88 | case FCOND_F: |
| 89 | case FCOND_T: return "f"; |
| 90 | case FCOND_UN: |
| 91 | case FCOND_OR: return "un"; |
Akira Hatanaka | a535270 | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 92 | case FCOND_OEQ: |
| 93 | case FCOND_UNE: return "eq"; |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 94 | case FCOND_UEQ: |
Akira Hatanaka | a535270 | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 95 | case FCOND_ONE: return "ueq"; |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 96 | case FCOND_OLT: |
| 97 | case FCOND_UGE: return "olt"; |
| 98 | case FCOND_ULT: |
| 99 | case FCOND_OGE: return "ult"; |
| 100 | case FCOND_OLE: |
| 101 | case FCOND_UGT: return "ole"; |
| 102 | case FCOND_ULE: |
| 103 | case FCOND_OGT: return "ule"; |
| 104 | case FCOND_SF: |
| 105 | case FCOND_ST: return "sf"; |
| 106 | case FCOND_NGLE: |
| 107 | case FCOND_GLE: return "ngle"; |
| 108 | case FCOND_SEQ: |
| 109 | case FCOND_SNE: return "seq"; |
| 110 | case FCOND_NGL: |
| 111 | case FCOND_GL: return "ngl"; |
| 112 | case FCOND_LT: |
| 113 | case FCOND_NLT: return "lt"; |
| 114 | case FCOND_NGE: |
Akira Hatanaka | a535270 | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 115 | case FCOND_GE: return "nge"; |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 116 | case FCOND_LE: |
Akira Hatanaka | a535270 | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 117 | case FCOND_NLE: return "le"; |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 118 | case FCOND_NGT: |
Akira Hatanaka | a535270 | 2011-03-31 18:26:17 +0000 | [diff] [blame] | 119 | case FCOND_GT: return "ngt"; |
Bruno Cardoso Lopes | c9c3f49 | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 120 | } |
| 121 | } |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 124 | /// MipsII - This namespace holds all of the target specific flags that |
| 125 | /// instruction info tracks. |
| 126 | /// |
| 127 | namespace MipsII { |
| 128 | /// Target Operand Flag enum. |
| 129 | enum TOF { |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 130 | //===------------------------------------------------------------------===// |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 131 | // Mips Specific MachineOperand flags. |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 132 | |
Dan Gohman | 2728569 | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 133 | MO_NO_FLAG, |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 134 | |
| 135 | /// MO_GOT - Represents the offset into the global offset table at which |
| 136 | /// the address the relocation entry symbol resides during execution. |
Dan Gohman | 2728569 | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 137 | MO_GOT, |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 138 | |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 139 | /// MO_GOT_CALL - Represents the offset into the global offset table at |
| 140 | /// which the address of a call site relocation entry symbol resides |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 141 | /// during execution. This is different from the above since this flag |
| 142 | /// can only be present in call instructions. |
Dan Gohman | 2728569 | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 143 | MO_GOT_CALL, |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 144 | |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 145 | /// MO_GPREL - Represents the offset from the current gp value to be used |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 146 | /// for the relocatable object file being produced. |
Dan Gohman | 2728569 | 2009-10-05 15:52:08 +0000 | [diff] [blame] | 147 | MO_GPREL, |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 148 | |
Akira Hatanaka | 56d9ef5 | 2011-04-01 21:41:06 +0000 | [diff] [blame] | 149 | /// MO_ABS_HI/LO - Represents the hi or low part of an absolute symbol |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 150 | /// address. |
Akira Hatanaka | 56d9ef5 | 2011-04-01 21:41:06 +0000 | [diff] [blame] | 151 | MO_ABS_HI, |
Bruno Cardoso Lopes | bf3c125 | 2011-05-31 02:53:58 +0000 | [diff] [blame] | 152 | MO_ABS_LO, |
| 153 | |
| 154 | /// MO_TLSGD - Represents the offset into the global offset table at which |
| 155 | // the module ID and TSL block offset reside during execution (General |
| 156 | // Dynamic TLS). |
| 157 | MO_TLSGD, |
| 158 | |
| 159 | /// MO_GOTTPREL - Represents the offset from the thread pointer (Initial |
| 160 | // Exec TLS). |
| 161 | MO_GOTTPREL, |
| 162 | |
| 163 | /// MO_TPREL_HI/LO - Represents the hi and low part of the offset from |
| 164 | // the thread pointer (Local Exec TLS). |
| 165 | MO_TPREL_HI, |
| 166 | MO_TPREL_LO |
Bruno Cardoso Lopes | 0f20a5b | 2009-09-01 17:27:58 +0000 | [diff] [blame] | 167 | }; |
| 168 | } |
| 169 | |
Evan Cheng | 703a0fb | 2011-07-01 17:57:27 +0000 | [diff] [blame^] | 170 | class MipsInstrInfo : public MipsGenInstrInfo { |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 171 | MipsTargetMachine &TM; |
| 172 | const MipsRegisterInfo RI; |
| 173 | public: |
Dan Gohman | c60c67f | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 174 | explicit MipsInstrInfo(MipsTargetMachine &TM); |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 175 | |
| 176 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 177 | /// such, whenever a client has an instance of instruction info, it should |
| 178 | /// always be able to get register info as well (through this method). |
| 179 | /// |
Dan Gohman | eabd647 | 2008-05-14 01:58:56 +0000 | [diff] [blame] | 180 | virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; } |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 181 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 182 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 183 | /// load from a stack slot, return the virtual or physical register number of |
| 184 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 185 | /// not, return 0. This predicate must return 0 if the instruction has |
| 186 | /// any side effects other than loading from the stack slot. |
Dan Gohman | 0b27325 | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 187 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 188 | int &FrameIndex) const; |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 189 | |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 190 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 191 | /// store to a stack slot, return the virtual or physical register number of |
| 192 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 193 | /// not, return 0. This predicate must return 0 if the instruction has |
| 194 | /// any side effects other than storing to the stack slot. |
Dan Gohman | 0b27325 | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 195 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 196 | int &FrameIndex) const; |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 197 | |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 198 | /// Branch Analysis |
| 199 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 200 | MachineBasicBlock *&FBB, |
Evan Cheng | 64dfcac | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 201 | SmallVectorImpl<MachineOperand> &Cond, |
| 202 | bool AllowModify) const; |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 203 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
Akira Hatanaka | 93f898f | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 204 | |
| 205 | private: |
| 206 | void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, |
| 207 | const SmallVectorImpl<MachineOperand>& Cond) const; |
| 208 | |
| 209 | public: |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 210 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 211 | MachineBasicBlock *FBB, |
Stuart Hastings | 0125b64 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 212 | const SmallVectorImpl<MachineOperand> &Cond, |
| 213 | DebugLoc DL) const; |
Jakob Stoklund Olesen | 7002c31 | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 214 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 215 | MachineBasicBlock::iterator MI, DebugLoc DL, |
| 216 | unsigned DestReg, unsigned SrcReg, |
| 217 | bool KillSrc) const; |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 218 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 219 | MachineBasicBlock::iterator MBBI, |
Akira Hatanaka | e248912 | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 220 | unsigned SrcReg, bool isKill, int FrameIndex, |
Evan Cheng | efb126a | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 221 | const TargetRegisterClass *RC, |
| 222 | const TargetRegisterInfo *TRI) const; |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 223 | |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 224 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 225 | MachineBasicBlock::iterator MBBI, |
| 226 | unsigned DestReg, int FrameIndex, |
Evan Cheng | efb126a | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 227 | const TargetRegisterClass *RC, |
| 228 | const TargetRegisterInfo *TRI) const; |
Owen Anderson | eee1460 | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 229 | |
Akira Hatanaka | f2bcad9 | 2011-07-01 01:04:43 +0000 | [diff] [blame] | 230 | virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF, |
| 231 | int FrameIx, uint64_t Offset, |
| 232 | const MDNode *MDPtr, |
| 233 | DebugLoc DL) const; |
| 234 | |
Owen Anderson | 4f6bf04 | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 235 | virtual |
| 236 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 237 | |
| 238 | /// Insert nop instruction when hazard condition is found |
Bruno Cardoso Lopes | ed874ef | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 239 | virtual void insertNoop(MachineBasicBlock &MBB, |
Bruno Cardoso Lopes | 0c53063 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 240 | MachineBasicBlock::iterator MI) const; |
Dan Gohman | d5ca7064 | 2009-06-03 20:30:14 +0000 | [diff] [blame] | 241 | |
| 242 | /// getGlobalBaseReg - Return a virtual register initialized with the |
| 243 | /// the global base register value. Output instructions required to |
| 244 | /// initialize the register in the function entry block, if necessary. |
| 245 | /// |
| 246 | unsigned getGlobalBaseReg(MachineFunction *MF) const; |
Bruno Cardoso Lopes | 35e43c4 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 247 | }; |
| 248 | |
| 249 | } |
| 250 | |
| 251 | #endif |