nv50/ir: make Instruction::src/def container private
[mesa.git] / src / gallium / drivers / nv50 / codegen / nv50_ir_target.h
1 /*
2 * Copyright 2011 Christoph Bumiller
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #ifndef __NV50_IR_TARGET_H__
24 #define __NV50_IR_TARGET_H__
25
26 #include "nv50_ir.h"
27
28 namespace nv50_ir {
29
30 struct RelocInfo;
31
32 struct RelocEntry
33 {
34 enum Type
35 {
36 TYPE_CODE,
37 TYPE_BUILTIN,
38 TYPE_DATA
39 };
40
41 uint32_t data;
42 uint32_t mask;
43 uint32_t offset;
44 int8_t bitPos;
45 Type type;
46
47 inline void apply(uint32_t *binary, const RelocInfo *info) const;
48 };
49
50 struct RelocInfo
51 {
52 uint32_t codePos;
53 uint32_t libPos;
54 uint32_t dataPos;
55
56 uint32_t count;
57
58 RelocEntry entry[0];
59 };
60
61 class CodeEmitter
62 {
63 public:
64 // returns whether the instruction was encodable and written
65 virtual bool emitInstruction(Instruction *) = 0;
66
67 virtual uint32_t getMinEncodingSize(const Instruction *) const = 0;
68
69 void setCodeLocation(void *, uint32_t size);
70 inline void *getCodeLocation() const { return code; }
71 inline uint32_t getCodeSize() const { return codeSize; }
72
73 bool addReloc(RelocEntry::Type, int w, uint32_t data, uint32_t m,
74 int s);
75
76 inline void *getRelocInfo() const { return relocInfo; }
77
78 void prepareEmission(Program *);
79 void prepareEmission(Function *);
80 virtual void prepareEmission(BasicBlock *);
81
82 void printBinary() const;
83
84 protected:
85 uint32_t *code;
86 uint32_t codeSize;
87 uint32_t codeSizeLimit;
88
89 RelocInfo *relocInfo;
90 };
91
92 class Target
93 {
94 public:
95 static Target *create(uint32_t chipset);
96 static void destroy(Target *);
97
98 // 0x50 and 0x84 to 0xaf for nv50
99 // 0xc0 to 0xdf for nvc0
100 inline uint32_t getChipset() const { return chipset; }
101
102 virtual CodeEmitter *getCodeEmitter(Program::Type) = 0;
103
104 // Drivers should upload this so we can use it from all programs.
105 // The address chosen is supplied to the relocation routine.
106 virtual void getBuiltinCode(const uint32_t **code, uint32_t *size) const = 0;
107
108 virtual bool runLegalizePass(Program *, CGStage stage) const = 0;
109
110 public:
111 struct OpInfo
112 {
113 OpInfo *variants;
114 operation op;
115 uint16_t srcTypes;
116 uint16_t dstTypes;
117 uint32_t immdBits;
118 uint8_t srcNr;
119 uint8_t srcMods[3];
120 uint8_t dstMods;
121 uint8_t srcFiles[3];
122 uint8_t dstFiles;
123 unsigned int minEncSize : 4;
124 unsigned int vector : 1;
125 unsigned int predicate : 1;
126 unsigned int commutative : 1;
127 unsigned int pseudo : 1;
128 unsigned int flow : 1;
129 unsigned int hasDest : 1;
130 unsigned int terminator : 1;
131 };
132
133 inline const OpInfo& getOpInfo(const Instruction *) const;
134 inline const OpInfo& getOpInfo(const operation) const;
135
136 inline DataFile nativeFile(DataFile f) const;
137
138 virtual bool insnCanLoad(const Instruction *insn, int s,
139 const Instruction *ld) const = 0;
140 virtual bool isOpSupported(operation, DataType) const = 0;
141 virtual bool isAccessSupported(DataFile, DataType) const = 0;
142 virtual bool isModSupported(const Instruction *,
143 int s, Modifier) const = 0;
144 virtual bool isSatSupported(const Instruction *) const = 0;
145 virtual bool isPostMultiplySupported(operation op, float f,
146 int& e) const { return false; }
147 virtual bool mayPredicate(const Instruction *,
148 const Value *) const = 0;
149
150 virtual int getLatency(const Instruction *) const { return 1; }
151 virtual int getThroughput(const Instruction *) const { return 1; }
152
153 virtual unsigned int getFileSize(DataFile) const = 0;
154 virtual unsigned int getFileUnit(DataFile) const = 0;
155
156 virtual uint32_t getSVAddress(DataFile, const Symbol *) const = 0;
157
158 public:
159 bool joinAnterior; // true if join is executed before the op
160
161 static const uint8_t operationSrcNr[OP_LAST + 1];
162
163 protected:
164 uint32_t chipset;
165
166 DataFile nativeFileMap[DATA_FILE_COUNT];
167
168 OpInfo opInfo[OP_LAST + 1];
169 };
170
171 const Target::OpInfo& Target::getOpInfo(const Instruction *insn) const
172 {
173 return opInfo[MIN2(insn->op, OP_LAST)];
174 }
175
176 const Target::OpInfo& Target::getOpInfo(const operation op) const
177 {
178 return opInfo[op];
179 }
180
181 inline DataFile Target::nativeFile(DataFile f) const
182 {
183 return nativeFileMap[f];
184 }
185
186 } // namespace nv50_ir
187
188 #endif // __NV50_IR_TARGET_H__