i965: Use brw_wm_prog_data::uses_kill, not gl_fragment_program::UsesKill
[mesa.git] / src / mesa / drivers / dri / i965 / brw_cfg.h
1 /*
2 * Copyright © 2012 Intel Corporation
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 (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28 #pragma once
29 #ifndef BRW_CFG_H
30 #define BRW_CFG_H
31
32 #include "brw_shader.h"
33
34 struct bblock_t;
35
36 struct bblock_link {
37 #ifdef __cplusplus
38 DECLARE_RALLOC_CXX_OPERATORS(bblock_link)
39
40 bblock_link(bblock_t *block)
41 : block(block)
42 {
43 }
44 #endif
45
46 struct exec_node link;
47 struct bblock_t *block;
48 };
49
50 struct backend_instruction;
51
52 struct bblock_t {
53 #ifdef __cplusplus
54 DECLARE_RALLOC_CXX_OPERATORS(bblock_t)
55
56 explicit bblock_t(cfg_t *cfg);
57
58 void add_successor(void *mem_ctx, bblock_t *successor);
59 bool is_predecessor_of(const bblock_t *block) const;
60 bool is_successor_of(const bblock_t *block) const;
61 bool can_combine_with(const bblock_t *that) const;
62 void combine_with(bblock_t *that);
63 void dump(backend_visitor *v) const;
64
65 backend_instruction *start();
66 const backend_instruction *start() const;
67 backend_instruction *end();
68 const backend_instruction *end() const;
69
70 bblock_t *next();
71 const bblock_t *next() const;
72 bblock_t *prev();
73 const bblock_t *prev() const;
74
75 bool starts_with_control_flow() const;
76 bool ends_with_control_flow() const;
77
78 backend_instruction *first_non_control_flow_inst();
79 backend_instruction *last_non_control_flow_inst();
80 #endif
81
82 struct exec_node link;
83 struct cfg_t *cfg;
84
85 int start_ip;
86 int end_ip;
87
88 struct exec_list instructions;
89 struct exec_list parents;
90 struct exec_list children;
91 int num;
92 };
93
94 static inline struct backend_instruction *
95 bblock_start(struct bblock_t *block)
96 {
97 return (struct backend_instruction *)exec_list_get_head(&block->instructions);
98 }
99
100 static inline const struct backend_instruction *
101 bblock_start_const(const struct bblock_t *block)
102 {
103 return (const struct backend_instruction *)exec_list_get_head_const(&block->instructions);
104 }
105
106 static inline struct backend_instruction *
107 bblock_end(struct bblock_t *block)
108 {
109 return (struct backend_instruction *)exec_list_get_tail(&block->instructions);
110 }
111
112 static inline const struct backend_instruction *
113 bblock_end_const(const struct bblock_t *block)
114 {
115 return (const struct backend_instruction *)exec_list_get_tail_const(&block->instructions);
116 }
117
118 static inline struct bblock_t *
119 bblock_next(struct bblock_t *block)
120 {
121 return (struct bblock_t *)block->link.next;
122 }
123
124 static inline const struct bblock_t *
125 bblock_next_const(const struct bblock_t *block)
126 {
127 return (const struct bblock_t *)block->link.next;
128 }
129
130 static inline struct bblock_t *
131 bblock_prev(struct bblock_t *block)
132 {
133 return (struct bblock_t *)block->link.prev;
134 }
135
136 static inline const struct bblock_t *
137 bblock_prev_const(const struct bblock_t *block)
138 {
139 return (const struct bblock_t *)block->link.prev;
140 }
141
142 static inline bool
143 bblock_starts_with_control_flow(const struct bblock_t *block)
144 {
145 enum opcode op = bblock_start_const(block)->opcode;
146 return op == BRW_OPCODE_DO || op == BRW_OPCODE_ENDIF;
147 }
148
149 static inline bool
150 bblock_ends_with_control_flow(const struct bblock_t *block)
151 {
152 enum opcode op = bblock_end_const(block)->opcode;
153 return op == BRW_OPCODE_IF ||
154 op == BRW_OPCODE_ELSE ||
155 op == BRW_OPCODE_WHILE ||
156 op == BRW_OPCODE_BREAK ||
157 op == BRW_OPCODE_CONTINUE;
158 }
159
160 static inline struct backend_instruction *
161 bblock_first_non_control_flow_inst(struct bblock_t *block)
162 {
163 struct backend_instruction *inst = bblock_start(block);
164 if (bblock_starts_with_control_flow(block))
165 #ifdef __cplusplus
166 inst = (struct backend_instruction *)inst->next;
167 #else
168 inst = (struct backend_instruction *)inst->link.next;
169 #endif
170 return inst;
171 }
172
173 static inline struct backend_instruction *
174 bblock_last_non_control_flow_inst(struct bblock_t *block)
175 {
176 struct backend_instruction *inst = bblock_end(block);
177 if (bblock_ends_with_control_flow(block))
178 #ifdef __cplusplus
179 inst = (struct backend_instruction *)inst->prev;
180 #else
181 inst = (struct backend_instruction *)inst->link.prev;
182 #endif
183 return inst;
184 }
185
186 #ifdef __cplusplus
187 inline backend_instruction *
188 bblock_t::start()
189 {
190 return bblock_start(this);
191 }
192
193 inline const backend_instruction *
194 bblock_t::start() const
195 {
196 return bblock_start_const(this);
197 }
198
199 inline backend_instruction *
200 bblock_t::end()
201 {
202 return bblock_end(this);
203 }
204
205 inline const backend_instruction *
206 bblock_t::end() const
207 {
208 return bblock_end_const(this);
209 }
210
211 inline bblock_t *
212 bblock_t::next()
213 {
214 return bblock_next(this);
215 }
216
217 inline const bblock_t *
218 bblock_t::next() const
219 {
220 return bblock_next_const(this);
221 }
222
223 inline bblock_t *
224 bblock_t::prev()
225 {
226 return bblock_prev(this);
227 }
228
229 inline const bblock_t *
230 bblock_t::prev() const
231 {
232 return bblock_prev_const(this);
233 }
234
235 inline bool
236 bblock_t::starts_with_control_flow() const
237 {
238 return bblock_starts_with_control_flow(this);
239 }
240
241 inline bool
242 bblock_t::ends_with_control_flow() const
243 {
244 return bblock_ends_with_control_flow(this);
245 }
246
247 inline backend_instruction *
248 bblock_t::first_non_control_flow_inst()
249 {
250 return bblock_first_non_control_flow_inst(this);
251 }
252
253 inline backend_instruction *
254 bblock_t::last_non_control_flow_inst()
255 {
256 return bblock_last_non_control_flow_inst(this);
257 }
258 #endif
259
260 struct cfg_t {
261 #ifdef __cplusplus
262 DECLARE_RALLOC_CXX_OPERATORS(cfg_t)
263
264 cfg_t(exec_list *instructions);
265 ~cfg_t();
266
267 void remove_block(bblock_t *block);
268
269 bblock_t *new_block();
270 void set_next_block(bblock_t **cur, bblock_t *block, int ip);
271 void make_block_array();
272
273 void dump(backend_visitor *v) const;
274 #endif
275 void *mem_ctx;
276
277 /** Ordered list (by ip) of basic blocks */
278 struct exec_list block_list;
279 struct bblock_t **blocks;
280 int num_blocks;
281 };
282
283 /* Note that this is implemented with a double for loop -- break will
284 * break from the inner loop only!
285 */
286 #define foreach_block_and_inst(__block, __type, __inst, __cfg) \
287 foreach_block (__block, __cfg) \
288 foreach_inst_in_block (__type, __inst, __block)
289
290 /* Note that this is implemented with a double for loop -- break will
291 * break from the inner loop only!
292 */
293 #define foreach_block_and_inst_safe(__block, __type, __inst, __cfg) \
294 foreach_block_safe (__block, __cfg) \
295 foreach_inst_in_block_safe (__type, __inst, __block)
296
297 #define foreach_block(__block, __cfg) \
298 foreach_list_typed (bblock_t, __block, link, &(__cfg)->block_list)
299
300 #define foreach_block_safe(__block, __cfg) \
301 foreach_list_typed_safe (bblock_t, __block, link, &(__cfg)->block_list)
302
303 #define foreach_inst_in_block(__type, __inst, __block) \
304 foreach_in_list(__type, __inst, &(__block)->instructions)
305
306 #define foreach_inst_in_block_safe(__type, __inst, __block) \
307 for (__type *__inst = (__type *)__block->instructions.head, \
308 *__next = (__type *)__inst->next, \
309 *__end = (__type *)__block->instructions.tail; \
310 __next != __end; \
311 __inst = __next, \
312 __next = (__type *)__next->next)
313
314 #define foreach_inst_in_block_reverse(__type, __inst, __block) \
315 foreach_in_list_reverse(__type, __inst, &(__block)->instructions)
316
317 #define foreach_inst_in_block_starting_from(__type, __scan_inst, __inst, __block) \
318 for (__type *__scan_inst = (__type *)__inst->next; \
319 !__scan_inst->is_tail_sentinel(); \
320 __scan_inst = (__type *)__scan_inst->next)
321
322 #define foreach_inst_in_block_reverse_starting_from(__type, __scan_inst, __inst, __block) \
323 for (__type *__scan_inst = (__type *)__inst->prev; \
324 !__scan_inst->is_head_sentinel(); \
325 __scan_inst = (__type *)__scan_inst->prev)
326
327 #endif /* BRW_CFG_H */