blob: 2146788604b6f12cf61f07f191a1f58d875abddc [file] [log] [blame]
Tom Stellard75aadc22012-12-11 21:25:42 +00001//===-- 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
Tom Stellard75aadc22012-12-11 21:25:42 +000018#include "AMDGPUInstrInfo.h"
Chandler Carruthbe810232013-01-02 10:22:59 +000019#include "AMDIL.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000020#include "R600Defines.h"
21#include "R600RegisterInfo.h"
Tom Stellard75aadc22012-12-11 21:25:42 +000022#include <map>
23
24namespace 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;
Vincent Lejeunec2991642013-04-30 00:13:39 +000036 const AMDGPUSubtarget &ST;
Tom Stellard75aadc22012-12-11 21:25:42 +000037
38 int getBranchInstr(const MachineOperand &op) const;
39
40 public:
41 explicit R600InstrInfo(AMDGPUTargetMachine &tm);
42
43 const R600RegisterInfo &getRegisterInfo() const;
44 virtual void copyPhysReg(MachineBasicBlock &MBB,
45 MachineBasicBlock::iterator MI, DebugLoc DL,
46 unsigned DestReg, unsigned SrcReg,
47 bool KillSrc) const;
48
49 bool isTrig(const MachineInstr &MI) const;
50 bool isPlaceHolderOpcode(unsigned opcode) const;
51 bool isReductionOp(unsigned opcode) const;
52 bool isCubeOp(unsigned opcode) const;
53
54 /// \returns true if this \p Opcode represents an ALU instruction.
55 bool isALUInstr(unsigned Opcode) const;
56
Vincent Lejeunec2991642013-04-30 00:13:39 +000057 bool usesVertexCache(unsigned Opcode) const;
58 bool usesVertexCache(const MachineInstr *MI) const;
59 bool usesTextureCache(unsigned Opcode) const;
60 bool usesTextureCache(const MachineInstr *MI) const;
61
Vincent Lejeune0a22bc42013-03-14 15:50:45 +000062 bool fitsConstReadLimitations(const std::vector<unsigned>&) const;
63 bool canBundle(const std::vector<MachineInstr *> &) const;
64
Tom Stellard75aadc22012-12-11 21:25:42 +000065 /// \breif Vector instructions are instructions that must fill all
66 /// instruction slots within an instruction group.
67 bool isVector(const MachineInstr &MI) const;
68
69 virtual MachineInstr * getMovImmInstr(MachineFunction *MF, unsigned DstReg,
70 int64_t Imm) const;
71
72 virtual unsigned getIEQOpcode() const;
73 virtual bool isMov(unsigned Opcode) const;
74
75 DFAPacketizer *CreateTargetScheduleState(const TargetMachine *TM,
76 const ScheduleDAG *DAG) const;
77
78 bool ReverseBranchCondition(SmallVectorImpl<MachineOperand> &Cond) const;
79
80 bool AnalyzeBranch(MachineBasicBlock &MBB, MachineBasicBlock *&TBB, MachineBasicBlock *&FBB,
81 SmallVectorImpl<MachineOperand> &Cond, bool AllowModify) const;
82
83 unsigned InsertBranch(MachineBasicBlock &MBB, MachineBasicBlock *TBB, MachineBasicBlock *FBB, const SmallVectorImpl<MachineOperand> &Cond, DebugLoc DL) const;
84
85 unsigned RemoveBranch(MachineBasicBlock &MBB) const;
86
87 bool isPredicated(const MachineInstr *MI) const;
88
89 bool isPredicable(MachineInstr *MI) const;
90
91 bool
92 isProfitableToDupForIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
93 const BranchProbability &Probability) const;
94
95 bool isProfitableToIfCvt(MachineBasicBlock &MBB, unsigned NumCyles,
96 unsigned ExtraPredCycles,
97 const BranchProbability &Probability) const ;
98
99 bool
100 isProfitableToIfCvt(MachineBasicBlock &TMBB,
101 unsigned NumTCycles, unsigned ExtraTCycles,
102 MachineBasicBlock &FMBB,
103 unsigned NumFCycles, unsigned ExtraFCycles,
104 const BranchProbability &Probability) const;
105
106 bool DefinesPredicate(MachineInstr *MI,
107 std::vector<MachineOperand> &Pred) const;
108
109 bool SubsumesPredicate(const SmallVectorImpl<MachineOperand> &Pred1,
110 const SmallVectorImpl<MachineOperand> &Pred2) const;
111
112 bool isProfitableToUnpredicate(MachineBasicBlock &TMBB,
113 MachineBasicBlock &FMBB) const;
114
115 bool PredicateInstruction(MachineInstr *MI,
116 const SmallVectorImpl<MachineOperand> &Pred) const;
117
118 unsigned int getInstrLatency(const InstrItineraryData *ItinData,
119 const MachineInstr *MI,
120 unsigned *PredCost = 0) const;
121
122 virtual int getInstrLatency(const InstrItineraryData *ItinData,
123 SDNode *Node) const { return 1;}
124
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000125 /// \returns a list of all the registers that may be accesed using indirect
126 /// addressing.
127 std::vector<unsigned> getIndirectReservedRegs(const MachineFunction &MF) const;
128
129 virtual int getIndirectIndexBegin(const MachineFunction &MF) const;
130
131 virtual int getIndirectIndexEnd(const MachineFunction &MF) const;
132
133
134 virtual unsigned calculateIndirectAddress(unsigned RegIndex,
135 unsigned Channel) const;
136
137 virtual const TargetRegisterClass *getIndirectAddrStoreRegClass(
138 unsigned SourceReg) const;
139
140 virtual const TargetRegisterClass *getIndirectAddrLoadRegClass() const;
141
142 virtual MachineInstrBuilder buildIndirectWrite(MachineBasicBlock *MBB,
143 MachineBasicBlock::iterator I,
144 unsigned ValueReg, unsigned Address,
145 unsigned OffsetReg) const;
146
147 virtual MachineInstrBuilder buildIndirectRead(MachineBasicBlock *MBB,
148 MachineBasicBlock::iterator I,
149 unsigned ValueReg, unsigned Address,
150 unsigned OffsetReg) const;
151
152 virtual const TargetRegisterClass *getSuperIndirectRegClass() const;
153
Vincent Lejeune80031d9f2013-04-03 16:49:34 +0000154 unsigned getMaxAlusPerClause() const;
Tom Stellardf3b2a1e2013-02-06 17:32:29 +0000155
156 ///buildDefaultInstruction - This function returns a MachineInstr with
157 /// all the instruction modifiers initialized to their default values.
Tom Stellard75aadc22012-12-11 21:25:42 +0000158 /// You can use this function to avoid manually specifying each instruction
159 /// modifier operand when building a new instruction.
160 ///
161 /// \returns a MachineInstr with all the instruction modifiers initialized
162 /// to their default values.
163 MachineInstrBuilder buildDefaultInstruction(MachineBasicBlock &MBB,
164 MachineBasicBlock::iterator I,
165 unsigned Opcode,
166 unsigned DstReg,
167 unsigned Src0Reg,
168 unsigned Src1Reg = 0) const;
169
170 MachineInstr *buildMovImm(MachineBasicBlock &BB,
171 MachineBasicBlock::iterator I,
172 unsigned DstReg,
173 uint64_t Imm) const;
174
175 /// \brief Get the index of Op in the MachineInstr.
176 ///
177 /// \returns -1 if the Instruction does not contain the specified \p Op.
178 int getOperandIdx(const MachineInstr &MI, R600Operands::Ops Op) const;
179
180 /// \brief Get the index of \p Op for the given Opcode.
181 ///
182 /// \returns -1 if the Instruction does not contain the specified \p Op.
183 int getOperandIdx(unsigned Opcode, R600Operands::Ops Op) const;
184
185 /// \brief Helper function for setting instruction flag values.
186 void setImmOperand(MachineInstr *MI, R600Operands::Ops Op, int64_t Imm) const;
187
188 /// \returns true if this instruction has an operand for storing target flags.
189 bool hasFlagOperand(const MachineInstr &MI) const;
190
191 ///\brief Add one of the MO_FLAG* flags to the specified \p Operand.
192 void addFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
193
194 ///\brief Determine if the specified \p Flag is set on this \p Operand.
195 bool isFlagSet(const MachineInstr &MI, unsigned Operand, unsigned Flag) const;
196
197 /// \param SrcIdx The register source to set the flag on (e.g src0, src1, src2)
198 /// \param Flag The flag being set.
199 ///
200 /// \returns the operand containing the flags for this instruction.
201 MachineOperand &getFlagOp(MachineInstr *MI, unsigned SrcIdx = 0,
202 unsigned Flag = 0) const;
203
204 /// \brief Clear the specified flag on the instruction.
205 void clearFlag(MachineInstr *MI, unsigned Operand, unsigned Flag) const;
206};
207
208} // End llvm namespace
209
210#endif // R600INSTRINFO_H_