LLVM API Documentation

PPCInstrInfo.h
Go to the documentation of this file.
00001 //===-- PPCInstrInfo.h - PowerPC 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 PowerPC implementation of the TargetInstrInfo class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef LLVM_LIB_TARGET_POWERPC_PPCINSTRINFO_H
00015 #define LLVM_LIB_TARGET_POWERPC_PPCINSTRINFO_H
00016 
00017 #include "PPC.h"
00018 #include "PPCRegisterInfo.h"
00019 #include "llvm/Target/TargetInstrInfo.h"
00020 
00021 #define GET_INSTRINFO_HEADER
00022 #include "PPCGenInstrInfo.inc"
00023 
00024 namespace llvm {
00025 
00026 /// PPCII - This namespace holds all of the PowerPC target-specific
00027 /// per-instruction flags.  These must match the corresponding definitions in
00028 /// PPC.td and PPCInstrFormats.td.
00029 namespace PPCII {
00030 enum {
00031   // PPC970 Instruction Flags.  These flags describe the characteristics of the
00032   // PowerPC 970 (aka G5) dispatch groups and how they are formed out of
00033   // raw machine instructions.
00034 
00035   /// PPC970_First - This instruction starts a new dispatch group, so it will
00036   /// always be the first one in the group.
00037   PPC970_First = 0x1,
00038 
00039   /// PPC970_Single - This instruction starts a new dispatch group and
00040   /// terminates it, so it will be the sole instruction in the group.
00041   PPC970_Single = 0x2,
00042 
00043   /// PPC970_Cracked - This instruction is cracked into two pieces, requiring
00044   /// two dispatch pipes to be available to issue.
00045   PPC970_Cracked = 0x4,
00046 
00047   /// PPC970_Mask/Shift - This is a bitmask that selects the pipeline type that
00048   /// an instruction is issued to.
00049   PPC970_Shift = 3,
00050   PPC970_Mask = 0x07 << PPC970_Shift
00051 };
00052 enum PPC970_Unit {
00053   /// These are the various PPC970 execution unit pipelines.  Each instruction
00054   /// is one of these.
00055   PPC970_Pseudo = 0 << PPC970_Shift,   // Pseudo instruction
00056   PPC970_FXU    = 1 << PPC970_Shift,   // Fixed Point (aka Integer/ALU) Unit
00057   PPC970_LSU    = 2 << PPC970_Shift,   // Load Store Unit
00058   PPC970_FPU    = 3 << PPC970_Shift,   // Floating Point Unit
00059   PPC970_CRU    = 4 << PPC970_Shift,   // Control Register Unit
00060   PPC970_VALU   = 5 << PPC970_Shift,   // Vector ALU
00061   PPC970_VPERM  = 6 << PPC970_Shift,   // Vector Permute Unit
00062   PPC970_BRU    = 7 << PPC970_Shift    // Branch Unit
00063 };
00064 } // end namespace PPCII
00065 
00066 
00067 class PPCInstrInfo : public PPCGenInstrInfo {
00068   PPCSubtarget &Subtarget;
00069   const PPCRegisterInfo RI;
00070 
00071   bool StoreRegToStackSlot(MachineFunction &MF,
00072                            unsigned SrcReg, bool isKill, int FrameIdx,
00073                            const TargetRegisterClass *RC,
00074                            SmallVectorImpl<MachineInstr*> &NewMIs,
00075                            bool &NonRI, bool &SpillsVRS) const;
00076   bool LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL,
00077                             unsigned DestReg, int FrameIdx,
00078                             const TargetRegisterClass *RC,
00079                             SmallVectorImpl<MachineInstr*> &NewMIs,
00080                             bool &NonRI, bool &SpillsVRS) const;
00081   virtual void anchor();
00082 public:
00083   explicit PPCInstrInfo(PPCSubtarget &STI);
00084 
00085   /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
00086   /// such, whenever a client has an instance of instruction info, it should
00087   /// always be able to get register info as well (through this method).
00088   ///
00089   const PPCRegisterInfo &getRegisterInfo() const { return RI; }
00090 
00091   ScheduleHazardRecognizer *
00092   CreateTargetHazardRecognizer(const TargetSubtargetInfo *STI,
00093                                const ScheduleDAG *DAG) const override;
00094   ScheduleHazardRecognizer *
00095   CreateTargetPostRAHazardRecognizer(const InstrItineraryData *II,
00096                                      const ScheduleDAG *DAG) const override;
00097 
00098   int getOperandLatency(const InstrItineraryData *ItinData,
00099                         const MachineInstr *DefMI, unsigned DefIdx,
00100                         const MachineInstr *UseMI,
00101                         unsigned UseIdx) const override;
00102   int getOperandLatency(const InstrItineraryData *ItinData,
00103                         SDNode *DefNode, unsigned DefIdx,
00104                         SDNode *UseNode, unsigned UseIdx) const override {
00105     return PPCGenInstrInfo::getOperandLatency(ItinData, DefNode, DefIdx,
00106                                               UseNode, UseIdx);
00107   }
00108 
00109   bool isCoalescableExtInstr(const MachineInstr &MI,
00110                              unsigned &SrcReg, unsigned &DstReg,
00111                              unsigned &SubIdx) const override;
00112   unsigned isLoadFromStackSlot(const MachineInstr *MI,
00113                                int &FrameIndex) const override;
00114   unsigned isStoreToStackSlot(const MachineInstr *MI,
00115                               int &FrameIndex) const override;
00116 
00117   // commuteInstruction - We can commute rlwimi instructions, but only if the
00118   // rotate amt is zero.  We also have to munge the immediates a bit.
00119   MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const override;
00120 
00121   bool findCommutedOpIndices(MachineInstr *MI, unsigned &SrcOpIdx1,
00122                              unsigned &SrcOpIdx2) const override;
00123 
00124   void insertNoop(MachineBasicBlock &MBB,
00125                   MachineBasicBlock::iterator MI) const override;
00126 
00127 
00128   // Branch analysis.
00129   bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
00130                      MachineBasicBlock *&FBB,
00131                      SmallVectorImpl<MachineOperand> &Cond,
00132                      bool AllowModify) const override;
00133   unsigned RemoveBranch(MachineBasicBlock &MBB) const override;
00134   unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
00135                         MachineBasicBlock *FBB,
00136                         const SmallVectorImpl<MachineOperand> &Cond,
00137                         DebugLoc DL) const override;
00138 
00139   // Select analysis.
00140   bool canInsertSelect(const MachineBasicBlock&,
00141                        const SmallVectorImpl<MachineOperand> &Cond,
00142                        unsigned, unsigned, int&, int&, int&) const override;
00143   void insertSelect(MachineBasicBlock &MBB,
00144                     MachineBasicBlock::iterator MI, DebugLoc DL,
00145                     unsigned DstReg,
00146                     const SmallVectorImpl<MachineOperand> &Cond,
00147                     unsigned TrueReg, unsigned FalseReg) const override;
00148 
00149   void copyPhysReg(MachineBasicBlock &MBB,
00150                    MachineBasicBlock::iterator I, DebugLoc DL,
00151                    unsigned DestReg, unsigned SrcReg,
00152                    bool KillSrc) const override;
00153 
00154   void storeRegToStackSlot(MachineBasicBlock &MBB,
00155                            MachineBasicBlock::iterator MBBI,
00156                            unsigned SrcReg, bool isKill, int FrameIndex,
00157                            const TargetRegisterClass *RC,
00158                            const TargetRegisterInfo *TRI) const override;
00159 
00160   void loadRegFromStackSlot(MachineBasicBlock &MBB,
00161                             MachineBasicBlock::iterator MBBI,
00162                             unsigned DestReg, int FrameIndex,
00163                             const TargetRegisterClass *RC,
00164                             const TargetRegisterInfo *TRI) const override;
00165 
00166   bool
00167   ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const override;
00168 
00169   bool FoldImmediate(MachineInstr *UseMI, MachineInstr *DefMI,
00170                      unsigned Reg, MachineRegisterInfo *MRI) const override;
00171 
00172   // If conversion by predication (only supported by some branch instructions).
00173   // All of the profitability checks always return true; it is always
00174   // profitable to use the predicated branches.
00175   bool isProfitableToIfCvt(MachineBasicBlock &MBB,
00176                           unsigned NumCycles, unsigned ExtraPredCycles,
00177                           const BranchProbability &Probability) const override {
00178     return true;
00179   }
00180 
00181   bool isProfitableToIfCvt(MachineBasicBlock &TMBB,
00182                            unsigned NumT, unsigned ExtraT,
00183                            MachineBasicBlock &FMBB,
00184                            unsigned NumF, unsigned ExtraF,
00185                            const BranchProbability &Probability) const override;
00186 
00187   bool isProfitableToDupForIfCvt(MachineBasicBlock &MBB,
00188                                  unsigned NumCycles,
00189                                  const BranchProbability
00190                                  &Probability) const override {
00191     return true;
00192   }
00193 
00194   bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
00195                                  MachineBasicBlock &FMBB) const override {
00196     return false;
00197   }
00198 
00199   // Predication support.
00200   bool isPredicated(const MachineInstr *MI) const override;
00201 
00202   bool isUnpredicatedTerminator(const MachineInstr *MI) const override;
00203 
00204   bool PredicateInstruction(MachineInstr *MI,
00205                     const SmallVectorImpl<MachineOperand> &Pred) const override;
00206 
00207   bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
00208                    const SmallVectorImpl<MachineOperand> &Pred2) const override;
00209 
00210   bool DefinesPredicate(MachineInstr *MI,
00211                         std::vector<MachineOperand> &Pred) const override;
00212 
00213   bool isPredicable(MachineInstr *MI) const override;
00214 
00215   // Comparison optimization.
00216 
00217 
00218   bool analyzeCompare(const MachineInstr *MI,
00219                       unsigned &SrcReg, unsigned &SrcReg2,
00220                       int &Mask, int &Value) const override;
00221 
00222   bool optimizeCompareInstr(MachineInstr *CmpInstr,
00223                             unsigned SrcReg, unsigned SrcReg2,
00224                             int Mask, int Value,
00225                             const MachineRegisterInfo *MRI) const override;
00226 
00227   /// GetInstSize - Return the number of bytes of code the specified
00228   /// instruction may be.  This returns the maximum number of bytes.
00229   ///
00230   unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
00231 
00232   void getNoopForMachoTarget(MCInst &NopInst) const override;
00233 };
00234 
00235 }
00236 
00237 #endif