1 //===-- MipsInstrInfo.h - Mips Instruction Information ----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the Mips implementation of the TargetInstrInfo class.
12 //===----------------------------------------------------------------------===//
14 #ifndef MIPSINSTRUCTIONINFO_H
15 #define MIPSINSTRUCTIONINFO_H
18 #include "MipsAnalyzeImmediate.h"
19 #include "MipsRegisterInfo.h"
20 #include "llvm/CodeGen/MachineInstrBuilder.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Target/TargetInstrInfo.h"
24 #define GET_INSTRINFO_HEADER
25 #include "MipsGenInstrInfo.inc"
29 class MipsInstrInfo : public MipsGenInstrInfo {
30 virtual void anchor();
32 MipsTargetMachine &TM;
37 BT_None, // Couldn't analyze branch.
38 BT_NoBranch, // No branches found.
39 BT_Uncond, // One unconditional branch.
40 BT_Cond, // One conditional branch.
41 BT_CondUncond, // A conditional branch followed by an unconditional branch.
42 BT_Indirect // One indirct branch.
45 explicit MipsInstrInfo(MipsTargetMachine &TM, unsigned UncondBrOpc);
47 static const MipsInstrInfo *create(MipsTargetMachine &TM);
50 virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
51 MachineBasicBlock *&FBB,
52 SmallVectorImpl<MachineOperand> &Cond,
53 bool AllowModify) const;
55 virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
57 virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
58 MachineBasicBlock *FBB,
59 const SmallVectorImpl<MachineOperand> &Cond,
63 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
65 BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
66 MachineBasicBlock *&FBB,
67 SmallVectorImpl<MachineOperand> &Cond,
69 SmallVectorImpl<MachineInstr*> &BranchInstrs) const;
71 /// Insert nop instruction when hazard condition is found
72 virtual void insertNoop(MachineBasicBlock &MBB,
73 MachineBasicBlock::iterator MI) const;
75 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As
76 /// such, whenever a client has an instance of instruction info, it should
77 /// always be able to get register info as well (through this method).
79 virtual const MipsRegisterInfo &getRegisterInfo() const = 0;
81 virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0;
83 /// Return the number of bytes of code the specified instruction may be.
84 unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
86 virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
87 MachineBasicBlock::iterator MBBI,
88 unsigned SrcReg, bool isKill, int FrameIndex,
89 const TargetRegisterClass *RC,
90 const TargetRegisterInfo *TRI) const {
91 storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0);
94 virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
95 MachineBasicBlock::iterator MBBI,
96 unsigned DestReg, int FrameIndex,
97 const TargetRegisterClass *RC,
98 const TargetRegisterInfo *TRI) const {
99 loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0);
102 virtual void storeRegToStack(MachineBasicBlock &MBB,
103 MachineBasicBlock::iterator MI,
104 unsigned SrcReg, bool isKill, int FrameIndex,
105 const TargetRegisterClass *RC,
106 const TargetRegisterInfo *TRI,
107 int64_t Offset) const = 0;
109 virtual void loadRegFromStack(MachineBasicBlock &MBB,
110 MachineBasicBlock::iterator MI,
111 unsigned DestReg, int FrameIndex,
112 const TargetRegisterClass *RC,
113 const TargetRegisterInfo *TRI,
114 int64_t Offset) const = 0;
116 /// Create an instruction which has the same operands and memory operands
117 /// as MI but has a new opcode.
118 MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc,
119 MachineBasicBlock::iterator I) const;
122 bool isZeroImm(const MachineOperand &op) const;
124 MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI,
125 unsigned Flag) const;
128 virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0;
130 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc,
131 MachineBasicBlock *&BB,
132 SmallVectorImpl<MachineOperand> &Cond) const;
134 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL,
135 const SmallVectorImpl<MachineOperand>& Cond) const;
138 /// Create MipsInstrInfo objects.
139 const MipsInstrInfo *createMips16InstrInfo(MipsTargetMachine &TM);
140 const MipsInstrInfo *createMipsSEInstrInfo(MipsTargetMachine &TM);