Add definitions of two subclasses of MipsInstrInfo, MipsInstrInfo (for mips16),
[oota-llvm.git] / lib / Target / Mips / MipsInstrInfo.h
1 //===-- MipsInstrInfo.h - Mips Instruction Information ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
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 "MipsAnalyzeImmediate.h"
19 #include "MipsRegisterInfo.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Target/TargetInstrInfo.h"
22
23 #define GET_INSTRINFO_HEADER
24 #include "MipsGenInstrInfo.inc"
25
26 namespace llvm {
27
28 class MipsInstrInfo : public MipsGenInstrInfo {
29 protected:
30   MipsTargetMachine &TM;
31   const MipsRegisterInfo RI;
32   unsigned UncondBrOpc;
33
34 public:
35   explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc);
36
37   /// Branch Analysis
38   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
39                              MachineBasicBlock *&FBB,
40                              SmallVectorImpl<MachineOperand> &Cond,
41                              bool AllowModify) const;
42
43   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
44
45   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
46                                 MachineBasicBlock *FBB,
47                                 const SmallVectorImpl<MachineOperand> &Cond,
48                                 DebugLoc DL) const;
49
50   virtual
51   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
52
53   virtual MachineInstr* emitFrameIndexDebugValue(MachineFunction &MF,
54                                                  int FrameIx, uint64_t Offset,
55                                                  const MDNode *MDPtr,
56                                                  DebugLoc DL) const;
57
58   /// Insert nop instruction when hazard condition is found
59   virtual void insertNoop(MachineBasicBlock &MBB,
60                           MachineBasicBlock::iterator MI) const;
61
62   /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
63   /// such, whenever a client has an instance of instruction info, it should
64   /// always be able to get register info as well (through this method).
65   ///
66   virtual const MipsRegisterInfo &getRegisterInfo() const;
67
68   virtual unsigned GetOppositeBranchOpc(unsigned Opc) const = 0;
69
70   /// Return the number of bytes of code the specified instruction may be.
71   unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
72
73 protected:
74   bool isZeroImm(const MachineOperand &op) const;
75
76   MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
77                                    unsigned Flag) const;
78
79 private:
80   virtual unsigned GetAnalyzableBrOpc(unsigned Opc) const = 0;
81
82   void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
83                      MachineBasicBlock *&BB,
84                      SmallVectorImpl<MachineOperand> &Cond) const;
85
86   void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
87                    const SmallVectorImpl<MachineOperand>& Cond) const;
88 };
89
90 namespace Mips {
91   /// Emit a series of instructions to load an immediate. All instructions
92   /// except for the last one are emitted. The function returns the number of
93   /// MachineInstrs generated. The opcode-immediate pair of the last
94   /// instruction is returned in LastInst, if it is not 0.
95   unsigned
96   loadImmediate(int64_t Imm, bool IsN64, const TargetInstrInfo &TII,
97                 MachineBasicBlock& MBB, MachineBasicBlock::iterator II,
98                 DebugLoc DL, bool LastInstrIsADDiu,
99                 MipsAnalyzeImmediate::Inst *LastInst);
100 }
101
102 }
103
104 #endif