LLVM API Documentation
00001 //===-- MipsInstrInfo.h - Mips Instruction Information ----------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the Mips implementation of the TargetInstrInfo class. 00011 // 00012 // FIXME: We need to override TargetInstrInfo::getInlineAsmLength method in 00013 // order for MipsLongBranch pass to work correctly when the code has inline 00014 // assembly. The returned value doesn't have to be the asm instruction's exact 00015 // size in bytes; MipsLongBranch only expects it to be the correct upper bound. 00016 //===----------------------------------------------------------------------===// 00017 00018 #ifndef LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H 00019 #define LLVM_LIB_TARGET_MIPS_MIPSINSTRINFO_H 00020 00021 #include "Mips.h" 00022 #include "MipsAnalyzeImmediate.h" 00023 #include "MipsRegisterInfo.h" 00024 #include "llvm/CodeGen/MachineInstrBuilder.h" 00025 #include "llvm/Support/ErrorHandling.h" 00026 #include "llvm/Target/TargetInstrInfo.h" 00027 00028 #define GET_INSTRINFO_HEADER 00029 #include "MipsGenInstrInfo.inc" 00030 00031 namespace llvm { 00032 00033 class MipsInstrInfo : public MipsGenInstrInfo { 00034 virtual void anchor(); 00035 protected: 00036 const MipsSubtarget &Subtarget; 00037 unsigned UncondBrOpc; 00038 00039 public: 00040 enum BranchType { 00041 BT_None, // Couldn't analyze branch. 00042 BT_NoBranch, // No branches found. 00043 BT_Uncond, // One unconditional branch. 00044 BT_Cond, // One conditional branch. 00045 BT_CondUncond, // A conditional branch followed by an unconditional branch. 00046 BT_Indirect // One indirct branch. 00047 }; 00048 00049 explicit MipsInstrInfo(const MipsSubtarget &STI, unsigned UncondBrOpc); 00050 00051 static const MipsInstrInfo *create(MipsSubtarget &STI); 00052 00053 /// Branch Analysis 00054 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, 00055 MachineBasicBlock *&FBB, 00056 SmallVectorImpl<MachineOperand> &Cond, 00057 bool AllowModify) const override; 00058 00059 unsigned RemoveBranch(MachineBasicBlock &MBB) const override; 00060 00061 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, 00062 MachineBasicBlock *FBB, 00063 const SmallVectorImpl<MachineOperand> &Cond, 00064 DebugLoc DL) const override; 00065 00066 bool 00067 ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override; 00068 00069 BranchType AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, 00070 MachineBasicBlock *&FBB, 00071 SmallVectorImpl<MachineOperand> &Cond, 00072 bool AllowModify, 00073 SmallVectorImpl<MachineInstr*> &BranchInstrs) const; 00074 00075 /// Insert nop instruction when hazard condition is found 00076 void insertNoop(MachineBasicBlock &MBB, 00077 MachineBasicBlock::iterator MI) const override; 00078 00079 /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info. As 00080 /// such, whenever a client has an instance of instruction info, it should 00081 /// always be able to get register info as well (through this method). 00082 /// 00083 virtual const MipsRegisterInfo &getRegisterInfo() const = 0; 00084 00085 virtual unsigned getOppositeBranchOpc(unsigned Opc) const = 0; 00086 00087 /// Return the number of bytes of code the specified instruction may be. 00088 unsigned GetInstSizeInBytes(const MachineInstr *MI) const; 00089 00090 void storeRegToStackSlot(MachineBasicBlock &MBB, 00091 MachineBasicBlock::iterator MBBI, 00092 unsigned SrcReg, bool isKill, int FrameIndex, 00093 const TargetRegisterClass *RC, 00094 const TargetRegisterInfo *TRI) const override { 00095 storeRegToStack(MBB, MBBI, SrcReg, isKill, FrameIndex, RC, TRI, 0); 00096 } 00097 00098 void loadRegFromStackSlot(MachineBasicBlock &MBB, 00099 MachineBasicBlock::iterator MBBI, 00100 unsigned DestReg, int FrameIndex, 00101 const TargetRegisterClass *RC, 00102 const TargetRegisterInfo *TRI) const override { 00103 loadRegFromStack(MBB, MBBI, DestReg, FrameIndex, RC, TRI, 0); 00104 } 00105 00106 virtual void storeRegToStack(MachineBasicBlock &MBB, 00107 MachineBasicBlock::iterator MI, 00108 unsigned SrcReg, bool isKill, int FrameIndex, 00109 const TargetRegisterClass *RC, 00110 const TargetRegisterInfo *TRI, 00111 int64_t Offset) const = 0; 00112 00113 virtual void loadRegFromStack(MachineBasicBlock &MBB, 00114 MachineBasicBlock::iterator MI, 00115 unsigned DestReg, int FrameIndex, 00116 const TargetRegisterClass *RC, 00117 const TargetRegisterInfo *TRI, 00118 int64_t Offset) const = 0; 00119 00120 /// Create an instruction which has the same operands and memory operands 00121 /// as MI but has a new opcode. 00122 MachineInstrBuilder genInstrWithNewOpc(unsigned NewOpc, 00123 MachineBasicBlock::iterator I) const; 00124 00125 protected: 00126 bool isZeroImm(const MachineOperand &op) const; 00127 00128 MachineMemOperand *GetMemOperand(MachineBasicBlock &MBB, int FI, 00129 unsigned Flag) const; 00130 00131 private: 00132 virtual unsigned getAnalyzableBrOpc(unsigned Opc) const = 0; 00133 00134 void AnalyzeCondBr(const MachineInstr *Inst, unsigned Opc, 00135 MachineBasicBlock *&BB, 00136 SmallVectorImpl<MachineOperand> &Cond) const; 00137 00138 void BuildCondBr(MachineBasicBlock &MBB, MachineBasicBlock *TBB, DebugLoc DL, 00139 const SmallVectorImpl<MachineOperand>& Cond) const; 00140 }; 00141 00142 /// Create MipsInstrInfo objects. 00143 const MipsInstrInfo *createMips16InstrInfo(const MipsSubtarget &STI); 00144 const MipsInstrInfo *createMipsSEInstrInfo(const MipsSubtarget &STI); 00145 00146 } 00147 00148 #endif