Jia Liu | bb481f8 | 2012-02-28 07:46:26 +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" |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 18 | #include "MipsAnalyzeImmediate.h" |
Craig Topper | 79aa341 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 19 | #include "MipsRegisterInfo.h" |
Torok Edwin | c25e758 | 2009-07-11 20:10:48 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ErrorHandling.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 21 | #include "llvm/Target/TargetInstrInfo.h" |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 22 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 23 | #define GET_INSTRINFO_HEADER |
| 24 | #include "MipsGenInstrInfo.inc" |
| 25 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 26 | namespace llvm { |
| 27 | |
Evan Cheng | 4db3cff | 2011-07-01 17:57:27 +0000 | [diff] [blame] | 28 | class MipsInstrInfo : public MipsGenInstrInfo { |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 29 | protected: |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 30 | MipsTargetMachine &TM; |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 31 | unsigned UncondBrOpc; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 32 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 33 | public: |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 34 | enum BranchType { |
| 35 | BT_None, // Couldn't analyze branch. |
| 36 | BT_NoBranch, // No branches found. |
| 37 | BT_Uncond, // One unconditional branch. |
| 38 | BT_Cond, // One conditional branch. |
| 39 | BT_CondUncond, // A conditional branch followed by an unconditional branch. |
| 40 | BT_Indirect // One indirct branch. |
| 41 | }; |
| 42 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 43 | explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc); |
| 44 | |
Akira Hatanaka | af26626 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 45 | static const MipsInstrInfo *create(MipsTargetMachine &TM); |
| 46 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 47 | /// Branch Analysis |
| 48 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 49 | MachineBasicBlock *&FBB, |
| 50 | SmallVectorImpl<MachineOperand> &Cond, |
| 51 | bool AllowModify) const; |
| 52 | |
| 53 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 54 | |
| 55 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 56 | MachineBasicBlock *FBB, |
| 57 | const SmallVectorImpl<MachineOperand> &Cond, |
| 58 | DebugLoc DL) const; |
| 59 | |
| 60 | virtual |
| 61 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
| 62 | |
Akira Hatanaka | d0a4b60 | 2013-03-01 01:10:17 +0000 | [diff] [blame] | 63 | BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 64 | MachineBasicBlock *&FBB, |
| 65 | SmallVectorImpl<MachineOperand> &Cond, |
| 66 | bool AllowModify, |
| 67 | SmallVectorImpl<MachineInstr*> &BranchInstrs) const; |
| 68 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 69 | virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF, |
| 70 | int FrameIx, uint64_t Offset, |
| 71 | const MDNode *MDPtr, |
| 72 | DebugLoc DL) const; |
| 73 | |
| 74 | /// Insert nop instruction when hazard condition is found |
| 75 | virtual void insertNoop(MachineBasicBlock &MBB, |
| 76 | MachineBasicBlock::iterator MI) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 77 | |
| 78 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 79 | /// such, whenever a client has an instance of instruction info, it should |
| 80 | /// always be able to get register info as well (through this method). |
| 81 | /// |
Akira Hatanaka | 8589010 | 2012-07-31 23:41:32 +0000 | [diff] [blame] | 82 | virtual const MipsRegisterInfo &getRegisterInfo() const = 0; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 83 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 84 | virtual unsigned GetOppositeBranchOpc(unsigned Opc) const = 0; |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 85 | |
| 86 | /// Return the number of bytes of code the specified instruction may be. |
| 87 | unsigned GetInstSizeInBytes(const MachineInstr *MI) const; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 88 | |
Akira Hatanaka | c713e99 | 2013-03-29 02:14:12 +0000 | [diff] [blame] | 89 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 90 | MachineBasicBlock::iterator MBBI, |
| 91 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 92 | const TargetRegisterClass *RC, |
| 93 | const TargetRegisterInfo *TRI) const { |
| 94 | storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0); |
| 95 | } |
| 96 | |
| 97 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 98 | MachineBasicBlock::iterator MBBI, |
| 99 | unsigned DestReg, int FrameIndex, |
| 100 | const TargetRegisterClass *RC, |
| 101 | const TargetRegisterInfo *TRI) const { |
| 102 | loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0); |
| 103 | } |
| 104 | |
| 105 | virtual void storeRegToStack(MachineBasicBlock &MBB, |
| 106 | MachineBasicBlock::iterator MI, |
| 107 | unsigned SrcReg, bool isKill, int FrameIndex, |
| 108 | const TargetRegisterClass *RC, |
| 109 | const TargetRegisterInfo *TRI, |
| 110 | int64_t Offset) const = 0; |
| 111 | |
| 112 | virtual void loadRegFromStack(MachineBasicBlock &MBB, |
| 113 | MachineBasicBlock::iterator MI, |
| 114 | unsigned DestReg, int FrameIndex, |
| 115 | const TargetRegisterClass *RC, |
| 116 | const TargetRegisterInfo *TRI, |
| 117 | int64_t Offset) const = 0; |
| 118 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 119 | protected: |
| 120 | bool isZeroImm(const MachineOperand &op) const; |
| 121 | |
| 122 | MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI, |
| 123 | unsigned Flag) const; |
| 124 | |
| 125 | private: |
| 126 | virtual unsigned GetAnalyzableBrOpc(unsigned Opc) const = 0; |
| 127 | |
| 128 | void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, |
| 129 | MachineBasicBlock *&BB, |
| 130 | SmallVectorImpl<MachineOperand> &Cond) const; |
| 131 | |
| 132 | void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, |
| 133 | const SmallVectorImpl<MachineOperand>& Cond) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
Akira Hatanaka | af26626 | 2012-08-02 18:21:47 +0000 | [diff] [blame] | 136 | /// Create MipsInstrInfo objects. |
| 137 | const MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM); |
| 138 | const MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM); |
| 139 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | #endif |