Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 1 | //===- MipsInstrInfo.h - Mips Instruction Information -----------*- C++ -*-===// |
| 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 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the Mips implementation of the TargetInstrInfo class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef MIPSINSTRUCTIONINFO_H |
| 15 | #define MIPSINSTRUCTIONINFO_H |
| 16 | |
| 17 | #include "Mips.h" |
| 18 | #include "llvm/Target/TargetInstrInfo.h" |
| 19 | #include "MipsRegisterInfo.h" |
| 20 | |
| 21 | namespace llvm { |
| 22 | |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 23 | namespace Mips { |
| 24 | |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 25 | // Mips Branch Codes |
| 26 | enum FPBranchCode { |
| 27 | BRANCH_F, |
| 28 | BRANCH_T, |
| 29 | BRANCH_FL, |
| 30 | BRANCH_TL, |
| 31 | BRANCH_INVALID |
| 32 | }; |
| 33 | |
Bruno Cardoso Lopes | dc0c04c | 2007-08-28 05:06:17 +0000 | [diff] [blame] | 34 | // Mips Condition Codes |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 35 | enum CondCode { |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 36 | // To be used with float branch True |
| 37 | FCOND_F, |
| 38 | FCOND_UN, |
| 39 | FCOND_EQ, |
| 40 | FCOND_UEQ, |
| 41 | FCOND_OLT, |
| 42 | FCOND_ULT, |
| 43 | FCOND_OLE, |
| 44 | FCOND_ULE, |
| 45 | FCOND_SF, |
| 46 | FCOND_NGLE, |
| 47 | FCOND_SEQ, |
| 48 | FCOND_NGL, |
| 49 | FCOND_LT, |
| 50 | FCOND_NGE, |
| 51 | FCOND_LE, |
| 52 | FCOND_NGT, |
| 53 | |
| 54 | // To be used with float branch False |
| 55 | // This conditions have the same mnemonic as the |
| 56 | // above ones, but are used with a branch False; |
| 57 | FCOND_T, |
| 58 | FCOND_OR, |
| 59 | FCOND_NEQ, |
| 60 | FCOND_OGL, |
| 61 | FCOND_UGE, |
| 62 | FCOND_OGE, |
| 63 | FCOND_UGT, |
| 64 | FCOND_OGT, |
| 65 | FCOND_ST, |
| 66 | FCOND_GLE, |
| 67 | FCOND_SNE, |
| 68 | FCOND_GL, |
| 69 | FCOND_NLT, |
| 70 | FCOND_GE, |
| 71 | FCOND_NLE, |
| 72 | FCOND_GT, |
| 73 | |
| 74 | // Only integer conditions |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 75 | COND_E, |
| 76 | COND_GZ, |
| 77 | COND_GEZ, |
| 78 | COND_LZ, |
| 79 | COND_LEZ, |
| 80 | COND_NE, |
| 81 | COND_INVALID |
| 82 | }; |
| 83 | |
| 84 | // Turn condition code into conditional branch opcode. |
| 85 | unsigned GetCondBranchFromCond(CondCode CC); |
Bruno Cardoso Lopes | 85e31e3 | 2008-07-28 19:11:24 +0000 | [diff] [blame] | 86 | |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 87 | /// GetOppositeBranchCondition - Return the inverse of the specified cond, |
| 88 | /// e.g. turning COND_E to COND_NE. |
| 89 | CondCode GetOppositeBranchCondition(Mips::CondCode CC); |
| 90 | |
Bruno Cardoso Lopes | 225ca9c | 2008-07-05 19:05:21 +0000 | [diff] [blame] | 91 | /// MipsCCToString - Map each FP condition code to its string |
| 92 | inline static const char *MipsFCCToString(Mips::CondCode CC) |
| 93 | { |
| 94 | switch (CC) { |
| 95 | default: assert(0 && "Unknown condition code"); |
| 96 | case FCOND_F: |
| 97 | case FCOND_T: return "f"; |
| 98 | case FCOND_UN: |
| 99 | case FCOND_OR: return "un"; |
| 100 | case FCOND_EQ: |
| 101 | case FCOND_NEQ: return "eq"; |
| 102 | case FCOND_UEQ: |
| 103 | case FCOND_OGL: return "ueq"; |
| 104 | case FCOND_OLT: |
| 105 | case FCOND_UGE: return "olt"; |
| 106 | case FCOND_ULT: |
| 107 | case FCOND_OGE: return "ult"; |
| 108 | case FCOND_OLE: |
| 109 | case FCOND_UGT: return "ole"; |
| 110 | case FCOND_ULE: |
| 111 | case FCOND_OGT: return "ule"; |
| 112 | case FCOND_SF: |
| 113 | case FCOND_ST: return "sf"; |
| 114 | case FCOND_NGLE: |
| 115 | case FCOND_GLE: return "ngle"; |
| 116 | case FCOND_SEQ: |
| 117 | case FCOND_SNE: return "seq"; |
| 118 | case FCOND_NGL: |
| 119 | case FCOND_GL: return "ngl"; |
| 120 | case FCOND_LT: |
| 121 | case FCOND_NLT: return "lt"; |
| 122 | case FCOND_NGE: |
| 123 | case FCOND_GE: return "ge"; |
| 124 | case FCOND_LE: |
| 125 | case FCOND_NLE: return "nle"; |
| 126 | case FCOND_NGT: |
| 127 | case FCOND_GT: return "gt"; |
| 128 | } |
| 129 | } |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Chris Lattner | 6410552 | 2008-01-01 01:03:04 +0000 | [diff] [blame] | 132 | class MipsInstrInfo : public TargetInstrInfoImpl { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 133 | MipsTargetMachine &TM; |
| 134 | const MipsRegisterInfo RI; |
| 135 | public: |
Dan Gohman | 950a4c4 | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 136 | explicit MipsInstrInfo(MipsTargetMachine &TM); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 137 | |
| 138 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 139 | /// such, whenever a client has an instance of instruction info, it should |
| 140 | /// always be able to get register info as well (through this method). |
| 141 | /// |
Dan Gohman | c9f5f3f | 2008-05-14 01:58:56 +0000 | [diff] [blame] | 142 | virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; } |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 143 | |
| 144 | /// Return true if the instruction is a register to register move and |
| 145 | /// leave the source and dest operands in the passed parameters. |
| 146 | /// |
| 147 | virtual bool isMoveInstr(const MachineInstr &MI, |
| 148 | unsigned &SrcReg, unsigned &DstReg) const; |
| 149 | |
| 150 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 151 | /// load from a stack slot, return the virtual or physical register number of |
| 152 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 153 | /// not, return 0. This predicate must return 0 if the instruction has |
| 154 | /// any side effects other than loading from the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame^] | 155 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 156 | int &FrameIndex) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 157 | |
| 158 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 159 | /// store to a stack slot, return the virtual or physical register number of |
| 160 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 161 | /// not, return 0. This predicate must return 0 if the instruction has |
| 162 | /// any side effects other than storing to the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame^] | 163 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 164 | int &FrameIndex) const; |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 165 | |
| 166 | /// Branch Analysis |
| 167 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 168 | MachineBasicBlock *&FBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 169 | SmallVectorImpl<MachineOperand> &Cond) const; |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 170 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 171 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 172 | MachineBasicBlock *FBB, |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 173 | const SmallVectorImpl<MachineOperand> &Cond) const; |
Owen Anderson | 940f83e | 2008-08-26 18:03:31 +0000 | [diff] [blame] | 174 | virtual bool copyRegToReg(MachineBasicBlock &MBB, |
Bruno Cardoso Lopes | 7b76da1 | 2008-07-09 04:45:36 +0000 | [diff] [blame] | 175 | MachineBasicBlock::iterator I, |
Owen Anderson | d10fd97 | 2007-12-31 06:32:00 +0000 | [diff] [blame] | 176 | unsigned DestReg, unsigned SrcReg, |
| 177 | const TargetRegisterClass *DestRC, |
| 178 | const TargetRegisterClass *SrcRC) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 179 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 180 | MachineBasicBlock::iterator MBBI, |
| 181 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 182 | const TargetRegisterClass *RC) const; |
| 183 | |
| 184 | virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill, |
| 185 | SmallVectorImpl<MachineOperand> &Addr, |
| 186 | const TargetRegisterClass *RC, |
| 187 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
| 188 | |
| 189 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 190 | MachineBasicBlock::iterator MBBI, |
| 191 | unsigned DestReg, int FrameIndex, |
| 192 | const TargetRegisterClass *RC) const; |
| 193 | |
| 194 | virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg, |
| 195 | SmallVectorImpl<MachineOperand> &Addr, |
| 196 | const TargetRegisterClass *RC, |
| 197 | SmallVectorImpl<MachineInstr*> &NewMIs) const; |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 198 | |
Evan Cheng | 5fd79d0 | 2008-02-08 21:20:40 +0000 | [diff] [blame] | 199 | virtual MachineInstr* foldMemoryOperand(MachineFunction &MF, |
| 200 | MachineInstr* MI, |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame] | 201 | const SmallVectorImpl<unsigned> &Ops, |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 202 | int FrameIndex) const; |
| 203 | |
Evan Cheng | 5fd79d0 | 2008-02-08 21:20:40 +0000 | [diff] [blame] | 204 | virtual MachineInstr* foldMemoryOperand(MachineFunction &MF, |
| 205 | MachineInstr* MI, |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame] | 206 | const SmallVectorImpl<unsigned> &Ops, |
Owen Anderson | 43dbe05 | 2008-01-07 01:35:02 +0000 | [diff] [blame] | 207 | MachineInstr* LoadMI) const { |
| 208 | return 0; |
| 209 | } |
| 210 | |
Dan Gohman | 8e8b8a2 | 2008-10-16 01:49:15 +0000 | [diff] [blame] | 211 | virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const; |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 212 | virtual |
| 213 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 214 | |
| 215 | /// Insert nop instruction when hazard condition is found |
| 216 | virtual void insertNoop(MachineBasicBlock &MBB, |
| 217 | MachineBasicBlock::iterator MI) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | } |
| 221 | |
| 222 | #endif |