2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef R600_COMPILER_H
24 #define R600_COMPILER_H
26 #include "util/u_double_list.h"
30 /* operand are the basic source/destination of each operation */
32 struct list_head head
;
33 unsigned vindex
; /**< index in vector X,Y,Z,W (0,1,2,3) */
34 unsigned value
; /**< immediate value 32bits */
35 struct c_vector
*vector
; /**< vector to which it belongs */
38 /* in GPU world most of the time operand are grouped into vector
39 * of 4 component this structure is mostly and handler to group
40 * operand into a same vector
43 struct list_head head
;
44 unsigned id
; /**< vector uniq id */
45 unsigned name
; /**< semantic name */
46 unsigned file
; /**< operand file C_FILE_* */
47 int sid
; /**< semantic id */
48 struct c_channel
*channel
[4]; /**< operands */
51 #define C_PROGRAM_TYPE_VS 0
52 #define C_PROGRAM_TYPE_FS 1
53 #define C_PROGRAM_TYPE_COUNT 2
55 #define C_NODE_FLAG_ALU 1
56 #define C_NODE_FLAG_FETCH 2
67 #define C_FILE_CONSTANT 1
68 #define C_FILE_INPUT 2
69 #define C_FILE_OUTPUT 3
70 #define C_FILE_TEMPORARY 4
71 #define C_FILE_SAMPLER 5
72 #define C_FILE_ADDRESS 6
73 #define C_FILE_IMMEDIATE 7
75 #define C_FILE_PREDICATE 9
76 #define C_FILE_SYSTEM_VALUE 10
77 #define C_FILE_RESOURCE 11
78 #define C_FILE_COUNT 12
80 #define C_SEMANTIC_POSITION 0
81 #define C_SEMANTIC_COLOR 1
82 #define C_SEMANTIC_BCOLOR 2 /**< back-face color */
83 #define C_SEMANTIC_FOG 3
84 #define C_SEMANTIC_PSIZE 4
85 #define C_SEMANTIC_GENERIC 5
86 #define C_SEMANTIC_NORMAL 6
87 #define C_SEMANTIC_FACE 7
88 #define C_SEMANTIC_EDGEFLAG 8
89 #define C_SEMANTIC_PRIMID 9
90 #define C_SEMANTIC_INSTANCEID 10
91 #define C_SEMANTIC_VERTEXID 11
92 #define C_SEMANTIC_COUNT 12 /**< number of semantic values */
94 #define C_OPCODE_NOP 0
95 #define C_OPCODE_MOV 1
96 #define C_OPCODE_LIT 2
97 #define C_OPCODE_RCP 3
98 #define C_OPCODE_RSQ 4
99 #define C_OPCODE_EXP 5
100 #define C_OPCODE_LOG 6
101 #define C_OPCODE_MUL 7
102 #define C_OPCODE_ADD 8
103 #define C_OPCODE_DP3 9
104 #define C_OPCODE_DP4 10
105 #define C_OPCODE_DST 11
106 #define C_OPCODE_MIN 12
107 #define C_OPCODE_MAX 13
108 #define C_OPCODE_SLT 14
109 #define C_OPCODE_SGE 15
110 #define C_OPCODE_MAD 16
111 #define C_OPCODE_SUB 17
112 #define C_OPCODE_LRP 18
113 #define C_OPCODE_CND 19
115 #define C_OPCODE_DP2A 21
117 #define C_OPCODE_FRC 24
118 #define C_OPCODE_CLAMP 25
119 #define C_OPCODE_FLR 26
120 #define C_OPCODE_ROUND 27
121 #define C_OPCODE_EX2 28
122 #define C_OPCODE_LG2 29
123 #define C_OPCODE_POW 30
124 #define C_OPCODE_XPD 31
126 #define C_OPCODE_ABS 33
127 #define C_OPCODE_RCC 34
128 #define C_OPCODE_DPH 35
129 #define C_OPCODE_COS 36
130 #define C_OPCODE_DDX 37
131 #define C_OPCODE_DDY 38
132 #define C_OPCODE_KILP 39 /* predicated kill */
133 #define C_OPCODE_PK2H 40
134 #define C_OPCODE_PK2US 41
135 #define C_OPCODE_PK4B 42
136 #define C_OPCODE_PK4UB 43
137 #define C_OPCODE_RFL 44
138 #define C_OPCODE_SEQ 45
139 #define C_OPCODE_SFL 46
140 #define C_OPCODE_SGT 47
141 #define C_OPCODE_SIN 48
142 #define C_OPCODE_SLE 49
143 #define C_OPCODE_SNE 50
144 #define C_OPCODE_STR 51
145 #define C_OPCODE_TEX 52
146 #define C_OPCODE_TXD 53
147 #define C_OPCODE_TXP 54
148 #define C_OPCODE_UP2H 55
149 #define C_OPCODE_UP2US 56
150 #define C_OPCODE_UP4B 57
151 #define C_OPCODE_UP4UB 58
152 #define C_OPCODE_X2D 59
153 #define C_OPCODE_ARA 60
154 #define C_OPCODE_ARR 61
155 #define C_OPCODE_BRA 62
156 #define C_OPCODE_CAL 63
157 #define C_OPCODE_RET 64
158 #define C_OPCODE_SSG 65 /* SGN */
159 #define C_OPCODE_CMP 66
160 #define C_OPCODE_SCS 67
161 #define C_OPCODE_TXB 68
162 #define C_OPCODE_NRM 69
163 #define C_OPCODE_DIV 70
164 #define C_OPCODE_DP2 71
165 #define C_OPCODE_TXL 72
166 #define C_OPCODE_BRK 73
167 #define C_OPCODE_IF 74
168 #define C_OPCODE_BGNFOR 75
169 #define C_OPCODE_REP 76
170 #define C_OPCODE_ELSE 77
171 #define C_OPCODE_ENDIF 78
172 #define C_OPCODE_ENDFOR 79
173 #define C_OPCODE_ENDREP 80
174 #define C_OPCODE_PUSHA 81
175 #define C_OPCODE_POPA 82
176 #define C_OPCODE_CEIL 83
177 #define C_OPCODE_I2F 84
178 #define C_OPCODE_NOT 85
179 #define C_OPCODE_TRUNC 86
180 #define C_OPCODE_SHL 87
182 #define C_OPCODE_AND 89
183 #define C_OPCODE_OR 90
184 #define C_OPCODE_MOD 91
185 #define C_OPCODE_XOR 92
186 #define C_OPCODE_SAD 93
187 #define C_OPCODE_TXF 94
188 #define C_OPCODE_TXQ 95
189 #define C_OPCODE_CONT 96
190 #define C_OPCODE_EMIT 97
191 #define C_OPCODE_ENDPRIM 98
192 #define C_OPCODE_BGNLOOP 99
193 #define C_OPCODE_BGNSUB 100
194 #define C_OPCODE_ENDLOOP 101
195 #define C_OPCODE_ENDSUB 102
197 #define C_OPCODE_NRM4 112
198 #define C_OPCODE_CALLNZ 113
199 #define C_OPCODE_IFC 114
200 #define C_OPCODE_BREAKC 115
201 #define C_OPCODE_KIL 116 /* conditional kill */
202 #define C_OPCODE_END 117 /* aka HALT */
204 #define C_OPCODE_F2I 119
205 #define C_OPCODE_IDIV 120
206 #define C_OPCODE_IMAX 121
207 #define C_OPCODE_IMIN 122
208 #define C_OPCODE_INEG 123
209 #define C_OPCODE_ISGE 124
210 #define C_OPCODE_ISHR 125
211 #define C_OPCODE_ISLT 126
212 #define C_OPCODE_F2U 127
213 #define C_OPCODE_U2F 128
214 #define C_OPCODE_UADD 129
215 #define C_OPCODE_UDIV 130
216 #define C_OPCODE_UMAD 131
217 #define C_OPCODE_UMAX 132
218 #define C_OPCODE_UMIN 133
219 #define C_OPCODE_UMOD 134
220 #define C_OPCODE_UMUL 135
221 #define C_OPCODE_USEQ 136
222 #define C_OPCODE_USGE 137
223 #define C_OPCODE_USHR 138
224 #define C_OPCODE_USLT 139
225 #define C_OPCODE_USNE 140
226 #define C_OPCODE_SWITCH 141
227 #define C_OPCODE_CASE 142
228 #define C_OPCODE_DEFAULT 143
229 #define C_OPCODE_ENDSWITCH 144
230 #define C_OPCODE_VFETCH 145
231 #define C_OPCODE_ENTRY 146
232 #define C_OPCODE_ARL 147
233 #define C_OPCODE_LAST 148
235 #define C_OPERAND_FLAG_ABS (1 << 0)
236 #define C_OPERAND_FLAG_NEG (1 << 1)
239 struct c_vector
*vector
;
246 struct c_operand input
[3];
247 struct c_operand output
;
251 struct c_instruction
{
252 struct list_head head
;
260 struct list_head head
;
267 * @next: all node are in a double linked list, this point to
269 * @next: all node are in a double linked list, this point to
271 * @predecessors: list of all predecessor nodes in the flow graph
272 * @successors: list of all sucessor nodes in the flow graph
273 * @parent: parent node in the depth first walk tree
274 * @childs: child nodes in the depth first walk tree
277 struct list_head head
;
278 struct list_head predecessors
;
279 struct list_head successors
;
280 struct list_head childs
;
281 struct c_node
*parent
;
282 struct list_head insts
;
291 struct list_head vectors
;
296 struct c_file files
[C_FILE_COUNT
];
297 struct list_head nodes
;
303 int c_shader_init(struct c_shader
*shader
, unsigned type
);
304 void c_shader_destroy(struct c_shader
*shader
);
305 struct c_vector
*c_shader_vector_new(struct c_shader
*shader
, unsigned file
, unsigned name
, int sid
);
306 int c_shader_build_dominator_tree(struct c_shader
*shader
);
307 void c_shader_dump(struct c_shader
*shader
);
309 void c_node_init(struct c_node
*node
);
310 int c_node_add_new_instruction(struct c_node
*node
, struct c_instruction
*instruction
);
311 int c_node_add_new_instruction_head(struct c_node
*node
, struct c_instruction
*instruction
);
313 /* control flow graph functions */
314 int c_node_cfg_link(struct c_node
*predecessor
, struct c_node
*successor
);
315 struct c_node
*c_node_cfg_new_after(struct c_node
*predecessor
);
316 struct c_node
*c_shader_cfg_new_node_after(struct c_shader
*shader
, struct c_node
*predecessor
);
318 struct c_vector
*c_vector_new(void);