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