i965/cfg: Keep pointers to IF/ELSE/ENDIF instructions in the cfg.
[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 #include "brw_fs.h"
29
30 class bblock_link : public exec_node {
31 public:
32 bblock_link(bblock_t *block)
33 : block(block)
34 {
35 }
36
37 bblock_t *block;
38 };
39
40 class bblock_t {
41 public:
42 DECLARE_RALLOC_CXX_OPERATORS(bblock_t)
43
44 bblock_link *make_list(void *mem_ctx);
45
46 bblock_t();
47
48 void add_successor(void *mem_ctx, bblock_t *successor);
49 void dump(backend_visitor *v);
50
51 backend_instruction *start;
52 backend_instruction *end;
53
54 int start_ip;
55 int end_ip;
56
57 exec_list parents;
58 exec_list children;
59 int block_num;
60
61 /* If the current basic block ends in an IF, ELSE, or ENDIF instruction,
62 * these pointers will hold the locations of the other associated control
63 * flow instructions.
64 *
65 * Otherwise they are NULL.
66 */
67 backend_instruction *if_inst;
68 backend_instruction *else_inst;
69 backend_instruction *endif_inst;
70 };
71
72 class cfg_t {
73 public:
74 DECLARE_RALLOC_CXX_OPERATORS(cfg_t)
75
76 cfg_t(backend_visitor *v);
77 cfg_t(void *mem_ctx, exec_list *instructions);
78 ~cfg_t();
79
80 void create(void *mem_ctx, exec_list *instructions);
81
82 bblock_t *new_block();
83 void set_next_block(bblock_t *block);
84 void make_block_array();
85
86 void dump(backend_visitor *v);
87
88 /** @{
89 *
90 * Used while generating the block list.
91 */
92 bblock_t *cur;
93 int ip;
94 /** @} */
95
96 void *mem_ctx;
97
98 /** Ordered list (by ip) of basic blocks */
99 exec_list block_list;
100 bblock_t **blocks;
101 int num_blocks;
102 };