LLVM API Documentation

ARMInstrInfo.h

Go to the documentation of this file.
00001 //===- ARMInstrInfo.h - ARM 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 ARM implementation of the TargetInstrInfo class.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #ifndef ARMINSTRUCTIONINFO_H
00015 #define ARMINSTRUCTIONINFO_H
00016 
00017 #include "llvm/Target/TargetInstrInfo.h"
00018 #include "ARMRegisterInfo.h"
00019 #include "ARM.h"
00020 
00021 namespace llvm {
00022   class ARMSubtarget;
00023 
00024 /// ARMII - This namespace holds all of the target specific flags that
00025 /// instruction info tracks.
00026 ///
00027 namespace ARMII {
00028   enum {
00029     //===------------------------------------------------------------------===//
00030     // Instruction Flags.
00031 
00032     //===------------------------------------------------------------------===//
00033     // This four-bit field describes the addressing mode used.
00034 
00035     AddrModeMask  = 0xf,
00036     AddrModeNone  = 0,
00037     AddrMode1     = 1,
00038     AddrMode2     = 2,
00039     AddrMode3     = 3,
00040     AddrMode4     = 4,
00041     AddrMode5     = 5,
00042     AddrModeT1    = 6,
00043     AddrModeT2    = 7,
00044     AddrModeT4    = 8,
00045     AddrModeTs    = 9,  // i8 * 4 for pc and sp relative data
00046 
00047     // Size* - Flags to keep track of the size of an instruction.
00048     SizeShift     = 4,
00049     SizeMask      = 7 << SizeShift,
00050     SizeSpecial   = 1,   // 0 byte pseudo or special case.
00051     Size8Bytes    = 2,
00052     Size4Bytes    = 3,
00053     Size2Bytes    = 4,
00054     
00055     // IndexMode - Unindex, pre-indexed, or post-indexed. Only valid for load
00056     // and store ops 
00057     IndexModeShift = 7,
00058     IndexModeMask  = 3 << IndexModeShift,
00059     IndexModePre   = 1,
00060     IndexModePost  = 2,
00061     
00062     //===------------------------------------------------------------------===//
00063     // Misc flags.
00064 
00065     // UnaryDP - Indicates this is a unary data processing instruction, i.e.
00066     // it doesn't have a Rn operand.
00067     UnaryDP       = 1 << 9,
00068 
00069     //===------------------------------------------------------------------===//
00070     // Instruction encoding formats.
00071     //
00072     FormShift     = 10,
00073     FormMask      = 0x1f << FormShift,
00074 
00075     // Pseudo instructions
00076     Pseudo        = 0  << FormShift,
00077 
00078     // Multiply instructions
00079     MulFrm        = 1  << FormShift,
00080 
00081     // Branch instructions
00082     BrFrm         = 2  << FormShift,
00083     BrMiscFrm     = 3  << FormShift,
00084 
00085     // Data Processing instructions
00086     DPFrm         = 4  << FormShift,
00087     DPSoRegFrm    = 5  << FormShift,
00088 
00089     // Load and Store
00090     LdFrm         = 6  << FormShift,
00091     StFrm         = 7  << FormShift,
00092     LdMiscFrm     = 8  << FormShift,
00093     StMiscFrm     = 9  << FormShift,
00094     LdStMulFrm    = 10 << FormShift,
00095 
00096     // Miscellaneous arithmetic instructions
00097     ArithMiscFrm  = 11 << FormShift,
00098 
00099     // Extend instructions
00100     ExtFrm        = 12 << FormShift,
00101 
00102     // VFP formats
00103     VFPUnaryFrm   = 13 << FormShift,
00104     VFPBinaryFrm  = 14 << FormShift,
00105     VFPConv1Frm   = 15 << FormShift,
00106     VFPConv2Frm   = 16 << FormShift,
00107     VFPConv3Frm   = 17 << FormShift,
00108     VFPConv4Frm   = 18 << FormShift,
00109     VFPConv5Frm   = 19 << FormShift,
00110     VFPLdStFrm    = 20 << FormShift,
00111     VFPLdStMulFrm = 21 << FormShift,
00112     VFPMiscFrm    = 22 << FormShift,
00113 
00114     // Thumb format
00115     ThumbFrm      = 23 << FormShift,
00116 
00117     //===------------------------------------------------------------------===//
00118     // Field shifts - such shifts are used to set field while generating
00119     // machine instructions.
00120     M_BitShift     = 5,
00121     ShiftImmShift  = 5,
00122     ShiftShift     = 7,
00123     N_BitShift     = 7,
00124     ImmHiShift     = 8,
00125     SoRotImmShift  = 8,
00126     RegRsShift     = 8,
00127     ExtRotImmShift = 10,
00128     RegRdLoShift   = 12,
00129     RegRdShift     = 12,
00130     RegRdHiShift   = 16,
00131     RegRnShift     = 16,
00132     S_BitShift     = 20,
00133     W_BitShift     = 21,
00134     AM3_I_BitShift = 22,
00135     D_BitShift     = 22,
00136     U_BitShift     = 23,
00137     P_BitShift     = 24,
00138     I_BitShift     = 25,
00139     CondShift      = 28
00140   };
00141 }
00142 
00143 class ARMInstrInfo : public TargetInstrInfoImpl {
00144   const ARMRegisterInfo RI;
00145 public:
00146   explicit ARMInstrInfo(const ARMSubtarget &STI);
00147 
00148   /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
00149   /// such, whenever a client has an instance of instruction info, it should
00150   /// always be able to get register info as well (through this method).
00151   ///
00152   virtual const ARMRegisterInfo &getRegisterInfo() const { return RI; }
00153 
00154   /// getPointerRegClass - Return the register class to use to hold pointers.
00155   /// This is used for addressing modes.
00156   virtual const TargetRegisterClass *getPointerRegClass() const;
00157 
00158   /// Return true if the instruction is a register to register move and return
00159   /// the source and dest operands and their sub-register indices by reference.
00160   virtual bool isMoveInstr(const MachineInstr &MI,
00161                            unsigned &SrcReg, unsigned &DstReg,
00162                            unsigned &SrcSubIdx, unsigned &DstSubIdx) const;
00163 
00164   virtual unsigned isLoadFromStackSlot(const MachineInstr *MI,
00165                                        int &FrameIndex) const;
00166   virtual unsigned isStoreToStackSlot(const MachineInstr *MI,
00167                                       int &FrameIndex) const;
00168   
00169   void reMaterialize(MachineBasicBlock &MBB, MachineBasicBlock::iterator MI,
00170                      unsigned DestReg, const MachineInstr *Orig) const;
00171 
00172   virtual MachineInstr *convertToThreeAddress(MachineFunction::iterator &MFI,
00173                                               MachineBasicBlock::iterator &MBBI,
00174                                               LiveVariables *LV) const;
00175 
00176   // Branch analysis.
00177   virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
00178                              MachineBasicBlock *&FBB,
00179                              SmallVectorImpl<MachineOperand> &Cond,
00180                              bool AllowModify) const;
00181   virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
00182   virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
00183                                 MachineBasicBlock *FBB,
00184                             const SmallVectorImpl<MachineOperand> &Cond) const;
00185   virtual bool copyRegToReg(MachineBasicBlock &MBB,
00186                             MachineBasicBlock::iterator I,
00187                             unsigned DestReg, unsigned SrcReg,
00188                             const TargetRegisterClass *DestRC,
00189                             const TargetRegisterClass *SrcRC) const;
00190   virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
00191                                    MachineBasicBlock::iterator MBBI,
00192                                    unsigned SrcReg, bool isKill, int FrameIndex,
00193                                    const TargetRegisterClass *RC) const;
00194 
00195   virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
00196                               SmallVectorImpl<MachineOperand> &Addr,
00197                               const TargetRegisterClass *RC,
00198                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
00199 
00200   virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
00201                                     MachineBasicBlock::iterator MBBI,
00202                                     unsigned DestReg, int FrameIndex,
00203                                     const TargetRegisterClass *RC) const;
00204 
00205   virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
00206                                SmallVectorImpl<MachineOperand> &Addr,
00207                                const TargetRegisterClass *RC,
00208                                SmallVectorImpl<MachineInstr*> &NewMIs) const;
00209   virtual bool spillCalleeSavedRegisters(MachineBasicBlock &MBB,
00210                                          MachineBasicBlock::iterator MI,
00211                                  const std::vector<CalleeSavedInfo> &CSI) const;
00212   virtual bool restoreCalleeSavedRegisters(MachineBasicBlock &MBB,
00213                                            MachineBasicBlock::iterator MI,
00214                                  const std::vector<CalleeSavedInfo> &CSI) const;
00215   
00216   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
00217                                               MachineInstr* MI,
00218                                            const SmallVectorImpl<unsigned> &Ops,
00219                                               int FrameIndex) const;
00220 
00221   virtual MachineInstr* foldMemoryOperandImpl(MachineFunction &MF,
00222                                               MachineInstr* MI,
00223                                            const SmallVectorImpl<unsigned> &Ops,
00224                                               MachineInstr* LoadMI) const {
00225     return 0;
00226   }
00227 
00228   virtual bool canFoldMemoryOperand(const MachineInstr *MI,
00229                                     const SmallVectorImpl<unsigned> &Ops) const;
00230   
00231   virtual bool BlockHasNoFallThrough(const MachineBasicBlock &MBB) const;
00232   virtual
00233   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
00234 
00235   // Predication support.
00236   virtual bool isPredicated(const MachineInstr *MI) const;
00237 
00238   ARMCC::CondCodes getPredicate(const MachineInstr *MI) const {
00239     int PIdx = MI->findFirstPredOperandIdx();
00240     return PIdx != -1 ? (ARMCC::CondCodes)MI->getOperand(PIdx).getImm() 
00241                       : ARMCC::AL;
00242   }
00243 
00244   virtual
00245   bool PredicateInstruction(MachineInstr *MI,
00246                             const SmallVectorImpl<MachineOperand> &Pred) const;
00247 
00248   virtual
00249   bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
00250                          const SmallVectorImpl<MachineOperand> &Pred2) const;
00251 
00252   virtual bool DefinesPredicate(MachineInstr *MI,
00253                                 std::vector<MachineOperand> &Pred) const;
00254     
00255   /// GetInstSize - Returns the size of the specified MachineInstr.
00256   ///
00257   virtual unsigned GetInstSizeInBytes(const MachineInstr* MI) const;
00258 };
00259 
00260 }
00261 
00262 #endif