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 { |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 29 | MipsTargetMachine &TM; |
Akira Hatanaka | 3ee306c | 2012-07-23 23:45:54 +0000 | [diff] [blame] | 30 | bool IsN64; bool InMips16Mode; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 31 | const MipsRegisterInfo RI; |
Akira Hatanaka | 6e55ff5 | 2011-12-12 22:39:35 +0000 | [diff] [blame] | 32 | unsigned UncondBrOpc; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 33 | public: |
Dan Gohman | 950a4c4 | 2008-03-25 22:06:05 +0000 | [diff] [blame] | 34 | explicit MipsInstrInfo(MipsTargetMachine &TM); |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 35 | |
| 36 | /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As |
| 37 | /// such, whenever a client has an instance of instruction info, it should |
| 38 | /// always be able to get register info as well (through this method). |
| 39 | /// |
Akira Hatanaka | 794bf17 | 2011-07-07 23:56:50 +0000 | [diff] [blame] | 40 | virtual const MipsRegisterInfo &getRegisterInfo() const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 41 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 42 | /// isLoadFromStackSlot - If the specified machine instruction is a direct |
| 43 | /// load from a stack slot, return the virtual or physical register number of |
| 44 | /// the destination along with the FrameIndex of the loaded stack slot. If |
| 45 | /// not, return 0. This predicate must return 0 if the instruction has |
| 46 | /// any side effects other than loading from the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 47 | virtual unsigned isLoadFromStackSlot(const MachineInstr *MI, |
| 48 | int &FrameIndex) const; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 49 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 50 | /// isStoreToStackSlot - If the specified machine instruction is a direct |
| 51 | /// store to a stack slot, return the virtual or physical register number of |
| 52 | /// the source reg along with the FrameIndex of the loaded stack slot. If |
| 53 | /// not, return 0. This predicate must return 0 if the instruction has |
| 54 | /// any side effects other than storing to the stack slot. |
Dan Gohman | cbad42c | 2008-11-18 19:49:32 +0000 | [diff] [blame] | 55 | virtual unsigned isStoreToStackSlot(const MachineInstr *MI, |
| 56 | int &FrameIndex) const; |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 57 | |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 58 | /// Branch Analysis |
| 59 | virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, |
| 60 | MachineBasicBlock *&FBB, |
Evan Cheng | dc54d31 | 2009-02-09 07:14:22 +0000 | [diff] [blame] | 61 | SmallVectorImpl<MachineOperand> &Cond, |
| 62 | bool AllowModify) const; |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 63 | virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const; |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 64 | |
| 65 | private: |
Akira Hatanaka | 182ef6f | 2012-07-10 00:19:06 +0000 | [diff] [blame] | 66 | void ExpandRetRA(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 67 | unsigned Opc) const; |
Akira Hatanaka | 3ee306c | 2012-07-23 23:45:54 +0000 | [diff] [blame] | 68 | void ExpandRetRA16(MachineBasicBlock &MBB, MachineBasicBlock::iterator I, |
| 69 | unsigned Opc) const; |
| 70 | |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 71 | void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, |
| 72 | const SmallVectorImpl<MachineOperand>& Cond) const; |
Akira Hatanaka | 564f690 | 2012-05-25 20:52:52 +0000 | [diff] [blame] | 73 | void ExpandExtractElementF64(MachineBasicBlock &MBB, |
| 74 | MachineBasicBlock::iterator I) const; |
| 75 | void ExpandBuildPairF64(MachineBasicBlock &MBB, |
| 76 | MachineBasicBlock::iterator I) const; |
Akira Hatanaka | 20ada98 | 2011-04-01 17:39:08 +0000 | [diff] [blame] | 77 | |
| 78 | public: |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 79 | virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 80 | MachineBasicBlock *FBB, |
Stuart Hastings | 3bf9125 | 2010-06-17 22:43:56 +0000 | [diff] [blame] | 81 | const SmallVectorImpl<MachineOperand> &Cond, |
| 82 | DebugLoc DL) const; |
Jakob Stoklund Olesen | 273c14f | 2010-07-11 01:08:31 +0000 | [diff] [blame] | 83 | virtual void copyPhysReg(MachineBasicBlock &MBB, |
| 84 | MachineBasicBlock::iterator MI, DebugLoc DL, |
| 85 | unsigned DestReg, unsigned SrcReg, |
| 86 | bool KillSrc) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 87 | virtual void storeRegToStackSlot(MachineBasicBlock &MBB, |
| 88 | MachineBasicBlock::iterator MBBI, |
Akira Hatanaka | 4552c9a | 2011-04-15 21:51:11 +0000 | [diff] [blame] | 89 | unsigned SrcReg, bool isKill, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 90 | const TargetRegisterClass *RC, |
| 91 | const TargetRegisterInfo *TRI) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 92 | |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 93 | virtual void loadRegFromStackSlot(MachineBasicBlock &MBB, |
| 94 | MachineBasicBlock::iterator MBBI, |
| 95 | unsigned DestReg, int FrameIndex, |
Evan Cheng | 746ad69 | 2010-05-06 19:06:44 +0000 | [diff] [blame] | 96 | const TargetRegisterClass *RC, |
| 97 | const TargetRegisterInfo *TRI) const; |
Owen Anderson | f6372aa | 2008-01-01 21:11:32 +0000 | [diff] [blame] | 98 | |
Akira Hatanaka | 564f690 | 2012-05-25 20:52:52 +0000 | [diff] [blame] | 99 | virtual bool expandPostRAPseudo(MachineBasicBlock::iterator MI) const; |
| 100 | |
Akira Hatanaka | c4f24eb | 2011-07-01 01:04:43 +0000 | [diff] [blame] | 101 | virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF, |
| 102 | int FrameIx, uint64_t Offset, |
| 103 | const MDNode *MDPtr, |
| 104 | DebugLoc DL) const; |
| 105 | |
Owen Anderson | 44eb65c | 2008-08-14 22:49:33 +0000 | [diff] [blame] | 106 | virtual |
| 107 | bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const; |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 108 | |
| 109 | /// Insert nop instruction when hazard condition is found |
Bruno Cardoso Lopes | 81092dc | 2011-03-04 17:51:39 +0000 | [diff] [blame] | 110 | virtual void insertNoop(MachineBasicBlock &MBB, |
Bruno Cardoso Lopes | 0b2cd89 | 2007-08-18 01:59:45 +0000 | [diff] [blame] | 111 | MachineBasicBlock::iterator MI) const; |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 112 | |
| 113 | /// Return the number of bytes of code the specified instruction may be. |
| 114 | unsigned GetInstSizeInBytes(const MachineInstr *MI) const; |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 115 | }; |
| 116 | |
Akira Hatanaka | d4b48b2 | 2012-06-14 01:16:45 +0000 | [diff] [blame] | 117 | namespace Mips { |
| 118 | /// GetOppositeBranchOpc - Return the inverse of the specified |
| 119 | /// opcode, e.g. turning BEQ to BNE. |
| 120 | unsigned GetOppositeBranchOpc(unsigned Opc); |
| 121 | |
| 122 | /// Emit a series of instructions to load an immediate. All instructions |
| 123 | /// except for the last one are emitted. The function returns the number of |
| 124 | /// MachineInstrs generated. The opcode-immediate pair of the last |
| 125 | /// instruction is returned in LastInst, if it is not 0. |
| 126 | unsigned |
| 127 | loadImmediate(int64_t Imm, bool IsN64, const TargetInstrInfo &TII, |
| 128 | MachineBasicBlock& MBB, MachineBasicBlock::iterator II, |
| 129 | DebugLoc DL, bool LastInstrIsADDiu, |
| 130 | MipsAnalyzeImmediate::Inst *LastInst); |
| 131 | } |
| 132 | |
Bruno Cardoso Lopes | 972f589 | 2007-06-06 07:42:06 +0000 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | #endif |