1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===- PPCInstrInfo.h - PowerPC Instruction Information ---------*- C++ -*-===//
2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//                     The LLVM Compiler Infrastructure
4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source
6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details.
7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file contains the PowerPC implementation of the TargetInstrInfo class.
11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//
12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===//
13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef POWERPC32_INSTRUCTIONINFO_H
15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define POWERPC32_INSTRUCTIONINFO_H
16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "PPC.h"
18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Target/TargetInstrInfo.h"
19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "PPCRegisterInfo.h"
20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
2119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#define GET_INSTRINFO_HEADER
2219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#include "PPCGenInstrInfo.inc"
2319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm {
25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// PPCII - This namespace holds all of the PowerPC target-specific
27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// per-instruction flags.  These must match the corresponding definitions in
28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman/// PPC.td and PPCInstrFormats.td.
29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace PPCII {
30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanenum {
31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // PPC970 Instruction Flags.  These flags describe the characteristics of the
32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // PowerPC 970 (aka G5) dispatch groups and how they are formed out of
33894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // raw machine instructions.
34894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
35894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// PPC970_First - This instruction starts a new dispatch group, so it will
36894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// always be the first one in the group.
37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_First = 0x1,
3819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// PPC970_Single - This instruction starts a new dispatch group and
40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// terminates it, so it will be the sole instruction in the group.
41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_Single = 0x2,
42894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
43894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// PPC970_Cracked - This instruction is cracked into two pieces, requiring
44894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// two dispatch pipes to be available to issue.
45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_Cracked = 0x4,
4619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// PPC970_Mask/Shift - This is a bitmask that selects the pipeline type that
48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// an instruction is issued to.
49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_Shift = 3,
50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_Mask = 0x07 << PPC970_Shift
51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanenum PPC970_Unit {
53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// These are the various PPC970 execution unit pipelines.  Each instruction
54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// is one of these.
55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_Pseudo = 0 << PPC970_Shift,   // Pseudo instruction
56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_FXU    = 1 << PPC970_Shift,   // Fixed Point (aka Integer/ALU) Unit
57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_LSU    = 2 << PPC970_Shift,   // Load Store Unit
58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_FPU    = 3 << PPC970_Shift,   // Floating Point Unit
59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_CRU    = 4 << PPC970_Shift,   // Control Register Unit
60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_VALU   = 5 << PPC970_Shift,   // Vector ALU
61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_VPERM  = 6 << PPC970_Shift,   // Vector Permute Unit
62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPC970_BRU    = 7 << PPC970_Shift    // Branch Unit
63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
6419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman} // end namespace PPCII
6519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
6619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Baumanclass PPCInstrInfo : public PPCGenInstrInfo {
68894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  PPCTargetMachine &TM;
69894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  const PPCRegisterInfo RI;
70894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
71894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool StoreRegToStackSlot(MachineFunction &MF,
72894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                           unsigned SrcReg, bool isKill, int FrameIdx,
73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                           const TargetRegisterClass *RC,
74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                           SmallVectorImpl<MachineInstr*> &NewMIs) const;
7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  void LoadRegFromStackSlot(MachineFunction &MF, DebugLoc DL,
76894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                            unsigned DestReg, int FrameIdx,
77894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                            const TargetRegisterClass *RC,
78894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                            SmallVectorImpl<MachineInstr*> &NewMIs) const;
79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumanpublic:
80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  explicit PPCInstrInfo(PPCTargetMachine &TM);
81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// getRegisterInfo - TargetInstrInfo is a superset of MRegister info.  As
83894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// such, whenever a client has an instance of instruction info, it should
84894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// always be able to get register info as well (through this method).
85894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
86894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual const PPCRegisterInfo &getRegisterInfo() const { return RI; }
87894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  ScheduleHazardRecognizer *
8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  CreateTargetHazardRecognizer(const TargetMachine *TM,
9019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman                               const ScheduleDAG *DAG) const;
9119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
92894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned isLoadFromStackSlot(const MachineInstr *MI,
93894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                               int &FrameIndex) const;
94894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  unsigned isStoreToStackSlot(const MachineInstr *MI,
95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                              int &FrameIndex) const;
96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // commuteInstruction - We can commute rlwimi instructions, but only if the
98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // rotate amt is zero.  We also have to munge the immediates a bit.
99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual MachineInstr *commuteInstruction(MachineInstr *MI, bool NewMI) const;
10019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
10119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman  virtual void insertNoop(MachineBasicBlock &MBB,
102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                          MachineBasicBlock::iterator MI) const;
103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  // Branch analysis.
106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB,
107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                             MachineBasicBlock *&FBB,
108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                             SmallVectorImpl<MachineOperand> &Cond,
109894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                             bool AllowModify) const;
110894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual unsigned RemoveBranch(MachineBasicBlock &MBB) const;
111894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB,
112894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                MachineBasicBlock *FBB,
113894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                const SmallVectorImpl<MachineOperand> &Cond,
114894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                DebugLoc DL) const;
115894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual void copyPhysReg(MachineBasicBlock &MBB,
116894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                           MachineBasicBlock::iterator I, DebugLoc DL,
117894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                           unsigned DestReg, unsigned SrcReg,
118894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                           bool KillSrc) const;
11919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual void storeRegToStackSlot(MachineBasicBlock &MBB,
121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   MachineBasicBlock::iterator MBBI,
122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   unsigned SrcReg, bool isKill, int FrameIndex,
123894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   const TargetRegisterClass *RC,
124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                   const TargetRegisterInfo *TRI) const;
125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual void loadRegFromStackSlot(MachineBasicBlock &MBB,
127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                    MachineBasicBlock::iterator MBBI,
128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                    unsigned DestReg, int FrameIndex,
129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                    const TargetRegisterClass *RC,
130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                    const TargetRegisterInfo *TRI) const;
13119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual MachineInstr *emitFrameIndexDebugValue(MachineFunction &MF,
133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                                 int FrameIx,
134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                                 uint64_t Offset,
135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                                 const MDNode *MDPtr,
136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman                                                 DebugLoc DL) const;
137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual
139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
14019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman
141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// GetInstSize - Return the number of bytes of code the specified
142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  /// instruction may be.  This returns the maximum number of bytes.
143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  ///
144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman  virtual unsigned GetInstSizeInBytes(const MachineInstr *MI) const;
145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman};
146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman}
148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman
149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif
150