LLVM API Documentation

MipsInstrInfo.h

Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef MIPSINSTRUCTIONINFO_H
00015 #define MIPSINSTRUCTIONINFO_H
00016 
00017 #include "Mips.h"
00018 #include "llvm/Target/TargetInstrInfo.h"
00019 #include "MipsRegisterInfo.h"
00020 
00021 namespace llvm {
00022 
00023 namespace Mips {
00024 
00025   // Mips Branch Codes
00026   enum FPBranchCode {
00027     BRANCH_F,
00028     BRANCH_T,
00029     BRANCH_FL,
00030     BRANCH_TL,
00031     BRANCH_INVALID
00032   };
00033 
00034   // Mips Condition Codes
00035   enum CondCode {
00036     // To be used with float branch True
00037     FCOND_F,
00038     FCOND_UN,
00039     FCOND_EQ,
00040     FCOND_UEQ,
00041     FCOND_OLT,
00042     FCOND_ULT,
00043     FCOND_OLE,
00044     FCOND_ULE,
00045     FCOND_SF,
00046     FCOND_NGLE,
00047     FCOND_SEQ,
00048     FCOND_NGL,
00049     FCOND_LT,
00050     FCOND_NGE,
00051     FCOND_LE,
00052     FCOND_NGT,
00053 
00054     // To be used with float branch False
00055     // This conditions have the same mnemonic as the
00056     // above ones, but are used with a branch False;
00057     FCOND_T,
00058     FCOND_OR,
00059     FCOND_NEQ,
00060     FCOND_OGL,
00061     FCOND_UGE,
00062     FCOND_OGE,
00063     FCOND_UGT,
00064     FCOND_OGT,
00065     FCOND_ST,
00066     FCOND_GLE,
00067     FCOND_SNE,
00068     FCOND_GL,
00069     FCOND_NLT,
00070     FCOND_GE,
00071     FCOND_NLE,
00072     FCOND_GT,
00073 
00074     // Only integer conditions
00075     COND_E,
00076     COND_GZ,
00077     COND_GEZ,
00078     COND_LZ,
00079     COND_LEZ,
00080     COND_NE,
00081     COND_INVALID
00082   };
00083   
00084   // Turn condition code into conditional branch opcode.
00085   unsigned GetCondBranchFromCond(CondCode CC);
00086 
00087   /// GetOppositeBranchCondition - Return the inverse of the specified cond,
00088   /// e.g. turning COND_E to COND_NE.
00089   CondCode GetOppositeBranchCondition(Mips::CondCode CC);
00090 
00091   /// MipsCCToString - Map each FP condition code to its string
00092   inline static const char *MipsFCCToString(Mips::CondCode CC) 
00093   {
00094     switch (CC) {
00095       default: assert(0 && "Unknown condition code");
00096       case FCOND_F:
00097       case FCOND_T:   return "f";
00098       case FCOND_UN:
00099       case FCOND_OR:  return "un";
00100       case FCOND_EQ: 
00101       case FCOND_NEQ: return "eq";
00102       case FCOND_UEQ:
00103       case FCOND_OGL: return "ueq";
00104       case FCOND_OLT:
00105       case FCOND_UGE: return "olt";
00106       case FCOND_ULT:
00107       case FCOND_OGE: return "ult";
00108       case FCOND_OLE:
00109       case FCOND_UGT: return "ole";
00110       case FCOND_ULE:
00111       case FCOND_OGT: return "ule";
00112       case FCOND_SF:
00113       case FCOND_ST:  return "sf";
00114       case FCOND_NGLE:
00115       case FCOND_GLE: return "ngle";
00116       case FCOND_SEQ:
00117       case FCOND_SNE: return "seq";
00118       case FCOND_NGL:
00119       case FCOND_GL:  return "ngl";
00120       case FCOND_LT:
00121       case FCOND_NLT: return "lt";
00122       case FCOND_NGE:
00123       case FCOND_GE:  return "ge";
00124       case FCOND_LE:
00125       case FCOND_NLE: return "nle";
00126       case FCOND_NGT:
00127       case FCOND_GT:  return "gt";
00128     }
00129   }
00130 }
00131 
00132 class MipsInstrInfo : public TargetInstrInfoImpl {
00133   MipsTargetMachine &TM;
00134   const MipsRegisterInfo RI;
00135 public:
00136   explicit MipsInstrInfo(MipsTargetMachine &TM);
00137 
00138   /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
00139   /// such, whenever a client has an instance of instruction info, it should
00140   /// always be able to get register info as well (through this method).
00141   ///
00142   virtual const MipsRegisterInfo &getRegisterInfo() const { return RI; }
00143 
00144   /// Return true if the instruction is a register to register move and return
00145   /// the source and dest operands and their sub-register indices by reference.
00146   virtual bool isMoveInstr(const MachineInstr &MI,
00147                            unsigned &SrcReg, unsigned &DstReg,
00148                            unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
00149   
00150   /// isLoadFromStackSlot - If the specified machine instruction is a direct
00151   /// load from a stack slot, return the virtual or physical register number of
00152   /// the destination along with the FrameIndex of the loaded stack slot.  If
00153   /// not, return 0.  This predicate must return 0 if the instruction has
00154   /// any side effects other than loading from the stack slot.
00155   virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
00156                                        int &FrameIndex) const;
00157   
00158   /// isStoreToStackSlot - If the specified machine instruction is a direct
00159   /// store to a stack slot, return the virtual or physical register number of
00160   /// the source reg along with the FrameIndex of the loaded stack slot.  If
00161   /// not, return 0.  This predicate must return 0 if the instruction has
00162   /// any side effects other than storing to the stack slot.
00163   virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
00164                                       int &FrameIndex) const;
00165  
00166   /// Branch Analysis
00167   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
00168                              MachineBasicBlock *&FBB,
00169                              SmallVectorImpl<MachineOperand> &Cond,
00170                              bool AllowModify) const;
00171   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
00172   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
00173                                 MachineBasicBlock *FBB,
00174                             const SmallVectorImpl<MachineOperand> &Cond) const;
00175   virtual bool copyRegToReg(MachineBasicBlock &MBB, 
00176                             MachineBasicBlock::iterator I,
00177                             unsigned DestReg, unsigned SrcReg,
00178                             const TargetRegisterClass *DestRC,
00179                             const TargetRegisterClass *SrcRC) const;
00180   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
00181                                    MachineBasicBlock::iterator MBBI,
00182                                    unsigned SrcReg, bool isKill, int FrameIndex,
00183                                    const TargetRegisterClass *RC) const;
00184 
00185   virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
00186                               SmallVectorImpl<MachineOperand> &Addr,
00187                               const TargetRegisterClass *RC,
00188                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
00189 
00190   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
00191                                     MachineBasicBlock::iterator MBBI,
00192                                     unsigned DestReg, int FrameIndex,
00193                                     const TargetRegisterClass *RC) const;
00194 
00195   virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
00196                                SmallVectorImpl<MachineOperand> &Addr,
00197                                const TargetRegisterClass *RC,
00198                                SmallVectorImpl<MachineInstr*> &NewMIs) const;
00199   
00200   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
00201                                               MachineInstr* MI,
00202                                            const SmallVectorImpl<unsigned> &Ops,
00203                                               int FrameIndex) const;
00204 
00205   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
00206                                               MachineInstr* MI,
00207                                            const SmallVectorImpl<unsigned> &Ops,
00208                                               MachineInstr* LoadMI) const {
00209     return 0;
00210   }
00211   
00212   virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
00213   virtual
00214   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
00215 
00216   /// Insert nop instruction when hazard condition is found
00217   virtual void insertNoop(MachineBasicBlock &MBB, 
00218                           MachineBasicBlock::iterator MI) const;
00219 };
00220 
00221 }
00222 
00223 #endif