efe721c00cf13e19889fa37ade446c7ae6268a14
[oota-llvm.git] / lib / Target / R600 / R600InstrInfo.h
1 //===-- R600InstrInfo.h - R600 Instruction Info Interface -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// \brief Interface definition for R600InstrInfo
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef R600INSTRUCTIONINFO_H_
16 #define R600INSTRUCTIONINFO_H_
17
18 #include "AMDGPUInstrInfo.h"
19 #include "AMDIL.h"
20 #include "R600Defines.h"
21 #include "R600RegisterInfo.h"
22 #include <map>
23
24 namespace llvm {
25
26   class AMDGPUTargetMachine;
27   class DFAPacketizer;
28   class ScheduleDAG;
29   class MachineFunction;
30   class MachineInstr;
31   class MachineInstrBuilder;
32
33   class R600InstrInfo : public AMDGPUInstrInfo {
34   private:
35   const R600RegisterInfo RI;
36
37   int getBranchInstr(const MachineOperand &op) const;
38
39   public:
40   explicit R600InstrInfo(AMDGPUTargetMachine &tm);
41
42   const R600RegisterInfo &getRegisterInfo() const;
43   virtual void copyPhysReg(MachineBasicBlock &MBB,
44                            MachineBasicBlock::iterator MI, DebugLoc DL,
45                            unsigned DestReg, unsigned SrcReg,
46                            bool KillSrc) const;
47
48   bool isTrig(const MachineInstr &MI) const;
49   bool isPlaceHolderOpcode(unsigned opcode) const;
50   bool isReductionOp(unsigned opcode) const;
51   bool isCubeOp(unsigned opcode) const;
52
53   /// \returns true if this \p Opcode represents an ALU instruction.
54   bool isALUInstr(unsigned Opcode) const;
55
56   /// \breif Vector instructions are instructions that must fill all
57   /// instruction slots within an instruction group.
58   bool isVector(const MachineInstr &MI) const;
59
60   virtual MachineInstr * getMovImmInstr(MachineFunction *MF, unsigned DstReg,
61                                         int64_t Imm) const;
62
63   virtual unsigned getIEQOpcode() const;
64   virtual bool isMov(unsigned Opcode) const;
65
66   DFAPacketizer *CreateTargetScheduleState(const TargetMachine *TM,
67                                            const ScheduleDAG *DAG) const;
68
69   bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
70
71   bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
72                      SmallVectorImpl<MachineOperand> &Cond, bool AllowModify) const;
73
74   unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, const SmallVectorImpl<MachineOperand> &Cond, DebugLoc DL) const;
75
76   unsigned RemoveBranch(MachineBasicBlock &MBB) const;
77
78   bool isPredicated(const MachineInstr *MI) const;
79
80   bool isPredicable(MachineInstr *MI) const;
81
82   bool
83    isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
84                              const BranchProbability &Probability) const;
85
86   bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
87                            unsigned ExtraPredCycles,
88                            const BranchProbability &Probability) const ;
89
90   bool
91    isProfitableToIfCvt(MachineBasicBlock &TMBB,
92                        unsigned NumTCycles, unsigned ExtraTCycles,
93                        MachineBasicBlock &FMBB,
94                        unsigned NumFCycles, unsigned ExtraFCycles,
95                        const BranchProbability &Probability) const;
96
97   bool DefinesPredicate(MachineInstr *MI,
98                                   std::vector<MachineOperand> &Pred) const;
99
100   bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
101                          const SmallVectorImpl<MachineOperand> &Pred2) const;
102
103   bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
104                                           MachineBasicBlock &FMBB) const;
105
106   bool PredicateInstruction(MachineInstr *MI,
107                         const SmallVectorImpl<MachineOperand> &Pred) const;
108
109   unsigned int getInstrLatency(const InstrItineraryData *ItinData,
110                                const MachineInstr *MI,
111                                unsigned *PredCost = 0) const;
112
113   virtual int getInstrLatency(const InstrItineraryData *ItinData,
114                               SDNode *Node) const { return 1;}
115
116   /// \returns a list of all the registers that may be accesed using indirect
117   /// addressing.
118   std::vector<unsigned> getIndirectReservedRegs(const MachineFunction &MF) const;
119
120   virtual int getIndirectIndexBegin(const MachineFunction &MF) const;
121
122   virtual int getIndirectIndexEnd(const MachineFunction &MF) const;
123
124
125   virtual unsigned calculateIndirectAddress(unsigned RegIndex,
126                                             unsigned Channel) const;
127
128   virtual const TargetRegisterClass *getIndirectAddrStoreRegClass(
129                                                       unsigned SourceReg) const;
130
131   virtual const TargetRegisterClass *getIndirectAddrLoadRegClass() const;
132
133   virtual MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
134                                   MachineBasicBlock::iterator I,
135                                   unsigned ValueReg, unsigned Address,
136                                   unsigned OffsetReg) const;
137
138   virtual MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
139                                   MachineBasicBlock::iterator I,
140                                   unsigned ValueReg, unsigned Address,
141                                   unsigned OffsetReg) const;
142
143   virtual const TargetRegisterClass *getSuperIndirectRegClass() const;
144
145
146   ///buildDefaultInstruction - This function returns a MachineInstr with
147   /// all the instruction modifiers initialized to their default values.
148   /// You can use this function to avoid manually specifying each instruction
149   /// modifier operand when building a new instruction.
150   ///
151   /// \returns a MachineInstr with all the instruction modifiers initialized
152   /// to their default values.
153   MachineInstrBuilder buildDefaultInstruction(MachineBasicBlock &MBB,
154                                               MachineBasicBlock::iterator I,
155                                               unsigned Opcode,
156                                               unsigned DstReg,
157                                               unsigned Src0Reg,
158                                               unsigned Src1Reg = 0) const;
159
160   MachineInstr *buildMovImm(MachineBasicBlock &BB,
161                                   MachineBasicBlock::iterator I,
162                                   unsigned DstReg,
163                                   uint64_t Imm) const;
164
165   /// \brief Get the index of Op in the MachineInstr.
166   ///
167   /// \returns -1 if the Instruction does not contain the specified \p Op.
168   int getOperandIdx(const MachineInstr &MI, R600Operands::Ops Op) const;
169
170   /// \brief Get the index of \p Op for the given Opcode.
171   ///
172   /// \returns -1 if the Instruction does not contain the specified \p Op.
173   int getOperandIdx(unsigned Opcode, R600Operands::Ops Op) const;
174
175   /// \brief Helper function for setting instruction flag values.
176   void setImmOperand(MachineInstr *MI, R600Operands::Ops Op, int64_t Imm) const;
177
178   /// \returns true if this instruction has an operand for storing target flags.
179   bool hasFlagOperand(const MachineInstr &MI) const;
180
181   ///\brief Add one of the MO_FLAG* flags to the specified \p Operand.
182   void addFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
183
184   ///\brief Determine if the specified \p Flag is set on this \p Operand.
185   bool isFlagSet(const MachineInstr &MI, unsigned Operand, unsigned Flag) const;
186
187   /// \param SrcIdx The register source to set the flag on (e.g src0, src1, src2)
188   /// \param Flag The flag being set.
189   ///
190   /// \returns the operand containing the flags for this instruction.
191   MachineOperand &getFlagOp(MachineInstr *MI, unsigned SrcIdx = 0,
192                             unsigned Flag = 0) const;
193
194   /// \brief Clear the specified flag on the instruction.
195   void clearFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
196 };
197
198 } // End llvm namespace
199
200 #endif // R600INSTRINFO_H_