PPCInstrInfo.h revision 44eb65cf58e3ab9b5621ce72256d1621a18aeed7
1603c4be006d8c53905d736bf1f19a49f5ce98276Alexey Samsonov//===- PPCInstrInfo.h - PowerPC Instruction Information ---------*- C++ -*-===//
27ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
37ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//                     The LLVM Compiler Infrastructure
47ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
57ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file is distributed under the University of Illinois Open Source
67ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// License. See LICENSE.TXT for details.
77ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
87ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===//
97ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany// This file contains the PowerPC implementation of the TargetInstrInfo class.
117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//
127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany//===----------------------------------------------------------------------===//
137ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
140969bcf2c936126b1f6e636b978aade8fc207437Alexey Samsonov#ifndef POWERPC32_INSTRUCTIONINFO_H
157f9c5a220b2768a450696bbd157a0e6f2e9ceea3Alexey Samsonov#define POWERPC32_INSTRUCTIONINFO_H
167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
177ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "PPC.h"
187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "llvm/Target/TargetInstrInfo.h"
197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany#include "PPCRegisterInfo.h"
207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
217ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanynamespace llvm {
227ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
237ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/// PPCII - This namespace holds all of the PowerPC target-specific
247ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/// per-instruction flags.  These must match the corresponding definitions in
257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany/// PPC.td and PPCInstrFormats.td.
267ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanynamespace PPCII {
277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum {
287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  // PPC970 Instruction Flags.  These flags describe the characteristics of the
297ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  // PowerPC 970 (aka G5) dispatch groups and how they are formed out of
307ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  // raw machine instructions.
3167a64dd8259fdbd867633b27f54d584f435f1ce6Alexey Samsonov
327ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// PPC970_First - This instruction starts a new dispatch group, so it will
330969bcf2c936126b1f6e636b978aade8fc207437Alexey Samsonov  /// always be the first one in the group.
347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_First = 0x1,
357ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
3667a64dd8259fdbd867633b27f54d584f435f1ce6Alexey Samsonov  /// PPC970_Single - This instruction starts a new dispatch group and
377ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// terminates it, so it will be the sole instruction in the group.
387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_Single = 0x2,
397ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
407ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// PPC970_Cracked - This instruction is cracked into two pieces, requiring
417ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// two dispatch pipes to be available to issue.
4267a64dd8259fdbd867633b27f54d584f435f1ce6Alexey Samsonov  PPC970_Cracked = 0x4,
437ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
447ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// PPC970_Mask/Shift - This is a bitmask that selects the pipeline type that
457ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// an instruction is issued to.
467ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_Shift = 3,
477ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_Mask = 0x07 << PPC970_Shift
4867a64dd8259fdbd867633b27f54d584f435f1ce6Alexey Samsonov};
497ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyenum PPC970_Unit {
507ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// These are the various PPC970 execution unit pipelines.  Each instruction
517ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// is one of these.
527ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_Pseudo = 0 << PPC970_Shift,   // Pseudo instruction
537ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_FXU    = 1 << PPC970_Shift,   // Fixed Point (aka Integer/ALU) Unit
547ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_LSU    = 2 << PPC970_Shift,   // Load Store Unit
557ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_FPU    = 3 << PPC970_Shift,   // Floating Point Unit
567ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_CRU    = 4 << PPC970_Shift,   // Control Register Unit
577ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPC970_VALU   = 5 << PPC970_Shift,   // Vector ALU
5820f60c53c446f42af2b4ebc3b85f6a5042be6904Dmitry Vyukov  PPC970_VPERM  = 6 << PPC970_Shift,   // Vector Permute Unit
5920f60c53c446f42af2b4ebc3b85f6a5042be6904Dmitry Vyukov  PPC970_BRU    = 7 << PPC970_Shift    // Branch Unit
607ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany};
617ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany}
627ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
637ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
647ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanyclass PPCInstrInfo : public TargetInstrInfoImpl {
657ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  PPCTargetMachine &TM;
667ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  const PPCRegisterInfo RI;
677ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
687ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  bool StoreRegToStackSlot(MachineFunction &MF,
697ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                           unsigned SrcReg, bool isKill, int FrameIdx,
707ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                           const TargetRegisterClass *RC,
717ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                           SmallVectorImpl<MachineInstr*> &NewMIs) const;
7288207ab15125e2f1e9b3d541b735b2b8aba9b6d9Alexey Samsonov  void LoadRegFromStackSlot(MachineFunction &MF,
737ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            unsigned DestReg, int FrameIdx,
747ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            const TargetRegisterClass *RC,
757ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            SmallVectorImpl<MachineInstr*> &NewMIs) const;
767ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryanypublic:
777ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  explicit PPCInstrInfo(PPCTargetMachine &TM);
787ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
797ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
807ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// such, whenever a client has an instance of instruction info, it should
817ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// always be able to get register info as well (through this method).
827ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  ///
837ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual const PPCRegisterInfo &getRegisterInfo() const { return RI; }
847ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
857ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// getPointerRegClass - Return the register class to use to hold pointers.
867ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// This is used for addressing modes.
877ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual const TargetRegisterClass *getPointerRegClass() const;
887ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
897ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  // Return true if the instruction is a register to register move and
907ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  // leave the source and dest operands in the passed parameters.
917ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  //
927ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual bool isMoveInstr(const MachineInstr& MI,
937ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                           unsigned& sourceReg,
947ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                           unsigned& destReg) const;
957ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
967ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  unsigned isLoadFromStackSlot(MachineInstr *MI, int &FrameIndex) const;
9788207ab15125e2f1e9b3d541b735b2b8aba9b6d9Alexey Samsonov  unsigned isStoreToStackSlot(MachineInstr *MI, int &FrameIndex) const;
987ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
997ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  // commuteInstruction - We can commute rlwimi instructions, but only if the
10088207ab15125e2f1e9b3d541b735b2b8aba9b6d9Alexey Samsonov  // rotate amt is zero.  We also have to munge the immediates a bit.
1017ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const;
1027ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1037ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual void insertNoop(MachineBasicBlock &MBB,
10488207ab15125e2f1e9b3d541b735b2b8aba9b6d9Alexey Samsonov                          MachineBasicBlock::iterator MI) const;
1057ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1067ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1077ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  // Branch analysis.
10888207ab15125e2f1e9b3d541b735b2b8aba9b6d9Alexey Samsonov  virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
1097ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                             MachineBasicBlock *&FBB,
1107ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                             SmallVectorImpl<MachineOperand> &Cond) const;
1117ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
1127ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
11367a64dd8259fdbd867633b27f54d584f435f1ce6Alexey Samsonov                                MachineBasicBlock *FBB,
1147ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            const SmallVectorImpl<MachineOperand> &Cond) const;
1157ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual void copyRegToReg(MachineBasicBlock &MBB,
1167ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            MachineBasicBlock::iterator MI,
1177ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            unsigned DestReg, unsigned SrcReg,
1187ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            const TargetRegisterClass *DestRC,
1197ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                            const TargetRegisterClass *SrcRC) const;
1207ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
12120f60c53c446f42af2b4ebc3b85f6a5042be6904Dmitry Vyukov  virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
12288207ab15125e2f1e9b3d541b735b2b8aba9b6d9Alexey Samsonov                                   MachineBasicBlock::iterator MBBI,
12320f60c53c446f42af2b4ebc3b85f6a5042be6904Dmitry Vyukov                                   unsigned SrcReg, bool isKill, int FrameIndex,
1247ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                   const TargetRegisterClass *RC) const;
1257ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1267ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual void storeRegToAddr(MachineFunction &MF, unsigned SrcReg, bool isKill,
1277ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                              SmallVectorImpl<MachineOperand> &Addr,
1287ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                              const TargetRegisterClass *RC,
1297ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                              SmallVectorImpl<MachineInstr*> &NewMIs) const;
1307ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1317ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
1327ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                    MachineBasicBlock::iterator MBBI,
1337ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                    unsigned DestReg, int FrameIndex,
1347ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                    const TargetRegisterClass *RC) const;
1357ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1367ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual void loadRegFromAddr(MachineFunction &MF, unsigned DestReg,
1377ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                               SmallVectorImpl<MachineOperand> &Addr,
1387ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                               const TargetRegisterClass *RC,
1397ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                               SmallVectorImpl<MachineInstr*> &NewMIs) const;
1407ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1417ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// foldMemoryOperand - PowerPC (like most RISC's) can only fold spills into
1427ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// copy instructions, turning them into load/store instructions.
1437ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
1447ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                          MachineInstr* MI,
1457ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                          SmallVectorImpl<unsigned> &Ops,
1467ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                          int FrameIndex) const;
1477ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1487ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual MachineInstr* foldMemoryOperand(MachineFunction &MF,
1497ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                          MachineInstr* MI,
1507ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                          SmallVectorImpl<unsigned> &Ops,
1517ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany                                          MachineInstr* LoadMI) const {
1527ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany    return 0;
153a13749bd7b3629a3498e765960729a8ade5db7cfDmitry Vyukov  }
154a13749bd7b3629a3498e765960729a8ade5db7cfDmitry Vyukov
155a13749bd7b3629a3498e765960729a8ade5db7cfDmitry Vyukov  virtual bool canFoldMemoryOperand(MachineInstr *MI,
15620f60c53c446f42af2b4ebc3b85f6a5042be6904Dmitry Vyukov                                    SmallVectorImpl<unsigned> &Ops) const;
1577ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1587ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual bool BlockHasNoFallThrough(MachineBasicBlock &MBB) const;
1597ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  virtual
1607ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
1617ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany
1627ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// GetInstSize - Return the number of bytes of code the specified
1637ac41484ea322e0ea5774df681660269f5dc321eKostya Serebryany  /// instruction may be.  This returns the maximum number of bytes.
164  ///
165  virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
166};
167
168}
169
170#endif
171