• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include <stdbool.h>
35 
36 struct radeon_compiler;
37 struct rc_instruction;
38 struct rc_swizzle_caps;
39 struct rc_src_register;
40 struct rc_pair_instruction_arg;
41 struct rc_pair_instruction_source;
42 struct rc_pair_sub_instruction;
43 struct rc_compiler;
44 
45 
46 /**
47  * Help analyze and modify the register accesses of instructions.
48  */
49 /*@{*/
50 typedef void (*rc_read_write_chan_fn)(void * userdata, struct rc_instruction * inst,
51 			rc_register_file file, unsigned int index, unsigned int chan);
52 void rc_for_all_reads_chan(struct rc_instruction * inst, rc_read_write_chan_fn cb, void * userdata);
53 void rc_for_all_writes_chan(struct rc_instruction * inst, rc_read_write_chan_fn cb, void * userdata);
54 
55 typedef void (*rc_read_write_mask_fn)(void * userdata, struct rc_instruction * inst,
56 			rc_register_file file, unsigned int index, unsigned int mask);
57 void rc_for_all_reads_mask(struct rc_instruction * inst, rc_read_write_mask_fn cb, void * userdata);
58 void rc_for_all_writes_mask(struct rc_instruction * inst, rc_read_write_mask_fn cb, void * userdata);
59 
60 typedef void (*rc_read_src_fn)(void * userdata, struct rc_instruction * inst,
61 			struct rc_src_register * src);
62 void rc_for_all_reads_src(struct rc_instruction * inst, rc_read_src_fn cb,
63 			void * userdata);
64 
65 typedef void (*rc_pair_read_arg_fn)(void * userdata,
66 	struct rc_instruction * inst, struct rc_pair_instruction_arg * arg,
67 	struct rc_pair_instruction_source * src);
68 void rc_pair_for_all_reads_arg(struct rc_instruction * inst,
69 					rc_pair_read_arg_fn cb, void * userdata);
70 
71 typedef void (*rc_remap_register_fn)(void * userdata, struct rc_instruction * inst,
72 			rc_register_file * pfile, unsigned int * pindex);
73 void rc_remap_registers(struct rc_instruction * inst, rc_remap_register_fn cb, void * userdata);
74 /*@}*/
75 
76 struct rc_reader {
77 	struct rc_instruction * Inst;
78 	unsigned int WriteMask;
79 	union {
80 		struct {
81 			struct rc_src_register * Src;
82 		} I;
83 		struct {
84 			struct rc_pair_instruction_arg * Arg;
85 			struct rc_pair_instruction_source * Src;
86 		} P;
87 	} U;
88 };
89 
90 struct rc_reader_data {
91 	unsigned int Abort;
92 	unsigned int AbortOnRead;
93 	unsigned int AbortOnWrite;
94 	unsigned int LoopDepth;
95 	unsigned int InElse;
96 	bool ReadersAfterEndloop;
97 	struct rc_instruction * Writer;
98 
99 	unsigned int ReaderCount;
100 	unsigned int ReadersReserved;
101 	struct rc_reader * Readers;
102 
103 	/* If this flag is enabled, rc_get_readers will exit as soon possbile
104 	 * after the Abort flag is set.*/
105 	unsigned int ExitOnAbort;
106 	void * CbData;
107 };
108 
109 void rc_get_readers(
110 	struct radeon_compiler * c,
111 	struct rc_instruction * writer,
112 	struct rc_reader_data * data,
113 	rc_read_src_fn read_normal_cb,
114 	rc_pair_read_arg_fn read_pair_cb,
115 	rc_read_write_mask_fn write_cb);
116 
117 void rc_get_readers_sub(
118 	struct radeon_compiler * c,
119 	struct rc_instruction * writer,
120 	struct rc_pair_sub_instruction * sub_writer,
121 	struct rc_reader_data * data,
122 	rc_read_src_fn read_normal_cb,
123 	rc_pair_read_arg_fn read_pair_cb,
124 	rc_read_write_mask_fn write_cb);
125 /**
126  * Compiler passes based on dataflow analysis.
127  */
128 /*@{*/
129 typedef void (*rc_dataflow_mark_outputs_fn)(void * userdata, void * data,
130 			void (*mark_fn)(void * data, unsigned int index, unsigned int mask));
131 void rc_dataflow_deadcode(struct radeon_compiler * c, void *user);
132 void rc_dataflow_swizzles(struct radeon_compiler * c, void *user);
133 /*@}*/
134 
135 void rc_optimize(struct radeon_compiler * c, void *user);
136 void rc_inline_literals(struct radeon_compiler *c, void *user);
137 
138 #endif /* RADEON_DATAFLOW_H */
139