R600: Simplify stream outputs intrinsic
[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   /// You can use this function to avoid manually specifying each instruction
117   /// modifier operand when building a new instruction.
118   ///
119   /// \returns a MachineInstr with all the instruction modifiers initialized
120   /// to their default values.
121   MachineInstrBuilder buildDefaultInstruction(MachineBasicBlock &MBB,
122                                               MachineBasicBlock::iterator I,
123                                               unsigned Opcode,
124                                               unsigned DstReg,
125                                               unsigned Src0Reg,
126                                               unsigned Src1Reg = 0) const;
127
128   MachineInstr *buildMovImm(MachineBasicBlock &BB,
129                                   MachineBasicBlock::iterator I,
130                                   unsigned DstReg,
131                                   uint64_t Imm) const;
132
133   /// \brief Get the index of Op in the MachineInstr.
134   ///
135   /// \returns -1 if the Instruction does not contain the specified \p Op.
136   int getOperandIdx(const MachineInstr &MI, R600Operands::Ops Op) const;
137
138   /// \brief Get the index of \p Op for the given Opcode.
139   ///
140   /// \returns -1 if the Instruction does not contain the specified \p Op.
141   int getOperandIdx(unsigned Opcode, R600Operands::Ops Op) const;
142
143   /// \brief Helper function for setting instruction flag values.
144   void setImmOperand(MachineInstr *MI, R600Operands::Ops Op, int64_t Imm) const;
145
146   /// \returns true if this instruction has an operand for storing target flags.
147   bool hasFlagOperand(const MachineInstr &MI) const;
148
149   ///\brief Add one of the MO_FLAG* flags to the specified \p Operand.
150   void addFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
151
152   ///\brief Determine if the specified \p Flag is set on this \p Operand.
153   bool isFlagSet(const MachineInstr &MI, unsigned Operand, unsigned Flag) const;
154
155   /// \param SrcIdx The register source to set the flag on (e.g src0, src1, src2)
156   /// \param Flag The flag being set.
157   ///
158   /// \returns the operand containing the flags for this instruction.
159   MachineOperand &getFlagOp(MachineInstr *MI, unsigned SrcIdx = 0,
160                             unsigned Flag = 0) const;
161
162   /// \brief Clear the specified flag on the instruction.
163   void clearFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
164 };
165
166 } // End llvm namespace
167
168 #endif // R600INSTRINFO_H_