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 POWERPC32_INSTRUCTIONINFO_H
00015 #define POWERPC32_INSTRUCTIONINFO_H
00016 
00017 #include "PPC.h"
00018 #include "llvm/Target/TargetInstrInfo.h"
00019 #include "PPCRegisterInfo.h"
00020 
00021 namespace llvm {
00022 
00023 /// PPCII - This namespace holds all of the PowerPC target-specific
00024 /// per-instruction flags.  These must match the corresponding definitions in
00025 /// PPC.td and PPCInstrFormats.td.
00026 namespace PPCII {
00027 enum {
00028   // PPC970 Instruction Flags.  These flags describe the characteristics of the
00029   // PowerPC 970 (aka G5) dispatch groups and how they are formed out of
00030   // raw machine instructions.
00031 
00032   /// PPC970_First - This instruction starts a new dispatch group, so it will
00033   /// always be the first one in the group.
00034   PPC970_First = 0x1,
00035   
00036   /// PPC970_Single - This instruction starts a new dispatch group and
00037   /// terminates it, so it will be the sole instruction in the group.
00038   PPC970_Single = 0x2,
00039 
00040   /// PPC970_Cracked - This instruction is cracked into two pieces, requiring
00041   /// two dispatch pipes to be available to issue.
00042   PPC970_Cracked = 0x4,
00043   
00044   /// PPC970_Mask/Shift - This is a bitmask that selects the pipeline type that
00045   /// an instruction is issued to.
00046   PPC970_Shift = 3,
00047   PPC970_Mask = 0x07 << PPC970_Shift
00048 };
00049 enum PPC970_Unit {
00050   /// These are the various PPC970 execution unit pipelines.  Each instruction
00051   /// is one of these.
00052   PPC970_Pseudo = 0 << PPC970_Shift,   // Pseudo instruction
00053   PPC970_FXU    = 1 << PPC970_Shift,   // Fixed Point (aka Integer/ALU) Unit
00054   PPC970_LSU    = 2 << PPC970_Shift,   // Load Store Unit
00055   PPC970_FPU    = 3 << PPC970_Shift,   // Floating Point Unit
00056   PPC970_CRU    = 4 << PPC970_Shift,   // Control Register Unit
00057   PPC970_VALU   = 5 << PPC970_Shift,   // Vector ALU
00058   PPC970_VPERM  = 6 << PPC970_Shift,   // Vector Permute Unit
00059   PPC970_BRU    = 7 << PPC970_Shift    // Branch Unit
00060 };
00061 }
00062   
00063   
00064 class PPCInstrInfo : public TargetInstrInfoImpl {
00065   PPCTargetMachine &TM;
00066   const PPCRegisterInfo RI;
00067 
00068   bool StoreRegToStackSlot(MachineFunction &MF,
00069                            unsigned SrcReg, bool isKill, int FrameIdx,
00070                            const TargetRegisterClass *RC,
00071                            SmallVectorImpl<MachineInstr*> &NewMIs) const;
00072   void LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL, 
00073                             unsigned DestReg, int FrameIdx,
00074                             const TargetRegisterClass *RC,
00075                             SmallVectorImpl<MachineInstr*> &NewMIs) const;
00076 public:
00077   explicit PPCInstrInfo(PPCTargetMachine &TM);
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 PPCRegisterInfo &getRegisterInfo() const { return RI; }
00084 
00085   /// Return true if the instruction is a register to register move and return
00086   /// the source and dest operands and their sub-register indices by reference.
00087   virtual bool isMoveInstr(const MachineInstr &MI,
00088                            unsigned &SrcReg, unsigned &DstReg,
00089                            unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
00090 
00091   unsigned isLoadFromStackSlot(const MachineInstr *MI,
00092                                int &FrameIndex) const;
00093   unsigned isStoreToStackSlot(const MachineInstr *MI,
00094                               int &FrameIndex) const;
00095 
00096   // commuteInstruction - We can commute rlwimi instructions, but only if the
00097   // rotate amt is zero.  We also have to munge the immediates a bit.
00098   virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const;
00099   
00100   virtual void insertNoop(MachineBasicBlock &MBB, 
00101                           MachineBasicBlock::iterator MI) const;
00102 
00103 
00104   // Branch analysis.
00105   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
00106                              MachineBasicBlock *&FBB,
00107                              SmallVectorImpl<MachineOperand> &Cond,
00108                              bool AllowModify) const;
00109   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
00110   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
00111                                 MachineBasicBlock *FBB,
00112                             const SmallVectorImpl<MachineOperand> &Cond) const;
00113   virtual bool copyRegToReg(MachineBasicBlock &MBB,
00114                             MachineBasicBlock::iterator MI,
00115                             unsigned DestReg, unsigned SrcReg,
00116                             const TargetRegisterClass *DestRC,
00117                             const TargetRegisterClass *SrcRC) const;
00118   
00119   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
00120                                    MachineBasicBlock::iterator MBBI,
00121                                    unsigned SrcReg, bool isKill, int FrameIndex,
00122                                    const TargetRegisterClass *RC) const;
00123 
00124   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
00125                                     MachineBasicBlock::iterator MBBI,
00126                                     unsigned DestReg, int FrameIndex,
00127                                     const TargetRegisterClass *RC) const;
00128   
00129   /// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into
00130   /// copy instructions, turning them into load/store instructions.
00131   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
00132                                               MachineInstr* MI,
00133                                               const SmallVectorImpl<unsigned> &Ops,
00134                                               int FrameIndex) const;
00135 
00136   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
00137                                               MachineInstr* MI,
00138                                               const SmallVectorImpl<unsigned> &Ops,
00139                                               MachineInstr* LoadMI) const {
00140     return 0;
00141   }
00142 
00143   virtual bool canFoldMemoryOperand(const MachineInstr *MI,
00144                                     const SmallVectorImpl<unsigned> &Ops) const;
00145   
00146   virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
00147   virtual
00148   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
00149 
00150   virtual bool isDeadInstruction(const MachineInstr *MI) const {
00151     // FIXME: Without this, ppc llvm-gcc doesn't bootstrap. That means some
00152     // instruction definitions are not modeling side effects correctly.
00153     // This is a workaround until we know the exact cause.
00154     return false;
00155   }
00156   
00157   /// GetInstSize - Return the number of bytes of code the specified
00158   /// instruction may be.  This returns the maximum number of bytes.
00159   ///
00160   virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
00161 };
00162 
00163 }
00164 
00165 #endif