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 | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 34 | explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc); |
| 35 | |
| 36 | /// Branch Analysis |
| 37 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 38 | MachineBasicBlock *&FBB, |
| 39 | SmallVectorImpl<MachineOperand> &Cond, |
| 40 | bool AllowModify) const; |
| 41 | |
| 42 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
| 43 | |
| 44 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
| 45 | MachineBasicBlock *FBB, |
| 46 | const SmallVectorImpl<MachineOperand> &Cond, |
| 47 | DebugLoc DL) const; |
| 48 | |
| 49 | virtual |
| 50 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
| 51 | |
| 52 | virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF, |
| 53 | int FrameIx, uint64_t Offset, |
| 54 | const MDNode *MDPtr, |
| 55 | DebugLoc DL) const; |
| 56 | |
| 57 | /// Insert nop instruction when hazard condition is found |
| 58 | virtual void insertNoop(MachineBasicBlock &MBB, |
| 59 | MachineBasicBlock::iterator MI) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 60 | |
| 61 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 62 | /// such, whenever a client has an instance of instruction info, it should |
| 63 | /// always be able to get register info as well (through this method). |
| 64 | /// |
Akira Hatanaka | 8589010 | 2012-07-31 23:41:32 +0000 | [diff] [blame^] | 65 | virtual const MipsRegisterInfo &getRegisterInfo() const = 0; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 66 | |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 67 | virtual unsigned GetOppositeBranchOpc(unsigned Opc) const = 0; |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 68 | |
| 69 | /// Return the number of bytes of code the specified instruction may be. |
| 70 | unsigned GetInstSizeInBytes(const MachineInstr *MI) const; |
Akira Hatanaka | 0bc1adb | 2012-07-31 21:49:49 +0000 | [diff] [blame] | 71 | |
| 72 | protected: |
| 73 | bool isZeroImm(const MachineOperand &op) const; |
| 74 | |
| 75 | MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI, |
| 76 | unsigned Flag) const; |
| 77 | |
| 78 | private: |
| 79 | virtual unsigned GetAnalyzableBrOpc(unsigned Opc) const = 0; |
| 80 | |
| 81 | void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, |
| 82 | MachineBasicBlock *&BB, |
| 83 | SmallVectorImpl<MachineOperand> &Cond) const; |
| 84 | |
| 85 | void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, |
| 86 | const SmallVectorImpl<MachineOperand>& Cond) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 89 | namespace Mips { |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 90 | /// Emit a series of instructions to load an immediate. All instructions |
| 91 | /// except for the last one are emitted. The function returns the number of |
| 92 | /// MachineInstrs generated. The opcode-immediate pair of the last |
| 93 | /// instruction is returned in LastInst, if it is not 0. |
| 94 | unsigned |
| 95 | loadImmediate(int64_t Imm, bool IsN64, const TargetInstrInfo &TII, |
| 96 | MachineBasicBlock& MBB, MachineBasicBlock::iterator II, |
| 97 | DebugLoc DL, bool LastInstrIsADDiu, |
| 98 | MipsAnalyzeImmediate::Inst *LastInst); |
| 99 | } |
| 100 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | #endif |