r300/compiler: Add a new function for more efficient dataflow analysis
[mesa.git] / src / mesa / drivers / dri / r300 / compiler / radeon_dataflow.h
1 /*
2 * Copyright (C) 2009 Nicolai Haehnle.
3 * Copyright 2010 Tom Stellard <tstellar@gmail.com>
4 *
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial
17 * portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
23 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 */
28
29 #ifndef RADEON_DATAFLOW_H
30 #define RADEON_DATAFLOW_H
31
32 #include "radeon_program_constants.h"
33
34 struct radeon_compiler;
35 struct rc_instruction;
36 struct rc_swizzle_caps;
37 struct rc_src_register;
38 struct rc_pair_instruction_arg;
39 struct rc_compiler;
40
41
42 /**
43 * Help analyze and modify the register accesses of instructions.
44 */
45 /*@{*/
46 typedef void (*rc_read_write_chan_fn)(void * userdata, struct rc_instruction * inst,
47 rc_register_file file, unsigned int index, unsigned int chan);
48 void rc_for_all_reads_chan(struct rc_instruction * inst, rc_read_write_chan_fn cb, void * userdata);
49 void rc_for_all_writes_chan(struct rc_instruction * inst, rc_read_write_chan_fn cb, void * userdata);
50
51 typedef void (*rc_read_write_mask_fn)(void * userdata, struct rc_instruction * inst,
52 rc_register_file file, unsigned int index, unsigned int mask);
53 void rc_for_all_reads_mask(struct rc_instruction * inst, rc_read_write_mask_fn cb, void * userdata);
54 void rc_for_all_writes_mask(struct rc_instruction * inst, rc_read_write_mask_fn cb, void * userdata);
55
56 typedef void (*rc_read_src_fn)(void * userdata, struct rc_instruction * inst,
57 struct rc_src_register * src);
58 void rc_for_all_reads_src(struct rc_instruction * inst, rc_read_src_fn cb,
59 void * userdata);
60
61 typedef void (*rc_pair_read_arg_fn)(void * userdata,
62 struct rc_instruction * inst, struct rc_pair_instruction_arg * arg);
63 void rc_pair_for_all_reads_arg(struct rc_instruction * inst,
64 rc_pair_read_arg_fn cb, void * userdata);
65
66 typedef void (*rc_remap_register_fn)(void * userdata, struct rc_instruction * inst,
67 rc_register_file * pfile, unsigned int * pindex);
68 void rc_remap_registers(struct rc_instruction * inst, rc_remap_register_fn cb, void * userdata);
69 /*@}*/
70
71 struct rc_reader {
72 struct rc_instruction * Inst;
73 unsigned int WriteMask;
74 struct rc_src_register * Src;
75 };
76
77 struct rc_reader_data {
78 unsigned int Abort;
79 unsigned int AbortOnRead;
80 unsigned int InElse;
81 struct rc_instruction * Writer;
82
83 unsigned int ReaderCount;
84 unsigned int ReadersReserved;
85 struct rc_reader * Readers;
86
87 void * CbData;
88 };
89
90 void rc_get_readers_normal(
91 struct radeon_compiler * c,
92 struct rc_instruction * inst,
93 struct rc_reader_data * data,
94 /*XXX: These should be their own function types. */
95 rc_read_src_fn read_cb,
96 rc_read_write_mask_fn write_cb);
97
98 /**
99 * Compiler passes based on dataflow analysis.
100 */
101 /*@{*/
102 typedef void (*rc_dataflow_mark_outputs_fn)(void * userdata, void * data,
103 void (*mark_fn)(void * data, unsigned int index, unsigned int mask));
104 void rc_dataflow_deadcode(struct radeon_compiler * c, void *user);
105 void rc_dataflow_swizzles(struct radeon_compiler * c, void *user);
106 /*@}*/
107
108 void rc_optimize(struct radeon_compiler * c, void *user);
109
110 #endif /* RADEON_DATAFLOW_H */