2 * Copyright 2011 Christoph Bumiller
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef __NV50_IR_TARGET_H__
24 #define __NV50_IR_TARGET_H__
26 #include "codegen/nv50_ir.h"
47 inline void apply(uint32_t *binary
, const RelocInfo
*info
) const;
62 FixupData(bool force
, bool flat
, uint8_t alphatest
) :
63 force_persample_interp(force
), flatshade(flat
), alphatest(alphatest
) {}
64 bool force_persample_interp
;
70 typedef void (*FixupApply
)(const FixupEntry
*, uint32_t*, const FixupData
&);
74 FixupEntry(FixupApply apply
, int ipa
, int reg
, int loc
) :
75 apply(apply
), ipa(ipa
), reg(reg
), loc(loc
) {}
80 uint32_t ipa
:4; // SC mode used to identify colors
81 uint32_t reg
:8; // The reg used for perspective division
82 uint32_t loc
:20; // Let's hope we don't have more than 1M-sized shaders
97 CodeEmitter(const Target
*);
98 virtual ~CodeEmitter() { }
100 // returns whether the instruction was encodable and written
101 virtual bool emitInstruction(Instruction
*) = 0;
103 virtual uint32_t getMinEncodingSize(const Instruction
*) const = 0;
105 void setCodeLocation(void *, uint32_t size
);
106 inline void *getCodeLocation() const { return code
; }
107 inline uint32_t getCodeSize() const { return codeSize
; }
109 bool addReloc(RelocEntry::Type
, int w
, uint32_t data
, uint32_t m
,
112 inline void *getRelocInfo() const { return relocInfo
; }
114 bool addInterp(int ipa
, int reg
, FixupApply apply
);
115 inline void *getFixupInfo() const { return fixupInfo
; }
117 virtual void prepareEmission(Program
*);
118 virtual void prepareEmission(Function
*);
119 virtual void prepareEmission(BasicBlock
*);
121 void printBinary() const;
128 uint32_t codeSizeLimit
;
130 RelocInfo
*relocInfo
;
131 FixupInfo
*fixupInfo
;
147 OPCLASS_TEXTURE
= 10,
148 OPCLASS_SURFACE
= 11,
152 OPCLASS_BITFIELD
= 16,
153 OPCLASS_CONTROL
= 17,
160 Target(bool m
, bool j
, bool s
) : hasJoin(m
), joinAnterior(j
), hasSWSched(s
) { }
161 virtual ~Target() { }
163 static Target
*create(uint32_t chipset
);
164 static void destroy(Target
*);
166 // 0x50 and 0x84 to 0xaf for nv50
167 // 0xc0 to 0xdf for nvc0
168 inline uint32_t getChipset() const { return chipset
; }
170 virtual CodeEmitter
*getCodeEmitter(Program::Type
) = 0;
172 // Drivers should upload this so we can use it from all programs.
173 // The address chosen is supplied to the relocation routine.
174 virtual void getBuiltinCode(const uint32_t **code
, uint32_t *size
) const = 0;
176 virtual void parseDriverInfo(const struct nv50_ir_prog_info
*info
) {
177 threads
= info
->prop
.cp
.numThreads
[0] *
178 info
->prop
.cp
.numThreads
[1] *
179 info
->prop
.cp
.numThreads
[2];
181 threads
= info
->target
>= NVISA_GK104_CHIPSET
? 1024 : 512;
184 virtual bool runLegalizePass(Program
*, CGStage stage
) const = 0;
197 uint16_t srcFiles
[3];
199 unsigned int minEncSize
: 4;
200 unsigned int vector
: 1;
201 unsigned int predicate
: 1;
202 unsigned int commutative
: 1;
203 unsigned int pseudo
: 1;
204 unsigned int flow
: 1;
205 unsigned int hasDest
: 1;
206 unsigned int terminator
: 1;
209 inline const OpInfo
& getOpInfo(const Instruction
*) const;
210 inline const OpInfo
& getOpInfo(const operation
) const;
212 inline DataFile
nativeFile(DataFile f
) const;
214 virtual bool insnCanLoad(const Instruction
*insn
, int s
,
215 const Instruction
*ld
) const = 0;
216 virtual bool insnCanLoadOffset(const Instruction
*insn
, int s
,
217 int offset
) const = 0;
218 virtual bool isOpSupported(operation
, DataType
) const = 0;
219 virtual bool isAccessSupported(DataFile
, DataType
) const = 0;
220 virtual bool isModSupported(const Instruction
*,
221 int s
, Modifier
) const = 0;
222 virtual bool isSatSupported(const Instruction
*) const = 0;
223 virtual bool isPostMultiplySupported(operation op
, float f
,
224 int& e
) const { return false; }
225 virtual bool mayPredicate(const Instruction
*,
226 const Value
*) const = 0;
228 // whether @insn can be issued together with @next (order matters)
229 virtual bool canDualIssue(const Instruction
*insn
,
230 const Instruction
*next
) const { return false; }
231 virtual int getLatency(const Instruction
*) const { return 1; }
232 virtual int getThroughput(const Instruction
*) const { return 1; }
234 virtual unsigned int getFileSize(DataFile
) const = 0;
235 virtual unsigned int getFileUnit(DataFile
) const = 0;
237 virtual uint32_t getSVAddress(DataFile
, const Symbol
*) const = 0;
240 const bool hasJoin
; // true if instructions have a join modifier
241 const bool joinAnterior
; // true if join is executed before the op
242 const bool hasSWSched
; // true if code should provide scheduling data
244 static const uint8_t operationSrcNr
[];
245 static const OpClass operationClass
[];
247 static inline uint8_t getOpSrcNr(operation op
)
249 return operationSrcNr
[op
];
251 static inline OpClass
getOpClass(operation op
)
253 return operationClass
[op
];
260 DataFile nativeFileMap
[DATA_FILE_COUNT
];
262 OpInfo opInfo
[OP_LAST
+ 1];
265 const Target::OpInfo
& Target::getOpInfo(const Instruction
*insn
) const
267 return opInfo
[MIN2(insn
->op
, OP_LAST
)];
270 const Target::OpInfo
& Target::getOpInfo(const operation op
) const
275 inline DataFile
Target::nativeFile(DataFile f
) const
277 return nativeFileMap
[f
];
280 } // namespace nv50_ir
282 #endif // __NV50_IR_TARGET_H__