01fcc1befdc8150c4920697c7711028b8228e36a
[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 #ifndef __cplusplus
51 struct backend_instruction;
52 #endif
53
54 struct bblock_t {
55 #ifdef __cplusplus
56 DECLARE_RALLOC_CXX_OPERATORS(bblock_t)
57
58 bblock_t();
59
60 void add_successor(void *mem_ctx, bblock_t *successor);
61 void dump(backend_visitor *v);
62 #endif
63
64 struct backend_instruction *start;
65 struct backend_instruction *end;
66
67 int start_ip;
68 int end_ip;
69
70 struct exec_list parents;
71 struct exec_list children;
72 int block_num;
73
74 /* If the current basic block ends in an IF, ELSE, or ENDIF instruction,
75 * these pointers will hold the locations of the other associated control
76 * flow instructions.
77 *
78 * Otherwise they are NULL.
79 */
80 struct backend_instruction *if_inst;
81 struct backend_instruction *else_inst;
82 struct backend_instruction *endif_inst;
83 };
84
85 struct cfg_t {
86 #ifdef __cplusplus
87 DECLARE_RALLOC_CXX_OPERATORS(cfg_t)
88
89 cfg_t(exec_list *instructions);
90 ~cfg_t();
91
92 bblock_t *new_block();
93 void set_next_block(bblock_t **cur, bblock_t *block, int ip);
94 void make_block_array();
95
96 void dump(backend_visitor *v);
97 #endif
98 void *mem_ctx;
99
100 /** Ordered list (by ip) of basic blocks */
101 struct exec_list block_list;
102 struct bblock_t **blocks;
103 int num_blocks;
104 };
105
106 #define foreach_block_and_inst(__block, __type, __inst, __cfg) \
107 foreach_block (__block, __cfg) \
108 foreach_inst_in_block (__type, __inst, __block)
109
110 #define foreach_inst_in_block(__type, __inst, __block) \
111 for (__type *__inst = (__type *)__block->start; \
112 __inst != __block->end->next; \
113 __inst = (__type *)__inst->next)
114
115 #define foreach_inst_in_block_reverse(__type, __inst, __block) \
116 for (__type *__inst = (__type *)__block->end; \
117 __inst != __block->start->prev; \
118 __inst = (__type *)__inst->prev)
119
120 #endif /* BRW_CFG_H */